Subversion Repositories Kolibri OS

Rev

Rev 111 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 111 Rev 131
1
; @RCHER parser and filter routines
1
; @RCHER parser and filter routines
2
; Written in pure assembler by Ivushkin Andrey aka Willow
2
; Written in pure assembler by Ivushkin Andrey aka Willow
3
 
3
 
4
  fhs_local   equ 0x04034b50
4
  fhs_local   equ 0x04034b50
5
  fhs_central equ 0x02014b50
5
  fhs_central equ 0x02014b50
6
  fhs_end     equ 0x06054b50
6
  fhs_end     equ 0x06054b50
7
  fhs_enc     equ 0x08074b50
7
  fhs_enc     equ 0x08074b50
8
 
8
 
9
SkipASCIIZ:
9
SkipASCIIZ:
10
    xor  eax,eax
10
    xor  eax,eax
11
    mov  ecx,255
11
    mov  ecx,255
12
    mov  edi,esi
12
    mov  edi,esi
13
    repne scasb
13
    repne scasb
14
    mov  esi,edi
14
    mov  esi,edi
15
    ret
15
    ret
16
 
16
 
17
PrintFilename:
17
PrintFilename:
18
    pusha
18
    pusha
19
    mov  esi,edx
19
    mov  esi,edx
20
    mov  edi,os_work
20
    mov  edi,os_work
21
    mov  edx,edi
21
    mov  edx,edi
22
    rep  movsb
22
    rep  movsb
23
    mov  dword[edi],0x00a0d
23
    mov  dword[edi],0x00a0d
24
    call DebugPrint
24
    call DebugPrint
25
;    mcall 10
-
 
26
;    mcall 2
-
 
27
    popa
25
    popa
-
 
26
    call Add2Fat
28
    ret
27
    ret
-
 
28
 
-
 
29
Add2Fat:
-
 
30
; edx - ptr, ecx - len
-
 
31
 
-
 
32
    pusha
-
 
33
    test [Flags],LIST_MODE
-
 
34
    jz   .ex
-
 
35
    mov  ebp,8
-
 
36
    mov  edi,edx
-
 
37
    lea  ebx,[edx+ecx]
-
 
38
    mov  ecx,[lpath_len]
-
 
39
    cmp  ecx,1
-
 
40
    je   .lbl
-
 
41
    mov  esi,[lpath]
-
 
42
    repe cmpsb
-
 
43
    jne  .full
-
 
44
    mov  eax,[lpath_len]
-
 
45
    sub  dword[esp+24],eax;path_len-path
-
 
46
    cmp  edi,ebx
-
 
47
    je   .full
-
 
48
    mov  edx,edi
-
 
49
  .lbl:
-
 
50
    mov  ecx,[esp+24]
-
 
51
    mov  al,'/'
-
 
52
    repne scasb
-
 
53
    mov  eax,[fat_]
-
 
54
    mov  ecx,[esp+24]
-
 
55
    jne  .nofol
-
 
56
    cmp  edi,ebx
-
 
57
    jne  .full
-
 
58
    lea  ecx,[edi-1]
-
 
59
    sub  ecx,edx
-
 
60
    or   byte[eax+11],0x10
-
 
61
;    sub  edx,ecx
-
 
62
  .nofol:
-
 
63
 
-
 
64
    push [fat_fnum]
-
 
65
    pop  dword[eax+12]
-
 
66
    mov  edi,eax
-
 
67
    mov  esi,edx
-
 
68
  .lp1:
-
 
69
 
-
 
70
    mov  bl,[esi]
-
 
71
    lea  edx,[eax+ebp]
-
 
72
    inc  esi
-
 
73
    cmp  bl,'.'
-
 
74
    jne  .nodot
-
 
75
    lea  edi,[eax+ebp]
-
 
76
    mov  ebp,11
-
 
77
    jmp  .ll
-
 
78
  .nodot:
-
 
79
    cmp  edi,edx
-
 
80
    jae  .ll
-
 
81
    mov  [edi],bl
-
 
82
    inc  edi
-
 
83
  .ll:
-
 
84
    loop .lp1
-
 
85
    mov  ecx,11
-
 
86
    dec  eax
-
 
87
  .lp2:
-
 
88
    cmp  byte[eax+ecx],0
-
 
89
    jne  .no0
-
 
90
    mov  byte[eax+ecx],' '
-
 
91
  .no0:
-
 
92
    loop .lp2
-
 
93
    cmp  eax,child_stack-1
-
 
94
    jae  .full
-
 
95
    add  [fat_],32
-
 
96
  .full:
-
 
97
    inc  [fat_fnum]
-
 
98
  .ex:
-
 
99
    popa
-
 
100
    ret
-
 
101
 
-
 
102
;path db '/';'fasm/examples/elfexe/'
29
 
103
;path_len:
30
 
104
 
31
; Parse routines:
105
; Parse routines:
32
;   out: edx= 0 if all ok, 1 - central dir, 2-EOD
106
;   out: edx= 0 if all ok, 1 - central dir, 2-EOD
33
;             50 - encrypted
107
;             50 - encrypted
34
;             51 - not deflated
108
;             51 - not deflated
35
;             52 - invalid format
109
;             52 - invalid format
36
;             53 - dir skipped
110
;             53 - dir skipped
37
;             1 - encrypted
111
;             1 - encrypted
38
 
112
 
39
; ****************************************************
113
; ****************************************************
40
ZipParse:
114
ZipParse:
41
 
115
 
42
    call ResetFile
116
    call ResetFile
43
  .nxt:
117
  .nxt:
44
    call ZipCrawl
118
    call ZipCrawl
45
 
119
 
46
    cmp  edx,3
120
    cmp  edx,3
47
    je  .ex
121
    je  .ex
48
    cmp  edx,1
122
    cmp  edx,1
49
    je   .skipinc
123
    je   .skipinc
50
if  IGNORE_DIRS eq 1
124
if  IGNORE_DIRS eq 1
51
    cmp  edx,53
125
    cmp  edx,53
52
    jne  .skipinc
126
    jne  .skipinc
53
end if
127
end if
54
    inc  [file_count]
128
    inc  [file_count]
55
  .skipinc:
129
  .skipinc:
56
    cmp  edx,52
130
    cmp  edx,52
57
    je   .er1
131
    je   .er1
58
    cmp  edx,50
132
    cmp  edx,50
59
    jne   .seek
133
    jne   .seek
60
  .er1:
134
  .er1:
61
    Msg  edx
135
    Msg  edx
62
    ret
136
    ret
63
  .seek:
137
  .seek:
64
    add  eax,ecx
138
    add  eax,ecx
65
    mov  ebx,1
139
    mov  ebx,1
66
    call FileSeek
140
    call FileSeek
67
    jmp  .nxt
141
    jmp  .nxt
68
  .ex:
142
  .ex:
69
    Msg  2
143
    Msg  2
70
    mov  eax,[file_count]
144
    mov  eax,[file_count]
71
 if ~ SYS eq win
145
 if ~ SYS eq win
72
    dpd  eax
146
    dpd  eax
73
 else
147
 else
