dnpatch
dnpatch copied to clipboard
Add instruction inserting
Added so targets can now be inserted while patching.
To insert instructions you have to follow a similar path of replacing them at a given index:
- Add
Instruction(s)to theTarget; - Add the
Indices/Indexto theTarget - Set the bool var
InsertInstructionsto true (which defaults to false so it is compatible with codes from before this change)
Instruction[] insertingOpCodes = {
Instruction.Create(OpCodes.Ldstr, "Hello Sir"), // String to print
Instruction.Create(OpCodes.Call, p.BuildCall(typeof(Console), "WriteLine", typeof(void), new[] { typeof(string) })), // Console.WriteLine call
};
Target insertingTarget = new Target()
{
Namespace = "Test",
Class = "Program",
Method = "Print",
Instructions = insertingOpCodes,
Indices = new[] { 3, 4 }, // Insert instructions at given index
InsertInstructions = true // Tells the patcher to insert and not replace
};
p.Patch(insertingTarget);
p.Save("Test15.exe");
Before the patch:

After the patch:
