|
@@ -1,11 +1,10 @@
|
|
|
-#include <obs.h>
|
|
|
|
|
|
|
+#include "window-helpers.h"
|
|
|
|
|
+
|
|
|
#include <util/dstr.h>
|
|
#include <util/dstr.h>
|
|
|
|
|
+#include <util/windows/obfuscate.h>
|
|
|
|
|
|
|
|
#include <dwmapi.h>
|
|
#include <dwmapi.h>
|
|
|
#include <psapi.h>
|
|
#include <psapi.h>
|
|
|
-#include <windows.h>
|
|
|
|
|
-#include "window-helpers.h"
|
|
|
|
|
-#include "obfuscate.h"
|
|
|
|
|
|
|
|
|
|
static inline void encode_dstr(struct dstr *str)
|
|
static inline void encode_dstr(struct dstr *str)
|
|
|
{
|
|
{
|
|
@@ -22,8 +21,8 @@ static inline char *decode_str(const char *src)
|
|
|
return str.array;
|
|
return str.array;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-extern void build_window_strings(const char *str, char **class, char **title,
|
|
|
|
|
- char **exe)
|
|
|
|
|
|
|
+void ms_build_window_strings(const char *str, char **class, char **title,
|
|
|
|
|
+ char **exe)
|
|
|
{
|
|
{
|
|
|
char **strlist;
|
|
char **strlist;
|
|
|
|
|
|
|
@@ -46,6 +45,58 @@ extern void build_window_strings(const char *str, char **class, char **title,
|
|
|
strlist_free(strlist);
|
|
strlist_free(strlist);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void insert_preserved_val(obs_property_t *p, const char *val, size_t idx)
|
|
|
|
|
+{
|
|
|
|
|
+ char *window_class = NULL;
|
|
|
|
|
+ char *title = NULL;
|
|
|
|
|
+ char *executable = NULL;
|
|
|
|
|
+ struct dstr desc = {0};
|
|
|
|
|
+
|
|
|
|
|
+ ms_build_window_strings(val, &window_class, &title, &executable);
|
|
|
|
|
+
|
|
|
|
|
+ dstr_printf(&desc, "[%s]: %s", executable, title);
|
|
|
|
|
+ obs_property_list_insert_string(p, idx, desc.array, val);
|
|
|
|
|
+ obs_property_list_item_disable(p, idx, true);
|
|
|
|
|
+
|
|
|
|
|
+ dstr_free(&desc);
|
|
|
|
|
+ bfree(window_class);
|
|
|
|
|
+ bfree(title);
|
|
|
|
|
+ bfree(executable);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool ms_check_window_property_setting(obs_properties_t *ppts, obs_property_t *p,
|
|
|
|
|
+ obs_data_t *settings, const char *val,
|
|
|
|
|
+ size_t idx)
|
|
|
|
|
+{
|
|
|
|
|
+ const char *cur_val;
|
|
|
|
|
+ bool match = false;
|
|
|
|
|
+ size_t i = 0;
|
|
|
|
|
+
|
|
|
|
|
+ cur_val = obs_data_get_string(settings, val);
|
|
|
|
|
+ if (!cur_val) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (;;) {
|
|
|
|
|
+ const char *val = obs_property_list_item_string(p, i++);
|
|
|
|
|
+ if (!val)
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ if (strcmp(val, cur_val) == 0) {
|
|
|
|
|
+ match = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (cur_val && *cur_val && !match) {
|
|
|
|
|
+ insert_preserved_val(p, cur_val, idx);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ UNUSED_PARAMETER(ppts);
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static HMODULE kernel32(void)
|
|
static HMODULE kernel32(void)
|
|
|
{
|
|
{
|
|
|
static HMODULE kernel32_handle = NULL;
|
|
static HMODULE kernel32_handle = NULL;
|
|
@@ -60,13 +111,13 @@ static inline HANDLE open_process(DWORD desired_access, bool inherit_handle,
|
|
|
typedef HANDLE(WINAPI * PFN_OpenProcess)(DWORD, BOOL, DWORD);
|
|
typedef HANDLE(WINAPI * PFN_OpenProcess)(DWORD, BOOL, DWORD);
|
|
|
static PFN_OpenProcess open_process_proc = NULL;
|
|
static PFN_OpenProcess open_process_proc = NULL;
|
|
|
if (!open_process_proc)
|
|
if (!open_process_proc)
|
|
|
- open_process_proc = (PFN_OpenProcess)get_obfuscated_func(
|
|
|
|
|
|
|
+ open_process_proc = (PFN_OpenProcess)ms_get_obfuscated_func(
|
|
|
kernel32(), "B}caZyah`~q", 0x2D5BEBAF6DDULL);
|
|
kernel32(), "B}caZyah`~q", 0x2D5BEBAF6DDULL);
|
|
|
|
|
|
|
|
return open_process_proc(desired_access, inherit_handle, process_id);
|
|
return open_process_proc(desired_access, inherit_handle, process_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool get_window_exe(struct dstr *name, HWND window)
|
|
|
|
|
|
|
+bool ms_get_window_exe(struct dstr *name, HWND window)
|
|
|
{
|
|
{
|
|
|
wchar_t wname[MAX_PATH];
|
|
wchar_t wname[MAX_PATH];
|
|
|
struct dstr temp = {0};
|
|
struct dstr temp = {0};
|
|
@@ -103,7 +154,7 @@ fail:
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void get_window_title(struct dstr *name, HWND hwnd)
|
|
|
|
|
|
|
+void ms_get_window_title(struct dstr *name, HWND hwnd)
|
|
|
{
|
|
{
|
|
|
int len;
|
|
int len;
|
|
|
|
|
|
|
@@ -130,7 +181,7 @@ void get_window_title(struct dstr *name, HWND hwnd)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void get_window_class(struct dstr *class, HWND hwnd)
|
|
|
|
|
|
|
+void ms_get_window_class(struct dstr *class, HWND hwnd)
|
|
|
{
|
|
{
|
|
|
wchar_t temp[256];
|
|
wchar_t temp[256];
|
|
|
|
|
|
|
@@ -192,21 +243,21 @@ static void add_window(obs_property_t *p, HWND hwnd, add_window_cb callback)
|
|
|
struct dstr encoded = {0};
|
|
struct dstr encoded = {0};
|
|
|
struct dstr desc = {0};
|
|
struct dstr desc = {0};
|
|
|
|
|
|
|
|
- if (!get_window_exe(&exe, hwnd))
|
|
|
|
|
|
|
+ if (!ms_get_window_exe(&exe, hwnd))
|
|
|
return;
|
|
return;
|
|
|
if (is_microsoft_internal_window_exe(exe.array)) {
|
|
if (is_microsoft_internal_window_exe(exe.array)) {
|
|
|
dstr_free(&exe);
|
|
dstr_free(&exe);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- get_window_title(&title, hwnd);
|
|
|
|
|
|
|
+ ms_get_window_title(&title, hwnd);
|
|
|
if (dstr_cmp(&exe, "explorer.exe") == 0 && dstr_is_empty(&title)) {
|
|
if (dstr_cmp(&exe, "explorer.exe") == 0 && dstr_is_empty(&title)) {
|
|
|
dstr_free(&exe);
|
|
dstr_free(&exe);
|
|
|
dstr_free(&title);
|
|
dstr_free(&title);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- get_window_class(&class, hwnd);
|
|
|
|
|
|
|
+ ms_get_window_class(&class, hwnd);
|
|
|
|
|
|
|
|
if (callback && !callback(title.array, class.array, exe.array)) {
|
|
if (callback && !callback(title.array, class.array, exe.array)) {
|
|
|
dstr_free(&title);
|
|
dstr_free(&title);
|
|
@@ -268,7 +319,7 @@ static bool check_window_valid(HWND window, enum window_search_mode mode)
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool is_uwp_window(HWND hwnd)
|
|
|
|
|
|
|
+bool ms_is_uwp_window(HWND hwnd)
|
|
|
{
|
|
{
|
|
|
wchar_t name[256];
|
|
wchar_t name[256];
|
|
|
|
|
|
|
@@ -279,7 +330,7 @@ bool is_uwp_window(HWND hwnd)
|
|
|
return wcscmp(name, L"ApplicationFrameWindow") == 0;
|
|
return wcscmp(name, L"ApplicationFrameWindow") == 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-HWND get_uwp_actual_window(HWND parent)
|
|
|
|
|
|
|
+HWND ms_get_uwp_actual_window(HWND parent)
|
|
|
{
|
|
{
|
|
|
DWORD parent_id = 0;
|
|
DWORD parent_id = 0;
|
|
|
HWND child;
|
|
HWND child;
|
|
@@ -319,8 +370,8 @@ static HWND next_window(HWND window, enum window_search_mode mode, HWND *parent,
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (is_uwp_window(window)) {
|
|
|
|
|
- HWND child = get_uwp_actual_window(window);
|
|
|
|
|
|
|
+ if (ms_is_uwp_window(window)) {
|
|
|
|
|
+ HWND child = ms_get_uwp_actual_window(window);
|
|
|
if (child) {
|
|
if (child) {
|
|
|
*parent = window;
|
|
*parent = window;
|
|
|
return child;
|
|
return child;
|
|
@@ -357,8 +408,8 @@ static HWND first_window(enum window_search_mode mode, HWND *parent,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (is_uwp_window(window)) {
|
|
|
|
|
- HWND child = get_uwp_actual_window(window);
|
|
|
|
|
|
|
+ if (ms_is_uwp_window(window)) {
|
|
|
|
|
+ HWND child = ms_get_uwp_actual_window(window);
|
|
|
if (child) {
|
|
if (child) {
|
|
|
*parent = window;
|
|
*parent = window;
|
|
|
return child;
|
|
return child;
|
|
@@ -368,8 +419,8 @@ static HWND first_window(enum window_search_mode mode, HWND *parent,
|
|
|
return window;
|
|
return window;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void fill_window_list(obs_property_t *p, enum window_search_mode mode,
|
|
|
|
|
- add_window_cb callback)
|
|
|
|
|
|
|
+void ms_fill_window_list(obs_property_t *p, enum window_search_mode mode,
|
|
|
|
|
+ add_window_cb callback)
|
|
|
{
|
|
{
|
|
|
HWND parent;
|
|
HWND parent;
|
|
|
bool use_findwindowex = false;
|
|
bool use_findwindowex = false;
|
|
@@ -391,10 +442,10 @@ static int window_rating(HWND window, enum window_priority priority,
|
|
|
struct dstr cur_exe = {0};
|
|
struct dstr cur_exe = {0};
|
|
|
int val = 0x7FFFFFFF;
|
|
int val = 0x7FFFFFFF;
|
|
|
|
|
|
|
|
- if (!get_window_exe(&cur_exe, window))
|
|
|
|
|
|
|
+ if (!ms_get_window_exe(&cur_exe, window))
|
|
|
return 0x7FFFFFFF;
|
|
return 0x7FFFFFFF;
|
|
|
- get_window_title(&cur_title, window);
|
|
|
|
|
- get_window_class(&cur_class, window);
|
|
|
|
|
|
|
+ ms_get_window_title(&cur_title, window);
|
|
|
|
|
+ ms_get_window_class(&cur_class, window);
|
|
|
|
|
|
|
|
bool class_matches = dstr_cmpi(&cur_class, class) == 0;
|
|
bool class_matches = dstr_cmpi(&cur_class, class) == 0;
|
|
|
bool exe_matches = dstr_cmpi(&cur_exe, exe) == 0;
|
|
bool exe_matches = dstr_cmpi(&cur_exe, exe) == 0;
|
|
@@ -457,8 +508,8 @@ static bool is_generic_class(const char *current_class)
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-HWND find_window(enum window_search_mode mode, enum window_priority priority,
|
|
|
|
|
- const char *class, const char *title, const char *exe)
|
|
|
|
|
|
|
+HWND ms_find_window(enum window_search_mode mode, enum window_priority priority,
|
|
|
|
|
+ const char *class, const char *title, const char *exe)
|
|
|
{
|
|
{
|
|
|
HWND parent;
|
|
HWND parent;
|
|
|
bool use_findwindowex = false;
|
|
bool use_findwindowex = false;
|
|
@@ -520,9 +571,9 @@ BOOL CALLBACK enum_windows_proc(HWND window, LPARAM lParam)
|
|
|
return rating > 0;
|
|
return rating > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-HWND find_window_top_level(enum window_search_mode mode,
|
|
|
|
|
- enum window_priority priority, const char *class,
|
|
|
|
|
- const char *title, const char *exe)
|
|
|
|
|
|
|
+HWND ms_find_window_top_level(enum window_search_mode mode,
|
|
|
|
|
+ enum window_priority priority, const char *class,
|
|
|
|
|
+ const char *title, const char *exe)
|
|
|
{
|
|
{
|
|
|
if (!class)
|
|
if (!class)
|
|
|
return NULL;
|
|
return NULL;
|