本文整理汇总了C++中AsmJitHelper::relocCode方法的典型用法代码示例。如果您正苦于以下问题:C++ AsmJitHelper::relocCode方法的具体用法?C++ AsmJitHelper::relocCode怎么用?C++ AsmJitHelper::relocCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsmJitHelper
的用法示例。
在下文中一共展示了AsmJitHelper::relocCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Hook
/// <summary>
/// Hook function in vtable
/// </summary>
/// <param name="ppVtable">Pointer to vtable pointer</param>
/// <param name="index">Function index</param>
/// <param name="hkPtr">Hook function address</param>
/// <param name="copyVtable">if true, vtable will be copied and edited, otherwise existing vtable will be edited</param>
/// <param name="vtableLen">Optional. Valid only when copyVtable is true. Number of function in vtable.
/// Used to determine number of function to copy</param>
/// <returns>true on success</returns>
bool Hook( void** ppVtable, int index, hktype hkPtr, bool copyVtable = false, int vtableLen = 0 )
{
AsmJitHelper jmpToHook;
//_order = CallOrder::HookFirst;
//_retType = ReturnMethod::UseOriginal;
this->_type = HookType::VTable;
this->_callOriginal = this->_original = (*(void***)ppVtable)[index];
this->_callback = hkPtr;
this->_internalHandler = &HookHandler<Fn, C>::Handler;
this->_ppVtable = ppVtable;
this->_pVtable = *ppVtable;
this->_vtIndex = index;
this->_vtCopied = copyVtable;
// Construct jump to hook handler
#ifdef USE64
// mov gs:[0x28], this
jmpToHook->mov( asmjit::host::rax, (uint64_t)this );
jmpToHook->mov( asmjit::host::qword_ptr_abs( 0x28 ).setSegment( asmjit::host::gs ), asmjit::host::rax );
#else
// mov fs:[0x14], this
jmpToHook->mov( asmjit::host::dword_ptr_abs( 0x14 ).setSegment( asmjit::host::fs ), (uint32_t)this );
#endif // USE64
jmpToHook->jmp( (asmjit::Ptr)this->_internalHandler );
jmpToHook->relocCode( this->_buf );
// Modify VTable copy
if (copyVtable)
{
uintptr_t ccpad;
memset( &ccpad, 0xCC, sizeof(ccpad) );
// Copy VTable
if (vtableLen != 0)
{
memcpy( this->_buf + 0x300, *ppVtable, vtableLen * sizeof( void* ) );
}
else for (;; vtableLen++)
{
if ((*(void***)ppVtable)[vtableLen] == nullptr ||
(*(void***)ppVtable)[vtableLen] == (void**)ccpad)
{
memcpy( this->_buf + 0x300, *ppVtable, vtableLen * sizeof( void* ) );
break;
}
}
// Replace pointer to VTable
((void**)this->_buf + 0x300 / sizeof( uintptr_t ))[index] = this->_buf;
*ppVtable = this->_buf + 0x300;
}
// Modify pointer in-place
else
{
DWORD flOld = 0;
VirtualProtect( *(uintptr_t**)ppVtable + index, sizeof(void*), PAGE_EXECUTE_READWRITE, &flOld );
(*(void***)ppVtable)[index] = this->_buf;
VirtualProtect( *(uintptr_t**)ppVtable + index, sizeof(void*), flOld, &flOld );
}
return (this->_hooked = true);
}