74
    pusha
148
    pusha
75
    call  int2str
149
    call  int2str
76
    mov   edx,os_work
150
    mov   edx,os_work
77
   	call  DebugPrint
151
   	call  DebugPrint
78
   	popa
152
   	popa
79
 end if
153
 end if
80
    Newline
154
    Newline
-
 
155
;    Dump fat,160,os_work
81
    ret
156
    ret
82
 
157
 
83
ZipFindN:
158
ZipFindN:
84
; ecx - file #
159
; ecx - file #
85
    Msg 33
160
    Msg 33
-
 
161
    or   [Flags],FIND_MODE
86
    cmp  ecx,[file_count]
162
    cmp  ecx,[file_count]
87
    jae  .err
163
    jae  .err
88
    push ecx
164
    push ecx
89
    call ResetFile
165
    call ResetFile
90
  .nxt:
166
  .nxt:
-
 
167
 
91
    call ZipCrawl
168
    call ZipCrawl
92
    cmp  edx,51
169
    cmp  edx,51
93
    je   .ok2
170
    je   .ok2
94
  .noenc:
171
  .noenc:
95
    test edx,edx
172
    test edx,edx
96
    jnz  .err
173
    jnz  .err
97
  .ok2:
174
  .ok2:
98
    add  eax,ecx
175
    add  eax,ecx
99
    cmp  dword[esp],0
176
    cmp  dword[esp],0
100
    jz   .ok
177
    jz   .ok
101
    dec  dword[esp]
178
    dec  dword[esp]
102
    mov  ebx,1
179
    mov  ebx,1
103
    call FileSeek
180
    call FileSeek
104
    jmp  .nxt
181
    jmp  .nxt
105
  .err:
182
  .err:
106
    mov  edx,4
183
    mov  edx,4
107
    jmp  .ex
184
    jmp  .ex
108
  .ok:
185
  .ok:
109
    pop  ecx
186
    pop  ecx
110
    sub  eax,[esi+18]
187
    sub  eax,[esi+18]
111
    add  esi,eax
188
    add  esi,eax
112
    mov  edx,5
189
    mov  edx,5
113
  .ex:
190
  .ex:
-
 
191
    and   [Flags],-1-FIND_MODE
114
    push edx
192
    push edx
115
    Msg  edx
193
    Msg  edx
116
    pop  edx
194
    pop  edx
117
    ret
195
    ret
118
 
196
 
119
ZipCrawl:
197
ZipCrawl:
120
    mov  edx,52
198
    mov  edx,52
121
    cmp  dword[esi],fhs_central
199
    cmp  dword[esi],fhs_central
122
    jne  .noc
200
    jne  .noc
123
    mov  eax,46
201
    mov  eax,46
124
    movzx ecx,word[esi+28]
202
    movzx ecx,word[esi+28]
125
    add  eax,ecx
203
    add  eax,ecx
126
    movzx ecx,word[esi+30]
204
    movzx ecx,word[esi+30]
127
    add  eax,ecx
205
    add  eax,ecx
128
    movzx ecx,word[esi+32]
206
    movzx ecx,word[esi+32]
129
    mov  edx,1
207
    mov  edx,1
130
    ret
208
    ret
131
  .noc:
209
  .noc:
132
    cmp  dword[esi],fhs_end
210
    cmp  dword[esi],fhs_end
133
    jne  .noe
211
    jne  .noe
134
  .edx3:
212
  .edx3:
135
    Msg 3
213
    Msg 3
136
    mov  edx,3
214
    mov  edx,3
137
    ret
215
    ret
138
  .noe:
216
  .noe:
139
    cmp  dword[esi],fhs_local
217
    cmp  dword[esi],fhs_local
140
    je   .loc
218
    je   .loc
141
    cmp  dword[esi],fhs_enc
219
    cmp  dword[esi],fhs_enc
142
    jne  .err
220
    jne  .err
143
    mov  eax,16
221
    mov  eax,16
144
    xor  ecx,ecx
222
    xor  ecx,ecx
145
    mov  edx,1
223
    mov  edx,1
146
    ret
224
    ret
147
  .loc:
225
  .loc:
148
    push word[esi+6]
226
    push word[esi+6]
149
    pop  [gpbf]
227
    pop  [gpbf]
150
    push dword[esi+14]
228
    push dword[esi+14]
151
    pop  [CRC_check]
229
    pop  [CRC_check]
152
    push dword[esi+22]
230
    push dword[esi+22]
153
    pop  [unp_size]
231
    pop  [unp_size]
154
    movzx ecx,word[esi+26]
232
    movzx ecx,word[esi+26]
155
    mov  eax,30
233
    mov  eax,30
156
    lea  edx,[esi+eax]
234
    lea  edx,[esi+eax]
157
    add  eax,ecx
235
    add  eax,ecx
158
if  IGNORE_DIRS eq 1
236
if  IGNORE_DIRS eq 1
159
    cmp  byte[edx+ecx-1],'/'
237
    cmp  byte[edx+ecx-1],'/'
160
    je   .skipdp
238
    je   .skipdp
161
end if
239
end if
-
 
240
    test [Flags],FIND_MODE
-
 
241
    jnz  .skipdp
162
    call PrintFilename
242
    call PrintFilename
163
  .skipdp:
243
  .skipdp:
164
    movzx ecx,word[esi+28]
244
    movzx ecx,word[esi+28]
165
    add  eax,[esi+18]
245
    add  eax,[esi+18]
166
    test [gpbf],1
246
    test [gpbf],1
167
    jz   .no_enc
247
    jz   .no_enc
168
    or   [Flags],DECRYPT_MODE  ; encrypted
248
    or   [Flags],DECRYPT_MODE  ; encrypted
169
    mov  edx,51
249
    mov  edx,51
170
    jmp  .err
250
    jmp  .err
171
  .no_enc:
251
  .no_enc:
172
    test word[esi+8],7
252
    test word[esi+8],7
173
    rep_err z,50
253
    rep_err z,50
174
  .ok:
254
  .ok:
175
    xor  edx,edx
255
    xor  edx,edx
176
  .err:
256
  .err:
177
    ret
257
    ret
178
 
258
 
179
; ***********************************************
259
; ***********************************************
180
GzipParse:
260
GzipParse:
181
    ID1ID2 equ 0x8b1f
261
    ID1ID2 equ 0x8b1f
182
    FTEXT equ 1b
262
    FTEXT equ 1b
183
    FHCRC equ 10b
263
    FHCRC equ 10b
184
    FEXTRA equ 100b
264
    FEXTRA equ 100b
185
    FNAME equ 1000b
265
    FNAME equ 1000b
186
    FCOMMENT equ 10000b
266
    FCOMMENT equ 10000b
187
    mov  eax,7
267
    mov  eax,7
188
    mov  ebx,2
268
    mov  ebx,2
189
    call FileSeek
269
    call FileSeek
190
    push dword[esi]
270
    push dword[esi]
191
    pop  [CRC_check]
271
    pop  [CRC_check]
192
    push dword[esi+4]
272
    push dword[esi+4]
193
    pop  [unp_size]
