April 11, 2021, 02:18:57 PM

Author Topic: packets.cpp  (Read 397 times)

sit0

  • DarkBlizz
  • Resident
  • *****
  • Posts: 26
    • View Profile
packets.cpp
« on: January 09, 2011, 12:27:49 PM »
Code: [Select]
#include "bot.h"

void Bot::RP_TEXT(unsigned char PID, char *DATA, ...)
{
if((PSB == SB))
{
char buf[2048];
va_list argptr;

va_start(argptr, DATA);

vsprintf(buf, DATA, argptr);
printf("|0x%02X| %s", PID, buf); //"|%#02X|" will produce the 0X46

va_end(argptr);
}
}

void Bot::RP_HANDLER(unsigned char PID, char *DATA, short DATALEN)
{
switch (PID)
{
case 0x00: SP_0x00(); break;
case 0x09: RP_0x09(DATA, DATALEN); break;
case 0x0A: RP_0x0A(DATA); break;
case 0x0B: RP_0x0B(DATA); break;
case 0x0F: RP_0x0F(DATA); break;
case 0x25: RP_0x25(DATA); break;
case 0x3A: RP_0x3A(DATA); break;
case 0x3D: RP_0x3D(DATA); break;
case 0x46: RP_0x46(DATA); break;
case 0x50: RP_0x50(DATA); break;
case 0x51: RP_0x51(DATA); break;
//case 0x5E: RP_0x5E(DATA); break;
default: printf("unhandled packet: ");if(Dump==false) hexdump(DATA,DATALEN); break;
}
}

void Bot::SP_0x00()
{
APACKET(0x00);
}

void Bot::RP_0x09(char *DATA, short DATALEN)
{
if(Dump==false) {hexdump(DATA,DATALEN);}
unsigned long sum,status;

unsigned short gametype[30];
unsigned short paramet[30];//?
unsigned long langid[30];
unsigned short ipfamily[30];//af_inet
unsigned short ipport[30];
unsigned long iphost[30];
unsigned long ipsinzero1[30];
unsigned long ipsinzero2[30];
unsigned long gamestatus[30];
unsigned long gameelapsedtime[30];
char *gamename;
char *gamepass;
char *gamestat;

sum = ( *(unsigned long *)(DATA + 4) );
printf("\nthe amount of games listed %lu\n",sum);

if(sum==0)
{
status = ( *(unsigned long *)(DATA + 8) );
printf("status of recieved 0x09 packet %lu\n",status);

switch(status)
{
case 0: printf("ok\n"); break;
case 1: printf("game doesnt exist\n"); break;
case 2: printf("incorrect password\n"); break;
case 3: printf("game full\n"); break;
case 4: printf("game already started\n");break;
case 6: printf("too many server requests\n"); break;
default:printf("no idea what when wrong\n"); break;
}
}
else
{
int prevpacket=0;

DATA= DATA+ 8;

for (int b=0; b < sum; b++)
{
gametype[b] = ( *(unsigned short *)(DATA + prevpacket) );
printf("gametype: %hu\n",gametype[b]);

paramet[b] = ( *(unsigned short *)(DATA + prevpacket + 2) );
printf("paramet: %hu\n",paramet[b]);

langid[b] = ( *(unsigned long *)(DATA + prevpacket + 4 ) );
printf("langid: %lx\n",langid[b]);

ipfamily[b] = ( *(unsigned short *)(DATA + prevpacket + 8) );
printf("ipfamily: %hu\n",ipfamily[b]);

ipport[b] = ( *(unsigned short *)(DATA + prevpacket + 10) );
printf("ipport: %hu\n",ipport[b]);

iphost[b] = ( *(unsigned long *)(DATA + prevpacket + 12 ) );
printf("iphost: %lu\n",iphost[b]);

ipsinzero1[b] = ( *(unsigned long *)(DATA + prevpacket + 16 ) );
printf("ipsinzero1: %lu\n",ipsinzero1[b]);

ipsinzero2[b] = ( *(unsigned long *)(DATA + prevpacket + 20 ) );
printf("ipsinzero2: %lu\n",ipsinzero2[b]);

gamestatus[b] = ( *(unsigned long *)(DATA + prevpacket + 24 ) );
printf("gamestatus: %lu\n",gamestatus[b] );

gameelapsedtime[b] = ( *(unsigned long *)(DATA + prevpacket + 28 ) );
printf("gameelapsedtime: %lu\n",gameelapsedtime[b]);

gamename = DATA + prevpacket + 32;
printf("gamename: %s\n",gamename);

gamepass = DATA + (strlen(gamename)) + prevpacket + 33;
printf("gamepass: %s\n",gamepass);

gamestat = DATA + (strlen(gamename)) + (strlen(gamepass)) + prevpacket + 34;
printf("gamestat: %s\n",gamestat);

prevpacket += (strlen(gamename)) +(strlen(gamepass)) + (strlen(gamestat)) + 35;
}
}
}

void Bot::SP_0x09()
{
AWORD(0x0A);
AWORD(0x0);
ADWORD(0xFFFF);
ADWORD(0);
ADWORD(0x09); //number of game
ASTRING0("");
ASTRING0("");
ASTRING0("");
APACKET(0x09);
}

void Bot::RP_0x0A(char *DATA)
{
if(Connected == false)
Connected = true;

strcpy(strname,DATA+4);
RP_TEXT(DATA[1], "%s",strname );
}

void Bot::SP_0x0A()
{
ASTRING0(Username);
ABYTE(0x00);
APACKET(0x0A);
}

void Bot::RP_0x0B(char *DATA)
{
char blah = DATA[1];
DATA += 4;

while( *DATA != 0 )
{
RP_TEXT(blah, "%s",DATA );
DATA += strlen( DATA ) + 1;
}
}

void Bot::SP_0x0B()
{
ADWORD(0);
APACKET(0x0B);
}

void Bot::SP_0x0C(int ss, char *DATA)
{
ADWORD(ss); //0x02 to force join  0x01 to join broodwar on connect
ASTRING0(DATA);
APACKET(0x0C);
}

void Bot::SP_0x0E(char *DATA)
{
ASTRING0(DATA);
APACKET(0x0E);
}

void Bot::RP_0x0F(char *DATA)
{
char *USER;
char* TEXT;
unsigned long VAR[6];

for (int b=0; b < 6; b++)
VAR[b] = ( *(unsigned long *)(DATA + 4 + (4*b)) );

USER = DATA + 28;
TEXT = DATA + (strlen(USER)) + 29;

switch(VAR[0])
{
case 0x1: EID_USER(USER, VAR[1], TEXT); break;
case 0x2: EID_JOIN(USER, VAR[1], TEXT); break;
case 0x3: EID_LEFT(USER, VAR[1], TEXT); break;
case 0x4: break;
case 0x5: break;
case 0x6: break;
case 0x7: EID_CHAN(USER, VAR[1], TEXT); break;
case 0x9: break;
case 0xA: break;
case 0xD: break;
case 0xE: break;
case 0xF: break;
case 0x12: break;
case 0x13: break;
case 0x17: break;
case 0x18: break;
case 0x19: break;
default: if(Dump==false) hexdump(DATA,2500); return;
}

if(PSB == SB) BVDispatch(USER, TEXT, VAR);
}

void Bot::SP_0x14()
{
ASTRING(BPlug);
APACKET(0x14);
}

void Bot::RP_0x25(char *DATA)
{
if((Ping1 == true) || (Ping0 == true)) return;

if((SPing != 0) && (spingbb == false))
{
spingbb = true;
double waittime = (double)SPing/60;
RP_TEXT( DATA[1], "SPOOFING PING, WAITING %g MINUTES...\n", waittime); // sping=1800 -> 30min 1800031ms
sleep(SPing); // |0x0F-01| 0:1800016 sit0 [PXES 0 0 0 0 0 0 0 0 PXES] ||||| 1900 ---> |0x0F-17| 0:1900063 sit0 test
RP_TEXT( DATA[1], "SPOOFING COMPLETE\n",0);
}

DATA+=4;
SP_0x25(DATA);
}

void Bot::SP_0x25(char *DATA)
{
AVOID(DATA,4);
APACKET(0x25);
}

void Bot::SP_0x3A()
{
char buf[20];

doubleHashPassword(Password, ClientToken, ServerToken, buf);
RP_TEXT(0x3A, "dhashpw(\"%s\", 0x%08X, 0x%08X) = ",Password, ClientToken, ServerToken);
hex_print(buf, strlen(buf));
ADWORD(ClientToken);
ADWORD(ServerToken);
AVOID(buf, 20);
ASTRING0(Username);
APACKET(0x3A);
}

void Bot::RP_0x3A(char *DATA)
{
switch (*(unsigned long *)(DATA + 4))
{
case 0:
SP_0x14();
SP_0x0A();
SP_0x0B();
SP_0x46();
SP_0x0C(1,Channel);
//SP_0x0C(2,Channel);
return;
case 1: SP_0x3D(); return;
case 2: RP_TEXT(DATA[1], "login failed \n", 0); break;
case 6: RP_TEXT(DATA[1], "ACCOUNT closed \n", 0); break;
default: RP_TEXT(DATA[1],"unknown 0x3A exiting %s\n",DATA + 8); break;
}
exit(1);
}

