-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
executable file
·112 lines (105 loc) · 3.18 KB
/
main.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
105
106
107
108
109
110
111
112
#include <QCoreApplication>
#include <QDebug>
#include <QString>
#include <Windows.h>
#include <cstdio>
#include <tlhelp32.h>
#include <shellapi.h>
QStringList Apps;
bool isBlacklist = false;
void RaiseToDebugPermission()
{
HANDLE hToken;
HANDLE hProcess = GetCurrentProcess();
if (OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
TOKEN_PRIVILEGES tkp;
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid))
{
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
}
CloseHandle(hToken);
}
}
int GetProcessID(wchar_t *process_name)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (wcscmp(entry.szExeFile, process_name) == 0)
{
return entry.th32ProcessID;
}
}
}
CloseHandle(snapshot);
return 4;
}
BOOL OccupyFile(LPCTSTR lpFileName)
{
BOOL bRet;
RaiseToDebugPermission();
QString CHRName = "explorer.exe";
wchar_t *WCTName = reinterpret_cast<wchar_t *>(CHRName.data());
HANDLE hProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, GetProcessID(WCTName));
if (hProcess == NULL)
{
qDebug() << "Failed";
return FALSE;
}
HANDLE hFile;
HANDLE hTargetHandle;
hFile = CreateFile(lpFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hProcess);
qDebug() << "Failed";
return FALSE;
}
qDebug() << "Succeeded";
bRet = DuplicateHandle(GetCurrentProcess(), hFile, hProcess, &hTargetHandle,
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
CloseHandle(hProcess);
return bRet;
}
void ForbidFile(QStringList qname)
{
while (1)
{
for (int i = 0; i < qname.count(); i++)
{
qname[i].replace("/", "\\");
QString aqname = qname[i].right(qname[i].length() - qname[i].lastIndexOf("\\") - 1);
QString taskkill = "taskkill /im \"" + aqname + "\"";
std::string SSTaskkill = taskkill.toStdString();
const char *CCTaskkill = SSTaskkill.c_str();
qDebug() << CCTaskkill;
system(CCTaskkill);
}
Sleep(10000);
}
}
void ParseArguments()
{
QStringList arguments = QCoreApplication::arguments();
isBlacklist = arguments.at(1) == "black";
for (int i = 2; i < arguments.count(); i++)
{
Apps.append(arguments.at(i));
const wchar_t *WCTArg = reinterpret_cast<const wchar_t *>(arguments.at(i).data());
OccupyFile(WCTArg);
}
ForbidFile(Apps);
}
int main(int argc, char *argv[])
{
QCoreApplication QCApp(argc, argv);
ParseArguments();
return QCApp.exec();
}