Making a simple repack script

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Making a simple repack script

Post by sigroon365 »

I know quickbms doesn't support repacking but I want to learn how to make a repack script.
(Use Open FDDE or.. well, I'm not sure.) Is there a tutorial for it?

For example, http://aluigi.altervista.org/papers/bms/others/gunpoint.bms

Code: Select all

# Gunpoint
# script for QuickBMS http://quickbms.aluigi.org

get BASE_OFF long
get FILES long
for i = 0 < FILES
    get NAMESZ long
    getdstring NAME NAMESZ
    get SIZE long
    get OFFSET long
    math OFFSET + BASE_OFF
    log NAME OFFSET SIZE
next i
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Making a simple repack script

Post by aluigi »

There are tons of ways for creating a rebuilder script with quickbms, just in case the reimport feature is not enough.

The following is the rebuilding script for Gunpoint:

Code: Select all

# 1) script.bms
# 2) the input file is ignored, select the same script
# 3) the output folder is the folder containing the files to pack

set OUTPUT_ARCHIVE string "dump.pak"

# init the buffers
log MEMORY_FILE  0 0
log MEMORY_FILE2 0 0

# placeholders
put 0 long MEMORY_FILE  # BASE_OFF
put 0 long MEMORY_FILE  # FILES

for FILES = 0

    # copy&paste code
    scanDir "." NAME SIZE       # get the file from the current folder
    if NAME == ""               # no other files are available so append index
        break
    endif
    open "." NAME
    string NAME << 2            # remove ".\"
    if NAME != OUTPUT_ARCHIVE   # in case the archive already exists
        # end of copy&paste code

        # add information to the index table
        string NAME R \ /
        strlen NAMESZ NAME
        put NAMESZ long MEMORY_FILE
        putdstring NAME NAMESZ MEMORY_FILE
        put SIZE long MEMORY_FILE
        get OFFSET asize MEMORY_FILE2
        put OFFSET long MEMORY_FILE

        # add the file to the archive
        append
        log MEMORY_FILE2 0 SIZE
        append
        math FILES + 1
    endif

next

get BASE_OFF asize MEMORY_FILE
putvarchr MEMORY_FILE 0 BASE_OFF long   # BASE_OFF
putvarchr MEMORY_FILE 4 FILES    long   # FILES

get SIZE asize MEMORY_FILE2
append
log MEMORY_FILE 0 SIZE MEMORY_FILE2
append

get SIZE asize MEMORY_FILE
log OUTPUT_ARCHIVE 0 SIZE MEMORY_FILE


I opted for the solution of using the output folder as also input folder where retrieving the files to add.
The input file is useless so you can just select the same script, example:
quickbms script.bms script.bms input_output_folder

If you want another example of rebulder that uses different methods, take a look at the one for Beats of Rage:
http://aluigi.org/papers/bms/bor_rebuilder.bms
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Making a simple repack script

Post by sigroon365 »

aluigi wrote:There are tons of ways for creating a rebuilder script with quickbms, just in case the reimport feature is not enough.

I opted for the solution of using the output folder as also input folder where retrieving the files to add.
The input file is useless so you can just select the same script, example:
quickbms script.bms script.bms input_output_folder

If you want another example of rebulder that uses different methods, take a look at the one for Beats of Rage:
http://aluigi.org/papers/bms/bor_rebuilder.bms


Thank you! Great works! :P I have a question though. Would it be possible to write /(2F) instead of \(5C)?
For example, the original file name is 'GL/Assets/GL/splash.png.phyre', not 'GL\Assets\GL\splash.png.phyre'.
I found all of the data files was written in this format.
It doesn't matter when unpacking or repacking but it causes error when the game read the file.

Hmm.. For example, another game's file path is also written in this case; 'cache/itf_cooked/pc32/enginedata/textures/'.
When I change all of \(5C) to /(2F) then the game works well, but it is hard to edit manually all of \(5C) to /(2F).
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Making a simple repack script

Post by aluigi »

Sure, put the following before "strlen NAMESZ NAME":
string NAME R \ /

Just a quick note about the '\' character, it's a special char so in this case I preferred to not delimit it by quotes.
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Making a simple repack script

Post by sigroon365 »

aluigi wrote:Sure, put the following before "strlen NAMESZ NAME":
string NAME R \ /

Just a quick note about the '\' character, it's a special char so in this case I preferred to not delimit it by quotes.


Thank you! :P