Are there techniques for patching .net executables in memory? Let's say we've have a .net dll/exe, we identified what method we want to patch and what IL to replace the existing code with. Executing this on the binary file is easy (let's assume it does not have a strong name for simplicity). But what if we want to leave the file intact? Is it possible to make the patch in-memory? Maybe it is possible to write an exe loader that would intercept dll loading and re-write IL on the fly somehow?
The problem is that once the code is in memory it is no longer IL, but natively compiled, and thus, our knowledge of what method we want to patch with which IL does not help us a lot. So it looks like doing this during load time is the only way which might allow us not modifying the original files on disk. Is this possible?
Note: I'm especially interested in the case where the main program executable is not .net, but native, which loads .net dlls, such as in case with Unity3D player.