WritePeToStream on Mono

Topics: PDB Writer, PE Writer
Nov 9, 2014 at 6:39 PM
Any ideas on how to write a PE to a stream (memory or file) on Mono?

It looks like we might be out of luck because the PDB Writer relies on COM and the unmanaged CorSymWriter_SxS.

To give a bit of context, we're trying to load + instrument + write an assembly.

Nov 9, 2014 at 11:05 PM
I'm afraid that you are probably out of luck. The PDB format is quite involved and unfortunately also completely undocumented. The PDB reader was reverse engineered from the CorSym sources by a very senior OS engineer in a hurry. With enough effort and experimentation you might be able to infer the format from the reader. I had a look at doing that some years ago, but could not find enough time to do it.

I would dearly love to make C# the default language for any serious software development on Linux (these days I have to use Java, which makes me sad and less productive). Unfortunately I have no time to spare for helping out on this.

As things stand, you should be able to use CCI on Mono to create PE files. You just have to a) give up on writing PDB files and b) compile CCI with the Mono switch.

Mono also has its own debugging file format. If you ask around on Mono forums, you might get some pointers on code mods that allow CCI to write to that format.
Nov 10, 2014 at 2:06 PM
Thanks, Herman. I was able to get CCI to create PE files on Mono.

For our project, we care more about reading the debug file because we have a static analysis that depends on it. I'll ask around the Mono forums.