Last active
December 27, 2015 08:19
-
-
Save einarwh/7295906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void TamperWith( | |
MethodDefinition method, | |
IEnumerable<Instruction> calls) | |
{ | |
foreach (var call in calls) | |
{ | |
var il = method.Body.GetILProcessor(); | |
int counter = method.Parameters.Count; | |
while (counter > 0) | |
{ | |
var starg = il.Create(OpCodes.Starg, --counter); | |
il.InsertBefore(call, starg); | |
} | |
var start = method.Body.Instructions[0]; | |
var loop = il.Create(OpCodes.Br_S, start); | |
il.InsertBefore(call, loop); | |
il.Remove(call.Next); // Ret | |
il.Remove(call); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment