老外发布了一篇通用解包器制作工具QuickBMS的图文教程,想学制作解包器的朋友可以仔细看看。 其实不是太难的。
- B- {' A5 p7 B0 \' r# O4 B
3 g2 |3 J- X. Y: ^9 O原文
; j% _7 x& z) C# Q! a, z! hhttp://forum.xentax.com/viewtopi ... 0&sk=t&sd=a ; f X* Z7 R+ F# v7 _( z2 ]# Z# I
8 m, n" D. M9 l' ^! J" g; R" GI am going to make a tutorial for using quickbms for extracting archives that are no extractors for. " f: `/ Z, T9 H$ Y) T, C- D
I am going to start off easy then add more and more difficult archives so you can learn and write your own scripts. $ L- g* H0 s! a, O$ v
the tools you need are just 4 things. - \2 ~) b0 O* {% S& n# q; C
1. A HEX editor I use HxD 0 W/ K3 j1 J3 G
2.Quick BMS http://aluigi.org/papers/quickbms.zip 1 J( _3 \& X" {
3. a text editor like wordpad
5 z t5 g( g3 b2 @4. a calculator that supports hex like the one built into windows. % @1 z$ P) f% U, F
We will start with a game called FEZ (Fantasy Earth Zero) 5 A9 I8 {6 Q$ {& l
this is a great archive format for someone to learn bms scripting from. # \4 X1 }6 J: L
I attached a sample. 0 w, K4 z& \" r7 t
website http://tw.fez.gamania.com/
/ l9 U3 H1 {/ Einstaller http://tw.dl.gamania.com/fez/FEZ_1103.exe
C, H* k& K6 y* ^this game uses textures with wrong headers mainly dds and some tga and some kind of .mdl format.
. C, \+ r9 x) E1 L. {& r% x% @+ J/ J( F- ?0 j: O$ A
ok so you can download the full installer or this sample pac file here 6 _" t( U8 p! s* W
http://www.MegaShare.com/1029061
( ]& `' r7 u6 _; fok so open the file up in your hex editor so you see what I have open here ' |6 y G# p' L1 {% ^* G3 f+ r
$ G- [; C. ]4 a- K6 Z1 l8 B$ `
' F4 G7 r! b8 W- R. ]# o
4 L: A, [6 n1 _3 _so if you look to the right you will notice some readable text
& Y, k/ |; z8 i5 a+ vEtc\aura.tex , Etc\cursor.tex , Etc\mahoujin.tex , Etc\env2.tex , and Etc\kaze.tex .
% S* `7 h6 c a- Q* cso just looking with out eyes we now know that there are at least 5 files in this bin file and after we extract them they will be placed in a folder called Etc.
3 i/ f1 P% _+ p- I7 E# h9 iso lets start looking at the other parts of the header in this file we will start with the first 4 bytes 8 u6 e: a# L" p" j
2 v% n% \" ?0 S6 \1 i3 n
well we have 05 00 00 00 . H: ]! I: _: B; W' C+ d2 M
whenever you are working with archives for computer games 99% of the time you read the values in reverse so the above number 9 j+ E* d: w& ^0 a0 q
would not be 5,000,000 but instead would be read as 00 00 00 05 or 5 & g. t5 J3 r- J$ x4 [) K& H1 T5 J* W8 g
Well if we remember from earlier we saw 5 file names and our first 4 bytes of our file are equal to 5 so there is a good chance we just discovered where the file count is stored in this archive.
@* `; F9 N$ w3 f7 G% ?: xdata is stored in groups of 4 bytes " a long" 2 bytes " a short" or 1 byte "a byte" so we have our first part of our script 3 z7 r" \/ p# o& |
get FILES long ' Y2 ^5 I7 g/ K/ u
this tells quickbms to read a long value "aka 4 bytes" and store it as the variable FILES.
7 y( X0 w3 x6 `" n7 d0 \ok the next 4 bytes 74 00 00 00 are not needed in order for quickbms to extract our files but it represents the total size of our header.
+ t6 n, B0 o1 m( M1 i5 i* g ' k0 w1 H6 i1 z0 s2 l
so I will write the next line of code for quickbms _. w$ K5 N- r2 ?
get HEADERSZ long . g8 m- E. ~) b( ^/ p# b
this stores the header size in the variable HEADERSZ
( w4 k2 F2 }8 X+ W2 bok now we have 2 more bytes before the file name ! ^$ k6 u7 U4 S( S$ H% n4 d
so that is 0C 00 well 2 bytes is know as a short. but what does 00 0C stand for?
- v' t0 T* k' u2 o: @if we highlight the whole name of the file in out hex editor it shows us a length of C
n6 L0 p" L3 P1 s. \+ hwe found the name length so we would write that as
! Q, p' V+ N+ n" L' Jget NSIZE short
3 p- V8 v/ K/ N: h+ F5 F9 {8 ~& d( \this stores the 2 bytes in the variable NSIZE representing the length of the name
1 F8 _3 M8 p$ C' m' L 8 s9 J1 O" r1 x, X( k l
well next comes the name so to store that as a word in bms language we will write the next line
2 B6 G; {/ x# H* R- p+ {( Rgetdstring NAME NSIZE
: o+ L3 T- o: i4 w& d0 v* f" Sthis is saying store a string "aka a word" in the variable NAME and its length is equal to the variable NSIZE.
& H7 u4 f+ Y0 k6 [$ C) \ok now we have another 4 bytes after the name 7C 00 00 00 6 l @' m- P, t* M
well we already know the name of the file so now to extract the file we need to know its size and location in the archive. 1 G& n) s! L# W2 |
7C is not a very big number for the size of the file to lets see what happens if we go to offset 7C / {* u( M3 `' W2 F" W% I+ E
in HxD press ctrl +E and type in 7c for the start and end then click ok. % ]' r" g: _5 m! n" j3 f8 k
' S+ Y' y2 J9 _- G% `
you should look like this after clicking ok . w/ N4 W' X; b V. }
& n E* ]( A, J7 H5 u: y4 J
hmm this looks good it looks like a file header IMG0 so we will write out line saying that is the start of the file
. M( O+ m( z' ?" j7 K9 x" v9 \- mget OFFSET long $ W0 y0 y5 p0 L+ _/ L
this stores the 4 bytes as the variable OFFSET : K! B Z( N+ A; Q& Y
ok the next 4 bytes are 70 10 00 00 well that looks bigger so lets see if that is the size of out file so it will translate into 00 00 10 70 or 1070 5 F3 o- ]2 Y# j
so lets go to our offset 7C and then we will add in the length column 1070
# `: ?9 H2 \2 A- O , `+ F O1 o8 g) b6 P
wow look at that I see TRUEVISION-XFILE that is a classic tga ending and we also end just before IMG0 which was the start of our first file t" \7 d" a1 w6 f5 e0 k: V- {
* G& ^/ U2 q2 Oso that means we found our size
$ ` ^5 L; d8 H: H n& ?we write that as ' d. _, \! q& d/ p1 Q* E4 f0 z
get SIZE long
/ ~( [0 q' K3 f8 ]6 v' J( ithis stores the 4 bytes in the variable SIZE % f1 g; E. x0 K
ok now we have 2 bytes then the next file name hmm that seems familiar + Q5 F8 B# _0 l8 X
lets see 0E 00so that means it translates into 00 0E or E
! N# x* A, @+ kwell the last 2 bytes we had before a name was the name size lets see if it still holds true
6 ?8 L7 b7 I& e& a4 \" m# n$ ?: Z & Q1 b+ h; L2 B- l: C1 c; @" }
it does the name length is E
5 \" o9 `: U, r& N, X. x/ D9 Tso that means we found where the pattern in the header repeats and we identified all that we need to extract the files so now we can finish our script and our extractor.
: K" g9 y* a" y7 r, a2 N4 m( jwhenever the pattern starts you want to begin a loop so it will keep cycling through it until there are no files left. the easiest way to write that is. ( g6 c% N8 u: H) c1 g6 g
for i = 0 < FILES $ x: y4 J# `) M
this means run the following commands until i = 0 and set i = FILES 2 q! ~+ O$ Z4 M6 P/ e0 @5 n9 U. }
so we will put that before our NSIZE variable because that is where the pattern starts. ; x# k0 m- F! Y4 b
next you want it to write out the file and we do that with the log command in the following format
( \! \6 i0 D) @# q$ glog NAME OFFSET SIZE
# ]/ O3 `3 F2 |" @/ s( Qthis says write the file name and fill it with the data starting at the variable OFFSET and a length of SIZE.
) ?# b/ d* n- {9 A4 Nnow this is great but we want it to keep repeating the loop till there are no more files so we must add
( z8 j- N4 G0 y6 Ynext i
; I: W* ^3 r( Qat the end so the loop continues. ' c/ z' z0 ^* ]4 d0 F
ok so now save the file we created as extract.bms 5 T. O8 \5 n! h. A
and put Etc.pac extract.bms and quickbms.exe all in the same folder for wthis demo we will say c:\temp
" f4 w |( z7 ~, J- gso now at the command prompt change to that directory and type
' C( r; ]% N+ o7 C% C* j zquickbms.exe -l extract.bms Etc.pac . % l+ a# Q$ X+ O4 L+ r0 T
this will list the the file contents and size or give you an error if your script is not correct. . B/ E0 m, G& V
Yay it worked * k+ H/ [4 S3 k: ^$ ]7 E2 ^
- Q# o, C9 p) B6 U
now lets try extracting them create a folder in c:\temp called extracted 7 C. y7 |' a+ I9 x- n# w
now type the command
9 ?% x8 ~8 E4 M1 x2 X6 Kquickbms.exe extract.bms Etc.pac extracted
- R9 w9 Z h! L0 W# P) v# U( U' Gyes it worked now they are in the filder and extracted.
" P6 X" l. L% m, n/ n
- K2 A) {! T( y @3 {3 k
$ G& R$ S, [4 A8 K: b: C! XCode: / C E+ h( ^. O4 K2 u, G# r
get FILES long
7 j. N1 u% J0 d2 rget HEADERSZ long 4 I8 b2 ?0 a2 t% E% ]7 [8 y
for i = 0 < FILES
* _7 Q. ~6 }" q+ D( @get NSIZE short
& u. p: \4 j0 }& h; `9 i) Y2 dgetdstring NAME NSIZE : ^# J7 F+ r5 \. Y9 d
get OFFSET long
3 j& H( z& D% `/ d1 [) m# q1 lget SIZE long
- [) u; T3 O; T+ U* ]
7 d* @ |- X0 F$ E4 _$ g l6 ~. W- e6 u, Klog NAME OFFSET SIZE
7 P, j- @2 H9 k y# Qnext i
' @, b& s2 c4 s5 g4 W2 d/ I
2 `4 a. Z& | ]' V1 iLet me know what you think of this tutorial and if you want me to continue on with more examples and more compex scripts. |