-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelinuxi386.nasm
More file actions
65 lines (55 loc) · 2.72 KB
/
helinuxi386.nasm
File metadata and controls
65 lines (55 loc) · 2.72 KB
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
;
; helinuxi386.nasm: hello-world as a tiny Linux i386 ELF executable
; by [email protected] at Mon Jul 13 21:05:33 CEST 2020
;
; $ nasm -f bin -o helinuxi386 helinuxi386.nasm && chmod +x helinuxi386
;
; Based on https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
;
bits 32
org 0x08048000
ehdr: ; Elf32_Ehdr
db 0x7F, "ELF" ; e_ident[EI_MAG*]
db 1 ; e_ident[EI_CLASS]
db 1 ; e_ident[EI_DATA]
db 1 ; e_ident[EI_VERSION]
db 3 ; e_ident[EI_OSABI]
dd 0, 0 ; e_ident[EI_PAD+]
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
dd _start ; e_entry
dd phdr - $$ ; e_phoff
dd 0 ; e_shoff
dd 0 ; e_flags
dw ehdrsize ; e_ehsize
dw phdrsize ; e_phentsize
dw 1 ; e_phnum
dw 0 ; e_shentsize
dw 0 ; e_shnum
dw 0 ; e_shstrndx
ehdrsize equ $ - ehdr
phdr: ; Elf32_Phdr
dd 1 ; p_type
dd 0 ; p_offset
dd $$ ; p_vaddr
dd $$ ; p_paddr
dd filesize ; p_filesz
dd memsize ; p_memsz
dd 5 ; p_flags
dd 0x1000 ; p_align
phdrsize equ $ - phdr
_start:
mov eax, 4 ; __NR_write.
mov ebx, 1 ; STDOUT_FILENO.
mov ecx, msg
mov edx, msg_end-msg
int 0x80
xor eax, eax
inc eax ; __NR_exit.
xor ebx, ebx ; EXIT_SUCCESS.
int 0x80
msg: db 'Hello, World!', 10
msg_end:
filesize equ $ - $$
memsize equ $ - $$