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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
#include <logging.h>
#include <sharedparameters.h>
#include <usvfsparametersprivate.h>
namespace usvfs
{
ForcedLibrary::ForcedLibrary(const std::string& process, const std::string& path,
const shared::VoidAllocatorT& alloc)
: m_processName(process.begin(), process.end(), alloc),
m_libraryPath(path.begin(), path.end(), alloc)
{}
std::string ForcedLibrary::processName() const
{
return {m_processName.begin(), m_processName.end()};
}
std::string ForcedLibrary::libraryPath() const
{
return {m_libraryPath.begin(), m_libraryPath.end()};
}
SharedParameters::SharedParameters(const usvfsParameters& reference,
const shared::VoidAllocatorT& allocator)
: m_instanceName(reference.instanceName, allocator),
m_currentSHMName(reference.currentSHMName, allocator),
m_currentInverseSHMName(reference.currentInverseSHMName, allocator),
m_debugMode(reference.debugMode), m_logLevel(reference.logLevel),
m_crashDumpsType(reference.crashDumpsType),
m_crashDumpsPath(reference.crashDumpsPath, allocator),
m_delayProcess(reference.delayProcessMs), m_userCount(1),
m_processBlacklist(allocator), m_processList(allocator),
m_fileSuffixSkipList(allocator), m_directorySkipList(allocator),
m_forcedLibraries(allocator)
{}
usvfsParameters SharedParameters::makeLocal() const
{
bi::scoped_lock lock(m_mutex);
return usvfsParameters(m_instanceName.c_str(), m_currentSHMName.c_str(),
m_currentInverseSHMName.c_str(), m_debugMode, m_logLevel,
m_crashDumpsType, m_crashDumpsPath.c_str(),
m_delayProcess.count());
}
std::string SharedParameters::instanceName() const
{
bi::scoped_lock lock(m_mutex);
return {m_instanceName.begin(), m_instanceName.end()};
}
std::string SharedParameters::currentSHMName() const
{
bi::scoped_lock lock(m_mutex);
return {m_currentSHMName.begin(), m_currentSHMName.end()};
}
std::string SharedParameters::currentInverseSHMName() const
{
bi::scoped_lock lock(m_mutex);
return {m_currentInverseSHMName.begin(), m_currentInverseSHMName.end()};
}
void SharedParameters::setSHMNames(const std::string& current,
const std::string& inverse)
{
bi::scoped_lock lock(m_mutex);
m_currentSHMName.assign(current.begin(), current.end());
m_currentInverseSHMName.assign(inverse.begin(), inverse.end());
}
void SharedParameters::setDebugParameters(LogLevel level, CrashDumpsType dumpType,
const std::string& dumpPath,
std::chrono::milliseconds delayProcess)
{
bi::scoped_lock lock(m_mutex);
m_logLevel = level;
m_crashDumpsType = dumpType;
m_crashDumpsPath.assign(dumpPath.begin(), dumpPath.end());
m_delayProcess = delayProcess;
}
std::size_t SharedParameters::userConnected()
{
bi::scoped_lock lock(m_mutex);
return ++m_userCount;
}
std::size_t SharedParameters::userDisconnected()
{
bi::scoped_lock lock(m_mutex);
return --m_userCount;
}
std::size_t SharedParameters::userCount()
{
bi::scoped_lock lock(m_mutex);
return m_userCount;
}
std::size_t SharedParameters::registeredProcessCount() const
{
bi::scoped_lock lock(m_mutex);
return m_processList.size();
}
std::vector<DWORD> SharedParameters::registeredProcesses() const
{
bi::scoped_lock lock(m_mutex);
return {m_processList.begin(), m_processList.end()};
}
void SharedParameters::registerProcess(DWORD pid)
{
bi::scoped_lock lock(m_mutex);
m_processList.insert(pid);
}
void SharedParameters::unregisterProcess(DWORD pid)
{
{
bi::scoped_lock lock(m_mutex);
auto itor = m_processList.find(pid);
if (itor != m_processList.end()) {
m_processList.erase(itor);
return;
}
}
spdlog::get("usvfs")->error("cannot unregister process {}, not in list", pid);
}
void SharedParameters::blacklistExecutable(const std::string& name)
{
bi::scoped_lock lock(m_mutex);
m_processBlacklist.insert(
shared::StringT(name.begin(), name.end(), m_processBlacklist.get_allocator()));
}
void SharedParameters::clearExecutableBlacklist()
{
bi::scoped_lock lock(m_mutex);
m_processBlacklist.clear();
}
bool SharedParameters::executableBlacklisted(const std::string& appName,
const std::string& cmdLine) const
{
bool blacklisted = false;
std::string log;
{
bi::scoped_lock lock(m_mutex);
for (const shared::StringT& sitem : m_processBlacklist) {
const auto item = "\\" + std::string(sitem.begin(), sitem.end());
if (!appName.empty()) {
if (boost::algorithm::iends_with(appName, item)) {
blacklisted = true;
log = std::format("application {} is blacklisted", appName);
break;
}
}
if (!cmdLine.empty()) {
if (boost::algorithm::icontains(cmdLine, item)) {
blacklisted = true;
log = std::format("command line {} is blacklisted", cmdLine);
break;
}
}
}
}
if (blacklisted) {
spdlog::get("usvfs")->info(log);
return true;
}
return false;
}
void SharedParameters::addSkipFileSuffix(const std::string& fileSuffix)
{
bi::scoped_lock lock(m_mutex);
m_fileSuffixSkipList.insert(shared::StringT(fileSuffix.begin(), fileSuffix.end(),
m_fileSuffixSkipList.get_allocator()));
}
void SharedParameters::clearSkipFileSuffixes()
{
bi::scoped_lock lock(m_mutex);
m_fileSuffixSkipList.clear();
}
std::vector<std::string> SharedParameters::skipFileSuffixes() const
{
bi::scoped_lock lock(m_mutex);
return {m_fileSuffixSkipList.begin(), m_fileSuffixSkipList.end()};
}
void SharedParameters::addSkipDirectory(const std::string& directory)
{
bi::scoped_lock lock(m_mutex);
m_directorySkipList.insert(shared::StringT(directory.begin(), directory.end(),
m_directorySkipList.get_allocator()));
}
void SharedParameters::clearSkipDirectories()
{
bi::scoped_lock lock(m_mutex);
m_directorySkipList.clear();
}
std::vector<std::string> SharedParameters::skipDirectories() const
{
bi::scoped_lock lock(m_mutex);
return {m_directorySkipList.begin(), m_directorySkipList.end()};
}
void SharedParameters::addForcedLibrary(const std::string& processName,
const std::string& libraryPath)
{
bi::scoped_lock lock(m_mutex);
m_forcedLibraries.push_front(
ForcedLibrary(processName, libraryPath, m_forcedLibraries.get_allocator()));
}
std::vector<std::string>
SharedParameters::forcedLibraries(const std::string& processName)
{
std::vector<std::string> v;
{
bi::scoped_lock lock(m_mutex);
for (const auto& lib : m_forcedLibraries) {
if (boost::algorithm::iequals(processName, lib.processName())) {
v.push_back(lib.libraryPath());
}
}
}
return v;
}
void SharedParameters::clearForcedLibraries()
{
bi::scoped_lock lock(m_mutex);
m_forcedLibraries.clear();
}
} // namespace usvfs
|