Thanks for the help so far, guys.
I've stumbled across a (seemingly common) problem, but I can't find/figure out any fix. Google/MSDN were useless here >
.
Immediately after refExport.Init() is called (whether or not I fed the export my function or the original), I get the debugging exception:
... Privileged instruction (0xC0000096) occurred at ...
Here's some of my code (I truncated parts (// continue exports) to make it easier to read).
DLL:
Code:
#include <windows.h>
#include <detours.h>
#include "Engine/ref.h"
#pragma comment(lib, "detours.lib")
#pragma warning(disable: 4996)
refexport_t refExports;
refimport_t refImports;
static bool dtrSet = false;
typedef HMODULE (WINAPI *LoadLibrary_t)(LPCSTR);
// this is already defined in ref.h
//typedef refexport_t (*GetRefAPI_t)(refimport_t);
qboolean h_Init(void *hInstance, void *wndProc)
{
return refExports.Init(hInstance, wndProc);
}
void h_Shutdown()
{
refExports.Shutdown();
}
void h_BeginRegistration(char *map)
{
refExports.BeginRegistration(map);
}
... // continue exports
#define DEF_EXPORT(name) ret.##name = h_##name
GetRefAPI_t o_GetRefAPI;
refexport_t h_GetRefAPI(refimport_t refImport)
{
refexport_t ret = o_GetRefAPI(refImport);
refExports = ret;
refImports = refImport;
ret.api_version = API_VERSION;
DEF_EXPORT(Init);
DEF_EXPORT(Shutdown);
DEF_EXPORT(BeginRegistration);
... // continue exports
return ret;
}
LoadLibrary_t o_LoadLibrary;
HMODULE h_LoadLibrary(LPCSTR lpLibrary)
{
HMODULE hM = o_LoadLibrary(lpLibrary);
if (hM)
{
if (strstr(lpLibrary, "ref_pbgl.dll") && !dtrSet)
{
DetourFunction(
(PBYTE)GetProcAddress(hM, "GetRefAPI"),
(PBYTE)h_GetRefAPI);
__asm mov [o_GetRefAPI], eax;
dtrSet = true;
}
}
return o_LoadLibrary(lpLibrary);
}
bool WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DetourFunction(
(LPBYTE)LoadLibraryA,
(LPBYTE)h_LoadLibrary);
__asm mov [o_LoadLibrary], eax;
break;
case DLL_PROCESS_DETACH:
if (dtrSet)
DetourRemove((LPBYTE)h_GetRefAPI, (LPBYTE)o_GetRefAPI);
DetourRemove((LPBYTE)h_LoadLibrary, (LPBYTE)LoadLibraryA);
break;
}
return true;
} Injector:
Code:
#include <windows.h>
#include <iostream>
#include <detours.h>
using namespace std;
#pragma comment(lib, "detours.lib")
int main()
{
const char *appName = "C:\\games\\PAINTB~1\\paintball2.exe";
const char *dllName = "C:\\Documents and Settings\\Admin\\My Documents\\Visual Studio 2005\\Projects\\pb2_BaseHook2\\debug\\pb2_BaseHook2.dll";
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);
cout << "Paintball2 Hackz - By TheSorc3r3r\nCredits: Panzer, inspire-, Couch, null"
<< "\nGameDeception.com & CheatersUtopia.com"
<< "\n\nStarting Digital Paintball 2 with hacks...";
if (DetourCreateProcessWithDll(appName, "", 0, 0, 0, 0, 0, 0, &si, &pi, dllName,
0))
cout << "\nHacks successful =)!";
else
cout << "\nHacks unsuccessful =(.\nError was:" << GetLastError();
cout << "\n\n";
return 1;
} Thanks for any help
!
Bookmarks