sinojelly / mockcpp

Two C/C++ testing tools, mockcpp and testngpp.
Apache License 2.0
66 stars 39 forks source link

Visual Studio 2019 API Hook doesn't work #18

Open sinojelly opened 3 years ago

sinojelly commented 3 years ago

The crashed tests are:

---------------------SUITE: TestApiHook---------------------

(ApiHook)
[  ERROR   ] can mock C function - TestApiHook.h:66: hardware exception STATUS_ACCESS_VIOLATION raised in setup or running test
[  ERROR   ] can mock C function - TestApiHook.h:66: hardware exception STATUS_ACCESS_VIOLATION raised in teardown
-------------------SUITE: TestApiHookBase-------------------

(ApiHookBase)
[  ERROR   ] can mock C function with no return and no parameter - TestApiHookBase.h:148: hardware exception STATUS_PRIVILEGED_INSTRUCTION raised in setup or running test
[  ERROR   ] can mock C function with no return and no parameter - TestApiHookBase.h:148: hardware exception STATUS_PRIVILEGED_INSTRUCTION raised in teardown
-----------------SUITE: TestApiHookStdcall------------------

(ApiHookStdcall)
[  ERROR   ] can mock stdcall C function - TestApiHookStdcall.h:60: hardware exception STATUS_ACCESS_VIOLATION raised in setup or running test
[  ERROR   ] can mock stdcall C function - TestApiHookStdcall.h:60: hardware exception STATUS_ACCESS_VIOLATION raised in teardown

The API Hook actually modifies a few bytes at the entry of the function to a jmp instruction that jumps to another stub function. VS 2019 does not work in this way, probably because of adding a new protection to the code segment. If you have any information, you are welcome to provide clues or submit a PR.

API Hook 实际上是修改了代码段函数入口处的几个字节,把它改成了跳转到另外一个stub函数的jmp指令。VS 2019这种方式不可工作,可能是对代码段的修改增加了新的保护措施。如果有人了解相关信息,欢迎提供线索或者提交PR。