All pastes #466505 Raw Edit

Something

public text v1 · immutable
·published 2007-05-01 00:46 UTC
rendered paste body
[bits 32]

%define		sys_socketcall	102
%define		server		0x77841955	; irc.anomalous-security.org
%define		port		0xb1a		; 6667
%define		stdin		0
%define		stdout		1
%define		sys_connect	3
%define		sys_read	3
%define		sys_write	4
%define		sys_select	142
%define		maxlen		510


[section .data]
	nick             db	"NICK testing",0x0A
	user             db	'USER test 0 0 :test',0x0A
	channel          db	"JOIN #test",0x0A


[section .bss]
	msg		resb	510 ; irc messages are 510 + \r\n at most ///THIS ISN'T TRUE
	fd		resd	1
	fdset		resb	40


[section .text]
global _start

_start:
	mov eax, sys_socketcall
	push ebx		; ebx = 0
	inc ebx
	push ebx
	mov dl, 0x02		; edx = 2
	push edx
	mov ecx, esp
	int 0x80
	mov [fd], eax
connect: 
	mov ebx, sys_connect
	mov eax, sys_socketcall
	push dword server
	push word port
	push word 0x02
	mov ecx, esp
	push dword 0x10
	push ecx   ; sockaddr_in
	push dword [fd]
	mov ecx, esp
	int 0x80
signin:
;	mov ebx, [fd]		; this seems to do fuck all so I commented it out tgo
	mov ecx, user
	call write
	mov ecx, nick
	call write
	mov ecx, channel
	call write
whileone:
	call set_fdset
select:
	mov eax, sys_select
	mov ebx, 0x0A		; number of fds to check
	mov ecx, fdset		; read
	xor edx, edx		; write
	mov esi, edx		; error
	push edx		; smaller than push dword 0x00
	push dword 0x01		; 1 second timeout
	mov edi, esp
	int 0x80
	add esp, 0x08
	test eax, eax		; timeout
	je whileone
	mov ecx, stdin
	call fd_isset
	jne readin		; test stdin for reading
	mov ecx, [fd]
	call fd_isset
	je whileone		; test stdin for reading
readsock:
	mov ebx, [fd]
	mov ecx, msg
	call read
	mov edx, eax
	mov ebx, stdout
	mov ecx, msg
	call writelen
	jmp whileone		; before there was a retn here, which caused the segmentation fault

readin:
	mov ebx, stdin
	mov ecx, msg
	call read
	mov edx, eax
	mov ebx, [fd]
	mov ecx, msg
	call writelen
	retn

close:
	mov ebx, [fd]
	mov eax, 0x06
	int 0x80
quit:
	xor eax,eax
	inc al
	int 0x80

	; expects ecx to point to string, ebx to file desc
	; how much was written is in eax on retn
	; ----- I completley re-wrote strlen and put it in the write procedure tgo. -----
write:
	mov esi, ecx		; ecx = string address
	xor edx, edx
strlen.loop:
	inc edx
	lodsb
	cmp al, 0x0A
	jne strlen.loop
	mov eax, sys_write	; edx = stringth length
	int 0x80
	test eax, eax
	jl close
	retn

	; writelen
	; excepts ebx,ecx,edx to be set to their proper values
writelen:
	mov eax, sys_write
	int 0x80
	test eax, eax
	jl close
	retn

	; on call:
	; ecx points to buffer to fill with what is read
	; ebx to point to fd
read:
	mov edx, maxlen
	mov eax, sys_read
	int 0x80
	retn

	; sets master fd_set of stdin and remote socket
set_fdset:
	mov dword [fdset], 0x00  ; FD_ZERO
	mov ecx, stdin
	call fd_set
	mov ecx, [fd]
	call fd_set
	retn
	
	; takes number to set in ecx
	; |= (1<<(n)))
fd_set:
	xor ebx, ebx
	inc ebx
	shl ebx, cl
	or [fdset], ebx		
	retn

	; checks if the fd (ecx) is set in fdset
fd_isset:
	bt [fdset], ecx
	setb cl
	test cl, cl
	retn