273
    pop  [unp_size]
194
    call ResetFile
274
    call ResetFile
195
    xor  edx,edx
275
    xor  edx,edx
196
    cmp  word[esi],ID1ID2
276
    cmp  word[esi],ID1ID2
197
    rep_err e, 52, 15
277
    rep_err e, 52, 15
198
    cmp  byte[esi+2],8
278
    cmp  byte[esi+2],8
199
    rep_err e, 52, 50
279
    rep_err e, 52, 50
200
    mov  bl,[esi+3]  ; bl - FLG
280
    mov  bl,[esi+3]  ; bl - FLG
201
    add  esi,10 ; esi->extra
281
    add  esi,10 ; esi->extra
202
    test bl,FEXTRA
282
    test bl,FEXTRA
203
    jz   .noextr
283
    jz   .noextr
204
    movzx eax,word[esi]
284
    movzx eax,word[esi]
205
    lea  esi,[esi+eax+2] ; esi->FNAME
285
    lea  esi,[esi+eax+2] ; esi->FNAME
206
  .noextr:
286
  .noextr:
207
    test bl,FNAME
287
    test bl,FNAME
208
    jz   .nofname
288
    jz   .nofname
209
    mov  edx,esi
289
    mov  edx,esi
210
    call DebugPrint
290
    call DebugPrint
211
    call SkipASCIIZ
291
    call SkipASCIIZ
212
    cmp  dword[esi-5],'.tar'
292
    cmp  dword[esi-5],'.tar'
213
    jne  .nofname
293
    jne  .nofname
214
    or   [Flags],TAR_MODE
294
    or   [Flags],TAR_MODE
215
  .nofname:     ; esi->FCOMMENT
295
  .nofname:     ; esi->FCOMMENT
216
    test bl,FCOMMENT
296
    test bl,FCOMMENT
217
    jz   .nocomm
297
    jz   .nocomm
218
    call SkipASCIIZ
298
    call SkipASCIIZ
219
  .nocomm:      ; esi->HCRC
299
  .nocomm:      ; esi->HCRC
220
    test bl,FHCRC
300
    test bl,FHCRC
221
    jz   .noCRC16
301
    jz   .noCRC16
222
    add  esi,2
302
    add  esi,2
223
  .noCRC16:
303
  .noCRC16:
224
    cmp  [unp_size],OUTBUF
304
    cmp  [unp_size],OUTBUF
225
    jb   .sizeok2
305
    jb   .sizeok2
226
    Msg  16
306
    Msg  16
227
    mov  edx,15
307
    mov  edx,15
228
    ret
308
    ret
229
  .sizeok2:
309
  .sizeok2:
230
    xor  edx,edx
310
    xor  edx,edx
231
  .err:
311
  .err:
232
    ret
312
    ret
233
 
313
 
234
PngParse:
314
PngParse:
235
    ID1 equ 0x474e5089
315
    ID1 equ 0x474e5089
236
    ID2 equ 0x0a1a0a0d
316
    ID2 equ 0x0a1a0a0d
237
    FDICT equ 100000b
317
    FDICT equ 100000b
238
    InitIDAT equ 2
318
    InitIDAT equ 2
239
    mov  [IDATcount],InitIDAT
319
    mov  [IDATcount],InitIDAT
240
    call ResetFile
320
    call ResetFile
241
    cmp  dword[esi],ID1
321
    cmp  dword[esi],ID1
242
    rep_err e, 52, 18
322
    rep_err e, 52, 18
243
    cmp  dword[esi+4],ID2
323
    cmp  dword[esi+4],ID2
244
    rep_err e, 52, 18
324
    rep_err e, 52, 18
245
    add  esi,8
325
    add  esi,8
246
    cmp  dword[esi+4],'IHDR'
326
    cmp  dword[esi+4],'IHDR'
247
    rep_err e,52, 18
327
    rep_err e,52, 18
248
    or   [Flags],PNG_MODE
328
    or   [Flags],PNG_MODE
249
    memcpy_esi PNG_info,13,8
329
    memcpy_esi PNG_info,13,8
250
    mov  eax,[PNG_info.Width]
330
    mov  eax,[PNG_info.Width]
251
    bswap eax
331
    bswap eax
252
    mov  [PNG_info.Width],eax
332
    mov  [PNG_info.Width],eax
253
    mov  eax,[PNG_info.Height]
333
    mov  eax,[PNG_info.Height]
254
    bswap eax
334
    bswap eax
-
 
335
    mov  ebx,eax
255
    mov  [PNG_info.Height],eax
336
    mov  [PNG_info.Height],eax
-
 
337
    call scanline_calc
-
 
338
;    dps  'All='
-
 
339
    cmp  [PNG_info.Color_type],3
-
 
340
    jne  .nopal
-
 
341
    shl  eax,3
-
 
342
    inc  eax
-
 
343
  .nopal:
-
 
344
    inc  eax
-
 
345
    imul eax,ebx
-
 
346
    mov  [unp_size],eax
-
 
347
;    dpd  eax
256
    add  esi,25
348
    add  esi,25
257
    cmp  byte[esi-5],0
349
    cmp  byte[esi-5],0
258
    rep_err e,52,29
350
    rep_err e,52,29
259
  .nxt_sec:
351
  .nxt_sec:
260
    lodsd
352
    lodsd
261
    bswap eax ; eax - section size
353
    bswap eax ; eax - section size
262
    push eax
354
    push eax
263
    lodsd
355
    lodsd
264
    mov  edi,Png_ch
356
    mov  edi,Png_ch
265
    mov  ecx,(E_ch-Png_ch) / 4
357
    mov  ecx,(E_ch-Png_ch) / 4
266
    repne scasd
358
    repne scasd
267
    pop  eax
359
    pop  eax
268
    mov  ebx,[esi-4]
360
    mov  ebx,[esi-4]
269
    mov  edx,os_work
361
    mov  edx,os_work
270
    mov  [edx],ebx
362
    mov  [edx],ebx
271
    mov  dword[edx+4],0x0a0d
363
    mov  dword[edx+4],0x0a0d
272
  .dp:
364
  .dp:
273
    sub  edi,Png_ch
365
    sub  edi,Png_ch
274
    shr  edi,2  ; edi- chunk #
366
    shr  edi,2  ; edi- chunk #
275
 if SHOW_PNG_SEC eq 1
367
 if SHOW_PNG_SEC eq 1
276
    call DebugPrint
368
    call DebugPrint
277
 end if
369
 end if
278
    cmp  edi,1
370
    cmp  edi,1
279
    jne  .noend
371
    jne  .noend
280
    mov  edx,21
372
    mov  edx,21
281
    jmp  .err
373
    jmp  .err
282
  .noend:
374
  .noend:
283
    cmp  edi,2
375
    cmp  edi,2
284
    jne  .noplte
376
    jne  .noplte
285
    memcpy_esi PNG_info.Palette,eax
377
    memcpy_esi PNG_info.Palette,eax
286
    jmp  .noidat
378
    jmp  .noidat
287
   .noplte:
379
   .noplte:
288
    cmp  edi,3
