1
votes

Mono.Cecil does not support mixed mode assemblies as of date, and even though it can read the .NET portion of such assemblies, it does not write such assemblies back to disk. What does it take to support a read->write roundtrip for mixed mode assemblies? (without making any changes to the x86/x64 assembly)

Please note I only need to work with .NET metadata and CIL, not the actualy x86/x64 assembly itself. I only need to modify some .NET classes within a mixed-mode assembly, therefore, I need to load it into objects using Cecil, make my changes, and then save it back, leaving the x86/x64 assembly code unmodified.

I'm assuming the x86/x64 assembly would be stored in a chunk, which could be simply read into a bytearray during parsing, and outputted back into the generated EXE when saving the assembly. Is it so simple?

From the FAQ:

Cecil can read mixed mode assemblies, but writing mixed mode assemblies is not supported

1
I'm not trying to disassemble or patch the x86 itself. I'm actually just looking at modifying the .NET parts of the assembly. This works fine with Mono.Cecil for pure .NET assemblies but breaks with mixed mode ones. The addresses from .NET to x86 should remain the same since only the .NET classes are modified. Is this workable?Robin Rodricks

1 Answers

0
votes

Mono.Cecil does not support writing mixed mode assemblies.

There is another library, dnlib, which does. The API is similar, but not the same, so it's not a drop-in replacement.

From the project's README.md

dnlib was created because de4dot needed a robust .NET assembly library that could handle all types of obfuscated assemblies. de4dot used to use Mono.Cecil but since Mono.Cecil can't handle obfuscated assemblies, doesn't fully support mixed mode assemblies, doesn't read .NET assemblies the same way the CLR does and many other missing features de4dot needed, dnlib was a necessity. The API is similar because it made porting de4dot to dnlib a lot easier.

GitHub repository is here: https://github.com/0xd4d/dnlib