Breaking Eggs And Making Omelettes

Topics On Multimedia Technology and Reverse Engineering


Archives:

Parsing GRAF Scripts

December 30th, 2005 by Multimedia Mike

I missed out on any kind of compiler theory course during my time in academia. Add that to the list of topics I would like to study and comprehend someday (along with 3D graphics and artificial intelligence).

The MultiEx Commander program uses a simple, custom scripting language to interpret game resource archive formats (a.k.a. GRAFs). Why do I care? Because these GRAF files often carry lots of FMV files that I want to separate and study invidually. This is a script that takes apart the BIFF (.bif) GRAF files from Baldur’s Gate:

IDString 0 BIFFV1 ;
Get DUMMYL Int 0 ;
SavePos FILESTART 0 ;
Get FILECNTL Long 0 ;
Math FILESTART += 16 ;
Do ;
GoTo FILESTART 0 ;
Get FILEOFF Long 0 ;
Get FILESIZE Long 0 ;
Math FILESTART += 16 ;
Log FILENAME FILEOFF FILESIZE 0 0 ;
Math EXTRCNT += 1 ;
While EXTRCNT <> FILECNTL ;

That script was taken from the XentaxWiki entry for BIF. Plenty more sample scripts are available on that Wiki.

Who can tell me the best approach to writing a program that can interpret scripts like the one shown above? Something tells me that full-fledged compiler theory is overkill for this type of application. It looks like the language was designed to be parsed in a fairly braindead virtual machine. But that’s just my best, uneducated guess.

Update: I am working on a BMS language spec in the XentaxWiki.

Posted in General | 4 Comments »

4 Responses

  1. john_doe Says:

    This looks fairly simple and you’re right, you can do it with a simple line-by-line parser. You basically tokenize a line and the first token tells you what kind of data/arguments follow on that line.
    I’d probably “compile” the script and store it in some kind of list and then run it with a very simple VM. I haven’t checked yet, but if there’s a manual to the scripting language it should be rather easy to implement a script interpreter for it.

  2. Multimedia Mike Says:

    I don’t believe there is a manual for the language. I have searched high and low. I also asked the creators about this last June and they said indicated that it would be a good idea to make a manual.

    I am going onto the the Xentax GRAF Wiki right now to create what language description I can figure out.

  3. Multimedia Mike Says:

    One thing I would like to do is make a BMS script (that’s apparently what the scripts are called) interpreter for the FUSE project (Filesystem in Userspace):

    http://fuse.sourceforge.net/

    Then, somehow, be able to mount resource files as read-only filesystems in Linux (without requiring root privileges) and browse/extract the contents.