forked from hellman/shtest
-
Notifications
You must be signed in to change notification settings - Fork 2
/
i386.S
73 lines (66 loc) · 1.52 KB
/
i386.S
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
#include "asm_common.h"
.file "i386.s"
.globl cdecl(print_regs)
cdecl(print_regs):
push esp
push ebp
pushf // must be saved here, or the following operation may affact eflags, push operation does not affact eflags
mov ebp, esp
and esp, 0xfffffff0 // for alignment, will cause segfault in printf SSE instructions if not correctly aligned
sub esp, 8
push ebp
xor ebp, ebp
push bp
push SS // 2 bytes
push bp
push CS // 2 bytes
push bp
push DS // 2 bytes
push bp
push ES // 2 bytes
push FS // 4 bytes
push GS // 4 bytes
// push eflags
push bp
mov ebp, [esp+26]
mov bp, [ebp]
push bp
// push general registers
push edi
push esi
push ebx
push edx
push ecx
push eax
mov ebp, [esp+52]
// reserve space for eip, esp, ebp
sub esp, 12
// ebp
mov eax, [ebp+2]
mov [esp+8], eax
// esp
mov eax, [ebp+6]
add eax, 4
mov [esp+4], eax
// eip
mov eax, [ebp+10]
mov [esp], eax
// push fmt string
jmp print_regs_fmt
get_back:
call cdecl(printf)
add esp, 16
pop eax
pop ecx
pop edx
pop ebx
pop esi
pop edi
add esp, 42
popf
pop ebp
pop esp
ret
print_regs_fmt:
call get_back
.asciz "$eip = 0x%x\n$esp = 0x%x\n$ebp = 0x%x\n$eax = 0x%x\n$ecx = 0x%x\n$edx = 0x%x\n$ebx = 0x%x\n$esi = 0x%x\n$edi = 0x%x\n$eflags = 0x%x\n$gs = 0x%x\n$fs = 0x%x\n$es = 0x%x\n$ds = 0x%x\n$cs = 0x%x\n$ss = 0x%x\n"