380
    cmp  edi,3
289
    jne  .noidat
381
    jne  .noidat
290
    mov  [IDATsize],eax
382
    mov  [IDATsize],eax
291
    cmp  [IDATcount],InitIDAT
383
    cmp  [IDATcount],InitIDAT
292
    jne  .ex
384
    jne  .ex
293
    mov  [bits],8
385
    mov  [bits],8
294
  if RBLOCK eq 4
386
  if RBLOCK eq 4
295
    lodsd
387
    lodsd
296
  else
388
  else
297
    lodsb
389
    lodsb
298
  end if
390
  end if
299
    call setcurb
391
    call setcurb
300
    rbits 0,16
392
    rbits 0,16
301
    test ah,FDICT
393
    test ah,FDICT
302
    jz   .ex
394
    jz   .ex
303
    rbits 0,32
395
    rbits 0,32
304
    add  [IDATcount],4
396
    add  [IDATcount],4
305
    jmp  .ex
397
    jmp  .ex
306
   .noidat:
398
   .noidat:
307
    add  eax,4
399
    add  eax,4
308
    mov  ebx,1
400
    mov  ebx,1
309
    call FileSeek
401
    call FileSeek
310
    jmp  .nxt_sec
402
    jmp  .nxt_sec
311
   .ex:
403
   .ex:
312
    xor  edx,edx
404
    xor  edx,edx
313
   .err:
405
   .err:
314
    ret
406
    ret
315
 
407
 
316
Png_ch:
408
Png_ch:
317
    dd 'IEND','PLTE','IDAT','????'
409
    dd 'IEND','PLTE','IDAT','????'
318
E_ch:
410
E_ch:
319
 
411
 
320
ZipDecrypt:
412
ZipDecrypt:
321
    push edi
413
    push edi
322
    mov  ecx,3
414
    mov  ecx,3
323
    mov  edi,Dheader
415
    mov  edi,Dheader
324
    rep  movsd
416
    rep  movsd
325
    pop  edi
417
    pop  edi
326
    call QueryPwd
418
    call QueryPwd
327
    jecxz .ex
419
    jecxz .ex
328
    push esi
420
    push esi
329
    mov  [DKeys],  305419896
421
    mov  [DKeys],  305419896
330
    mov  [DKeys+4],591751049
422
    mov  [DKeys+4],591751049
331
    mov  [DKeys+8],878082192
423
    mov  [DKeys+8],878082192
332
    xor  eax,eax
424
    xor  eax,eax
333
    mov  esi,Dpassword
425
    mov  esi,Dpassword
334
  .enc_init:
426
  .enc_init:
335
    lodsb
427
    lodsb
336
    call UKeys
428
    call UKeys
337
    loop .enc_init
429
    loop .enc_init
338
    mov  ecx,12
430
    mov  ecx,12
339
    mov  esi,Dheader
431
    mov  esi,Dheader
340
  .dec_header:
432
  .dec_header:
341
    call decrypt_byte
433
    call decrypt_byte
342
    xor  al,[esi]
434
    xor  al,[esi]
343
    call UKeys
435
    call UKeys
344
    mov  [esi],al
436
    mov  [esi],al
345
    inc  esi
437
    inc  esi
346
    loop .dec_header
438
    loop .dec_header
347
    mov  eax,[CRC_check]
439
    mov  eax,[CRC_check]
348
    pop  esi
440
    pop  esi
349
  .ex:
441
  .ex:
350
    ret
442
    ret
351
 
443
 
352
QueryPwd:
444
QueryPwd:
353
; out: ecx - passwd len
445
; out: ecx - passwd len
354
if  SYS eq win
446
if  SYS eq win
355
    Msg 32
447
    Msg 32
356
    invoke ReadConsole,[cons_in],Dpassword,PASSW_LEN,cparam1,NULL
448
    invoke ReadConsole,[cons_in],Dpassword,PASSW_LEN,cparam1,NULL
357
    test eax,eax
449
    test eax,eax
358
    jnz  .inp_ok
450
    jnz  .inp_ok
359
    xor  ecx,ecx
451
    xor  ecx,ecx
360
    jmp  .ex
452
    jmp  .ex
361
  .inp_ok:
453
  .inp_ok:
362
    mov  ecx,[cparam1]
454
    mov  ecx,[cparam1]
363
    cmp  ecx,PASSW_LEN
455
    cmp  ecx,PASSW_LEN
364
    je   .ex
456
    je   .ex
365
    sub  ecx,2
457
    sub  ecx,2
366
else
458
else
367
end if
459
end if
368
  .ex:
460
  .ex:
369
    ret
461
    ret
370
 
462
 
371
UKeys:
463
UKeys:
372
; in: al - char
464
; in: al - char
373
    pusha
465
    pusha
374
    mov  edi,134775813
466
    mov  edi,134775813
375
    mov  ebx,DKeys
467
    mov  ebx,DKeys
376
    mov  esi,os_work
468
    mov  esi,os_work
377
    mov  byte[esi],al
469
    mov  byte[esi],al
378
    mov  ecx,1
470
    mov  ecx,1
379
    push dword[ebx]
471
    push dword[ebx]
380
    pop  [CRC32]
472
    pop  [CRC32]
381
    call UCRC
473
    call UCRC
382
    push [CRC32]
474
    push [CRC32]
383
    pop  dword[ebx]
475
    pop  dword[ebx]
384
    mov  eax,[ebx]
476
    mov  eax,[ebx]
385
    and  eax,0xff
477
    and  eax,0xff
386
    add  eax,[ebx+4]
478
    add  eax,[ebx+4]
387
    mul  edi
479
    mul  edi
388
    inc  eax
480
    inc  eax
389
    mov  [ebx+4],eax
481
    mov  [ebx+4],eax
390
    shr  eax,24
482
    shr  eax,24
391
    mov  byte[esi],al
483
    mov  byte[esi],al
392
    push dword[ebx+8]
484
    push dword[ebx+8]
393
    pop  [CRC32]
485
    pop  [CRC32]
394
    call UCRC
486
    call UCRC
395
    push [CRC32]
487
    push [CRC32]
396
    pop  dword[ebx+8]
488
    pop  dword[ebx+8]
397
    popa
489
    popa
398
    ret
490
    ret
399
 
491
 
400
decrypt_byte:
492
decrypt_byte:
401
; out: al
493
; out: al
402
    push ebx edx
494
    push ebx edx
403
    movzx ebx,word[DKeys+8]
495
    movzx ebx,word[DKeys+8]
404
    or   ebx,2
496
    or   ebx,2
405
    mov  eax,ebx
497
    mov  eax,ebx
406
    xor  eax,1
498
    xor  eax,1
407
    mul  ebx
499
    mul  ebx
408
    shr  eax,8
500
    shr  eax,8
409
    pop  edx ebx
501
    pop  edx ebx
410
    ret
502
    ret
411
 
503
 
412
setcurb:
504
setcurb:
413
; in: eax
505
; in: eax
414
    test [Flags],DECRYPT_MODE
506
    test [Flags],DECRYPT_MODE
415
    jz   .noenc
