我需要劫持我自己进程的所有操作系统调用。我无法重写代码,因为它部分不是我的代码(插件)。我需要能够在特定系统调用的实现中决定是否要调用原始实现。
操作系统首先是Windows XP及更高版本。稍后将推出 os x 10.5 及更高版本。从 Windows 上开始使用 32 位版本,后来所有操作系统也使用 64 位版本。
我找到了很多有关挂钩其他进程的文档和工具,但我希望我的工作更简单,并且我希望有一些源代码。
预先非常感谢,贝恩德。
I need to hijack all operating system calls of my own process. I cannot rewrite code as it is partly not my code (plug-ins). I need to be able to decide within my implementation of a specific system call, if I want to call the original implementation or not.
Operating systems will be at first windows xp and higher versions. Later os x 10.5 and higher will follow. Starting on windows with 32 bit versions, later for all operating systems also 64 bit versions.
I found a lot of documentation and tools about hooking other processes but I would hope my job is much simpler and I would hope for some source code.
Thanks a lot in advance, Bernd.
发布评论
评论(3)
有许多挂钩库可以让您执行此操作,例如 Windows 上的 Detours 或 madCodeHook。毫无疑问,OSX 上也有类似的库,只是我不知道它们!
挂钩例程并将其替换为您自己的实现非常容易。在某些情况下,保留运行原始例程的选项并不容易,而这就是使用挂钩库将为您减轻痛苦的地方。
There are many hooking libraries that will let you do this, for example Detours or madCodeHook on Windows. No doubt there are similar libraries on OSX, I just don't know them!
It's very easy to hook a routine and replace it with your own implementation. It's less easy to retain the option of running the original routine in some circumstances, and that's where using a hooking library will take the pain away for you.
在 Mac OS X 上,您可以使用
DYLD_INTERPOSE
宏(以及DYLD_INSERT_LIBRARIES
(如果需要)。这个答案有一个例子: 使用 dlsym 的 Ansi C 补丁在 Linux 下编译正常,但在 Mac Os X 上失败On Mac OS X, you can override functions with the
DYLD_INTERPOSE
macro (andDYLD_INSERT_LIBRARIES
, if needed). This answer has an example: Ansi C patch using dlsym compiles OK under linux but fails on Mac Os X对于 Windows,有一个名为 EasyHook 的 Microsoft Detours 的开源替代方案:
For Windows, there is the open source alternative to Microsoft Detours called EasyHook: