Removed dependency with Restart Manager and using Process Status API instead (Windows).

This commit is contained in:
Gonzalo Exequiel Pedone 2020-06-06 19:02:10 -03:00
parent 7e35bf47f5
commit 602829f351
No known key found for this signature in database
GPG key ID: B8B09E63E9B85BAF
2 changed files with 46 additions and 40 deletions

View file

@ -45,8 +45,7 @@ LIBS = \
-L$${OUT_PWD}/../../VCamUtils/$${BIN_DIR} -lVCamUtils \ -L$${OUT_PWD}/../../VCamUtils/$${BIN_DIR} -lVCamUtils \
-ladvapi32 \ -ladvapi32 \
-lkernel32 \ -lkernel32 \
-lpsapi \ -lpsapi
-lrstrmgr
win32-g++: LIBS += -lssp win32-g++: LIBS += -lssp

View file

@ -26,7 +26,6 @@
#include <thread> #include <thread>
#include <dshow.h> #include <dshow.h>
#include <psapi.h> #include <psapi.h>
#include <restartmanager.h>
#include "PlatformUtils/src/messageserver.h" #include "PlatformUtils/src/messageserver.h"
#include "PlatformUtils/src/mutex.h" #include "PlatformUtils/src/mutex.h"
@ -571,55 +570,63 @@ std::vector<uint64_t> AkVCam::IpcBridge::clientsPids() const
} }
std::vector<uint64_t> pids; std::vector<uint64_t> pids;
DWORD sessionHnd = 0;
WCHAR sessionKey[CCH_RM_SESSION_KEY + 1]; const DWORD nElements = 4096;
memset(sessionKey, 0, (CCH_RM_SESSION_KEY + 1) * sizeof(WCHAR)); DWORD process[nElements];
memset(process, 0, nElements * sizeof(DWORD));
DWORD needed = 0;
if (!EnumProcesses(process, nElements * sizeof(DWORD), &needed))
return {};
size_t nProcess = needed / sizeof(DWORD);
auto currentPid = GetCurrentProcessId(); auto currentPid = GetCurrentProcessId();
if (SUCCEEDED(RmStartSession(&sessionHnd, 0, sessionKey))) { for (size_t i = 0; i < nProcess; i++) {
std::vector<LPCWSTR> resources; auto processHnd = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE,
process[i]);
if (!processHnd)
continue;
for (auto &plugin: pluginsPaths) HMODULE modules[nElements];
resources.push_back(plugin.c_str()); memset(modules, 0, nElements * sizeof(HMODULE));
if (SUCCEEDED(RmRegisterResources(sessionHnd, if (EnumProcessModules(processHnd,
UINT(resources.size()), modules,
resources.data(), nElements * sizeof(HMODULE),
0, &needed)) {
nullptr, size_t nModules =
0, std::min<DWORD>(needed / sizeof(HMODULE), nElements);
nullptr))) {
UINT nProcInfoNeeded = 0;
UINT nProcInfo = 0;
DWORD rebootReasons = 0;
if (SUCCEEDED(RmGetList(sessionHnd, for (size_t j = 0; j < nModules; j++) {
&nProcInfoNeeded, WCHAR moduleName[MAX_PATH];
&nProcInfo, memset(moduleName, 0, MAX_PATH * sizeof(WCHAR));
nullptr,
&rebootReasons))) {
nProcInfo = nProcInfoNeeded;
nProcInfoNeeded = 0;
rebootReasons = 0;
std::vector<RM_PROCESS_INFO> affectedApps(nProcInfo);
if (SUCCEEDED(RmGetList(sessionHnd, if (GetModuleFileNameExW(processHnd,
&nProcInfoNeeded, modules[j],
&nProcInfo, moduleName,
affectedApps.data(), MAX_PATH)) {
&rebootReasons))) { auto pluginsIt = std::find(pluginsPaths.begin(),
for (UINT i = 0; i < nProcInfo; i++) { pluginsPaths.end(),
auto pid = affectedApps[i].Process.dwProcessId; std::wstring(moduleName));
auto it = std::find(pids.begin(), pids.end(), pid);
if (pid > 0 && it == pids.end() && pid != currentPid) if (pluginsIt != pluginsPaths.end()) {
pids.push_back(pid); auto pidsIt = std::find(pids.begin(),
pids.end(),
process[i]);
if (process[i] > 0
&& pidsIt == pids.end()
&& process[i] != currentPid)
pids.push_back(process[i]);
} }
} }
} }
} }
RmEndSession(sessionHnd); CloseHandle(processHnd);
} }
return pids; return pids;