diff --git a/README.md b/README.md index 7c06ad0..a1c0137 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Then it will attempt to sign-in as a user for which you must enter the **phone_n If the verification succeeds but the phone number is unknown to Telegram, the user might be prompted to sign-up (accepting the Terms of Service) and enter their **first_name** and **last_name**. -And that's it, you now have access to the full range of Telegram services, mainly through calls to `await client.Some_TL_Method(...)` +And that's it, you now have access to the [full range of Telegram services](https://core.telegram.org/methods), mainly through calls to `await client.Some_TL_Method(...)` # Saved session If you run this program again, you will notice that the previous prompts are gone and you are automatically logged-on and ready to go. diff --git a/src/Client.cs b/src/Client.cs index e12b030..cf46a73 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -234,7 +234,7 @@ namespace WTelegram var buffer = memStream.GetBuffer(); int frameLength = (int)memStream.Length; BinaryPrimitives.WriteInt32LittleEndian(buffer, frameLength + 4); // patch frame_len with correct value - uint crc = Force.Crc32.Crc32Algorithm.Compute(buffer, 0, frameLength); + uint crc = Helpers.UpdateCrc32(0, buffer, 0, frameLength); writer.Write(crc); // int32 frame_crc //TODO: support Transport obfuscation? @@ -277,8 +277,8 @@ namespace WTelegram var payload = new byte[length]; if (await FullReadAsync(_networkStream, payload, length, ct) != length) throw new ApplicationException("Could not read frame data : Connection shut down"); - uint crc32 = Force.Crc32.Crc32Algorithm.Compute(frame, 0, 8); - crc32 = Force.Crc32.Crc32Algorithm.Append(crc32, payload); + uint crc32 = Helpers.UpdateCrc32(0, frame, 0, 8); + crc32 = Helpers.UpdateCrc32(crc32, payload, 0, payload.Length); if (await FullReadAsync(_networkStream, frame, 4, ct) != 4) throw new ApplicationException("Could not read frame CRC : Connection shut down"); if (crc32 != BinaryPrimitives.ReadUInt32LittleEndian(frame)) diff --git a/src/Helpers.cs b/src/Helpers.cs index 31b5f53..2be1fbd 100644 --- a/src/Helpers.cs +++ b/src/Helpers.cs @@ -189,5 +189,11 @@ namespace WTelegram } return true; } + + // see also https://github.com/dotnet/runtime/issues/2036 and https://github.com/dotnet/runtime/pull/53623 + internal static readonly Func UpdateCrc32 = (Func) + typeof(System.IO.Compression.ZipArchive).Assembly.GetType("System.IO.Compression.Crc32Helper") + .GetMethod("UpdateCrc32", new[] { typeof(uint), typeof(byte[]), typeof(int), typeof(int) }) + .CreateDelegate(typeof(Func)); } } diff --git a/src/WTelegramClient.csproj b/src/WTelegramClient.csproj index 20c3a2f..608736d 100644 --- a/src/WTelegramClient.csproj +++ b/src/WTelegramClient.csproj @@ -40,7 +40,6 @@ -