/// <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; }
void CCodeCoverage::InstrumentMethod(ModuleID moduleId, Method& method, std::vector<SequencePoint> seqPoints, std::vector<BranchPoint> brPoints) { if (m_useOldStyle) { mdSignature pvsig = GetMethodSignatureToken_I4(moduleId); void(__fastcall *pt)(ULONG) = GetInstrumentPointVisit(); InstructionList instructions; if (seqPoints.size() > 0) CoverageInstrumentation::InsertFunctionCall(instructions, pvsig, (FPTR)pt, seqPoints[0].UniqueId); if (method.IsInstrumented(0, instructions)) return; CoverageInstrumentation::AddBranchCoverage([pvsig, pt](InstructionList& instructions, ULONG uniqueId)->Instruction* { return CoverageInstrumentation::InsertFunctionCall(instructions, pvsig, (FPTR)pt, uniqueId); }, method, brPoints, seqPoints); CoverageInstrumentation::AddSequenceCoverage([pvsig, pt](InstructionList& instructions, ULONG uniqueId)->Instruction* { return CoverageInstrumentation::InsertFunctionCall(instructions, pvsig, (FPTR)pt, uniqueId); }, method, seqPoints); } else { mdMethodDef injectedVisitedMethod = RegisterSafeCuckooMethod(moduleId); InstructionList instructions; if (seqPoints.size() > 0) CoverageInstrumentation::InsertInjectedMethod(instructions, injectedVisitedMethod, seqPoints[0].UniqueId); if (method.IsInstrumented(0, instructions)) return; CoverageInstrumentation::AddBranchCoverage([injectedVisitedMethod](InstructionList& instructions, ULONG uniqueId)->Instruction* { return CoverageInstrumentation::InsertInjectedMethod(instructions, injectedVisitedMethod, uniqueId); }, method, brPoints, seqPoints); CoverageInstrumentation::AddSequenceCoverage([injectedVisitedMethod](InstructionList& instructions, ULONG uniqueId)->Instruction* { return CoverageInstrumentation::InsertInjectedMethod(instructions, injectedVisitedMethod, uniqueId); }, method, seqPoints); } }