forked from smtlaissezfaire/bcompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex1.he
105 lines (92 loc) · 2.05 KB
/
hex1.he
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
#
# HEX1 for Linux-i386-ELF
#
# Copyright (C) 2001, Edmund GRIMLEY EVANS <[email protected]>
#
# Elf32_Ehdr
7f 45 4c 46 01 01 01 # e_ident
00 00 00 00 00 00 00 00 00
02 00 # e_type
03 00 # e_machine
01 00 00 00 # e_version
54 80 04 08 # e_entry = 0x08048000 + len(ehdr) + len(phdr)
34 00 00 00 # e_phoff = len(ehdr)
00 00 00 00 # e_shoff
00 00 00 00 # e_flags
34 00 # e_ehsize = len(ehdr)
20 00 # e_phentsize = len(phdr)
01 00 # e_phnum
00 00 # e_shentsize
00 00 # e_shnum
00 00 # e_shstrndx
# Elf32_Phdr
01 00 00 00 # p_type
00 00 00 00 # p_offset
00 80 04 08 # p_vaddr = 0x08048000
00 80 04 08 # p_paddr = 0x08048000
bf 00 00 00 #! # p_filesz = len(ehdr) + len(phdr) + len(prog)
bf 00 00 00 #! # p_memsz = len(ehdr) + len(phdr) + len(prog)
05 00 00 00 # p_flags
00 10 00 00 # p_align
# Enter here:
# A stackless implementation of exit(42), for debugging:
# 31 c0 40 b3 2a cd 80
# _start:
e8 25 00 00 00 # call gethex
c1 e0 04 # sall $4,%eax
50 # push %eax
e8 1c 00 00 00 # call gethex
01 04 24 # add %eax,(%esp)
e8 03 00 00 00 # call putchar
58 # pop %eax
eb e7 # jmp _start
# +25
# putchar:
31 db # xor %ebx,%ebx
43 # inc %ebx
8d 4c 24 04 # lea 4(%esp),%ecx
89 da # mov %ebx,%edx
b8 04 00 00 00 # mov $4,%eax
cd 80 # int $0x80
c3 # ret
# +17
# gethex:
e8 1f 00 00 00 # call getchar
83 f8 23 # cmp $35,%eax
75 0c # jne .convhex
# +10
# .loop:
e8 15 00 00 00 # call getchar
83 f8 0a # cmp $10,%eax
75 f6 # jne .loop
eb ea # jmp gethex
# +12
# .convhex:
83 e8 30 # sub $48,%eax
7c e5 # jl gethex
83 f8 30 # cmp $48,%eax
7c 03 # jl .ret
83 e8 27 # sub $39,%eax
# +13
# 1 byte
c3 # ret
# +1
# getchar:
6a 00 # push $0
31 db # xor %ebx,%ebx
89 e1 # mov %esp,%ecx
89 da # mov %ebx,%edx
42 # inc %edx
b8 03 00 00 00 # mov $3,%eax
cd 80 # int $0x80
85 c0 # test %eax,%eax
74 02 # je exit ##
58 # pop %eax
c3 # ret
# +22
# exit:
31 c0 # xor %eax,%eax
89 c3 # mov %eax,%ebx
40 # inc %eax
cd 80 # int $0x80
# +7