65,198
社区成员




//RealRun.h
CRealRun
{
public:
CRealRun();
int Run(int cmd);
};
//RealRun.cpp
CRealRun::CRealRun()
{
}
int CRealRun::Run(int cmd)
{
return cmd;
}
//dllmain.cpp
class CDetour /* add ": public CRealRun" to enable access to member variables... */
{
public:
int Mine_Target(int cmd)
static int(CDetour::* Real_Target)(int cmd);
// Class shouldn't have any member variables or virtual functions.
};
int CDetour::Mine_Target(int cmd)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}
int (CDetour::* CDetour::Real_Target)(int cmd) = (int (CDetour::*)(int cmd))&CRealRun::Run;
////////
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (DLL_PROCESS_ATTACH == ul_reason_for_call)
{
MessageBox(NULL, _T("DLL已从目标进程。"), _T("信息"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//DetourAttach(&(PVOID&)CDataHook::RealRun, DetourRunapi);
DetourTransactionCommit();
}
else if (DLL_PROCESS_DETACH == ul_reason_for_call)
{
MessageBox(NULL, _T("DLL已从目标进程卸载。"), _T("信息"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)SysMessageBox, HookMessageBox);
DetourAttach(&(PVOID&)CDetour::Real_Target,
(PVOID)(&(PVOID&)CDetour::Mine_Target));
DetourTransactionCommit();
}
return TRUE;
}
[/quote]
囧,上面的还没写完就莫名其妙的被提交了。以下面的为准。
首先这个类我动不了,只能这样;后来我去看了detours samples的member.cpp,但是运行会报:1>e:\projects\classdtours\classdtours\classdtours.cpp(109): error C2440: 'type cast' : cannot convert from 'void (__thiscall CDetour::* )(void)' to 'PVOID &'
1> Reason: cannot convert from 'overloaded-function' to 'PVOID *'
1> There is no context in which this conversion is possible
1>e:\projects\classdtours\classdtours\classdtours.cpp(109): error C2660: 'DetourAttach' : function does not take 1 arguments
//classdtours.cpp
class CDetour /* add ": public CRealRun" to enable access to member variables... */
{
public:
int Mine_Target(int cmd)
static int(CDetour::* Real_Target)(int cmd);
// Class shouldn't have any member variables or virtual functions.
};
int CDetour::Mine_Target(int cmd)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}
int (CDetour::* CDetour::Real_Target)(int cmd) = (int (CDetour::*)(int cmd))&CRealRun::Run;
////////
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (DLL_PROCESS_ATTACH == ul_reason_for_call)
{
MessageBox(NULL, _T("DLL已从目标进程。"), _T("信息"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)CDetour::Real_Target, (PVOID)(&(PVOID&)CDetour::Mine_Target);
DetourTransactionCommit();
}
else if (DLL_PROCESS_DETACH == ul_reason_for_call)
{
MessageBox(NULL, _T("DLL已从目标进程卸载。"), _T("信息"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)SysMessageBox, HookMessageBox);
DetourDetach(&(PVOID&)CDetour::Real_Target, (PVOID)(&(PVOID&)CDetour::Mine_Target));
DetourTransactionCommit();
}
return TRUE;
}
//dllmain.cpp
class CDetour /* add ": public CRealRun" to enable access to member variables... */
{
public:
int Mine_Target(int cmd)
static int(CDetour::* Real_Target)(int cmd);
// Class shouldn't have any member variables or virtual functions.
};
int CDetour::Mine_Target(int cmd)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}
int (CDetour::* CDetour::Real_Target)(int cmd) = (int (CDetour::*)(int cmd))&CRealRun::Run;
////////
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (DLL_PROCESS_ATTACH == ul_reason_for_call)
{
MessageBox(NULL, _T("DLL已从目标进程。"), _T("信息"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//DetourAttach(&(PVOID&)CDataHook::RealRun, DetourRunapi);
DetourTransactionCommit();
}
else if (DLL_PROCESS_DETACH == ul_reason_for_call)
{
MessageBox(NULL, _T("DLL已从目标进程卸载。"), _T("信息"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)SysMessageBox, HookMessageBox);
DetourAttach(&(PVOID&)CDetour::Real_Target,
(PVOID)(&(PVOID&)CDetour::Mine_Target));
DetourTransactionCommit();
}
return TRUE;
}