Rev 134 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
131 | diamond | 1 | ; @RCHER - Deflate unpacker v2.0 beta |
31 | halyavin | 2 | ; |
3 | ; Written in pure assembler by Ivushkin Andrey aka Willow |
||
4 | ; |
||
5 | ; Created: May 6, 2005 |
||
6 | ; |
||
139 | diamond | 7 | ; Last changed: August 26, 2006 |
31 | halyavin | 8 | ; |
9 | ; Compile with FASM |
||
10 | |||
11 | SYS equ meos |
||
131 | diamond | 12 | OUTBUF equ 4*1024*1024 |
13 | png_imag = output+OUTBUF |
||
14 | PARAM_PTR = os_work;png_image |
||
15 | MEMINIT=next_code;output |
||
139 | diamond | 16 | DUMPFILE equ '/hd0/1/out.txt' |
31 | halyavin | 17 | |
18 | SHOW_RBLOCK equ 0;1 |
||
19 | SHOW_PNG_SEC equ 0;1 |
||
20 | SHOW_METH equ 0;1 |
||
131 | diamond | 21 | FILE_NUM equ 15;8 |
31 | halyavin | 22 | MEMORY equ 0x800000 |
23 | |||
24 | BITS equ 16 |
||
25 | BUFSIZE equ 32 |
||
26 | BUFPTR equ area |
||
27 | |||
28 | PASSW_LEN equ 32 |
||
29 | NO_STOPS equ 1 |
||
30 | SHOW_CHARS equ 0 |
||
31 | BSIZE equ 512 |
||
32 | INBUF equ BUFSIZE*BSIZE*2 |
||
33 | IGNORE_DIRS equ 0 |
||
34 | |||
35 | MOVE_SLINE_LEV equ 8 |
||
36 | |||
37 | DECRYPT_MODE equ 100b |
||
38 | PNG_MODE equ 10b |
||
39 | TAR_MODE equ 1000b |
||
40 | STAY_MODE equ 10000b |
||
41 | IPC_MODE equ 100000b |
||
42 | RAW_MODE equ 1000000b |
||
43 | THREAD_YES equ 10000000b |
||
131 | diamond | 44 | LIST_MODE equ 100000000b |
45 | MEM_MODE equ 1000000000b |
||
46 | FIND_MODE equ 10000000000b |
||
31 | halyavin | 47 | |
48 | if SYS eq win |
||
49 | format PE console |
||
50 | entry start |
||
51 | ;match =win,SYS |
||
52 | ;{ |
||
53 | ; include 'D:\Ivushkin\projects\fasmw\INCLUDE\win32a.inc' |
||
54 | ;} |
||
55 | else |
||
56 | use32 |
||
57 | |||
58 | org 0x0 |
||
59 | |||
60 | db 'MENUET01' |
||
61 | dd 0x01 |
||
62 | dd start |
||
63 | dd I_END |
||
131 | diamond | 64 | dd MEMINIT |
139 | diamond | 65 | dd main_stack_top;MEMORY-2048 |
31 | halyavin | 66 | if PARAM_PTR eq param |
67 | dd 0 |
||
68 | else |
||
69 | dd PARAM_PTR |
||
70 | end if |
||
71 | dd 0x0 |
||
72 | |||
73 | if PARAM_PTR eq param |
||
131 | diamond | 74 | param db 'N' |
75 | db '000015' |
||
76 | db '/hd/1/zip/gz/fasm-1~1.tgz',0 |
||
31 | halyavin | 77 | end if |
78 | ;match =meos,SYS |
||
79 | ;{ |
||
80 | include "macros.inc" |
||
81 | ; purge mov |
||
82 | include "debug.inc" |
||
131 | diamond | 83 | include 'dump.inc' |
31 | halyavin | 84 | ;} |
85 | end if |
||
86 | |||
131 | diamond | 87 | include 'lang.inc' |
88 | language equ lang |
||
31 | halyavin | 89 | |
90 | if SYS eq win |
||
91 | section '.text' code readable executable writeable |
||
92 | end if |
||
131 | diamond | 93 | |
31 | halyavin | 94 | include "arcmacro.inc" |
95 | include "parser.inc" |
||
96 | include "deflate.inc" |
||
97 | include "sys.inc" |
||
98 | |||
99 | FileNum dd FILE_NUM |
||
100 | ;FNAME equ '/hd/1/zip/pngsuite/s01n3p01.png' |
||
101 | |||
102 | start: |
||
103 | if SYS eq win |
||
104 | invoke GetStdHandle, STD_OUTPUT_HANDLE |
||
105 | mov [cons],eax |
||
106 | invoke GetStdHandle, STD_INPUT_HANDLE |
||
107 | mov [cons_in],eax |
||
108 | Msg 0 |
||
109 | Msg 1 |
||
110 | else |
||
111 | Msg 0 |
||
112 | Msg 1 |
||
134 | diamond | 113 | mcall 40,1000101b |
31 | halyavin | 114 | ; jmp again |
115 | CmdLine |
||
131 | diamond | 116 | cmdl: |
117 | test [Flags],LIST_MODE |
||
118 | jz red |
||
119 | |||
120 | ; Dump [lpath],[lpath_len],os_work |
||
121 | ; ud2 |
||
31 | halyavin | 122 | red: |
123 | call draw_window |
||
124 | mcall 12,2 |
||
125 | |||
126 | still: |
||
127 | mcall 10 |
||
128 | cmp eax,1 |
||
129 | je red |
||
130 | cmp eax,2 |
||
131 | jne .nokey |
||
132 | mcall 2 |
||
133 | cmp ah,9 |
||
134 | jz quit |
||
135 | jmp still |
||
136 | .nokey: |
||
137 | cmp eax,3 |
||
138 | jne still |
||
139 | mcall 17 |
||
140 | cmp ah,1 |
||
141 | jne still |
||
142 | mcall 23,30 |
||
143 | cmp eax,3 |
||
144 | jne .noquit |
||
145 | call KillViewer |
||
146 | mcall -1 |
||
147 | .noquit: |
||
148 | mcall 17 |
||
131 | diamond | 149 | mcall 64,1,MEMINIT |
31 | halyavin | 150 | QueryFile |
131 | diamond | 151 | mov [FileNum],FILE_NUM |
31 | halyavin | 152 | test eax,eax |
153 | jnz still |
||
154 | end if |
||
155 | again: |
||
131 | diamond | 156 | ; Dump Flags,4,os_work |
157 | mov [fat_],fat |
||
31 | halyavin | 158 | Newline |
159 | xor eax,eax |
||
160 | ; and [Flags],STAY_MODE |
||
161 | and [CRC32],eax |
||
162 | and [IDATsize],eax |
||
163 | mov [Adler32],1 |
||
164 | call OpenFile |
||
165 | test ebx,ebx |
||
166 | jnz .sizeok2 |
||
167 | .sizebad2: |
||
168 | Msg 14 |
||
169 | jmp quit |
||
170 | .sizeok2: |
||
131 | diamond | 171 | call KillViewer |
172 | xor eax,eax |
||
173 | mov ecx,(child_stack-fat)/4 |
||
174 | mov edi,fat |
||
175 | rep stosd |
||
31 | halyavin | 176 | mov [filesize],ebx |
177 | test [Flags],RAW_MODE |
||
178 | jz .norawm |
||
179 | mov eax,[arc_base] |
||
180 | xor ebx,ebx |
||
181 | call FileSeek |
||
182 | jmp .sizeok |
||
183 | .norawm: |
||
184 | call SfxParse |
||
185 | |||
186 | call ZipParse |
||
187 | cmp edx,52 |
||
188 | je .notzip |
||
189 | mov ecx,[FileNum] |
||
190 | call ZipFindN |
||
191 | cmp edx,4 |
||
192 | je quit |
||
193 | test [Flags],DECRYPT_MODE |
||
194 | jz .nopass |
||
195 | call ZipDecrypt |
||
196 | push esi |
||
197 | mov ecx,31 |
||
198 | ._: |
||
199 | mov al,[esi] |
||
200 | push eax |
||
201 | call decrypt_byte |
||
202 | xor al,byte[esp] |
||
203 | add esp,4 |
||
204 | call UKeys |
||
205 | mov [esi],al |
||
206 | inc esi |
||
207 | loop ._ |
||
208 | pop esi |
||
209 | ud2 |
||
210 | .nopass: |
||
211 | cmp [unp_size],0 |
||
212 | jne .sizeok |
||
213 | .sizebadq: |
||
214 | Msg 13 |
||
215 | jmp quit |
||
216 | .notzip: |
||
217 | call GzipParse |
||
218 | test edx,edx |
||
219 | jne .notgzip |
||
220 | jmp .sizeok |
||
221 | .notgzip: |
||
222 | call PngParse |
||
223 | test edx,edx |
||
224 | jz .sizeok1 |
||
225 | cmp edx,21 |
||
226 | je .sizebad |
||
227 | test [Flags],RAW_MODE |
||
228 | jne .sizeok |
||
229 | Msg 40 |
||
230 | jmp exit |
||
231 | .sizebad: |
||
232 | Msg 17 |
||
233 | jmp exit |
||
234 | .sizeok1: |
||
235 | if ~ SYS eq win |
||
236 | end if |
||
131 | diamond | 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 |
||
250 | Msg 41 |
||
251 | jmp exit |
||
252 | .ok: |
||
31 | halyavin | 253 | mov edi,[outp] |
254 | call Deflate.blkbegin |
||
255 | jmp .defl_end |
||
256 | .sizeok: |
||
131 | diamond | 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: |
||
31 | halyavin | 267 | call Deflate ; <=========== |
268 | .defl_end: |
||
269 | test [bits],7 |
||
270 | jnz .esi_ok |
||
271 | dec esi |
||
272 | .esi_ok: |
||
273 | push dword[esi] ; <- Adler !!! |
||
274 | mov esi,output |
||
275 | sub edi,esi |
||
276 | mov ecx,edi |
||
277 | mov [outfile.size],ecx |
||
278 | test [Flags],RAW_MODE |
||
279 | jnz .skipAdler |
||
280 | test [Flags],PNG_MODE |
||
281 | jnz .skipCRC |
||
282 | push esi ecx |
||
283 | call UCRC |
||
284 | Msg 11 |
||
285 | mov eax,[CRC32] |
||
286 | mov edx,36 |
||
287 | cmp eax,[CRC_check] |
||
288 | je .crcok |
||
289 | dec edx |
||
290 | .crcok: |
||
291 | Msg edx |
||
292 | if SYS eq win |
||
293 | else |
||
294 | dph eax |
||
295 | end if |
||
296 | pop ecx esi |
||
297 | jmp .skipAdler |
||
298 | .skipCRC: |
||
131 | diamond | 299 | ; dps 'Out=' |
300 | ; dpd ecx |
||
31 | halyavin | 301 | call UAdler |
302 | Msg 10 |
||
303 | mov eax,[Adler32] |
||
304 | bswap eax ; <- calculated Adler !!! |
||
305 | mov edx,36 |
||
306 | cmp eax,[esp] |
||
307 | je .adlok |
||
308 | dec edx |
||
309 | .adlok: |
||
310 | Msg edx |
||
311 | if SYS eq win |
||
312 | else |
||
313 | dph eax |
||
314 | end if |
||
315 | .skipAdler: |
||
316 | pop eax |
||
317 | Newline |
||
318 | .nomoreIDAT: |
||
319 | mov ebx,output |
||
320 | if SYS eq win |
||
321 | Msg 37 |
||
322 | invoke CloseHandle, [hnd] |
||
323 | |||
324 | invoke CreateFile,dumpfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \ |
||
325 | CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL |
||
326 | mov [hnd],eax |
||
327 | invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL |
||
328 | invoke CloseHandle, [hnd] |
||
329 | else |
||
330 | test [Flags],PNG_MODE |
||
331 | jnz .nosave |
||
131 | diamond | 332 | test [Flags],LIST_MODE |
333 | jnz quit |
||
334 | |||
31 | halyavin | 335 | test [Flags],TAR_MODE |
336 | jnz .nomsg |
||
337 | Msg 37 |
||
338 | .nomsg: |
||
339 | mov [outfile.out],ebx |
||
139 | diamond | 340 | mcall 70,outfile |
131 | diamond | 341 | ; dps 'Before Quit1' |
342 | ; ud2 |
||
31 | halyavin | 343 | test [Flags],TAR_MODE |
131 | diamond | 344 | jz exit.pad |
345 | ; call StartPad |
||
31 | halyavin | 346 | .nosave: |
347 | end if |
||
348 | test [Flags],PNG_MODE |
||
349 | jz NoPng |
||
350 | xor eax,eax |
||
351 | mov edi,filters |
||
352 | mov ecx,6 |
||
353 | rep stosd |
||
131 | diamond | 354 | mov edi,[png_] |
31 | halyavin | 355 | mov esi,output |
356 | ;// |
||
357 | mov [outp],edi |
||
358 | ;// |
||
359 | call PngFilter |
||
360 | call FiltStats |
||
361 | mov [outfile.size],edi |
||
362 | mov ebx,[outp];png_image |
||
363 | if SYS eq win |
||
131 | diamond | 364 | exit: |
31 | halyavin | 365 | Msg 12 |
366 | invoke CreateFile,outfile,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, \ |
||
367 | CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL |
||
368 | mov [hnd],eax |
||
369 | invoke WriteFile, eax,ebx,[outfile.size],cparam1,NULL |
||
370 | invoke CloseHandle, [hnd] |
||
131 | diamond | 371 | call RunViewer |
372 | and [arc_base],0 |
||
31 | halyavin | 373 | and [Flags],STAY_MODE |
131 | diamond | 374 | ; dps 'Before Quit2' |
375 | quit: |
||
31 | halyavin | 376 | QueryFile |
377 | test eax,eax |
||
378 | jnz again |
||
379 | invoke ExitProcess,0 |
||
380 | else |
||
131 | diamond | 381 | exit: |
31 | halyavin | 382 | mov [outfile.out],ebx |
383 | test [Flags],TAR_MODE |
||
384 | jz .notar |
||
385 | Msg 37 |
||
131 | diamond | 386 | test [Flags],LIST_MODE |
387 | jne quit |
||
139 | diamond | 388 | mcall 70,outfile |
131 | diamond | 389 | .pad: |
31 | halyavin | 390 | call StartPad |
131 | diamond | 391 | .notar: |
31 | halyavin | 392 | Msg 12 |
131 | diamond | 393 | call RunViewer |
394 | and [arc_base],0 |
||
31 | halyavin | 395 | and [Flags],STAY_MODE |
396 | quit: |
||
397 | test [Flags],STAY_MODE |
||
398 | jnz red |
||
399 | mcall -1 |
||
400 | end if |
||
401 | |||
402 | NoPng: |
||
403 | test [Flags],TAR_MODE |
||
404 | if SYS eq win |
||
405 | jz quit |
||
406 | else |
||
407 | jz still |
||
408 | end if |
||
131 | diamond | 409 | ; Dump output,255,os_work |
410 | ; ud2 |
||
411 | ; mov ecx,dumpf_len |
||
412 | ; mov esi,dumpfile |
||
413 | ; mov edi,filename |
||
414 | ; rep movsb |
||
415 | ; call OpenFile |
||
416 | ; test ebx,ebx |
||
417 | ; jz again.sizebadq |
||
31 | halyavin | 418 | call TarParse |
419 | mov ecx,[FileNum] |
||
420 | call TarFindN |
||
131 | diamond | 421 | ; dpd [outfile.size] |
31 | halyavin | 422 | cmp [outfile.size],0 |
423 | jz again.sizebadq |
||
424 | mov ebx,esi |
||
425 | jmp exit |
||
426 | |||
427 | if ~ SYS eq win |
||
428 | draw_window: |
||
429 | mcall 12,1 |
||
430 | mov ebx,15 |
||
431 | mov ecx,ebx |
||
432 | mov edx,0x0e26830 |
||
433 | mov edi,edx |
||
434 | mcall 0,,,,0x1f2a870 |
||
435 | mcall 8,,,1+1 shl 30 |
||
436 | mcall 4,<6,5>,0x10d0d0d0,msgs+5,1 |
||
437 | mcall ,<5,5>,0x10202020 |
||
438 | ret |
||
439 | end if |
||
440 | |||
441 | include 'data.inc' |
||
442 | |||
443 | if SYS eq win |
||
444 | section '.idata' import data readable writeable |
||
445 | |||
446 | library kernel,'KERNEL32.DLL',\ |
||
447 | comdlg,'COMDLG32.DLL',\ |
||
448 | user,'USER32.DLL' |
||
449 | |||
450 | import kernel,\ |
||
451 | CreateFile,'CreateFileA',\ |
||
452 | GetFileSize,'GetFileSize',\ |
||
453 | ReadFile,'ReadFile',\ |
||
454 | WriteFile,'WriteFile',\ |
||
455 | SetFilePointer,'SetFilePointer',\ |
||
456 | CloseHandle,'CloseHandle',\ |
||
131 | diamond | 457 | GetStdHandle,'GetStdHandle',\ |
458 | WriteConsole,'WriteConsoleA',\ |
||
459 | ReadConsole,'ReadConsoleA',\ |
||
460 | CreateProcess,'CreateProcessA',\ |
||
461 | WritePrivateProfileString,'WritePrivateProfileStringA',\ |
||
462 | ExitProcess,'ExitProcess' |
||
31 | halyavin | 463 | |
464 | import comdlg,\ |
||
465 | GetOpenFileName,'GetOpenFileNameA' |
||
466 | |||
467 | import user,\ |
||
131 | diamond | 468 | wsprintf,'wsprintfA',\ |
469 | SendMessage,'SendMessageA',\ |
||
470 | FindWindowEx,'FindWindowExA',\ |
||
471 | WaitForInputIdle,'WaitForInputIdle' |
||
472 | |||
31 | halyavin | 473 | |
474 | section '.reloc' fixups data readable discardable |
||
475 | end if |
||
476 | |||
477 | if ~ SYS in |
||
478 | error "Please specify SYS: meos OR win" |
||
479 | end if5,5>6,5>->->=========== |
||
480 | |||
481 |