Rev 1718 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1718 | mario79 | 1 | ; Disassemled and corrected in 2010 specially for FASM |
2 | ; by Marat Zakiyanov aka Mario79, aka Mario |
||
3 | ; All sources only assembler is now |
||
4 | ; GCC using for linking |
||
5 | ;--------------------------------------------------------------------- |
||
6 | ; Linux port by mike.dld in 2007 |
||
7 | ;--------------------------------------------------------------------- |
||
8 | ; kpack = Kolibri Packer |
||
9 | ; Written by diamond in 2006 specially for KolibriOS |
||
10 | |||
11 | ; Uses LZMA compression library by Igor Pavlov |
||
12 | ; (for more information on LZMA and 7-Zip visit http://www.7-zip.org) |
||
13 | ; (plain-C packer and ASM unpacker are ported by diamond) |
||
14 | |||
15 | format ELF |
||
16 | public _start |
||
17 | |||
18 | ;********************************************************************* |
||
19 | section ".text" executable align 16 |
||
20 | |||
21 | _start: |
||
22 | mov ecx,[esp+0] |
||
23 | lea ebx,[esp+4] |
||
24 | call combine_program_arguments |
||
25 | |||
26 | xor ebx, ebx |
||
27 | push eax ; reserve dword on the stack |
||
28 | |||
29 | xor eax,eax |
||
30 | inc eax |
||
31 | |||
32 | xchg eax, ebp |
||
33 | ; parse command line |
||
34 | mov eax,program_arguments |
||
35 | |||
36 | xchg eax, esi |
||
37 | call skip_spaces |
||
38 | call get_file_name |
||
39 | test al, al |
||
40 | jz short usage |
||
41 | |||
42 | call get_file_name |
||
43 | |||
44 | mov [infilename], edi |
||
45 | test al, al |
||
46 | jnz short two_files |
||
47 | |||
48 | mov [outfilename], edi |
||
49 | jmp short cont |
||
50 | ;********************************************************************* |
||
51 | write_string: |
||
52 | push eax ; reserve dword on the stack |
||
53 | mov eax, esp |
||
54 | push ebx |
||
55 | push eax |
||
56 | push dword [eax+12] |
||
57 | push dword [eax+8] |
||
58 | push ebp |
||
59 | call WriteConsoleA |
||
60 | pop eax |
||
61 | ret 8 |
||
62 | ;********************************************************************* |
||
63 | write_exit: |
||
64 | call write_string |
||
65 | ;--------------------------------------------------------------------- |
||
66 | doexit: |
||
67 | push ebx |
||
68 | call ExitProcess |
||
69 | ;--------------------------------------------------------------------- |
||
70 | usage: |
||
71 | cmp [bNoLogo], 0 |
||
72 | jnz doexit |
||
73 | |||
74 | push info_len + usage_len |
||
75 | push info_str |
||
76 | jmp write_exit |
||
77 | ;********************************************************************* |
||
78 | two_files: |
||
79 | call get_file_name |
||
80 | mov [outfilename], edi |
||
81 | test al, al |
||
82 | jnz short usage |
||
83 | ;--------------------------------------------------------------------- |
||
84 | cont: |
||
85 | cmp [bNoLogo], 0 |
||
86 | jnz @f |
||
87 | |||
88 | push info_len |
||
89 | push info_str |
||
90 | call write_string |
||
91 | ;--------------------------------------------------------------------- |
||
92 | @@: |
||
93 | ; Input file |
||
94 | push ebx |
||
95 | push ebx |
||
96 | push 3 ; OPEN_EXISTING |
||
97 | push ebx |
||
98 | push 1 ; FILE_SHARE_READ |
||
99 | push 80000000h ; GENERIC_READ |
||
100 | push [infilename] |
||
101 | call CreateFileA |
||
102 | inc eax |
||
103 | jnz short inopened |
||
104 | ;--------------------------------------------------------------------- |
||
105 | infileerr: |
||
106 | push errload_len |
||
107 | push errload_str |
||
108 | jmp write_exit |
||
109 | ;********************************************************************* |
||
110 | inopened: |
||
111 | dec eax |
||
112 | xchg eax, esi |
||
113 | push ebx |
||
114 | push esi |
||
115 | call GetFileSize |
||
116 | inc eax |
||
117 | jz short infileerr |
||
118 | |||
119 | dec eax |
||
120 | jz short infileerr |
||
121 | |||
122 | mov [insize], eax |
||
123 | push eax |
||
124 | push 4 ; PAGE_READWRITE |
||
125 | push 1000h ; MEM_COMMIT |
||
126 | push eax |
||
127 | push ebx |
||
128 | call VirtualAlloc |
||
129 | test eax, eax |
||
130 | jz nomem |
||
131 | |||
132 | mov [infile], eax |
||
133 | pop edx |
||
134 | mov ecx, esp |
||
135 | push ebx |
||
136 | push ecx |
||
137 | push edx |
||
138 | push eax |
||
139 | push esi |
||
140 | call ReadFile |
||
141 | test eax, eax |
||
142 | jz short infileerr |
||
143 | |||
144 | push esi |
||
145 | call CloseHandle |
||
146 | |||
147 | mov eax, [insize] |
||
148 | shr eax, 3 |
||
149 | add eax, [insize] |
||
150 | add eax, 400h ; should be enough for header |
||
151 | mov esi, eax |
||
152 | add eax, eax |
||
153 | push 4 |
||
154 | push 1000h |
||
155 | push eax |
||
156 | push ebx |
||
157 | call VirtualAlloc |
||
158 | test eax, eax |
||
159 | jnz short outmemok |
||
160 | ;--------------------------------------------------------------------- |
||
161 | nomem: |
||
162 | push nomem_len |
||
163 | push nomem_str |
||
164 | jmp write_exit |
||
165 | ;********************************************************************* |
||
166 | outmemok: |
||
167 | mov [outfile], eax |
||
168 | mov [outfile1], eax |
||
169 | mov [outfilebest], eax |
||
170 | add eax, esi |
||
171 | mov [outfile2], eax |
||
172 | sub eax, esi |
||
173 | mov dword [eax], 'KPCK' |
||
174 | mov ecx, [insize] |
||
175 | mov dword [eax+4], ecx |
||
176 | dec ecx |
||
177 | bsr eax, ecx |
||
178 | inc eax |
||
179 | cmp eax, 28 |
||
180 | jb short @f |
||
181 | |||
182 | mov eax, 28 |
||
183 | ;--------------------------------------------------------------------- |
||
184 | @@: |
||
185 | push eax |
||
186 | push eax |
||
187 | call lzma_set_dict_size |
||
188 | |||
189 | pop ecx |
||
190 | mov eax, 1 |
||
191 | shl eax, cl |
||
192 | mov [lzma_dictsize], eax |
||
193 | imul eax, 19 |
||
194 | shr eax, 1 |
||
195 | add eax, 509000h |
||
196 | push 4 |
||
197 | push 1000h |
||
198 | push eax |
||
199 | push ebx |
||
200 | call VirtualAlloc |
||
201 | test eax, eax |
||
202 | jz nomem |
||
203 | |||
204 | mov [workmem], eax |
||
205 | push compressing_len |
||
206 | push compressing_str |
||
207 | call write_string |
||
208 | |||
209 | mov eax, [outfile2] |
||
210 | mov [outfile], eax |
||
211 | xchg eax, edi |
||
212 | mov esi, [outfile1] |
||
213 | movsd |
||
214 | movsd |
||
215 | call pack_lzma |
||
216 | |||
217 | mov [outsize], eax |
||
218 | mov eax, [outfile] |
||
219 | mov [outfilebest], eax |
||
220 | mov [method], use_lzma |
||
221 | call preprocess_calltrick |
||
222 | test eax, eax |
||
223 | jz short noct1 |
||
224 | |||
225 | call set_outfile |
||
226 | call pack_lzma |
||
227 | |||
228 | add eax, 5 |
||
229 | cmp eax, [outsize] |
||
230 | jae short @f |
||
231 | mov [outsize], eax |
||
232 | mov eax, [outfile] |
||
233 | mov [outfilebest], eax |
||
234 | mov [method], use_lzma or use_calltrick1 |
||
235 | ;--------------------------------------------------------------------- |
||
236 | @@: |
||
237 | noct1: |
||
238 | call set_outfile |
||
239 | |||
240 | push [ctn] |
||
241 | mov al, [cti] |
||
242 | push eax |
||
243 | call preprocess_calltrick2 |
||
244 | test eax, eax |
||
245 | jz noct2 |
||
246 | |||
247 | call set_outfile |
||
248 | call pack_lzma |
||
249 | |||
250 | add eax, 5 |
||
251 | cmp eax, [outsize] |
||
252 | jae short @f |
||
253 | |||
254 | mov [outsize], eax |
||
255 | mov eax, [outfile] |
||
256 | mov [outfilebest], eax |
||
257 | mov [method], use_lzma or use_calltrick2 |
||
258 | pop ecx |
||
259 | pop ecx |
||
260 | push [ctn] |
||
261 | mov al, [cti] |
||
262 | push eax |
||
263 | ;--------------------------------------------------------------------- |
||
264 | @@: |
||
265 | noct2: |
||
266 | pop eax |
||
267 | mov [cti], al |
||
268 | pop [ctn] |
||
269 | add [outsize], 12 |
||
270 | mov eax, [outsize] |
||
271 | cmp eax, [insize] |
||
272 | jb short packed_ok |
||
273 | |||
274 | push too_big_len |
||
275 | push too_big_str |
||
276 | jmp write_exit |
||
277 | ;********************************************************************* |
||
278 | packed_ok: |
||
279 | push 8000h ; MEM_RELEASE |
||
280 | push ebx |
||
281 | push [workmem] |
||
282 | call VirtualFree |
||
283 | ; set header |
||
284 | movzx eax, [method] |
||
285 | mov edi, [outfilebest] |
||
286 | mov [edi+8], eax |
||
287 | test al, use_calltrick1 or use_calltrick2 |
||
288 | jz short @f |
||
289 | |||
290 | mov ecx, [outsize] |
||
291 | add ecx, edi |
||
292 | mov eax, [ctn] |
||
293 | mov [ecx-5], eax |
||
294 | mov al, [cti] |
||
295 | mov [ecx-1], al |
||
296 | @@: |
||
297 | mov eax, [outsize] |
||
298 | mov ecx, 100 |
||
299 | mul ecx |
||
300 | div [insize] |
||
301 | aam |
||
302 | xchg al, ah |
||
303 | add ax, '00' |
||
304 | mov [ratio], ax |
||
305 | push done_len |
||
306 | cmp [bNoLogo], 0 |
||
307 | jz @f |
||
308 | |||
309 | sub dword [esp], 2 |
||
310 | ;--------------------------------------------------------------------- |
||
311 | @@: |
||
312 | push done_str |
||
313 | call write_string |
||
314 | ; Output file |
||
315 | push ebx |
||
316 | push 80h ; FILE_ATTRIBUTE_NORMAL |
||
317 | push 2 ; CREATE_ALWAYS |
||
318 | push ebx |
||
319 | push ebx |
||
320 | push 40000000h ; GENERIC_WRITE |
||
321 | push [outfilename] |
||
322 | call CreateFileA |
||
323 | inc eax |
||
324 | jnz short @f |
||
325 | ;--------------------------------------------------------------------- |
||
326 | outerr: |
||
327 | push outfileerr_len |
||
328 | push outfileerr_str |
||
329 | jmp write_exit |
||
330 | ;********************************************************************* |
||
331 | @@: |
||
332 | dec eax |
||
333 | xchg eax, esi |
||
334 | mov eax, esp |
||
335 | push ebx |
||
336 | push eax |
||
337 | push [outsize] |
||
338 | push edi |
||
339 | push esi |
||
340 | call WriteFile |
||
341 | test eax, eax |
||
342 | jz short outerr |
||
343 | |||
344 | push esi |
||
345 | call CloseHandle |
||
346 | |||
347 | push ebx |
||
348 | call ExitProcess |
||
349 | ;--------------------------------------------------------------------- |
||
350 | get_file_name: |
||
351 | mov edi, esi |
||
352 | lodsb |
||
353 | cmp al, 0 |
||
354 | jz short _ret |
||
355 | |||
356 | cmp al, '"' |
||
357 | setz dl |
||
358 | jz short @f |
||
359 | |||
360 | dec esi |
||
361 | ;--------------------------------------------------------------------- |
||
362 | @@: |
||
363 | mov edi, esi |
||
364 | ;--------------------------------------------------------------------- |
||
365 | @@loop: |
||
366 | lodsb |
||
367 | cmp al, 0 |
||
368 | jz short _ret |
||
369 | |||
370 | cmp al, ' ' |
||
371 | ja short @f |
||
372 | |||
373 | test dl, 1 |
||
374 | jz short @@end |
||
375 | ;--------------------------------------------------------------------- |
||
376 | @@: |
||
377 | cmp al, '"' |
||
378 | jnz short @@loop |
||
379 | |||
380 | test dl, 1 |
||
381 | jz short @@loop |
||
382 | ;--------------------------------------------------------------------- |
||
383 | @@end: |
||
384 | mov byte [esi-1], 0 |
||
385 | ;--------------------------------------------------------------------- |
||
386 | skip_spaces: |
||
387 | lodsb |
||
388 | cmp al, 0 |
||
389 | jz short @f |
||
390 | |||
391 | cmp al, ' ' |
||
392 | jbe short skip_spaces |
||
393 | ;--------------------------------------------------------------------- |
||
394 | @@: |
||
395 | dec esi |
||
396 | cmp dword [esi+0],'--no' |
||
397 | jnz @f |
||
398 | |||
399 | cmp dword [esi+4],'logo' |
||
400 | jnz @f |
||
401 | |||
402 | mov [bNoLogo], 1 |
||
403 | add esi, 8 |
||
404 | jmp skip_spaces |
||
405 | ;********************************************************************* |
||
406 | @@: |
||
407 | mov al, [esi] |
||
408 | ;--------------------------------------------------------------------- |
||
409 | _ret: |
||
410 | ret |
||
411 | ;********************************************************************* |
||
412 | set_outfile: |
||
413 | mov eax,[outfilebest] |
||
414 | xor eax,[outfile1] |
||
415 | xor eax,[outfile2] |
||
416 | mov [outfile],eax |
||
417 | ret |
||
418 | ;********************************************************************* |
||
419 | pack_calltrick_fail: |
||
420 | xor eax,eax |
||
421 | xor ebx,ebx |
||
422 | mov [ctn],eax |
||
423 | ret |
||
424 | ;********************************************************************* |
||
425 | preprocess_calltrick: |
||
426 | ; input preprocessing |
||
427 | push 4 ; PAGE_READWRITE |
||
428 | push 1000h ; MEM_COMMIT |
||
429 | push [insize] |
||
430 | push ebx |
||
431 | call VirtualAlloc |
||
432 | test eax, eax |
||
433 | jz pack_calltrick_fail |
||
434 | |||
435 | push eax |
||
436 | xor eax, eax |
||
437 | mov edi, ct1 |
||
438 | mov ecx, 256/4 |
||
439 | push edi |
||
440 | rep stosd |
||
441 | |||
442 | pop edi |
||
443 | mov ecx, [insize] |
||
444 | mov esi, [infile] |
||
445 | xchg eax, edx |
||
446 | pop eax |
||
447 | xchg eax, ebx |
||
448 | push ebx |
||
449 | ;--------------------------------------------------------------------- |
||
450 | input_pre: |
||
451 | lodsb |
||
452 | sub al, 0E8h |
||
453 | cmp al, 1 |
||
454 | ja short input_pre_cont |
||
455 | |||
456 | cmp ecx, 5 |
||
457 | jb short input_pre_done |
||
458 | |||
459 | lodsd |
||
460 | add eax, esi |
||
461 | sub eax, [infile] |
||
462 | cmp eax, [insize] |
||
463 | jae short xxx |
||
464 | |||
465 | cmp eax, 1000000h |
||
466 | jae short xxx |
||
467 | |||
468 | sub ecx, 4 |
||
469 | bswap eax |
||
470 | mov [esi-4], eax |
||
471 | inc edx |
||
472 | mov [ebx], esi |
||
473 | add ebx, 4 |
||
474 | jmp short input_pre_cont |
||
475 | ;********************************************************************* |
||
476 | xxx: |
||
477 | sub esi, 4 |
||
478 | movzx eax, byte [esi] |
||
479 | mov byte [eax+edi], 1 |
||
480 | ;--------------------------------------------------------------------- |
||
481 | input_pre_cont: |
||
482 | loop input_pre |
||
483 | ;--------------------------------------------------------------------- |
||
484 | input_pre_done: |
||
485 | mov [ctn], edx |
||
486 | pop edx |
||
487 | xor eax, eax |
||
488 | mov ecx, 256 |
||
489 | repnz scasb |
||
490 | jnz pack_calltrick_fail |
||
491 | not cl |
||
492 | |||
493 | mov [cti], cl |
||
494 | ;--------------------------------------------------------------------- |
||
495 | @@: |
||
496 | cmp ebx, edx |
||
497 | jz @f |
||
498 | |||
499 | sub ebx, 4 |
||
500 | mov eax, [ebx] |
||
501 | mov [eax-4], cl |
||
502 | jmp @b |
||
503 | ;********************************************************************* |
||
504 | @@: |
||
505 | xor ebx, ebx |
||
506 | push 8000h |
||
507 | push ebx |
||
508 | push edx |
||
509 | call VirtualFree |
||
510 | ret |
||
511 | ;********************************************************************* |
||
512 | pack_lzma: |
||
513 | mov eax, [outfile] |
||
514 | add eax, 11 |
||
515 | push [workmem] |
||
516 | push [insize] |
||
517 | push eax |
||
518 | push [infile] |
||
519 | call lzma_compress |
||
520 | |||
521 | mov ecx, [outfile] |
||
522 | mov edx, [ecx+12] |
||
523 | bswap edx |
||
524 | mov [ecx+12], edx |
||
525 | dec eax |
||
526 | ret |
||
527 | ;********************************************************************* |
||
528 | preprocess_calltrick2: |
||
529 | ; restore input |
||
530 | mov esi, [infile] |
||
531 | mov ecx, [ctn] |
||
532 | jecxz pc2l2 |
||
533 | ;--------------------------------------------------------------------- |
||
534 | pc2l1: |
||
535 | lodsb |
||
536 | sub al, 0E8h |
||
537 | cmp al, 1 |
||
538 | ja short pc2l1 |
||
539 | |||
540 | mov al, [cti] |
||
541 | cmp [esi], al |
||
542 | jnz short pc2l1 |
||
543 | |||
544 | lodsd |
||
545 | mov al, 0 |
||
546 | bswap eax |
||
547 | sub eax, esi |
||
548 | add eax, [infile] |
||
549 | mov [esi-4], eax |
||
550 | loop pc2l1 |
||
551 | ;--------------------------------------------------------------------- |
||
552 | pc2l2: |
||
553 | ; input preprocessing |
||
554 | push 4 ; PAGE_READWRITE |
||
555 | push 1000h ; MEM_COMMIT |
||
556 | push [insize] |
||
557 | push ebx |
||
558 | call VirtualAlloc |
||
559 | test eax, eax |
||
560 | jz pack_calltrick_fail |
||
561 | |||
562 | mov edi, ct1 |
||
563 | xchg eax, ebx |
||
564 | xor eax, eax |
||
565 | push edi |
||
566 | mov ecx, 256/4 |
||
567 | rep stosd |
||
568 | |||
569 | pop edi |
||
570 | mov ecx, [insize] |
||
571 | mov esi, [infile] |
||
572 | xchg eax, edx |
||
573 | push ebx |
||
574 | ;--------------------------------------------------------------------- |
||
575 | input_pre2: |
||
576 | lodsb |
||
577 | ;--------------------------------------------------------------------- |
||
578 | @@: |
||
579 | cmp al, 0Fh |
||
580 | jnz short ip1 |
||
581 | |||
582 | dec ecx |
||
583 | jz short input_pre_done2 |
||
584 | |||
585 | lodsb |
||
586 | cmp al, 80h |
||
587 | jb short @b |
||
588 | |||
589 | cmp al, 90h |
||
590 | jb short @f |
||
591 | ;--------------------------------------------------------------------- |
||
592 | ip1: |
||
593 | sub al, 0E8h |
||
594 | cmp al, 1 |
||
595 | ja short input_pre_cont2 |
||
596 | ;--------------------------------------------------------------------- |
||
597 | @@: |
||
598 | cmp ecx, 5 |
||
599 | jb short input_pre_done2 |
||
600 | |||
601 | lodsd |
||
602 | add eax, esi |
||
603 | sub eax, [infile] |
||
604 | cmp eax, [insize] |
||
605 | jae short xxx2 |
||
606 | |||
607 | cmp eax, 1000000h |
||
608 | jae short xxx2 |
||
609 | |||
610 | sub ecx, 4 |
||
611 | bswap eax |
||
612 | mov [esi-4], eax |
||
613 | inc edx |
||
614 | mov [ebx], esi |
||
615 | add ebx, 4 |
||
616 | jmp short input_pre_cont2 |
||
617 | ;********************************************************************* |
||
618 | xxx2: |
||
619 | sub esi, 4 |
||
620 | movzx eax, byte [esi] |
||
621 | mov byte [eax+edi], 1 |
||
622 | ;--------------------------------------------------------------------- |
||
623 | input_pre_cont2: |
||
624 | loop input_pre2 |
||
625 | ;--------------------------------------------------------------------- |
||
626 | input_pre_done2: |
||
627 | mov [ctn], edx |
||
628 | pop edx |
||
629 | xor eax, eax |
||
630 | mov ecx, 256 |
||
631 | repnz scasb |
||
632 | jnz pack_calltrick_fail |
||
633 | |||
634 | not cl |
||
635 | mov [cti], cl |
||
636 | ;--------------------------------------------------------------------- |
||
637 | @@: |
||
638 | cmp ebx, edx |
||
639 | jz @f |
||
640 | |||
641 | sub ebx, 4 |
||
642 | mov eax, [ebx] |
||
643 | mov [eax-4], cl |
||
644 | jmp @b |
||
645 | ;********************************************************************* |
||
646 | @@: |
||
647 | xor ebx, ebx |
||
648 | push 8000h |
||
649 | push ebx |
||
650 | push edx |
||
651 | call VirtualFree |
||
652 | ret |
||
653 | ;********************************************************************* |
||
654 | extrn exit |
||
655 | extrn putchar |
||
656 | extrn fopen |
||
657 | extrn fread |
||
658 | extrn fwrite |
||
659 | extrn fclose |
||
660 | extrn fseek |
||
661 | extrn ftell |
||
662 | extrn malloc |
||
663 | extrn free |
||
664 | |||
665 | open_mode db "rb",0 |
||
666 | create_mode db "wb",0 |
||
667 | ;********************************************************************* |
||
668 | combine_program_arguments: ; ecx = argc, ebx = argv |
||
669 | mov edi,program_arguments |
||
670 | cld |
||
671 | mov al,'"' |
||
672 | stosb |
||
673 | mov esi,[ebx] |
||
674 | ;--------------------------------------------------------------------- |
||
675 | @@: |
||
676 | lodsb |
||
677 | or al,al |
||
678 | jz @f |
||
679 | stosb |
||
680 | jmp @b |
||
681 | ;********************************************************************* |
||
682 | @@: |
||
683 | add ebx,4 |
||
684 | mov al,'"' |
||
685 | stosb |
||
686 | dec ecx |
||
687 | jz .no_args |
||
688 | ;--------------------------------------------------------------------- |
||
689 | .next_arg: |
||
690 | dec ecx |
||
691 | js .no_args |
||
692 | |||
693 | mov al,' ' |
||
694 | stosb |
||
695 | mov esi,[ebx] |
||
696 | ;--------------------------------------------------------------------- |
||
697 | @@: |
||
698 | lodsb |
||
699 | or al,al |
||
700 | jz @f |
||
701 | stosb |
||
702 | jmp @b |
||
703 | ;********************************************************************* |
||
704 | @@: |
||
705 | add ebx,4 |
||
706 | jmp .next_arg |
||
707 | ;********************************************************************* |
||
708 | .no_args: |
||
709 | mov al,0 |
||
710 | stosb |
||
711 | ret |
||
712 | ;********************************************************************* |
||
713 | WriteConsoleA: ; handle, buf, buf_size, num_wrote, NULL |
||
714 | push ebx esi edi |
||
715 | mov esi,[esp+16+4] |
||
716 | mov ecx,[esp+16+8] |
||
717 | cld |
||
718 | ;--------------------------------------------------------------------- |
||
719 | @@: |
||
720 | push ecx |
||
721 | movzx edx,byte[esi] |
||
722 | push edx |
||
723 | call putchar |
||
724 | add esp,4 |
||
725 | inc esi |
||
726 | pop ecx |
||
727 | loop @b |
||
728 | |||
729 | pop edi esi ebx |
||
730 | ret 20 |
||
731 | ;********************************************************************* |
||
732 | CreateFileA: ; filename, access_mode, share_mode, security_attr, creation_disposition, flags, template |
||
733 | push ebx esi edi |
||
734 | cmp byte[esp+16+16],3 |
||
735 | push open_mode |
||
736 | je @f |
||
737 | |||
738 | mov dword[esp],create_mode |
||
739 | ;--------------------------------------------------------------------- |
||
740 | @@: |
||
741 | pushd [esp+16+0+4] |
||
742 | call fopen |
||
743 | add esp,8 |
||
744 | or eax,eax |
||
745 | jnz @f |
||
746 | |||
747 | or eax,-1 |
||
748 | ;--------------------------------------------------------------------- |
||
749 | @@: |
||
750 | pop edi esi ebx |
||
751 | ret 28 |
||
752 | ;********************************************************************* |
||
753 | GetFileSize: ; handle, high_part |
||
754 | push ebx esi edi |
||
755 | pushd [esp+16+0] |
||
756 | call ftell |
||
757 | |||
758 | mov [esp],eax |
||
759 | pushd 2 0 [esp+16+0+12] ; go to EOF |
||
760 | call fseek |
||
761 | |||
762 | add esp,12 |
||
763 | pushd [esp+16+0+4] |
||
764 | call ftell |
||
765 | |||
766 | add esp,4 |
||
767 | xchg eax,[esp] |
||
768 | pushd 0 eax [esp+16+0+12] ; go to BOF |
||
769 | call fseek |
||
770 | |||
771 | add esp,12 |
||
772 | pop eax |
||
773 | pop edi esi ebx |
||
774 | ret 8 |
||
775 | ;********************************************************************* |
||
776 | VirtualAlloc: ; address, size, alloc_type, mem_protection |
||
777 | push ebx esi edi |
||
778 | mov eax,[esp+16+4] |
||
779 | add eax,4095 |
||
780 | and eax,not 4095 |
||
781 | push eax |
||
782 | call malloc |
||
783 | |||
784 | add esp,4 |
||
785 | pop edi esi ebx |
||
786 | ret 16 |
||
787 | ;********************************************************************* |
||
788 | ReadFile: ; handle, buf, buf_size, num_read, overlapped |
||
789 | push ebx esi edi |
||
790 | pushd [esp+16+0] 1 [esp+16+8+8] [esp+16+4+12] |
||
791 | call fread |
||
792 | |||
793 | add esp,16 |
||
794 | mov [esp+16+12],eax |
||
795 | cmp eax,1 |
||
796 | je @f |
||
797 | |||
798 | xor eax,eax |
||
799 | ;--------------------------------------------------------------------- |
||
800 | @@: |
||
801 | pop edi esi ebx |
||
802 | ret 20 |
||
803 | ;********************************************************************* |
||
804 | WriteFile: ; handle, buf, buf_size, num_wrote, overlapped |
||
805 | push ebx esi edi |
||
806 | pushd [esp+16+0] 1 [esp+16+8+8] [esp+16+4+12] |
||
807 | call fwrite |
||
808 | |||
809 | add esp,16 |
||
810 | mov [esp+16+12],eax |
||
811 | cmp eax,1 |
||
812 | je @f |
||
813 | |||
814 | xor eax,eax |
||
815 | ;--------------------------------------------------------------------- |
||
816 | @@: |
||
817 | pop edi esi ebx |
||
818 | ret 20 |
||
819 | ;********************************************************************* |
||
820 | CloseHandle: ; handle |
||
821 | push ebx esi edi |
||
822 | pushd [esp+16+0] |
||
823 | call fclose |
||
824 | add esp,4 |
||
825 | pop edi esi ebx |
||
826 | ret 4 |
||
827 | ;********************************************************************* |
||
828 | VirtualFree: ; address, size, free_type |
||
829 | push ebx esi edi |
||
830 | pushd [esp+16+0] |
||
831 | call free |
||
832 | add esp,4 |
||
833 | pop edi esi ebx |
||
834 | ret 12 |
||
835 | ;********************************************************************* |
||
836 | ExitProcess: |
||
837 | pushd [esp+4] |
||
838 | call exit |
||
839 | ret 4 |
||
840 | ;********************************************************************* |
||
841 | include 'lzma_compress.inc' |
||
842 | include 'lzma_set_dict_size.inc' |
||
843 | ;********************************************************************* |
||
844 | section ".const" align 4 |
||
845 | ;--------------------------------------------------------------------- |
||
846 | align 4 |
||
847 | LiteralNextStates: |
||
848 | db 0,0,0,0,1,2,3,4,5,6,4,5 |
||
849 | MatchNextStates: |
||
850 | db 7,7,7,7,7,7,7,10,10,10,10,10 |
||
851 | RepNextStates: |
||
852 | db 8,8,8,8,8,8,8,11,11,11,11,11 |
||
853 | ShortRepNextStates: |
||
854 | db 9,9,9,9,9,9,9,11,11,11,11,11 |
||
855 | ;--------------------------------------------------------------------- |
||
856 | info_str db 'KPack - Kolibri Packer, version 0.11',13,10 |
||
857 | db 'Uses LZMA v4.32 compression library',13,10,13,10 |
||
858 | info_len = $ - info_str |
||
859 | usage_str db 'Written by diamond in 2006, 2007 specially for KolibriOS',13,10 |
||
860 | db 'LZMA compression library is copyright (c) 1999-2005 by Igor Pavlov',13,10 |
||
861 | db 13,10 |
||
862 | db 'Usage: kpack [--nologo] |
||
863 | usage_len = $ - usage_str |
||
864 | errload_str db 'Cannot load input file',13,10 |
||
865 | errload_len = $ - errload_str |
||
866 | outfileerr_str db 'Cannot save output file',13,10 |
||
867 | outfileerr_len = $ - outfileerr_str |
||
868 | nomem_str db 'No memory',13,10 |
||
869 | nomem_len = $ - nomem_str |
||
870 | too_big_str db 'failed, output is greater than input.',13,10 |
||
871 | too_big_len = $ - too_big_str |
||
872 | compressing_str db 'Compressing ... ' |
||
873 | compressing_len = $ - compressing_str |
||
874 | ;********************************************************************* |
||
875 | section ".data" writeable align 4 |
||
876 | bNoLogo db 0 |
||
877 | done_str db 'OK! Compression ratio: ' |
||
878 | ratio dw '00' |
||
879 | db '%',13,10,13,10 |
||
880 | done_len = $ - done_str |
||
881 | |||
882 | use_lzma = 1 |
||
883 | |||
884 | use_no_calltrick = 0 |
||
885 | use_calltrick1 = 40h |
||
886 | use_calltrick2 = 80h |
||
887 | |||
888 | method db 1 |
||
889 | ;********************************************************************* |
||
890 | section ".bss" writeable align 4 |
||
891 | infilename dd ? |
||
892 | outfilename dd ? |
||
893 | infile dd ? |
||
894 | outfile1 dd ? |
||
895 | outfile2 dd ? |
||
896 | outfile dd ? |
||
897 | outfilebest dd ? |
||
898 | workmem dd ? |
||
899 | insize dd ? |
||
900 | outsize dd ? |
||
901 | LastWriteTime dq ? |
||
902 | LastAccessTime dq ? |
||
903 | CreationTime dq ? |
||
904 | lzma_dictsize dd ? |
||
905 | ct1 db 256 dup (?) |
||
906 | ctn dd ? |
||
907 | cti db ? |
||
908 | |||
909 | program_arguments db 512 dup (?) |
||
910 | |||
911 | include 'data.inc' |
||
3587 | fedesco | 912 | ;********************************************************************* |