I'm using:
MS VS 10
Detours v3.0 Express
The complete source code DLL:
#include <windows.h>
#include <detours.h>
ofstream prclist ;
#pragma comment(lib,"detours.lib")
FARPROC (WINAPI * pGetProcAddress)(HMODULE hModule,LPCSTR lpProcName) = GetProcAddress;
FARPROC WINAPI myGetProcAddress(HMODULE hModule,LPCSTR lpProcName);
FARPROC WINAPI myGetProcAddress(HMODULE hModule,LPCSTR lpProcName)
{
prclist << lpProcName << endl; // <- ACCESS_VIOLATION READ
return pGetProcAddress( hModule, lpProcName);
}
BOOL APIENTRY DllMain(HINSTANCE hDLL, DWORD reason, LPVOID reserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
{
prclist.open("proclst.log",ios::out | ios::app );
DisableThreadLibraryCalls(hDLL);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pGetProcAddress, myGetProcAddress);
DetourTransactionCommit();
break;
}
case DLL_PROCESS_DETACH:
{
prclist.close();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pGetProcAddress, myGetProcAddress);
DetourTransactionCommit();
break;
}
}
return TRUE;
}
I try to view the list of functions received by GetProcAddress. But after start, the program is closed with an error: "ACCESS_VIOLATION, UNABLE_TO_READ"
Somebody can prompt how to fix it ?