首页 > 解决方案 > AgileDotNet 混淆器弄乱了 httpClient.PostAsync

问题描述

我注意到使用 AgileDotNet 混淆的应用程序无法发送请求httpClient.PostAsync。我将问题缩减为 20 行代码,以便每个人都可以尝试。

  internal class Program
  {
    public static void Main(string[] args){
      Send("lala", "https://url");
      Console.ReadLine();
    }

    public static async Task<string> Send(string jsonString, string url){

      using (var client = new HttpClient()){

        StringContent stringContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
        var result = await client.PostAsync(url, stringContent);

        Console.WriteLine(result.StatusCode);
        if (result.StatusCode == HttpStatusCode.OK){
          string response = await result.Content.ReadAsStringAsync();
          Console.WriteLine(response);
          return response;

        }else{
          string response = await result.Content.ReadAsStringAsync();
          Console.WriteLine(response);
          return response;
        }
      }

    }
  }

如果没有被混淆,下面的代码将发送一个 Post 请求。如果使用 AgileDotNet,它永远不会发送请求。此外,错误是完全无声的,因为 Event Viever 和控制台中都没有显示。

有没有人经历过这个?任何已知的解决方法?我正在使用 AgileDotNet 6.6.0.11

更新:将 Main 的返回类型更改为async Task并调用时,await Send我收到一个错误:

Unhandled Exception: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ohM=.oRM=.<Send>d__1.MoveNext() in C:\Users\User\source\repos\PostAsyncTests\PostAsyncTests\Program.cs:line 24
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ohM=.oRM=.<Main>d__0.MoveNext() in C:\Users\User\source\repos\PostAsyncTests\PostAsyncTests\Program.cs:line 14
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at ohM=.oRM=.pRM=(String[] args)

显然,建立 SSL 连接会导致问题。

有问题的敏捷项目 .cls 文件:

<?xml version="1.0" encoding="utf-16"?>
<AgileDotNet Version="6.6.0.11">
  <AssemblyList>
    <Assembly Path="PostAsyncTests.exe" Secure="true" Obfuscation="true" FlowObfuscation="true" MethodCallObfuscation="true" ILMerge="none" />
  </AssemblyList>
  <Settings>
    <General OutputDirectory="Secured" SignatureFile="" PfxPassword="" FilePathMode="relativepath" GenerateDebugInfo="True" SdkPath="" />
    <Obfuscation ObfuscationMapFile="ObfuscationMap" RenamingScheme="printablechars" CrossAssemblyObfuscation="true" ExcludeXamlTypes="false" ControlFlowObfuscation="basic" PredefindSymbolNamesFilePath="" RenameMethodParameters="False">
      <RenamingExclusions />
      <AssemblyLoadPaths />
    </Obfuscation>
    <Secure SecureUserStrings="true" EncryptManagedResources="true" RedistName="AgileDotNetRT" RedistName64="AgileDotNetRT64" DisableRuntimeEmbedding="False" AntiDebuggerDetection="False" SkipSmallMethods="False" />
    <Tracking ConfigureErrorReporting="false" ProductName="PostAsyncTests" ProductVersion="1.0.0.0" CompanyName="SecureTeam Software Ltd." />
    <CodeVirtualization PerformCodeVirtualization="false" RedistName="AgileDotNet.VMRuntime" />
    <LicenseFeatures />
  </Settings>
  <Licensing>
    <Licenses />
  </Licensing>
</AgileDotNet>

标签: c#obfuscation

解决方案


推荐阅读