c# gamePacket decryption - ertow - 14-03-2015 02:09 AM
Hi. I try to create a world server in c# for my own learning but i have a probleme with uncrypt packet...
This is the code i have in c# (translate of the trollface, C++ code thanks to him)
but there is a big probleme with my code i've replace char by byte witch is equivalent in the most of case but not in this case... In fact byte = 1 byte( \o/) and it's seems that in c++ char is 4byte:
how can i change this code in order to make it work?
Thanks in advance.
Citazione: public static string DecryptGamePacket2(byte[] str)
{
string decrypted_string = "";
char[] table = { ' ', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'n' };
int count = 0;
for (count = 0; count < Function.strlen(str); )
{
if (str[count] <= 0x7A)
{
byte len = str[count];
for (int i = 0; i < (int)len; i++)
{
count++;
decrypted_string += Function.getextendedascii((count < str.Length ? str[count] : 0) ^ 0xFF);
}
int x = decrypted_string[1];
count++;
}
else
{
byte len = str[count];
len &= 0x7F;
for (int i = 0; i < (int)len; )
{
count++;
byte highbyte = str[count];
highbyte &= 0xF0;
highbyte >>= 0x4;
byte lowbyte = str[count];
lowbyte &= 0x0F;
if (highbyte != 0x0 && highbyte != 0xF)
{
decrypted_string += table[highbyte - 1];
i++;
}
if (lowbyte != 0x0 && lowbyte != 0xF)
{
decrypted_string += table[lowbyte - 1];
i++;
}
}
count++;
}
}
return decrypted_string;
}
public static string DecryptGamePacket(int session_id, byte[] str, int length)
{
string encrypted_string = "";
int session_key = session_id & 0xFF;
byte session_number = Convert.ToByte(session_id >> 6);
session_number &= 0xFF;
session_number &= Convert.ToByte(0x80000003);
switch (session_number)
{
case 0:
for (int i = 0; i < length; i++)
{
byte firstbyte = Convert.ToByte(session_key + 0x40);
byte highbyte = Convert.ToByte(str[i] - firstbyte);
encrypted_string += highbyte;
}
break;
case 1:
for (int i = 0; i < length; i++)
{
byte firstbyte = Convert.ToByte(session_key + 0x40);
byte highbyte = Convert.ToByte(str[i] + firstbyte);
encrypted_string += highbyte;
}
break;
case 2:
for (int i = 0; i < length; i++)
{
byte firstbyte = Convert.ToByte(session_key + 0x40);
byte highbyte = Convert.ToByte(str[i] - firstbyte ^ 0xC3);
encrypted_string += highbyte;
}
break;
case 3:
for (int i = 0; i < length; i++)
{
byte firstbyte = Convert.ToByte(session_key + 0x40);
byte highbyte = Convert.ToByte(str[i] + firstbyte ^ 0xC3);
encrypted_string += highbyte;
}
break;
default:
encrypted_string += 0xF;
break;
}
List<string> temp = new List<string>(encrypted_string.Split(Function.getextendedascii(0xFF)[0]));
string save = "";
for (int i = 0; i < temp.Count; i++)
{
save += DecryptGamePacket2(Function.StringToByteArray(temp[i]));
save += 0xFF;
}
return save;
}
|