Paste: upload

Author: erg
Mode: factor
Date: Mon, 26 Jan 2009 23:47:41
Plain Text |
H{
    {
        "file2"
        T{ mime-file
            { headers
                H{
                    {
                        "content-disposition"
                        "form-data; name=\"file2\"; filename=\"lambda-calculus.pdf\""
                    }
                    { "content-type" "application/pdf" }
                }
            }
            { filename "lambda-calculus.pdf" }
            { temporary-path "/tmp/factor-f85G6MPUWG-upload" }
        }
    }
    {
        "file3"
        T{ mime-file
            { headers
                H{
                    {
                        "content-disposition"
                        "form-data; name=\"file3\"; filename=\"nonstop-haskell.pdf\""
                    }
                    { "content-type" "application/pdf" }
                }
            }
            { filename "nonstop-haskell.pdf" }
            { temporary-path "/tmp/factor-cdi4vZe430-upload" }
        }
    }
    {
        "text1"
        T{ mime-variable
            { headers
                H{
                    {
                        "content-disposition"
                        "form-data; name=\"text1\""
                    }
                }
            }
            { key "text1" }
            { value "fewfwfew" }
        }
    }
    {
        "file1"
        T{ mime-file
            { headers
                H{
                    {
                        "content-disposition"
                        "form-data; name=\"file1\"; filename=\"rounding.pdf\""
                    }
                    { "content-type" "application/pdf" }
                }
            }
            { filename "rounding.pdf" }
            { temporary-path "/tmp/factor-4GRJ79JFb1-upload" }
        }
    }
}

Annotation: d

Author: d
Mode: factor
Date: Sun, 22 Feb 2009 04:19:58
Plain Text |
; Common linux definitions
; System call interrupt number
%define LINUX_SYSCALL 0x80

; Standard file descriptors
%define STDIN 0
%define STDOUT 1
%define STDERR 2

; Common status codes
%define EOF 0
%define NULL 0

; Socket definitions
%define SOCK_STREAM 1
%define AF_INET 2

; Define some macros llalala
%macro exit 1
   mov eax, 1
   mov ebx, %1
   int LINUX_SYSCALL
%endmacro

%macro  prologue 1
        push    ebp
        mov     ebp, esp
        sub     esp, %1
%endmacro

%macro  epilogue 0
        mov esp, ebp
   pop ebp
%endmacro

section .data
   nick db "APieSM", 0
   ident db "Testyooo", 0
   realname db "OMGWTFBBQ", 0
   parameter db " 8 * :", 0
   server_address db "monkeyserv.hopto.org", 0
   server_ipaddress db "172.207.21.235", 0
   %define PORT 6667
   error_no_such_host db "Error: No such host", 0
   error_open_socket db "Error opening socket", 0
   error_connect db "Error connecting to host", 0
   error_writeto_socket db "Could not write to socket", 0
   error_read db "Error reading from socket", 0
   
   ping_str db "PING", 0
   pong_sp_str db "PONG ", 0
   privmsg_str db "PRIVMSG", 0
   quit_str db "QUIT", 0
   whoami_str db ":!whoami", 0
   say_str db ":!say", 0
   cmd_str db ":!cmd", 0
   login_str db ":!login", 0
   load_str db ":!load", 0
   unload_str db ":!unload", 0
   privmsg_sp_str db "PRIVMSG ", 0
   sp_colon_str db " :", 0
   you_str db "You are ", 0
   ident_str db " (Ident: ", 0
   hostname_str db " -- Hostname: ", 0
   para_str db ")", 0xD, 0xA, 0
   
   newline db 0xD, 0xA, 0
   space db 0x20, 0
   nick_cmd db "NICK ", 0
   user_cmd db "USER ", 0
    format db "%d", 0xA, 0
    formatc db "%s", 0xA, 0
    formatec db "Error: %s", 0xA, 0
    tokens db ":!@", 0
   
   username db "peacey", 0
   password db "testy", 0
   
   host1 db ":peacey!peacey@dxb-as78510.alshamil.net.ae", 0
   host_list dd host1, 0
    
    parse_secondary_array dd parse_secondary_ping, parse_secondary_privmsg, parse_secondary_privmsg_ll_ptr, 0
    parse_secondary_privmsg_array dd parse_secondary_privmsg_whoami, parse_secondary_privmsg_say, parse_secondary_privmsg_cmd, parse_secondary_privmsg_load, parse_secondary_privmsg_unload, 0
    
;     /* struct *handle {
;        void *funcptr
;        char *string
;     } */
   
section .bss
   li resd 1
   parse_secondary_privmsg_ll_ptr resd 1
section .text
   global _start
_start:
   call main
   exit 0

main:
; Main funcion!
; Let's define some local variables ya? good, sexy!
; ###Socket Information###
%define sockfd [ebp-4]
%define server_ptr [ebp-8]
%define serv_addr_struct [ebp-24] ; size of struct sockaddr_in -> 16
%define temp [ebp-28]
%define buffer [ebp-1056] ; buffer[1028]
%define buffer_ptr [ebp-1060]

; ###End socket information###
   prologue 1060
    
    ; setup GSLIST parse_secondary_privmsg_ll
    mov dword [parse_secondary_privmsg_ll_ptr], 0
    
    push server_address
    call gethostbyname
    mov server_ptr, eax ; Move return variable
    cmp dword server_ptr, 0
    jne .nsh_continue ; If it's not equal then coninue and dont exit okay!
   push error_no_such_host
    call exit_with_error ; else exit
  .nsh_continue: ; continue
   ; setup socket
   lea eax, sockfd ; eax = &sockfd
   push 0
   push SOCK_STREAM
   push AF_INET
   push dword eax
   call setup_socket
   add esp, 16 ; on return sockfd is the socket fd
   
   ; setup sockaddr struct
   lea eax, serv_addr_struct
   push PORT
   push AF_INET
   push dword server_ptr
   push eax
   call setup_sockaddr_struct
   add esp, 16
   
   ; try to connect
    lea eax, serv_addr_struct ; eax = &serv_addr_struct
    push 16
    push eax
    push dword sockfd
    call connect
    cmp eax, 0
    jge .con_continue ; jump to continue if we have connected fine yeeeeey! woooo!
    push error_connect
    call exit_with_error ; else exit with an error :< WHYYYYYY ALLAH WHYY!
 
 .con_continue:
   ; Now that we've connected send the NICK command
   push NULL
   push newline
   push nick
   push nick_cmd
   call g_strconcat
   add esp, 16
   mov temp, eax
   
    push dword temp
    push dword sockfd
    call write_to
    add esp, 8
    
    push dword temp
    call free ; aaf caarse we have to free temp so we can reuse it!
    add esp, 4
    
    ; Now now we send the USER command
    push NULL
    push newline
    push realname
    push parameter
    push ident
    push user_cmd
    call g_strconcat
    add esp, 24
    mov temp, eax
    
    push dword temp
    push dword sockfd
    call write_to
    add esp, 8
    
    push dword temp
    call free ; and fwee it again!
    add esp, 4
    
    lea eax, buffer
    mov buffer_ptr, eax

 .while_loop:
    ; now we enter teh sexy while(1) loop
    ; now we read what the irc server is giving us
    push 1024
    push dword buffer_ptr
    push dword sockfd
    call read
    add esp, 12
    
    cmp eax, 0
    jge .r_continue ; if it read greater than or equal to continue the loop
    push error_read
    call exit_with_error ; else exit with an error
    
 .r_continue:
    ; now we call the intial parse function
    push dword sockfd
    push dword buffer_ptr
    call parse_initial
    add esp, 8
    
    jmp .while_loop
    
   epilogue
   ret
; ## END main function ##

; ## setup_socket function ##
; void setup_socket(int *socketfd, int domain, int type, int protocol)
;
setup_socket:
   %define socketfd [ebp+8]
   %define domain [ebp+12]
   %define type [ebp+16]
   %define protocol [ebp+20]
   prologue 0
   
   push dword protocol
   push dword type
   push dword domain
   call socket ; call socket(domain, type, protocol)
   add esp, 12
   mov ebx, socketfd ; move it here so we can dereference socketfd
   mov [ebx], eax ; move return variable to *socketfd
   cmp dword [ebx], 0
   jge .ss_continue ; If its greater than or equal to 0 then continue
   
   push error_open_socket ; else spit out an erroor and exit!
   call exit_with_error
   add esp, 4
   
 .ss_continue:
   epilogue
   ret ; return from function
; ##END setup_socket##
   
; ## setup_sockaddr_struct function ##
; void setup_sockaddr_struct(struct sockaddr_in *serv_addr, struct hostent *server_ip, int domain_type, int port)
;
setup_sockaddr_struct:
   %define serv_addr [ebp+8]
   %define server_ip [ebp+12]
   %define domain_type [ebp+16]
   %define port [ebp+20]
   
   ; sockaddr_in structure offsets
   %define sin_family 0
   %define sin_port 2
   %define sin_addr 4
   
   ; hostent structure offsets
   %define h_addr_list 16

   prologue 0
   
    mov eax, serv_addr ; move it to eax so we can dereference it
    mov ebx, domain_type
    mov dword [eax+sin_family], ebx ; serv_addr->sin_family = domain;
    
    push dword port
    call htons
    
    mov ebx, serv_addr
    mov [ebx+sin_port], eax ; serv_addr->sin_port = htons(port)
   
;     push dword server_ipaddress
;     call inet_addr
;     mov ebx, serv_addr
;       mov dword [ebx+sin_addr], eax ; i dont know what the ~censored~ im doing so
;                      ; im not sure if thisll work or not ^.^
     
     mov eax, server_ip
     push dword [eax] ; *server_ip == the hostname
     call strlen
     add esp, 4
     mov edx, eax ; edx = strlen(hostname)
    
       mov eax, server_ip
       mov ebx, [eax+h_addr_list] ; [ebx] = server_address->h_addr ... i think
       
       mov eax, serv_addr
       lea eax, [eax+sin_addr]
       push 4
       push dword [ebx]
       push dword eax
       call memcpy
       add esp, 12
       ; again dont ask me, i just tried it and it worked!
     ; Fricking finally now we can return!

   epilogue
   ret
   
; ## END setup_sockaddr_struct ##
   
; ## write_to function ##
; void write_to(int sockfd, char *msg)
;
write_to:
   %define sockfd [ebp+8]
   %define msg [ebp+12]
   
   prologue 0
   
   ; Get the messages string length
   push dword msg
   call strlen
   
   push eax
   push dword msg
   push dword sockfd
   call write
   add esp, 12
   
   cmp eax, 0
   jge .wts_continue ; if its gretaer than or equal to 0 then jump to return
   push error_writeto_socket
   call exit_with_error ; else exit with an error
   
 .wts_continue:
   epilogue
   ret
   
; ##END write_to function##

; ## parse_initial function ##
; void parse_initial(char *buffer)
;
parse_initial:
   %define buffer_ptr [ebp+8]
   %define sockfd [ebp+12]
   ; local variables
   %define bsplit_line [ebp-4] ; char **bsplit_line
   %define bsplit_line_len [ebp-8]
   %define bsplit [ebp-12] ; char **bsplit
   %define bsplit_len [ebp-16]
   
   prologue 16
    ; now that we're here, we have a buffer filled with 1024 bytes
    ; of what the irc server sent us! yeeeey!
      push dword buffer_ptr
      push formatc
      call printf
    
    ; Now for the formatting of zeh buffer!
    ; First we split into lines
    push -1
    push dword newline
    push dword buffer_ptr
    call g_strsplit
    add esp, 12
    mov bsplit_line, eax
    
    push dword bsplit_line
    call g_strv_length
    add esp, 4
    mov bsplit_line_len, eax
    
    ; nows for the for loop
    xor edx, edx
 .for_loop:   
    push edx ; save edx register
    
    cmp edx, bsplit_line_len
    jge near .fl_continue ; jump to end of loop if edx >= bsplit_line_len
    
    ; now we split the split string at the spaces
    mov eax, bsplit_line
    lea eax, [eax+edx*4]
     push -1
     push space
    push dword [eax]
     call g_strsplit
     add esp, 12
     mov bsplit, eax
     
     ; now we find bsplit's len
     push dword bsplit
     call g_strv_length
     add esp, 4
     mov bsplit_len, eax
     
     cmp dword bsplit_len, 0
     jle .eo_bl0 ; just to make sure the array isnt empty
     ; start of if (bsplit_len > 0)
     cmp dword bsplit_len, 1
     jle .eo_bl1
     ;  start of if (bsplit_len > 1)
     push dword sockfd
     push dword bsplit_len
     push dword bsplit
     call parse_secondary
     add esp, 12
  .eo_bl1:
     ; end of if (bsplit_len > 1)
  .eo_bl0:
     ; end of if (bsplit_len > 0)
     push dword bsplit
     call g_strfreev
     add esp, 4 ; free bsplit
     
    pop edx ; restore edx register
    inc edx
    
 .fl_continue:
    ; end of for loop so we have to free some stuff
    push dword bsplit_line
    call g_strfreev
    add esp, 4 ; free bsplit_line
    push 1028
    push dword buffer_ptr
    call bzero
    add esp, 8 ; zero out buffer
    
    epilogue ; now return from the function
    ret

; ##END parse_initial##

; ## parse_secondary function ##
; void parse_secondary(char **bsplit, , int bsplit_len, sockfd)
;
parse_secondary:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define sockfd [ebp+16]
   %define ebx_temp [ebp-4]
   %define ecx_temp [ebp-8]
   %define eax_temp [ebp-12]
   
   %define next 4
   
   prologue 12
   
   push dword sockfd
   push dword bsplit_len
   push dword bsplit
   mov ebx, parse_secondary_array
   xor ecx, ecx
 .start_secondary_call_loop:
    lea eax, [ebx+ecx*4]
    mov eax_temp, eax
    mov ebx_temp, ebx
    mov ecx_temp, ecx
;     pusha
;    push dword ecx
;    push format
;    call printf
;    add esp, 8
;    popa
       cmp dword [eax], parse_secondary_privmsg_ll_ptr
       jne .end_iterating_ll
       
     .start_iterating_ll:
     lea eax, [parse_secondary_privmsg_ll_ptr-4] ; subtract address by -4 so we can start at 0 later
   mov [li], dword eax
   
   .start_loop:
   mov eax, [li]
   lea ebx, [eax+next]
   mov ecx, [ebx]
   cmp dword ecx, 0
   je .end_loop
   mov [li], ecx
   mov edx, [ecx]
   call [edx]
   
   cmp eax, 1
   je .end_secondary_call_loop
   jmp .start_loop 
     .end_loop:
     mov eax, eax_temp
      mov ebx, ebx_temp
      mov ecx, ecx_temp
     inc ecx
     jmp .start_secondary_call_loop
    .end_iterating_ll:
      mov eax, eax_temp
      mov ebx, ebx_temp
      mov ecx, ecx_temp
    cmp dword [eax], 0
    je .end_secondary_call_loop ; jump to the end of the loop if we found a NULL value
    mov ebx_temp, ebx
    mov ecx_temp, ecx
    call dword [eax]
    cmp eax, 1
    je .end_secondary_call_loop ; if return value is 1 then no needyyeeh to run anymore functions
    
      mov ebx, ebx_temp
      mov ecx, ecx_temp
      
    inc ecx
    jmp .start_secondary_call_loop
  .end_secondary_call_loop:
    ; now we continue after each function was called
   add esp, 12
   
   epilogue
   ret

; ##END parse_secondary##

