views:

25

answers:

2

Hello everybody

I'm having a problem comparing two strings with each other, one string receives data from an irc server, one line at a time, and the other holds hard coded data ("PING :") But every time I try and compare the strings nothing happens. Can you guys help me out?

The compare function is in Handleping

Here's the code I'm currently using:

.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
include \masm32\include\msvcrt.inc
includelib  \masm32\lib\msvcrt.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 
USER db "USER SCHiMBez 8 * :SCHiMBez",13,10 
CHANNEL db "JOIN #botss",13,10  
NICK db "NICK SCHiMBez",13,10 
trans_buffer db 500 dup (0)
failmatch db "They match!",0
sin sockaddr_in <?>
buff      db 500 dup (0) 
bbuff db (0)
sendbuff db 500 dup (0)
Pong db "PONG :irc.corruptcode.org",13,10,0
Ping db "PING :irc.corruptcode.org"

CLRF    db 13d, 10d
lstring EQU     LENGTHOF Ping


.data?

sock dd ? 
ErrorCode  dd ?


.code



show_error proc caption:ptr byte, err_txt:ptr byte
    invoke WSAGetLastError
    mov ErrorCode, eax
    invoke MessageBoxA, MB_OK, caption, err_txt, 0
    ret
show_error endp

main proc
    invoke  AllocConsole
    invoke WSAStartup, 101h,addr wsadata

    .if eax==0   ; An error occured if eax != 0, because there's no return value for this api, if there's return, there's an error
        invoke socket,AF_INET,SOCK_STREAM,0     ; Create a stream socket for internet use
        .if eax!=INVALID_SOCKET
            mov sock,eax

            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;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]       ; copy IP address into eax
            mov sin.sin_addr,eax

            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Now That's done we can connect to a site! (an irc channel in this case)
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

            invoke connect, sock, addr sin, sizeof sin

;invoke lstrcpy, addr sendbuff, addr USER   

;call sndd  ;possible error producer ;p ;if it produces an error, uncomment...

invoke send, sock, addr USER, 29,   0   
invoke send, sock, addr NICK, 15,   0   
invoke send, sock, addr CHANNEL, 13,    0   




            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Receive response from the server
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


  loopspt:  


        call Recvv  ;Receiving data



        call HandlePing
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Do something with the data
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


        invoke MessageBox, 0, addr buff, addr capt, 0


 jmp loopspt 




            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;All data received & check for errors
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

            .else
                invoke show_error, offset capt, offset txt2
            .endif
        .else
            invoke show_error, offset capt, offset txt1
        .endif
     invoke ExitProcess, 0

            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Recvv funciong
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Recvv:

invoke RtlZeroMemory, addr buff, sizeof buff
mov bbuff, 0

Gline:

invoke recv,sock,addr bbuff,sizeof bbuff,0

cmp bbuff, 10d
je done

invoke lstrcat, addr buff, addr bbuff   

jmp Gline

done:
ret


            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Recvv funciong
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Ping? Pong! commented for now
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


HandlePing:         


        cld                         ; Work upward
        mov     cx, lstring         ; Load length of string
        mov     esi, offset buff  ; Load offset of string1
        mov     edi, offset Ping  ; Load offset of string2
        repe    cmpsb               ; Compare
        je      allmatch            ; Jump if all match

        jmp zzor
        allmatch:                          
        invoke MessageBoxA, 0, addr failmatch, addr capt, MB_OK

zzor:
ret                             ;return

            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Ping? Pong! commented for now
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Send function
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

sndd:

invoke lstrcat, addr sendbuff, 13d   ;this works 
invoke lstrcat, addr sendbuff, 10d   ;this works

invoke lstrlen, sendbuff    ;ERROR HERE, ERROR HERE!!!


invoke send, sock, addr sendbuff, eax,  0



ret

            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
            ;Send function
            ;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤





main endp
end main

Thanks in advance -SCHiM

ps: I'm going to the gym now, I can answer any comments in about 2 or 2.5 hours

A: 

I suspect the problem is here:

    mov     cx, lstring         ; Load length of string

In 32-bit mode, REP prefixes use the full 32 bits of ECX as the count. What is probably happening is that there is a non-zero value in the top half of ECX, so the repe cmpsb is scanning too far, and inevitably soon hits bytes which don't match.

Matthew Slattery
A: 

@matthew

But how can I fix it? (sorry for not commenting, but I've lost my account because the server went down)

@Jens Björnhager You're right! Thank you!

Rick