Creating a PE file using IMetaDataEmit::Save(/ToMemory/ToStream)

205 Views Asked by At

I'm writing a native CLR Profiler which does some heavy IL rewriting. When developing a new feature, we sometimes encounter a CLR verification error. For small methods, it's pretty easy to compare the bytes before and after, looking at the various elements (method header, signature, locals, code and exception table, mostly) and finding the error. Sometimes, this can be on huge methods and the process might take a while. I'm trying to dump the current module to a file, in order to easily run peverify.exe (and https://github.com/dotnet/corert/tree/master/src/ILVerify). I found IMetaDataEmit::Save, which looks perfect on paper (we're using IMetaDataEmit constantly to perform the IL rewriting). I can dump my module, open it in a hex viewer and see the changes I made. However, it only dumps the module (the .Net directory inside the PE). How can I create a full PE (dll/exe) from this module, preferably programmatically?

0

There are 0 best solutions below