Create Your Own Yahoo Bot

This example are written in Delphi, Support YMSG16 (lastest yahoo protocol). Useful since http://www.imcomponents.com/ is quite expensive.

1. Login

a. Get Cookie from Login Server

Write a socket client to connect to yahoo login server, port 80. List of several yahoo login server:
login.yahoo.com
login.europe.yahoo.com
login.korea.yahoo.com

send this stream to one above server:

‘GET /config/login?login=’ + ” +
‘&passwd=’ + ‘<your_password>’ + #13+#10 +
‘Host: ‘ + ” + ‘:80’ + #13#10 +
‘Connection: Keep Alive’ + #13#10 +
‘Accept-Language: en-us’ + #13#10 +
‘Accept: -/-‘ + #13+#10 + #13#10);

you will receive a cookie if and is valid, catch this cookie, parse it:

strData := strData + Socket.ReceiveText;
if MidStr(strData, 10, 3) = ‘302’ then // Got the cookie!
begin // Let’s parse it out
a := pos(‘Y=v=’, strData);
strData := copy(strData, a, length(strData) – a);
b := pos(‘;’, strData);
cookie := copy(strData, 0, b);
a := pos(‘T=z=’, strData);
strData := copy(strData, a, length(strData) – a);
b := pos(‘;’, strData) – 1;
Cookie := Cookie + ‘ ‘ + copy(strData, 0, b);
log.WriteLog(‘STAT – COOKIE : ‘ + Cookie,false);
GotCookie := True;
CookieSock.Active := false; // Close Socket
SendLogin; // Call SendLogin

b. Create pack and calc function

function calc (const X: Integer): string;
var
X1: Integer;
X2: Integer;
const
DIVISOR: Integer = 256;
begin
asm
MOV EAX,0
MOV ECX,X
@@1: CMP ECX,DIVISOR
JL @@2
SUB ECX,DIVISOR
INC EAX
JMP @@1
@@2: MOV X1,EAX
MOV X2,ECX
end;
Result := Chr(X1) + Chr(X2);
end;

function pack(Service: Integer; Packet: String): String;
begin
Result := ‘YMSG’ + #$0#$0F#$0#$0 + calc(Length(Packet)) + calc(Service) + StringOfChar(#$0,8) + Packet;
end;

c. Login using your cookie

Create a socket to one of yahoo server, such as:

scs.msg.yahoo.com:5050
cn.scs.msg.yahoo.com:5050
etc.

this is the body of SendLogin, after you connected to one of yahoo server above:

Socket.SendText ( pack(550, ‘0À€’ + strID + ‘À€2À€’ + + ‘À€1À€’ + strID + ‘À€244À€1À€6À€’ + Cookie + ‘À€98À€usÀ€);

the Cookie is the result from login server

2. Send PM

msg := pack(6, ‘1À€’ + yahoo_login + ‘À€5À€’ + yahoo_dest + ‘À€14À€’ + msg + ‘À€’);
Socket.SendText(msg);

no explanation, clear enough.

3. Receive PM

Once your socket connected you will receive a stream every time there is a private message to you. Parse it. It easy to parce, I will not paste my code here.

Advertisements

4 thoughts on “Create Your Own Yahoo Bot

  1. Actually I made it on my own, I went back to my previous delphi and I’ve switched it to ICS instead of the old socket component. But can you please share the Receive PM code please? Thanks.

    Like

  2. Hello,
    This is a great piece of code, but I have a problem, the exe file compiled with Delphi 7 works fine, but I use Delphi 2010 and I can’t login. I can compile the exe with no errors, just some warnings refarding “ansi to string / string to ansi”… but no go… Can you please help me change the code so it works on Delphi 2010?

    Thanks.

    Like

Komentar, pertanyaan, sanggahan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s