jmp什么情況下會超過0x7fff0000,?
最近在分析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)建一個跳轉(zhuǎn)到替換函數(shù)的存根。
//我們需要這個,,因?yàn)橹苯訌腁PI跳到鉤子
//將是一個遠(yuǎn)跳,在x64上是14字節(jié),,我們希望
//避免這種情況——API可能有空間也可能沒有空間容納這些東西,。
//(請記住,API中只保證有5個字節(jié),。)
//另一方面,,我們確實(shí)有空間,trampoline永遠(yuǎn)都是
//在API的2GB范圍內(nèi),,因此我們在那里進(jìn)行遠(yuǎn)跳,。
//API將跳轉(zhuǎn)到"reverse trampoline",其中
//將跳轉(zhuǎn)到用戶的鉤子代碼
//,。
內(nèi)存空間不是應(yīng)該是一共就是4GB嗎,,按理說一個跳轉(zhuǎn)的偏移無論如何也不會超過 +- 2GB把?