vincity
11-03-2014, 05:16 PM
In that code i have a exception.. my buffer always is 126 bytes long... so i have a diff of 2 between temp and usable area of buffer. Why i have that ? is a xteaKey Problem ? A protocol problem ? where is my mistake ?
Here information about how i try make that instance.
//Rsa class
public static bool RsaEncrypt(BigInteger e, BigInteger m, ref byte[] buffer, int position)
{
byte[] temp = new byte[128];
try {
Array.Copy(buffer, position, temp, 0, 128);
}
catch (Exception ex)
{
Console.WriteLine("temp["+temp.Length+"] buffer["+(buffer.Length-position)+"]");
Console.WriteLine(ex.GetBaseException());
}
BigInteger input = new BigInteger(temp);
BigInteger output = input.modPow(e, m);
// it's sometimes possible for the results to be a byte short
// and this can break some software so we 0x00 pad the result
Array.Copy(GetPaddedValue(output), 0, buffer, position, 128);
return true;
}
//NetworkMessage creator
public static NetworkMessage Create(byte OS, ushort Version,
byte[] Signatures, byte[] XteaKey, string AccountName, string Password, bool OpenTibia)
{
NetworkMessage msg = new NetworkMessage(149);
msg.AddByte(0x95);
msg.AddByte(0x00);
msg.Position += 4;
msg.AddByte(0x01);
msg.AddUInt16(OS);
msg.AddUInt16(Version);
msg.AddBytes(Signatures);
int offset = msg.Data.Length;
int rsaStart = msg.Position;
msg.AddByte(0x0);
msg.AddBytes(XteaKey);
msg.AddString(AccountName);
msg.AddString(Password);
int toAdd = 128 - (msg.Position - 6 - rsaStart);
System.Console.WriteLine("offset " + offset + " rsaStart " + rsaStart + " " + toAdd);
msg.RsaOTEncrypt(23);
msg.AddAdler32();
return msg;
}
byte[] xteaKey = new byte[16];
rand.NextBytes(xteaKey);
// Instancing a new NetworkMessage
NetworkMessage networkMessage = LoginServerRequestPacket.Create(
(byte)2, // SO Version
(ushort)860, // Tibia Version
(new byte[12]{0x7A,0x60,0x3D,0x49,0x7C,0x4E,0x3D,0x49,0x78,0x41 ,0x14,0x49}), // Signature is Right ?
xteaKey, // key generate above
"1", //user
"1", //passwd
true // OpenTibia
);
Topics unsolved about login protocol.
http://tpforums.org/forum/threads/4881-C-Clientless-bot-for-8-6?highlight=AddPaddingBytes
http://tpforums.org/forum/threads/4704-C-8-57-login-packet-structure-what-s-wrong-here?highlight=AddPaddingBytes
I really dont have any reference to that problem.
{ Remember that code dont use client it is not a possibility }
Here information about how i try make that instance.
//Rsa class
public static bool RsaEncrypt(BigInteger e, BigInteger m, ref byte[] buffer, int position)
{
byte[] temp = new byte[128];
try {
Array.Copy(buffer, position, temp, 0, 128);
}
catch (Exception ex)
{
Console.WriteLine("temp["+temp.Length+"] buffer["+(buffer.Length-position)+"]");
Console.WriteLine(ex.GetBaseException());
}
BigInteger input = new BigInteger(temp);
BigInteger output = input.modPow(e, m);
// it's sometimes possible for the results to be a byte short
// and this can break some software so we 0x00 pad the result
Array.Copy(GetPaddedValue(output), 0, buffer, position, 128);
return true;
}
//NetworkMessage creator
public static NetworkMessage Create(byte OS, ushort Version,
byte[] Signatures, byte[] XteaKey, string AccountName, string Password, bool OpenTibia)
{
NetworkMessage msg = new NetworkMessage(149);
msg.AddByte(0x95);
msg.AddByte(0x00);
msg.Position += 4;
msg.AddByte(0x01);
msg.AddUInt16(OS);
msg.AddUInt16(Version);
msg.AddBytes(Signatures);
int offset = msg.Data.Length;
int rsaStart = msg.Position;
msg.AddByte(0x0);
msg.AddBytes(XteaKey);
msg.AddString(AccountName);
msg.AddString(Password);
int toAdd = 128 - (msg.Position - 6 - rsaStart);
System.Console.WriteLine("offset " + offset + " rsaStart " + rsaStart + " " + toAdd);
msg.RsaOTEncrypt(23);
msg.AddAdler32();
return msg;
}
byte[] xteaKey = new byte[16];
rand.NextBytes(xteaKey);
// Instancing a new NetworkMessage
NetworkMessage networkMessage = LoginServerRequestPacket.Create(
(byte)2, // SO Version
(ushort)860, // Tibia Version
(new byte[12]{0x7A,0x60,0x3D,0x49,0x7C,0x4E,0x3D,0x49,0x78,0x41 ,0x14,0x49}), // Signature is Right ?
xteaKey, // key generate above
"1", //user
"1", //passwd
true // OpenTibia
);
Topics unsolved about login protocol.
http://tpforums.org/forum/threads/4881-C-Clientless-bot-for-8-6?highlight=AddPaddingBytes
http://tpforums.org/forum/threads/4704-C-8-57-login-packet-structure-what-s-wrong-here?highlight=AddPaddingBytes
I really dont have any reference to that problem.
{ Remember that code dont use client it is not a possibility }