EveryOne。我有一个项目,它调用一些功能来获得时间,例如
time_t t= time(NULL);
#ifndef _WIN32
timespec ts;
if( -1 == clock_gettime(CLOCK_MONOTONIC,&ts) )
GenErrnoErr()
return uint64( ( ((uint64)ts.tv_sec*1000 + (uint64)ts.tv_nsec/1000000) - m_uBaseTime ) * ms_dTimeRatio ) ;
#else
LARGE_INTEGER uTime;
QueryPerformanceCounter(&uTime);
return uint64( ( uint64(uTime.QuadPart/CFrequency::Instance().Get().QuadPart) - m_uBaseTime ) * ms_dTimeRatio );
#endif`
我的意思是在不改变代码存在的情况下,将所有这些时间挂起func。当它调用time(NULL)或其他func时,它会返回我伪造的时间。
发布于 2016-10-08 07:24:17
做这种事情的通常方法是使用链接器的--wrap选项。它的工作方式如下:
time(...),而是命名它为__wrap_time(...);time()函数,实际上调用__real_time();--wrap=time。这将使链接器链接到任何其他模块对time()的__wrap_time()调用,但仍然允许通过__real_time()调用原始的time()函数。因此:
// Need this to satisfy the compiler
extern time_t __real_time(time_t *seconds);
time_t __wrap_time(time_t *seconds) {
if (seconds==NULL) {
return 0;
} // if
return __real_time(seconds)
} // __wrap_time(seconds)发布于 2016-10-08 07:22:08
绕开过程中的功能到你的钩子。您将需要注入一个dll来挂钩它,并在原始函数结束符中将一个jmp添加到您的钩子函数地址。更多的信息也会有帮助..。
https://stackoverflow.com/questions/39929748
复制相似问题