From 69c7a889b209f2b07766e210b44e5fb799c8bd86 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Thu, 12 Dec 2019 19:15:43 -0600 Subject: [PATCH] Fiixed CriticalSection and crash-on-exit --- Doorstop/Proxy/main.c | 11 +++++++++++ Doorstop/Proxy/mono.h | 5 ++++- IPA.Loader/Utilities/CriticalSection.cs | 7 +++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Doorstop/Proxy/main.c b/Doorstop/Proxy/main.c index 1184fc2d..a5be31dd 100644 --- a/Doorstop/Proxy/main.c +++ b/Doorstop/Proxy/main.c @@ -181,6 +181,17 @@ void *ownMonoJitInitVersion(const char *root_domain_name, const char *runtime_ve mono_install_unhandled_exception_hook(unhandledException, NULL); + wchar_t* dll_path_w; // self path + size_t dll_path_len = get_module_path((HINSTANCE)&__ImageBase, &dll_path_w, NULL, 0); + char* self_dll_path = memalloc(dll_path_len + 1); + WideCharToMultiByte(CP_UTF8, 0, dll_path_w, -1, self_dll_path, dll_path_len + 1, NULL, NULL); + + mono_dllmap_insert(NULL, "i:bsipa-doorstop", NULL, self_dll_path, NULL); // remap `bsipa-doorstop` to this assembly + + memfree(self_dll_path); + memfree(dll_path_w); + + unhandledMutex = CreateMutexW(NULL, FALSE, NULL); LOG("Invoking method!\n"); diff --git a/Doorstop/Proxy/mono.h b/Doorstop/Proxy/mono.h index a49357f8..f218adbe 100644 --- a/Doorstop/Proxy/mono.h +++ b/Doorstop/Proxy/mono.h @@ -40,7 +40,7 @@ typedef enum { void (*mono_jit_parse_options)(int argc, char * argv[]); void (*mono_debug_init)(MonoDebugFormat format); -void(*mono_debug_domain_create)(void*); +void (*mono_debug_domain_create)(void*); void *(*mono_jit_init_version)(const char *root_domain_name, const char *runtime_version); void *(*mono_domain_assembly_open)(void *domain, const char *name); @@ -61,6 +61,8 @@ void *(*mono_string_new_utf16)(void *domain, const wchar_t *text, INT32 len); void* (*mono_object_to_string)(void* obj, void** exc); +void (*mono_dllmap_insert)(void* assemblyImage, const char* dll, const char* func, const char* tdll, const char* tfunc); + char* (*mono_string_to_utf8)(void* str); void (*mono_free)(void*); @@ -101,5 +103,6 @@ inline void loadMonoFunctions(HMODULE monoLib) GET_MONO_PROC(mono_object_to_string); GET_MONO_PROC(mono_string_to_utf8); GET_MONO_PROC(mono_free); + GET_MONO_PROC(mono_dllmap_insert); GET_MONO_PROC(mono_install_unhandled_exception_hook); } diff --git a/IPA.Loader/Utilities/CriticalSection.cs b/IPA.Loader/Utilities/CriticalSection.cs index 1a3835be..3ef57d29 100644 --- a/IPA.Loader/Utilities/CriticalSection.cs +++ b/IPA.Loader/Utilities/CriticalSection.cs @@ -18,9 +18,6 @@ namespace IPA.Utilities { Logger.log.Debug("Configuring exit handlers"); - AppDomain.CurrentDomain.ProcessExit -= Reset; - AppDomain.CurrentDomain.ProcessExit += Reset; - ResetExitHandlers(); } @@ -52,7 +49,7 @@ namespace IPA.Utilities uint filterMax, ref Win32.PeekMessageParams removeMsg); - [DllImport("winhttp")] + [DllImport("bsipa-doorstop")] public static extern void SetPeekMessageHook( [MarshalAs(UnmanagedType.FunctionPtr)] PeekMessageHook hook); @@ -139,6 +136,8 @@ namespace IPA.Utilities _handler = null; isInExecuteSection = false; + Reset(null, null); + if (exitRecieved) Environment.Exit(1); }