Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instruction inserting #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

1 participant