This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathhook.cpp
49 lines (35 loc) · 1.44 KB
/
hook.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "hook.h"
#include "utils.h"
#include "MinHook.h"
#include <iostream>
#include <windows.h>
typedef HANDLE(WINAPI* CREATE_FILE_W)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
namespace hook {
CREATE_FILE_W p_CreateFileW = nullptr;
CREATE_FILE_W t_CreateFileW;
HANDLE WINAPI h_CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
if (memcmp(lpFileName, L"\\\\.\\ACE-BASE", 12) == 0) {
wprintf(L"Thread (%i) attempting to communicate with anti-cheat driver -> %s\n", GetCurrentThreadId(), lpFileName);
SuspendThread(GetCurrentThread()); // 200iq bypass for memory protection
}
return p_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
void init() {
if (MH_Initialize() != MH_OK)
{
printf("Error initializing MinHook library\n");
return;
}
if (MH_CreateHookApiEx(L"kernelbase", "CreateFileW", &h_CreateFileW, reinterpret_cast<void**>(&p_CreateFileW), reinterpret_cast<void**>(&t_CreateFileW)) != MH_OK)
{
printf("Error creating hook for CreateFileW function\n");
return;
}
if (MH_EnableHook(t_CreateFileW) != MH_OK)
{
printf("Error enabling hook for CreateFileW function\n");
return;
}
}
}