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

R2R Linux PE file Invalid section RVA #267

Open
FickoDeLux opened this issue Dec 1, 2023 · 3 comments
Open

R2R Linux PE file Invalid section RVA #267

FickoDeLux opened this issue Dec 1, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@FickoDeLux
Copy link

dnSpyEx version

6.4.1

Describe the Bug

DnSpyEx loads the mixed linux module (R2R crossgened) just fine.
But by saving (without any modification) generates exception:

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 C:\Users\admin\Desktop\dnSpy-hotfix\dnSpy\Extensions\dnSpy.AsmEditor\SaveModule\ModuleSaver.cs:line 187
at dnSpy.AsmEditor.SaveModule.ModuleSaver.SaveAll() in C:\Users\admin\Desktop\dnSpy-hotfix\dnSpy\Extensions\dnSpy.AsmEditor\SaveModule\ModuleSaver.cs:line 151
at dnSpy.AsmEditor.SaveModule.SaveMultiModuleVM.SaveAsync(SaveOptionsVM[] mods) in C:\Users\admin\Desktop\dnSpy-hotfix\dnSpy\Extensions\dnSpy.AsmEditor\SaveModule\SaveMultiModuleVM.cs:line 250

How To Reproduce

1.) Load dll
2.) Save module

Expected Behavior

Saves the module

Actual Behavior

Saving 0 bytes

Additional Context

DnSpyEx handels crossgened windows dll just fine.

Steps needed to overcome the linux burden:

  1. Use "crossgen2.exe --compile-no-methods --targetos:windows" to strip native code and convert it to windows PE.
    2.) Load dll into DnSpyEx (It still handels it as a mixed module maybe oneother bug?)
    3.) Modify dll as needed (or not)
    4.) Save module (because it is a windows PE now DnSpyEx able to save it.)
    5.) Use "crossgen2.exe --compile-no-methods --targetos:linux" to convert it back to linux PE
@FickoDeLux FickoDeLux added the bug Something isn't working label Dec 1, 2023
@ElektroKill
Copy link
Member

Hi, could you provide a .exe/.dll file using which I can reproduce the issue easily? It would make diagnosing and fixing this bug much easier :p. If you would rather send it to me directly rather than upload it to GitHub, please email me elektrokilldev@protonmail.com

Thanks in advance!

@ElektroKill
Copy link
Member

Hi, this issue is not caused by dnSpy. It occurs in dnlib which is the metadata reading and writing library dnSpy uses. Please report the issue over at https://github.com/0xd4d/dnlib. The code required to reproduce it using dnlib is the following:

var mod = ModuleDefMD.Load("input.dll");

mod.NativeWrite("output.dll"); // crashes here

@FickoDeLux
Copy link
Author

I did
https://github.com/0xd4d/dnlib/issues/533
Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants