runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Reading (and writing) NGEN output files

Open WebDancer69 opened this issue 11 years ago • 5 comments

@richlander @jkotas

Is there any way to work with the output files from NGEN? Is the format documented, or even stable? If not, is there, or can you make, an API to read and write such files?

It would be particular useful for e.g. hardening tools.

WebDancer69 avatar Jun 04 '15 22:06 WebDancer69

We plan to add some documentation as part of fixing dotnet/runtime#3967.

The NGen files are just another executable binary format. The format is similar to other executable binary formats out there. There is number of compiler frameworks designed to work with executable binary formats. I do not think it make sense to build a greenfield APIs to work with NGen files. It would make more sense to enhance an existing compiler framework for NGen files e.g. LLVM as part of https://github.com/dotnet/llilc/ project.

The NGen format is extension of regular PE file format used for IL files. Existing tools for PE IL files will work on NGen files too: ildasm, link /dump, ... .

Could you please elaborate on what kind of hardening tools you have in mind?

jkotas avatar Jun 04 '15 23:06 jkotas

We use a tool that does e.g. checksums and code damage/repair hardening "actions", both which gets messed up when NGENing the hardened assembly. One potential solution could be to harden the image after NGEN, but currently the tool can not run on NGENed images, apparently because of the undocumented parts of the file. Also if we want a certain (private) method to be damaged or have a checksum, can it be tracked through NGEN?

Is there a way tell NGEN to not generate native images for such files, in case someone tries directly or indirectly to do this?

WebDancer69 avatar Jun 04 '15 23:06 WebDancer69

https://github.com/dotnet/coreclr/blob/master/Documentation/botr/readytorun-overview.md is overview of the readytorun file format that we plan to document in future.

jkotas avatar Aug 25 '15 01:08 jkotas

@jkotas Sounds great! Will this also be part of the Desktop version?

We are still struggling with some DLLs that does not work with NGEN, but "something" NGENs them, probably as a dependency. Is there a way to tell NGEN to not generate native images for a certain assembly, by attribute or maybe in DLLMain?

WebDancer69 avatar Aug 27 '15 21:08 WebDancer69

Closing this 2-year old issue since we don't plan to document or provide tools for parsing the Ngen binary format.

nattress avatar Jan 25 '18 22:01 nattress