Esempio n. 1
0
/// <summary>This is the body of our method marked with the SecuritySafeCriticalAttribute</summary>
/// <remarks>Calls the method that is marked with the SecurityCriticalAttribute</remarks>
HRESULT CCodeCoverage::AddSafeCuckooBody(ModuleID moduleId)
{
    ATLTRACE(_T("::AddSafeCuckooBody => Adding SafeVisited..."));

    BYTE data[] = {(0x01 << 2) | CorILMethod_TinyFormat, CEE_RET};
    Method criticalMethod((IMAGE_COR_ILMETHOD*)data);
    InstructionList instructions;
    instructions.push_back(new Instruction(CEE_LDARG_0));
    instructions.push_back(new Instruction(CEE_CALL, m_cuckooCriticalToken));

    criticalMethod.InsertInstructionsAtOffset(0, instructions);
    criticalMethod.DumpIL();

    CComPtr<IMethodMalloc> methodMalloc;
    COM_FAIL_RETURNMSG(m_profilerInfo->GetILFunctionBodyAllocator(moduleId, &methodMalloc), 
        _T("    ::AddSafeCuckooBody => SetILFunctionBody(0x%x)"));

    void* pMethodBody = methodMalloc->Alloc(criticalMethod.GetMethodSize());
    criticalMethod.WriteMethod((IMAGE_COR_ILMETHOD*)pMethodBody);

    COM_FAIL_RETURNMSG(m_profilerInfo->SetILFunctionBody(moduleId, 
        m_cuckooSafeToken, (LPCBYTE)pMethodBody), 
        _T("    ::AddSafeCuckooBody => SetILFunctionBody(0x%x)"));

    ATLTRACE(_T("::AddSafeCuckooBody => Adding SafeVisited - Done!"));

    return S_OK;
}
/// <summary>This is the method marked with the SecurityCriticalAttribute</summary>
/// <remarks>This method makes the call into the profiler</remarks>
HRESULT CCodeCoverage::AddCriticalCuckooBody(ModuleID moduleId)
{
	ATLTRACE(_T("::AddCriticalCuckooBody => Adding VisitedCritical..."));

	mdSignature pvsig = GetMethodSignatureToken_I4(moduleId);
	void(__fastcall *pt)(ULONG) = GetInstrumentPointVisit();

	BYTE data[] = { (0x01 << 2) | CorILMethod_TinyFormat, CEE_RET };
	Method criticalMethod((IMAGE_COR_ILMETHOD*)data);
	InstructionList instructions;
	instructions.push_back(new Instruction(CEE_LDARG_0));
#if _WIN64
	instructions.push_back(new Instruction(CEE_LDC_I8, (ULONGLONG)pt));
#else
	instructions.push_back(new Instruction(CEE_LDC_I4, (ULONG)pt));
#endif
	instructions.push_back(new Instruction(CEE_CALLI, pvsig));

	criticalMethod.InsertInstructionsAtOffset(0, instructions);
	//criticalMethod.DumpIL();

	InstrumentMethodWith(moduleId, m_cuckooCriticalToken, instructions);

	ATLTRACE(_T("::AddCriticalCuckooBody => Adding VisitedCritical - Done!"));

	return S_OK;
}
/// <summary>This is the body of our method marked with the SecuritySafeCriticalAttribute</summary>
/// <remarks>Calls the method that is marked with the SecurityCriticalAttribute</remarks>
HRESULT CCodeCoverage::AddSafeCuckooBody(ModuleID moduleId)
{
	ATLTRACE(_T("::AddSafeCuckooBody => Adding SafeVisited..."));

	BYTE data[] = { (0x01 << 2) | CorILMethod_TinyFormat, CEE_RET };
	Method criticalMethod((IMAGE_COR_ILMETHOD*)data);
	InstructionList instructions;
	instructions.push_back(new Instruction(CEE_LDARG_0));
	instructions.push_back(new Instruction(CEE_CALL, m_cuckooCriticalToken));

	criticalMethod.InsertInstructionsAtOffset(0, instructions);
	//criticalMethod.DumpIL();

	InstrumentMethodWith(moduleId, m_cuckooSafeToken, instructions);

	ATLTRACE(_T("::AddSafeCuckooBody => Adding SafeVisited - Done!"));

	return S_OK;
}
Esempio n. 4
0
/// <summary>This is the method marked with the SecurityCriticalAttribute</summary>
/// <remarks>This method makes the call into the profiler</remarks>
HRESULT CCodeCoverage::AddCriticalCuckooBody(ModuleID moduleId)
{
    ATLTRACE(_T("::AddCriticalCuckooBody => Adding VisitedCritical..."));

    // our profiler hook
    mdSignature pvsig = GetMethodSignatureToken_I4(moduleId);
    void (__fastcall *pt)(ULONG) = &InstrumentPointVisit ;

    BYTE data[] = {(0x01 << 2) | CorILMethod_TinyFormat, CEE_RET};
    Method criticalMethod((IMAGE_COR_ILMETHOD*)data);
    InstructionList instructions;
    instructions.push_back(new Instruction(CEE_LDARG_0));
#if _WIN64
    instructions.push_back(new Instruction(CEE_LDC_I8, (ULONGLONG)pt));
#else
    instructions.push_back(new Instruction(CEE_LDC_I4, (ULONG)pt));
#endif
    instructions.push_back(new Instruction(CEE_CALLI, pvsig));

    criticalMethod.InsertInstructionsAtOffset(0, instructions);
    criticalMethod.DumpIL();

    CComPtr<IMethodMalloc> methodMalloc;
    COM_FAIL_RETURNMSG(m_profilerInfo->GetILFunctionBodyAllocator(moduleId, &methodMalloc), 
        _T("    ::AddCriticalCuckooBody => Failed GetILFunctionBodyAllocator(0x%x)"));

    void* pMethodBody = methodMalloc->Alloc(criticalMethod.GetMethodSize());
    criticalMethod.WriteMethod((IMAGE_COR_ILMETHOD*)pMethodBody);

    COM_FAIL_RETURNMSG(m_profilerInfo->SetILFunctionBody(moduleId, 
        m_cuckooCriticalToken, (LPCBYTE)pMethodBody), 
        _T("    ::AddCriticalCuckooBody => SetILFunctionBody(0x%x)"));

    ATLTRACE(_T("::AddCriticalCuckooBody => Adding VisitedCritical - Done!"));

    return S_OK;
}