507
    jz   .noenc
416
    push eax
508
    push eax
417
    call decrypt_byte
509
    call decrypt_byte
418
    xor  al,byte[esp]
510
    xor  al,byte[esp]
419
    add  esp,4
511
    add  esp,4
420
    call UKeys
512
    call UKeys
421
  .noenc:
513
  .noenc:
422
    mov  [cur_byte],eax
514
    mov  [cur_byte],eax
423
    ret
515
    ret
424
 
516
 
425
TarParse:
517
TarParse:
-
 
518
    mov  esi,output
426
    call ResetFile
519
;    call ResetFile
427
  .nxt:
520
  .nxt:
428
    call TarCrawl
521
    call TarCrawl
429
;    wait
522
;    wait
430
    cmp  edx,3
523
    cmp  edx,3
431
    je   ZipParse.ex
524
    je   ZipParse.ex
432
if  IGNORE_DIRS eq 1
525
if  IGNORE_DIRS eq 1
433
    cmp  edx,53
526
    cmp  edx,53
434
    jne  .skipinc
527
    jne  .skipinc
435
end if
528
end if
436
    inc  [file_count]
529
    inc  [file_count]
437
  .skipinc:
530
  .skipinc:
438
    add  eax,ecx
531
    add  eax,ecx
439
    mov  ebx,1
532
;    mov  ebx,1
-
 
533
    add  esi,eax
440
    call FileSeek
534
;    call FileSeek
441
    jmp  .nxt
535
    jmp  .nxt
442
 
536
 
443
TarFindN:
537
TarFindN:
444
; in:  ecx - file number
538
; in:  ecx - file number
445
; ecx - file #
539
; ecx - file #
446
    Msg 33
540
    Msg 33
447
    cmp  ecx,[file_count]
541
    cmp  ecx,[file_count]
448
    jae  .err
542
    jae  .err
449
    push ecx
543
    push ecx
-
 
544
    mov  esi,output
450
    call ResetFile
545
;    call ResetFile
451
  .nxt:
546
  .nxt:
452
    call TarCrawl
547
    call TarCrawl
453
if  IGNORE_DIRS eq 1
548
if  IGNORE_DIRS eq 1
454
    cmp  edx,53
549
    cmp  edx,53
455
    je  .seek
550
    je  .seek
456
end if
551
end if
457
    test edx,edx
552
    test edx,edx
458
    jnz  .err
553
    jnz  .err
459
    cmp  dword[esp],0
554
    cmp  dword[esp],0
460
    jz   .ok
555
    jz   .ok
461
    dec  dword[esp]
556
    dec  dword[esp]
462
  .seek:
557
  .seek:
463
    add  eax,ecx
558
    add  eax,ecx
464
    mov  ebx,1
559
;    mov  ebx,1
-
 
560
    add  esi,eax
465
    call FileSeek
561
;    call FileSeek
466
    jmp  .nxt
562
    jmp  .nxt
467
  .err:
563
  .err:
468
    mov  edx,4
564
    mov  edx,4
469
    jmp  .ex
565
    jmp  .ex
470
  .ok:
566
  .ok:
471
    pop  ecx
567
    pop  ecx
472
    add  esi,eax
568
    add  esi,eax
473
    mov  edx,5
569
    mov  edx,5
474
  .ex:
570
  .ex:
475
    Msg  edx
571
    Msg  edx
476
    ret
572
    ret
477
 
573
 
478
TarCrawl:
574
TarCrawl:
479
    cmp  byte[esi],0
575
    cmp  byte[esi],0
480
    jz   ZipCrawl.edx3
576
    jz   ZipCrawl.edx3
481
    push esi
577
    push esi
482
    mov  ecx,11
578
    mov  ecx,11
483
    add  esi,0x7c
579
    add  esi,0x7c
484
    call Octal_str
580
    call Octal_str
485
    mov  esi,[esp]
581
    mov  esi,[esp]
486
    mov  [outfile.size],eax
582
    mov  [outfile.size],eax
487
    call SkipASCIIZ
583
    call SkipASCIIZ
488
if  IGNORE_DIRS eq 1
584
if  IGNORE_DIRS eq 1
489
    cmp  byte[esi-2],'/'
585
    cmp  byte[esi-2],'/'
490
    je   .skipdp
586
    je   .skipdp
491
end if
587
end if
492
    mov  edx,[esp]
588
    mov  edx,[esp]
493
    lea  ecx,[esi-1]
589
    lea  ecx,[esi-1]
494
    sub  ecx,edx
590
    sub  ecx,edx
495
    call PrintFilename
591
    call PrintFilename
496
  .skipdp:
592
  .skipdp:
497
    mov  ecx,[outfile.size]
593
    mov  ecx,[outfile.size]
498
    jecxz .zerolen
594
    jecxz .zerolen
499
    shr  ecx,9
595
    shr  ecx,9
500
    inc  ecx
596
    inc  ecx
501
    shl  ecx,9
597
    shl  ecx,9
502
  .zerolen:
598
  .zerolen:
503
    mov  eax,512
599
    mov  eax,512
504
    pop  esi
600
    pop  esi
505
    jmp  ZipCrawl.ok
601
    jmp  ZipCrawl.ok
506
 
602
 
507
Octal_str:
603
Octal_str:
508
; in:  esi - ASCIIZ octal string
604
; in:  esi - ASCIIZ octal string
509
;      ecx - its length
605
;      ecx - its length
510
; out: eax - value
606
; out: eax - value
511
    push esi ebx ecx
607
    push esi ebx ecx
512
    xor  ebx,ebx
608
    xor  ebx,ebx
513
    xor  eax,eax
609
    xor  eax,eax
514
  .jec:
610
  .jec:
515
    jecxz .zero
611
    jecxz .zero
516
    cmp  byte[esi+ecx-1],' '
612
    cmp  byte[esi+ecx-1],' '
517
    jne  .lp
613
    jne  .lp
518
    dec  ecx
614
    dec  ecx
519
    jmp  .jec
615
    jmp  .jec
520
  .lp:
616
  .lp:
521
    lodsb
617
    lodsb
522
    shl  ebx,3
618
    shl  ebx,3
523
    cmp  eax,' '
619
    cmp  eax,' '
524
    je   .space
620
    je   .space
525
    lea  ebx,[ebx+eax-'0']
621
    lea  ebx,[ebx+eax-'0']
526
  .space:
622
  .space:
527
    loop .lp
623
    loop .lp
528
    mov  eax,ebx
624
    mov  eax,ebx
529
  .zero:
625
  .zero:
530
    pop  ecx ebx esi
626
    pop  ecx ebx esi
531
    ret
627
    ret
532
 
628
 
533
TRAILING_BUF equ 2048
629
TRAILING_BUF equ 2048
534
SfxParse:
630
SfxParse:
535
    call ResetFile
631
    call ResetFile
536
    cmp  word[esi],'MZ'
632
    cmp  word[esi],'MZ'
537
    rep_err e, 34
633
    rep_err e, 34
538
    mov  eax,TRAILING_BUF
634
    mov  eax,TRAILING_BUF
