mirror of
https://github.com/sochix/TLSharp.git
synced 2026-03-20 20:25:32 +01:00
Added debug logging to MtProtoSender, so that state machine can be "visible".
This commit is contained in:
parent
3f5adeb3e9
commit
ef1f961592
|
|
@ -18,6 +18,8 @@ namespace TLSharp.Core.Network
|
||||||
{
|
{
|
||||||
//private ulong sessionId = GenerateRandomUlong();
|
//private ulong sessionId = GenerateRandomUlong();
|
||||||
|
|
||||||
|
private static NLog.Logger logger = NLog.LogManager.GetLogger("MTProto");
|
||||||
|
|
||||||
private readonly uint UpdatesTooLongID = (uint) new TeleSharp.TL.TLUpdatesTooLong ().Constructor;
|
private readonly uint UpdatesTooLongID = (uint) new TeleSharp.TL.TLUpdatesTooLong ().Constructor;
|
||||||
|
|
||||||
private TcpTransport _transport;
|
private TcpTransport _transport;
|
||||||
|
|
@ -88,7 +90,9 @@ namespace TLSharp.Core.Network
|
||||||
plaintextWriter.Write(packet.Length);
|
plaintextWriter.Write(packet.Length);
|
||||||
plaintextWriter.Write(packet);
|
plaintextWriter.Write(packet);
|
||||||
|
|
||||||
msgKey = Helpers.CalcMsgKey(plaintextPacket.GetBuffer());
|
var buffer = plaintextPacket.GetBuffer();
|
||||||
|
logger.Debug(Sniffer.MessageOut(buffer));
|
||||||
|
msgKey = Helpers.CalcMsgKey(buffer);
|
||||||
ciphertext = AES.EncryptAES(Helpers.CalcKey(_session.AuthKey.Data, msgKey, true), plaintextPacket.GetBuffer());
|
ciphertext = AES.EncryptAES(Helpers.CalcKey(_session.AuthKey.Data, msgKey, true), plaintextPacket.GetBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -123,6 +127,7 @@ namespace TLSharp.Core.Network
|
||||||
AESKeyData keyData = Helpers.CalcKey(_session.AuthKey.Data, msgKey, false);
|
AESKeyData keyData = Helpers.CalcKey(_session.AuthKey.Data, msgKey, false);
|
||||||
|
|
||||||
byte[] plaintext = AES.DecryptAES(keyData, inputReader.ReadBytes((int)(inputStream.Length - inputStream.Position)));
|
byte[] plaintext = AES.DecryptAES(keyData, inputReader.ReadBytes((int)(inputStream.Length - inputStream.Position)));
|
||||||
|
logger.Debug(Sniffer.MessageIn(plaintext));
|
||||||
|
|
||||||
using (MemoryStream plaintextStream = new MemoryStream(plaintext))
|
using (MemoryStream plaintextStream = new MemoryStream(plaintext))
|
||||||
using (BinaryReader plaintextReader = new BinaryReader(plaintextStream))
|
using (BinaryReader plaintextReader = new BinaryReader(plaintextStream))
|
||||||
|
|
|
||||||
25
TLSharp.Core/Network/Sniffer.cs
Normal file
25
TLSharp.Core/Network/Sniffer.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TLSharp.Core.Network
|
||||||
|
{
|
||||||
|
public static class Sniffer
|
||||||
|
{
|
||||||
|
public static string MessageOut(byte[] data)
|
||||||
|
{
|
||||||
|
return WriteMessage(new StringBuilder("[OUT]:"), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string MessageIn(byte[] data)
|
||||||
|
{
|
||||||
|
return WriteMessage(new StringBuilder("[IN]:"), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string WriteMessage(StringBuilder log, byte[] data)
|
||||||
|
{
|
||||||
|
foreach (var b in data)
|
||||||
|
log.AppendFormat(" {:x2}", b);
|
||||||
|
return log.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -42,6 +42,9 @@
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="NLog">
|
||||||
|
<HintPath>..\..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Auth\Authenticator.cs" />
|
<Compile Include="Auth\Authenticator.cs" />
|
||||||
|
|
@ -68,6 +71,7 @@
|
||||||
<Compile Include="Session.cs" />
|
<Compile Include="Session.cs" />
|
||||||
<Compile Include="TelegramClient.cs" />
|
<Compile Include="TelegramClient.cs" />
|
||||||
<Compile Include="Utils\Helpers.cs" />
|
<Compile Include="Utils\Helpers.cs" />
|
||||||
|
<Compile Include="Network\Sniffer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="MarkerMetro.Unity.Ionic.Zlib" version="2.0.0.14" targetFramework="net452" />
|
<package id="MarkerMetro.Unity.Ionic.Zlib" version="2.0.0.14" targetFramework="net452" />
|
||||||
|
<package id="NLog" version="4.4.12" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
Reference in a new issue