-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cpp
104 lines (88 loc) · 2.03 KB
/
Program.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
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
103
104
#include "stdafx.h"
#include "Program.h"
Program::Program()
{
attached = FALSE;
}
Program::Program(wstring name){
this->name = name;
attached = FALSE;
}
void Program::setName(wstring name){
this->name = name;
}
void Program::setAttached(bool attached){
this->attached = attached;
}
wstring Program::getName(){
return name;
}
DWORD Program::getBaseAddress(){
MODULEENTRY32 moduleentry32;
moduleentry32.dwSize = sizeof(MODULEENTRY32W);
windowHandle = FindWindow(NULL, getName().c_str());
if (windowHandle == NULL)
{
return 1;
}
GetWindowThreadProcessId(windowHandle, &processId);
if (processId == NULL)
{
return 2;
}
programHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
if (programHandle == INVALID_HANDLE_VALUE)
{
return 3;
}
if (!Module32First(programHandle, &moduleentry32))
{
return 4;
}
if (setDebugPrivilegesEnabled() == FALSE){
return 5;
}
baseAddress = (DWORD)moduleentry32.modBaseAddr;
return baseAddress;
}
HANDLE Program::getProgramHandle(){
programHandle = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_READ | PROCESS_VM_OPERATION, FALSE, processId);
return programHandle;
}
bool Program::setDebugPrivilegesEnabled(){
HANDLE hToken;
LUID SeDebugNameValue;
TOKEN_PRIVILEGES TokenPrivileges;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &SeDebugNameValue))
{
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Luid = SeDebugNameValue;
TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{
CloseHandle(hToken);
}
else
{
CloseHandle(hToken);
debugPrivilegesEnabled = false;
return false;
}
}
else
{
CloseHandle(hToken);
debugPrivilegesEnabled = false;
return false;
}
}
else
{
debugPrivilegesEnabled = false;
return false;
}
debugPrivilegesEnabled = true;
return true;
}