1 ; vim
: set filetype
=fasm foldmethod
=marker commentstring
=;
%s colorcolumn
=101 :
2 inflate
: namespace inflate
8 mov rsi
, 0x0000000000000001 ; RTLD_LAZY
11 jz
.err_module_open_failed
12 mov
[module.handle
], rax
21 error module_open
, module_open_failed
, module.name
22 error module_inflateInit_sym
, sym_resolution_failed
, inflateInit.sym
23 error module_inflateEnd_sym
, sym_resolution_failed
, inflateEnd.sym
24 error module_inflate_sym
, sym_resolution_failed
, inflate.sym
25 ;
---------------------------------------------------------------------------------------------------
26 ; in
: rdi
= inflate_bytes_start
27 ; in
: rsi
= inflate_bytes_n_max
28 ; in
: rdx
= deflate_bytes_start
29 ; in
: rcx
= deflate_bytes_n
30 define inflate_bytes_start rbx
31 define inflate_bytes_n_max
r12
32 define inflate_bytes_n_max_dword r12d ;
32bits dword
33 define deflate_bytes_start
r13
34 define deflate_bytes_n
r14
35 define deflate_bytes_n_dword r14d ;
32bits dword
39 and rsp
, not 0xf ; align the stack here for external calls
40 mov
[rbp
- 8 * 1], inflate_bytes_start
41 mov
[rbp
- 8 * 2], inflate_bytes_n_max
42 mov
[rbp
- 8 * 3], deflate_bytes_start
43 mov
[rbp
- 8 * 4], deflate_bytes_n
45 mov inflate_bytes_start
, rdi
46 mov inflate_bytes_n_max
, rsi
47 mov deflate_bytes_start
, rdx
48 mov deflate_bytes_n
, rcx
50 mov qword
[z_stream
+ z_stream_t.zalloc
], 0
51 mov qword
[z_stream
+ z_stream_t.zfree
], 0
52 mov dword
[z_stream
+ z_stream_t.avail_in
], 0
53 mov qword
[z_stream
+ z_stream_t.next_in
], 0
55 lea rsi
, [zlib_version
]
56 mov rdx
, z_stream_t.bytes_n
57 call qword
[inflateInit
]
61 mov qword
[z_stream
+ z_stream_t.next_in
], deflate_bytes_start
62 mov dword
[z_stream
+ z_stream_t.avail_in
], deflate_bytes_n_dword
63 mov qword
[z_stream
+ z_stream_t.next_out
], inflate_bytes_start
64 mov dword
[z_stream
+ z_stream_t.avail_out
], inflate_bytes_n_max_dword
66 mov rsi
, 4 ;
= Z_FINISH we want
a 1 call inflate
68 cmp rax
, 1 ;
= Z_STREAM_END
69 setne
bl ; error
or deflate
not performed in
1 call
(bad omens
)
72 call qword
[inflateEnd
]
78 mov inflate_bytes_start
, [rbp
- 8 * 1]
79 mov inflate_bytes_n_max
, [rbp
- 8 * 2]
80 mov deflate_bytes_start
, [rbp
- 8 * 3]
81 mov deflate_bytes_n
, [rbp
- 8 * 4]
87 ;
---------------------------------------------------------------------------------------------------
88 purge inflate_bytes_start
89 purge inflate_bytes_n_max
90 purge inflate_bytes_n_max_dword
91 purge deflate_bytes_start
93 purge deflate_bytes_n_dword
94 ;
---------------------------------------------------------------------------------------------------
99 mov rdi
, [module.handle
]
100 call PLT.dlclose ;
0 on success
104 ;
---------------------------------------------------------------------------------------------------
107 mov rdi
, [module.handle
]
111 jz
.err_module_#name#_sym_failed
115 macro error name
, fmt
, s
119 call qword
[libc.printf
]