[英]Raise an exception when an address is executed without modifying it directly
I would like to raise an exception when code at a given address is executed, without making it visible in the code. 我想在执行给定地址的代码时引发异常,而不会使其在代码中可见。
I know that using a hardware breakpoint is a possibility, but these would get removed if someone were to attach a debugger that uses them and I wouldn't have a way of detecting if they are missing and replacing them. 我知道使用硬件断点是可能的,但是如果有人要附加使用它们的调试器,这些断点将被删除,而我将无法检测到它们是否丢失并更换它们。 What other options are there?
还有什么其他选择?
Speed is a concern, ie: I cannot do PAGE_GUARD single stepping; 速度是一个问题,即:我无法执行PAGE_GUARD单步执行; the user would lag to death.
用户将死于死亡。
I'm on Windows and using VC 2012 w/ C++. 我在Windows上并使用带有C ++的VC 2012。
If exception handling is too costly, the only other solution is to emulate the code as the CPU would do. 如果异常处理的成本太高,则唯一的解决方案是像CPU一样模拟代码。
There are a few caveats, though: 但是,有一些警告:
Another, perhaps more practical, option would be to patch the executable at that address of interest, divert execution to your code (with the jmp
instruction), do whatever you need there and then go back. 另一个可能更实际的选择是在该目标地址处修补可执行文件,将执行转移到您的代码中(使用
jmp
指令),在其中执行所需的任何操作,然后返回。 You'll have to take care of all context preservation/restoration and also emulate the instructions damaged by the jmp
instruction written on top of them. 您将必须注意所有上下文的保存/恢复,并模拟被其上写的
jmp
指令损坏的指令。 There are caveats here as well. 这里也有一些警告。 Those overwritten instructions may be jumped to from elsewhere in the code.
这些被覆盖的指令可能会从代码中的其他地方跳转到。 You'll have to either choose the address in such a way that there're no jumps into the middle of your
jmp
or you'll have to deal with them somehow (not sure how yet). 您必须以一种不会跳到
jmp
中间的方式选择地址,或者必须以某种方式处理它们(不确定如何)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.