Paste number 22515: send_tcp.asm

Paste number 22515: send_tcp.asm
Pasted by: pireau
When:2 years, 11 months ago
Share:Tweet this! | http://paste.lisp.org/+HDF
Channel:None
Paste contents:
Raw Source | XML | Display As
; File name: send_tcp.asm 
; Description: sends "Ah, deja?\r\n" to port 1337 of 127.0.0.1
; Historic:
;
;   +---------------+------------+------------------+
;   |Author         |Date        | Description      |
;   +---------------+------------+------------------+
;   | pireau        | 06-08-05   |  1st code entry  |
;   +---------------+------------+------------------+

%define SYS_SOCKETCALL  102
%define SYS_SOCKET  1
%define SYS_CONNECT 3
%define SYS_EXIT    SYS_SOCKET
%define PF_INET     2
%define SOCK_STREAM SYS_SOCKET
%define IPPROTO_TCP 6
%define SYS_SEND    9

section .data
test_str db "Ah, deja ?",0xD,0xA

section .bss
sockaddr    resw 4
x_args      resw 3
send_args   resw 4

section .text
global _start

_start:
    mov dword [x_args],  PF_INET        ; the first element of the array contains the protocol family, PF_INET.
    mov dword [x_args+4],SOCK_STREAM    ; second element contains the socket type, SOCK_STREAM.
    mov dword [x_args+8],IPPROTO_TCP    ; third element is the protocol type, IPPROTO_TCP. 

    mov eax,SYS_SOCKETCALL              ; System call number.   
    mov ebx,SYS_SOCKET                  ; 1st systam call argument, here the function number.
    lea ecx,[x_args]                    ; load the args...
    int 80h                             ; *poke*

    mov dword [sockaddr],   0x39050002  ; PF_INET and htons(1337) rolled into one.
    mov dword [sockaddr+4], 0x0100007F  ; inet_addr("127.0.0.1");
    mov dword [sockaddr+8], 0x00000000  ; padding ...

    mov dword [x_args], 3               ; 1st element conains the socket fd.
    mov eax,sockaddr
    mov dword [x_args+4], eax           ; 2nd is sockaddr_in...
    mov dword [x_args+8], 0x10          ; 3rd element is the size... 16 bytes.

    mov eax,SYS_SOCKETCALL              ; System call number.
    mov ebx,SYS_CONNECT                 ; 1st systam call argument, here the function number.
    lea ecx,[x_args]                    ; load the arguments.
    int 80h                             ; *poke*

    mov dword [send_args],3             ; 1st element contains the socket fd.
    mov eax,test_str
    mov dword [send_args+4],eax         ; 2nd is the address of our test string.
    mov dword [send_args+8],12          ; 3rd is the length of that string.
    mov dword [send_args+12],0          ; 4th is the flags ...

    mov eax,SYS_SOCKETCALL              ; System call number.
    mov ebx,SYS_SEND                    ; 1st system call argument, here the function number.
    lea ecx,[send_args]                 ; 2nd is the address of send's arguments array
    int 80h                             ; *poke*

    mov eax,SYS_EXIT                    ; System call number.
    mov ebx,0x00                        ; 1st systam call argument, here the function number.
    int 80h                             ; *poke*

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.