# Ai Sp@ce (script 0.1.2, final update 2011-05-24)
# script for QuickBMS http://aluigi.org/papers.htm#quickbms

quickbmsver 0.4.5
getdstring SIGN 4
if SIGN != "FPMF"
    print "you must use this script only with the files having the HED extension (FPMF archives) because QuickBMS will extract all the files inside the 0000.dat files automatically!"
    cleanexit
endif
get DUMMY short
get DUMMY short
get DATA_SIZE long
get DUMMY long

savepos OFFSET
get DUMMY byte
get ZERO short
if ZERO == 0x16f6
	encryption rot "\x0B\xF6\x16\xB7\x6D\x61\x21\x40\x75\x76\x15\x27\x88\xF1\x59\xAB\x88\xE7\xF1\xDA\x0F\x8B\x50\x6A\xB1\xBD\x24\xB0\x73\xC6\x04\xFC\x43\x09\xB3\xCD\xEB\xC7\xB1\x66\x96\x8A\xC0\x13\xC8\xA0\x56\xD0\x65\x55\x4F\x0A\xB2\x69\x9C\x97\x31\x06\x12\x8A\x0F\xBF\x0F\x40" "" 1
elif ZERO == 0x84d4
  encryption rot "\x5f\xd4\x84\xe0\xc1\x5c\x0c\x3d\xed\x9b\xf6\x08\x79\x36\x01\x3d\x34\x40\x78\x3a\xce\xb1\x00\xa8\xe2\x08\x79\xb8\x75\x8b\x10\x18\x0e\xa0\xd9\xd5\x4d\x8f\x60\x58\xd1\xae\x9a\x34\xef\xd6\xa0\xe3\xe6\x15\x04\x7c\xa5\xae\xce\x60\xd4\x4e\xff\x1d\x3c\x56\x3c\xfa" "" 1
elif ZERO == 0x9495
	encryption rot "\x77\x95\x94\xcc\xb1\x18\x42\x19\x0c\xc2\x73\x3a\xca\x0b\x03\x68\x53\xa5\x89\xd3\x1b\x25\x01\x41\x4e\xfb\x83\x3d\xfc\xbf\x65\x3c\xe6\x3b\xce\xac\x30\x38\x1e\xa2\x57\x67\xdc\x02\x62\xc6\x5e\x0f\xbd\x5a\x94\x2d\xf4\xdd\x08\x95\x87\x49\x38\x8c\x86\xcd\xa0\x6a" "" 1
else
    print "unknown key (%ZERO%), contact me"
    cleanexit
endif
log MEMORY_FILE OFFSET DATA_SIZE
encryption "" ""

get DUMMY long MEMORY_FILE
get DUMMY long MEMORY_FILE
get NAMESZ byte MEMORY_FILE
math NAMESZ *= 2
getdstring NAME NAMESZ MEMORY_FILE
set BASE_NAME unicode NAME
get DUMMY long MEMORY_FILE
get DUMMY long MEMORY_FILE
get DUMMY long MEMORY_FILE
get DUMMY long MEMORY_FILE
get KEY_SIZE long MEMORY_FILE
getdstring KEY KEY_SIZE MEMORY_FILE
get DUMMY long MEMORY_FILE
get DUMMY long MEMORY_FILE
get FILES long MEMORY_FILE

math PREV_PACKNUM = -1
for i = 0 < FILES
    get FOLDERSZ byte MEMORY_FILE
    math FOLDERSZ *= 2
    getdstring FOLDER FOLDERSZ MEMORY_FILE
    set FOLDER unicode FOLDER

    get NAMESZ byte MEMORY_FILE
    math NAMESZ *= 2
    getdstring NAME NAMESZ MEMORY_FILE
    set NAME unicode NAME

    get PACKNUM long MEMORY_FILE
    get OFFSET long MEMORY_FILE
    get SIZE long MEMORY_FILE
    get CRC long MEMORY_FILE
    get ZERO long MEMORY_FILE

    if PACKNUM != PREV_PACKNUM
        string TMP printf BASE_NAME PACKNUM
        open FDSE TMP 1
        math PREV_PACKNUM = PACKNUM
    endif

    set FULLNAME string FOLDER
    string FULLNAME += NAME
    encryption rot KEY "" 1 KEY_SIZE
    log FULLNAME OFFSET SIZE 1
    encryption "" ""
next i