Creating files with offsets values
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Creating files with offsets values
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.
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
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.
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
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
Try this:
*edit* new script
Code: Select all
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
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Re: Creating files with offsets values
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
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
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
Script fixed.
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Re: Creating files with offsets values
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)
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
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: Select all
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
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
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
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
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Re: Creating files with offsets values
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
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
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
Using quickbms for building stuff requires some skills so I suggest you to use a real programming language.
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Re: Creating files with offsets values
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
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
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
I have found a topic that may be of interest for you:
viewtopic.php?f=9&t=1104
viewtopic.php?f=9&t=1104
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Re: Creating files with offsets values
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
Chinese basic for me xDDDD lol i know, this isn't for me
I need to see it with more patience
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
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
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.
-
- Posts: 12
- Joined: Thu May 05, 2016 10:53 pm
Re: Creating files with offsets values
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
It's for AFS File format.
Greets
There is a way to add to the last code the size of each file?
Example
It's for AFS File format.
Greets
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
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
putarray 1 FILES SIZE
After the "put OFFSET" add:
getarray SIZE 1 i
put SIZE long MEMORY_FILE
*edit* fixed
-
- Site Admin
- Posts: 12984
- Joined: Wed Jul 30, 2014 9:32 pm
Re: Creating files with offsets values
There was a bug in the previous patch, now fixed.