Skip to content

Conversation

@loco-choco
Copy link

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:

  1. Add Instruction(s) to the Target;
  2. Add the Indices/Index to the Target
  3. Set the bool var InsertInstructions to 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:
image
image

After the patch:
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant