Need help with code

Doubts, help and support about QuickBMS and other game research tools
h3x3r
Posts: 165
Joined: Wed Jun 01, 2016 5:53 pm

Need help with code

Post by h3x3r »

Hi there. I need your help guys. I mean you luigi.
I have this piece of code to parse file but i need to convert MATNAME long values to plain text and save as *.txt.
Output format should look like

Code: Select all

0x13F610C6
0x0ABA20A8
and so on depends on MATCOUNT

and code

Code: Select all

   if file_type == 25
      get SIZE long
      savepos OFFSET
      get MATCOUNT long
      math MATCOUNT - 2
      endian big
      get MDLHDRNAME long
         for i = 0 < MATCOUNT
            get MATNAME long
         next i
      endian little
      string NAME p "%s%s/%s/%d/0x%08x.mdlhdr_hdr" FNAME _unpacked Data file_type file_ID
      log NAME OFFSET SIZE

I tried slog but unsuccessfully. Maybe prinf function? Thanks in advance.
spiritovod
Posts: 719
Joined: Sat Sep 28, 2019 7:00 pm

Re: Need help with code

Post by spiritovod »

I believe it's not an extremely casual task in quickbms, but you can use some workaround like the following one:

Code: Select all

set TAB binary "\x0A"
set TMP string "0x"
log MEMORY_FILE2 0 0
math MEM = -2

for i = 0 < MATCOUNT
   getdstring MATNAME 4
   #string MATNAME r MATNAME # uncomment to swap endianness
   string MATNAME 0b MATNAME
   string BASE p "%s%s" TMP MATNAME
   putdstring BASE 10 MEM
   putct TAB string -1 MEM
next i

get SIZE asize MEM
log "output.txt" 0 SIZE MEM

You can set your own delimiter and prefix, and also change value endianness this way.
h3x3r
Posts: 165
Joined: Wed Jun 01, 2016 5:53 pm

Re: Need help with code

Post by h3x3r »

Thanks spirit it works like charm. But... it output only one file.
Here is whole code.

Code: Select all

get FILES long
getdstring DUMMY 0x78

savepos TMP
math BASE_OFF = FILES
math BASE_OFF *= 10
math BASE_OFF += TMP
math BASE_OFF x= 8

for i = 0 < FILES

    get OFFSET long
   endian big
    get file_ID long
   endian little   
    get file_type byte
    get bComplex byte      
   string NAME p "%s%s/%s/%d/0x%08x.dat" FNAME _unpacked Data file_type file_ID
    math OFFSET *= 8
    math OFFSET += BASE_OFF
    savepos TMP
   goto OFFSET

   if file_type == 25
      get SIZE long
      savepos OFFSET
      get MATCOUNT long
      math MATCOUNT - 2
      set TAB binary "\x0A"
      set TMP string "0x"
      log MEMORY_FILE2 0 0
      math MEM = -2
      endian big
      get MDLHDRNAME long
         for i = 0 < MATCOUNT
            getdstring MATNAME 4
            #string MATNAME r MATNAME # uncomment to swap endianness
            string MATNAME 0b MATNAME
            string BASE p "%s%s" TMP MATNAME
            putdstring BASE 10 MEM
            putct TAB string -1 MEM
         next i
      endian little
      get SIZE asize MEM
      string NAME p "%s%s/%s/%d/0x%08x.txt" FNAME _unpacked Data file_type file_ID
      log NAME 0 SIZE MEM
   endif
    goto TMP
next i   


EDiT: Fixed. It was caused by set TMP string "0x" and string BASE p "%s%s" TMP MATNAME. Changed TMP to TMP0.
One more time thank you spirit.