将例程的内容复制到内存中的另一个位置

发布于 2025-01-05 06:38:31 字数 742 浏览 5 评论 0原文

我想将内存中的例程代码复制到另一个位置。例如,假设

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

我想将例程复制到内存中的另一个位置。我已经声明了

var
  lopShowMessage : procedure; // procedural pointer.

一些伪代码,就像

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

我只是想知道是否有可能这样做。我已经修补了一个例程来调用新例程,但由于我们使用代码绕道放置了 JMP 指令,我可能无法使用旧例程中提供的功能。

我上一个问题的参考是此处

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˇ宁静的妩媚 2025-01-12 06:38:31

如果您阅读了 Detours 实际工作原理的技术细节,您将请注意,您可以通过使用蹦床作为绕行的一部分来利用旧例行程序。然后,只要您想调用旧例程,就可以调用蹦床。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文