Audizine - An Automotive Enthusiast Community

Results 1 to 2 of 2
  1. #1
    Veteran Member Three Rings DrGER's Avatar
    Join Date
    Aug 31 2014
    AZ Member #
    279216
    My Garage
    '17 Audi A4Q 6MT CYMC/RJN, '11 VW GOV TDI 6MT CJAA/LHD
    Location
    NW OH USA

    New and Improved Encoded copie_scr.sh Script

    Guest-only advertisement. Register or Log In now!
    The "standard" 161 byte encoded copie_scr.sh script for launching SD card shell scripts on MMI 3G systems, while useful, doesn't take full advantage of its native QNX environment, namely, in how it determines the path to the calling SD card root/base directory. I've been using this frequently lately to look at various processes and file systems in our MMI 3G+ system, and found the "standard" copie_scr.sh lacking, particularly with regard to its behavior when other removable media is connected to the system.

    Inspection of "pidin" shows that the script launcher process (proc_scriptlauncher) identifies correctly the mount path to the SD card in which the encoded copie_scr.sh script resides, for example:

    Code:
      323657   24584 /bin/proc_scriptlauncher -i 30 -p /dev/shmem/copie_scr.sh
    ...
      966717  323657 ksh /dev/shmem/copie_scr.sh /mnt/sdcard10t12

    and

    Code:
      323657   24584 /bin/proc_scriptlauncher -i 30 -p /dev/shmem/copie_scr.sh
    ...
     1212477  323657 ksh /dev/shmem/copie_scr.sh /mnt/sdcard20t12

    In the former case, the SD script is run from slot SD 1; in the latter, slot SD 2.

    Thus, shell argument 1 to the encoded copie_scr.sh script contains the correct mount path to the SD card. Using this information about the calling process, we can include it in a new (encoded) copie_scr.sh script:

    Code:
    #!/bin/ksh
    # 20220102 drger; MMI3G SD shell script launcher
    export SDPATH=$1
    export PATH=${SDPATH}/bin:$PATH
    export SDLIB=${SDPATH}/lib
    export SDVAR=${SDPATH}/var
    export SWTRAIN="`cat /dev/shmem/sw_trainname.txt`"
    mount -u $SDPATH
    cd $SDPATH
    exec ksh ./run.sh $SDPATH

    Here, new exported environment variable SDPATH contains the value passed from the script launcher process as argument number 1 ($1). And while we're at it, we can prepend our SD card bin directory to the PATH, and add a new SWTRAIN environment variable using the contents of /dev/shmem/sw_trainname.txt (this is the MMI firmware version name) (along with a couple environment variables I use routinely in my MMI SD scripts: SDLIB and SDVAR).

    Finally, the new encoded copie_scr.sh script launches our plain-text "run.sh" shell script with argument $SDPATH for completeness.

    A ZIP archive of this new and improved copie_scr.sh SD card script launcher (and its source text) can be found HERE.

    The size of this encoded copie_scr.sh file is 268 bytes and the md5sum is a18e6f7ebedc97b28f99cacb2ff87d4b. --g
    Last edited by DrGER; 01-11-2022 at 11:01 AM.
    2017 B9 A4Q P+ 2.0T 6MT Daytona Gray. Previous: 2014 B8.5 A4Q P+ 2.0T 6MT Monsoon Gray; 2009 B8 A4Q P+ 2.0T 6MT Brilliant Red; 2005 B6 A4Q 1.8T 6MT Cambridge Green; 1995 B4 A90Q V6 5MT Pearl White; 1990 B3 A80Q I5 5MT Crystal Silver; 1984 C3 5000S I5 5MT Montego Black; 1978 C2 5000 I5 4AT Helios Blue; 1977 C1 100LS I4 4AT Signal Green; 1974 B1 Fox I4 4AT Sahara Sand.

  2. #2
    Veteran Member Three Rings DrGER's Avatar
    Join Date
    Aug 31 2014
    AZ Member #
    279216
    My Garage
    '17 Audi A4Q 6MT CYMC/RJN, '11 VW GOV TDI 6MT CJAA/LHD
    Location
    NW OH USA

    Some additional information on this topic:

    The C source code to decrypt/encrypt the VAG Harman-Becker copie_scr.sh file comes from Github HERE.

    The plain-text C source code:
    Code:
    #include <stdio.h>
    
    unsigned int seed = 0x001be3ac;
    
    unsigned int prng_rand() {
        unsigned int r1, r3, r0;
    
        r0 = seed;
        r1 = (seed >> 1) | (seed << 31);
        r3 = ((r1 >> 16) & 0xFF) + r1;
        r1 = ((r3 >> 8) & 0xFF) << 16;
        r3 -= r1;
        seed = r3;
    
        return r0;
    }
    
    int main(int argc, char *argv[]) {
        int c;
    
        prng_rand();
    
        c = getchar();
        while (c != EOF) {
            c ^= (prng_rand() & 0xFF);
            putchar(c);
            c = getchar();
        }
    }
    On most Unix/Linux systems, this can be compiled with gcc simply with: $ gcc -o copiescrio main.c

    Simple shell redirection is used for input to & output from the executable copiescrio.

    Thus, decrypting an existing copie_scr.sh file to plain-text: $ copiescrio < copie_src.sh > copie_scr.txt
    And encrypting a plain-text source is the opposite: $ copiescrio < copie_scr.txt > copie_scr.sh
    2017 B9 A4Q P+ 2.0T 6MT Daytona Gray. Previous: 2014 B8.5 A4Q P+ 2.0T 6MT Monsoon Gray; 2009 B8 A4Q P+ 2.0T 6MT Brilliant Red; 2005 B6 A4Q 1.8T 6MT Cambridge Green; 1995 B4 A90Q V6 5MT Pearl White; 1990 B3 A80Q I5 5MT Crystal Silver; 1984 C3 5000S I5 5MT Montego Black; 1978 C2 5000 I5 4AT Helios Blue; 1977 C1 100LS I4 4AT Signal Green; 1974 B1 Fox I4 4AT Sahara Sand.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


    © 2001-2025 Audizine, Audizine.com, and Driverzines.com
    Audizine is an independently owned and operated automotive enthusiast community and news website.
    Audi and the Audi logo(s) are copyright/trademark Audi AG. Audizine is not endorsed by or affiliated with Audi AG.