Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnlib.DotNet.Writer.ModuleWriterException #548

Closed
CatLover248 opened this issue Mar 3, 2024 · 2 comments
Closed

dnlib.DotNet.Writer.ModuleWriterException #548

CatLover248 opened this issue Mar 3, 2024 · 2 comments

Comments

@CatLover248
Copy link

Hello!

I am having some issues. I am writing to a cilBody then merging the il. But when I try to write it with module.Write() I get an error.


var cilBody = method.Body;
method.Body.Instructions.Clear();
cilBody.Instructions.Add(new Instruction......
method.Body.UpdateInstructionOffsets();
method.Body.KeepOldMaxStack = true;

dnlib.DotNet.Writer.ModuleWriterException
HResult=0x80131500
Message=Instruction is null. Error occurred after metadata event BeginWriteMethodBodies during writing method 'System.Void ConsoleAppTestForObfuscation.Program::Main(System.String[])' (0x06000001).
Source=dnlib
StackTrace:
at dnlib.DotNet.DummyLogger.Log(Object sender, LoggerEvent loggerEvent, String format, Object[] args)
at dnlib.DotNet.Writer.ModuleWriterBase.dnlib.DotNet.ILogger.Log(Object sender, LoggerEvent loggerEvent, String format, Object[] args)
at dnlib.DotNet.Writer.Metadata.Error(String message, Object[] args)
at dnlib.DotNet.Writer.Metadata.dnlib.DotNet.Writer.IWriterError.Error(String message)
at dnlib.DotNet.Writer.MethodBodyWriter.ErrorImpl(String message)
at dnlib.DotNet.Writer.MethodBodyWriterBase.Error(String message)
at dnlib.DotNet.Writer.MethodBodyWriterBase.GetOffset(Instruction instr)
at dnlib.DotNet.Writer.MethodBodyWriterBase.WriteShortInlineBrTarget(ArrayWriter& writer, Instruction instr)
at dnlib.DotNet.Writer.MethodBodyWriterBase.WriteOperand(ArrayWriter& writer, Instruction instr)
at dnlib.DotNet.Writer.MethodBodyWriterBase.WriteInstruction(ArrayWriter& writer, Instruction instr)
at dnlib.DotNet.Writer.MethodBodyWriterBase.WriteInstructions(ArrayWriter& writer)
at dnlib.DotNet.Writer.MethodBodyWriter.WriteFatHeader()
at dnlib.DotNet.Writer.MethodBodyWriter.Write()
at dnlib.DotNet.Writer.Metadata.WriteMethodBodies()
at dnlib.DotNet.Writer.Metadata.Create()
at dnlib.DotNet.Writer.Metadata.CreateTables()
at dnlib.DotNet.Writer.ModuleWriter.WriteImpl()
at dnlib.DotNet.Writer.ModuleWriterBase.Write(Stream dest)
at dnlib.DotNet.Writer.ModuleWriterBase.Write(String fileName)
at dnlib.DotNet.ModuleDef.Write(String filename, ModuleWriterOptions options)
at dnlib.DotNet.ModuleDef.Write(String filename)
at MeteorObfuscation.Meteor.MeteorObfuscation.init(String path) in C:\Users\hampter\source\repos\MeteorObfuscation\MeteorObfuscation\Meteor\MeteorObfuscation.cs:line 37
at MeteorObfuscation.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\hampter\source\repos\MeteorObfuscation\MeteorObfuscation\Form1.cs:line 27
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

@wtfsck
Copy link
Contributor

wtfsck commented Mar 4, 2024

The message says the instruction is null so check which instruction is null. Also check exception handlers and other places that could have instruction references.

@CatLover248
Copy link
Author

Thank you for your help!

Ive been able to identify the null instruction by checking if the individual instructions are null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants