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


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

本文整理汇总了C++中AsmJitHelper::emit方法的典型用法代码示例。如果您正苦于以下问题:C++ AsmJitHelper::emit方法的具体用法?C++ AsmJitHelper::emit怎么用?C++ AsmJitHelper::emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AsmJitHelper的用法示例。


在下文中一共展示了AsmJitHelper::emit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateVEH

/// <summary>
/// Inject VEH wrapper into process
/// Used to enable execution of SEH handlers out of image
/// </summary>
/// <param name="pTargetBase">Target image base address</param>
/// <param name="imageSize">Size of the image</param>
/// <returns>Error code</returns>
NTSTATUS MExcept::CreateVEH( size_t pTargetBase, size_t imageSize )
{    
    AsmJitHelper ea;
    uint64_t result = 0;
    
    // VEH codecave
    _pVEHCode = _proc.memory().Allocate( 0x2000 );
    _pVEHCode.Release();
    if (!_pVEHCode.valid())
        return LastNtStatus();

#ifdef USE64 
    asmjit::Label lExit = ea->newLabel();

    //
    // Assembly code for VectoredHandler64
    // 0x10 - EXCEPTION_RECORD.ExceptionAddress
    // 0x20 - EXCEPTION_RECORD.ExceptionInformation[0]
    // 0x30 - EXCEPTION_RECORD.ExceptionInformation[2]
    // 0x38 - EXCEPTION_RECORD.ExceptionInformation[3]
    //
    ea->mov( asmjit::host::rax, qword_ptr( asmjit::host::rcx ) );
    ea->cmp( asmjit::host::dword_ptr( asmjit::host::rax ), EH_EXCEPTION_NUMBER );
    ea->jne( lExit );
    ea->mov( asmjit::host::rdx, pTargetBase );
    ea->mov( asmjit::host::r8, asmjit::host::qword_ptr( asmjit::host::rax, 0x30 ) );
    ea->cmp( asmjit::host::r8, asmjit::host::rdx );;
    ea->jl( lExit );
    ea->add( asmjit::host::rdx, imageSize );
    ea->cmp( asmjit::host::r8, asmjit::host::rdx );;
    ea->jg( lExit );
    ea->cmp( asmjit::host::qword_ptr( asmjit::host::rax, 0x20 ), EH_PURE_MAGIC_NUMBER1 );;
    ea->jne( lExit );
    ea->cmp( asmjit::host::qword_ptr( asmjit::host::rax, 0x38 ), 0 );
    ea->jne( lExit );
    ea->mov( asmjit::host::qword_ptr( asmjit::host::rax, 0x20 ), EH_MAGIC_NUMBER1 );
    ea->mov( asmjit::host::rcx, qword_ptr( asmjit::host::rcx ) );
    ea->mov( asmjit::host::rdx, pTargetBase );
    ea->mov( asmjit::host::qword_ptr( asmjit::host::rax, 0x38 ), asmjit::host::rdx );
    ea->bind( lExit );
    ea->xor_( asmjit::host::rax, asmjit::host::rax );
    ea->ret();
    ea->emit( 0xCC );
    ea->emit( 0xCC );
    ea->emit( 0xCC );

    if (_pVEHCode.Write( 0, ea->getCodeSize(), ea->make() ) != STATUS_SUCCESS)
    {
        _pVEHCode.Free();
        return LastNtStatus();
    }
#else
    UNREFERENCED_PARAMETER( pTargetBase );
    UNREFERENCED_PARAMETER( imageSize );

    // Resolve compiler incremental table address if any
    void *pFunc = ResolveJmp( &VectoredHandler );
    size_t fnSize = static_cast<size_t>(SizeOfProc( pFunc ));
    size_t dataOfs = 0, code_ofs = 0;

    // Find and replace magic values
    for (uint8_t *pData = reinterpret_cast<uint8_t*>(pFunc);
          pData < reinterpret_cast<uint8_t*>(pFunc) + fnSize - 4; 
          pData++)
    {
        // LdrpInvertedFunctionTable
        if(*(size_t*)pData == 0xDEADDA7A)
        {
            dataOfs = pData - reinterpret_cast<uint8_t*>(pFunc);
            continue;
        }

        // DecodeSystemPointer address
        if(*(size_t*)pData == 0xDEADC0DE)
        {
            code_ofs = pData - reinterpret_cast<uint8_t*>(pFunc);
            break;
        }  
    }

    // Write handler data into target process
    if (_pVEHCode.Write( 0, fnSize, pFunc ) != STATUS_SUCCESS ||
         _pVEHCode.Write( dataOfs, _proc.nativeLdr().LdrpInvertedFunctionTable() ) != STATUS_SUCCESS ||
         _pVEHCode.Write( code_ofs, &DecodeSystemPointer ) != STATUS_SUCCESS)
    {
        _pVEHCode.Free();
        return LastNtStatus();
    }

#endif

    ea.GenPrologue();

//.........这里部分代码省略.........
开发者ID:qiaohang,项目名称:Blackbone,代码行数:101,代码来源:MExcept.cpp


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