Rev 111 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 111 | Rev 131 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ; @RCHER - DEflate unpacker v1.0 |
1 | ; @RCHER - Deflate unpacker v2.0 beta |
2 | ; |
2 | ; |
3 | ; Written in pure assembler by Ivushkin Andrey aka Willow |
3 | ; Written in pure assembler by Ivushkin Andrey aka Willow |
4 | ; |
4 | ; |
5 | ; Created: May 6, 2005 |
5 | ; Created: May 6, 2005 |
6 | ; |
6 | ; |
7 | ; Last changed: July 14, 2005 |
7 | ; Last changed: July 14, 2005 |
8 | ; |
8 | ; |
9 | ; Compile with FASM |
9 | ; Compile with FASM |
Line 10... | Line -... | ||
10 | - | ||
11 | 10 | ||
- | 11 | SYS equ meos |
|
- | 12 | OUTBUF equ 4*1024*1024 |
|
12 | SYS equ meos |
13 | png_imag = output+OUTBUF |
- | 14 | PARAM_PTR = os_work;png_image |
|
13 | PARAM_PTR equ png_image |
15 | MEMINIT=next_code;output |
Line 14... | Line 16... | ||
14 | DUMPFILE equ '/hd/1/out.txt' |
16 | DUMPFILE equ '/hd/1/out.txt' |
15 | 17 | ||
16 | SHOW_RBLOCK equ 0;1 |
18 | SHOW_RBLOCK equ 0;1 |
17 | SHOW_PNG_SEC equ 0;1 |
19 | SHOW_PNG_SEC equ 0;1 |
18 | SHOW_METH equ 0;1 |
20 | SHOW_METH equ 0;1 |
Line 19... | Line 21... | ||
19 | FILE_NUM equ 0 |
21 | FILE_NUM equ 15;8 |
20 | MEMORY equ 0x800000 |
22 | MEMORY equ 0x800000 |
21 | 23 | ||
Line 26... | Line 28... | ||
26 | PASSW_LEN equ 32 |
28 | PASSW_LEN equ 32 |
27 | NO_STOPS equ 1 |
29 | NO_STOPS equ 1 |
28 | SHOW_CHARS equ 0 |
30 | SHOW_CHARS equ 0 |
29 | BSIZE equ 512 |
31 | BSIZE equ 512 |
30 | INBUF equ BUFSIZE*BSIZE*2 |
32 | INBUF equ BUFSIZE*BSIZE*2 |
31 | OUTBUF equ 4*1024*1024 |
- | |
32 | IGNORE_DIRS equ 0 |
33 | IGNORE_DIRS equ 0 |
Line 33... | Line 34... | ||
33 | 34 | ||
Line 34... | Line 35... | ||
34 | MOVE_SLINE_LEV equ 8 |
35 | MOVE_SLINE_LEV equ 8 |
Line 38... | Line 39... | ||
38 | TAR_MODE equ 1000b |
39 | TAR_MODE equ 1000b |
39 | STAY_MODE equ 10000b |
40 | STAY_MODE equ 10000b |
40 | IPC_MODE equ 100000b |
41 | IPC_MODE equ 100000b |
41 | RAW_MODE equ 1000000b |
42 | RAW_MODE equ 1000000b |
42 | THREAD_YES equ 10000000b |
43 | THREAD_YES equ 10000000b |
- | 44 | LIST_MODE equ 100000000b |
|
- | 45 | MEM_MODE equ 1000000000b |
|
- | 46 | FIND_MODE equ 10000000000b |
|
Line 43... | Line 47... | ||
43 | 47 | ||
44 | if SYS eq win |
48 | if SYS eq win |
45 | format PE console |
49 | format PE console |
46 | entry start |
50 | entry start |
Line 55... | Line 59... | ||
55 | 59 | ||
56 | db 'MENUET01' |
60 | db 'MENUET01' |
57 | dd 0x01 |
61 | dd 0x01 |
58 | dd start |
62 | dd start |
59 | dd I_END |
63 | dd I_END |
60 | dd MEMORY |
64 | dd MEMINIT |
61 | dd MEMORY-2048 |
65 | dd main_stack;MEMORY-2048 |
62 | if PARAM_PTR eq param |
66 | if PARAM_PTR eq param |
63 | dd 0 |
67 | dd 0 |
64 | else |
68 | else |
65 | dd PARAM_PTR |
69 | dd PARAM_PTR |
66 | end if |
70 | end if |
67 | dd 0x0 |
- | |
Line 68... | Line 71... | ||
68 | include "lang.inc" |
71 | dd 0x0 |
69 | 72 | ||
70 | if PARAM_PTR eq param |
73 | if PARAM_PTR eq param |
71 | param db 'RQ' |
74 | param db 'N' |
72 | db '000037' |
75 | db '000015' |
73 | db '/hd/1/zip/png.zip',0 |
76 | db '/hd/1/zip/gz/fasm-1~1.tgz',0 |
74 | end if |
77 | end if |
75 | ;match =meos,SYS |
78 | ;match =meos,SYS |
76 | ;{ |
79 | ;{ |
77 | include "macros.inc" |
80 | include "macros.inc" |
- | 81 | ; purge mov |
|
78 | ; purge mov |
82 | include "debug.inc" |
79 | include "debug.inc" |
83 | include 'dump.inc' |
Line -... | Line 84... | ||
- | 84 | ;} |
|
80 | ;} |
85 | end if |
Line 81... | Line 86... | ||
81 | end if |
86 | |
82 | 87 | include 'lang.inc' |
|
83 | language equ en |
88 | language equ lang |
- | 89 | ||
84 | 90 | if SYS eq win |
|
85 | if SYS eq win |
91 | section '.text' code readable executable writeable |
86 | section '.text' code readable executable writeable |
92 | end if |
87 | end if |
93 | |
Line 105... | Line 111... | ||
105 | Msg 0 |
111 | Msg 0 |
106 | Msg 1 |
112 | Msg 1 |
107 | mcall 40,10000101b |
113 | mcall 40,10000101b |
108 | ; jmp again |
114 | ; jmp again |
109 | CmdLine |
115 | CmdLine |
- | 116 | cmdl: |
|
- | 117 | test [Flags],LIST_MODE |
|
- | 118 | jz red |
|
- | 119 | ||
- | 120 | ; Dump [lpath],[lpath_len],os_work |
|
- | 121 | ; ud2 |
|
110 | red: |
122 | red: |
111 | call draw_window |
123 | call draw_window |
112 | mcall 12,2 |
124 | mcall 12,2 |
Line 113... | Line 125... | ||
113 | 125 | ||
Line 132... | Line 144... | ||
132 | jne .noquit |
144 | jne .noquit |
133 | call KillViewer |
145 | call KillViewer |
134 | mcall -1 |
146 | mcall -1 |
135 | .noquit: |
147 | .noquit: |
136 | mcall 17 |
148 | mcall 17 |
- | 149 | mcall 64,1,MEMINIT |
|
137 | QueryFile |
150 | QueryFile |
138 | and [FileNum],0 |
151 | mov [FileNum],FILE_NUM |
139 | test eax,eax |
152 | test eax,eax |
140 | jnz still |
153 | jnz still |
141 | end if |
154 | end if |
142 | again: |
155 | again: |
- | 156 | ; Dump Flags,4,os_work |
|
- | 157 | mov [fat_],fat |
|
143 | Newline |
158 | Newline |
144 | xor eax,eax |
159 | xor eax,eax |
145 | ; and [Flags],STAY_MODE |
160 | ; and [Flags],STAY_MODE |
146 | and [CRC32],eax |
161 | and [CRC32],eax |
147 | and [IDATsize],eax |
162 | and [IDATsize],eax |
Line 151... | Line 166... | ||
151 | jnz .sizeok2 |
166 | jnz .sizeok2 |
152 | .sizebad2: |
167 | .sizebad2: |
153 | Msg 14 |
168 | Msg 14 |
154 | jmp quit |
169 | jmp quit |
155 | .sizeok2: |
170 | .sizeok2: |
- | 171 | call KillViewer |
|
- | 172 | xor eax,eax |
|
- | 173 | mov ecx,(child_stack-fat)/4 |
|
- | 174 | mov edi,fat |
|
- | 175 | rep stosd |
|
156 | mov [filesize],ebx |
176 | mov [filesize],ebx |
157 | test [Flags],RAW_MODE |
177 | test [Flags],RAW_MODE |
158 | jz .norawm |
178 | jz .norawm |
159 | mov eax,[arc_base] |
179 | mov eax,[arc_base] |
160 | xor ebx,ebx |
180 | xor ebx,ebx |
Line 211... | Line 231... | ||
211 | .sizebad: |
231 | .sizebad: |
212 | Msg 17 |
232 | Msg 17 |
213 | jmp exit |
233 | jmp exit |
214 | .sizeok1: |
234 | .sizeok1: |
215 | if ~ SYS eq win |
235 | if ~ SYS eq win |
216 | call KillViewer |
- | |
217 | end if |
236 | end if |
- | 237 | Msg 39 ; unpacking PNG |
|
- | 238 | mov ecx,[unp_size] |
|
- | 239 | add ecx,output |
|
- | 240 | mov [png_],ecx |
|
- | 241 | mov eax,[PNG_info.Width] |
|
- | 242 | imul eax,[PNG_info.Height] |
|
- | 243 | lea eax,[eax+eax*2] |
|
- | 244 | add ecx,eax |
|
- | 245 | ; dps 'Mem=' |
|
- | 246 | ; dpd ecx |
|
- | 247 | mcall 64,1 |
|
- | 248 | test eax,eax |
|
- | 249 | jz .ok |
|
218 | Msg 39 |
250 | Msg 41 |
- | 251 | jmp exit |
|
- | 252 | .ok: |
|
219 | mov edi,[outp] |
253 | mov edi,[outp] |
220 | call Deflate.blkbegin |
254 | call Deflate.blkbegin |
221 | jmp .defl_end |
255 | jmp .defl_end |
222 | .sizeok: |
256 | .sizeok: |
- | 257 | mov ecx,[unp_size] |
|
- | 258 | dpd ecx |
|
- | 259 | add ecx,output |
|
- | 260 | ; mov [png_],ecx |
|
- | 261 | mcall 64,1 |
|
- | 262 | test eax,eax |
|
- | 263 | jz .ok2 |
|
- | 264 | Msg 41 |
|
- | 265 | jmp exit |
|
- | 266 | .ok2: |
|
223 | call Deflate ; <=========== |
267 | call Deflate ; <=========== |
224 | .defl_end: |
268 | .defl_end: |
225 | test [bits],7 |
269 | test [bits],7 |
226 | jnz .esi_ok |
270 | jnz .esi_ok |
227 | dec esi |
271 | dec esi |
Line 250... | Line 294... | ||
250 | dph eax |
294 | dph eax |
251 | end if |
295 | end if |
252 | pop ecx esi |
296 | pop ecx esi |
253 | jmp .skipAdler |
297 | jmp .skipAdler |
254 | .skipCRC: |
298 | .skipCRC: |
- | 299 | ; dps 'Out=' |
|
- | 300 | ; dpd ecx |
|
255 | call UAdler |
301 | call UAdler |
256 | Msg 10 |
302 | Msg 10 |
257 | mov eax,[Adler32] |
303 | mov eax,[Adler32] |
258 | bswap eax ; <- calculated Adler !!! |
304 | bswap eax ; <- calculated Adler !!! |
259 | mov edx,36 |
305 | mov edx,36 |
Line 281... | Line 327... | ||
281 | invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL |
327 | invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL |
282 | invoke CloseHandle, [hnd] |
328 | invoke CloseHandle, [hnd] |
283 | else |
329 | else |
284 | test [Flags],PNG_MODE |
330 | test [Flags],PNG_MODE |
285 | jnz .nosave |
331 | jnz .nosave |
- | 332 | test [Flags],LIST_MODE |
|
- | 333 | jnz quit |
|
- | 334 | ||
286 | test [Flags],TAR_MODE |
335 | test [Flags],TAR_MODE |
287 | jnz .nomsg |
336 | jnz .nomsg |
288 | Msg 37 |
337 | Msg 37 |
289 | .nomsg: |
338 | .nomsg: |
290 | mov [outfile.out],ebx |
339 | mov [outfile.out],ebx |
291 | mcall 58,outfile |
340 | mcall 58,outfile |
- | 341 | ; dps 'Before Quit1' |
|
- | 342 | ; ud2 |
|
292 | test [Flags],TAR_MODE |
343 | test [Flags],TAR_MODE |
293 | jnz .nosave |
344 | jz exit.pad |
294 | call StartPad |
345 | ; call StartPad |
295 | .nosave: |
346 | .nosave: |
296 | end if |
347 | end if |
297 | test [Flags],PNG_MODE |
348 | test [Flags],PNG_MODE |
298 | jz NoPng |
349 | jz NoPng |
299 | xor eax,eax |
350 | xor eax,eax |
300 | mov edi,filters |
351 | mov edi,filters |
301 | mov ecx,6 |
352 | mov ecx,6 |
302 | rep stosd |
353 | rep stosd |
303 | mov edi,png_image |
354 | mov edi,[png_] |
304 | mov esi,output |
355 | mov esi,output |
305 | ;// |
356 | ;// |
306 | mov [outp],edi |
357 | mov [outp],edi |
307 | ;// |
358 | ;// |
308 | call PngFilter |
359 | call PngFilter |
Line 318... | Line 369... | ||
318 | invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL |
369 | invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL |
319 | invoke CloseHandle, [hnd] |
370 | invoke CloseHandle, [hnd] |
320 | call RunViewer |
371 | call RunViewer |
321 | and [arc_base],0 |
372 | and [arc_base],0 |
322 | and [Flags],STAY_MODE |
373 | and [Flags],STAY_MODE |
323 | - | ||
- | 374 | ; dps 'Before Quit2' |
|
324 | quit: |
375 | quit: |
325 | QueryFile |
376 | QueryFile |
326 | test eax,eax |
377 | test eax,eax |
327 | jnz again |
378 | jnz again |
328 | invoke ExitProcess,0 |
379 | invoke ExitProcess,0 |
Line 330... | Line 381... | ||
330 | exit: |
381 | exit: |
331 | mov [outfile.out],ebx |
382 | mov [outfile.out],ebx |
332 | test [Flags],TAR_MODE |
383 | test [Flags],TAR_MODE |
333 | jz .notar |
384 | jz .notar |
334 | Msg 37 |
385 | Msg 37 |
- | 386 | test [Flags],LIST_MODE |
|
- | 387 | jne quit |
|
335 | mcall 58,outfile |
388 | mcall 58,outfile |
- | 389 | .pad: |
|
336 | call StartPad |
390 | call StartPad |
337 | .notar: |
391 | .notar: |
338 | Msg 12 |
392 | Msg 12 |
339 | call RunViewer |
393 | call RunViewer |
340 | and [arc_base],0 |
394 | and [arc_base],0 |
Line 350... | Line 404... | ||
350 | if SYS eq win |
404 | if SYS eq win |
351 | jz quit |
405 | jz quit |
352 | else |
406 | else |
353 | jz still |
407 | jz still |
354 | end if |
408 | end if |
- | 409 | ; Dump output,255,os_work |
|
- | 410 | ; ud2 |
|
355 | mov ecx,dumpf_len |
411 | ; mov ecx,dumpf_len |
356 | mov esi,dumpfile |
412 | ; mov esi,dumpfile |
357 | mov edi,filename |
413 | ; mov edi,filename |
358 | rep movsb |
414 | ; rep movsb |
359 | call OpenFile |
415 | ; call OpenFile |
360 | test ebx,ebx |
416 | ; test ebx,ebx |
361 | jz again.sizebadq |
417 | ; jz again.sizebadq |
362 | call TarParse |
418 | call TarParse |
363 | mov ecx,[FileNum] |
419 | mov ecx,[FileNum] |
364 | call TarFindN |
420 | call TarFindN |
- | 421 | ; dpd [outfile.size] |
|
365 | cmp [outfile.size],0 |
422 | cmp [outfile.size],0 |
366 | jz again.sizebadq |
423 | jz again.sizebadq |
367 | mov ebx,esi |
424 | mov ebx,esi |
368 | jmp exit |
425 | jmp exit |