From efd90a90d15f15353c65c69eeb2336bd8b72c604 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 1 Jan 2023 12:16:31 +0100 Subject: [PATCH] fix(inject): add possibility to inject multiple .NET runtime dlls without crashing --- src/Inject/NosSmooth.Inject/nossmooth.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Inject/NosSmooth.Inject/nossmooth.cpp b/src/Inject/NosSmooth.Inject/nossmooth.cpp index 75e37b7..e9b6f24 100644 --- a/src/Inject/NosSmooth.Inject/nossmooth.cpp +++ b/src/Inject/NosSmooth.Inject/nossmooth.cpp @@ -42,8 +42,11 @@ void* get_export(void*, const char*); void* load_library(const char_t* path) { - HMODULE h = ::LoadLibraryW(path); - assert(h != nullptr); + HMODULE h = ::GetModuleHandleW(path); + if (h == nullptr) { + h = ::LoadLibraryW(path); + assert(h != nullptr); + } return (void*)h; } void* get_export(void* h, const char* name) @@ -79,7 +82,7 @@ load_assembly_and_get_function_pointer_fn get_dotnet_load_assembly(const char_t* void* load_assembly_and_get_function_pointer = nullptr; hostfxr_handle cxt = nullptr; int rc = init_fptr(config_path, nullptr, &cxt); - if (rc != 0 || cxt == nullptr) + if (rc > 1 || cxt == nullptr) { std::cerr << "Init failed: " << std::hex << std::showbase << rc << std::endl; close_fptr(cxt); -- 2.48.1