0

I want to copy the routine code in memory to another location. For e.g.

procedure OldShowMessage;
begin
  ShowMessage('Old message..');
end;

Say i want to copy the routine to another location in memory. I have declared something like

var
  lopShowMessage : procedure; // procedural pointer.

Some pseudo code would be like

// VirtualProtect(@OldShowMessage, <length of routine>, ..., ...);
// Allocate memory
// lopShowMessage := AllocMem(<length of routine>);
// Move(@OldMessage, Pointer(lopShowMessage)^, <length of routine>);
// FlushInstructioncache.....

I just want to know if there is any possibility of doing this. I have patched a routine to call a new routine, but since we place a JMP instruction using code detours, i may not be able to use the functionality provided in the old routine.

A reference for my previous question is here

Community
  • 1
  • 1
Rahul W
  • 833
  • 11
  • 26

1 Answers1

0

If you read up on the technical details of how Detours actually work, you will see that you can make use of the old routine by utilizing a trampoline as part of your detour. You can then call the trampoline whenever you want to invoke the old routine.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770