This project is read-only.

Modifying Already Loaded Assembly

Topics: PDB Writer, PE Writer, Source Model
May 20, 2012 at 5:25 AM

I have started probing CCI for only a couple of days, so pardon my noob question: With CCI is it possible to modify an already loaded Assembly in memory? From the pe to pe sample code it appears you have to load the assembly from a file, make modifications and save to a file.

What I'm looking to do is scan assemblies already in memory, find the one I'm looking for (perhaps using standard reflection + linq C#) and pass a reference to this assembly to CCI. Then using the mutable model / CCI Code, locate a particular method within that assembly and insert a few lines of code in it.

I am not looking to save this change to disk and whenever the assembly unloads, the changes are lost, but there is code in the assembly to invoke this CCI logic every time it loads. This ensures that compiled assemblies aren't changed but 'aspects' get added on to them at runtime. The aspects are invoked through a .initialize() call that kicks off the process just described.

Is this scenario possible in CCI?