-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheck.asm
67 lines (44 loc) · 1.43 KB
/
scheck.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
;;
;; aPLib compression library - the smaller the better :)
;;
;; fasm safe assembler crc checker
;;
;; Copyright (c) 1998-2014 Joergen Ibsen
;; All Rights Reserved
;;
;; http://www.ibsensoftware.com/
;;
format MS COFF
public aPsafe_check as '_aPsafe_check'
extrn '_aP_crc32' as aP_crc32
; =============================================================
section '.text' code readable executable
aPsafe_check:
; aPsafe_check(const void *source)
.ret$ equ 7*4
.src$ equ 8*4 + 4
pushad
mov esi, [esp + .src$] ; esi -> buffer
test esi, esi
jz .return_error
mov ebx, [esi] ; ebx = header.tag
cmp ebx, 032335041h ; check tag == 'AP32'
jne .return_error
mov ebx, [esi + 4] ; ebx = header.header_size
cmp ebx, 24 ; check header_size >= 24
jb .return_error
add ebx, esi ; ebx -> packed data
push dword [esi + 8] ; push header.packed_size
push ebx
call aP_crc32
add esp, 8
cmp eax, [esi + 12] ; check eax == header.packed_crc
mov eax, [esi + 16] ; eax = header.orig_size
je .return_eax
.return_error:
or eax, -1 ; eax = -1
.return_eax:
mov [esp + .ret$], eax ; return unpacked length in eax
popad
ret
; =============================================================