namecrc

Doubts, help and support about QuickBMS and other game research tools
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

namecrc

Post by chrrox »

How do I use the namecrc function
I stored the file names in a memory_file
ten i logged that file to file.lst
then i used
namecrc NAME HASH file.lst 32
but my file names are not working.
am i using this correct?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: namecrc

Post by aluigi »

Try replacing the 0x00 byte with a line-feed.
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

Re: namecrc

Post by chrrox »

I tried this i check logging names to file and it put the line feed in it but i get no names.
how would i check the crc quickbms calculates of a string

Code: Select all

# Soul Sacrifice Delta (Vita)
# script for QuickBMS http://quickbms.aluigi.org
#made by chrrox
get name basename
endian big
Open FDDE PK 0
Open FDDE pfs 1
Open FDDE pkh 2
goto 8 1
get FOLDERS long 1
get TFILES long 1

for i = 0 < FOLDERS
   get FOLDERID long 1
   get FOLDERPARENT long 1
   get UNK long 1
   get SUBFLDR long 1
   get FILESTART long 1
   get FOLDERFILES long 1
   #print "%FOLDERID% %FOLDERPARENT% %UNK% %SUBFLDR% %FILESTART% %FOLDERFILES%"
   PutArray 3 i FOLDERPARENT
   PutArray 4 i FILESTART
   PutArray 5 i FOLDERFILES
next i

for i = 0 < FOLDERS
   get FOLDERNAMEOFF long 1
   PutArray 0 i FOLDERNAMEOFF
next i

for i = 0 < TFILES
   get FILENAMEOFF long 1
   PutArray 1 i FILENAMEOFF
next i

savepos NAMEBASE 1

for i = 0 < FOLDERS
   GetArray FOLDERNAMEOFF 0 i
   math FOLDERNAMEOFF += NAMEBASE
   goto FOLDERNAMEOFF 1
   get FOLDERNAME string 1
   #print "%FOLDERNAME%"
   PutArray 2 i FOLDERNAME
next i

for i = 0 < TFILES
   GetArray FILENAMEOFF 1 i
   math FILENAMEOFF += NAMEBASE
   goto FILENAMEOFF 1
   get FILENAME string 1
   #print "%FILENAME%"
   PutArray 7 i FILENAME
next i

set MEMORY_FILE binary ""

for i = 0 < FOLDERS
   GetArray FOLDERNAME 2 i
   GetArray FOLDERPARENT 3 i
   GetArray FILESTART 4 i
   GetArray FOLDERFILES 5 i
   math FOLDERFILES += FILESTART
   set FOLDERBASE ""
   #print "%FOLDERPARENT% %FILESTART% %FOLDERFILES%"
   if FOLDERPARENT >= 0
   GetArray FOLDERBASE 6 FOLDERPARENT
   string FOLDERBASE += /
   #print "%FOLDERNAME%"
   endif
   string FOLDERBASE += FOLDERNAME
   PutArray 6 i FOLDERBASE
   #print "%FOLDERBASE%"
   if FOLDERFILES > 0
      for a = FILESTART < FOLDERFILES
         set NAME FOLDERBASE
         GetArray FILE 7 a
         string NAME += /
         string NAME += FILE
         #print "%NAME%"
         PutArray 8 a NAME
         Put NAME LINE MEMORY_FILE
      next a
   endif
next i

get FILES long 2
for i = 0 < FILES
   GetArray NAME 8 i
   get HASH long 2
   get OFFSET long 2
   get SIZE long 2
   get ZSIZE long 2
   if ZSIZE == 0
      log NAME OFFSET SIZE
   else
      clog NAME OFFSET ZSIZE SIZE
   endif
next i


so i am doin gthis
Put NAME LINE MEMORY_FILE
can i run a crc check on the name variable?

it needs to match this
Hash: CC2F8C6D
Offset: 1673354624
Size: 2998
ZSize: 1161
Index in PKH table: 40398
Path: resource/windows/camera.ico
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

Re: namecrc

Post by chrrox »

ok I see its using the bzip2 variant of crc32

http://www.sunshine2k.de/coding/javascr ... rc_js.html

how do i do this in quickbms.

i tried
# calculate checksum
encryption crc "" 32
string NAME E= NAME
encryption "" ""
print "CRC %QUICKBMS_CRC|x%"
but its different result.

example
resource/boot/magic_space_param_ply.csv

should give

0xA880FC6A

I found this online

Code: Select all

pwnlib.util.crc.crc_32_bzip2(data) → int[source]
Calculates the crc_32_bzip2 checksum.

This is simply the generic_crc() with these frozen arguments:

polynom = 0x4c11db7
width = 32
init = 0xffffffff
refin = False
refout = False
xorout = 0xffffffff
See also: http://reveng.sourceforge.net/crc-catalogue/all.htm#crc.cat.crc-32-bzip2

Parameters:   data (bytes, str) – The data to checksum.
Example

>>> print(crc_32_bzip2('123456789'))
4236843288


I used the scanner but i cant get it to work on the string variable only when i save it as a file manually with no null at the string end

0xe7f08054 0x5480f0e7 - CONFIG 0x04c11db7 32 -1 -1 1 0 0
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: namecrc

Post by aluigi »

It seems a bug in quickbms because the following script should return the correct filename but it returns an empty string:

Code: Select all

math NAME_CRC = 0xA880FC6A
NameCRC NAME NAME_CRC "file.lst" 32 0x04c11db7 "32 -1 -1 1 0 0"
print "%NAME%"

I'm checking what's wrong and I will update the program.
It's very strange because it has ever worked perfectly.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: namecrc

Post by aluigi »

There is something in the calculation of the crc that is different.
Those parameters return the correct CRC when used with the crc scan and calculation but they give 0xd2691b04, 0x05e155c7 and 0x34a1ead6 in namecrc.
Still investigating...
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: namecrc

Post by aluigi »

Problem found.
key and ivec are parsed as strings from the bms script and handled as variables in the command... the result is that it can't work (NULL and NULL).
I'm going to fix it as soon as possible.
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

Re: namecrc

Post by chrrox »

I tried creating the file and could not get it working
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: namecrc

Post by aluigi »

Using the pre-built crc is a good idea while waiting the next 0.7.5, well done.

I tried the script I posted before with this new file and it works correctly:

Code: Select all

NameCRC NAME NAME_CRC "file.txt" 32
What's the problem you are experiencing?
chrrox
Posts: 388
Joined: Thu Aug 07, 2014 10:28 pm

Re: namecrc

Post by chrrox »

I need to convert the strings to lowercase.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: namecrc

Post by aluigi »

String NAME l NAME