首页
社区
课程
招聘
jmp什么情况下会超过0x7fff0000?
sanqiu 2021-8-13 1366

最近在分析mhook,这是个inlinehook库,虽然是2013年一个外国人写的,但是有分析价值,其中有一段代码

 

DWORD_PTR dwDistance = (PBYTE)pHookFunction < (PBYTE)pSystemFunction ? (PBYTE)pSystemFunction - (PBYTE)pHookFunction : (PBYTE)pHookFunction - (PBYTE)pSystemFunction;
if (dwDistance > 0x7fff0000) {}
作者的写下了如下解析
// create a stub that jumps to the replacement function.
// we need this because jumping from the API to the hook directly
// will be a long jump, which is 14 bytes on x64, and we want to
// avoid that - the API may or may not have room for such stuff.
// (remember, we only have 5 bytes guaranteed in the API.)
// on the other hand we do have room, and the trampoline will always be
// within 2GB of the API, so we do the long jump in there.
// the API will jump to the "reverse trampoline" which
// will jump to the user's hook code.
我帮下做了以下翻译,但是还是没看懂。。。。。。。。。
//创建一个跳转到替换函数的存根。
//我们需要这个,因为直接从API跳到钩子
//将是一个远跳,在x64上是14字节,我们希望
//避免这种情况——API可能有空间也可能没有空间容纳这些东西。
//(请记住,API中只保证有5个字节。)
//另一方面,我们确实有空间,trampoline永远都是
//在API的2GB范围内,因此我们在那里进行远跳。
//API将跳转到"reverse trampoline",其中
//将跳转到用户的钩子代码
//。
内存空间不是应该是一共就是4GB吗,按理说一个跳转的偏移无论如何也不会超过 +- 2GB把?

收藏
1条回答
hzqst 2021-8-13

两个PBYTE相减得到的结果可能大于2GB不是很正常?且不说x64上出现地址相差超过2GB的情况,哪怕是x86也可能出现0xF0000000-0x01000000>2GB这种啊

回复
sanqiu: 你的意思是说,可以直接从内核函数jmp到应用层来实现inline  hook吗
回复 2021-8-13
hzqst: 谁告诉你的0xF0000000就一定是内核地址了?
回复 2021-8-14