foo()
。我希望在每次调用foo()
时收到通知消息,但我不被允许更改其他人编写的任何源代码。我在互联网上搜索了几天,并找到了一些类似的问答,但这些建议都无法真正解决我的问题。我列出其中一些:
use
gcc -wrap
: Override a function call in C Thank god, I'm using Microsoft C compiler and linker, and I can't find an equivalent option as-wrap
.Microsoft Detours: Detours intercepts C calls in runtime and re-direct the call to a trampoline function. But Detours is only free for IA32 version, and it's not open source.
I'm thinking about injecting a jmp instruction at the start of function
foo()
to redirect it to my own function. However it's not feasible whenfoo()
is empty, likevoid foo() ---> will be compiled into 0xC3 (ret) { but it'll need at least 8 bytes to inject a jmp }
I found a technology named Hotpatch on MSDN. It says the linker will add serveral bytes of padding at the beginning of each function. That's great, because I can replace the padding bytes with jmp instruction to realize the interception in runtime! But when I use the /FUNCTIONPADMIN option with the linker, it gives me a warning:
LINK : warning LNK4044: unrecognized option '/FUNCTIONPADMIN'; ignored
Anybody could tell me how could I make a "hotpatchable" image correctly? Is it a workable solution for my question ?