rendered paste body; irc client ;D
; tgo@anomalous-security.org
; TODO:
; ping/pong reply
; version reply
bits 32
global _start
section .data
stdin dd 0
stdout dd 1
sys_socketcall dd 102
sys_socket db 1
sys_connect dd 3
sys_read dd 3
sys_write dd 4
sys_select dd 142
fd dd 0
maxlen dd 510
msg times 510 db 0 ; irc messages are 510 + \r\n at most
nick db "NICK testing",0xa
user db 'USER test 0 0 :test',0xa
server dd 0x77841955 ; irc.anomalous-security.org
port dw 0xb1a ; 6667
channel db "JOIN #test",0xa
fdset times 10 dd 0
section .text
_start:
socket:
push dword ebx
add byte bl,1
push dword ebx
mov byte dl,2
push dword edx
mov dword ecx,esp
mov dword eax,[sys_socketcall]
int 0x80 ; socket
cmp byte al,1
jl near quit
mov dword [fd],eax
connect:
push dword [server]
push word [port]
push word 2
mov dword ecx,esp
push byte 0x10
push dword ecx ; sockaddr_in
push dword [fd]
mov dword ecx,esp
mov dword ebx,[sys_connect]
mov dword eax,[sys_socketcall]
int 0x80
test eax,eax
jne near quit
signin:
mov ebx,[fd]
mov dword ecx,user
call write
mov dword ecx,nick
call write
mov dword ecx,channel
call write
sub dword esp,4 ; no idea dont ask why
whileone:
call set_fdset
select:
mov dword eax,[sys_select]
mov dword ebx,10 ; number of fds to check
mov dword ecx,fdset ; read
xor dword edx,edx ; write
mov dword esi,edx ; error
push dword 0
push dword 1 ; 1 second timeout
mov dword edi,esp
int 0x80
add dword esp,8
test eax,eax
jl close
test eax,eax ; timeout
je whileone
mov dword ecx,[stdin]
call fd_isset
je notreadin ; test stdin for reading
readin:
mov ebx,[stdin]
mov ecx,msg
call read
mov dword edx,eax
mov dword ebx,[fd]
mov dword ecx,msg
call writelen
ret
notreadin:
mov dword ecx,[fd]
call fd_isset
jne readsock ; test stdin for reading
jmp whileone
close:
mov dword ebx,[fd]
mov dword eax,6
int 0x80
quit:
xor dword eax,eax
inc byte al
int 0x80
readsock:
mov ebx,[fd]
mov ecx,msg
call read
mov dword edx,eax
mov dword ebx,[stdout]
mov dword ecx,msg
call writelen
ret
; write
; expects ecx to point to string, ebx to file desc
; how much was written is in eax on ret
write:
call strlen ; sets edx to length
mov dword eax,[sys_write]
int 0x80
test eax,eax
jl close
ret
; writelen
; excepts ebx,ecx,edx to be set to their proper values
writelen:
mov dword eax,[sys_write]
int 0x80
test eax,eax
jl close
ret
; strlen
; call:
; ecx points to string
; return:
; edx holds length since most syscalls use edx for the length
strlen:
push dword eax
push dword ecx
mov dword edi,ecx
mov dword ecx,[maxlen]
xor dword eax,eax
mov byte al,0xa
cld
repne scasb
mov dword edx,[maxlen]
sub dword edx,ecx
pop dword ecx
pop dword eax
ret
; read
; on call:
; ecx points to buffer to fill with what is read
; ebx to point to fd
read:
mov dword edx,[maxlen]
mov dword eax,[sys_read]
int 0x80
test eax,eax
jl quit
ret
; set_fdset
; sets master fd_set of stdin and remote socket
set_fdset:
mov dword [fdset],0 ; FD_ZERO
mov dword ecx,[stdin]
call fd_set
mov dword ecx,[fd]
call fd_set
ret
; fd_set
; takes number to set in ecx
; |= (1<<(n)))
fd_set:
mov dword ebx,1
shl dword ebx,cl
or dword [fdset],ebx
ret
; fd_isset
; checks if the fd (ecx) is set in fdset
fd_isset:
bt dword [fdset],ecx
setb byte cl
test cl,cl
ret