# rFactor 2 (script 0.1.4)
#   RFCMP, MAS and other archives using the same format
# script for QuickBMS http://quickbms.aluigi.org

# original source code http://aluigi.org/papers/bms/rfactor2dec_dll.zip
set MEMORY_FILE4 compressed "[encoded data, 18244 characters]"
math RET = 0
math RFACTOR_RND_SEED = 0

#getdstring SIGN 16  # obfuscated "GMOTOR_MAS_2.90"
idstring "\x66\x31\x05\x44\x20\x7D"
goto 0x10

get KEY32 long
get KEY64 long
getdstring DATA1 32
getdstring DATA2 32
getdstring DATA3 32
getvarchr KEY32_SIGN DATA2 0 long
getvarchr KEY64_SIGN DATA2 4 long

callfunction GENERATE_KEY_DB 1

get SIZE long
savepos BASE_OFF
encryption calldll "MEMORY_FILE4 rfactor2_00475BD0_dll stdcall %RET% #INPUT# %SIZE% 0 %KEY32% %KEY64%"
log MEMORY_FILE BASE_OFF SIZE
math BASE_OFF += SIZE

    # no file encryption
    math FILE_ENCRYPT = 0
    math FILE_KEY32 = 0
    math FILE_KEY64 = 0

callfunction GET_KEY_DB 1
print "key %KEY32|x% %KEY64|x% | %FILE_KEY32|x% %FILE_KEY64|x%"

if FILE_ENCRYPT == 0
    encryption "" ""
else
    # this
    log MEMORY_FILE3 0 0
    putvarchr MEMORY_FILE3 0x80 0
    math TMP = KEY32
    math TMP &= 0xff
    if TMP < 0x40
        math TMP += 0x40
    endif
    putvarchr MEMORY_FILE3 0x34 TMP long
    putvarchr MEMORY_FILE3 0x38 KEY32 long
    putvarchr MEMORY_FILE3 0x3c KEY64 long
    putvarchr MEMORY_FILE3 0x40 FILE_KEY32 long
    putvarchr MEMORY_FILE3 0x44 FILE_KEY64 long
    encryption calldll "MEMORY_FILE4 rfactor2_00476460_dll stdcall %RET% %MEMORY_FILE3% #INPUT# %ZSIZE% 0 %FILE_KEY32% %FILE_KEY64%"
endif

get DUMMY long MEMORY_FILE
get FILES longlong MEMORY_FILE
for i = 0 < FILES
    get FLAGS long MEMORY_FILE
    getdstring NAME 228 MEMORY_FILE
    get OFFSET longlong MEMORY_FILE
    get SIZE longlong MEMORY_FILE
    get ZSIZE longlong MEMORY_FILE

    math OFFSET += BASE_OFF
    if FLAGS & 0x10
        comtype zlib
        clog NAME OFFSET ZSIZE SIZE
    elif FLAGS & 0x10000
        comtype yappy
        clog NAME OFFSET ZSIZE SIZE
    else
        log NAME OFFSET SIZE
    endif
next i

startfunction GENERATE_KEY_DB
    # file keys for rFactor2
    # xor 0xD0C25BF9
    # xor 0xABA62287
    
    math i = 0

    putarray 0 i 0
    putarray 2 i 0xcfd9c9d0
    putarray 1 i 0x3cdf9c62
    math i += 1

    putarray 0 i 0
    putarray 2 i 0xb95e9560
    putarray 1 i 0xfa9d3564
    math i += 1

    putarray 0 i 0
    putarray 2 i 0x28ae57a9
    putarray 1 i 0xf1bafd7c
    math i += 1

    putarray 0 i 0
    putarray 2 i 0x45c3652f
    putarray 1 i 0x9f3e61b3
    math i += 1

    putarray 0 i 0
    putarray 2 i 0x45213be9
    putarray 1 i 0x69c6ca9f
    math i += 1

    putarray 0 i 0
    putarray 2 i 0x13dbe30d
    putarray 1 i 0x80cfc16f
    math i += 1

    putarray 0 i 0
    putarray 2 i 0x4d310d89
    putarray 1 i 0xaa400e4a
    math i += 1

    putarray 0 i 0
    putarray 2 i 0x47615f32
    putarray 1 i 0xd8684b01
    math i += 1

    math KEY_DB_SIZE = i
endfunction

startfunction GET_KEY_DB
    math OK = 0
    log MEMORY_FILE3 0 0
    log MEMORY_FILE2 0 0
    putvarchr MEMORY_FILE2 0x20 0

    # if the decrypted KEY is the same of the one at offset 0x18, don't use file encryption
    putvarchr MEMORY_FILE3 0 KEY32 long
    putvarchr MEMORY_FILE3 4 KEY64 long
    calldll MEMORY_FILE4 "rfactor2_00476520_dll" stdcall "" MEMORY_FILE3 8 MEMORY_FILE2 0
    getvarchr TMP32_SIGN MEMORY_FILE2 0 long
    getvarchr TMP64_SIGN MEMORY_FILE2 4 long
    if TMP32_SIGN == KEY32_SIGN
    if TMP64_SIGN == KEY64_SIGN
        math OK = 1
    endif
    endif

    if OK == 0
        math i = -1
        do
            math TMP32 = KEY32
            math TMP64 = KEY64
        
            math i += 1
            if i > 4000 # the limit is 1024 (plus the pre-built array)
                get NAME filename
                print "Error: file encryption key not found for %NAME%, contact me"
                cleanexit
            endif
            if i == KEY_DB_SIZE
                math RFACTOR_RND_SEED = 0x9F731BC7
            endif
            if i >= KEY_DB_SIZE
                callfunction RFACTOR_RND 1
            else
                getarray TMP_KEY32 2 i
                getarray TMP_KEY64 1 i
            endif

            math TMP32 ^= TMP_KEY32
            putvarchr MEMORY_FILE3 0 TMP32 long
            math TMP64 ^= TMP_KEY64
            putvarchr MEMORY_FILE3 4 TMP64 long

            calldll MEMORY_FILE4 "rfactor2_00476520_dll" stdcall "" MEMORY_FILE3 8 MEMORY_FILE2 0

            getvarchr TMP32_SIGN MEMORY_FILE2 0 long
            getvarchr TMP64_SIGN MEMORY_FILE2 4 long
            if TMP32_SIGN == KEY32_SIGN
            if TMP64_SIGN == KEY64_SIGN
                math OK = 1
            endif
            endif

        while OK == 0

        math FILE_ENCRYPT = 1
        math FILE_KEY32 = TMP_KEY32
        math FILE_KEY64 = TMP_KEY64
    endif
endfunction

startfunction DO_RANDOM
    math RND = RFACTOR_RND_SEED
    math RND *= 0x343fd
    math RND += 0x269ec3
    math RFACTOR_RND_SEED = RND
    math RND u>> 0x10
    math RND & 0x7fff
endfunction

startfunction RFACTOR_RND
    # 16ED918 (converted from long to byte)
    set MEMORY_FILE5 binary "\xb8\xa8\x8b\x07\x8a\x0e\xf2\x11\x68\xfb\xbc\xdb\x12\xd0\xb6\xb3\x9f\x69\x55\x5f\xc7\xca\x61\xad\x3c\x56\xc1\xdf\x46\x13\x28\x1c\x4b\x20\x3b\x75\xac\xe7\x3e\x9a\xb1\x8d\xe1\x6e\x6f\x14\xc0\x88\x97\x95\x6b\xb0\xd7\x64\x17\x30\xa4\xce\x66\x9e\x70\x03\x1e\xec\xe9\xde\x5a\xb2\x90\xa2\xba\x4a\x2a\xf8\x6d\xe6\x23\x59\x7a\xee\xf6\xda\x3a\x60\xb5\xfe\x06\x2b\xea\xd4\xe3\x72\x62\x27\xa1\x4c\x0b\x3d\x8f\x34\xeb\x15\x18\x39\xc5\x22\x58\x94\xf5\x42\xa3\xc2\x25\x87\x81\x48\x93\x02\xd6\xc9\x71\x7d\x35\xbd\xd3\x09\x9d\x7f\x53\xcd\xae\x21\x4e\x77\xe8\x43\xd1\xb9\xff\x33\xbb\xf7\x8c\xb4\xbf\xd9\xab\x4f\x4d\xe0\x6a\xd5\xf3\xd8\xc6\x08\x83\x1d\xfa\x05\x41\xcb\xd2\xf9\xc3\x84\x65\x40\x49\x54\xcc\xef\x0f\xa6\xa9\xaf\x5c\x91\x1a\x36\xbe\x01\x2f\x16\x1f\xa5\xfd\x45\x96\x52\x79\xe5\x10\x1b\x67\x63\x24\x32\x80\x9c\x2e\x47\x57\x2d\x8e\x7e\xe4\x78\xa0\x99\xdc\xb7\xfc\x76\xf4\x19\x3f\xaa\x5d\x04\x26\x7c\xf0\xf1\x37\xa7\xed\x86\xdd\x98\xc4\x82\x89\x31\x5b\x74\x0c\x92\x0d\x6c\x38\xcf\x51\x2c\x7b\x44\x50\x0a\x9b\x5e\x00\x73\x29\x85\xc8\xe2"
    set MEMORY_FILE6 binary "\x36\x2a\xc5\x70\x1a\x1b\xa8\xd0\x36\x33\xb8\xce\x36\xc5\x9f\xdc\x2a\x54\x6f\x8a\xd9\x18\xc2\x30\x41\xde\xbf\x3e\x9d\x6a\x9d\xfa\x31\x4f\x7c\xf6\x56\xd6\x82\x22\xdc\xfa\x3d\x8f\xf7\xba\xc6\x69\x13\x03\x67\x93\x01\x23\xe7\x42\xa0\xaf\x6a\xa5\xff\xd3\xf1\xb8\x7a\x6d\x34\xe7\xaf\x38\x9f\x7a\x6b\x14\x00\xc8\x31\xdd\xda\x97\x3b\x19\xf5\x0f\x81\xe2\x65\x85\xe0\xc2\x3b\x79\x51\x3f\xd2\xe2\x04\x7e\x4c\x99\x6d\x15\x65\x04\xa6\x00\x7a\x4d\xa0\x09\x9e\xb1\x4f\x3f\x27\xa7\x9c\x4a\x1b\xa4\xe0\x44\x34\xe8\x0e\x43\xfa\x97\x55\xc9\x53\x69\x3e\x9f\x3c\x66\x45\xd8\x62\x15\x70\x1b\xce\xd7\xa7\x25\xa0\xc6\x73\x4f\x2d\x74\x05\x63\x31\x49\x41\x31\xdb\x58\x40\xaa\xcf\x80\xbc\xae\x35\x99\x8f\x3e\x72\xfd\xdc\xf8\x80\x3e\xa5\x76\x97\xb8\x19\x5f\xfc\xf7\x4a\x9f\x0b\xb3\x1f\xdb\xb7\x28\xa9\x70\x11\xbd\xc2\x06\xd2\xd8\x2c\x9c\x31\xbd\x88\xa2\xba\xf1\xa2\x8a\x15\x14\x6f\xe5\x82\xed\xaa\x6f\xaf\xb6\x4e\xb6\xdf\x3c\x5d\x8d\x18\xa4\x0e\x83\xce\x47\x7b\xc2\xea\xd4\xbb\x5e\x11\x4e\xf7\x43\xf1\x4c\xbd\x8c\xd6\xa6\x13\xb4\x2f\x34\x60\xcf\x31\x4e\xb7\xbf\x2e\x8e\x8e\xbc\x61\xe5\x3e\x27\xf2\x6c\x88\xb4\xaf\x70\x96\xa1\xf7\xc3\x1b\x4d\x95\x65\x1b\xab\x7c\x07\xbb\x1e\x92\x77\x1e\xfb\xab\x84\xa6\x06\xfa\x97\xc0\xce\xe8\xbd\x29\x6e\x72\x14\x91\xc5\x9c\x00\x28\x61\x9a\xb5\x02\x8e\xb8\x2e\xc0\x60\xfd\x7d\x1d\x4b\xef\xa1\xd3\x0a\x45\xa1\xf3\xc5\x0f\x35\xe9\x0b\x13\xb2\x1f\xcb\xd4\x71\xa1\x44\x67\x21\xa5\x63\x04\x5a\x63\x66\xef\x32\x35\x6c\x17\x2d\x09\x50\x0d\x53\x76\x0d\xd3\xe8\x92\x82\x14\xec\x08\x2c\xde\xb1\xb4\x12\x77\x2f\xa9\x53\xad\x75\x41\xd2\x2e\x97\xac\xf0\xcd\xd6\xc4\xe5\x18\xa2\x8d\x13\xc2\xd0\x19\xad\x88\xb9\x22\xed\xff\x8c\xbd\x98\x02\xee\x72\xbd\x09\xa4\x22\xf8\x4a\x6b\x12\x0b\x0e\xbd\xc9\x50\x76\x3d\x44\xea\x5d\x59\x46\x39\x94\x83\x27\x37\x85\x32\x73\xb4\x5f\x29\xd6\x38\xdd\xa8\x99\x75\xd4\xd8\x90\x30\x19\x5f\xbb\x13\xf2\x71\xb5\x6f\xfd\x6c\x57\x59\x28\x07\xf9\x7c\x4f\x51\x77\x2f\x00\xc7\xd8\x31\xee\x29\x93\x7a\xba\xaa\x8e\xdb\xee\xa4\xdc\xfc\xb1\x48\x47\xc1\xc5\xa6\x67\x73\xd1\xd8\x11\xdb\xd5\x98\xa7\x45\x24\xb7\x14\x86\xf1\xb8\x4a\x6b\x68\xd8"
    set MEMORY_FILE7 binary "\xd0\xcf\xdf\x38\x80\xe2\x80\xc1\x2d\x73\xf4\x8c\x05\x61\xcc\xf5\xf3\x4a\x76\xab\x28\x37\x62\x8f\x53\x3f\x84\x2d\xf9\x39\x74\x1b\x26\x5b\xb3\x61\x82\x8c\x83\x02\x5e\xb8\x70\x7d\x4e\xb2\x01\x13\x82\x7f\xa1\x4b\xa0\x3f\x45\x62\x30\x4f\x3c\xf2\x0d\x73\x5e\xe9\xca\x79\xd5\xe1\xd3\x21\xf6\xab\x1a\x93\x96\xbc\x37\x29\x69\x31\xad\x6f\xd2\xa8\x0c\x53\xfd\x9c\xf0\x8a\x9e\xea\x9e\x21\xef\x92\xb3\x41\x50\xff\x1a\x6d\x50\x31\x63\x3a\x7c\xfd\xea\x3b\x51\xb9\x82\x42\xda\xf8\xfa\x95\xc3\x20\xd1\xde\x00\x5f\xb1\xc1\xcd\x10\x07\x27\x97\xea\x43\x09\x16\x32\x0f\x34\xb2\x48\xf8\xb5\x1b\x1e\x07\x93\xdb\xe8\xa4\xc9\x56\xd6\x45\x60\x00\xc4\xe1\x4a\x79\x59\xd1\x4f\x49\xc7\xcc\x6a\xed\x52\x5f\xa9\x06\xce\x00\xcb\xe4\x8e\x5c\xe6\x8f\xc3\x8c\x5d\x6e\x4b\xd8\x98\xa8\x96\x15\x65\x35\x6a\xd9\x5a\x2f\xc7\x9c\x05\xe6\xad\xf7\x2f\x38\xdb\x61\x44\xfa\x9f\xd8\xd4\x9a\xf0\x70\x1d\xd4\x10\xba\x65\xc9\x50\x50\x79\xc3\x0f\x0a\x25\x11\x2d\x66\xf3\xfd\xcc\x92\x87\x68\xaa\x9d\x4a\x57\x27\x93\xcc\x5c\x65\x27\x78\x2d\x7d\x46\x17\x6a\xa5\x94\xe3\xa6\x96\x00\xc4\xf3\x0c\xe3\x00\x0a\x9d\xcd\x39\x53\x90\xbc\xfc\xc8\x79\xba\x4e\x7a\xf5\xd0\x18\x2b\xe2\xde\x41\x01\x43\xd1\x87\x9f\xca\xe4\xe9\xa2\x87\x14\xab\x88\xfb\x29\xc1\x47\x58\xa9\xc6\x0b\x4a\xec\xe2\xff\xba\x84\x44\x52\x7f\xdf\x08\x1b\x15\x72\x5b\x82\x2d\x6b\x15\xa2\x76\xc1\x4f\x6e\x25\x3a\x9c\x49\x71\x53\x89\x35\x67\xd8\x44\x3b\xbf\x91\x2a\x55\x0a\xd2\x81\x22\x8c\x6a\x85\xaa\xff\xa6\x69\x05\x55\x86\xcd\x9c\x8a\xde\x44\x14\xeb\x30\x7f\x45\x5e\xd7\x08\xda\x93\xfe\x7c\x62\x9c\xb4\x75\xd3\x6a\xa5\xcf\x5b\xe0\x64\x35\xab\x70\x89\x02\x17\xd8\xc4\x0f\x15\x64\x0f\x3d\xa4\xe8\x3d\x2f\x01\x4b\xfa\xba\xb0\xa0\x5c\xc9\x64\xfa\xde\xd2\x6f\xc1\x85\x22\x91\x4a\xfa\x1c\x32\x82\xe8\xf4\x02\x14\x84\xe0\xfc\xd5\x62\x04\x2c\xff\xc7\xe0\x1e\x21\x18\x46\xc1\x49\xdd\x91\x88\x54\x1c\xcb\x79\x58\x9b\x5a\xd7\xe1\xd1\x21\x5a\x20\x17\x23\x8c\x92\x63\x0d\x8d\x74\xf9\x5b\x73\x07\x21\x71\xcb\x1c\x81\xe4\x04\x8d\x99\xcc\xd7\xb8\x92\xa3\x37\x56\x22\x8f\xe5\x03\x9b\x7a\xf7\x4f\xc7\xd0\xb6\xc1\x4a\x0e\x66\xa5\xad\x16\x08\xdf\x9e\xb5\x20\xc5"
    set MEMORY_FILE8 binary "\x5a\x69\xf2\x4c\xd3\x01\x55\xfa\xd2\x68\x63\x45\x61\x85\x19\x5b\x90\x8c\x98\xd0\x21\xf7\x2e\x4f\x80\xc8\xa2\xe8\x4d\x41\x9b\x7f\xd8\x98\x61\x47\x43\x94\x80\x5a\x02\x88\x0a\x9c\x97\xb8\x2d\x72\x71\xad\x9d\x19\x1f\x37\xd0\xe7\xcb\x76\xbe\xee\x35\xbf\x32\x9f\xb8\x91\x58\x46\xa3\x03\x2e\xbe\x5f\x36\x7f\xc2\x9f\x3a\xa6\xab\xb3\x99\x14\x92\x68\xbf\x2c\x27\xee\x32\x3f\x36\xf8\xbb\x06\xa5\xdf\x08\x7e\xa2\x6f\x30\x50\xc1\xac\xf8\xdc\x06\xb3\x4e\xa7\xd2\x6b\x25\xf5\x68\xb1\x11\x99\x39\xfa\xf5\x40\xa1\x43\x06\x9d\x5a\xdc\x18\xc2\x83\x6e\x2f\xf6\xab\xcf\xb9\xcf\x19\xd9\xcf\x6b\x45\x64\x55\x11\xd8\xa7\x46\xcb\x18\x7b\xbd\x58\x80\x26\xa0\xeb\x84\xe2\x78\xce\x70\x34\xeb\x24\xe3\x72\x0d\xca\x99\x93\xca\x01\x7c\x29\xc0\x3b\xff\x32\x59\x7e\xcb\xfc\xec\x0f\x57\xb4\xf8\x7c\x67\x33\x02\xfa\x61\x2a\x9c\x0c\xf0\x5e\xb9\xf3\x0d\xdf\x78\x64\x3a\x38\xd6\xdb\x13\x14\x9b\xae\x48\x88\x5d\xb1\x43\xb4\xf1\xd0\xa2\x95\x23\x82\x1a\x4b\x18\xa4\x8e\x4c\x6a\x32\x76\x82\x92\x15\xfe\xe2\x94\x0c\x9b\xfd\x13\xb1\x3e\x5e\xb3\x32\x79\xc2\xb0\xbf\x98\x6b\x14\x5f\xf9\x7c\xa4\x40\xb8\x5c\xd9\xe9\xc7\x80\x2b\x31\x4d\xf0\x4a\x2c\x90\xeb\xe0\xd6\x50\x3f\xe9\x75\x1b\xce\xff\xc1\xe6\x53\x36\x21\x45\x9c\xf9\xed\xe6\x33\x0a\x88\x92\xdb\x1b\x6a\x6a\xf0\x43\x2c\x00\x09\x57\xdc\xf0\xd2\x86\xd0\x36\xef\x35\xe3\xb4\xff\xac\x54\x5f\x0a\xe3\x67\xd5\x13\x07\x14\xe7\x77\xda\x89\x58\x46\x71\xcd\x7c\xc0\xc0\xda\x98\xc9\xbf\x25\x38\xd0\x38\xf7\x1c\x31\x48\x7b\xdd\x94\x8a\xae\x28\xd2\xa8\x8f\x92\xb4\xf7\x95\x68\xaf\xd9\x20\xc8\xf6\xae\x78\xd0\x33\x0f\xb3\x0d\x2d\x70\x18\xab\x87\xb3\x35\x6a\x10\x5b\x40\xa9\x2e\x2c\x5c\x80\x0f\x3b\xe4\x4d\x56\x99\x7f\xaf\x03\x5c\x9b\x78\xb1\xdb\x3f\x5f\x92\x16\x7f\xcd\x57\x4f\x47\x97\x7c\x07\x65\x1a\x91\xba\x1b\xe8\x31\xb8\xa6\xac\xd1\x4d\x10\x56\x35\x39\xec\x99\x81\xc4\x59\x3a\x9b\x7d\x2e\xd7\xce\xb0\x46\xa0\x0f\x93\x7a\x05\xda\x93\x70\xce\x7a\x99\x43\x00\x80\x59\xe6\xb4\x01\xac\x0f\xc1\x87\xb2\x65\xf3\xd4\x84\x59\xb9\x56\x9f\xed\x3b\x17\x28\x93\xca\x05\x96\x3b\x80\x31\x70\x5c\x29\xdd\xf8\x96\xba\xba\x9b\xd1\x4e\xcc\xb0\x0e\x73\x07\xb2\xc1\xe0"
    set MEMORY_FILE9 binary "\x71\x0d\xbc\x03\xd8\xd8\xef\x44\xe8\xd4\x50\x49\x5e\xb4\xa5\x89\xbd\x1b\xb2\x97\x51\x29\xc5\xf4\x62\x1b\x95\x0b\x64\x8d\x9b\x8b\xcf\xc2\x88\xdb\xda\xc8\x8f\x53\x74\xdb\x3b\x14\x7d\xcd\x86\x3c\x1e\xdc\xca\x96\x08\xaa\x51\xde\xff\xba\x83\x66\xb0\xa5\xde\x91\x7d\x22\x0b\x25\x03\xec\x48\xb8\xa7\xd5\x2e\xba\x68\x29\xa7\x40\xe5\xa2\xe9\xf4\xf0\x54\x47\x01\xdc\x18\x63\xfc\x97\xba\xcb\xd0\x62\xea\x51\x59\x65\x00\x14\x74\x4b\x87\x60\xf3\xeb\x24\xcc\x6b\x87\x62\xeb\x3b\x13\x7b\x92\x05\x4a\xe1\x1e\xc4\x95\xca\x50\xbf\x25\xf7\x17\x28\x39\x5e\x09\x5c\x3a\xcf\x54\x59\x48\xd5\x5b\xc5\xef\xa4\x11\x4b\xd0\xc9\x85\x6d\x16\xfb\x82\x42\x6f\x31\x8a\x62\xea\xff\x20\xbe\x43\x09\x9c\x61\xec\x52\x78\xb5\x72\x7b\xf0\xd5\x27\x18\x49\xa3\xf6\x1c\x42\x8f\x79\xc2\xe8\x24\x8a\x52\x9f\xea\xbd\xea\x22\x86\x47\x23\x1c\xfa\x4c\xf2\x99\xcb\xd6\xae\x7e\xbd\x4f\xc4\x60\x95\x06\xc8\x64\xec\x84\xe9\xfe\xf3\x17\xb4\x0f\x23\x19\xce\x0f\x23\x3d\x4f\x63\x04\x68\xda\xce\xb4\xb4\x77\xc8\x90\x2f\xc7\x20\xcf\xc5\x69\xab\x76\x48\x87\x3f\x89\xf7\xdf\x08\x4f\x71\x2d\xa8\xdb\xce\xb4\x87\x62\x1e\xbe\xa7\xb1\x82\x62\xd5\x88\xb8\xdc\x65\x95\xb2\xce\x0d\x7d\x4f\xb1\xbc\xbe\xb9\x9e\xbb\x01\xa5\x63\x6f\x2a\x19\x64\xa8\x79\x24\x18\xa9\x57\x53\x49\x6d\x45\x01\x83\x63\x3a\xb1\x4d\x1a\x24\x39\x59\x54\xb9\xee\x94\x8d\x7c\x20\x18\x62\xf3\x4f\xc1\xab\x1c\xc2\xaf\xb4\x5e\xa0\xc9\xaa\x06\x33\x0f\x3b\xea\xda\x96\x89\x62\x57\x26\x4c\x0e\x40\xc0\xd6\x78\x89\x0d\x51\x69\xeb\x11\x08\xdc\x2a\x0e\xf7\x2b\xfd\x1f\x42\xb1\xd4\xf7\x12\xdb\x3c\x89\x94\x8d\x80\x8d\xf3\xa3\x05\xbc\xd8\x48\xce\xb4\xc2\x00\xe2\x86\xbd\x7e\x2d\xb7\x16\xa4\x89\x3b\xf4\x1c\x0c\x45\x89\x54\x0d\xe3\xb9\x59\xef\xd2\x3e\xe9\xa3\x89\xb2\x17\xbf\x39\x5b\x1d\x03\x90\x0a\x23\x0d\xe5\x95\x6c\xed\xf2\x0a\x91\xae\x28\xa5\xf6\xeb\x3d\x87\x22\xce\x27\x49\x57\xc3\x10\xa9\x79\xb4\x08\x12\x12\x31\xf6\x33\x9a\x9f\x3d\x8b\x1a\xb2\xde\xdf\x3c\xdc\xf0\x69\x25\x64\x1b\xae\xa9\xcf\x30\xe2\x24\x25\x65\xd7\xdc\x20\x11\x79\x24\xb2\x86\xb8\x44\xbe\x98\xd3\x6f\x32\x5f\xab\x80\xed\xf4\x3a\x66\x4a\x6c\xe9\x3b\xe3\x04\x68\xd5\xc0\xc2\xe2\xb4"

    callfunction DO_RANDOM 1
    math RND1 = RND
    math RND1 u>> 8
    math RND1 & 0xff
    math RND2 = RND
    math RND2 & 0xff
    
    callfunction DO_RANDOM 1
    math RND3 = RND
    math RND3 u>> 8
    math RND3 & 0xff
    math RND4 = RND
    math RND4 & 0xff

    #print "RND %RND1|x% %RND2|x% %RND3|x% %RND4|x%"
    
    if RND4 & 1
        getvarchr EAX MEMORY_FILE5 RND2 byte
        getvarchr ECX MEMORY_FILE5 RND3 byte
        math EAX *= 2
        getvarchr ESI MEMORY_FILE6 EAX short
        getvarchr EAX MEMORY_FILE5 RND1 byte
        math EAX *= 2
        getvarchr EAX MEMORY_FILE7 EAX short
        xmath ESI "(ESI << 0x10) | EAX"
        getvarchr EAX MEMORY_FILE5 RND4 byte
    else
        getvarchr EAX MEMORY_FILE5 RND4 byte
        math EAX *= 2
        getvarchr ESI MEMORY_FILE6 EAX short
        getvarchr EAX MEMORY_FILE5 RND2 byte
        math EAX *= 2
        getvarchr EAX MEMORY_FILE7 EAX short
        xmath ESI "(ESI << 0x10) | EAX"
        getvarchr EAX MEMORY_FILE5 RND3 byte
        getvarchr ECX MEMORY_FILE5 RND1 byte
    endif
    math EAX *= 2
    getvarchr EAX MEMORY_FILE8 EAX short
    math ECX *= 2
    getvarchr ECX MEMORY_FILE9 ECX short
    xmath EAX "(EAX << 0x10) | ECX"

    math TMP_KEY64 = ESI
    math TMP_KEY32 = EAX
endfunction
