Programmer
- Joined
- Jun 10, 2009
- Messages
- 659
- Reaction score
- 141
char* CPSock::ReadClientMessage(int* ErrorCode, int* ErrorType)
{
*ErrorCode = 0;
// Proc°¡ Recv¸¦ ÃÊ°úÇÑ °æ¿ì. (½É°¢ÇÑ ¿À·ù, ³ªÅ¸³¯¼ö ¾ø� °æ¿ì�Ù)
if (nProcPosition >= nRecvPosition) {
nRecvPosition = 0;
nProcPosition = 0;
return 0;
}
// Init packet authentication
if (Init == 0) {
if (nRecvPosition - nProcPosition < 4)
return 0;
int InitCode = *((unsigned int*)(pRecvBuffer + nProcPosition));
if (InitCode != INITCODE) {
*ErrorCode = 2;
*ErrorType = InitCode;
CloseSocket(); //fors_debug ÌØÊâ�¦Àí
return 0;
}
Init = 1;
nProcPosition += 4;
}
// Ccheck received message is larger than HEADER
if (nRecvPosition - nProcPosition < sizeof(HEADER))
return 0;
// Check full message arrived
int sh = sizeof(HEADER);
unsigned short Size = *((unsigned short*)(pRecvBuffer + nProcPosition + 4));
Size = Size + sizeof(HEADER);
unsigned char CheckSum = *((unsigned char*)(pRecvBuffer + nProcPosition + 3));
unsigned int SockType = *((unsigned short*)(pRecvBuffer + nProcPosition));
unsigned int ClentTick = *((unsigned int*)(pRecvBuffer + nProcPosition + 6));
if (Size > MAX_MESSAGE_SIZE || Size < sizeof(HEADER)) {
nRecvPosition = 0;
nProcPosition = 0;
*ErrorCode = 2;
*ErrorType = Size;
return 0;
}
unsigned short Rest = nRecvPosition - nProcPosition;
if (Size > Rest)
return 0;
// Get message
char* pMsg = &(pRecvBuffer[nProcPosition]);
nProcPosition = nProcPosition + Size;
if (nRecvPosition <= nProcPosition) {
nRecvPosition = 0;
nProcPosition = 0;
}
// Compare check_sum in packet
int KeywordFlag = oldRecvChecksum % 2;
unsigned char Sum = 0;
int pos = ucRecvSeq;
for (int i = sizeof(HEADER); i < Size; i++, pos++) {
int rst = pos % 256;
unsigned char Trans = pKeyWord[rst][KeywordFlag];
int mod = i & 0x3;
if (mod == 0)
pMsg[i] = pMsg[i] - (Trans << 2);
if (mod == 1)
pMsg[i] = pMsg[i] + (Trans >> 1);
if (mod == 2)
pMsg[i] = pMsg[i] - (Trans << 1);
if (mod == 3)
pMsg[i] = pMsg[i] + (Trans >> 2);
Sum += pMsg[i];
}
ucRecvSeq++;
oldRecvChecksum = CheckSum;
// return packet, even check_sum not match
if (Sum != CheckSum) {
*ErrorCode = 1;
*ErrorType = Size;
return pMsg;
}
return pMsg;
}
if (nProcPosition >= nRecvPosition) {
nRecvPosition = 0;
nProcPosition = 0;
return 0;
}
if (Init == 0) {
if (nRecvPosition - nProcPosition < 4)
return 0;
int InitCode = *((unsigned int*)(pRecvBuffer + nProcPosition));
if (InitCode != INITCODE) {
*ErrorCode = 2;
*ErrorType = InitCode;
CloseSocket(); //fors_debug ÌØÊâ¦Àí
return 0;
}
Init = 1;
nProcPosition += 4;
}
Only perform this check if we haven't done it ' (Init == 0)' {
if we have less than 4bytes to read '(nRecvPosition - nProcPosition < 4)' {
abort;
}
read 4bytes from the buffer and cast it to an unsigned int 'int InitCode = *((unsigned int*)(pRecvBuffer + nProcPosition));'
if the read 'InitCode' is not what we expect 'INITCODE' {
set some errors, close the connection and abort
}
Mark that we succesfully checked the first 4 bytes 'Init = 1;' so we don't need to check again (until init is reset?)
Advance the number of processed bytes by 4 ' nProcPosition += 4;'
}
// Ccheck received message is larger than HEADER
if (nRecvPosition - nProcPosition < sizeof(HEADER))
return 0;
// Check full message arrived
int sh = sizeof(HEADER);
unsigned short Size = *((unsigned short*)(pRecvBuffer + nProcPosition + 4));
Size = Size + sizeof(HEADER);
unsigned char CheckSum = *((unsigned char*)(pRecvBuffer + nProcPosition + 3));
unsigned int SockType = *((unsigned short*)(pRecvBuffer + nProcPosition));
unsigned int ClentTick = *((unsigned int*)(pRecvBuffer + nProcPosition + 6));
if (Size > MAX_MESSAGE_SIZE || Size < sizeof(HEADER)) {
nRecvPosition = 0;
nProcPosition = 0;
*ErrorCode = 2;
*ErrorType = Size;
return 0;
}
[4bytes|uint|InitCode]-[2bytes|ushort|SockType]-[1byte|char|Checksum]-[2bytes|ushort|PacketSize]-[4bytes|uint|ClentTick] <- Structure to read
{0, 1, 2, 3, ----------4,5----------------------6---------------------7,8------------------------9,10,11,12} <--------------Buffer Position
unsigned short Rest = nRecvPosition - nProcPosition;
if (Size > Rest)
return 0;
// Get message
char* pMsg = &(pRecvBuffer[nProcPosition]);
nProcPosition = nProcPosition + Size;
if (nRecvPosition <= nProcPosition) {
nRecvPosition = 0;
nProcPosition = 0;
}
// Compare check_sum in packet
int KeywordFlag = oldRecvChecksum % 2;
unsigned char Sum = 0;
int pos = ucRecvSeq;
for (int i = sizeof(HEADER); i < Size; i++, pos++) {
int rst = pos % 256;
unsigned char Trans = pKeyWord[rst][KeywordFlag];
int mod = i & 0x3;
if (mod == 0)
pMsg[i] = pMsg[i] - (Trans << 2);
if (mod == 1)
pMsg[i] = pMsg[i] + (Trans >> 1);
if (mod == 2)
pMsg[i] = pMsg[i] - (Trans << 1);
if (mod == 3)
pMsg[i] = pMsg[i] + (Trans >> 2);
Sum += pMsg[i];
}
ucRecvSeq++;
oldRecvChecksum = CheckSum;
struct HEADER {
WORD wType;
WORD wSeq;
WORD wPDULength;
WORD wDummy;
DWORD dwClientTick;
}
[COLOR=#666666][4bytes|uint|InitCode]-[2bytes|ushort|SockType]-[1byte|char|Checksum]-[2bytes|ushort|PacketSize]-[4bytes|uint|ClentTick] <- Structure to read
[/COLOR][COLOR=#666666]{0, 1, 2, 3, ----------4,5----------------------6---------------------7,8------------------------9,10,11,12} <--------------Buffer Position[/COLOR]
[COLOR=#666666]int KeywordFlag = oldRecvChecksum % 2;
[/COLOR]....
[COLOR=#666666]unsigned char Trans = [/COLOR][COLOR=#666666]pKeyWord[rst][KeywordFlag];[/COLOR]
what version of visual studio do you actually used to build the source? i got lots of error in my compiler.
The table you requested is below.//snipit looks like it is some sort of JaggedArray that acts as a lookup table.
//snip
unsigned char dTable[256][2] ={ 0xE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, 0x37, 0x68, 0xC3, 0x79, 0xCD, 0x7D, 0xEB, 0x7A, 0x21, 0x7D, 0xEB, 0x19, 0xEB, 0x95, 0x87, 0x7D, 0xE1, 0x78, 0xCD, 0x7D, 0x87, 0x7D, 0xD7, 0x7D, 0x23, 0x7D, 0x87, 0x7C, 0xDD, 0x91, 0xEB, 0x7A, 0xEB, 0xAF, 0x87, 0x23, 0xEB, 0x10, 0xCD, 0xDF, 0x87, 0x86, 0x87, 0xA5, 0x87, 0x7C, 0x73, 0x7E, 0xED, 0x7D, 0xD7, 0x7D, 0xEB, 0x7D, 0x0F, 0x7D, 0xD7, 0x7D, 0xE1, 0x7A, 0x68, 0x79, 0xD6, 0x7E, 0xEB, 0x98, 0xEB, 0x79, 0xF5, 0x7D, 0xE1, 0x7A, 0xEB, 0x23, 0x37, 0x6F, 0x23, 0x7C, 0x87, 0x7B, 0xD7, 0x7A, 0x7D, 0x80, 0xE7, 0x67, 0xEB, 0x7A, 0x23, 0x7D, 0x87, 0x6A, 0xEB, 0xA5, 0x23, 0x7D, 0xEB, 0x7F, 0xAF, 0x79, 0x37, 0x7C, 0xC3, 0x79, 0xCD, 0x7D, 0xEB, 0x7A, 0x21, 0x7D, 0xEB, 0x19, 0xEB, 0x95, 0x23, 0x7D, 0x23, 0x79, 0xD5, 0x7D, 0x73, 0x7D, 0xE1, 0x7A, 0x87, 0x79, 0xEB, 0x7D, 0xEB, 0x7D, 0xCD, 0x7A, 0xEB, 0x37, 0xEB, 0x73, 0xD7, 0x87, 0xE7, 0xE3, 0xEB, 0x6C, 0x7C, 0x91, 0xEB, 0x7D };
I cannot compile this code. Some of the files are missing. I was trying to rewrite the whole logic by seeing this existing code!
Sadly all the source is already outdated. but thank you for sharing this cyberinferno, i will try to explore these files.All the source I have is of Tantra k3
SQLDAEMON:You must be registered to see links
DSRV and ZONESRV:You must be registered to see links
HTLauncher:You must be registered to see links
SQLDAEMON and DBSRV do compile but they do not work with k6 Tantra server exes!
He's rebuilding / understanding the logic of that code to rebuild it as a new "emulator".
He's not going to compile that old code to make it work with the latest client (K5).
The table you requested is below.
Code:unsigned char dTable[256][2] ={ 0xEB, 0x7D, 0xD7, 0x7C, 0x87, 0x69, 0xEB, 0x79, 0xEB, 0x79, 0xEB, 0x7F, 0x87, 0x7D, 0x87, 0x66, 0xCD, 0x7D, 0xEB, 0x7D, 0x73, 0x73, 0x23, 0x37, 0xD7, 0x91, 0xCD, 0x79, 0xE1, 0x7D, 0xEB, 0x73, 0x23, 0x7D, 0xE1, 0x7B, 0x87, 0x91, 0x87, 0xE5, 0x7D, 0xD7, 0x73, 0x2F, 0x87, 0x69, 0x23, 0x7C, 0xCD, 0x7B, 0xEB, 0x79, 0x23, 0x7D, 0x73, 0x7D, 0x20, 0xD4, 0xEB, 0x78, 0x83, 0xE1, 0xEB, 0x90, 0x23, 0xC3, 0x0F, 0x87, 0x91, 0x79, 0x23, 0x79, 0x87, 0x78, 0x87, 0x84, 0x1B, 0x7D, 0xEB, 0x80, 0x82, 0x6E, 0x91, 0x7C, 0x87, 0xBB, 0xEB, 0x79, 0xFF, 0x05, 0xEB, 0x69, 0x69, 0x6F, 0xEB, 0x79, 0xEB, 0x19, 0x05, 0x2F, 0xC2, 0x5F, 0x19, 0x41, 0xEB, 0x91, 0x71, 0x7B, 0xA7, 0x4B, 0xE6, 0x7D, 0xA4, 0x7D, 0x87, 0x19, 0x21, 0xC2, 0x87, 0x16, 0xEB, 0x70, 0xEB, 0x7D, 0x23, 0x7D, 0xEB, 0x7D, 0xEB, 0x17, 0x23, 0x80, 0xCD, 0x78, 0xEB, 0x7D, 0x87, 0x7D, 0xEB, 0x7B, 0x8B, 0xC3, 0xEB, 0x7A, 0x87, 0x7D, 0x70, 0x83, 0xD1, 0xDD, 0xEB, 0x78, 0xF6, 0x7E, 0x87, 0x7D, 0x88, 0x19, 0x87, 0xF5, 0x87, 0x7D, 0xD7, 0xE1, 0x9B, 0x87, 0xEB, 0x9B, 0xCD, 0x7B, 0x23, 0x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x87, 0x6F, 0xE7, 0x79, 0xD7, 0x7C, 0x23, 0x1C, 0x23, 0x7D, 0xEB, 0x7F, 0xAF, 0x79, 0x37, 0x68, 0xC3, 0x79, 0xCD, 0x7D, 0xEB, 0x7A, 0x21, 0x7D, 0xEB, 0x19, 0xEB, 0x95, 0x87, 0x7D, 0xE1, 0x78, 0xCD, 0x7D, 0x87, 0x7D, 0xD7, 0x7D, 0x23, 0x7D, 0x87, 0x7C, 0xDD, 0x91, 0xEB, 0x7A, 0xEB, 0xAF, 0x87, 0x23, 0xEB, 0x10, 0xCD, 0xDF, 0x87, 0x86, 0x87, 0xA5, 0x87, 0x7C, 0x73, 0x7E, 0xED, 0x7D, 0xD7, 0x7D, 0xEB, 0x7D, 0x0F, 0x7D, 0xD7, 0x7D, 0xE1, 0x7A, 0x68, 0x79, 0xD6, 0x7E, 0xEB, 0x98, 0xEB, 0x79, 0xF5, 0x7D, 0xE1, 0x7A, 0xEB, 0x23, 0x37, 0x6F, 0x23, 0x7C, 0x87, 0x7B, 0xD7, 0x7A, 0x7D, 0x80, 0xE7, 0x67, 0xEB, 0x7A, 0x23, 0x7D, 0x87, 0x6A, 0xEB, 0xA5, 0x23, 0x7D, 0xEB, 0x7F, 0xAF, 0x79, 0x37, 0x7C, 0xC3, 0x79, 0xCD, 0x7D, 0xEB, 0x7A, 0x21, 0x7D, 0xEB, 0x19, 0xEB, 0x95, 0x23, 0x7D, 0x23, 0x79, 0xD5, 0x7D, 0x73, 0x7D, 0xE1, 0x7A, 0x87, 0x79, 0xEB, 0x7D, 0xEB, 0x7D, 0xCD, 0x7A, 0xEB, 0x37, 0xEB, 0x73, 0xD7, 0x87, 0xE7, 0xE3, 0xEB, 0x6C, 0x7C, 0x91, 0xEB, 0x7D };
So the only missing part to calculating the checksum is most likly the 'pKeyWord' variable.
it looks like it is some sort of JaggedArray that acts as a lookup table.
for (var i = 12; i < Size; i++, pos++)...... also I would assume you can see how the checksum gets created by looking into the 'Send' part of the code.
You gess it right, it is a custom algo made by hanbit.I can't tell if its a well known algo, but since its coded like that and don't use a library I'd guess its custom.
for (int i = sizeof(HEADER); i < Size; i++, pos++) {
int rst = pos % 256;
unsigned char Trans = pKeyWord[rst][KeywordFlag];
int mod = i & 0x3;
if (mod == 0)
pMsg = pMsg - (Trans << 2);
if (mod == 1)
pMsg = pMsg + (Trans >> 1);
if (mod == 2)
pMsg = pMsg - (Trans << 1);
if (mod == 3)
pMsg = pMsg + (Trans >> 2);
Sum += pMsg;
}