Search code examples
c#.netwindowsclrapi-hook

How to intercept/overwrite function calls in a .net executable?


I would like to intercept CLR function calls in a .net executable (3rd party executable which i do not have access to the source code) for debugging purposes. I have been looking at some hooking apis (deviare, easyhook, mhook) etc but i think they only support hooking into simple functions in a dll such as xxx.dll!functionname and not capable of logging constructor calls on objects etc. I would like to know if they are any libs that are capable of easily logging function calls in a .net executable such as if a process calls the function File.ReadAllText(@"C:\name.txt"); i would log the function File.ReadAllText with the arguments c:\name.txt.

Here are some things i have tried/looked at but didn't do what i wanted.

Deviare

Mhook

EasyHooks

Microsoft Moles

Redgate Ants Profiler (This one is really close. it logs all the clr functions calls , i just need it to log the arguments. If you know how that would pretty much solve my problem)


Solution

  • If it's a .net executable and you have the legal rights to modify it, you can use reflector with a modifying plugin to change anything in the source code and recompile it.