I'm using the unmanaged .NET API and have come to the point where I want to obtain the CIL bytecode for a method. The IMetaDataImport interface can provide me with the RVA of the method implementation, but not the actual memory location as far as I've seen.
Is there a way to obtain the information without having to parse the PE headers myself? I know it's not so hard to do, but IMetaDataImport has already done it so that would be duplicating work.
If I really do have to parse the PE headers myself, can I obtain the HMODULE used by my IMetaDataImport instance or do I have to memory-map the file myself and call OpenScopeFromMemory to create my IMetaDataImport instance?
The last time I worked with this API there was no built-in functionality for mapping an RVA to an actual address. So yes, you have to map the file into memory yourself and parse the section table to find the section your RVA is in and read the base offset out of that. That value can then be added to your mapped image pointer to get to where the code is located in your memory mapping.