win-capture: Create all named objects within hook

All named objects (including file mapped shared memory) need to be
created within the hook itself due to the fact that UWP programs cannot
access named objects outside of the UWP process.

Because shared memory needs to be created within the hook, the capture
loop cannot start until the shared memory has been filled with valid
data.  Creating an additional "initialize" event fixes this issue.

Additionally, changed the way that named kernel objects are
opened/created.  Before, there were functions that would first try to
open named objects and then implicitly create them if opening failed
(assuming that if the hook didn't create it first, game capture would),
now it's been changed so that you can only either explicitly open or
create.
This commit is contained in:
jp9000
2016-11-01 00:21:42 -07:00
parent d19342442f
commit ab9bda52e0
4 changed files with 103 additions and 63 deletions

View File

@@ -31,6 +31,7 @@ HANDLE signal_restart = NULL;
HANDLE signal_stop = NULL;
HANDLE signal_ready = NULL;
HANDLE signal_exit = NULL;
static HANDLE signal_init = NULL;
HANDLE tex_mutexes[2] = {NULL, NULL};
static HANDLE filemap_hook_info = NULL;
@@ -75,7 +76,7 @@ bool init_pipe(void)
static HANDLE init_event(const char *name, DWORD pid)
{
HANDLE handle = get_event_plus_id(name, pid);
HANDLE handle = create_event_plus_id(name, pid);
if (!handle)
hlog("Failed to get event '%s': %lu", name, GetLastError());
return handle;
@@ -83,12 +84,7 @@ static HANDLE init_event(const char *name, DWORD pid)
static HANDLE init_mutex(const char *name, DWORD pid)
{
char new_name[64];
HANDLE handle;
sprintf(new_name, "%s%lu", name, pid);
handle = OpenMutexA(SYNCHRONIZE, false, new_name);
HANDLE handle = create_mutex_plus_id(name, pid);
if (!handle)
hlog("Failed to open mutex '%s': %lu", name, GetLastError());
return handle;
@@ -118,6 +114,11 @@ static inline bool init_signals(void)
return false;
}
signal_init = init_event(EVENT_HOOK_INIT, pid);
if (!signal_init) {
return false;
}
return true;
}
@@ -163,7 +164,7 @@ static inline void log_current_process(void)
static inline bool init_hook_info(void)
{
filemap_hook_info = get_hook_info(GetCurrentProcessId());
filemap_hook_info = create_hook_info(GetCurrentProcessId());
if (!filemap_hook_info) {
hlog("Failed to create hook info file mapping: %lu",
GetLastError());
@@ -238,16 +239,6 @@ static inline bool init_hook(HANDLE thread_handle)
WINDOW_HOOK_KEEPALIVE, GetCurrentProcessId());
init_pipe();
if (!init_signals()) {
return false;
}
init_mutexes();
if (!init_system_path()) {
return false;
}
if (!init_hook_info()) {
return false;
}
init_dummy_window_thread();
log_current_process();
@@ -380,6 +371,8 @@ static inline bool attempt_hook(void)
static inline void capture_loop(void)
{
WaitForSingleObject(signal_init, INFINITE);
while (!attempt_hook())
Sleep(40);
@@ -796,6 +789,19 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID unused1)
if (!success)
DbgOut("Failed to get current thread handle");
if (!init_signals()) {
return false;
}
if (!init_system_path()) {
return false;
}
if (!init_hook_info()) {
return false;
}
if (!init_mutexes()) {
return false;
}
/* this prevents the library from being automatically unloaded
* by the next FreeLibrary call */
GetModuleFileNameW(hinst, name, MAX_PATH);