Skip to content

Instantly share code, notes, and snippets.

@cabron
Created September 18, 2011 14:29
Show Gist options
  • Save cabron/1225122 to your computer and use it in GitHub Desktop.
Save cabron/1225122 to your computer and use it in GitHub Desktop.
format ELF executable
entry _start
stdout = 0
stdin = 1
sys_exit = 1
sys_fork = 2
sys_read = 3
sys_write = 4
sys_waitpid = 7
sys_execv = 11
sys_pipe = 42
sys_dup2 = 63
macro exit n {
mov eax, sys_exit
mov ebx, n
int 80h
}
macro fork regs {
mov eax, sys_fork
mov ebx, regs
int 80h
}
macro read d, buf, len {
mov eax, sys_read
mov ebx, d
mov ecx, buf
mov edx, len
int 80h
}
macro write d, buf, len {
mov eax, sys_write
mov ebx, d
mov ecx, buf
mov edx, len
int 80h
}
macro wait status {
mov eax, sys_waitpid
mov ebx, -1
mov ecx, status
xor edx, edx
int 80h
}
macro pipe fd {
mov eax, sys_pipe
mov ebx, fd
int 80h
}
macro dup2 d1, d2 {
mov eax, sys_dup2
mov ebx, d1
mov ecx, d2
int 80h
}
macro execv c, arg, env {
mov eax, sys_execv
mov ebx, get
mov ecx, get_arg
mov edx, get_env
int 80h
}
segment readable executable ; ----------------------------------
_start:
pipe fd1
test eax, eax
jnz .error
fork regs
cmp eax, 0
jl .error
test eax, eax
jne @f
dup2 [fd1+4], stdin
cmp eax, 0
jl .error
execv get, get_arg, get_env
jmp .end
@@:
read [fd1], buf, 4096
cld
mov ecx, eax
mov al, 'd'
mov ebx, 'ane/'
mov edi, buf
.loop:
repne scasb
jne .nf
cmp dword [edi], ebx
jne .loop
call print
jmp .loop
.nf:
cmp edi, buf+4096
jnb @r
@@:
wait 0
cmp eax, 0
jl .error
.end:
exit 0
.error:
exit 1
print: ;edi: "ane/" ... "/" ----------------------------------
pusha
add edi, 4
push edi
mov al, '/'
mov ecx, 256
repne scasb
mov [len], edi
dec edi
mov byte[edi], 0Ah
pop edi
sub [len], edi
write stdout, edi, [len]
popa
ret
segment readable writeable ; ----------------------------------
get db '/usr/bin/GET', 0
get_arg dd get
.url dd ranking
dd 0
get_env dd 0
ranking db 'wykop.pl/ranking', 0
regs:
dd 15 dup(0)
fd1 dd ?, ?
fd2 dd ?, ?
len dd ?
buf db 4096 dup(?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment