mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
fix dh keys exchange
This commit is contained in:
parent
7cc169dd3b
commit
1d67984481
|
|
@ -10,6 +10,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TeleSharp.TL;
|
using TeleSharp.TL;
|
||||||
using TLSharp.Core;
|
using TLSharp.Core;
|
||||||
|
using TLSharp.Core.MTProto.Crypto;
|
||||||
|
|
||||||
namespace ClientConsoleApp
|
namespace ClientConsoleApp
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +20,7 @@ namespace ClientConsoleApp
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
TestNewNonce();
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(2000);
|
||||||
Console.WriteLine("Hello World!");
|
Console.WriteLine("Hello World!");
|
||||||
|
|
||||||
|
|
@ -113,5 +115,27 @@ namespace ClientConsoleApp
|
||||||
|
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void TestNewNonce()
|
||||||
|
{
|
||||||
|
var g = 47;
|
||||||
|
BigInteger a = new BigInteger(2048, new Random());
|
||||||
|
BigInteger b = new BigInteger(2048, new Random());
|
||||||
|
var dhPrime = new BigInteger("20030004000", 16);
|
||||||
|
|
||||||
|
var ga = BigInteger.ValueOf(g).ModPow(a, dhPrime);
|
||||||
|
var gb = BigInteger.ValueOf(g).ModPow(b, dhPrime);
|
||||||
|
|
||||||
|
var ka = gb.ModPow(a, dhPrime);
|
||||||
|
var kb = ga.ModPow(b, dhPrime);
|
||||||
|
|
||||||
|
|
||||||
|
if (ka.Equals(kb))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ using TLSharp.Core.Network;
|
||||||
using TLSharp.Core.Utils;
|
using TLSharp.Core.Utils;
|
||||||
using static TLSharp.Core.MTProto.Serializers;
|
using static TLSharp.Core.MTProto.Serializers;
|
||||||
using TeleSharp.TL;
|
using TeleSharp.TL;
|
||||||
|
using TeleSharp.TL.Auth;
|
||||||
|
using TLSharp.Core.Requests;
|
||||||
|
|
||||||
namespace TlgListenerApplication
|
namespace TlgListenerApplication
|
||||||
{
|
{
|
||||||
|
|
@ -28,6 +30,7 @@ namespace TlgListenerApplication
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
TLContext.Init();
|
TLContext.Init();
|
||||||
|
ObjectUtils.ServerSide = true;
|
||||||
Console.WriteLine("Listening...");
|
Console.WriteLine("Listening...");
|
||||||
TcpListener();
|
TcpListener();
|
||||||
Console.WriteLine("The end");
|
Console.WriteLine("The end");
|
||||||
|
|
@ -69,8 +72,12 @@ namespace TlgListenerApplication
|
||||||
var tcpClient = tcpListener.AcceptTcpClient();
|
var tcpClient = tcpListener.AcceptTcpClient();
|
||||||
var netStream = tcpClient.GetStream();
|
var netStream = tcpClient.GetStream();
|
||||||
BigInteger ga = null;
|
BigInteger ga = null;
|
||||||
|
byte[] newNonce = new byte[32];
|
||||||
|
BigInteger a = new BigInteger(2048, new Random());
|
||||||
|
var dhPrime = new BigInteger("00C150023E2F70DB7985DED064759CFECF0AF328E69A41DAF4D6F01B538135A6F91F8F8B2A0EC9BA9720CE352EFCF6C5680FFC424BD634864902DE0B4BD6D49F4E580230E3AE97D95C8B19442B3C0A10D8F5633FECEDD6926A7F6DAB0DDB7D457F9EA81B8465FCD6FFFEED114011DF91C059CAEDAF97625F6C96ECC74725556934EF781D866B34F011FCE4D835A090196E9A5F0E4449AF7EB697DDB9076494CA5F81104A305B6DD27665722C46B60E5DF680FB16B210607EF217652E60236C255F6A28315F4083A96791D7214BF64C1DF4FD0DB1944FB26A2A57031B32EEE64AD15A8BA68885CDE74A5BFC920F6ABF59BA5C75506373E7130F9042DA922179251F", 16);
|
||||||
|
BigInteger gb = null;
|
||||||
var sequenceNumber = 1;
|
var sequenceNumber = 1;
|
||||||
|
ulong? messageId = null;
|
||||||
//var getingCounter = 0;
|
//var getingCounter = 0;
|
||||||
//while (true)
|
//while (true)
|
||||||
//{
|
//{
|
||||||
|
|
@ -86,10 +93,10 @@ namespace TlgListenerApplication
|
||||||
|
|
||||||
byte[] nonceFromClient = new byte[16];
|
byte[] nonceFromClient = new byte[16];
|
||||||
byte[] servernonce = new byte[16];
|
byte[] servernonce = new byte[16];
|
||||||
byte[] newNonce = new byte[32];
|
|
||||||
int responseCode = 0;
|
uint responseCode = 0;
|
||||||
BigInteger a = new BigInteger(2048, new Random());
|
int innerCode = 0;
|
||||||
var dhPrime = new BigInteger("00C150023E2F70DB7985DED064759CFECF0AF328E69A41DAF4D6F01B538135A6F91F8F8B2A0EC9BA9720CE352EFCF6C5680FFC424BD634864902DE0B4BD6D49F4E580230E3AE97D95C8B19442B3C0A10D8F5633FECEDD6926A7F6DAB0DDB7D457F9EA81B8465FCD6FFFEED114011DF91C059CAEDAF97625F6C96ECC74725556934EF781D866B34F011FCE4D835A090196E9A5F0E4449AF7EB697DDB9076494CA5F81104A305B6DD27665722C46B60E5DF680FB16B210607EF217652E60236C255F6A28315F4083A96791D7214BF64C1DF4FD0DB1944FB26A2A57031B32EEE64AD15A8BA68885CDE74A5BFC920F6ABF59BA5C75506373E7130F9042DA922179251F", 16);
|
long authkey = 123456789;
|
||||||
|
|
||||||
const long step1Constructor = 0x60469778;
|
const long step1Constructor = 0x60469778;
|
||||||
const long step2Constructor = 0xd712e4be;
|
const long step2Constructor = 0xd712e4be;
|
||||||
|
|
@ -112,7 +119,7 @@ namespace TlgListenerApplication
|
||||||
|
|
||||||
var binaryReader2 = new BinaryReader(new MemoryStream(data, false));
|
var binaryReader2 = new BinaryReader(new MemoryStream(data, false));
|
||||||
|
|
||||||
responseCode = (int)binaryReader2.ReadUInt32();
|
responseCode = binaryReader2.ReadUInt32();
|
||||||
Console.WriteLine("Request code: " + responseCode);
|
Console.WriteLine("Request code: " + responseCode);
|
||||||
if (responseCode == step1Constructor) //---Step1_PQRequest
|
if (responseCode == step1Constructor) //---Step1_PQRequest
|
||||||
{
|
{
|
||||||
|
|
@ -148,36 +155,52 @@ namespace TlgListenerApplication
|
||||||
var nonceFromClient_temp = binaryReadernner.ReadBytes(16);
|
var nonceFromClient_temp = binaryReadernner.ReadBytes(16);
|
||||||
var servernonce_temp = binaryReadernner.ReadBytes(16);
|
var servernonce_temp = binaryReadernner.ReadBytes(16);
|
||||||
var zero = binaryReadernner.ReadUInt64();
|
var zero = binaryReadernner.ReadUInt64();
|
||||||
var gb = Bytes.read(binaryReadernner);
|
gb = new BigInteger(Bytes.read(binaryReadernner));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var decodeMessage = DecodeMessage(tcpMessage.Body, null);
|
var decodeMessage = DecodeMessage(tcpMessage.Body, null);
|
||||||
var objrawReader = new BinaryReader(new MemoryStream(decodeMessage.Item1, false));
|
var objrawReader = new BinaryReader(new MemoryStream(decodeMessage.Item1, false));
|
||||||
responseCode = objrawReader.ReadInt32();
|
messageId = decodeMessage.Item2;
|
||||||
int layer = objrawReader.ReadInt32();
|
innerCode = objrawReader.ReadInt32();
|
||||||
int Constructor2 = objrawReader.ReadInt32();
|
|
||||||
Type t = TLContext.getType(Constructor2);
|
|
||||||
var obj = Activator.CreateInstance(t);
|
|
||||||
|
|
||||||
((TLRequestInitConnection)obj).DeserializeBodyFromRequest(objrawReader);
|
|
||||||
if (((TLRequestInitConnection)obj).Query is TeleSharp.TL.Help.TLRequestGetConfig)
|
if (innerCode == 0x62d6b459)//acknowledged
|
||||||
{
|
{
|
||||||
|
var vector = objrawReader.ReadInt32();
|
||||||
|
var msgCount = objrawReader.ReadInt32();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
else //if (responseCode == -627372787)
|
||||||
|
{
|
||||||
|
objrawReader.BaseStream.Position += -4;
|
||||||
|
var obj = ObjectUtils.DeserializeObject(objrawReader);
|
||||||
|
if (obj is TLRequestInvokeWithLayer)
|
||||||
|
{
|
||||||
|
var invokewithlayer = (TLRequestInvokeWithLayer)obj;
|
||||||
|
if (invokewithlayer.Query is TLRequestInitConnection)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (invokewithlayer.Query is TLRequestSendCode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (obj is TLRequestSendCode)
|
||||||
|
{
|
||||||
|
var requestSendCode = (TLRequestSendCode)obj;
|
||||||
|
}
|
||||||
|
else if (obj is TLRequestSignIn)
|
||||||
|
{
|
||||||
|
var requestSignIn = (TLRequestSignIn)obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//var keyData = Helpers.CalcKey(buffer, messageKey, false);
|
//var keyData = Helpers.CalcKey(buffer, messageKey, false);
|
||||||
//var data = AES.DecryptAES(keyData, buffer);
|
//var data = AES.DecryptAES(keyData, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//var obj = new Step1_PQRequest().FromBytes(data);
|
|
||||||
//var rr = FromByteArray<Step1_PQRequest>(data);
|
|
||||||
|
|
||||||
//var binaryReader = new BinaryReader(netStream);
|
|
||||||
//var a = binaryReader.ReadInt64();
|
|
||||||
//var b = binaryReader.ReadInt32();
|
|
||||||
//var c = binaryReader.ReadInt32();
|
|
||||||
//var d = binaryReader.ReadInt32();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netStream.CanWrite)
|
if (netStream.CanWrite)
|
||||||
|
|
@ -205,7 +228,7 @@ namespace TlgListenerApplication
|
||||||
|
|
||||||
byte[] answer;
|
byte[] answer;
|
||||||
var hashsum = Encoding.UTF8.GetBytes("asdfghjklmnbvcxzasdf");
|
var hashsum = Encoding.UTF8.GetBytes("asdfghjklmnbvcxzasdf");
|
||||||
const uint innerCode = 0xb5890dba;
|
const uint innerCodetemp = 0xb5890dba;
|
||||||
AESKeyData key = AES.GenerateKeyDataFromNonces(servernonce, newNonce);
|
AESKeyData key = AES.GenerateKeyDataFromNonces(servernonce, newNonce);
|
||||||
|
|
||||||
var g = 47;
|
var g = 47;
|
||||||
|
|
@ -216,7 +239,7 @@ namespace TlgListenerApplication
|
||||||
using (var binaryWriter = new BinaryWriter(memoryStream))
|
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||||
{
|
{
|
||||||
binaryWriter.Write(hashsum);
|
binaryWriter.Write(hashsum);
|
||||||
binaryWriter.Write(innerCode);
|
binaryWriter.Write(innerCodetemp);
|
||||||
binaryWriter.Write(nonceFromClient);
|
binaryWriter.Write(nonceFromClient);
|
||||||
binaryWriter.Write(servernonce);
|
binaryWriter.Write(servernonce);
|
||||||
binaryWriter.Write(g);
|
binaryWriter.Write(g);
|
||||||
|
|
@ -237,14 +260,15 @@ namespace TlgListenerApplication
|
||||||
}
|
}
|
||||||
else if (responseCode == step3Constructor)
|
else if (responseCode == step3Constructor)
|
||||||
{
|
{
|
||||||
AuthKey authKey = new AuthKey(ga.ModPow(a, dhPrime));
|
var _gba = gb.ModPow(a, dhPrime);
|
||||||
|
AuthKey authKey = new AuthKey(_gba);
|
||||||
var newNonceHash = authKey.CalcNewNonceHash(newNonce, 1);
|
var newNonceHash = authKey.CalcNewNonceHash(newNonce, 1);
|
||||||
const uint innerCode = 0x3bcbf734;
|
const uint innerCodeTemp = 0x3bcbf734;
|
||||||
using (var memoryStream = new MemoryStream())
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var binaryWriter = new BinaryWriter(memoryStream))
|
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||||
{
|
{
|
||||||
binaryWriter.Write(innerCode);
|
binaryWriter.Write(innerCodeTemp);
|
||||||
binaryWriter.Write(servernonce);
|
binaryWriter.Write(servernonce);
|
||||||
binaryWriter.Write(nonceFromClient);
|
binaryWriter.Write(nonceFromClient);
|
||||||
binaryWriter.Write(newNonceHash);//hashnewnonce
|
binaryWriter.Write(newNonceHash);//hashnewnonce
|
||||||
|
|
@ -252,11 +276,33 @@ namespace TlgListenerApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (responseCode == -627372787)
|
else if (innerCode == -2035355412)//TLRequestSendCode
|
||||||
{
|
{
|
||||||
long authkey = 123456789;
|
#region Generate TLSentCode
|
||||||
byte[] message = null;
|
|
||||||
|
|
||||||
|
var sentCode = new TLSentCode();
|
||||||
|
sentCode.PhoneRegistered = false;
|
||||||
|
sentCode.Timeout = 7777;
|
||||||
|
sentCode.PhoneCodeHash = "asdfghjklmnbvcxzasdf";
|
||||||
|
sentCode.Flags = 3;
|
||||||
|
sentCode.NextType = new TLCodeTypeSms();
|
||||||
|
sentCode.Type = new TLSentCodeTypeApp() { Length = 20 };
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||||
|
{
|
||||||
|
binaryWriter.Write(0xf35c6d01);//main code
|
||||||
|
binaryWriter.Write(messageId.Value);//requestId -- ulong -- from mesage id
|
||||||
|
sentCode.SerializeBody(binaryWriter);
|
||||||
|
outputdata = memoryStream.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (innerCode == -627372787)
|
||||||
|
{
|
||||||
#region Generate TLConfig
|
#region Generate TLConfig
|
||||||
//---Genrate mock tlconfig
|
//---Genrate mock tlconfig
|
||||||
var config = new TLConfig();
|
var config = new TLConfig();
|
||||||
|
|
@ -269,7 +315,7 @@ namespace TlgListenerApplication
|
||||||
config.Date = Convert.ToInt32((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
|
config.Date = Convert.ToInt32((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
|
||||||
config.DcOptions = new TLVector<TLDcOption>()
|
config.DcOptions = new TLVector<TLDcOption>()
|
||||||
{
|
{
|
||||||
new TLDcOption(){Flags=0,Id=1,IpAddress="192.168.1.1",Port=5000,TcpoOnly=true }
|
new TLDcOption(){Flags=0,Id=1,IpAddress="127.0.0.1",Port=5000 }
|
||||||
};
|
};
|
||||||
config.DisabledFeatures = new TLVector<TLDisabledFeature>();
|
config.DisabledFeatures = new TLVector<TLDisabledFeature>();
|
||||||
config.ForwardedCountMax = 777;
|
config.ForwardedCountMax = 777;
|
||||||
|
|
@ -288,47 +334,57 @@ namespace TlgListenerApplication
|
||||||
config.SavedGifsLimit = 777;
|
config.SavedGifsLimit = 777;
|
||||||
config.StickersRecentLimit = 777;
|
config.StickersRecentLimit = 777;
|
||||||
config.ThisDc = 1;//TODO: ---what's this?!---
|
config.ThisDc = 1;//TODO: ---what's this?!---
|
||||||
config.MeUrlPrefix = "https";
|
config.MeUrlPrefix = "https://t.me/";
|
||||||
config.TestMode = false;
|
config.TestMode = false;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using (var memoryStream = new MemoryStream())
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var binaryWriter = new BinaryWriter(memoryStream))
|
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||||
{
|
{
|
||||||
binaryWriter.Write(0xf35c6d01);//main code
|
binaryWriter.Write(0xf35c6d01);//main code
|
||||||
//binaryWriter.Write(0xf35c6d02);//code
|
//binaryWriter.Write(0xf35c6d02);//code
|
||||||
binaryWriter.Write(18446744073709111111);//requestId -- ulong
|
binaryWriter.Write(messageId.Value);//requestId -- ulong -- from mesage id
|
||||||
//binaryWriter.Write(0x2144ca17);//innercode -- int
|
//binaryWriter.Write(0x2144ca17);//innercode -- int
|
||||||
//binaryWriter.Write(1123456789);//sample code
|
//binaryWriter.Write(1123456789);//sample code
|
||||||
//Serializers.Bytes.write(binaryWriter, config.Serialize());
|
//Serializers.Bytes.write(binaryWriter, config.Serialize());
|
||||||
binaryWriter.Write(config.Serialize());
|
config.SerializeBody(binaryWriter);
|
||||||
message = memoryStream.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var memoryStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (var binaryWriter = new BinaryWriter(memoryStream))
|
|
||||||
{
|
|
||||||
binaryWriter.Write(authkey);
|
|
||||||
binaryWriter.Write(servernonce);
|
|
||||||
binaryWriter.Write(authkey);//salt
|
|
||||||
binaryWriter.Write(authkey);//sessionId
|
|
||||||
binaryWriter.Write(authkey);//messageid
|
|
||||||
binaryWriter.Write(sequenceNumber);
|
|
||||||
|
|
||||||
binaryWriter.Write(message.Length);
|
|
||||||
binaryWriter.Write(message);
|
|
||||||
|
|
||||||
outputdata = memoryStream.ToArray();
|
outputdata = memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if (innerCode == -1126886015)
|
||||||
|
{
|
||||||
|
#region Generate TLAuthorization
|
||||||
|
|
||||||
|
var auth = new TeleSharp.TL.Auth.TLAuthorization();
|
||||||
|
auth.Flags = 3;
|
||||||
|
auth.User = new TLUser() { FirstName = "Meysami" };
|
||||||
|
|
||||||
if (responseCode != -627372787)
|
#endregion
|
||||||
|
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||||
|
{
|
||||||
|
binaryWriter.Write(0xf35c6d01);//main code
|
||||||
|
binaryWriter.Write(messageId.Value);//requestId -- ulong -- from mesage id
|
||||||
|
auth.SerializeBody(binaryWriter);
|
||||||
|
outputdata = memoryStream.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (innerCode != 0)
|
||||||
|
{
|
||||||
|
outputdata = PrepareToSend2(outputdata, authkey, servernonce, sequenceNumber);
|
||||||
|
}
|
||||||
|
else
|
||||||
outputdata = PrepareToSend(outputdata);
|
outputdata = PrepareToSend(outputdata);
|
||||||
|
|
||||||
outputdata = Encode(outputdata, sequenceNumber++);
|
outputdata = Encode(outputdata, sequenceNumber++);
|
||||||
|
|
@ -459,6 +515,27 @@ namespace TlgListenerApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] PrepareToSend2(byte[] message, long authkey, byte[] servernonce, int sequenceNumber)
|
||||||
|
{
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||||
|
{
|
||||||
|
binaryWriter.Write(authkey);
|
||||||
|
binaryWriter.Write(servernonce);
|
||||||
|
binaryWriter.Write(authkey);//salt
|
||||||
|
binaryWriter.Write(authkey);//sessionId
|
||||||
|
binaryWriter.Write(authkey);//messageid
|
||||||
|
binaryWriter.Write(sequenceNumber);
|
||||||
|
|
||||||
|
binaryWriter.Write(message.Length);
|
||||||
|
binaryWriter.Write(message);
|
||||||
|
|
||||||
|
return memoryStream.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static long GetNewMessageId()
|
private static long GetNewMessageId()
|
||||||
{
|
{
|
||||||
long time = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds);
|
long time = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ namespace TLSharp.Core.Requests
|
||||||
{
|
{
|
||||||
private readonly List<ulong> _msgs;
|
private readonly List<ulong> _msgs;
|
||||||
|
|
||||||
|
public AckRequest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
public AckRequest(List<ulong> msgs)
|
public AckRequest(List<ulong> msgs)
|
||||||
{
|
{
|
||||||
_msgs = msgs;
|
_msgs = msgs;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ namespace TeleSharp.TL
|
||||||
{
|
{
|
||||||
public class ObjectUtils
|
public class ObjectUtils
|
||||||
{
|
{
|
||||||
|
public static bool ServerSide = false;
|
||||||
public static object DeserializeObject(BinaryReader reader)
|
public static object DeserializeObject(BinaryReader reader)
|
||||||
{
|
{
|
||||||
int Constructor = reader.ReadInt32();
|
int Constructor = reader.ReadInt32();
|
||||||
|
|
@ -24,6 +25,13 @@ namespace TeleSharp.TL
|
||||||
{
|
{
|
||||||
throw new InvalidDataException("Constructor Invalid Or Context.Init Not Called !", ex);
|
throw new InvalidDataException("Constructor Invalid Or Context.Init Not Called !", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ServerSide)
|
||||||
|
{
|
||||||
|
((TLObject)obj).DeserializeBody(reader);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
if (t.IsSubclassOf(typeof(TLMethod)))
|
if (t.IsSubclassOf(typeof(TLMethod)))
|
||||||
{
|
{
|
||||||
((TLMethod)obj).DeserializeResponse(reader);
|
((TLMethod)obj).DeserializeResponse(reader);
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,6 @@ namespace TeleSharp.TL
|
||||||
SystemVersion = StringUtil.Deserialize(br);
|
SystemVersion = StringUtil.Deserialize(br);
|
||||||
AppVersion = StringUtil.Deserialize(br);
|
AppVersion = StringUtil.Deserialize(br);
|
||||||
LangCode = StringUtil.Deserialize(br);
|
LangCode = StringUtil.Deserialize(br);
|
||||||
|
|
||||||
int queryconstructorid = br.ReadInt32();
|
|
||||||
var obj = Activator.CreateInstance(TLContext.getType(queryconstructorid));
|
|
||||||
((TLObject)obj).DeserializeBody(br);
|
|
||||||
Query = (TLObject)obj;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SerializeBody(BinaryWriter bw)
|
public override void SerializeBody(BinaryWriter bw)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace TeleSharp.TL
|
||||||
where t.IsSubclassOf(typeof(TLObject))
|
where t.IsSubclassOf(typeof(TLObject))
|
||||||
where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null
|
where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null
|
||||||
select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);
|
select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);
|
||||||
Types.Add(481674261, typeof(TLVector<>));
|
Types.Add(481674261, typeof(TLVector<>));
|
||||||
}
|
}
|
||||||
public static Type getType(int Constructor)
|
public static Type getType(int Constructor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue