Hook libamv

This commit is contained in:
Bottersnike 2023-04-04 02:01:54 +01:00
parent 800b6f28e1
commit b88e279b32
Signed by: Bottersnike
SSH Key Fingerprint: SHA256:3g0ghwd4dNX1k1RX8qazbiT+3RIYn/daeBevHZVCiU0
2 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,62 @@
#include <Windows.h>
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;
}

View File

@ -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);