• Welcome to Valhalla Legends Archive.
 

BNLS Protocol Error - Packet 0x09 BNLS_AUTHINFO

Started by Mephisto, November 13, 2004, 08:21 PM

Previous topic - Next topic

Mephisto

When I build 0x09, I insert into the buffer values 0x02, 0-7, ChecksumFormula.  It does not work as when I receive 0x09 from BNLS the success value is false.  I also checked the checksum formula to ensure it was correct, and that the version DLL digit was accurate.  I will supply my code for building 0x09 to make it more clear perhaps.

void BNLSConnection::Send_VERSIONCHECK(char *RecvBuffer) // This argument is the last packet received (in this case from 0x01).
{
                /* store some of the needed data from 0x01 */
PacketReader *pRead = new PacketReader(&RecvBuffer[11]);
pRead->read(externData->bnlsData->HashedCDKeyData[0]);
pRead->read(externData->bnlsData->HashedCDKeyData[1]);
pRead->read(externData->bnlsData->HashedCDKeyData[2]);
pRead->read(externData->bnlsData->HashedCDKeyData[3]);
pRead->read(externData->bnlsData->HashedCDKeyData[4]);
pRead->read(externData->bnlsData->HashedCDKeyData[5]);
pRead->read(externData->bnlsData->HashedCDKeyData[6]);
pRead->read(externData->bnlsData->HashedCDKeyData[7]);
pRead->read(externData->bnlsData->HashedCDKeyData[8]);

                /* Figure out what the version DLL digit is. */
unsigned long VersionDigit = -1;

if (externData->bnetData->VersionFile[7] == '0')
    VersionDigit = 0;
else if (externData->bnetData->VersionFile[7] == '1')
    VersionDigit = 1;
else if (externData->bnetData->VersionFile[7] == '2')
    VersionDigit = 2;
else if (externData->bnetData->VersionFile[7] == '3')
    VersionDigit = 3;
else if (externData->bnetData->VersionFile[7] == '4')
    VersionDigit = 4;
else if (externData->bnetData->VersionFile[7] == '5')
    VersionDigit = 5;
else if (externData->bnetData->VersionFile[7] == '6')
    VersionDigit = 6;
else if (externData->bnetData->VersionFile[7] == '7')
    VersionDigit = 7;

                /* Building the packet here. */
BNLSPacketBuffer *bnlsBuf = new BNLSPacketBuffer(BNLS_VERSIONCHECK);
bnlsBuf->pClear();
bnlsBuf->pInsert((unsigned long)0x02); // Broodwar
bnlsBuf->pInsert((unsigned long)VersionDigit);
bnlsBuf->pInsert(externData->bnetData->ChecksumFormula);
SendPacket(bnlsBuf);
delete bnlsBuf;
}


Here are the values I inserted the last time I tested:
Product ID = 0x02 (Broodwar)
VersionDigit = 3
ChecksumFormula = A=809621199 B=742895872 C=868793162 4 A=A-S B=B^C C=C+A A=A^B

Thankyou to anyone who can assist me here.

Mephisto

#1
Figured out the problem, but not a solution.

Here is the packet log of sending 0x09:
0000   00 0d 88 29 66 b7 00 0c f1 a9 37 b9 08 00 45 00  ...)f.....7...E.
0010   00 71 68 a0 40 00 80 06 d9 6c c0 a8 00 66 3f a1  [email protected]?.
0020   b7 ca 0c de 24 97 10 fe a3 3b 8b bd b7 e0 50 18  ....$....;....P.
0030   44 41 3c 46 00 00 49 00 09 00 00 00 00 00 00 00  DA<F..I.........
0040   00 41 3d 33 39 33 33 36 39 37 35 32 20 42 3d 32  .A=393369752 B=2
0050   32 33 39 39 38 38 35 31 20 43 3d 35 38 37 35 35  23998851 C=58755
0060   35 31 32 30 20 34 20 41 3d 41 2d 53 20 42 3d 42  5120 4 A=A-S B=B
0070   5e 43 20 43 3d 43 2d 41 20 41 3d 41 2b 42 00     ^C C=C-A A=A+B.


The data begins on line 0030 at 49 (length).  The amount sent is 73 bytes.  The problem if you examine the DWORD after the header is 00 00 00 00.  That is where the product ID should be (0x01, 0x02, etc.).  When I insert that into my packet buffer (bnlsBuf->pInsert((unsigned long)0x01);) it doesn't seem to insert it, but I will investigate why.  If anyone knows of a problem with this I'm not aware of please tell me, thank you.

Edit:  According to my buffer before I send it to BNLS (0x09) the product ID is in the buffer (2), but according to the packet log it isn't.

char *buf = bnlsBuf->GetBuffer(0;
cout << &buf[3] << endl; prints a 2, but it's 00 00 00 00 according to the packet log.  Wierd...

Mephisto

Ahaha, figured it out.  :)

The problem was when I went to build the packet (this was immediately after I checked the buffer to see if the 2 was there which it was, but before it got overwritten ;)).

Here was the code:
char *BnetPacketBuffer::GetPacket(void)
{
buffer[0] = (unsigned char)0xFF;
buffer[1] = ID;
*(size_t *)(&buffer[2]) = (unsigned short)ipos;

return buffer;
}


It should've been:
char *BnetPacketBuffer::GetPacket(void)
{
buffer[0] = (unsigned char)0xFF;
buffer[1] = ID;
*(unsigned short *)(&buffer[2]) = (unsigned short)ipos;

return buffer;
}


I was writing the length has 4 bytes, when it should've only been 2, thus overwriting the next DWORD in the buffer (the product ID), thus BNLS thought it was a bad packet (which it was).  :)  I'm just explaining what happened in case someone else gets something like this.