; ## parse_secondary_ping function ##
; void parse_secondary_ping(char **bsplit, int bsplit_len, int sockfd)
;
parse_secondary_ping:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define sockfd [ebp+16]
   
   prologue 0
    
   mov eax, bsplit
     lea eax, [eax+0]
     push dword ping_str
     push dword [eax]
     call strcmp
     add esp, 8
     
     cmp eax, 0
     jne .eoif_ping
     
     mov eax, bsplit
     lea eax, [eax+4]
     push NULL
     push newline
     push dword [eax]
     push pong_sp_str
     call g_strconcat
     add esp, 16
     
     push eax
     push dword sockfd
     call write_to
     add esp, 8
     
     mov eax, 1
     jmp .eof ; return that the function has executed fully
  .eoif_ping:
     ; end of if edx == 0
     mov eax, 0 ; ; return that the function has not executed fully
  .eof:
     epilogue
     ret
 
; ##END parse_secondary_ping##

; ## parse_secondary_privmsg function ##
; void parse_secondary_privmsg(char **bsplit, int bsplit_len, int sockfd)
;
parse_secondary_privmsg:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define sockfd [ebp+16]
   %define fuhost [ebp-4] ; char **fuhost
   %define unick [ebp-8]
   %define uident [ebp-12]
   %define uhostname [ebp-16]
   %define ebx_temp [ebp-20]
   %define ecx_temp [ebp-24]
   prologue 24
   
   mov eax, bsplit
     lea eax, [eax+4]
     push dword privmsg_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[1] == "PRIVMSG"
     
     cmp eax, 0
     jne near .eoif_privmsg ; if not equal jump to the end of the function
   ; else continue processing 
   ; check if full host is in hardcoded hosts array
   xor ecx, ecx
   mov ebx, bsplit
   lea ebx, [ebx]
   mov edi, host_list
 .validate_loop_start:
     lea esi, [edi+ecx*4]
     
     cmp dword [esi], 0
     je near .eoif_validate_privmsg ; if its equal jump to end of if host is in list - not the validate loop
     
     push ecx ; save ecx register
     
     push dword [esi]
     push dword [ebx]
     call strcmp
     add esp, 8
     cmp eax, 0
     je .validate_loop_end ; if its equal jump to end of loop and continue processing
     
     pop ecx ; restore ecx register
     
     inc ecx
     jmp .validate_loop_start
  .validate_loop_end:
;      /*else continue processing
;     :x!y@z.com
;    fuhost[0] = space
;    fuhost[1] = x -- nick
;    fuhost[2] = y -- ident
;    */fuhost[3] = z.com -- hostname
   
   ; set up fuhost and its relevant variables yeeeey
   mov eax, bsplit
     lea eax, [eax+0]
   push -1
   push tokens
   push dword [eax] ; bsplit[0]
   call g_strsplit_set
   add esp, 12
   mov fuhost, eax
   
   mov ecx, fuhost
   lea eax, [ecx+1*4]
   mov ebx, [eax]
   mov unick, ebx
   lea eax, [ecx+2*4]
   mov ebx, [eax]
   mov uident, ebx
   lea eax, [ecx+3*4]
   mov ebx, [eax]
   mov uhostname, ebx
   
   push dword sockfd
   push dword uhostname
   push dword uident
   push dword unick
   push dword bsplit_len
   push dword bsplit
   mov ebx, parse_secondary_privmsg_array
   xor ecx, ecx
 .start_privmsg_call_loop:
    lea eax, [ebx+ecx*4]
    cmp dword [eax], 0
    je .end_privmsg_call_loop ; jump to the end of the loop if we found a NULL value
    mov ebx_temp, ebx
    mov ecx_temp, ecx
    call dword [eax]
    cmp eax, 1
    je .end_privmsg_call_loop_success ; if return value is 1 then no needyyeeh to run anymore functions
    mov ebx, ebx_temp
    mov ecx, ecx_temp
    inc ecx
    jmp .start_privmsg_call_loop
 .end_privmsg_call_loop:
    ;now we continue after each function was called
    add esp, 24
   push dword fuhost
    call g_strfreev
    add esp, 4 ; free fuhost weeeee~
    jmp .eoif_privmsg ; jump so that we return 0 since no functions executed successfully
    
  .end_privmsg_call_loop_success:
    ;now we continue after each function was called
    add esp, 24
   push dword fuhost
    call g_strfreev
    add esp, 4 ; free fuhost weeeee~
    
 .eoif_validate_privmsg:
    mov eax, 1
    jmp .eof ; return that the function has executed fully
 .eoif_privmsg:
    ; return from the function
    mov eax, 0 ; return that the function has not executed fully
 .eof:
   epilogue
   ret

; ##END parse_secondary_privmsg##

