Skip to content

Instantly share code, notes, and snippets.

@mz0
Last active April 28, 2016 12:41
Show Gist options
  • Save mz0/02baa2175391eec5ab692d4afe96279f to your computer and use it in GitHub Desktop.
Save mz0/02baa2175391eec5ab692d4afe96279f to your computer and use it in GitHub Desktop.
Tiny42.asm with a tiny ORG - untested
BITS 64
org 0x1000
; cat /proc/sys/vm/mmap_min_addr
; sysctl -w vm.mmap_min_addr="0"
; https://wiki.debian.org/mmap_min_addr Debian 5.0.4 kernel 2.6.26 min 4096 2010.01.30
ehdr: ; Elf64_Ehdr
db 0x7f, "ELF", 2, 1, 1, 0 ; e_identr
;'2' class ELF64, '1' - Little-ending data, '1' version, '0' none/SYSV ('1' HP-UX is also Ok)
times 8 db 0
; '0' ABI version, 7 bytes padding
dw 2 ; e_type 2=ET_EXEC
dw 0x3e ; e_machine 62 for AMD64, 3 - i386, 6 - i486
dd 1 ; e_version
dq _start ; e_entry
dq phdr-$$ ; e_phoff
dq 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: ; Elf64_Phdr
dd 1 ; p_type
dd 5 ; p_flags
dq 0 ; p_offset
dq $$ ; p_vaddr
dq $$ ; p_paddr
dq filesize ; p_filesz
dq filesize ; p_memsz
dq 0x1 ; p_align
phdrsize equ $ - phdr
_start:
mov rax, 60 ; sys_exit
mov rdi, 42 ; int status
syscall
filesize equ $ - $$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment