问题标签 [mono.cecil]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 我可以从 MethodDefinition (Cecil) 获取 MethodInfo 吗?
我想使用 MethodInfo,有没有办法将 Cecil 的 MethodDefinition 转换为 MethodInfo?
.net - Decompile method from assembly (ICSharpCode)
I'm trying to decompile a method programmatically using ICSharpCode. I'm able to decompile the entire type, but whenever I try to decompile a single method, I get a null reference exception. The approach is much like this question ICSharpCode.Decompiler + Mono.Cecil -> How to generate code for a single method?
The exception is thrown when invoking astBuilder.AddMethod. Any idea of what I'm missing. Or maybe recommendations for a different framework?
Thanks in advance!
Stacktrace:
at ICSharpCode.Decompiler.Ast.NameVariables.AssignNamesToVariables(DecompilerContext context, IEnumerable
1 parameters, IEnumerable
1 variables, ILBlock methodBody) at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable1 parameters) at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable
1 parameters) at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethodBody(MethodDefinition method, IEnumerable`1 parameters) at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethod(MethodDefinition methodDef) at ICSharpCode.Decompiler.Ast.AstBuilder.AddMethod(MethodDefinition method) at CodeFlow.Decompile.DecompileMethod(String assemblyPath, String assemblyFile, String typeName, String methodName) in C:\Arbejdsfiler\DCFServices\Tools\CustomFxCopRules\CustomCodeAnalysis\CodeFlow\Decompile.cs:line 69
c# - 如何从方法引用生成委托类型?
我正在尝试从 MethodReference 生成委托类型,但 PEVerify 一直说我的类型无效。
这是我的代码:
在 peverify 我得到:
哪些是代表。
.net - 使用 Mono Cecil 添加指令时,IL 偏移发生错误更改
可能重复:
Mono.Cecil 是否负责分支等位置?
我正在开发一个项目,该项目要求我在我的应用程序中调用某些方法后插入一个静态方法调用。我正在使用 Mono Cecil,并且在大多数情况下一切正常。但是,当更新的程序集写入磁盘时,我遇到了一些分支偏移量被破坏的情况。这是我的代码的样子:
因此,该代码在 90% 的情况下都可以正常工作 - 目标方法通过我的额外调用进行了检测,并且一切正常。
另外 10% 的情况下,检测方法无法执行,并且尝试在 ILSpy 中查看它时出错。ILSpy 错误是:
我已经用 ildasm 反编译了代码,我注意到在保存程序集时如何更新偏移似乎存在问题。我没有对调用的偏移量做任何事情(试图手动设置它们,但看到了同样的问题)。我的一种问题方法的仪器前反汇编如下所示:
当我查看已检测的反汇编时,此示例中对应于 IL_0067 的行显示为:
由于当前方法中不存在 IL_0129,因此无法编译。
我注意到了,但我还没有证明这只发生在迭代器周围。到目前为止发生这种情况的两种情况的 C# 代码都是 foreach 循环,并且不正确的分支目标似乎都与 foreach 循环的结束条件有关。
所以,我的问题是:我需要手动管理偏移量引用,还是我做错了什么?
.net - 如何在 Mono.Cecil 中发出对 String.op_Equality 的调用
我正在尝试使用 Mono.Cecil 将代码注入程序集。到目前为止一切都很好,但现在我正在尝试实现这一点 IL:
我如何在 Cecil 中做到这一点?我知道这有点像
我不知道要发送什么样的参数或如何获取对该静态函数的引用。
我该怎么做呢?
c# - 在 MSBuild 任务中使用 Mono.Cecil 解决程序集是 Silverlight 还是 .NET
我正在使用MSBuild任务中的 Mono.Cecil,但在解决程序集的方式上遇到了问题。它正在选择.NET版本的Prism而不是 Silverlight。.NET 版本的 Prism 不包含Microsoft.Practices.Prism.Regions.Behaviors.TabControlRegionSyncBehavior
,因此我们无法解析该类型。
我正在对中间输出执行任务,因此引用的程序集不在该文件夹中。程序集的搜索路径在 MSBuild 脚本中设置为 ReferencePath。
Mono.Cecil 在此函数中进行基于名称的匹配:
有没有办法让它比较运行时(Silverlight 与 .NET)?有没有其他方法可以解决这个问题?让它使用元数据版本是否明智?
.net - Mono.Cecil:注入try/finally?
在Mono.Cecil中实现 try/catch 的很好的概述在这里得到了回答,但他在没有完整的 try/catch/finally 时停止了。那么如何使用 Mono.Cecil 实现 try/finally?
c# - 发出委托函数调用
我有以下 C# 代码:
这是IL代码:
我怎样才能发出
通过System.Reflection.Emit或更好地通过Mono.Cecil 指令?
!1 和 !0 代表什么?
c# - 带有可选参数的发射函数
我有以下 C# 代码:
这里是 IL 代码(ILSpy):
如何使用System.Reflection.Emit或更好地使用Mono.Cecil获得它?