; $Linux version 2.2.20 (root@mothership) (gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)) 
; 
; s0t4ipv6@shellcode.com.ar
; Tommy the Cat ;-) for pulldump progie
; 
; $0010v0x047d2
; 

segment .text

global main

main:
	; C convencion
	push	ebp
	mov	ebp, esp
	sub	esp, 04h	; marco para nuestro caracter dinamico

	; Argumento 
	mov	ebx, [edi+4]
	mov	eax, 05h		; sys_open
	xor	ecx, ecx
	int	80h
	test	eax,eax
	js	noargs

; eax = 0x5 ebx = 0x80483c0 ecx = 0x2 edx = 0x2108b8

	xchg	ebx, eax
	xor	eax,eax
	xor	edx,edx

	mov	[ebp],eax	; quiero ceros en la pila
	inc	edx		; leo de 1 caracter por vez

lup:	lea	ecx, [buf]
	mov	byte al, 03h
	int	80h
	test	eax, eax
	jne	imprimo
	
salir:
        mov     byte al, 06h    ; sys_close
        int     80h
        inc     eax             ; sys_exit
        int     80h

; eax = 0x0 ; ebx = 0x5 ; ecx = 0xbffffa0c ; edx = 0x1

imprimo:
	push	ebx		; guardamos el valor del file descriptor viejo
	mov	byte al, [buf]
	xor	byte al, 7fh	; pea !!!!!!!!!!
	mov	[buf], eax
	mov	byte bl, 01h
	mov	byte al, 04h
	int 	80h	
	pop	ebx		; recuperamos el fd
	jmp	lup

noargs:
	xor	ebx,ebx
	mov	ecx, banner
	xor	edx,edx
	mov	byte dl, 36h	; banner length
	sub	eax,eax
	mov	byte al, 04h
	int	80h
	call	salir

segment	.data
buf:	db	'00h'
banner:	db	's0t4ipv6 the Cat, 0010v0x047d2',10
	db	'usage: scat [pullfile]',10

