老外发布了一篇通用解包器制作工具QuickBMS的图文教程,想学制作解包器的朋友可以仔细看看。 其实不是太难的。
+ Z) f, z- r4 f4 m0 Y" d4 M( C3 o: d/ m& \7 w* d
原文 3 g* `' S- e2 u
http://forum.xentax.com/viewtopi ... 0&sk=t&sd=a
0 o; J6 k9 l8 w9 z3 p. ~4 V1 a8 T. E5 N5 t3 e# ^$ b/ ~0 H8 ^
I am going to make a tutorial for using quickbms for extracting archives that are no extractors for.
" h; m. f) C) f- M d9 Q2 H3 m' u- oI am going to start off easy then add more and more difficult archives so you can learn and write your own scripts.
9 k+ Y% M( |2 |$ Z# m. mthe tools you need are just 4 things.
?4 N' n; I6 Y; O1. A HEX editor I use HxD 9 ~4 ]: w% ]6 ^4 K& r: E
2.Quick BMS http://aluigi.org/papers/quickbms.zip 2 y# ^3 c( {2 ~1 p
3. a text editor like wordpad
. ?* f4 W7 t3 [# s7 B4. a calculator that supports hex like the one built into windows. 6 n* i- d7 g. m8 e4 X6 r' r+ z+ I
We will start with a game called FEZ (Fantasy Earth Zero)
4 G3 E; x$ v* Bthis is a great archive format for someone to learn bms scripting from. ! m( [7 ?8 p2 ?4 K9 o# ^
I attached a sample. . A) n' }# h! C5 p. p8 u
website http://tw.fez.gamania.com/ ! w. C1 t- a2 G- m. n
installer http://tw.dl.gamania.com/fez/FEZ_1103.exe
$ h, o$ Y; D$ I# Cthis game uses textures with wrong headers mainly dds and some tga and some kind of .mdl format. 3 P' ~& w; U C; I4 `
2 K; \ `+ X4 K: G# n- ^
ok so you can download the full installer or this sample pac file here
' @3 e& `1 [# B6 ]5 Dhttp://www.MegaShare.com/1029061
/ T$ N7 `2 t3 c5 W+ Jok so open the file up in your hex editor so you see what I have open here
% i2 U( [, l4 a+ \6 D y ; W, ^5 N0 i% J* I! G! ~
5 T$ M2 q8 c* r% c; ~. q
0 M9 R( @: _! Y2 L, xso if you look to the right you will notice some readable text
( A* b/ _5 i$ o' i9 x5 `Etc\aura.tex , Etc\cursor.tex , Etc\mahoujin.tex , Etc\env2.tex , and Etc\kaze.tex . . H% t* Z4 [ y* G! H
so 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.
% U7 f- X! r' z. M1 Gso lets start looking at the other parts of the header in this file we will start with the first 4 bytes 2 p2 A T1 r* e7 {. ^
) ~! Z! H" u( @& v; x3 Z
well we have 05 00 00 00
2 p" c u0 r1 Q! dwhenever you are working with archives for computer games 99% of the time you read the values in reverse so the above number : @4 }) f7 q! r1 R$ C* j0 \! k
would not be 5,000,000 but instead would be read as 00 00 00 05 or 5 ! l T7 }, l* f- K+ Z- E/ e
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. 3 f: ]( p) D8 P( w
data 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
- M8 y: i- [" Fget FILES long
5 T: e8 Y" h* O8 E2 m8 Vthis tells quickbms to read a long value "aka 4 bytes" and store it as the variable FILES. * ?, {7 \& l* \3 ~# M! c
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. . u& {; N! D- }% x' Z: K
; ~9 O. ^+ I3 r7 n; Xso I will write the next line of code for quickbms
% O! G4 l7 ^- {/ K5 [5 V2 J& Iget HEADERSZ long 3 Z, M6 z5 x, X" }
this stores the header size in the variable HEADERSZ
; g+ }/ L! I- e ?( {1 H4 Y$ Jok now we have 2 more bytes before the file name
& x- _* s. x- s, U f8 I3 k0 |so that is 0C 00 well 2 bytes is know as a short. but what does 00 0C stand for? " E$ L" B+ `. t8 G" O
if we highlight the whole name of the file in out hex editor it shows us a length of C c, E. m# e! q$ ~" M# V) h( w% v
we found the name length so we would write that as
9 }7 |4 T- [8 ~' _2 J" Rget NSIZE short
% v- o2 B8 z* [1 V4 N9 r0 K; O kthis stores the 2 bytes in the variable NSIZE representing the length of the name
8 a& V7 N! r2 C3 A) B6 p E) @ H4 m/ f; a& O0 r
well next comes the name so to store that as a word in bms language we will write the next line ; ?: q; v4 W) v8 ?- V, z3 b
getdstring NAME NSIZE 5 S! G$ t0 t t" |1 E
this is saying store a string "aka a word" in the variable NAME and its length is equal to the variable NSIZE.
/ ~5 Z7 e' d* L7 O/ Nok now we have another 4 bytes after the name 7C 00 00 00 4 c0 K- r( \2 r6 l4 x! n2 V
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.
2 f& q& J+ F2 H) Q& W( T' V3 [7C is not a very big number for the size of the file to lets see what happens if we go to offset 7C b! S: R5 Q4 u( Z3 e Q
in HxD press ctrl +E and type in 7c for the start and end then click ok. . ?) j! c2 _' V, F, ]" n
+ y* J. ?) `6 ]) V4 Qyou should look like this after clicking ok
) l7 z! Y; g+ |5 I4 c5 r$ q. Z 3 R( W5 Z& Y0 ]9 E
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 , Y5 K p+ Z5 D( k
get OFFSET long * H) ^* ~5 U G- c7 o3 K
this stores the 4 bytes as the variable OFFSET 0 p$ U/ \$ D8 ], ]/ ?
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 & d7 A& @, H+ V' `
so lets go to our offset 7C and then we will add in the length column 1070
4 x; V r9 s+ l) H
A0 x8 \6 x a. e* Qwow 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 ! l6 V4 J4 s$ m% E' X5 g
4 r/ w5 n0 ~- U- b4 `+ Q5 H8 Bso that means we found our size
3 i0 x* o8 h' k- o. G* M. u1 Uwe write that as
+ U) w; f- Z; b4 |get SIZE long 3 c+ D {) I3 G
this stores the 4 bytes in the variable SIZE 2 V% ^7 M+ r0 a) ~- j, }
ok now we have 2 bytes then the next file name hmm that seems familiar + ^( ?$ H2 r% S/ u: N1 j/ T
lets see 0E 00so that means it translates into 00 0E or E
+ R( i% I! m! Ywell the last 2 bytes we had before a name was the name size lets see if it still holds true
% X1 H' l2 T5 @$ d
* R% {5 g6 a4 ^2 w! `7 G+ ^ Fit does the name length is E ; D8 U. z, f5 X! ]9 ?5 e' ^% P
so 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.
0 Z+ ?/ A# |. r. {9 {whenever 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.
7 M3 O4 f7 U* Kfor i = 0 < FILES
) a* Y5 s z7 ^; t% Fthis means run the following commands until i = 0 and set i = FILES 1 P4 G; l9 z1 S* K% h
so we will put that before our NSIZE variable because that is where the pattern starts. $ x: z$ w* h8 q" T2 @! a, l
next you want it to write out the file and we do that with the log command in the following format - ~+ i. ?* b) {! z# v
log NAME OFFSET SIZE * j. s: s8 ?* f) R! ?
this says write the file name and fill it with the data starting at the variable OFFSET and a length of SIZE.
4 A6 C( U w" F G. D( {$ C, q& jnow this is great but we want it to keep repeating the loop till there are no more files so we must add % j2 a. N# Z7 P, Z$ Z- a
next i
. e7 y0 H! ]9 S# Mat the end so the loop continues.
! r, x; h7 w, }8 k, Tok so now save the file we created as extract.bms ( V" b' G( V, M( L
and put Etc.pac extract.bms and quickbms.exe all in the same folder for wthis demo we will say c:\temp 8 n4 K% D' t1 B4 a* l
so now at the command prompt change to that directory and type " c8 j/ y+ x) E- E
quickbms.exe -l extract.bms Etc.pac . 1 k0 T: u; a9 z+ t4 ]0 ?
this will list the the file contents and size or give you an error if your script is not correct. U& {- F" X6 j& y/ T
Yay it worked
d( i) a9 H" P3 |$ f
7 X5 _5 e- w Dnow lets try extracting them create a folder in c:\temp called extracted ! Z A3 l; M: }- @( I' U! ~8 {
now type the command 4 _' ^5 ^/ C6 s9 ?8 h/ b7 y4 b* j
quickbms.exe extract.bms Etc.pac extracted
( h& L/ q" [6 X( ~7 g8 }2 z3 Kyes it worked now they are in the filder and extracted. l/ f: h# \/ Q$ K6 j
3 N/ V( Y9 |) K! Y% @8 D) y; h
5 l% V M1 V) s fCode:
8 }) ?3 I5 B3 {- Mget FILES long
; P2 [ z5 {5 l2 x: W9 |: a8 }get HEADERSZ long & l# Z* F9 A/ ~9 h( x4 I
for i = 0 < FILES
- \9 @# o, r0 V% t$ _get NSIZE short 2 Q2 G$ B( B2 h0 m
getdstring NAME NSIZE , ~, K1 v7 ~9 H5 Y. a$ m
get OFFSET long
, F2 Q8 j2 H# Q! r( i9 rget SIZE long 8 _! q; P3 r9 @) u/ V, K
! [5 l+ [8 d- e3 nlog NAME OFFSET SIZE ' w, e6 {3 M; N- q3 P
next i
- c8 t9 l0 g) D9 }2 T5 P+ G0 ~" b" t" c7 A; z t4 T
Let me know what you think of this tutorial and if you want me to continue on with more examples and more compex scripts. |