; ## parse_secondary_privmsg_whoami function ##
; int parse_secondary_privmsg_whoami(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_whoami:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define temp [ebp-4]
   prologue 4
   
   cmp dword bsplit_len, 3
   jle near .eoif_len_whoami ; if bsplit_len <= 3 jump to te end
   ; else compare bsplit to :!whoami
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword whoami_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[1] == ":!whoami"
     cmp eax, 0
     jne .eoif_cmp_privmsg ; if not equal jump to the end of the function
   ; else continue processing
   
   mov eax, bsplit
     lea eax, [eax+2*4]
   push NULL
   push para_str
   push dword uhostname
   push hostname_str
   push dword uident
   push ident_str
   push dword unick
   push you_str
   push sp_colon_str
   push dword [eax]
   push privmsg_sp_str
   call g_strconcat
   add esp, 44
   mov temp, eax
   
   push dword temp
   push dword sockfd
   call write_to
   add esp, 8
   
   push dword temp
   call free
   add esp, 4
   
   mov eax, 1
   jmp .eof ; return that the function has executed fully
 .eoif_cmp_privmsg:
    ; continue here
 .eoif_len_whoami:
    mov eax, 0 ; ; return that the function has no executed fully
 .eof:
    epilogue
    ret
    
; ##END parse_secondary_privmsg_whoami##

; ##parse_secondary_privmsg_say function##
; int parse_secondary_privmsg_say(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_say:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define temp [ebp-4]
   prologue 4
   
   cmp dword bsplit_len, 4
   jle near .eoif_len_say ; if bsplit_len <= 4 jump to the end
   ; else compare bsplit to :!say
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword say_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!say"
     cmp eax, 0
     jne .eoif_cmp_say ; if not equal jump to the end of the function
   ; else continue processing
   
   push 4
   push dword bsplit_len
   push dword bsplit
   push space
   call strjoinv_from
    add esp, 16
   mov temp, eax
   
   mov eax, bsplit
     lea eax, [eax+2*4]
   push NULL
   push newline
   push dword temp
   push sp_colon_str
   push dword [eax]
   push privmsg_sp_str
   call g_strconcat
   add esp, 24
   
   push eax
   push dword sockfd
   call write_to
   add esp, 8
   
   push dword temp
   call free
   add esp, 4
   
   mov eax, 1
   jmp .eof ; return that the function has executed fully
 .eoif_cmp_say:
    ; continue here
 .eoif_len_say:
    mov eax, 0 ; return that the function has not executed fully
 .eof:
    epilogue
    ret
; ##END parse_secondary_privmsg_say##

; ## parse_secondary_privmsg_cmd function ##
; int parse_secondary_privmsg_cmd(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_cmd:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   prologue 0
   
   cmp dword bsplit_len, 4
   jle near .eoif_len_cmd ; if bsplit_len <= 4 jump to the end
   ; else compare bsplit to :!cmd
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword cmd_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!cmd"
     cmp eax, 0
     jne .eoif_cmp_cmd ; if not equal jump to the end of the function
   ; else continue processing
   
   push 4
   push dword bsplit_len
   push dword bsplit
   push space
   call strjoinv_from
    add esp, 16
   
   push NULL
   push newline
   push eax
   call g_strconcat
   add esp, 12
   
   push eax
   push dword sockfd
   call write_to
   add esp, 8
   ; Now check if bsplit[4] == QUIT
   ; if soes we need to close zeh socket!
   mov eax, bsplit
     lea eax, [eax+4*4]
     push quit_str
     push dword [eax]
     call g_ascii_strcasecmp
     add esp, 8
     cmp eax, 0
     jne .eoif_strcasecmp_cmd ; if its not equal to zegho jump to end of if
     lea eax, sockfd
     push eax
     call close_and_quit
     
     
 .eoif_strcasecmp_cmd:
     mov eax, 1 ; executed function fully
     jmp .eof
 .eoif_cmp_cmd:
   
 .eoif_len_cmd:
    mov eax, 0 ; did not execute function fully
 .eof:
    epilogue
    ret
    
; ##END parse_secondary_privmsg_cmd##

; ## parse_secondary_privmsg_login function ##
; int parse_secondary_privmsg_login(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_login:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define ufull [ebp-4]
   prologue 4
   
   cmp dword bsplit_len, 5
   jle near .eoif_len_login ; if bsplit_len <= 5 jump to the end
   ; else compare bsplit to :!login
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword login_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!login"
     cmp eax, 0
     jne .eoif_cmp_login ; if not equal jump to the end of the function
   ; else continue processing
   
   mov eax, bsplit
     lea eax, [eax+0]
     mov ebx, [eax]
   mov dword ufull, ebx ; store the users full thingy :!x@y.z
   
   mov eax, bsplit
     lea eax, [eax+4*4]
     push username
     push dword [eax]
     call strcmp
     add esp, 8
     mov ebx, eax
     
     push ebx
     mov eax, bsplit
     lea eax, [eax+5*4]
     push password
     push dword [eax]
     call strcmp
     add esp, 8
     pop ebx
   
   or ebx, eax
   cmp ebx, 0
   jne .eoif_validate_login ; if its not equal jump to end of if
   ; else continue
   ; add the host to the host list
   
 .eoif_validate_login:
    mov eax, 1
    jmp .eof
 .eoif_cmp_login:
   
 .eoif_len_login:
    mov eax, 0
 .eof:
    epilogue
    ret

; ##parse_secondary_privmsg_load function##
; int parse_secondary_privmsg_load(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_load:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define dlhandle [ebp-4]
   %define funcptr [ebp-8]
   %define handle [ebp-12]
   %define sohandle 8 ; size of struct handle
   
   prologue 12
   
   cmp dword bsplit_len, 5
   jle near .eoif_len_load ; if bsplit_len <= 5 jump to the end
   ; else compare bsplit to :!load
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword load_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!load"
     cmp eax, 0
     jne near .eoif_cmp_load ; if not equal jump to the end of the function
   ; else continue processing
   
   .start_iterating_ll:
     lea eax, [parse_secondary_privmsg_ll_ptr-4] ; subtract address by -4 so we can start at 0 later
   mov [li], dword eax
   
   ; Check if symbol is already loaded
   .start_loop:
   mov eax, [li]
   lea ebx, [eax+4]
   mov ecx, [ebx]
   cmp dword ecx, 0
   je .end_loop
   mov [li], ecx
   mov edx, [ecx]
   
   mov eax, bsplit
   lea eax, [eax+4*5]
   push dword [edx+4]
   push dword [eax]
   call strcmp
   add esp, 8
   
   cmp eax, 0
   je near .successful_exec
   jmp .start_loop
   .end_loop:
   
;    mov eax, bsplit
;    lea eax, [eax+4*4]
;    push dword [eax]
;    push formatc
;    call printf
;    add esp, 8
   mov eax, bsplit
   lea eax, [eax+4*4]
   push dword 1
   push dword [eax]
   call dlopen
   add esp, 8
   mov dword dlhandle, eax ; put the result into dlhandle
   cmp dword dlhandle, 0 ; comapre it to null
   je near .eoif_dlhandle
   
   ; locate the symbol
   mov eax, bsplit
   lea eax, [eax+4*5]
   push dword [eax]
   push dword dlhandle
   call dlsym
   add esp, 8
   cmp eax, 0 ; compare return value with null
   je near .eoif_dlhandle
   mov funcptr, eax ; else move it to the right place
   
   push dword sohandle
   call g_malloc
   add esp, 4
   mov handle, eax ; allocate enough space for the handle struct
   
   mov eax, handle
   mov ebx, funcptr
   mov dword [eax], ebx
   
   mov ebx, bsplit
   lea ebx, [ebx+4*5]
   mov ecx, [ebx]
   push ecx
   call g_strdup
   add esp, 4
   mov ebx, eax
   mov eax, handle
   mov dword [eax+4], ebx
   
   push dword handle
   push dword [parse_secondary_privmsg_ll_ptr]
   call g_slist_append
   add esp, 8
   mov [parse_secondary_privmsg_ll_ptr], eax ; return value is new start of list
   
 .successful_exec:
   mov eax, 1 ; executed function fully
   jmp .eof
   
 .eoif_dlhandle:
    call dlerror
    push eax
    push formatc
    call printf
    add esp, 8
 .eoif_cmp_load:
   
 .eoif_len_load:
    mov eax, 0
 .eof:
    epilogue
    ret
   
; ##END parse_secondary_privmsg_load##
   
; ##parse_secondary_privmsgun_load function##
; int parse_secondary_privmsg_unload(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_unload:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   
   prologue 0
   
   cmp dword bsplit_len, 4
   jle near .eoif_len_unload ; if bsplit_len <= 4 jump to the end
   ; else compare bsplit to :!load
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword unload_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!unload"
     cmp eax, 0
     jne near .eoif_cmp_unload ; if not equal jump to the end of the function
   ; else continue processing
   
   .start_iterating_ll:
     lea eax, [parse_secondary_privmsg_ll_ptr-4] ; subtract address by -4 so we can start at 0 later
   mov [li], dword eax
   
   .start_loop:
   mov eax, [li]
   lea ebx, [eax+4]
   mov ecx, [ebx]
   cmp dword ecx, 0
   je .end_loop
   mov [li], ecx
   mov edx, [ecx]
   
   mov eax, bsplit
   lea eax, [eax+4*4]
   push dword [edx+4]
   push dword [eax]
   call strcmp
   add esp, 8
   
   cmp eax, 0 ; check if strings are equal, and if not continue iterating
   jne .continue_iterating
   ; else remove the handle from the list
   ; first free previously allocated pointer and string: name
   mov ecx, [li]
   mov edx, [ecx]
   push dword edx
   call g_free
   pop edx
   push dword [edx+4]
   call g_free
   add esp, 4
   
   ; now remove the handle from the list
   mov ecx, [li]
   push dword [ecx]
   push dword [parse_secondary_privmsg_ll_ptr]
   call g_slist_remove
   add esp, 8
   mov [parse_secondary_privmsg_ll_ptr], eax ; return value is new start of list
   jmp .end_loop ; jump to the end since we finished removing the handle
   
   .continue_iterating:
   jmp .start_loop 
     .end_loop:
    .end_iterating_ll:

   mov eax, 1 ; executed function fully
   jmp .eof
   
 .eoif_dlhandle:
    call dlerror
    push eax
    push formatc
    call printf
    add esp, 8
 .eoif_cmp_unload:
   
 .eoif_len_unload:
    mov eax, 0
 .eof:
    epilogue
    ret
   
; ##END parse_secondary_privmsg_unload##

; ##strjoinv_from function##
; char *strjoinv_from(char *delimeter, char **array, int array_len, int from)
;
strjoinv_from:
   %define delimeter [ebp+8]
   %define array [ebp+12]
   %define array_len [ebp+16]
   %define from [ebp+20]
   %define new_str [ebp-4]
   %define tmp [ebp-8]
   prologue 8
   
   mov eax, array
   mov ebx, from
     lea eax, [eax+ebx*4]
   push NULL
   push dword [eax]
   call g_strconcat
   add esp, 8
   mov new_str, eax
   inc dword from
   
 .forl_start:
    mov eax, array_len
    cmp dword from, eax
    jge .forl_end ; if greater than or equal to then jump to end of for loop
    
    mov eax, new_str ; else continue
    mov tmp, eax
    mov eax, array
   mov ebx, from
     lea eax, [eax+ebx*4]
    push NULL
    push dword [eax]
    push dword new_str
    push space
    call g_strjoin
    add esp, 16
    mov new_str, eax
   
    push dword tmp
    call free
    add esp, 4
   
    inc dword from
    jmp .forl_start
    
 .forl_end:
     mov eax, dword new_str
    epilogue
    ret
    
; ##END strjoinv_from##

; ## close_and_quit function ##
; void close_and_quit(int *sockfd)
;
close_and_quit:
   %define sockfd [esp+4]
   mov eax, sockfd
   push dword [eax]
   call close
   add esp, 4
   exit 0
; ##END close_and_quit##

; ## exit_with_error function ##
; void exit_with_error(char *error_message)
;
exit_with_error:
   %define error_message [esp+4]
   push dword error_message
   call perror
   exit 0
; ##END exit_with_error## 

Annotation: SAULS BOT

Author: SAUL
Mode: c++
Date: Sun, 22 Feb 2009 04:20:33
Plain Text |
; Common linux definitions
; System call interrupt number
%define LINUX_SYSCALL 0x80

; Standard file descriptors
%define STDIN 0
%define STDOUT 1
%define STDERR 2

; Common status codes
%define EOF 0
%define NULL 0

; Socket definitions
%define SOCK_STREAM 1
%define AF_INET 2

; Define some macros llalala
%macro exit 1
   mov eax, 1
   mov ebx, %1
   int LINUX_SYSCALL
%endmacro

%macro  prologue 1
        push    ebp
        mov     ebp, esp
        sub     esp, %1
%endmacro

%macro  epilogue 0
        mov esp, ebp
   pop ebp
%endmacro

section .data
   nick db "APieSM", 0
   ident db "Testyooo", 0
   realname db "OMGWTFBBQ", 0
   parameter db " 8 * :", 0
   server_address db "monkeyserv.hopto.org", 0
   server_ipaddress db "172.207.21.235", 0
   %define PORT 6667
   error_no_such_host db "Error: No such host", 0
   error_open_socket db "Error opening socket", 0
   error_connect db "Error connecting to host", 0
   error_writeto_socket db "Could not write to socket", 0
   error_read db "Error reading from socket", 0
   
   ping_str db "PING", 0
   pong_sp_str db "PONG ", 0
   privmsg_str db "PRIVMSG", 0
   quit_str db "QUIT", 0
   whoami_str db ":!whoami", 0
   say_str db ":!say", 0
   cmd_str db ":!cmd", 0
   login_str db ":!login", 0
   load_str db ":!load", 0
   unload_str db ":!unload", 0
   privmsg_sp_str db "PRIVMSG ", 0
   sp_colon_str db " :", 0
   you_str db "You are ", 0
   ident_str db " (Ident: ", 0
   hostname_str db " -- Hostname: ", 0
   para_str db ")", 0xD, 0xA, 0
   
   newline db 0xD, 0xA, 0
   space db 0x20, 0
   nick_cmd db "NICK ", 0
   user_cmd db "USER ", 0
    format db "%d", 0xA, 0
    formatc db "%s", 0xA, 0
    formatec db "Error: %s", 0xA, 0
    tokens db ":!@", 0
   
   username db "peacey", 0
   password db "testy", 0
   
   host1 db ":peacey!peacey@dxb-as78510.alshamil.net.ae", 0
   host_list dd host1, 0
    
    parse_secondary_array dd parse_secondary_ping, parse_secondary_privmsg, parse_secondary_privmsg_ll_ptr, 0
    parse_secondary_privmsg_array dd parse_secondary_privmsg_whoami, parse_secondary_privmsg_say, parse_secondary_privmsg_cmd, parse_secondary_privmsg_load, parse_secondary_privmsg_unload, 0
    
;     /* struct *handle {
;        void *funcptr
;        char *string
;     } */
   
section .bss
   li resd 1
   parse_secondary_privmsg_ll_ptr resd 1
section .text
   global _start
_start:
   call main
   exit 0

main:
; Main funcion!
; Let's define some local variables ya? good, sexy!
; ###Socket Information###
%define sockfd [ebp-4]
%define server_ptr [ebp-8]
%define serv_addr_struct [ebp-24] ; size of struct sockaddr_in -> 16
%define temp [ebp-28]
%define buffer [ebp-1056] ; buffer[1028]
%define buffer_ptr [ebp-1060]

; ###End socket information###
   prologue 1060
    
    ; setup GSLIST parse_secondary_privmsg_ll
    mov dword [parse_secondary_privmsg_ll_ptr], 0
    
    push server_address
    call gethostbyname
    mov server_ptr, eax ; Move return variable
    cmp dword server_ptr, 0
    jne .nsh_continue ; If it's not equal then coninue and dont exit okay!
   push error_no_such_host
    call exit_with_error ; else exit
  .nsh_continue: ; continue
   ; setup socket
   lea eax, sockfd ; eax = &sockfd
   push 0
   push SOCK_STREAM
   push AF_INET
   push dword eax
   call setup_socket
   add esp, 16 ; on return sockfd is the socket fd
   
   ; setup sockaddr struct
   lea eax, serv_addr_struct
   push PORT
   push AF_INET
   push dword server_ptr
   push eax
   call setup_sockaddr_struct
   add esp, 16
   
   ; try to connect
    lea eax, serv_addr_struct ; eax = &serv_addr_struct
    push 16
    push eax
    push dword sockfd
    call connect
    cmp eax, 0
    jge .con_continue ; jump to continue if we have connected fine yeeeeey! woooo!
    push error_connect
    call exit_with_error ; else exit with an error :< WHYYYYYY ALLAH WHYY!
 
 .con_continue:
   ; Now that we've connected send the NICK command
   push NULL
   push newline
   push nick
   push nick_cmd
   call g_strconcat
   add esp, 16
   mov temp, eax
   
    push dword temp
    push dword sockfd
    call write_to
    add esp, 8
    
    push dword temp
    call free ; aaf caarse we have to free temp so we can reuse it!
    add esp, 4
    
    ; Now now we send the USER command
    push NULL
    push newline
    push realname
    push parameter
    push ident
    push user_cmd
    call g_strconcat
    add esp, 24
    mov temp, eax
    
    push dword temp
    push dword sockfd
    call write_to
    add esp, 8
    
    push dword temp
    call free ; and fwee it again!
    add esp, 4
    
    lea eax, buffer
    mov buffer_ptr, eax

 .while_loop:
    ; now we enter teh sexy while(1) loop
    ; now we read what the irc server is giving us
    push 1024
    push dword buffer_ptr
    push dword sockfd
    call read
    add esp, 12
    
    cmp eax, 0
    jge .r_continue ; if it read greater than or equal to continue the loop
    push error_read
    call exit_with_error ; else exit with an error
    
 .r_continue:
    ; now we call the intial parse function
    push dword sockfd
    push dword buffer_ptr
    call parse_initial
    add esp, 8
    
    jmp .while_loop
    
   epilogue
   ret
; ## END main function ##

; ## setup_socket function ##
; void setup_socket(int *socketfd, int domain, int type, int protocol)
;
setup_socket:
   %define socketfd [ebp+8]
   %define domain [ebp+12]
   %define type [ebp+16]
   %define protocol [ebp+20]
   prologue 0
   
   push dword protocol
   push dword type
   push dword domain
   call socket ; call socket(domain, type, protocol)
   add esp, 12
   mov ebx, socketfd ; move it here so we can dereference socketfd
   mov [ebx], eax ; move return variable to *socketfd
   cmp dword [ebx], 0
   jge .ss_continue ; If its greater than or equal to 0 then continue
   
   push error_open_socket ; else spit out an erroor and exit!
   call exit_with_error
   add esp, 4
   
 .ss_continue:
   epilogue
   ret ; return from function
; ##END setup_socket##
   
; ## setup_sockaddr_struct function ##
; void setup_sockaddr_struct(struct sockaddr_in *serv_addr, struct hostent *server_ip, int domain_type, int port)
;
setup_sockaddr_struct:
   %define serv_addr [ebp+8]
   %define server_ip [ebp+12]
   %define domain_type [ebp+16]
   %define port [ebp+20]
   
   ; sockaddr_in structure offsets
   %define sin_family 0
   %define sin_port 2
   %define sin_addr 4
   
   ; hostent structure offsets
   %define h_addr_list 16

   prologue 0
   
    mov eax, serv_addr ; move it to eax so we can dereference it
    mov ebx, domain_type
    mov dword [eax+sin_family], ebx ; serv_addr->sin_family = domain;
    
    push dword port
    call htons
    
    mov ebx, serv_addr
    mov [ebx+sin_port], eax ; serv_addr->sin_port = htons(port)
   
;     push dword server_ipaddress
;     call inet_addr
;     mov ebx, serv_addr
;       mov dword [ebx+sin_addr], eax ; i dont know what the ~censored~ im doing so
;                      ; im not sure if thisll work or not ^.^
     
     mov eax, server_ip
     push dword [eax] ; *server_ip == the hostname
     call strlen
     add esp, 4
     mov edx, eax ; edx = strlen(hostname)
    
       mov eax, server_ip
       mov ebx, [eax+h_addr_list] ; [ebx] = server_address->h_addr ... i think
       
       mov eax, serv_addr
       lea eax, [eax+sin_addr]
       push 4
       push dword [ebx]
       push dword eax
       call memcpy
       add esp, 12
       ; again dont ask me, i just tried it and it worked!
     ; Fricking finally now we can return!

   epilogue
   ret
   
; ## END setup_sockaddr_struct ##
   
; ## write_to function ##
; void write_to(int sockfd, char *msg)
;
write_to:
   %define sockfd [ebp+8]
   %define msg [ebp+12]
   
   prologue 0
   
   ; Get the messages string length
   push dword msg
   call strlen
   
   push eax
   push dword msg
   push dword sockfd
   call write
   add esp, 12
   
   cmp eax, 0
   jge .wts_continue ; if its gretaer than or equal to 0 then jump to return
   push error_writeto_socket
   call exit_with_error ; else exit with an error
   
 .wts_continue:
   epilogue
   ret
   
; ##END write_to function##

; ## parse_initial function ##
; void parse_initial(char *buffer)
;
parse_initial:
   %define buffer_ptr [ebp+8]
   %define sockfd [ebp+12]
   ; local variables
   %define bsplit_line [ebp-4] ; char **bsplit_line
   %define bsplit_line_len [ebp-8]
   %define bsplit [ebp-12] ; char **bsplit
   %define bsplit_len [ebp-16]
   
   prologue 16
    ; now that we're here, we have a buffer filled with 1024 bytes
    ; of what the irc server sent us! yeeeey!
      push dword buffer_ptr
      push formatc
      call printf
    
    ; Now for the formatting of zeh buffer!
    ; First we split into lines
    push -1
    push dword newline
    push dword buffer_ptr
    call g_strsplit
    add esp, 12
    mov bsplit_line, eax
    
    push dword bsplit_line
    call g_strv_length
    add esp, 4
    mov bsplit_line_len, eax
    
    ; nows for the for loop
    xor edx, edx
 .for_loop:   
    push edx ; save edx register
    
    cmp edx, bsplit_line_len
    jge near .fl_continue ; jump to end of loop if edx >= bsplit_line_len
    
    ; now we split the split string at the spaces
    mov eax, bsplit_line
    lea eax, [eax+edx*4]
     push -1
     push space
    push dword [eax]
     call g_strsplit
     add esp, 12
     mov bsplit, eax
     
     ; now we find bsplit's len
     push dword bsplit
     call g_strv_length
     add esp, 4
     mov bsplit_len, eax
     
     cmp dword bsplit_len, 0
     jle .eo_bl0 ; just to make sure the array isnt empty
     ; start of if (bsplit_len > 0)
     cmp dword bsplit_len, 1
     jle .eo_bl1
     ;  start of if (bsplit_len > 1)
     push dword sockfd
     push dword bsplit_len
     push dword bsplit
     call parse_secondary
     add esp, 12
  .eo_bl1:
     ; end of if (bsplit_len > 1)
  .eo_bl0:
     ; end of if (bsplit_len > 0)
     push dword bsplit
     call g_strfreev
     add esp, 4 ; free bsplit
     
    pop edx ; restore edx register
    inc edx
    
 .fl_continue:
    ; end of for loop so we have to free some stuff
    push dword bsplit_line
    call g_strfreev
    add esp, 4 ; free bsplit_line
    push 1028
    push dword buffer_ptr
    call bzero
    add esp, 8 ; zero out buffer
    
    epilogue ; now return from the function
    ret

; ##END parse_initial##

; ## parse_secondary function ##
; void parse_secondary(char **bsplit, , int bsplit_len, sockfd)
;
parse_secondary:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define sockfd [ebp+16]
   %define ebx_temp [ebp-4]
   %define ecx_temp [ebp-8]
   %define eax_temp [ebp-12]
   
   %define next 4
   
   prologue 12
   
   push dword sockfd
   push dword bsplit_len
   push dword bsplit
   mov ebx, parse_secondary_array
   xor ecx, ecx
 .start_secondary_call_loop:
    lea eax, [ebx+ecx*4]
    mov eax_temp, eax
    mov ebx_temp, ebx
    mov ecx_temp, ecx
;     pusha
;    push dword ecx
;    push format
;    call printf
;    add esp, 8
;    popa
       cmp dword [eax], parse_secondary_privmsg_ll_ptr
       jne .end_iterating_ll
       
     .start_iterating_ll:
     lea eax, [parse_secondary_privmsg_ll_ptr-4] ; subtract address by -4 so we can start at 0 later
   mov [li], dword eax
   
   .start_loop:
   mov eax, [li]
   lea ebx, [eax+next]
   mov ecx, [ebx]
   cmp dword ecx, 0
   je .end_loop
   mov [li], ecx
   mov edx, [ecx]
   call [edx]
   
   cmp eax, 1
   je .end_secondary_call_loop
   jmp .start_loop 
     .end_loop:
     mov eax, eax_temp
      mov ebx, ebx_temp
      mov ecx, ecx_temp
     inc ecx
     jmp .start_secondary_call_loop
    .end_iterating_ll:
      mov eax, eax_temp
      mov ebx, ebx_temp
      mov ecx, ecx_temp
    cmp dword [eax], 0
    je .end_secondary_call_loop ; jump to the end of the loop if we found a NULL value
    mov ebx_temp, ebx
    mov ecx_temp, ecx
    call dword [eax]
    cmp eax, 1
    je .end_secondary_call_loop ; if return value is 1 then no needyyeeh to run anymore functions
    
      mov ebx, ebx_temp
      mov ecx, ecx_temp
      
    inc ecx
    jmp .start_secondary_call_loop
  .end_secondary_call_loop:
    ; now we continue after each function was called
   add esp, 12
   
   epilogue
   ret

; ##END parse_secondary##

; ## parse_secondary_ping function ##
; void parse_secondary_ping(char **bsplit, int bsplit_len, int sockfd)
;
parse_secondary_ping:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define sockfd [ebp+16]
   
   prologue 0
    
   mov eax, bsplit
     lea eax, [eax+0]
     push dword ping_str
     push dword [eax]
     call strcmp
     add esp, 8
     
     cmp eax, 0
     jne .eoif_ping
     
     mov eax, bsplit
     lea eax, [eax+4]
     push NULL
     push newline
     push dword [eax]
     push pong_sp_str
     call g_strconcat
     add esp, 16
     
     push eax
     push dword sockfd
     call write_to
     add esp, 8
     
     mov eax, 1
     jmp .eof ; return that the function has executed fully
  .eoif_ping:
     ; end of if edx == 0
     mov eax, 0 ; ; return that the function has not executed fully
  .eof:
     epilogue
     ret
 
; ##END parse_secondary_ping##

; ## parse_secondary_privmsg function ##
; void parse_secondary_privmsg(char **bsplit, int bsplit_len, int sockfd)
;
parse_secondary_privmsg:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define sockfd [ebp+16]
   %define fuhost [ebp-4] ; char **fuhost
   %define unick [ebp-8]
   %define uident [ebp-12]
   %define uhostname [ebp-16]
   %define ebx_temp [ebp-20]
   %define ecx_temp [ebp-24]
   prologue 24
   
   mov eax, bsplit
     lea eax, [eax+4]
     push dword privmsg_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[1] == "PRIVMSG"
     
     cmp eax, 0
     jne near .eoif_privmsg ; if not equal jump to the end of the function
   ; else continue processing 
   ; check if full host is in hardcoded hosts array
   xor ecx, ecx
   mov ebx, bsplit
   lea ebx, [ebx]
   mov edi, host_list
 .validate_loop_start:
     lea esi, [edi+ecx*4]
     
     cmp dword [esi], 0
     je near .eoif_validate_privmsg ; if its equal jump to end of if host is in list - not the validate loop
     
     push ecx ; save ecx register
     
     push dword [esi]
     push dword [ebx]
     call strcmp
     add esp, 8
     cmp eax, 0
     je .validate_loop_end ; if its equal jump to end of loop and continue processing
     
     pop ecx ; restore ecx register
     
     inc ecx
     jmp .validate_loop_start
  .validate_loop_end:
;      /*else continue processing
;     :x!y@z.com
;    fuhost[0] = space
;    fuhost[1] = x -- nick
;    fuhost[2] = y -- ident
;    */fuhost[3] = z.com -- hostname
   
   ; set up fuhost and its relevant variables yeeeey
   mov eax, bsplit
     lea eax, [eax+0]
   push -1
   push tokens
   push dword [eax] ; bsplit[0]
   call g_strsplit_set
   add esp, 12
   mov fuhost, eax
   
   mov ecx, fuhost
   lea eax, [ecx+1*4]
   mov ebx, [eax]
   mov unick, ebx
   lea eax, [ecx+2*4]
   mov ebx, [eax]
   mov uident, ebx
   lea eax, [ecx+3*4]
   mov ebx, [eax]
   mov uhostname, ebx
   
   push dword sockfd
   push dword uhostname
   push dword uident
   push dword unick
   push dword bsplit_len
   push dword bsplit
   mov ebx, parse_secondary_privmsg_array
   xor ecx, ecx
 .start_privmsg_call_loop:
    lea eax, [ebx+ecx*4]
    cmp dword [eax], 0
    je .end_privmsg_call_loop ; jump to the end of the loop if we found a NULL value
    mov ebx_temp, ebx
    mov ecx_temp, ecx
    call dword [eax]
    cmp eax, 1
    je .end_privmsg_call_loop_success ; if return value is 1 then no needyyeeh to run anymore functions
    mov ebx, ebx_temp
    mov ecx, ecx_temp
    inc ecx
    jmp .start_privmsg_call_loop
 .end_privmsg_call_loop:
    ;now we continue after each function was called
    add esp, 24
   push dword fuhost
    call g_strfreev
    add esp, 4 ; free fuhost weeeee~
    jmp .eoif_privmsg ; jump so that we return 0 since no functions executed successfully
    
  .end_privmsg_call_loop_success:
    ;now we continue after each function was called
    add esp, 24
   push dword fuhost
    call g_strfreev
    add esp, 4 ; free fuhost weeeee~
    
 .eoif_validate_privmsg:
    mov eax, 1
    jmp .eof ; return that the function has executed fully
 .eoif_privmsg:
    ; return from the function
    mov eax, 0 ; return that the function has not executed fully
 .eof:
   epilogue
   ret

; ##END parse_secondary_privmsg##

; ## parse_secondary_privmsg_whoami function ##
; int parse_secondary_privmsg_whoami(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_whoami:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define temp [ebp-4]
   prologue 4
   
   cmp dword bsplit_len, 3
   jle near .eoif_len_whoami ; if bsplit_len <= 3 jump to te end
   ; else compare bsplit to :!whoami
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword whoami_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[1] == ":!whoami"
     cmp eax, 0
     jne .eoif_cmp_privmsg ; if not equal jump to the end of the function
   ; else continue processing
   
   mov eax, bsplit
     lea eax, [eax+2*4]
   push NULL
   push para_str
   push dword uhostname
   push hostname_str
   push dword uident
   push ident_str
   push dword unick
   push you_str
   push sp_colon_str
   push dword [eax]
   push privmsg_sp_str
   call g_strconcat
   add esp, 44
   mov temp, eax
   
   push dword temp
   push dword sockfd
   call write_to
   add esp, 8
   
   push dword temp
   call free
   add esp, 4
   
   mov eax, 1
   jmp .eof ; return that the function has executed fully
 .eoif_cmp_privmsg:
    ; continue here
 .eoif_len_whoami:
    mov eax, 0 ; ; return that the function has no executed fully
 .eof:
    epilogue
    ret
    
; ##END parse_secondary_privmsg_whoami##

; ##parse_secondary_privmsg_say function##
; int parse_secondary_privmsg_say(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_say:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define temp [ebp-4]
   prologue 4
   
   cmp dword bsplit_len, 4
   jle near .eoif_len_say ; if bsplit_len <= 4 jump to the end
   ; else compare bsplit to :!say
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword say_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!say"
     cmp eax, 0
     jne .eoif_cmp_say ; if not equal jump to the end of the function
   ; else continue processing
   
   push 4
   push dword bsplit_len
   push dword bsplit
   push space
   call strjoinv_from
    add esp, 16
   mov temp, eax
   
   mov eax, bsplit
     lea eax, [eax+2*4]
   push NULL
   push newline
   push dword temp
   push sp_colon_str
   push dword [eax]
   push privmsg_sp_str
   call g_strconcat
   add esp, 24
   
   push eax
   push dword sockfd
   call write_to
   add esp, 8
   
   push dword temp
   call free
   add esp, 4
   
   mov eax, 1
   jmp .eof ; return that the function has executed fully
 .eoif_cmp_say:
    ; continue here
 .eoif_len_say:
    mov eax, 0 ; return that the function has not executed fully
 .eof:
    epilogue
    ret
; ##END parse_secondary_privmsg_say##

; ## parse_secondary_privmsg_cmd function ##
; int parse_secondary_privmsg_cmd(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_cmd:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   prologue 0
   
   cmp dword bsplit_len, 4
   jle near .eoif_len_cmd ; if bsplit_len <= 4 jump to the end
   ; else compare bsplit to :!cmd
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword cmd_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!cmd"
     cmp eax, 0
     jne .eoif_cmp_cmd ; if not equal jump to the end of the function
   ; else continue processing
   
   push 4
   push dword bsplit_len
   push dword bsplit
   push space
   call strjoinv_from
    add esp, 16
   
   push NULL
   push newline
   push eax
   call g_strconcat
   add esp, 12
   
   push eax
   push dword sockfd
   call write_to
   add esp, 8
   ; Now check if bsplit[4] == QUIT
   ; if soes we need to close zeh socket!
   mov eax, bsplit
     lea eax, [eax+4*4]
     push quit_str
     push dword [eax]
     call g_ascii_strcasecmp
     add esp, 8
     cmp eax, 0
     jne .eoif_strcasecmp_cmd ; if its not equal to zegho jump to end of if
     lea eax, sockfd
     push eax
     call close_and_quit
     
     
 .eoif_strcasecmp_cmd:
     mov eax, 1 ; executed function fully
     jmp .eof
 .eoif_cmp_cmd:
   
 .eoif_len_cmd:
    mov eax, 0 ; did not execute function fully
 .eof:
    epilogue
    ret
    
; ##END parse_secondary_privmsg_cmd##

; ## parse_secondary_privmsg_login function ##
; int parse_secondary_privmsg_login(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_login:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define ufull [ebp-4]
   prologue 4
   
   cmp dword bsplit_len, 5
   jle near .eoif_len_login ; if bsplit_len <= 5 jump to the end
   ; else compare bsplit to :!login
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword login_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!login"
     cmp eax, 0
     jne .eoif_cmp_login ; if not equal jump to the end of the function
   ; else continue processing
   
   mov eax, bsplit
     lea eax, [eax+0]
     mov ebx, [eax]
   mov dword ufull, ebx ; store the users full thingy :!x@y.z
   
   mov eax, bsplit
     lea eax, [eax+4*4]
     push username
     push dword [eax]
     call strcmp
     add esp, 8
     mov ebx, eax
     
     push ebx
     mov eax, bsplit
     lea eax, [eax+5*4]
     push password
     push dword [eax]
     call strcmp
     add esp, 8
     pop ebx
   
   or ebx, eax
   cmp ebx, 0
   jne .eoif_validate_login ; if its not equal jump to end of if
   ; else continue
   ; add the host to the host list
   
 .eoif_validate_login:
    mov eax, 1
    jmp .eof
 .eoif_cmp_login:
   
 .eoif_len_login:
    mov eax, 0
 .eof:
    epilogue
    ret

; ##parse_secondary_privmsg_load function##
; int parse_secondary_privmsg_load(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_load:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   %define dlhandle [ebp-4]
   %define funcptr [ebp-8]
   %define handle [ebp-12]
   %define sohandle 8 ; size of struct handle
   
   prologue 12
   
   cmp dword bsplit_len, 5
   jle near .eoif_len_load ; if bsplit_len <= 5 jump to the end
   ; else compare bsplit to :!load
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword load_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!load"
     cmp eax, 0
     jne near .eoif_cmp_load ; if not equal jump to the end of the function
   ; else continue processing
   
   .start_iterating_ll:
     lea eax, [parse_secondary_privmsg_ll_ptr-4] ; subtract address by -4 so we can start at 0 later
   mov [li], dword eax
   
   ; Check if symbol is already loaded
   .start_loop:
   mov eax, [li]
   lea ebx, [eax+4]
   mov ecx, [ebx]
   cmp dword ecx, 0
   je .end_loop
   mov [li], ecx
   mov edx, [ecx]
   
   mov eax, bsplit
   lea eax, [eax+4*5]
   push dword [edx+4]
   push dword [eax]
   call strcmp
   add esp, 8
   
   cmp eax, 0
   je near .successful_exec
   jmp .start_loop
   .end_loop:
   
;    mov eax, bsplit
;    lea eax, [eax+4*4]
;    push dword [eax]
;    push formatc
;    call printf
;    add esp, 8
   mov eax, bsplit
   lea eax, [eax+4*4]
   push dword 1
   push dword [eax]
   call dlopen
   add esp, 8
   mov dword dlhandle, eax ; put the result into dlhandle
   cmp dword dlhandle, 0 ; comapre it to null
   je near .eoif_dlhandle
   
   ; locate the symbol
   mov eax, bsplit
   lea eax, [eax+4*5]
   push dword [eax]
   push dword dlhandle
   call dlsym
   add esp, 8
   cmp eax, 0 ; compare return value with null
   je near .eoif_dlhandle
   mov funcptr, eax ; else move it to the right place
   
   push dword sohandle
   call g_malloc
   add esp, 4
   mov handle, eax ; allocate enough space for the handle struct
   
   mov eax, handle
   mov ebx, funcptr
   mov dword [eax], ebx
   
   mov ebx, bsplit
   lea ebx, [ebx+4*5]
   mov ecx, [ebx]
   push ecx
   call g_strdup
   add esp, 4
   mov ebx, eax
   mov eax, handle
   mov dword [eax+4], ebx
   
   push dword handle
   push dword [parse_secondary_privmsg_ll_ptr]
   call g_slist_append
   add esp, 8
   mov [parse_secondary_privmsg_ll_ptr], eax ; return value is new start of list
   
 .successful_exec:
   mov eax, 1 ; executed function fully
   jmp .eof
   
 .eoif_dlhandle:
    call dlerror
    push eax
    push formatc
    call printf
    add esp, 8
 .eoif_cmp_load:
   
 .eoif_len_load:
    mov eax, 0
 .eof:
    epilogue
    ret
   
; ##END parse_secondary_privmsg_load##
   
; ##parse_secondary_privmsgun_load function##
; int parse_secondary_privmsg_unload(char **bsplit, int bsplit_len, char *unick, char *uident, char *uhostname, int sockfd)
;
parse_secondary_privmsg_unload:
   %define bsplit [ebp+8]
   %define bsplit_len [ebp+12]
   %define unick [ebp+16]
   %define uident [ebp+20]
   %define uhostname [ebp+24]
   %define sockfd [ebp+28]
   
   prologue 0
   
   cmp dword bsplit_len, 4
   jle near .eoif_len_unload ; if bsplit_len <= 4 jump to the end
   ; else compare bsplit to :!load
   mov eax, bsplit
     lea eax, [eax+3*4]
     push dword unload_str
     push dword [eax]
     call strcmp
     add esp, 8 ; compare bsplit[3] == ":!unload"
     cmp eax, 0
     jne near .eoif_cmp_unload ; if not equal jump to the end of the function
   ; else continue processing
   
   .start_iterating_ll:
     lea eax, [parse_secondary_privmsg_ll_ptr-4] ; subtract address by -4 so we can start at 0 later
   mov [li], dword eax
   
   .start_loop:
   mov eax, [li]
   lea ebx, [eax+4]
   mov ecx, [ebx]
   cmp dword ecx, 0
   je .end_loop
   mov [li], ecx
   mov edx, [ecx]
   
   mov eax, bsplit
   lea eax, [eax+4*4]
   push dword [edx+4]
   push dword [eax]
   call strcmp
   add esp, 8
   
   cmp eax, 0 ; check if strings are equal, and if not continue iterating
   jne .continue_iterating
   ; else remove the handle from the list
   ; first free previously allocated pointer and string: name
   mov ecx, [li]
   mov edx, [ecx]
   push dword edx
   call g_free
   pop edx
   push dword [edx+4]
   call g_free
   add esp, 4
   
   ; now remove the handle from the list
   mov ecx, [li]
   push dword [ecx]
   push dword [parse_secondary_privmsg_ll_ptr]
   call g_slist_remove
   add esp, 8
   mov [parse_secondary_privmsg_ll_ptr], eax ; return value is new start of list
   jmp .end_loop ; jump to the end since we finished removing the handle
   
   .continue_iterating:
   jmp .start_loop 
     .end_loop:
    .end_iterating_ll:

   mov eax, 1 ; executed function fully
   jmp .eof
   
 .eoif_dlhandle:
    call dlerror
    push eax
    push formatc
    call printf
    add esp, 8
 .eoif_cmp_unload:
   
 .eoif_len_unload:
    mov eax, 0
 .eof:
    epilogue
    ret
   
; ##END parse_secondary_privmsg_unload##

; ##strjoinv_from function##
; char *strjoinv_from(char *delimeter, char **array, int array_len, int from)
;
strjoinv_from:
   %define delimeter [ebp+8]
   %define array [ebp+12]
   %define array_len [ebp+16]
   %define from [ebp+20]
   %define new_str [ebp-4]
   %define tmp [ebp-8]
   prologue 8
   
   mov eax, array
   mov ebx, from
     lea eax, [eax+ebx*4]
   push NULL
   push dword [eax]
   call g_strconcat
   add esp, 8
   mov new_str, eax
   inc dword from
   
 .forl_start:
    mov eax, array_len
    cmp dword from, eax
    jge .forl_end ; if greater than or equal to then jump to end of for loop
    
    mov eax, new_str ; else continue
    mov tmp, eax
    mov eax, array
   mov ebx, from
     lea eax, [eax+ebx*4]
    push NULL
    push dword [eax]
    push dword new_str
    push space
    call g_strjoin
    add esp, 16
    mov new_str, eax
   
    push dword tmp
    call free
    add esp, 4
   
    inc dword from
    jmp .forl_start
    
 .forl_end:
     mov eax, dword new_str
    epilogue
    ret
    
; ##END strjoinv_from##

; ## close_and_quit function ##
; void close_and_quit(int *sockfd)
;
close_and_quit:
   %define sockfd [esp+4]
   mov eax, sockfd
   push dword [eax]
   call close
   add esp, 4
   exit 0
; ##END close_and_quit##

; ## exit_with_error function ##
; void exit_with_error(char *error_message)
;
exit_with_error:
   %define error_message [esp+4]
   push dword error_message
   call perror
   exit 0
; ##END exit_with_error## 

New Annotation

Summary:
Author:
Mode:
Body: