How to add extra data to the end of the file? [solved]

Doubts, help and support about QuickBMS and other game research tools
Shiroi Bara
Posts: 2
Joined: Sat Mar 05, 2016 1:16 pm

How to add extra data to the end of the file? [solved]

Post by Shiroi Bara »

I have a file "file.fle". It's size 40 bytes. I need add 5 bytes (01 fe 48 9a 53) to its end and keep 40 original bytes at the beginning. New size of "file.fle" should be 45 bytes. I tried to use MEMORY_FILE, PutVarChr, append commands but i'm stuck. How to write right bms script for that?
Last edited by Shiroi Bara on Sat Mar 05, 2016 3:53 pm, edited 1 time in total.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: How to add extra data to the end of the file?

Post by aluigi »

A solution can be the following:

Code: Select all

set NAME string "new_file.fle"
set MEMORY_FILE binary "\x01\xfe\x48\x9a\x53"
get SIZE asize
log NAME 0 SIZE
append
log NAME 0 5 MEMORY_FILE
Shiroi Bara
Posts: 2
Joined: Sat Mar 05, 2016 1:16 pm

Re: How to add extra data to the end of the file?

Post by Shiroi Bara »

Thank you very much for quick response! I just replaced first string in you code on (i'm using one script to add same data for different files):

Code: Select all

Get NAME filename

and it works perfect.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: How to add extra data to the end of the file? [solved]

Post by aluigi »

Yeah good.
Usually I prefer to create a new file, for example with some instructions like the following:

Code: Select all

get NAME basename
get EXT extension
string NAME + "_new."
string NAME + EXT
It may be a good suggestion for the future.