-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootsec.asm
78 lines (58 loc) · 1.01 KB
/
bootsec.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
org 0x7c00
xor cx, cx
mov ds, cx
mov es, cx
mov si, data_start
mov di, 0x7e00
xor ax, ax
decompress:
; while (ip < ibuf + ilen) {
.next:
cmp si, data_end
jae .done
; ctrl = *ip++
lodsb
; al = (ctrl & 0x7), ah = (ctrl >> 3)
aam 8
; if ((ctrl & 0x7) == 0) goto .literal
jz .literal
; len = (ctrl & 0x7)
xchg cl, al ; al = 0
; ref = op - ((ctrl >> 3) << 8) - 1
xor dx, dx
xchg dh, ah ; ah = 0
not dx
add dx, di
; if (len == 7) len += *ip++
cmp cl, 7
jne .format1
.format2:
lodsb
add cx, ax
.format1:
; ref -= *ip++
lodsb
sub dx, ax
; while (len--) { *op++ = *ref++; }
push si
mov si, dx
rep movsb
pop si
; } /* while */
jmp .next
.literal:
; cl = len
mov cl, ah
; while (len--) { *op++ = *ip++; }
rep movsb
; } /* while */
jmp .next
.done:
; jump to uncompressed payload
jmp 0x7e00
; compressed payload
data_start:
incbin "payload.lzf"
data_end:
times 512 - ($ - $$) - 2 db 0
dw 0xaa55