0xd4d / dnlib

Reads and writes .NET assemblies and modules
MIT License
2.18k stars 587 forks source link

ModuleWriterException: Invalid section RVA #545

Open Drovosek01 opened 9 months ago

Drovosek01 commented 9 months ago

I'm exploring. A dll file compiled using dotNet on a Mac with Apple Silicon processors.

I open the file in dnSpyEx v6.5.0 and then just try to save the module without any modifications

Screenshot 2024-02-19 at 16 03 42

and I get an error:

An exception has occurred dnlib.DotNet.Writer.ModuleWriterException: Invalid section RVA
   at dnlib.DotNet.Writer.NativeModuleWriter.WriteFile()
   at dnlib.DotNet.Writer.NativeModuleWriter.Write()
   at dnlib.DotNet.Writer.NativeModuleWriter.WriteImpl()
   at dnlib.DotNet.Writer.ModuleWriterBase.Write(Stream dest)
   at dnlib.DotNet.Writer.ModuleWriterBase.Write(String fileName)
   at dnlib.DotNet.ModuleDefMD.NativeWrite(String filename, NativeModuleWriterOptions options)
   at dnSpy.AsmEditor.SaveModule.ModuleSaver.Save(SaveModuleOptionsVM vm) in D:\a\dnSpy\dnSpy\Extensions\dnSpy.AsmEditor\SaveModule\ModuleSaver.cs:line 187
   at dnSpy.AsmEditor.SaveModule.ModuleSaver.SaveAll() in D:\a\dnSpy\dnSpy\Extensions\dnSpy.AsmEditor\SaveModule\ModuleSaver.cs:line 151
   at dnSpy.AsmEditor.SaveModule.SaveMultiModuleVM.SaveAsync(SaveOptionsVM[] mods) in D:\a\dnSpy\dnSpy\Extensions\dnSpy.AsmEditor\SaveModule\SaveMultiModuleVM.cs:line 250
Screenshot 2024-02-19 at 16 04 00

I tried to do this on Windows 10 x64 on an AMD laptop, and also tried to do it on Windows 11 ARM via Parallels Desktop and always get the same error.

Does anyone know how to fix this? Here is an example of such a file: CsvHelper dll for arm64.zip

ElektroKill commented 9 months ago

Probably related to: https://github.com/0xd4d/dnlib/issues/533