Hi,
Introduction
********************
I am writing some kind pf an assembly linker, this linker should be able to
work with an already compiled assembly, e.g. add several global methods,
To achieve that I use the unmanaged reflection COM interface e.g. ICeeFileGen,
IMetaDataEmit, ...
The problem
********************
Taking in mind what was just said, I am using the ICeeFileGen 'object' to create an identical copy of an existing assembly:
1. use IMetaDataDispenserEx->OpenScope To open an existing assembly.
2. Get a IMetaDataEmit for that assembly
3. use ICeeFileGen->CreateCeeFile to create a new file
4. Configures output file ( e.g. name, ... )
5. ICeeFileGen->LinkCeeFile
6. call FileGen->EmitMetaDataEx(IMetaDataEmit)
7. Add some propriotay methods
8. call ICeeFileGen->LinkCeeFile again
9. FileGen->GenerateCeeFile
10.FileGen->DestroyCeeFile
When using 'ildasm.exe' on the new assembly generated I can see that the methods of the original assembly has no MSIL implementation, it seems that calling FileGen->EmitMetaDataEx(IMetaDataEmit) doesn't ‘link’ the MSIL code provided for the original assembly, to achieve MSIL code duplication I have to do the following:
1. Enumerate through the original
assembly methods
2. Get the RVA of each method
3. Allocate memory for the code
segment on the new Assembly
through the ICeeFileGen interface
4. Copy the MSIL code from the
source assembly to the destination
assembly.
5. Set the destination RVA in the
new assembly metadata.
(*) Is there any way to avoid the manual copying of MSIL described above? is it possible to copy the method MSIL in the same manner it's metadata is copied?
Any comments samples or pointers will be appreciated.
--
Nadav
http://www.ddevel.com