Skip to content

Commit

Permalink
1、更新依赖版本
Browse files Browse the repository at this point in the history
2、使用 C# 8.0 using 语法
  • Loading branch information
yggo committed Feb 2, 2021
1 parent ca2c50b commit ed46646
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 288 deletions.
64 changes: 34 additions & 30 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,65 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="PacketDotNet" publicKeyToken="451414c7667b2a58" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.0.5.0" newVersion="1.0.5.0"/>
<assemblyIdentity name="PacketDotNet" publicKeyToken="451414c7667b2a58" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0"/>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1"/>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.2.5.0" newVersion="1.2.5.0"/>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1"/>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.4.0" newVersion="3.1.4.0"/>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.2.0.0"/>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
4 changes: 1 addition & 3 deletions Common/Common.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using App.Metrics.Concurrency;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using YgAndroidQQSniffer.Extension;
Expand Down Expand Up @@ -35,7 +34,6 @@ public class DecryptionKey
}
public class Common
{
public static AtomicInteger Index;

public static LinkedList<DecryptionKey> Keys { get; set; } = new LinkedList<DecryptionKey>();

Expand Down
4 changes: 2 additions & 2 deletions Component/PacketAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void Resolve0A01()
int qq_len = Buf.ReadInt() - 4;
Uin = Buf.ReadCharSequence(qq_len, Encoding.UTF8).ToString();
byte[] remaining = Util.ReadRemainingBytes(Buf);
byte[] decrypt_data = Common.TeaKeyLogDecrypt(remaining, out DecryptionKey decryptionKey);
byte[] decrypt_data = Common.TeaKeyLogDecrypt(remaining, out _);
if (decrypt_data == null) return;
var buf_part1 = Unpooled.WrappedBuffer(decrypt_data);
buf_part1.ReadInt();
Expand Down Expand Up @@ -204,7 +204,7 @@ protected void Resolve0B01()
int qq_len = Buf.ReadInt() - 4;
Uin = Buf.ReadCharSequence(qq_len, Encoding.UTF8).ToString();
byte[] remaining = Util.ReadRemainingBytes(Buf);
byte[] decrypt_data = Common.TeaKeyLogDecrypt(remaining, out DecryptionKey decryptionKey);
byte[] decrypt_data = Common.TeaKeyLogDecrypt(remaining, out _);
if (decrypt_data == null) return;
var buf_part1 = Unpooled.WrappedBuffer(decrypt_data);
buf_part1.ReadInt();//head_size
Expand Down
98 changes: 49 additions & 49 deletions Component/PacketFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ namespace YgAndroidQQSniffer.Component
{
public class PacketFormatter : IParser
{
private StringBuilder _sb { get; set; } = new StringBuilder();
private IByteBuffer _buf { get; set; }
private StringBuilder Sb { get; set; } = new StringBuilder();
private IByteBuffer Buf { get; set; }
public string Uin { get; set; }
public string Parse(IByteBuffer value)
{
_buf = value;
Buf = value;
ReadPacketLen();
int packet_type = _buf.ReadInt();
byte encrypt_type = _buf.ReadByte();
int packet_type = Buf.ReadInt();
byte encrypt_type = Buf.ReadByte();

if (packet_type == 0x0A)
{
_sb.Append(packet_type.HexPadLeft().HexDump()).Append(" //packet_type").AppendLine();
Sb.Append(packet_type.HexPadLeft().HexDump()).Append(" //packet_type").AppendLine();
if (encrypt_type == 0x01)
{
_sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Resolve0A01();
}
else if (encrypt_type == 0x02)
{
_sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Resolve0A02();
}
else if (encrypt_type == 0x00)
{
_sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Resolve0A00();
}
else
Expand All @@ -42,20 +42,20 @@ public string Parse(IByteBuffer value)
}
else if (packet_type == 0x0B)
{
_sb.Append(packet_type.HexPadLeft().HexDump()).Append(" //packet_type").AppendLine();
Sb.Append(packet_type.HexPadLeft().HexDump()).Append(" //packet_type").AppendLine();
if (encrypt_type == 0x01)
{
_sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Resolve0B01();
}
else if (encrypt_type == 0x02)
{
_sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Resolve0B02();
}
else if (encrypt_type == 0x00)
{
_sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Sb.Append(encrypt_type.HexPadLeft().HexDump()).Append(" //encrypt_type").AppendLine();
Resolve0B00();
}
else
Expand All @@ -67,13 +67,13 @@ public string Parse(IByteBuffer value)
{
throw new InvalidOperationException("invalid packet_type: " + packet_type.HexPadLeft());
}
return _sb.ToString();
return Sb.ToString();
}

private void ReadPacketLen()
{
int packet_len = _buf.ReadInt();
_sb.Append(packet_len.HexPadLeft().HexDump()).Append($" //packet_len {packet_len}").AppendLine();
int packet_len = Buf.ReadInt();
Sb.Append(packet_len.HexPadLeft().HexDump()).Append($" //packet_len {packet_len}").AppendLine();
}

private void Resolve0A01()
Expand All @@ -83,92 +83,92 @@ private void Resolve0A01()

private void Resolve0A02()
{
if (_buf.GetInt(_buf.ReaderIndex) == 0x04)
if (Buf.GetInt(Buf.ReaderIndex) == 0x04)
{
_sb.Append(_buf.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(Buf.ReadInt().HexPadLeft().HexDump()).AppendLine();
}
_sb.Append(_buf.ReadByte().HexPadLeft().HexDump()).AppendLine();
Sb.Append(Buf.ReadByte().HexPadLeft().HexDump()).AppendLine();

int uin_len = _buf.ReadInt() - 4;
Uin = _buf.ReadCharSequence(uin_len, Encoding.UTF8).ToString();
int uin_len = Buf.ReadInt() - 4;
Uin = Buf.ReadCharSequence(uin_len, Encoding.UTF8).ToString();

_sb.Append((uin_len + 4).HexPadLeft().HexDump()).Append(" //uin_len").AppendLine();
_sb.Append(Encoding.UTF8.GetBytes(Uin).HexDump()).Append($" //uin {Uin}").AppendLine();
Sb.Append((uin_len + 4).HexPadLeft().HexDump()).Append(" //uin_len").AppendLine();
Sb.Append(Encoding.UTF8.GetBytes(Uin).HexDump()).Append($" //uin {Uin}").AppendLine();

byte[] remaining = Util.ReadRemainingBytes(_buf);
_sb.Append(remaining.HexDump()).AppendLine().AppendLine();
byte[] remaining = Util.ReadRemainingBytes(Buf);
Sb.Append(remaining.HexDump()).AppendLine().AppendLine();

byte[] decrypt_data = Common.TeaKeyLogDecrypt(remaining, out DecryptionKey decryptionKey);
if (decrypt_data == null) return;

var buf_part1 = Unpooled.WrappedBuffer(decrypt_data);
_sb.Append(Common.PrettyKeyDecryptDump(decrypt_data, decryptionKey)).AppendLine();
Sb.Append(Common.PrettyKeyDecryptDump(decrypt_data, decryptionKey)).AppendLine();
int head_size = buf_part1.ReadInt();
_sb.Append(head_size.HexPadLeft().HexDump()).Append($" //head_size {head_size}").AppendLine();
Sb.Append(head_size.HexPadLeft().HexDump()).Append($" //head_size {head_size}").AppendLine();

uint sso_seq = buf_part1.ReadUnsignedInt();
_sb.Append(sso_seq.HexPadLeft().HexDump()).Append($" //sso_seq {sso_seq}").AppendLine();
Sb.Append(sso_seq.HexPadLeft().HexDump()).Append($" //sso_seq {sso_seq}").AppendLine();

if (buf_part1.GetInt(buf_part1.ReaderIndex) == 0x00)
{
_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
}
else
{
uint appid = buf_part1.ReadUnsignedInt();
_sb.Append(appid.HexPadLeft().HexDump()).Append($" //appid {appid}").AppendLine();
Sb.Append(appid.HexPadLeft().HexDump()).Append($" //appid {appid}").AppendLine();

uint appid2 = buf_part1.ReadUnsignedInt();
_sb.Append(appid2.HexPadLeft().HexDump()).Append($" //appid2 {appid2}").AppendLine();
Sb.Append(appid2.HexPadLeft().HexDump()).Append($" //appid2 {appid2}").AppendLine();

_sb.Append(buf_part1.ReadBytes(12).HexDump()).AppendLine();
Sb.Append(buf_part1.ReadBytes(12).HexDump()).AppendLine();

if (buf_part1.GetInt(buf_part1.ReaderIndex) == 0x4C)
{
int tgt_len = buf_part1.ReadInt();
_sb.Append(tgt_len.HexPadLeft().HexDump()).Append($"// tgt_len {tgt_len}").AppendLine();
_sb.Append(buf_part1.ReadBytes(tgt_len - 4).HexDump()).Append(" //tgt").AppendLine();
Sb.Append(tgt_len.HexPadLeft().HexDump()).Append($"// tgt_len {tgt_len}").AppendLine();
Sb.Append(buf_part1.ReadBytes(tgt_len - 4).HexDump()).Append(" //tgt").AppendLine();
}
else
{
_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
}
}

int service_cmd_len = buf_part1.ReadInt() - 4;
string serviceCmd = buf_part1.ReadCharSequence(service_cmd_len, Encoding.UTF8).ToString();
_sb.Append((service_cmd_len + 4).HexPadLeft().HexDump()).Append($" //service_cmd_len {service_cmd_len}").AppendLine();
_sb.Append(Encoding.UTF8.GetBytes(serviceCmd).HexDump()).Append($" //serviceCmd [{serviceCmd}]").AppendLine();
Sb.Append((service_cmd_len + 4).HexPadLeft().HexDump()).Append($" //service_cmd_len {service_cmd_len}").AppendLine();
Sb.Append(Encoding.UTF8.GetBytes(serviceCmd).HexDump()).Append($" //serviceCmd [{serviceCmd}]").AppendLine();

_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();

int imei_len = buf_part1.ReadInt() - 4;
string imei = buf_part1.ReadCharSequence(imei_len, Encoding.UTF8).ToString();
_sb.Append((imei_len + 4).HexPadLeft().HexDump()).Append($" //imei_len {imei_len}").AppendLine();
_sb.Append(Encoding.UTF8.GetBytes(imei).HexDump()).Append($" //imei [{imei}]").AppendLine();
Sb.Append((imei_len + 4).HexPadLeft().HexDump()).Append($" //imei_len {imei_len}").AppendLine();
Sb.Append(Encoding.UTF8.GetBytes(imei).HexDump()).Append($" //imei [{imei}]").AppendLine();

if (buf_part1.GetInt(buf_part1.ReaderIndex) == 0x14)
{
_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
_sb.Append(buf_part1.ReadBytes(16).HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadBytes(16).HexDump()).AppendLine();
}
else
{
_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
}

short ksid_len = buf_part1.ReadShort();
string ksid = buf_part1.ReadCharSequence(ksid_len - 2, Encoding.UTF8).ToString();
_sb.Append((ksid_len + 4).HexPadLeft().HexDump()).Append($" //ksid_len {ksid_len}").AppendLine();
_sb.Append(Encoding.UTF8.GetBytes(ksid).HexDump()).Append($" //ksid [{ksid}]").AppendLine();
Sb.Append((ksid_len + 4).HexPadLeft().HexDump()).Append($" //ksid_len {ksid_len}").AppendLine();
Sb.Append(Encoding.UTF8.GetBytes(ksid).HexDump()).Append($" //ksid [{ksid}]").AppendLine();

_sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();
Sb.Append(buf_part1.ReadInt().HexPadLeft().HexDump()).AppendLine();

uint wupBuffer_len = buf_part1.ReadUnsignedInt();
_sb.Append((wupBuffer_len + 4).HexPadLeft().HexDump()).Append($" //wupBuffer_len {wupBuffer_len}").AppendLine();
Sb.Append((wupBuffer_len + 4).HexPadLeft().HexDump()).Append($" //wupBuffer_len {wupBuffer_len}").AppendLine();

_sb.Append(buf_part1.HexDump());
Sb.Append(buf_part1.HexDump());
}

private void Resolve0A00()
Expand Down
Loading

0 comments on commit ed46646

Please sign in to comment.