void Bot::RP_0x3D(char *DATA)
{
switch (*(unsigned long *)(DATA + 4))
{
case 0: RP_TEXT(DATA[1], "ACCOUNT CREATED \n", 0); break;
case 2: RP_TEXT(DATA[1], "INVALID CHARACTERS\n ", 0); break;
case 3: RP_TEXT(DATA[1], "CONTAINS BANNED WORD\n ", 0); break;
case 4: RP_TEXT(DATA[1], "ALREADY EXISTS\n ", 0); break;
case 6: RP_TEXT(DATA[1], "TOO SHORT AN CHARACTERS\n ", 0); break;
default: RP_TEXT(DATA[1], "UNKNOWN 0x3D %s\n",DATA + 8); break;
}
exit(1);
}

void Bot::SP_0x3D()
{
char p[255];
for(int i=0; i < strlen(Password); i++)
{
p[i] = Password[i];
if (isupper(p[i]))
p[i] = tolower(Password[i]);
}
char buf[20];
hashPassword(p, buf);
RP_TEXT(0x3D, "hashpw: ", 0);
hex_print(buf, strlen(buf));
AVOID(buf, 20);
ASTRING0(Username);
APACKET(0x3D);
}

void Bot::RP_0x46(char *DATA)
{
RP_TEXT(DATA[1], "%s\n", DATA+21);
}

void Bot::SP_0x46()
{
ADWORD(0); //ADWORD(#) is acceptable even though it should be 0
APACKET(0x46);
}

void Bot::SP_0x50()
{
ADWORD(0);
AVOID(Client, strlen(Client));
ADWORD(VByte);
AVOID(Language, strlen(Language));
ADWORD(0);
ADWORD(0);
ADWORD(0);
ADWORD(0);
ASTRING0(ACountry);
ASTRING0(Country);
APACKET(0x50);

if(Ping0 == true)
SP_0x25("sit0");
}

void Bot::RP_0x50(char *DATA)
{
char mpqfile[FILENAME_MAX], digest[0x11];
char *mpqName = DATA + 24, *pch;
char *ChecksumFormula = DATA + strlen(mpqName) + 25;

int version;
int checksum;
int hashlen;
unsigned int product,value3,value4;

pch = strstr(mpqName,".mpq");
strncpy(pch,".dll",4);
strcpy(mpqfile, LDFile0);
strcat(mpqfile, mpqName);

ClientToken = rand();
ServerToken = *(unsigned int *)(DATA + 8);

CDKeyDecoder pm(CDKey);
hashlen = pm.calculateHash(ClientToken, ServerToken);
char* KeyHash = new char[hashlen];
pm.getHash(KeyHash);
RP_TEXT(DATA[1], "keyhash: ",0 );
hex_print(KeyHash, strlen(KeyHash));

product=pm.getProduct();
value3=pm.getVal1();
value4=pm.getVal2();

if(CheckRevision(VFile[1], VFile[2], VFile[3], ChecksumFormula, &version, &checksum, digest, mpqfile, VFile[0]))
{
RP_TEXT(DATA[1], "Arguments:\n Lockdown file: %s\n Checksum: %x\n Version: %x\n Digest: ", mpqfile, checksum, version, 0);
hex_print(digest, strlen(digest));
}
else
{
RP_TEXT(DATA[1], "CHECKREVISION FAILED\n", 0);
return;
}

SP_0x51(KeyHash, digest, version, checksum, product, value3);
}

void Bot::SP_0x51(char *KEY_HASH, char *EXE_INFO , unsigned long EXE_VER, unsigned long CHECKSUM, unsigned long PRODKEY, unsigned long PRIVKEY)
{
ADWORD(ClientToken);
ADWORD(EXE_VER);
ADWORD(CHECKSUM);
ADWORD(1);
ADWORD(0);
ADWORD(strlen(CDKey));
ADWORD(PRODKEY);
ADWORD(PRIVKEY);
ADWORD(0);
AVOID(KEY_HASH, 20);
ASTRING0(EXE_INFO);
ASTRING0(Username); //"AlenL");
APACKET(0x51);
}

void Bot::RP_0x51(char *DATA)
{
switch (*(unsigned long *)(DATA + 4))
{
case 0x000: SP_0x3A(); return;
case 0x100: RP_TEXT(DATA[1], "OLD GAME VERSION: %s\n", DATA + 8); break;
case 0x101: RP_TEXT(DATA[1], "INVALID VERSION\n", 0 ); break;
case 0x102: RP_TEXT(DATA[1], "GAME VERSION MUST BE DOWNGRADED: %s\n", DATA + 8); break;
case 0x200: RP_TEXT(DATA[1], "INVALID CD KEY\n ", 0 ); break;
case 0x201: RP_TEXT(DATA[1], "CD KEY IN USE BY: %s\n", DATA + 8 ); break;
case 0x202: RP_TEXT(DATA[1], "BANNED KEY\n", 0 ); break;
case 0x203: RP_TEXT(DATA[1], "WRONG PRODUCT\n", 0 ); break;
default: RP_TEXT(DATA[1], "DEFAULT: %s", DATA + 4 ); break;
}

exit(1);
}