本文整理汇总了C++中PIN_GetContextReg函数的典型用法代码示例。如果您正苦于以下问题:C++ PIN_GetContextReg函数的具体用法?C++ PIN_GetContextReg怎么用?C++ PIN_GetContextReg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PIN_GetContextReg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: REPLACE_Replaced
int REPLACE_Replaced(CONTEXT *context, THREADID tid, AFUNPTR func)
{
int ret;
printf("Calling replaced Replaced()\n");
CONTEXT writableContext, *ctxt;
if (KnobUseIargConstContext)
{ // need to copy the ctxt into a writable context
PIN_SaveContext(context, &writableContext);
ctxt = &writableContext;
}
else
{
ctxt = context;
}
PIN_SetContextReg(ctxt, scratchReg, 1);
printf("REPLACE_Replaced: REG_INST_G0=0x%x\n", PIN_GetContextReg(ctxt, scratchReg));
PIN_CallApplicationFunction(ctxt, tid, CALLINGSTD_DEFAULT, func,
PIN_PARG(int), &ret,
PIN_PARG_END());
printf("REPLACE_Replaced: REG_INST_G0=0x%x\n", PIN_GetContextReg(ctxt, scratchReg));
printf("Returning from replaced Replaced()\n");
return ret;
}
示例2: ThreadStart
VOID ThreadStart( THREADID tid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
ADDRINT rsp = PIN_GetContextReg(ctxt, REG_STACK_PTR);
ADDRINT eip = PIN_GetContextReg(ctxt, REG_INST_PTR);
OutFile << dec << tid << hex<< " NTH " << eip << " " << rsp << endl;
}
示例3: printRegisterDiffs
static VOID printRegisterDiffs(THREADID tid, CONTEXT *ctx, UINT32 where)
{
threadState * s = &threadStates[tid];
UINT32 seqNo = s->iCount;
CONTEXT * savedCtx = &s->context;
// Save the context if this was the first instruction
if (seqNo == 0)
PIN_SaveContext(ctx, savedCtx);
else
{
for (UINT32 i=0; i<sizeof(checkedRegisters)/sizeof(checkedRegisters[0]); i++)
{
REG r = checkedRegisters[i].regnum;
ADDRINT newValue = PIN_GetContextReg(ctx, r);
if (PIN_GetContextReg(savedCtx, r) != newValue)
{
if (where != 0)
{
out << "*** Instrumentation (" << dec << where << ") caused a change ";
}
out << dec << seqNo << ": " << checkedRegisters[i].name << " = " << hex << UINT32(newValue) << endl;
PIN_SetContextReg(savedCtx, r, newValue);
}
}
}
}
示例4: CheckPcBefore
static void CheckPcBefore (ADDRINT pcExpectedInstPtr,
CONTEXT *ctxt,
CONTEXT *constCtxt,
ADDRINT pcInstPtr, const char *dis)
{
ADDRINT pcCtxt = PIN_GetContextReg(ctxt, REG_INST_PTR);
ADDRINT pcConstCtxt = PIN_GetContextReg(constCtxt, REG_INST_PTR);
if (pcConstCtxt != pcCtxt)
{
haveError = TRUE;
Out << "***Error3 CONTEXT pc is 0x" << std::hex << pcCtxt << " at IPOINT_BEFORE " <<
" is not equal to CONST_CONTEXT pc 0x" << std::hex << pcConstCtxt << std::endl;
}
if (pcCtxt != pcExpectedInstPtr)
{
haveError = TRUE;
Out << "***Error3 CONTEXT pc is 0x" << std::hex << pcCtxt << " at IPOINT_BEFORE " <<
", but expected 0x" << std::hex << pcExpectedInstPtr <<
". PC of INS is 0x" << std::hex << pcExpectedInstPtr << ": " << dis << std::endl;
}
if (pcInstPtr != pcExpectedInstPtr)
{
haveError = TRUE;
Out << "***Error3 INST_PTR pc is 0x" << std::hex << pcInstPtr << " at IPOINT_BEFORE " <<
", but expected 0x" << std::hex << pcExpectedInstPtr << ": " << dis << std::endl;
}
}
示例5: Intercept
static BOOL Intercept(THREADID tid, DEBUGGING_EVENT eventType, CONTEXT *ctxt, VOID *)
{
if (eventType == DEBUGGING_EVENT_BREAKPOINT)
{
// When the child thread reaches the breakpoint in Breakpoint(), wait for the main
// thread to reach the One() function. If the main thread is not there yet, squash the
// breakpoint and move the PC back to the start of the Breakpoint() function. This will
// delay a while and then re-trigger the breakpoint.
//
ADDRINT pc = PIN_GetContextReg(ctxt, REG_INST_PTR);
if (pc == BreakpointLocation && !AllowBreakpoint)
{
PIN_SetContextReg(ctxt, REG_INST_PTR, BreakpointFunction);
GetLock(&Lock, 1);
std::cout << "Squashing breakpoint at 0x" << std::hex << pc << " on thread " << std::dec << tid << std::endl;
ReleaseLock(&Lock);
return FALSE;
}
GetLock(&Lock, 1);
std::cout << "Stopping at breakpoint at 0x" << std::hex << pc << " on thread " << std::dec << tid << std::endl;
ReleaseLock(&Lock);
return TRUE;
}
if (eventType == DEBUGGING_EVENT_ASYNC_BREAK)
{
// When the child thread triggers the breakpoint, we should be at the One() function.
// Change the PC to the Two() function, which is the point of this test. We want to
// make sure Pin properly handles the change of PC in this case.
//
ADDRINT pc = PIN_GetContextReg(ctxt, REG_INST_PTR);
if (pc == OneFunction)
{
PIN_SetContextReg(ctxt, REG_INST_PTR, TwoFunction);
GetLock(&Lock, 1);
std::cout << "Changing ASYNC BREAK PC to Two() on thread " << std::dec << tid << std::endl;
ReleaseLock(&Lock);
return TRUE;
}
// If the PC is not at the One() function, the child thread has probably hit some breakpoint
// other than the one at Breakpoint(). (E.g. an internal breakpoint set by GDB.) Don't
// change the PC in such a case.
//
GetLock(&Lock, 1);
std::cout << "ASYNC_BREAK at 0x" << std::hex << pc << " on thread " << std::dec << tid << std::endl;
ReleaseLock(&Lock);
return TRUE;
}
GetLock(&Lock, 1);
std::cout << "FAILURE: Unexpected debugging event type" << std::endl;
ReleaseLock(&Lock);
std::exit(1);
}
示例6: SyscallEntry
/*
* SyscallEntry
* Calls Sysbefore - syscall processor
*/
VOID SyscallEntry(THREADID threadIndex, CONTEXT *ctxt, SYSCALL_STANDARD std, VOID *v)
{
SysBefore(PIN_GetContextReg(ctxt, REG_INST_PTR),
PIN_GetSyscallNumber(ctxt, std),
PIN_GetSyscallArgument(ctxt, std, 0),
PIN_GetSyscallArgument(ctxt, std, 1),
PIN_GetSyscallArgument(ctxt, std, 2),
PIN_GetSyscallArgument(ctxt, std, 3),
PIN_GetSyscallArgument(ctxt, std, 4),
PIN_GetSyscallArgument(ctxt, std, 5),
PIN_GetContextReg(ctxt,REG_STACK_PTR));
}
示例7: After1WithContext
static VOID After1WithContext (ADDRINT ip,
ADDRINT repInsAddr,
CONTEXT * ctxt,
CONTEXT *constCtxt,
ADDRINT *constRefToIp
)
{
ADDRINT expectedIpAfter;
numCallsToAfter1WithContext++;
printf ("***After1WithContext# %d repInsAddr %p ip %p\n",//*constRefToIp %p\n",
numCallsToAfter1WithContext, (char *)repInsAddr, (char *)ip
//,(char *)constRefToIp,
//(char *)(*constRefToIp)
);
if (numCallsToAfter1WithContext == 2)
{ // see "Test different string comparison" in rep_ip_at_ipoint_after_app.c
expectedIpAfter = repInsAddr+GetInstructionLength(repInsAddr);
}
else
{
expectedIpAfter = repInsAddr;
}
if (ip != *constRefToIp)
{
printf ("Unexpcted diff between ip and *constRefToIp\n");
exit (1);
}
if (PIN_GetContextReg( ctxt, REG_INST_PTR )!=expectedIpAfter)
{
printf (" After1WithContext Unexpected IP in ctxt %p\n",
(char *)PIN_GetContextReg( ctxt, REG_INST_PTR ));
exit (1);
}
if (PIN_GetContextReg( constCtxt, REG_INST_PTR )!=expectedIpAfter)
{
printf (" After1WithContext Unexpected IP in constCtxt %p\n",
(char *)PIN_GetContextReg( constCtxt, REG_INST_PTR ));
exit (1);
}
if (expectedIpAfter!=ip)
{
printf (" After1WithContext Unexpected IP from REG_VALUE REG_INST_PTR %p\n", (char *)ip);
exit (1);
}
}
示例8: OnException
static VOID OnException(THREADID threadIndex,
CONTEXT_CHANGE_REASON reason,
const CONTEXT *ctxtFrom,
CONTEXT *ctxtTo,
INT32 info,
VOID *v)
{
if (!toolIsReadyForException && reason == CONTEXT_CHANGE_REASON_EXCEPTION)
{
fprintf (out, "See exception %d : info 0x%x from 0x%0x but this is not the exception we want to replay\n", exceptionCount, info,
PIN_GetContextReg(ctxtFrom, REG_INST_PTR));
return;
}
if (!foundReplayException)
{
fprintf (out, "Failed to instrument ReplayException!\n");
}
if (reason == CONTEXT_CHANGE_REASON_EXCEPTION)
{
if (exceptionCount++ == 0)
{
PIN_SaveContext (ctxtFrom, &savedFromContext);
PIN_SaveContext (ctxtTo, &savedToContext);
savedReason = info;
}
fprintf (out, "See exception %d : info 0x%x from 0x%0x\n", exceptionCount, info,
PIN_GetContextReg(ctxtFrom, REG_INST_PTR));
fflush(out);
if (exceptionCount == 2)
{
// Check that the second exception is the same as the first, at least to a first approximation.
if (info == savedReason &&
PIN_GetContextReg(ctxtFrom, REG_INST_PTR) == PIN_GetContextReg(&savedFromContext, REG_INST_PTR))
{
fprintf (out, "Second exception looks like a replay, good!\n");
fflush(out);
exit(0);
}
else
{
fprintf (out, "Second exception does not look like a replay, BAD!\n");
fflush(out);
exit(1);
}
}
}
}
示例9: doPause
VOID doPause(VOID * arg)
{
for (int i = 0; i < TIMES; i++)
{
while (stopFlag == false)
{
PIN_Sleep(10);
}
stopFlag = false;
printf("Threads to be stopped by internal thread %u\n", intTid);
fflush(stdout);
if (PIN_StopApplicationThreads(intTid))
{
UINT32 nThreads = PIN_GetStoppedThreadCount();
printf("Threads stopped by internal thread %u : %u\n", intTid, nThreads);
fflush(stdout);
for (UINT32 index = 0; index < nThreads; index++)
{
THREADID tid = PIN_GetStoppedThreadId(index);
const CONTEXT * ctxt = PIN_GetStoppedThreadContext(tid);
printf(" Thread %u, IP = %llx, icount = %llu\n", tid,
(long long unsigned int)PIN_GetContextReg(ctxt, REG_INST_PTR), icounter[tid]);
}
PIN_ResumeApplicationThreads(intTid);
printf("Threads resumed by internal thread %u\n", intTid);
fflush(stdout);
}
}
return;
}
示例10: OnThreadStart
// - retrive the stack base address
static VOID OnThreadStart(THREADID, CONTEXT *ctxt, INT32, VOID *){
ADDRINT stackBase = PIN_GetContextReg(ctxt, REG_STACK_PTR);
FilterHandler *filterH = FilterHandler::getInstance();
filterH->setStackBase(stackBase);
}
示例11: OnThreadStart
// - retrive the stack base address
static VOID OnThreadStart(THREADID, CONTEXT *ctxt, INT32, VOID *){
ADDRINT stackBase = PIN_GetContextReg(ctxt, REG_STACK_PTR);
ProcInfo *pInfo = ProcInfo::getInstance();
pInfo->addThreadStackAddress(stackBase);
pInfo->addThreadTebAddress();
//MYINFO("-----------------a NEW Thread started!--------------------\n");
}
示例12: PatchTimeoutSyscall
PostPatchFn PatchTimeoutSyscall(PrePatchArgs args) {
if (SkipTimeoutVirt(args)) return NullPostPatch;
int syscall = PIN_GetSyscallNumber(args.ctxt, args.std);
assert_msg(syscall == SYS_futex || syscall == SYS_epoll_wait || syscall == SYS_epoll_pwait || syscall == SYS_poll,
"Invalid timeout syscall %d", syscall);
FutexInfo fi = {0, 0};
if (syscall == SYS_futex) fi = PrePatchFutex(args.tid, args.ctxt, args.std);
if (PrePatchTimeoutSyscall(args.tid, args.ctxt, args.std, syscall)) {
ADDRINT prevIp = PIN_GetContextReg(args.ctxt, REG_INST_PTR);
ADDRINT timeoutArgVal = PIN_GetSyscallArgument(args.ctxt, args.std, getTimeoutArg(syscall));
return [syscall, prevIp, timeoutArgVal, fi](PostPatchArgs args) {
if (PostPatchTimeoutSyscall(args.tid, args.ctxt, args.std, syscall, prevIp, timeoutArgVal)) {
return PPA_USE_NOP_PTRS; // retry
} else {
if (syscall == SYS_futex) PostPatchFutex(args.tid, fi, args.ctxt, args.std);
return PPA_USE_JOIN_PTRS; // finish
}
};
} else {
if (syscall == SYS_futex) {
return [fi](PostPatchArgs args) {
PostPatchFutex(args.tid, fi, args.ctxt, args.std);
return PPA_NOTHING;
};
} else {
return NullPostPatch;
}
}
}
示例13: OnException
// this function verifies that the xmm regs in the ctxtFrom are as they were set in the app just before the
// exception occurs. Then it sets the xmm regs in the ctxtTo to a different value, finally it causes the
// execution to continue in the application function DumpXmmRegsAtException
static void OnException(THREADID threadIndex,
CONTEXT_CHANGE_REASON reason,
const CONTEXT *ctxtFrom,
CONTEXT *ctxtTo,
INT32 info,
VOID *v)
{
if (CONTEXT_CHANGE_REASON_SIGRETURN == reason || CONTEXT_CHANGE_REASON_APC == reason
|| CONTEXT_CHANGE_REASON_CALLBACK == reason || CONTEXT_CHANGE_REASON_FATALSIGNAL == reason
|| ctxtTo == NULL)
{ // don't want to handle these
return;
}
fprintf (stdout, "TOOL OnException callback\n");
fflush (stdout);
//PIN_SaveContext(ctxtFrom, ctxtTo);
CheckAndSetFpContextXmmRegs(ctxtFrom, ctxtTo);
// call the application function with the ctxtTo context
#ifdef TARGET_IA32E
PIN_SetContextReg(ctxtTo, REG_RIP, dumpXmmRegsAtExceptionAddr);
// take care of stack alignment since tool is redirecting execution flow to function
ADDRINT curSp = PIN_GetContextReg(ctxtTo, REG_RSP);
INT32 currentAlignment = curSp % 16;
PIN_SetContextReg(ctxtTo, REG_RSP, curSp - GetStackAdjustmentForRedirectionToFunction(currentAlignment));
#else
PIN_SetContextReg(ctxtTo, REG_EIP, dumpXmmRegsAtExceptionAddr);
#endif
}
示例14: safecast
// There is no verification on the validity of the ID.
uint64 PINContextHandler::getFlagValue(uint64 TritFlagID) const
{
uint64 rflags;
REG reg = safecast(PINConverter::convertTritonReg2DBIReg(ID_RFLAGS));
if (!REG_valid(reg))
throw std::runtime_error("Error: getFlagValue() - Invalid PIN register id.");
rflags = PIN_GetContextReg(this->_ctx, reg);
switch (TritFlagID){
case ID_AF: return (rflags >> 4) & 1;
case ID_CF: return (rflags & 1);
case ID_DF: return (rflags >> 10) & 1;
case ID_IF: return (rflags >> 9) & 1;
case ID_OF: return (rflags >> 11) & 1;
case ID_PF: return (rflags >> 2) & 1;
case ID_SF: return (rflags >> 7) & 1;
case ID_TF: return (rflags >> 8) & 1;
case ID_ZF: return (rflags >> 6) & 1;
default:
throw std::runtime_error("Error: getFlagValue() - Invalid Flag id.");
}
return 0;
}
示例15: OnIns
VOID OnIns(THREADID tid,
#if defined(TARGET_IA32) || defined(TARGET_IA32E)
CONTEXT *ctxt,
#endif
ADDRINT g0, ADDRINT g1, ADDRINT g2, ADDRINT g3, ADDRINT g4,
ADDRINT g5, ADDRINT g6, ADDRINT g7, ADDRINT g8, ADDRINT g9)
{
ADDRINT gx[10];
gx[0] = g0;
gx[1] = g1;
gx[2] = g2;
gx[3] = g3;
gx[4] = g4;
gx[5] = g5;
gx[6] = g6;
gx[7] = g7;
gx[8] = g8;
gx[9] = g9;
for (UINT32 r = 0; r <= 9; r++)
{
ADDRINT expect = BaseValue + tid + r;
if (expect != gx[r])
Error("on IARG_REG_VALUE", tid, r, expect, gx[r]);
#if defined(TARGET_IA32) || defined(TARGET_IA32E)
ADDRINT val = PIN_GetContextReg(ctxt, REG(REG_INST_G0 + r));
if (expect != val)
Error("on IARG_CONTEXT", tid, r, expect, val);
#endif
}
}