Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Krautz <mikkel@krautz.dk>2017-03-19 23:35:13 +0300
committerMikkel Krautz <mikkel@krautz.dk>2017-03-19 23:35:13 +0300
commitbe43c91f4fe60e280c21a89fdce0948c28b9a63e (patch)
tree2510d98ff2577099dcacb9b8f0bbfb7688a8f867 /overlay
parent88bfbbb3c3d96b3d5042a898261e05c33bd3b7d2 (diff)
overlay: add ancestor.cpp/.h, utilities for getting process ancestor info.
This new module exposes the GetProcessAncestorChain() function. This function is going to be used by the new exclusion check module to implement the launcher filter.
Diffstat (limited to 'overlay')
-rw-r--r--overlay/ancestor.cpp132
-rw-r--r--overlay/ancestor.h16
-rw-r--r--overlay/overlay-shared.pro4
3 files changed, 150 insertions, 2 deletions
diff --git a/overlay/ancestor.cpp b/overlay/ancestor.cpp
new file mode 100644
index 000000000..0800b4574
--- /dev/null
+++ b/overlay/ancestor.cpp
@@ -0,0 +1,132 @@
+// Copyright 2005-2017 The Mumble Developers. All rights reserved.
+// Use of this source code is governed by a BSD-style license
+// that can be found in the LICENSE file at the root of the
+// Mumble source tree or at <https://www.mumble.info/LICENSE>.
+
+#include "lib.h"
+
+#include <tlhelp32.h>
+
+#include <string>
+#include <vector>
+
+/// Find the PROCESSENTRY32 entry for the parent of the process with the |childpid| PID.
+///
+/// Returns true on success, and fills out |parent| with the correct PROCESSENTRY32.
+/// Returns false on failure, and does not touch |parent|.
+static bool findParentProcessForChild(DWORD childpid, PROCESSENTRY32 *parent) {
+ DWORD parentpid = 0;
+ HANDLE hSnap = NULL;
+ bool done = false;
+
+ PROCESSENTRY32 pe;
+ pe.dwSize = sizeof(pe);
+
+ MODULEENTRY32 me;
+ me.dwSize = sizeof(me);
+
+ // Find our parent's process ID.
+ {
+ BOOL ok = FALSE;
+
+ hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (hSnap == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+ ok = Process32First(hSnap, &pe);
+ while (ok) {
+ if (pe.th32ProcessID == childpid) {
+ parentpid = pe.th32ParentProcessID;
+ break;
+ }
+ ok = Process32Next(hSnap, &pe);
+ }
+ CloseHandle(hSnap);
+ }
+
+ if (parentpid == 0) {
+ return false;
+ }
+
+ // Find our parent's name.
+ {
+ BOOL ok = FALSE;
+
+ hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (hSnap == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+ ok = Process32First(hSnap, &pe);
+ while (ok) {
+ if (pe.th32ProcessID == parentpid) {
+ memcpy(parent, &pe, sizeof(pe));
+ ok = FALSE;
+ done = true;
+ break;
+ }
+ ok = Process32Next(hSnap, &pe);
+ }
+ CloseHandle(hSnap);
+ }
+
+ return done;
+}
+
+/// Find the MODULEENTRY32 for the PROCESSENTRY32 |parent|.
+/// The MODULEENTRY32 allows us to access the absolute path of the parent executable.
+///
+/// Returns true on success, and fills out |module| with the proper MODULEENTRY32 entry.
+/// Returns false on failure, and does not touch |module|.
+static bool getModuleForParent(PROCESSENTRY32 *parent, MODULEENTRY32 *module) {
+ HANDLE hSnap = NULL;
+ bool done = false;
+
+ MODULEENTRY32 me;
+ me.dwSize = sizeof(me);
+
+ hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE32 | TH32CS_SNAPMODULE, parent->th32ProcessID);
+ if (hSnap == INVALID_HANDLE_VALUE) {
+ goto out;
+ }
+
+ if (!Module32First(hSnap, &me)) {
+ goto out;
+ }
+
+ memcpy(module, &me, sizeof(me));
+ done = true;
+
+out:
+ CloseHandle(hSnap);
+ return done;
+}
+
+bool GetProcessAncestorChain(std::vector<std::string> &absAncestorExeNames, std::vector<std::string> &ancestorExeNames) {
+ PROCESSENTRY32 parent;
+ MODULEENTRY32 module;
+
+ std::vector<std::string> abs;
+ std::vector<std::string> rel;
+
+ bool ok = true;
+ DWORD childpid = GetCurrentProcessId();
+ while (ok) {
+ ok = findParentProcessForChild(childpid, &parent);
+ if (ok) {
+ ok = getModuleForParent(&parent, &module);
+ if (ok) {
+ abs.push_back(std::string(module.szExePath));
+ rel.push_back(std::string(parent.szExeFile));
+ childpid = parent.th32ProcessID;
+ }
+ }
+ }
+
+ ok = abs.size() > 0;
+ if (ok) {
+ absAncestorExeNames = abs;
+ ancestorExeNames = rel;
+ }
+
+ return ok;
+}
diff --git a/overlay/ancestor.h b/overlay/ancestor.h
new file mode 100644
index 000000000..3023d8f0b
--- /dev/null
+++ b/overlay/ancestor.h
@@ -0,0 +1,16 @@
+// Copyright 2005-2017 The Mumble Developers. All rights reserved.
+// Use of this source code is governed by a BSD-style license
+// that can be found in the LICENSE file at the root of the
+// Mumble source tree or at <https://www.mumble.info/LICENSE>.
+
+#ifndef MUMBLE_ANCESTOR_H_
+#define MUMBLE_ANCESTOR_H_
+
+/// Return the absolute and relative exe names of this process's ancestors in
+/// |absAncestorExeNames| and |ancestorExeNames|.
+///
+/// Returns true on success and fills out |absAncestorExeNames| and |ancestorExeNames|.
+/// Returns false on failure, and does not change |absAncestorExeNames| and |ancestorExeNames|.
+bool GetProcessAncestorChain(std::vector<std::string> &absAncestorExeNames, std::vector<std::string> &ancestorExeNames);
+
+#endif
diff --git a/overlay/overlay-shared.pro b/overlay/overlay-shared.pro
index 266339674..bc9caa6de 100644
--- a/overlay/overlay-shared.pro
+++ b/overlay/overlay-shared.pro
@@ -13,8 +13,8 @@ CONFIG *= dll shared debug_and_release warn_on
CONFIG -= embed_manifest_dll
TARGET = mumble_ol
RC_FILE = mumble_ol.rc
-SOURCES = lib.cpp d3d9.cpp dxgi.cpp d3d10.cpp d3d11.cpp ods.cpp opengl.cpp HardHook.cpp D11StateBlock.cpp
-HEADERS = lib.h ods.h HardHook.h overlay_blacklist.h D11StateBlock.h ../3rdparty/GL/glext.h
+SOURCES = ancestor.cpp lib.cpp d3d9.cpp dxgi.cpp d3d10.cpp d3d11.cpp ods.cpp opengl.cpp HardHook.cpp D11StateBlock.cpp
+HEADERS = ancestor.h lib.h ods.h HardHook.h overlay_blacklist.h D11StateBlock.h ../3rdparty/GL/glext.h
EFFECTS = overlay.fx
DX11_PIXEL_SHADERS = overlay11.ps
DX11_VERTEX_SHADERS = overlay11.vs