I can get at the method body easily enough using reflection
Type type = assembly.GetType("Lorem.Ipsum.Dolor.Sit");
MethodInfo methodInfo = type.GetMethod("Amet");
MethodBody methodBody = methodInfo.GetMethodBody();
How can I programatically change the method body and save my changes back to disk?
AFAIK, you can't.
With reflection you modified an in-memory object which was produced from a binary loaded and optimized by the CLR at runtime.
EDIT
This question has some more information on this.
Modifying Existing .NET Assemblies
One another good lib for this: https://bitbucket.org/0xd4d/dnlib
Handles obfuscated assemblies much better comparing to Mono.Cecil.
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