当前位置: 首页>>代码示例>>C++>>正文


C++ AsmJitHelper::relocCode方法代码示例

本文整理汇总了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);
    }
开发者ID:CodeBlueDev,项目名称:Blackbone,代码行数:76,代码来源:VTableHook.hpp


注:本文中的AsmJitHelper::relocCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。