From b88e279b3200b83de3fbf68f7afbbcc043f71e61 Mon Sep 17 00:00:00 2001 From: Bottersnike Date: Tue, 4 Apr 2023 02:01:54 +0100 Subject: [PATCH] Hook libamv --- src/micetools/dll/amvStub/amv.c | 62 ++++++++++++++++++++++++++++++++ src/micetools/dll/hooks/system.c | 18 ++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/micetools/dll/amvStub/amv.c diff --git a/src/micetools/dll/amvStub/amv.c b/src/micetools/dll/amvStub/amv.c new file mode 100644 index 0000000..98c31a5 --- /dev/null +++ b/src/micetools/dll/amvStub/amv.c @@ -0,0 +1,62 @@ +#include + +DWORD NvidiaDebugLevel = 0; + +__declspec(dllexport) int amvFinalize_Nvidia() { return 0; } +__declspec(dllexport) int amvGetAvailableDriverEx_Nvidia(LPVOID pGpuHandle, DWORD dwGpuHandleSize) { + return 0; +} +__declspec(dllexport) int amvGetAvailableDriver_Nvidia() { + return amvGetAvailableDriverEx_Nvidia(NULL, 4); +} +__declspec(dllexport) int amvGetConnectedDisplaysEx_Nvidia(LPVOID pGpuHandle, DWORD dwGpuHandleSize, + LPBYTE displayType) { + // TODO: Find a use of this to figure out what we should spoof! + if (displayType) *displayType = 0; + return 0; +} +__declspec(dllexport) int amvGetConnectedDisplays_Nvidia(LPBYTE displayType) { + return amvGetConnectedDisplays_Nvidia(NULL, 4, displayType); +} +__declspec(dllexport) int amvGetCurrentPstateEx_Nvidia(LPVOID pGpuHandle, DWORD dwGpuHandleSize, + DWORD* pPstate) { + // TODO: Find a use of this to figure out what we should spoof! + if (pPstate) *pPstate = 0; + return 0; +} +__declspec(dllexport) int amvGetCurrentPstate_Nvidia(DWORD* pPstate) { + return amvGetCurrentPstateEx_Nvidia(NULL, 4, pPstate); +} +__declspec(dllexport) int amvGetamvNvidiaDebugLevel() { return NvidiaDebugLevel; } +__declspec(dllexport) char* amvGetamvNvidiaVersion() { + return "\namv_nvidia Ver.1.05 Build:Jul 22 2011 13:53:26\n"; +} +__declspec(dllexport) int amvInitialize_Nvidia(LPVOID pGpuHandle, DWORD dwGpuHandleSize) { + return 0; +} +__declspec(dllexport) int amvSetCustomDisplaySetting2ndEx_Nvidia( + LPVOID pGpuHandle, DWORD dwGpuHandleSize, LPWORD NV_SetCustomDisplaySetting) { + return 0; +} +__declspec(dllexport) int amvSetCustomDisplaySetting2nd_Nvidia(LPVOID pGpuHandle) { + return amvSetCustomDisplaySetting2ndEx_Nvidia(NULL, 4, pGpuHandle); +} +__declspec(dllexport) int amvSetCustomDisplaySettingEx_Nvidia(LPVOID pGpuHandle, + DWORD dwGpuHandleSize, + LPWORD NV_SetCustomDisplaySetting) { + return 0; +} +__declspec(dllexport) int amvSetCustomDisplaySetting_Nvidia(LPVOID pGpuHandle) { + return amvSetCustomDisplaySettingEx_Nvidia(NULL, 4, pGpuHandle); +} +__declspec(dllexport) int amvSetDisplayModeEx_Nvidia(LPVOID pGpuHandle, DWORD dwGpuHandleSize, + BYTE displayMode) { + return 0; +} +__declspec(dllexport) int amvSetDisplayMode_Nvidia(BYTE displayMode) { + return amvSetDisplayModeEx_Nvidia(NULL, 4, displayMode); +} +__declspec(dllexport) int amvSetamvNvidiaDebugLevel(DWORD debugLevel) { + NvidiaDebugLevel = debugLevel; + return NvidiaDebugLevel; +} diff --git a/src/micetools/dll/hooks/system.c b/src/micetools/dll/hooks/system.c index dfd9394..ed31e65 100644 --- a/src/micetools/dll/hooks/system.c +++ b/src/micetools/dll/hooks/system.c @@ -64,6 +64,22 @@ LONG WINAPI FakeRtlGetVersion(PRTL_OSVERSIONINFOW lpVersionInformation) { return 0; } +// TODO: We should probably handle libamv_amd.dll at some point too +HMODULE WINAPI FakeLoadLibraryA(LPCSTR lpLibFileName) { + if (strcmp(lpLibFileName, "libamv_nvidia.dll") == 0) { + return TrueLoadLibraryA(MICELIB); + } + return TrueLoadLibraryA(lpLibFileName); +} +#define WIDEN2(x) L ## x +#define WIDEN(x) WIDEN2(x) +HMODULE WINAPI FakeLoadLibraryW(LPCWSTR lpLibFileName) { + if (wcscmp(lpLibFileName, L"libamv_nvidia.dll") == 0) { + return TrueLoadLibraryW(WIDEN(MICELIB)); + } + return TrueLoadLibraryW(lpLibFileName); +} + void hook_system() { // TODO: This should be part of drives/hooks.c hook("Kernel32.dll", "GetVolumeInformationW", FakeGetVolumeInformationW, NULL); @@ -71,6 +87,8 @@ void hook_system() { // hook("Kernel32.dll", "GetVersionExA", FakeGetVersionExA, NULL); // hook("Kernel32.dll", "GetProcAddress", FakeGetProcAddress, (void*)&TrueGetProcAddress); // hook("Kernel32.dll", "GetModuleHandleA", FakeGetModuleHandleA, (void*)&TrueGetModuleHandleA); + hook("Kernel32.dll", "LoadLibraryA", FakeLoadLibraryA, (void*)&TrueLoadLibraryA); + hook("Kernel32.dll", "LoadLibraryW", FakeLoadLibraryW, (void*)&TrueLoadLibraryW); // hook("ntdll.dll", "RtlGetVersion", FakeRtlGetVersion, NULL);