Add DDS header..?

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

Add DDS header..?

Post by sigroon365 »

Hi, :lol: I made bms script to convert some files to dds.
It extract dds data but can't add dds header yet.

sample https://www.sendspace.com/file/u72dkx

Code: Select all

endian big
goto 0x10
get Header_SIZE long
xmath base_off "Header_SIZE + 0x64"

xmath file_num_off "Header_SIZE - 0x10"
goto file_num_off
get files long

goto 0x28
get names_jump long
xmath noff "names_jump + 0x81"

for i = 0 < files

goto noff
get name string
strlen namesz name

if name = "Page0"
xmath noff "noff + 0xC"
goto noff
get name string
string name += ".dds"
savepos noff

else

string name += ".dds"
savepos noff

endif


goto base_off
get SIZE long
get UNK1 long
get UNK2 long
get WIDTH short
get HEIGHT short
savepos tmp
xmath OFFSET "tmp + 0x38"

log name OFFSET SIZE

xmath base_off "OFFSET + SIZE + 0x50"

next i


How can I use callfunction to add dds header?

Code: Select all

callfunction addDDSheader
startfunction addDDSheader
endian little
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x0A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x05\x00\x00\x00\x44\x58\x54\x35\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x10\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
putVarChr MEMORY_FILE 0x10 WIDTH long
putVarChr MEMORY_FILE 0xC HEIGHT long

endian big
append
log MEMORY_FILE OFFSET SIZE
append
endfunction
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Add DDS header..?

Post by sigroon365 »

Ah, I solve it. :D

Code: Select all

endian big
goto 0x10
get Header_SIZE long
xmath base_off "Header_SIZE + 0x64"
xmath file_num_off "Header_SIZE - 0x10"
goto file_num_off
get files long

goto 0x28
get names_jump long
xmath noff "names_jump + 0x81"

for i = 0 < files
goto noff
get name string
if name = "Page0"
xmath noff "noff + 0xC"

goto noff
get name string
string name += ".dds"
savepos noff

else
string name += ".dds"
savepos noff
endif

goto base_off
get SIZE long
get UNK1 long
get UNK2 long
get WIDTH short
get HEIGHT short
savepos tmp
xmath OFFSET "tmp + 0x38"

callfunction addDDSheader
log NAME 0 SIZE MEMORY_FILE
append

xmath base_off "OFFSET + SIZE + 0x50"
next i

startfunction addDDSheader
endian little
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x0A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x05\x00\x00\x00\x44\x58\x54\x35\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x10\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
putVarChr MEMORY_FILE 0x10 WIDTH long
putVarChr MEMORY_FILE 0xC HEIGHT long
endian big
append
log MEMORY_FILE OFFSET SIZE
endfunction
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Add DDS header..?

Post by sigroon365 »

Hmm.. unpack works well.
Image

But reimporting cause error. Can some one help me?
Image
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Add DDS header..?

Post by aluigi »

Because quickbms can't work with MEMORY_FILEs in reimporting.
It can reimport only files that have been extracted directly to disk.
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Add DDS header..?

Post by sigroon365 »

aluigi wrote:Because quickbms can't work with MEMORY_FILEs in reimporting.
It can reimport only files that have been extracted directly to disk.


Hmm.. Then I should remove DDS header and insertion it to original file, right?
Here is the complete version for various type..

Code: Select all

#Naruto ultimate storm 3 full burst xfbin to DDS written by me

endian big

goto 0x1C
get TYPE long

if TYPE < 9
math jump = 0xAC
else
math jump = 0x10C
endif

FindLoc GIDX_off string "GIDX" 0 ""
#goto 0x2A4
#savepos GIDX_off
xmath file_num_off "GIDX_off - jump"

goto file_num_off
get files long

goto 0x20
get names_jump1 long
goto 0x28
get names_jump2 long
goto 0x30
get names_jump3 long
xmath noff "0x44 + names_jump1 + names_jump2 + 1"

for i = 0 < files
goto noff
get name string

if name = "Page0"
xmath noff "noff + 0xC"
goto noff
get name string
string name += ".dds"
savepos noff

else
string name += ".dds"
savepos noff
endif

goto GIDX_off
xmath base_off "GIDX_off - 0x38"

goto base_off
get SIZE long
get UNK1 long
get UNK2 long
get WIDTH short
get HEIGHT short
savepos tmp
xmath OFFSET "tmp + 0x38"

callfunction addDDSheader

get packname filename
string packname += _unpacked/
string packname += name
log packname 0 SIZE MEMORY_FILE
append
xmath GIDX_off "OFFSET + SIZE + 0x88"

