Example #1
0
void InstallD3D8Hook()
{
	if(!m_pfnDirect3DCreate8)
	{
		m_pfnDirect3DCreate8 = (Direct3DCreate8_t)DetourFunction(DetourFindFunction("d3d8.dll", "Direct3DCreate8"), (PBYTE)Direct3DCreate8);
	}

	if(!m_pfnDirectInput8Create)
	{
		m_pfnDirectInput8Create = (DirectInput8Create_t)DetourFunction(DetourFindFunction("dinput8.dll", "DirectInput8Create"), (PBYTE)DirectInput8Create);
	}
}
bool CDirectInput8Hook::Install()
{
	if(!m_bInstalled)
	{
		m_pXInputGetState = (XInputGetState_t) DetourFunction( DetourFindFunction( "xinput1_3.dll", "XInputGetState" ), (PBYTE)XInputGetState__Hook );
		m_pDirectInput8Create = ( DirectInput8Create_t ) DetourFunction( DetourFindFunction( "dinput8.dll", "DirectInput8Create" ), (PBYTE)DirectInput8Create__Hook );
		m_pDirectInputCreateEx = ( DirectInputCreateEx_t ) DetourFunction( DetourFindFunction( "dinput.dll", "DirectInputCreateEx" ), (PBYTE)DirectInputCreateEx__Hook );	

		m_bInstalled = true;
		return true;
	}
	return false;
}
bool CDirect3D9Hook::Install()
{
	if(!m_bHookInstalled)
	{      
		CLogger::Debugf("Installing Direct3D9 Hook..");

		m_pfnDirect3DCreate9 = reinterpret_cast<Direct3DCreate9_t>(DetourFunction(DetourFindFunction ("D3D9.DLL", "Direct3DCreate9"),  reinterpret_cast<PBYTE>(Direct3DCreate9_Hook)));
		m_pfnDirect3DCreate9Ex = reinterpret_cast<Direct3DCreate9Ex_t>(DetourFunction(DetourFindFunction ("D3D9.DLL", "Direct3DCreate9Ex"),  reinterpret_cast<PBYTE>(Direct3DCreate9Ex_Hook)));

		CLogger::Debugf("Direct3D9 Hook applied!");

		m_bHookInstalled = true;
        return true;
    }
    return false;
}
Example #4
0
int WINAPI TimedEntryPoint(VOID)
{
    // We couldn't call LoadLibrary in DllMain,
    // so we detour SleepEx here...
    LONG error;

    TrueSleepEx = (DWORD (WINAPI *)(DWORD, BOOL))
        DetourFindFunction("kernel32.dll", "SleepEx");

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)TrueSleepEx, TimedSleepEx);
    error = DetourTransactionCommit();

    if (error == NO_ERROR) {
        printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
               " Detoured SleepEx().\n");

    }
    else {
        printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
               " Error detouring SleepEx(): %d\n", error);
    }

    Verify("SleepEx", (PVOID)SleepEx);
    printf("\n");
    fflush(stdout);

    printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
           " Calling EntryPoint\n");
    fflush(stdout);

    return TrueEntryPoint();
}
Example #5
0
LONG Hooks::FindAndAttach(LPCSTR pszModule, LPCSTR pszFunction,  PVOID* ppPointer, PVOID pDetour) {
    auto function = DetourFindFunction(pszModule, pszFunction);
    if (function == NULL) {
        return ERROR_INVALID_HANDLE;
    }

    *ppPointer = function;
    return DetourAttach(ppPointer, pDetour);
}
Example #6
0
void resolveAddresses()
{
    for( auto& hook : g_hooks )
    {
        if( !hook.m_publicAddress ) {
            void* addr = DetourFindFunction( hook.m_targetDll, hook.m_targetSymbol );
            hook.m_targetAddress = addr;
        }
    }
}
Example #7
0
void CHookCenter::StartHook(){	
	LoadLibrary(L"Wininet.dll");
	g_originConnect = (pInternetConnect)DetourFindFunction("Wininet.dll", "InternetConnectW");
	DetourTransactionBegin();
	DetourUpdateThread(::GetCurrentThread());
	DetourAttach((PVOID*)&g_originConnect, hook_InternetConnect);
	DetourTransactionCommit();	

	HookCookieDir();
}
Example #8
0
bool CDirect3D9Hook::Install()
{
    if(!m_bHookInstalled)
    {
        m_pfnDirect3DCreate9 = reinterpret_cast<Direct3DCreate9_t>(DetourFunction(DetourFindFunction ("D3D9.DLL", "Direct3DCreate9"),  reinterpret_cast<PBYTE>(Direct3DCreate9_Hook)));

        m_bHookInstalled = true;
        return true;
    }
    return false;
}
Example #9
0
void CHookCenter::HookCookieDir(){
	LoadLibrary(L"shell32.dll");

	g_SHGetFolderPath = (pFunc_SHGetFolderPath)DetourFindFunction("shell32.dll", "SHGetFolderPathW");

	DetourTransactionBegin();
	DetourUpdateThread(::GetCurrentThread());
	DetourAttach((PVOID*)&g_SHGetFolderPath, Hook_SHGetFolderPathW);
	DetourTransactionCommit();	
	
}
bool CDirectInput8Hook::Install( )
{
	// Is the proxy already installed?
	if( m_bInstalled )
		return false;

	// Install the detour patch
	m_pDirectInput8Create = ( DirectInput8Create_t ) DetourFunction( DetourFindFunction( "dinput8.dll", "DirectInput8Create" ), (PBYTE)DirectInput8Create__Hook );

	// Mark as installed
	m_bInstalled = true;

	return true;
}
Example #11
0
//安装Hook   
BOOL APIENTRY SetHook()  
{  
	//大概是 开始事务吧  
	DetourTransactionBegin();  
	//更新线程信息  
	DetourUpdateThread(GetCurrentThread());  
	//查询函数 地址 将MessageBoxA 地址保存在这个 指针里面  
	g_pOldMessageBoxA=DetourFindFunction("User32.dll","MessageBoxA");  
	//将我们的拦截函数 附加到 MessageBoxA 地址上  
	DetourAttach(&g_pOldMessageBoxA,ZwNewMessageBoxA);  
	//完成hook  
	LONG ret=DetourTransactionCommit();  
	return ret==NO_ERROR;  
}  
Example #12
0
bool HookDInput()
{
	LPSTR DllName = "DINPUT8.DLL";
	LoadLibraryA(DllName);

	PBYTE tmp = (PBYTE )DetourFindFunction(DllName, "DirectInput8Create");

	_TRACE(("HookDInput(), tmp = %p\n"), tmp);

	if (tmp == NULL)
		return false;

	Real_DirectInput8Create = (DirectInput8Create_t ) DetourFunction(
		(PBYTE )tmp, (PBYTE )MyDirectInput8Create);

	_TRACE( ("HookDInput(), Real_DirectInput8Create = %p, MyDirectInput8Create = %p\n"), 
		tmp, &MyDirectInput8Create);

	return true;
}
Example #13
0
void startDetour() {		
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	//DetourAttach(&(PVOID&)TrueSleepEx, DetouredSleepEx);
	//DetourAttach(&(PVOID&)TrueTimeGetTime, DetouredTimeGetTime);
	if(Settings::get().getSkipIntro()) DetourAttach(&(PVOID&)TrueQueryPerformanceCounter, DetouredQueryPerformanceCounter);
	//TrueD3DXCreateTexture = (D3DXCreateTexture_FNType)DetourFindFunction("d3dx9_43.dll", "D3DXCreateTexture");
	TrueD3DXCreateTextureFromFileInMemory = (D3DXCreateTextureFromFileInMemory_FNType)DetourFindFunction("d3dx9_43.dll", "D3DXCreateTextureFromFileInMemory");
	TrueD3DXCreateTextureFromFileInMemoryEx = (D3DXCreateTextureFromFileInMemoryEx_FNType)DetourFindFunction("d3dx9_43.dll", "D3DXCreateTextureFromFileInMemoryEx");
	//DetourAttach(&(PVOID&)TrueD3DXCreateTexture, DetouredD3DXCreateTexture);
	DetourAttach(&(PVOID&)TrueD3DXCreateTextureFromFileInMemory, DetouredD3DXCreateTextureFromFileInMemory);
	DetourAttach(&(PVOID&)TrueD3DXCreateTextureFromFileInMemoryEx, DetouredD3DXCreateTextureFromFileInMemoryEx);
	//TrueD3DXCompileShader = (D3DXCompileShader_FNType)DetourFindFunction("d3dx9_43.dll", "D3DXCompileShader");
	//SDLOG(0, "Detouring: compile shader: %p\n", TrueD3DXCompileShader);
	//DetourAttach(&(PVOID&)TrueD3DXCompileShader, DetouredD3DXCompileShader);

	if(DetourTransactionCommit() == NO_ERROR) {
		SDLOG(0, "Detouring: Detoured successfully\n");
	} else {
		SDLOG(0, "Detouring: Error detouring\n");
	}
}
Example #14
0
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved) {
	if (DetourIsHelperProcess()) {
		return TRUE;
	}
	
	char buffer[100];
	if (dwReason == DLL_PROCESS_ATTACH) {
		OutputDebugString("Hooking");	
		DetourRestoreAfterWith();

		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());		
		oldDirectInput8Create = (HRESULT(WINAPI *)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID * ppvOut, LPUNKNOWN punkOuter))DetourFindFunction("dinput8.dll", "DirectInput8Create");
		sprintf_s(buffer, 100, "DirectInput8Create at %x", oldDirectInput8Create);
		OutputDebugString(buffer);
		if(oldDirectInput8Create == NULL)
			OutputDebugString("Failed to find function");
		int error = DetourAttach(&(PVOID&)oldDirectInput8Create, myDirectInput8Create);
		if(error != NO_ERROR)
			OutputDebugString("Failed to detour");
		error = DetourTransactionCommit();
		if(error != NO_ERROR)
			OutputDebugString("Failed to commit");
	}
	else if (dwReason == DLL_PROCESS_DETACH) {
		OutputDebugString("Unhooking");
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)oldDirectInput8Create, myDirectInput8Create);
		DetourDetach(&(PVOID&)oldCreateDevice, myCreateDevice);
		DetourDetach(&(PVOID&)oldGetDeviceState, myGetDeviceState);
		DetourTransactionCommit();
	}
	return TRUE;
}
void CSetCursorPosHook::ApplyHook ( void ) 
{
    // Hook SetCursorPos
    m_pfnSetCursorPos = reinterpret_cast < pSetCursorPos > ( DetourFunction ( DetourFindFunction ( "User32.dll", "SetCursorPos" ),
                                                                              reinterpret_cast <PBYTE> ( API_SetCursorPos ) ) );
}
Example #16
0
bool CDirect3DHook9::ApplyHook ( )
{
    if ( UsingAltD3DSetup() )
        return true;

    // Hook Direct3DCreate9.
    if ( !m_pfnDirect3DCreate9 )
    {
        m_pfnDirect3DCreate9 = reinterpret_cast < pDirect3DCreate > ( DetourFunction ( DetourFindFunction ( "D3D9.DLL", "Direct3DCreate9" ), 
                                                                      reinterpret_cast < PBYTE > ( API_Direct3DCreate9 ) ) );

        WriteDebugEvent ( SString( "Direct3D9 hook applied %08x", m_pfnDirect3DCreate9 ) );
    }
    else
    {
        WriteDebugEvent ( "Direct3D9 hook resumed." );
        m_bDirect3DCreate9Suspended = false;
    }
    return true;
}
Example #17
0
void DirectX8Startup() {
	g_fpDirect3DCreate8 = (LPDIRECT3DCREATE8)DetourFindFunction("d3d8.dll", "Direct3DCreate8");
	if (g_fpDirect3DCreate8 != NULL) {
		DetourAttach(&(PVOID&)g_fpDirect3DCreate8, Direct3DCreate8Detour);		
	}
}
Example #18
0
// Initialize the main routines
void	D3D8_Init()
{
	// Hook us as D3D unit
	m_pfnDirect3DCreate8 = (pfnDirect3DCreate8)DetourFunction( DetourFindFunction("D3D8.DLL", "Direct3DCreate8"), (PBYTE)Hook_Direct3DCreate8);
}
Example #19
0
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
*/
#include "hooking.hpp"
#include "exception.hpp"

#include <detours.h>

/* Global variable */
// The address of the real ntdll.KiUserExceptionDispatcher
KiUserExceptionDispatcher_t TrueKiUserExceptionDispatcher = (KiUserExceptionDispatcher_t)DetourFindFunction(
    "ntdll.dll",
    "KiUserExceptionDispatcher"
);

// The address of the real kernel32.UnhandledExceptionFilter
// UnhandledExceptionFilter_t TrueUnhandledExceptionFilter = (UnhandledExceptionFilter_t)DetourFindFunction(
//    "kernel32.dll",
//    "UnhandledExceptionFilter"
// );

extern CRITICAL_SECTION critical_section;

// LONG WINAPI UnhandledExceptionFilter_(struct _EXCEPTION_POINTERS *ExceptionInfo)
// {
//     /* If we reached there, it is a good (good for us, bad for the coder/program :)) sign, report it! */
//     EnterCriticalSection(&critical_section);
//     log_exception(ExceptionInfo->ExceptionRecord, ExceptionInfo->ContextRecord);