首頁
社區(qū)
課程
招聘
jmp什么情況下會超過0x7fff0000?
sanqiu 2021-8-13 1528

最近在分析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.
我?guī)拖伦隽艘韵路g,但是還是沒看懂。。。。。。。。。
//創(chuàng)建一個跳轉到替換函數(shù)的存根。
//我們需要這個,因為直接從API跳到鉤子
//將是一個遠跳,在x64上是14字節(jié),我們希望
//避免這種情況——API可能有空間也可能沒有空間容納這些東西。
//(請記住,API中只保證有5個字節(jié)。)
//另一方面,我們確實有空間,trampoline永遠都是
//在API的2GB范圍內,因此我們在那里進行遠跳。
//API將跳轉到"reverse trampoline",其中
//將跳轉到用戶的鉤子代碼
//。
內存空間不是應該是一共就是4GB嗎,按理說一個跳轉的偏移無論如何也不會超過 +- 2GB把?

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

兩個PBYTE相減得到的結果可能大于2GB不是很正常?且不說x64上出現(xiàn)地址相差超過2GB的情況,哪怕是x86也可能出現(xiàn)0xF0000000-0x01000000>2GB這種啊

回復
sanqiu: 你的意思是說,可以直接從內核函數(shù)jmp到應用層來實現(xiàn)inline  hook嗎
回復 2021-8-13
hzqst: 誰告訴你的0xF0000000就一定是內核地址了?
回復 2021-8-14