if GIDX_off > EOF
cleanexit

else

goto GIDX_off
getdstring TEST 0x4
    if TEST == "GIDX"
    else
    cleanexit
    endif
endif

next i

startfunction addDDSheader
endian little
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x0A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x05\x00\x00\x00\x44\x58\x54\x35\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x10\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
putVarChr MEMORY_FILE 0x10 WIDTH long
putVarChr MEMORY_FILE 0xC HEIGHT long
endian big
append

log MEMORY_FILE OFFSET SIZE
endfunction
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Add DDS header..?

Post by aluigi »

Basically you should dump the file as-is, log NAME OFFSET SIZE.
The reimport feature is meant to reimport the extracted files while in this case you have "generated" a new file using the content of an archive file.

The reimport feature consists just in replacing the function that dumps the file on the disk with a function that reads the file from the disk and copies it in the original archive, just that.
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Add DDS header..?

Post by sigroon365 »

aluigi wrote:Basically you should dump the file as-is, log NAME OFFSET SIZE.
The reimport feature is meant to reimport the extracted files while in this case you have "generated" a new file using the content of an archive file.

The reimport feature consists just in replacing the function that dumps the file on the disk with a function that reads the file from the disk and copies it in the original archive, just that.


Ok, I understand it. Then.. After I extract it, it needs to remove header for reimporting.
But how can I remove DDS header from DDS file?
Image
...
Image

Code: Select all

idstring "DDS"
goto 0x80
savepos OFFSET

xmath SIZE "EOF - 0x80"
log "" OFFSET SIZE


Error
Image

I think EOF may cause error?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Add DDS header..?

Post by aluigi »

No, you must NOT log to MEMORY_FILE, that's the only thing to do.
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Add DDS header..?

Post by sigroon365 »

aluigi wrote:No, you must NOT log to MEMORY_FILE, that's the only thing to do.

Uhm.. But if I change "log MEMORY_FILE OFFSET SIZE" to "log name OFFSET SIZE", it causes error.

Code: Select all

callfunction addDDSheader
log NAME 0 SIZE MEMORY_FILE
append
...
log MEMORY_FILE OFFSET SIZE

to

Code: Select all

callfunction addDDSheader
log NAME 0 SIZE MEMORY_FILE
append
...
log name OFFSET SIZE


Actually, I have difficult in understand well MEMORY_FILE yet.
In my opinion, in order to reimport, I have to follow below progress.
First, generate dds file. Second, remove dds header. Third, reimporting.

<reimporting script> - extract only SIZE and reimport

Code: Select all

endian big

goto 0x1C
get TYPE long

if TYPE < 9
math jump = 0xAC
else
math jump = 0x10C
endif

FindLoc GIDX_off string "GIDX" 0 ""
#goto 0x2A4
#savepos GIDX_off
xmath file_num_off "GIDX_off - jump"

goto file_num_off
get files long

goto 0x20
get names_jump1 long
goto 0x28
get names_jump2 long
goto 0x30
get names_jump3 long
xmath noff "0x44 + names_jump1 + names_jump2 + 1"

for i = 0 < files
goto noff
get name string

if name = "Page0"
xmath noff "noff + 0xC"
goto noff
get name string
string name += ".dds"
savepos noff

else
string name += ".dds"
savepos noff
endif

goto GIDX_off
xmath base_off "GIDX_off - 0x38"

goto base_off
get SIZE long
get UNK1 long
get UNK2 long
get WIDTH short
get HEIGHT short
savepos tmp
xmath OFFSET "tmp + 0x38"

get packname filename
string packname += _unpacked/
string packname += name
log packname OFFSET SIZE
xmath GIDX_off "OFFSET + SIZE + 0x88"

if GIDX_off > EOF
cleanexit

else

goto GIDX_off
getdstring TEST 0x4
    if TEST == "GIDX"
    else
    cleanexit
    endif
endif

next i


However, you mean, if I modify my script(Not log to memory_file) then reimporting works on?
But I don't know how to generate dds file without memory_file.
So, I think that the above step is needed to reimport.

p.s. remove DDS header

Code: Select all

goto 0x80
savepos OFFSET

goto EOF
savepos End

xmath SIZE "End - OFFSET"
log "" OFFSET SIZE
sigroon365
Posts: 330
Joined: Fri Nov 21, 2014 4:03 am

Re: Add DDS header..?

Post by sigroon365 »

Anyway, I success to edit dds image. :D

Original
Image

After reimporting
Image