Rev 111 | 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 | ; |
||
7 | ; Last changed: July 14, 2005 |
||
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 |
||
31 | halyavin | 16 | DUMPFILE equ '/hd/1/out.txt' |
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 |
65 | dd main_stack;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 |
||
113 | mcall 40,10000101b |
||
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 |
||