539
    mov  ecx,eax
635
    mov  ecx,eax
540
    mov  ebx,2
636
    mov  ebx,2
541
    call FileSeek
637
    call FileSeek
542
    mov  edi,esi
638
    mov  edi,esi
543
    mov  al,'P'
639
    mov  al,'P'
544
  .lp:
640
  .lp:
545
    repne scasb
641
    repne scasb
546
    cmp  dword[edi-1],fhs_end
642
    cmp  dword[edi-1],fhs_end
547
    je   .end_found
643
    je   .end_found
548
    jecxz .err
644
    jecxz .err
549
    jmp   .lp
645
    jmp   .lp
550
  .end_found:
646
  .end_found:
551
    dec   edi
647
    dec   edi
552
    mov   esi,edi
648
    mov   esi,edi
553
    mov   eax,[edi+12]
649
    mov   eax,[edi+12]
554
    neg   eax
650
    neg   eax
555
    mov   ebx,1
651
    mov   ebx,1
556
    call  FileSeek
652
    call  FileSeek
557
    push  dword[esi+42]
653
    push  dword[esi+42]
558
    pop   [arc_base]
654
    pop   [arc_base]
559
  .err:
655
  .err:
560
    ret
656
    ret
561
 
-
 
562
; Created:  May 31, 2005
657
 
563
FiltCall:
-
 
564
dd PngFilter.nofilt,Filt_sub,Filt_up,Filt_av,Filt_paeth,PngFilter.nofilt
-
 
565
PngFilter:
-
 
566
; esi - filtered uncompressed image data
-
 
567
; edi - destination
658
scanline_calc:
568
    mov  cl,[PNG_info.Color_type]
659
    movzx ecx,byte[PNG_info.Color_type]
569
    mov  eax,1
660
    mov  eax,1
570
    cmp  cl,3
661
    cmp  cl,3
571
    je   .palette
662
    je   .palette
572
    test cl,2
663
    test cl,2
573
    jz  .notriple
664
    jz  .notriple
574
    add  eax,2
665
    add  eax,2
575
  .notriple:
666
  .notriple:
576
    test cl,4
667
    test cl,4
577
    jz   .calc_bpp
668
    jz   .calc_bpp
578
    inc  eax
669
    inc  eax
579
  .calc_bpp:
670
  .calc_bpp:
580
    mul  [PNG_info.Bit_depth]
671
    mul  [PNG_info.Bit_depth]
581
  .palette:
672
  .palette:
582
    mov  ecx,eax   ; in bits
673
    mov  ecx,eax   ; in bits
583
    shr  eax,3     ; in bytes
674
    shr  eax,3     ; in bytes
584
    test eax,eax
675
    test eax,eax
585
    jnz  .noz
676
    jnz  .noz
586
    inc  eax
677
    inc  eax
587
  .noz:
678
  .noz:
588
    mov  [png_bpp],eax
679
    mov  [png_bpp],eax
589
    mov  eax,[PNG_info.Width]
680
    mov  eax,[PNG_info.Width]
590
    mov  ebp,eax
681
    mov  ebp,eax
591
    imul ecx
682
    imul ecx
592
    shr  eax,3
683
    shr  eax,3
593
    test eax,eax
684
    test eax,eax
594
    jnz  .noz2
685
    jnz  .noz2
595
    inc  eax
686
    inc  eax
596
  .noz2:
687
  .noz2:
-
 
688
    ret
-
 
689
 
-
 
690
; Created:  May 31, 2005
-
 
691
FiltCall:
-
 
692
dd PngFilter.nofilt,Filt_sub,Filt_up,Filt_av,Filt_paeth,PngFilter.nofilt
-
 
693
PngFilter:
-
 
694
; esi - filtered uncompressed image data
-
 
695
; edi - destination
-
 
696
    call scanline_calc
597
    mov  [sline_len],eax   ; scanline length
697
    mov  [sline_len],eax   ; scanline length
598
    push edi
698
    push edi
599
    and  [Flags],not 1
699
    and  [Flags],not 1
600
    mov  ecx,[PNG_info.Height]
700
    mov  ecx,[PNG_info.Height]
601
  .scanline:
701
  .scanline:
602
;    Msg 9,1
702
;    Msg 9,1
603
    push ecx
703
    push ecx
604
    lodsb
704
    lodsb
605
    movzx eax,al
705
    movzx eax,al
606
    cmp  eax,5
706
    cmp  eax,5
607
    jb   .f_ok
707
    jb   .f_ok
608
    mov  eax,5
708
    mov  eax,5
609
  .f_ok:
709
  .f_ok:
610
    inc  dword[filters+eax*4]
710
    inc  dword[filters+eax*4]
611
    jmp  dword[FiltCall+eax*4]
711
    jmp  dword[FiltCall+eax*4]
612
  .nofilt:
712
  .nofilt:
613
    mov  dl,[PNG_info.Color_type]
713
    mov  dl,[PNG_info.Color_type]
614
    cmp  dl,3
714
    cmp  dl,3
615
    jne  .nopalette
715
    jne  .nopalette
616
    lodsb
716
    lodsb
617
    mov  [cur_byte],eax
717
    mov  [cur_byte],eax
618
    mov  [bits],8
718
    mov  [bits],8
619
    mov  ecx,ebp
719
    mov  ecx,ebp
620
  .pixel:
720
  .pixel:
621
    push ecx
721
    push ecx
622
    movzx ecx,[PNG_info.Bit_depth]
722
    movzx ecx,[PNG_info.Bit_depth]
623
    call rb_png
723
    call rb_png
624
    push esi
724
    push esi
625
    lea  esi,[eax+eax*2]
725
    lea  esi,[eax+eax*2]
626
    add  esi,PNG_info.Palette
726
    add  esi,PNG_info.Palette
627
    call PngStore
727
    call PngStore
628
    pop  esi
728
    pop  esi
629
    pop  ecx
729
    pop  ecx
630
    loop .pixel
730
    loop .pixel
631
    cmp  [bits],8
731
    cmp  [bits],8
632
    jne  .lp
732
    jne  .lp
633
    dec  esi
733
    dec  esi
634
  .lp:
734
  .lp:
635
    pop  ecx
735
    pop  ecx
636
    loop .sl
736
    loop .sl
637
    jmp  .sl2
737
    jmp  .sl2
638
  .sl:
738
  .sl:
639
;//
739
;//
640
MV equ 1
740
MV equ 1
641
;    mov  eax,ecx
741
;    mov  eax,ecx
642
;    and  eax,1 shl MOVE_SLINE_LEV-1
742
;    and  eax,1 shl MOVE_SLINE_LEV-1
643
;    jnz  .scanline
743
;    jnz  .scanline
644
;stop
744
;stop
645
if MV eq 0
745
if MV eq 0
646
    push ecx
746
    push ecx
647
    mov  ecx,edi
747
    mov  ecx,edi
648
    sub  ecx,esi
748
    sub  ecx,esi
649
    sub  [outp],esi
749
    sub  [outp],esi
650
    mov  edi,output
750
    mov  edi,output
651
    add  [outp],edi
