简体   繁体   English

设置 CilBody.KeepOldMaxStack 或 MetadataOptions.Flags

[英]setting CilBody.KeepOldMaxStack or MetadataOptions.Flags

While decompiling .net assembly using de4dot I am getting following message in console:在使用 de4dot 反编译 .net 程序集时,我在控制台中收到以下消息:

Error calculating max stack value.计算最大堆栈值时出错。 If the method's obfuscated, set CilBody.KeepOldMaxStack or MetadataOptions.Flags (KeepOldMaxStack, global option) to ignore this error如果方法被混淆了,设置 CilBody.KeepOldMaxStack 或 MetadataOptions.Flags (KeepOldMaxStack, global option) 忽略这个错误

How do I set CilBody.KeepOldMaxStack or MetadataOptions.Flags?如何设置 CilBody.KeepOldMaxStack 或 MetadataOptions.Flags?

Maybe a bit late, but I ran into the same problem today, finding your open question while looking for a solution, and this is how I solved it - I hope it works for you, too:也许有点晚了,但我今天遇到了同样的问题,在寻找解决方案的同时找到了你的未解决问题,这就是我解决它的方法 - 我希望它也对你有用:

// Working with an assembly definition
var ass = AssemblyDef.Load("filename.dll");

// Do whatever you want to do with dnLib here

// Create global module writer options
var options = new ModuleWriterOptions(ass.Modules[0]);
options.MetadataOptions.Flags |= MetadataFlags.KeepOldMaxStack;

// Write the new assembly using the global writer options
ass.Write("newfilename.dll", options);

If you want to set the flag only for a selection of methods that produce the problem before writing, just for example:如果您只想在编写之前为选择产生问题的方法设置标志,例如:

// Find the type in the first module, then find the method to set the flag for
ass.Modules[0]
    .Types.First((type) => type.Name == nameof(TypeToFind))
    .FindMethod(nameof(MethodToFind))
    .KeepOldMaxStack = true;

CilBody is maybe a bit confusing, if you're not too deep into the internal .NET assembly structures: It simply means the body object of the method that produces the problem, when writing the modified assembly. CilBody可能有点令人困惑,如果您对内部 .NET 程序集结构不太了解:它仅表示在编写修改后的程序集时产生问题的方法的主体 object。 Obfuscators often try to confuse disassemblers by producing invalid structures, what may cause a problem when calculating the maxstack value before writing the assembly with dnLib.混淆器经常试图通过产生无效结构来混淆反汇编程序,这可能会在使用 dnLib 编写程序集之前计算 maxstack 值时导致问题。 By keeping the original maxstack value, you can step over those invalid method structures.通过保留原始的 maxstack 值,您可以跳过那些无效的方法结构。

In the context of de4dot it seems to be a bug, or the application is simply not designed to solve invalid method structures of obfuscated assemblies - in this case there's no solution for you, if the de4net developer won't fix/implement it, and you don't want to write a patch using the source code from GitHub.在 de4dot 的上下文中,这似乎是一个错误,或者该应用程序根本不是为了解决混淆程序集的无效方法结构而设计的——在这种情况下,如果 de4net 开发人员不修复/实现它,则没有适合您的解决方案,并且您不想使用 GitHub 的源代码编写补丁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM