forked from MapleStoryGameHack/MSDoggy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiMS.h
102 lines (84 loc) · 3.1 KB
/
MultiMS.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <winternl.h>
typedef enum _OBJECT_INFORMATION_CLASS {
ObjectBasicInformation = 0,
ObjectTypeInformation = 2
} OBJECT_INFORMATION_CLASS;
typedef NTSTATUS (NTAPI *NtQuerySystemInformation_t) (SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
typedef NTSTATUS (NTAPI *NtQueryObject_t) (HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass, PVOID ObjectInformation, ULONG ObjectInformationLength, PULONG ReturnLength);
struct SYSTEM_HANDLE_INFORMATION
{
DWORD pid;
BYTE type;
BYTE flags;
WORD handle;
DWORD object;
DWORD access;
};
typedef struct _OBJECT_NAME_INFORMATION {
UNICODE_STRING Name;
} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
bool EnableMultiMS()
{
#ifdef VMProtectSDK
VMProtectBegin("MultiMS");
#endif
int handleCount = 1024;
HMODULE ntdll = GetModuleHandleW(L"ntdll");
if (ntdll == NULL)
{
//Log(L"Couldn't get ntdll handle\n");
return false;
}
NtQueryObject_t ntQO = (NtQueryObject_t)GetProcAddress(ntdll, "NtQueryObject");
NtQuerySystemInformation_t ntQSI = (NtQuerySystemInformation_t)GetProcAddress(ntdll, "NtQuerySystemInformation");
if (ntQO == NULL || ntQSI == NULL)
{
//Log(L"Couldn't find procedures for MultiMS (%x / %x)\n", ntQO, ntQSI);
return false;
}
struct HandleInfoSet
{
unsigned int count;
SYSTEM_HANDLE_INFORMATION handles[1];
};
HandleInfoSet *infoSet = (HandleInfoSet *)malloc(4 + sizeof(SYSTEM_HANDLE_INFORMATION) * handleCount);
DWORD length;
NTSTATUS status = ntQSI((SYSTEM_INFORMATION_CLASS)16, infoSet, 4 + sizeof(SYSTEM_HANDLE_INFORMATION) * handleCount, &length);
//Log(L"alloc with %i // %i\n", handleCount, handleCount * sizeof(SYSTEM_HANDLE_INFORMATION) + 4);
while (status == (NTSTATUS)0xc0000004) //STATUS_INFO_LENGTH_MISMATCH
{
free(infoSet);
handleCount *= 2;
//Log(L"alloc with %i // %i\n", handleCount, handleCount * sizeof(SYSTEM_HANDLE_INFORMATION) + 4);
infoSet = (HandleInfoSet *)malloc(4 + sizeof(SYSTEM_HANDLE_INFORMATION) * handleCount);
status = ntQSI((SYSTEM_INFORMATION_CLASS)16, infoSet, 4 + sizeof(SYSTEM_HANDLE_INFORMATION) * handleCount, &length);
}
if (status != 0) //STATUS_SUCCESS
{
//Log(L"Failed to enumerate handles open by this process (errorcode %x)\n", status);
free(infoSet);
return false;
}
for (unsigned int i = 0; i < infoSet->count; i++)
{
wchar_t nameBuffer[1024];
//if (infoSet->handles[i].handle == 0x0012019F) continue; // some buggy thing we need to skip
status = ntQO((HANDLE)infoSet->handles[i].handle, (OBJECT_INFORMATION_CLASS)1, nameBuffer, 1024, &length);
if (status != 0) //STATUS_SUCCESS
continue;
if (wcsstr(nameBuffer + 4, L"WvsClientMtx") != NULL)
{
HANDLE handle;
DuplicateHandle(GetCurrentProcess(), (HANDLE)infoSet->handles[i].handle, 0, &handle, 0, FALSE, DUPLICATE_CLOSE_SOURCE);
//CloseHandle(handle);
ReleaseMutex(handle);
//Log(L"Mutex closed, MultiMS is ok\n");
break;
}
}
free(infoSet);
#ifdef VMProtectSDK
VMProtectEnd();
#endif
return true;
}