From dbccdcdcca24e04282e1d4558dc3b1935b6e6737 Mon Sep 17 00:00:00 2001 From: Alexey Vereschagin Date: Thu, 13 Sep 2018 02:35:27 +0300 Subject: [PATCH] Implement injectLibrary() function --- NativeLauncher/launcher/injection.cc | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/launcher/injection.cc b/NativeLauncher/launcher/injection.cc index 6aeaa61..31134f6 100644 --- a/NativeLauncher/launcher/injection.cc +++ b/NativeLauncher/launcher/injection.cc @@ -19,9 +19,36 @@ #include #include +#include + static int injectLibrary(const char path[]) { - return 0; + typedef int inject_func(); + + int res = -1; + void *lib = nullptr; + inject_func *inject = nullptr; + const char *inject_sym = "dotnet_launcher_inject"; + + _INFO("Inject %s library", path); + + // FIXME: remove RTLD_GLOBAL? + lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL); + if (lib == nullptr) { + _ERR("%s", dlerror()); + goto ret; + } + + inject = reinterpret_cast(dlsym(lib, inject_sym)); + if (inject == nullptr) { + _ERR("%s is not found in the %s", inject_sym, path); + goto ret; + } + + res = inject(); + +ret: + return res; } int doInjection() -- 2.34.1