ZenHAX

Free Game Research Forum | Official QuickBMS support | twitter @zenhax | SSL HTTPS://zenhax.com
It is currently Sun Nov 28, 2021 5:56 pm

All times are UTC




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Apr 12, 2021 11:12 am 
User avatar

Joined: Wed Nov 18, 2020 5:54 pm
Posts: 18
I have an archive where data is stored like nodes, for each compressed file in this archive, there is a node-header, saying what kind of data it is. I want to log these compressed files' filename depending on the node type. So a file with the type of "TEX0", would have the extension ".gtx" and so on.

Here's the script I made for the archive.
Code:
idstring "ANP 151 "
endian big
get FILES long
get NAMESZ long

for i = 0 < FILES
   getdstring NODE 4
   goto 12 SEEK_CUR
   
   # this is where you do the node name parsing
   
   getdstring NAME NAMESZ
   get OFFSET longlong
   get SIZE longlong
   log NAME OFFSET SIZE
next i


Heres the archive too.
I don't know why I can't attach an archive, but I renamed it from ".anp" to ".txt", so I could upload it.


Attachments:
simple.txt [300 Bytes]
Downloaded 75 times

_________________
-Garo
Top
   
PostPosted: Mon Apr 12, 2021 10:30 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 12568
Unfortunately there is no "switch/case"-like command in quickbms therefore the long sequence of "if/elif/else/endif" is the only option.

There are alternatives like storing the magic value and the relative in two arrays... but the script will look quite messy.

In my opinion the bestt alternative is storing the long list of "magic:extension;" in a MEMORY_FILE and searching them:
Code:
set MEMORY_FILE string "TEX0:gxt;TEXT:txt;BLAH:blah;"

# read the magic
getdstring MAGIC 4

# search the magic
string MAGIC + ":"
goto 0 MEMORY_FILE
findloc POS binary MAGIC MEMORY_FILE ""

# set the extension
if POS == ""
    set EXT string "dat"
else
    math POS + 5
    goto POS MEMORY_FILE
    getct EXT string ';' MEMORY_FILE
endif

print "Extension: %EXT%"


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited