Skip to content

Instantly share code, notes, and snippets.

@303248153
Last active April 21, 2018 00:48
Show Gist options
  • Save 303248153/a00db7acbf0f9e391a35cf8f118f59fb to your computer and use it in GitHub Desktop.
Save 303248153/a00db7acbf0f9e391a35cf8f118f59fb to your computer and use it in GitHub Desktop.
system call example, use gcc -m32 32-{name}.S or gcc 64-{name}.S
.intel_syntax noprefix
.data
hello_string:
.ascii "Hello World!\n"
len:
.long len-hello_string
.text
.global main
main:
push ebp
mov ebp, esp
mov edx, len
lea ecx, hello_string
mov ebx, 1
mov eax, 4
int 0x80
mov eax, 0
leave
ret
.intel_syntax noprefix
.data
hello_string:
.ascii "Hello World!\n"
len:
.long len-hello_string
.text
.global main
main:
push ebp
mov ebp, esp
mov edx, len
lea ecx, hello_string
mov ebx, 1
mov eax, 4
call get_selfaddr
get_selfaddr:
add dword ptr [esp], sysenter_ret-get_selfaddr
push ecx
push edx
push ebp
mov ebp, esp
sysenter
sysenter_ret:
mov eax, 0
leave
ret
.intel_syntax noprefix
.data
hello_string:
.ascii "Hello World!\n"
len:
.long len-hello_string
.text
.global main
main:
push rbp
mov rbp, rsp
mov rdx, len[rip]
lea rsi, hello_string[rip]
mov rdi, 1
mov rax, 1
syscall
mov rax, 0
leave
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment