forked from AlexanderPro/SmartSystemMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
98 lines (88 loc) · 2.53 KB
/
Copy pathdllmain.cpp
File metadata and controls
98 lines (88 loc) · 2.53 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
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
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "tinyxml2.h"
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
extern HINSTANCE g_appInstance;
using namespace tinyxml2;
using namespace std;
bool array_contains(const string &value, const vector<string> &array)
{
return find(array.begin(), array.end(), value) != array.end();
}
string get_file_name(const string &path)
{
size_t index = path.find_last_of("/\\");
string fileName = path.substr(index + 1);
return fileName;
}
string get_directory_name(const string &path)
{
size_t index = path.find_last_of("/\\");
string directoryName = path.substr(0, index);
return directoryName;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
if (g_appInstance == NULL)
{
g_appInstance = hModule;
}
try
{
WCHAR exePath[MAX_PATH], dllPath[MAX_PATH];
if (GetModuleFileName(NULL, exePath, sizeof(exePath)) != 0 && GetModuleFileName(hModule, dllPath, sizeof(dllPath)) != 0)
{
wstring dllTempPath(&dllPath[0]);
string dllFileName(dllTempPath.begin(), dllTempPath.end());
string dllDirectoryName = get_directory_name(dllFileName);
string exclusionsFileName = dllDirectoryName + "\\SmartSystemMenu.xml";
XMLDocument doc;
doc.LoadFile(exclusionsFileName.c_str());
vector<string> processNames{};
XMLElement* element = doc.FirstChildElement("smartSystemMenu");
if (element)
{
element = element->FirstChildElement("processExclusions");
if (element)
{
element = element->FirstChildElement("processName");
while (element)
{
const char* value = element->GetText();
string processName = value;
transform(processName.begin(), processName.end(), processName.begin(), ::tolower);
processNames.push_back(processName);
element = element->NextSiblingElement("processName");
}
}
}
wstring exeTempPath(&exePath[0]);
string exeFileName(exeTempPath.begin(), exeTempPath.end());
exeFileName = get_file_name(exeFileName);
transform(exeFileName.begin(), exeFileName.end(), exeFileName.begin(), ::tolower);
if (array_contains(exeFileName, processNames))
{
return FALSE;
}
}
}
catch (...)
{
TCHAR buf[255];
wsprintf(buf, L"SmartSystemMenu exception");
OutputDebugString(buf);
}
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}