751
    add  [outp],edi
652
    rep  movsb
752
    rep  movsb
653
    mov  esi,output
753
    mov  esi,output
654
    pop  ecx
754
    pop  ecx
655
    pop  eax
755
    pop  eax
656
    push [outp]
756
    push [outp]
657
end if
757
end if
658
;;//
758
;;//
659
    jmp  .scanline
759
    jmp  .scanline
660
  .sl2:
760
  .sl2:
661
;//
761
;//
662
;    call MoveScanline
762
;    call MoveScanline
663
    sub  edi,[outp]
763
    sub  edi,[outp]
664
;//
764
;//
665
;    sub  edi,[esp]
765
;    sub  edi,[esp]
666
    pop  eax
766
    pop  eax
667
    ret
767
    ret
668
 
768
 
669
  .nopalette:
769
  .nopalette:
670
    test  dl,2
770
    test  dl,2
671
    jz   .notriple1
771
    jz   .notriple1
672
  .__:
772
  .__:
673
    mov  ecx,[PNG_info.Width]
773
    mov  ecx,[PNG_info.Width]
674
  .RGBcp:
774
  .RGBcp:
675
    call PngStore
775
    call PngStore
676
    add  esi,[png_bpp]
776
    add  esi,[png_bpp]
677
    loop .RGBcp
777
    loop .RGBcp
678
    jmp  .lp
778
    jmp  .lp
679
  .notriple1:
779
  .notriple1:
680
    test dl,dl
780
    test dl,dl
681
    jz  .gray
781
    jz  .gray
682
    cmp  dl,4
782
    cmp  dl,4
683
    jne .__
783
    jne .__
684
;    Msg 31
784
;    Msg 31
685
;    ud2
785
;    ud2
686
  .gray:
786
  .gray:
687
;    stop
787
;    stop
688
    push ecx
788
    push ecx
689
    mov  ecx,[PNG_info.Width]
789
    mov  ecx,[PNG_info.Width]
690
    mov  [bits],8
790
    mov  [bits],8
691
    lodsb
791
    lodsb
692
    mov  [cur_byte],eax
792
    mov  [cur_byte],eax
693
  .gray2:
793
  .gray2:
694
    push ecx
794
    push ecx
695
    movzx ecx,[PNG_info.Bit_depth]
795
    movzx ecx,[PNG_info.Bit_depth]
696
    push ecx
796
    push ecx
697
    call rb_png
797
    call rb_png
698
    pop  ecx
798
    pop  ecx
699
    cmp  ecx,8
799
    cmp  ecx,8
700
    jbe  .lo
800
    jbe  .lo
701
    add  esi,2
801
    add  esi,2
702
    shr  eax,8
802
    shr  eax,8
703
    jmp  .stsb
803
    jmp  .stsb
704
  .lo:
804
  .lo:
705
    neg  ecx
805
    neg  ecx
706
    add  ecx,8
806
    add  ecx,8
707
    shl  eax,cl
807
    shl  eax,cl
708
  .stsb:
808
  .stsb:
709
    mov  ecx,3
809
    mov  ecx,3
710
    rep  stosb
810
    rep  stosb
711
    pop  ecx
811
    pop  ecx
712
    loop .gray2
812
    loop .gray2
713
    dec  esi
813
    dec  esi
714
    pop  ecx
814
    pop  ecx
715
    jmp  .lp
815
    jmp  .lp
716
 
816
 
717
Filt_sub:
817
Filt_sub:
718
;    dps  '-'
818
;    dps  '-'
719
    mov  ecx,[sline_len]
819
    mov  ecx,[sline_len]
720
    sub  ecx,[png_bpp]
820
    sub  ecx,[png_bpp]
721
    push esi edi
821
    push esi edi
722
    mov  edi,esi
822
    mov  edi,esi
723
    add  edi,[png_bpp]
823
    add  edi,[png_bpp]
724
  .scan:    ; esi - previous, edi - current
824
  .scan:    ; esi - previous, edi - current
725
    lodsb
825
    lodsb
726
    add  [edi],al
826
    add  [edi],al
727
    inc  edi
827
    inc  edi
728
    loop .scan
828
    loop .scan
729
 
829
 
730
    pop  edi esi
830
    pop  edi esi
731
;    dps  '-'
831
;    dps  '-'
732
    jmp  PngFilter.nofilt
832
    jmp  PngFilter.nofilt
733
 
833
 
734
Filt_up:
834
Filt_up:
735
    cmp  ecx,[PNG_info.Height]
835
    cmp  ecx,[PNG_info.Height]
736
    je   PngFilter.nofilt
836
    je   PngFilter.nofilt
737
    push esi edi
837
    push esi edi
738
    mov  ecx,[sline_len]
838
    mov  ecx,[sline_len]
739
    mov  edi,esi
839
    mov  edi,esi
740
    sub  esi,ecx
840
    sub  esi,ecx
741
    dec  esi
841
    dec  esi
742
    jmp  Filt_sub.scan
842
    jmp  Filt_sub.scan
743
 
843
 
744
Filt_av:
844
Filt_av:
745
    pusha
845
    pusha
746
    mov  ecx,[sline_len]
846
    mov  ecx,[sline_len]
747
    mov  ebp,[PNG_info.Height]
847
    mov  ebp,[PNG_info.Height]
748
    mov  edx,[png_bpp] ; edx-raw
848
    mov  edx,[png_bpp] ; edx-raw
749
    neg  edx
849
    neg  edx
750
    mov  ebx,ecx
850
    mov  ebx,ecx
751
    sub  ebx,[png_bpp]
851
    sub  ebx,[png_bpp]
752
    mov  edi,esi
852
    mov  edi,esi
753
    sub  esi,ecx
853
    sub  esi,ecx
754
    dec  esi           ; esi-prior
854
    dec  esi           ; esi-prior
755
  .lpavg:
855
  .lpavg:
756
    xor  eax,eax
856
    xor  eax,eax
757
    cmp  [esp+24h],ebp
857
    cmp  [esp+24h],ebp
758
    je   .1stl
858
    je   .1stl
759
    movzx eax,byte[esi]
859
    movzx eax,byte[esi]
760
  .1stl:
860
  .1stl:
761
    cmp  ecx,ebx
861
    cmp  ecx,ebx
762
    ja   .leftbad
862
    ja   .leftbad
763
    push ecx
863
    push ecx
764
    movzx ecx,byte[edi+edx]
864
    movzx ecx,byte[edi+edx]
765
    add  eax,ecx
865
    add  eax,ecx
766
    pop  ecx
866
    pop  ecx
767
  .leftbad:
867
  .leftbad:
768
    shr  eax,1
868
    shr  eax,1
769
    add  [edi],al
869
    add  [edi],al
770
    inc  esi
870
    inc  esi
771
    inc  edi
871
    inc  edi
772
    loop .lpavg
872
    loop .lpavg
773
    popa
873
    popa
774
    jmp  PngFilter.nofilt
874
    jmp  PngFilter.nofilt
775
 
875
 
776
Filt_paeth:
876
Filt_paeth:
777
    pusha
