I've been looking at some of the articles for the CLR Profiling API, and many of those articles talk about calling SetILFunctionBody() to do the actual IL rewriting; however, none of those articles actually explain exactly what you could use to rewrite the actual method IL bytes. Is there an unmanaged library out there that allows me to write IL, or would I have to write one myself?
Probably. It depends.
The Mono Project has a library called Cecil, which you can access here:
http://mono-project.com/Cecil
However it's managed code, which you can't call while profiling. You may a have a few options though:
#1 introduces a bunch of extra complexity. Your profiler would end up having more moving parts than it really needed. Also, the IPC introduces a bunch of extra overhead.
#2 would take a long time. Given that Cecil is still only at version 0.6, it might not be worth the time to do it, vs writing your own implementation.
#3 would give you the greatest degree of control, and would probably be the most performant. However it would take substantially more effort than #1 would.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With