Refactor ace.c
This commit is contained in:
parent
2612ad2212
commit
eb38894de5
@ -9,14 +9,13 @@ static void _dll_notification(ULONG reason, const PLDR_DLL_NOTIFICATION_DATA dat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// context should be set to the target module name, lowercase
|
// context should be set to the target module name
|
||||||
wchar_t *targetModuleName = (wchar_t*)context;
|
wchar_t *targetModuleName = (wchar_t*)context;
|
||||||
|
|
||||||
wchar_t lwModuleName[MAX_PATH];
|
if (wcsicmp(targetModuleName, data->Loaded.BaseDllName->Buffer) != 0) {
|
||||||
wcscpy(lwModuleName, data->Loaded.BaseDllName->Buffer);
|
return;
|
||||||
_wcslwr(lwModuleName);
|
}
|
||||||
|
|
||||||
if (wcscmp(targetModuleName, lwModuleName) == 0) {
|
|
||||||
// Replace entry point with a stub
|
// Replace entry point with a stub
|
||||||
void *entryPoint = pe_find_entry_point(data->Loaded.DllBase);
|
void *entryPoint = pe_find_entry_point(data->Loaded.DllBase);
|
||||||
|
|
||||||
@ -31,61 +30,54 @@ static void _dll_notification(ULONG reason, const PLDR_DLL_NOTIFICATION_DATA dat
|
|||||||
memcpy(entryPoint, ENTRY_POINT_STUB, sizeof(ENTRY_POINT_STUB));
|
memcpy(entryPoint, ENTRY_POINT_STUB, sizeof(ENTRY_POINT_STUB));
|
||||||
|
|
||||||
VirtualProtect(entryPoint, sizeof(ENTRY_POINT_STUB), oldProtect, &oldProtect);
|
VirtualProtect(entryPoint, sizeof(ENTRY_POINT_STUB), oldProtect, &oldProtect);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _create_driver_file(const char *path) {
|
||||||
|
// They only report presence
|
||||||
|
HANDLE file = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
|
if (file == INVALID_HANDLE_VALUE) {
|
||||||
|
msg_err_a("Could not create driver file: %s", file);
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ace_fake_driver_files() {
|
void ace_fake_driver_files() {
|
||||||
// They only report presence
|
_create_driver_file("ACE-BASE.sys");
|
||||||
const char *wdDriverPath = "ACE-BASE.sys";
|
|
||||||
const char *s32DriverPath = "C:\\windows\\system32\\drivers\\ACE-BASE.sys";
|
|
||||||
|
|
||||||
HANDLE wdDriverFile = CreateFileA(wdDriverPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (!wdDriverFile) {
|
|
||||||
msg_err_a("Could not create driver file: %s", wdDriverPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just in case
|
// Just in case
|
||||||
HANDLE s32DriverFile = CreateFileA(s32DriverPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
_create_driver_file("C:\\windows\\system32\\drivers\\ACE-BASE.sys");
|
||||||
if (!s32DriverFile) {
|
|
||||||
msg_err_a("Could not create driver file: %s", s32DriverPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(wdDriverFile);
|
HMODULE _load_module_patched(wchar_t *path) {
|
||||||
CloseHandle(s32DriverFile);
|
// Get filename from the path
|
||||||
|
wchar_t *name = wcsrchr(path, '\\');
|
||||||
|
name = name ? name + 1 : path;
|
||||||
|
|
||||||
|
void *cookie;
|
||||||
|
LdrRegisterDllNotification(0, &_dll_notification, name, &cookie);
|
||||||
|
|
||||||
|
HMODULE module = LoadLibraryW(path);
|
||||||
|
if (!module) {
|
||||||
|
msg_err_w(L"Could not load module: %ls", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadLibraryW is synchronous; the notification function has already finished executing
|
||||||
|
LdrUnregisterDllNotification(cookie);
|
||||||
|
|
||||||
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
HMODULE ace_load_base_module(const char *exeName) {
|
HMODULE ace_load_base_module(const char *exeName) {
|
||||||
wchar_t baseModuleName[MAX_PATH];
|
wchar_t baseModuleName[MAX_PATH];
|
||||||
swprintf(baseModuleName, MAX_PATH, L"%sbase.dll", exeName);
|
swprintf(baseModuleName, MAX_PATH, L"%sBase.dll", exeName);
|
||||||
wcslwr(baseModuleName);
|
wcslwr(baseModuleName);
|
||||||
|
|
||||||
void *cookie;
|
return _load_module_patched(baseModuleName);
|
||||||
LdrRegisterDllNotification(0, &_dll_notification, baseModuleName, &cookie);
|
|
||||||
|
|
||||||
HMODULE baseModule = LoadLibraryW(baseModuleName);
|
|
||||||
if (!baseModule) {
|
|
||||||
msg_err_w(L"Could not load base module: %ls", baseModuleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadLibraryA is synchronous; the notification function has already finished executing
|
|
||||||
LdrUnregisterDllNotification(cookie);
|
|
||||||
|
|
||||||
return baseModule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HMODULE ace_load_driver_module() {
|
HMODULE ace_load_driver_module() {
|
||||||
const char *driverModulePath = "AntiCheatExpert/InGame/x64/ACE-DRV64.dll";
|
return _load_module_patched(L"AntiCheatExpert\\InGame\\x64\\ACE-DRV64.dll");
|
||||||
|
|
||||||
void *cookie;
|
|
||||||
LdrRegisterDllNotification(0, &_dll_notification, L"ace-drv64.dll", &cookie);
|
|
||||||
|
|
||||||
HMODULE driverModule = LoadLibraryA(driverModulePath);
|
|
||||||
if (!driverModule) {
|
|
||||||
msg_err_a("Could not load driver module: %s", driverModulePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadLibraryA is synchronous; the notification function has already finished executing
|
|
||||||
LdrUnregisterDllNotification(cookie);
|
|
||||||
|
|
||||||
return driverModule;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user