877
    pusha
778
    mov  ecx,[sline_len]
878
    mov  ecx,[sline_len]
779
    mov  edx,[png_bpp]
879
    mov  edx,[png_bpp]
780
    neg  edx
880
    neg  edx
781
    lea  ebp,[ecx+edx] ; left edge
881
    lea  ebp,[ecx+edx] ; left edge
782
    mov  edi,esi
882
    mov  edi,esi
783
    sub  esi,ecx
883
    sub  esi,ecx
784
    dec  esi
884
    dec  esi
785
  .lpaeth:
885
  .lpaeth:
786
    push ecx
886
    push ecx
787
    movzx eax,byte[edi+edx]
887
    movzx eax,byte[edi+edx]
788
    movzx ebx,byte[esi]
888
    movzx ebx,byte[esi]
789
    movzx ecx,byte[esi+edx]
889
    movzx ecx,byte[esi+edx]
790
    push eax
890
    push eax
791
    mov  eax,[esp+28h]
891
    mov  eax,[esp+28h]
792
    cmp  eax,[PNG_info.Height] ; 1st line
892
    cmp  eax,[PNG_info.Height] ; 1st line
793
    jne  .no1stlineok
893
    jne  .no1stlineok
794
    xor  ebx,ebx
894
    xor  ebx,ebx
795
    xor  ecx,ecx
895
    xor  ecx,ecx
796
  .no1stlineok:
896
  .no1stlineok:
797
    pop  eax
897
    pop  eax
798
    cmp  [esp],ebp     ; ecx
898
    cmp  [esp],ebp     ; ecx
799
    jbe  .leftok      ; x-bpp>=0
899
    jbe  .leftok      ; x-bpp>=0
800
    xor  eax,eax
900
    xor  eax,eax
801
    xor  ecx,ecx
901
    xor  ecx,ecx
802
  .leftok:
902
  .leftok:
803
    pusha   ; eax-28, ebx-16, ecx-24
903
    pusha   ; eax-28, ebx-16, ecx-24
804
    lea  edx,[eax+ebx]
904
    lea  edx,[eax+ebx]
805
    sub  edx,ecx        ; p=edx
905
    sub  edx,ecx        ; p=edx
806
    sub  eax,edx        ; pa := abs(p - a)
906
    sub  eax,edx        ; pa := abs(p - a)
807
    jge  .eaxp
907
    jge  .eaxp
808
    neg  eax
908
    neg  eax
809
  .eaxp:
909
  .eaxp:
810
    sub  ebx,edx        ; pb := abs(p - b)
910
    sub  ebx,edx        ; pb := abs(p - b)
811
    jge  .ebxp
911
    jge  .ebxp
812
    neg  ebx
912
    neg  ebx
813
  .ebxp:
913
  .ebxp:
814
    sub  ecx,edx        ; pc := abs(p - c)
914
    sub  ecx,edx        ; pc := abs(p - c)
815
    jge  .ecxp
915
    jge  .ecxp
816
    neg  ecx
916
    neg  ecx
817
  .ecxp:
917
  .ecxp:
818
    cmp  eax,ebx
918
    cmp  eax,ebx
819
    ja   .noa
919
    ja   .noa
820
    cmp  eax,ecx
920
    cmp  eax,ecx
821
    jbe  .ex            ; pa-min
921
    jbe  .ex            ; pa-min
822
  .noa:
922
  .noa:
823
    cmp  ebx,ecx
923
    cmp  ebx,ecx
824
    ja   .nob
924
    ja   .nob
825
    mov  eax,[esp+16]
925
    mov  eax,[esp+16]
826
    jmp  .ex2
926
    jmp  .ex2
827
  .nob:
927
  .nob:
828
    mov  eax,[esp+24]
928
    mov  eax,[esp+24]
829
  .ex2:
929
  .ex2:
830
    mov  [esp+28],eax
930
    mov  [esp+28],eax
831
  .ex:
931
  .ex:
832
    popa
932
    popa
833
    add  [edi],al
933
    add  [edi],al
834
    inc  esi
934
    inc  esi
835
    inc  edi
935
    inc  edi
836
    pop  ecx
936
    pop  ecx
837
    loop .lpaeth
937
    loop .lpaeth
838
    popa
938
    popa
839
    jmp  PngFilter.nofilt
939
    jmp  PngFilter.nofilt
840
 
940
 
841
rb_png: ; eax-dest; ecx-count
941
rb_png: ; eax-dest; ecx-count
842
    push ecx
942
    push ecx
843
    xor  eax,eax
943
    xor  eax,eax
844
  .shift:
944
  .shift:
845
    rol  byte[cur_byte],1
945
    rol  byte[cur_byte],1
846
    rcl  eax,1
946
    rcl  eax,1
847
  .dec:
947
  .dec:
848
    dec  [bits]
948
    dec  [bits]
849
    jnz  .loop1
949
    jnz  .loop1
850
  .push:
950
  .push:
851
    push dword[esi]
951
    push dword[esi]
852
    pop  [cur_byte]
952
    pop  [cur_byte]
853
    mov  [bits],8
953
    mov  [bits],8
854
    inc  esi
954
    inc  esi
855
  .loop1:
955
  .loop1:
856
    loop .shift
956
    loop .shift
857
    pop  ecx
957
    pop  ecx
858
    ret
958
    ret
859
 
959
 
860
PngStore:
960
PngStore:
861
    push esi
961
    push esi
862
    cmp  [PNG_info.Bit_depth],8
962
    cmp  [PNG_info.Bit_depth],8
863
    jbe  .lo
963
    jbe  .lo
864
    add  esi,3
964
    add  esi,3
865
  .lo:
965
  .lo:
866
  if ~ SYS eq win
966
  if ~ SYS eq win
867
    mov  esi,[esi]
967
    mov  esi,[esi]
868
    bswap esi
968
    bswap esi
869
    shr  esi,8
969
    shr  esi,8
870
    mov  [edi],esi
970
    mov  [edi],esi
871
    add  edi,3
971
    add  edi,3
872
  else
972
  else
873
    movsw
973
    movsw
874
    movsb
974
    movsb
875
  end if
975
  end if
876
    pop  esi
976
    pop  esi
877
    ret
977
    ret
878
 
978
 
879
FiltStats:
979
FiltStats:
880
    pusha
980
    pusha
881
    xor  ebx,ebx
981
    xor  ebx,ebx
882
    mov  edx,23
982
    mov  edx,23
883
    mov  ecx,6
983
    mov  ecx,6
884
  .lp:
984
  .lp:
885
    push ecx edx
985
    push ecx edx
886
    Msg  edx
986
    Msg  edx
887
    mov  eax,[filters+ebx*4]
987
    mov  eax,[filters+ebx*4]
888
    DebugPrintDec
988
    DebugPrintDec
889
    pop  edx ecx
989
    pop  edx ecx
890
    inc  edx
990
    inc  edx
891
    inc  ebx
991
    inc  ebx
892
    loop .lp
992
    loop .lp
893
    Newline
993
    Newline
894
    popa
994
    popa
895
    ret
995
    ret