Results 1 to 1 of 1
  1. #1
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted

    [Help]Irc bot, bugging with winsock

    Hello everyone, I'm following along with a winsock tutorial in MASM's syntax called: Iczelion's Guide to Winsock Programming

    I'm stuck, I receive an error but I don't know how to fix it. The thing is that everytime I try to connect to a server with my socket, I receive a WSANOTSOCK error (a socket opperation is preformed on something that is not a socket)

    But there was no error when calling WSAStartup() or Socket(). So how can this error be here now?

    Here's the code I'm currently using (I said I followed Iczelion's Guide to Winsock Programming, but I've modefied it to suit my needs, I'm trying to create an irc bot)
    Code:
    .386
    .model flat, stdcall
    option casemap: none
    
    
    include \masm32\include\windows.inc 
    include \masm32\include\user32.inc 
    include \masm32\include\kernel32.inc 
    include \masm32\include\shell32.inc
    include \masm32\include\wsock32.inc
    include \masm32\include\masm32.inc
    includelib \masm32\lib\shell32.lib
    includelib \masm32\lib\user32.lib 
    includelib \masm32\lib\kernel32.lib 
    includelib \masm32\lib\wsock32.lib
    includelib \masm32\lib\masm32.lib
    
    
    
    
    .data
    
    txt db "An error occured while calling WSAStartup",0
    txt1 db "An error occured while creating a socket",0
    txt2 db "An error occured while connecting",0
    capt db "SCHiM",0
    wsadata WSADATA <>
    hostname db "irc.corruptcode.org",0
    Port dd 6667 
    NICK db "NICK SCHiMBot",0
    USER db "USER SCHIMR 8 * :SCHMRR",0
    CHANNEL db "/join #botts",0
    sin sockaddr_in <?> 
    
    .data?
    sock dd ? 
    ;ErrorCode dd ?   
    ErrorCode  dd ?
    
    .code
    start:
    invoke WSAStartup, 101h,addr wsadata
    
    .if eax!=NULL   ;An error occured if eax != null, because there's no return value for this api, if there's return, there's an error
    
    mov ErrorCode, eax
    
    push MB_OK
    push offset capt
    push offset txt
    push 0
    call MessageBoxA
    
    
    .else
    
    invoke socket,AF_INET,SOCK_STREAM,0     ; Create a stream socket for internet use
    invoke WSAGetLastError
    
    
    .if eax!=INVALID_SOCKET
        mov sock,eax
    .else
        invoke WSAGetLastError
    
    push MB_OK
    push offset capt
    push offset txt1
    push 0
    call MessageBoxA
     .endif
    
    ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ;Now we have a socket ready for use, we still have to be able to connect to somewere though...
    ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    
    
    mov sin.sin_family, AF_INET
    invoke htons, Port                    ; convert port number into network byte order first
    mov sin.sin_port,ax                  ; note that this member is a word-size param.
    invoke gethostbyname, addr hostname
    mov eax,[eax+12]                ; move the value of h_list member into eax
    mov eax,[eax]                      ; copy the pointer to the actual IP address into eax
    mov eax,[eax]          
    mov sin.sin_addr,eax  ; copy IP address into eax
    
    
    ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ;Now That's done we can connect to a site! (an irc channel in this case)
    ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    
    invoke connect,socket,addr sin,sizeof sin
    
    
    
    .if eax==SOCKET_ERROR           
    
                 invoke WSAGetLastError                                          
    
    
    
    mov ErrorCode, eax
    
    push MB_OK
    push offset capt
    push offset txt2
    push 0
    call MessageBoxA
    
    invoke ExitProcess, NULL
    
    
    
        .endif
    
    invoke send, socket,addr USER, 100, 0
    .if eax==SOCKET_ERROR
    push MB_OK
    push offset capt
    push offset txt2
    push 0
    call MessageBoxA
    invoke ExitProcess, NULL
    .else 
    
    invoke send, socket,addr NICK, 100, 0
    invoke send, socket,addr CHANNEL, 100, 0
    
    .endif
    
    
    
    
    
    
    
    
    .endif
    
    
    
    
            invoke ExitProcess, NULL
    end start
    Thanks in advance

    -SCHiM

    Solved
    Last edited by .::SCHiM::.; 10-05-2010 at 11:41 AM.

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




Similar Threads

  1. Hey I need Help(not to do with hacks)
    By doombringerr in forum Combat Arms Europe Hacks
    Replies: 6
    Last Post: 01-25-2009, 01:17 AM
  2. Bug with skin.
    By Obey in forum General
    Replies: 4
    Last Post: 12-17-2008, 01:08 PM
  3. [VB6]IRC Bot D3RK4
    By Token in forum General Hacking
    Replies: 1
    Last Post: 10-14-2008, 03:10 PM
  4. Need help like right now with my d3d hook!
    By nukeist_ in forum C++/C Programming
    Replies: 0
    Last Post: 12-21-2007, 02:25 PM
  5. [Help]I got Promblme With Singup.
    By dor619 in forum WarRock Korea Hacks
    Replies: 3
    Last Post: 08-24-2007, 04:46 PM