De4dot 设置CilBody.KeepOldMaxStack或MetadataOptions.Flags

De4dot 设置CilBody.KeepOldMaxStack或MetadataOptions.Flags,de4dot,De4dot,使用de4dot反编译.net程序集时,我在控制台中收到以下消息: 计算最大堆栈值时出错。如果该方法已混淆,请设置CilBody.KeepOldMaxStack或MetadataOptions.Flags(KeepOldMaxStack,全局选项)以忽略此错误 如何设置CilBody.KeepOldMaxStack或MetadataOptions.Flags?可能有点晚了,但我今天遇到了同样的问题,在寻找解决方案的同时发现了您的开放问题,这就是我解决问题的方法-我希望它也适用于您: // Wor

使用de4dot反编译.net程序集时,我在控制台中收到以下消息:

计算最大堆栈值时出错。如果该方法已混淆,请设置CilBody.KeepOldMaxStack或MetadataOptions.Flags(KeepOldMaxStack,全局选项)以忽略此错误


如何设置CilBody.KeepOldMaxStack或MetadataOptions.Flags?

可能有点晚了,但我今天遇到了同样的问题,在寻找解决方案的同时发现了您的开放问题,这就是我解决问题的方法-我希望它也适用于您:

// 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);
如果只想在编写前为产生问题的方法选择设置标志,例如:

// 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
如果您对内部.NET程序集结构不太了解,可能会有点混淆:它只是指在编写修改后的程序集时产生问题的方法的body对象。混淆器通常试图通过生成无效结构来混淆反汇编程序,这可能导致在使用dnLib编写程序集之前计算maxstack值时出现问题。通过保留原始的maxstack值,可以跳过那些无效的方法结构

在de4dot的上下文中,它似乎是一个bug,或者应用程序根本不是为了解决模糊程序集的无效方法结构而设计的——在这种情况下,如果de4net开发人员不修复/实现它,并且您不想使用GitHub的源代码编写补丁,那么就没有解决方案