c# - AgileDotNet 混淆代码调用错误函数
问题描述
在 ac# 项目上运行 AgileDotNet 后,我遇到了最不寻常的错误:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'qVQ=.qLQ=' does not contain a definition for 'MyFunctionActualName'
at CallSite.Target(Closure , CallSite , Type , Object , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at ohM=.oQM=.<OnCallback>d__21.MoveNext() Program.cs::OnCallback() #449
C# 试图通过函数的实际名称调用函数,即:MyFunctionActualName
. 由于代码被混淆了,当然带有名称的函数MyFunctionActualName
不再存在。为什么 AgileDotNet 尝试调用它?如何调试这样的问题?
解决方案
此异常的原因是由于代码使用了该dynamic
类型,然后在此类实例上调用了方法。
让我给你看一个例子:
void Main()
{
dynamic t = new Test();
t.ActuallyNotPresentMethod();
}
public class Test
{
public void Execute() => "test".Dump();
}
这抛出:
RuntimeBinderException:“UserQuery.Test”不包含“ActuallyNotPresentMethod”的定义
让我们看一下它生成的 IL,该UserQuery
部分来自LINQPad,我用来运行上面的示例并从以下获取 IL:
IL_0000: newobj UserQuery+Test..ctor
IL_0005: stloc.0
IL_0006: ldsfld UserQuery+<>o__4.<>p__0
IL_000B: brtrue.s IL_0041
IL_000D: ldc.i4 00 01 00 00
IL_0012: ldstr "ActuallyNotPresentMethod"
IL_0017: ldnull
IL_0018: ldtoken UserQuery
IL_001D: call System.Type.GetTypeFromHandle
IL_0022: ldc.i4.1
IL_0023: newarr Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo
IL_0028: dup
IL_0029: ldc.i4.0
IL_002A: ldc.i4.0
IL_002B: ldnull
IL_002C: call Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create
IL_0031: stelem.ref
IL_0032: call Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember
IL_0037: call System.Runtime.CompilerServices.CallSite<System.Action<System.Runtime.CompilerServices.CallSite,System.Object>>.Create
IL_003C: stsfld UserQuery+<>o__4.<>p__0
IL_0041: ldsfld UserQuery+<>o__4.<>p__0
IL_0046: ldfld System.Runtime.CompilerServices.CallSite<System.Action<System.Runtime.CompilerServices.CallSite,System.Object>>.Target
IL_004B: ldsfld UserQuery+<>o__4.<>p__0
IL_0050: ldloc.0
IL_0051: callvirt System.Action<System.Runtime.CompilerServices.CallSite,System.Object>.Invoke
IL_0056: ret
如果你看这一行:
IL_0012: ldstr "ActuallyNotPresentMethod"
您可以看到要调用的方法的名称实际上作为字符串文字嵌入在 IL 中。
如果我们将代码更改为不使用dynamic
,并调用Execute
存在,我们得到:
IL_0000: newobj UserQuery+Test..ctor
IL_0005: callvirt UserQuery+Test.Execute
IL_000A: ret
你可以看到调用是完全不同的。
这解释了异常。该代码dynamic
用于调用方法,并且此字符串未经过混淆处理,因此包含原始未混淆方法名称。由于该方法不再以该名称存在,因此运行时绑定程序会在运行时引发异常。
为什么,确切地说,AgileDotNet 错过了我不知道的动态。可能是它根本无法处理dynamic
,在这种情况下,您将不得不处理它。您应该联系 Secureteam寻求帮助,以确定该工具能够提供什么(如果有的话)。
推荐阅读
- excel - excel使用vlookup使用另一列将两个表中的两列配对
- javascript - 捆绑和缩小以及异步/等待
- c# - 如果不在 .NET Core 中,是否可以引用解决方案中存在的项目并使用 NuGet 包引用作为后备?
- python - 如何实例化现有的 QGIS 插件工具栏
- zig - 预期类型 ?extern fn
- django - Django:根据未来 1 周和 2 周内的到期日期过滤数据
- android - 带有 Dialogfragment 的 Activity 总是在中间
- php - 制作自己的 loadhelper 函数(如在 CodeIgniter 中)
- c# - 如何处理服务器上的加密明文和客户端的解密?
- amazon-web-services - AWS Lambda Python 3.7:无法导入模块'lambda_function':缺少必需的依赖项['numpy']