geode/loader/dobby/builtin-plugin/BionicLinkerRestriction/linker_restriction_demo.cc

37 lines
846 B
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#include "dobby.h"
#include "bionic_linker_restriction.h"
#include "logging/logging.h"
#include <dlfcn.h>
#define LOG_TAG "AndroidLinkerRestriction"
__attribute__((constructor)) static void ctor() {
const char *lib = NULL;
#if defined(__LP64__)
lib = "/system/lib64/libandroid_runtime.so";
#else
lib = "/system/lib/libandroid_runtime.so";
#endif
void *vm = NULL;
vm = DobbySymbolResolver(lib, "_ZN7android14AndroidRuntime7mJavaVME");
LOG(1, "DobbySymbolResolver::vm %p", vm);
#if 0
linker_disable_namespace_restriction();
void *handle = NULL;
handle = dlopen(lib, RTLD_LAZY);
vm = dlsym(handle, "_ZN7android14AndroidRuntime7mJavaVME");
#else
void *handle = NULL;
handle = linker_dlopen(lib, RTLD_LAZY);
vm = dlsym(handle, "_ZN7android14AndroidRuntime7mJavaVME");
#endif
LOG(1, "vm %p", vm);
}