-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspack.asm
115 lines (86 loc) · 2.79 KB
/
spack.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;
;; aPLib compression library - the smaller the better :)
;;
;; fasm safe assembler wrapper for aP_pack
;;
;; Copyright (c) 1998-2014 Joergen Ibsen
;; All Rights Reserved
;;
;; http://www.ibsensoftware.com/
;;
; header format:
;
; offs size data
; --------------------------------------
; 0 dword tag ('AP32')
; 4 dword header_size (24 bytes)
; 8 dword packed_size
; 12 dword packed_crc
; 16 dword orig_size
; 20 dword orig_crc
format MS COFF
public aPsafe_pack as '_aPsafe_pack'
extrn '_aP_pack' as aP_pack
extrn '_aP_crc32' as aP_crc32
; =============================================================
section '.text' code readable executable
aPsafe_pack:
; aPsafe_pack(const void *source,
; void *destination,
; unsigned int length,
; void *workmem,
; int (*callback)(unsigned int, unsigned int, void *),
; void *cbparam)
.ret$ equ 7*4
.src$ equ 8*4 + 4
.dst$ equ 8*4 + 8
.len$ equ 8*4 + 12
.wmem$ equ 8*4 + 16
.cb$ equ 8*4 + 20
.cbp$ equ 8*4 + 24
pushad
mov ebp, esp
mov esi, [ebp + .src$] ; esi -> inbuffer
mov edi, [ebp + .dst$] ; edi -> outbuffer
mov ecx, [ebp + .len$] ; ecx = length
or eax, -1 ; eax = -1
test esi, esi ; check parameters
jz .return_eax ;
test edi, edi ;
jz .return_eax ;
test ecx, ecx ;
jz .return_eax ;
mov ebx, 032335041h
mov [edi], ebx ; set header.tag
mov ebx, 24
mov [edi + 4], ebx ; set header.header_size
add ebx, edi ; ebx -> destination for packed data
mov [edi + 16], ecx ; set header.orig_size
push ecx
push esi
call aP_crc32
add esp, 8
mov [edi + 20], eax ; set header.orig_crc
push dword [ebp + .cbp$] ; callback param
push dword [ebp + .cb$] ; callback
push dword [ebp + .wmem$] ; workmem
push ecx ; length
push ebx ; destination
push esi ; source
call aP_pack
add esp, 24
cmp eax, -1
je .return_eax
mov [edi + 8], eax ; set header.packed_size
mov edx, eax ; edx = packed size
push eax
push ebx
call aP_crc32
add esp, 8
mov [edi + 12], eax ; set header.packed_crc
lea eax, [edx + 24] ; eax = packed size + header size
.return_eax:
mov [esp + .ret$], eax ; return unpacked length in eax
popad
ret
; =============================================================