0

I've been trying to learn how to create an IRC bot in assembler from some old sources. Everything is going fine with my learning except for a prefix problem.

The prefix for the bot is:

CommandPrefix equ "^^"

And the length of the prefix is added with:

add eax, 2d

I want to change the prefix to just "^", but I am having trouble with figuring out what "add eax" should be changed too for it to work. Or even if that is the best way to do it. Any help with this would be appreciated.

Here is what the original code looks like to get some idea:

include "win32ax.inc"

entry Bot

CommandPrefix   equ "^^"


section '.code' code readable executable

Bot:
invoke WSAStartup,0101h,WSAData

cmp eax, 0
jne Exit

invoke socket,AF_INET,SOCK_STREAM,0

cmp eax, -1
je Exit

mov dword [SocketDesc], eax

invoke inet_addr,IRCServer

mov dword [SockAddr_IP], eax

invoke htons,IRCPort

mov word [SockAddr_Port], ax

invoke connect,dword [SocketDesc],SockAddr,16d

cmp eax, 0
jne Exit

call GenerateNickname

invoke lstrcpy,SendBuffer,"NICK "

invoke lstrcat,SendBuffer,Nickname

call SendLine

invoke lstrcpy,SendBuffer,"USER "

invoke lstrcat,SendBuffer,Nickname

invoke lstrcat,SendBuffer," 8 * :"

invoke lstrcat,SendBuffer,Nickname

call SendLine

GetMotd:
call RecvLine
call HandlePing

mov ecx, 0

IsMotd:
cmp dword [ReturnBuffer + ecx], "MOTD"
je HaveMotd

cmp byte [ReturnBuffer + ecx], 0d
je GetMotd

inc ecx
jmp IsMotd

HaveMotd:
invoke lstrcpy,SendBuffer,"JOIN "

invoke lstrcat,SendBuffer,Channel

invoke lstrcat,SendBuffer," "

call SendLine

RecvCommand:
call RecvLine
call HandlePing

mov ecx, 0

IsCommand:
cmp word [ReturnBuffer + ecx], CommandPrefix
je HaveCommand

cmp byte [ReturnBuffer + ecx], 0
je RecvCommand

inc ecx
jmp IsCommand

HaveCommand:
mov ebx, ReturnBuffer
add ebx, ecx
add ebx, 2d                       ;add length of command prefix

invoke lstrcpy,CommandBuffer,ebx

call ExecuteCommand

jmp RecvCommand
JesseR
  • 1
  • 1
  • As much of an assembly fan as I am, I can't imagine the motivation for writing an IRC bot or client in assembly. That said, there's not enough of the code here to figure out the answer to your question. In fact, I'd even go so far as to say that I'm not entirely sure that `add length of command prefix` has anything to do with the `^^` command marker since I can't see any relationship between 45 as a length. Looking at how `HaveCommand` gets called in what you posted it's not super clear to me how `RecvLine` is putting data into `ReturnBuffer` or why `^^` should appear at the end of that. – David Hoelzer Jun 12 '15 at 01:50
  • The original source is here: http://pastebin.com/ChpYHLRZ. I tried changing "add eax, 2d" to "add eax, 1" but that doesn't seem to do any good. I am trying to strip this down to learn the IRC protocol. I am wanting to create my own trivia bot in assembly. – JesseR Jun 12 '15 at 02:45
  • As I said, I seriously doubt that the `add eax, 2d` is actually referring to the "^^" since there is no actual relationship between them. Pastbin is great but not good for SO. – David Hoelzer Jun 12 '15 at 11:03
  • I see what you are saying. The code works as intended when compiled however. I just can't seem to change the prefix. Nothing else in the code seems to make sense as to referring to the prefix. I would really appreciate any help on how to change the prefix. This is my only sticking point. – JesseR Jun 12 '15 at 11:19

0 Answers0