Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

Creating files with offsets values

Featured Replies

  • Author
  • Localization

Racial, posted Sat Jun 11, 2016 12:42 am (14259)


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 :)
  • Author
  • Localization

aluigi, posted Sat Jun 11, 2016 9:14 am (14263)


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
  • Author
  • Localization

Racial, posted Sat Jun 11, 2016 1:08 pm (14284)


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
  • Author
  • Localization

aluigi, posted Sat Jun 11, 2016 1:49 pm (14286)


Script fixed.
  • Author
  • Localization

Racial, posted Sat Jun 11, 2016 2:21 pm (14289)


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
  • Author
  • Localization

aluigi, posted Sat Jun 11, 2016 2:40 pm (14293)


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 :)
  • Author
  • Localization

Racial, posted Sat Jun 11, 2016 2:53 pm (14294)


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 :)
  • Author
  • Localization

aluigi, posted Sat Jun 11, 2016 3:28 pm (14298)


Using quickbms for building stuff requires some skills so I suggest you to use a real programming language.
  • Author
  • Localization

Racial, posted Sat Jun 11, 2016 4:21 pm (14301)


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
  • Author
  • Localization

Racial, posted Sat Jun 11, 2016 9:32 pm (14315)


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 :)
  • Author
  • Localization

aluigi, posted Sat Jun 11, 2016 10:19 pm (14317)


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.
  • Author
  • Localization

Racial, posted Wed Mar 08, 2017 8:39 pm (21309)


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
  • Author
  • Localization

aluigi, posted Thu Mar 09, 2017 12:36 pm (21317)


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
  • Author
  • Localization

aluigi, posted Sun Mar 12, 2017 1:55 pm (21419)


There was a bug in the previous patch, now fixed.
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.