ZenHAX

Free Game Research Forum | Official QuickBMS support | twitter @zenhax | SSL HTTPS://zenhax.com
It is currently Thu Oct 19, 2017 12:42 pm

All times are UTC




Post new topic  Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Sat Jun 11, 2016 12:42 am 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
Hi, ive got a file that contains a lot of files inside, generally files taked from PS2 games. The number of files inside its marked in the first 4 bytes, as little endian. The file has too a final offset to show the finish.
Each file got a marked size, calculating with the next offset start, or finish byte.

I want to create a plugin to export each file with an order number (decimal byte position on offset) and make a recompiler taking the file names (position on offset) to create a new file with all inside.

Or there is something similar?


Example of header.
Image
Red its number of files inside
Green are files start offsets (the first for example its 0x40 = 64 bytes decimal)
Blue its final of the file.

Thanks a lot for reading :)

_________________
The most glorious ideas born of the most humble feathers


Top
   
PostPosted: Sat Jun 11, 2016 9:14 am 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
Try this:
Code:
get FILES long
    get OFFSET long
for i = 0 < FILES
    savepos TMP
    math TMP - 4
    get NEXT_OFFSET long
    math SIZE = NEXT_OFFSET
    math SIZE - OFFSET
    string NAME p "%d" TMP
    log NAME OFFSET SIZE
    math OFFSET = NEXT_OFFSET
next i

*edit* new script


Top
   
PostPosted: Sat Jun 11, 2016 1:08 pm 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
Thanks for help me
There are troubles with that script. It exports the first file in all cases so name of all files are all equal (and worng).
And the other problem its the name, its the offset in decimal, i want to put the order of file or byte where offset its placed in file.

For the name in the example
40 00 00 00 = 0004
00 20 00 00 = 0008
80 47 00 00 = 0012
80 4A 00 00 = 0016

With that names, i can get the info to rebuild the file with the separated ones


Attachments:
File comment: Here is the example file
Example.zip [17.43 KiB]
Downloaded 48 times

_________________
The most glorious ideas born of the most humble feathers
Top
   
PostPosted: Sat Jun 11, 2016 1:49 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
Script fixed.


Top
   
PostPosted: Sat Jun 11, 2016 2:21 pm 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
Perfect, really thanks. Export that amount of files manually takes a long time It seems to work on extraction of the file. Even i tried with a long file (about 400 files inside) and it works.

But for rebuild the file, taking the names of the files to an offset index i used reimport tool of QuickBMS but doesn't work, takes me an error on the first file.

I see this code, but doesn't create the file index at start (number of files and start-finish of each one)

Code:
get SIZE asize  # takes the size of the current file
append # enable the append mode for concatenating them
log "new.bin" 0 SIZE
append # disable concatenation (not necessary if its there are no other operations)


what can i add to that code to build it?

PD: Even if QuickBMS doesn't recognise the amount of files and i need to put the number of entries in the .BMS isn't a big problem, there is about 5 or 6 types of files that contain the same amount on each one, so edit a number for each one isn't a big problem

_________________
The most glorious ideas born of the most humble feathers


Top
   
PostPosted: Sat Jun 11, 2016 2:40 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
The reimport mode of quickbms works like a reinjector replacing the original bytes with the new ones, everything is writtein in section 3 of quickbms.txt.

Probably what you want is a rebuilder that takes the files and recreated the archive from scratch.
It's very easy for that simple archive format so I leave it to you or anyone else interested as exercise :)


Top
   
PostPosted: Sat Jun 11, 2016 2:53 pm 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
Ok, i will try it.

Do you suggest me to use base of that script or make a completly new one? Sorry but im noob xD even if you got a tutorial it will be helpfull :)

EDIT: No matter i will see examples and the quickbms.txt help
Thanks again :)

_________________
The most glorious ideas born of the most humble feathers


Top
   
PostPosted: Sat Jun 11, 2016 3:28 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
Using quickbms for building stuff requires some skills so I suggest you to use a real programming language.


Top
   
PostPosted: Sat Jun 11, 2016 4:21 pm 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
Exactly, maybe the best idea is to use a real language but also accept a challenge can be more rewarding.
I was planning that the script will do, i think that it's the first step.

For start i get the merged files so i can treat that file as a temporary that will put after the first (index) that i want to do or save as 2 files an then merge.

To make the index first of all i need to write FILES long.
Then need to put math FILES long * 4 + 4 (to put the start of the first file calculating index size)
To calculate the next value i need to take file SIZE + PREVIOUS_OFFSET
And finish in last file.

But i dont know how commands use to treat that type of data.

Thats creates me the merge files
get SIZE asize
append
log "Data.file" 0 SIZE
append

If i want to create a data for each file i dont know how to do it, how to tell to the program when he need to give back a value.

Yes, i will see it too with a friend who knows java, but this is personal with that files lol
I really appreciate your help, sorry for my poor english and poor knowledge

_________________
The most glorious ideas born of the most humble feathers


Top
   
PostPosted: Sat Jun 11, 2016 8:23 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
I have found a topic that may be of interest for you:
viewtopic.php?f=9&t=1104


Top
   
PostPosted: Sat Jun 11, 2016 9:32 pm 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
I see it, uses some information that i need to manage. But what about the order? It get first 100, then 1000, 1000 ones, 104 and continues.

Chinese basic for me xDDDD lol i know, this isn't for me
I need to see it with more patience :)

_________________
The most glorious ideas born of the most humble feathers


Top
   
PostPosted: Sat Jun 11, 2016 10:19 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
Code:
# 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

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
        get OFFSET asize MEMORY_FILE2
        putarray 0 FILES OFFSET

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

next

        # last offset
        get OFFSET asize MEMORY_FILE2
        putarray 0 FILES OFFSET

put FILES long MEMORY_FILE
xmath BASE_OFF "4 + (FILES + 1) * 4"
math BASE_OFF x 16
for i = 0 <= FILES
    getarray OFFSET 0 i
    math OFFSET + BASE_OFF
    put OFFSET long MEMORY_FILE
next i
for
    get TMP asize MEMORY_FILE
    if TMP == BASE_OFF
        break
    endif
    put 0 long MEMORY_FILE
next

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 want to remember to anyone that quickbms is not the best option for generating files... but it works.


Top
   
PostPosted: Wed Mar 08, 2017 8:39 pm 
User avatar

Joined: Thu May 05, 2016 10:53 pm
Posts: 12
Sorry if i bore you, and i will know if you don't want to help me, but...
There is a way to add to the last code the size of each file?

Example
Image

It's for AFS File format.

Greets

_________________
The most glorious ideas born of the most humble feathers


Top
   
PostPosted: Thu Mar 09, 2017 12:36 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
Yes, after the first "putarray" add:
putarray 1 FILES SIZE

After the "put OFFSET" add:
getarray SIZE 1 i
put SIZE long MEMORY_FILE

*edit* fixed


Top
   
PostPosted: Sun Mar 12, 2017 1:55 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 6876
There was a bug in the previous patch, now fixed.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 15 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