-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelf.3.s
67 lines (53 loc) · 1.26 KB
/
elf.3.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
; This is a minimal ELF hand-assembled using nasm.
; brew install nasm
; /usr/local/bin/nasm elf.3.s -o out
; void _start() {
; exit(3);
; }
bits 64
%define BASE_ADDR 0x00400000
%define EM_X86_64 0x0000003E
%define ET_EXEC 0x00000002
%define EV_CURRENT 0x00000001
%define PT_LOAD 0x00000001
%define PF_X 0x01
%define PF_W 0x02
%define PF_R 0x04
file_start:
exec_start:
elf_header_start:
; struct Elf64_Ehdr
db 0x7F, 'ELF', 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; e_ident
dw ET_EXEC ; e_type
dw EM_X86_64 ; e_machine
dd EV_CURRENT ; e_version
dq code_start + BASE_ADDR ; e_entry
dq program_headers_start ; e_phoff
dq 0 ; e_shoff
dd 0 ; e_flags
dw elf_header_end - elf_header_start ; e_ehsize
dw 0x38 ; e_phentsize
dw 1 ; e_phnum
dw 0 ; e_shentsize
dw 0 ; e_shnum
dw 0 ; e_shstrndx
elf_header_end:
program_headers_start:
; struct Elf64_Phdr
dd PT_LOAD ; p_type
dd PF_X | PF_R ; p_flags
dq exec_start ; p_offset
dq exec_start + BASE_ADDR ; p_vaddr
dq exec_start + BASE_ADDR ; p_paddr
dq exec_end - exec_start ; p_filesz
dq exec_end - exec_start ; p_memsz
dq 0x00200000 ; p_align
program_headers_end:
align 16, db 0
code_start:
mov rax, dword 60
mov rdi, dword 3
syscall
ret
code_end:
exec_end: