From 33a9a63787154facfdaddaf719e727947c159800 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Thu, 15 Feb 2018 00:59:08 +0200 Subject: Initial commit Stuff in src/linker will get rewritten from scratch eventually, it's all horrible. But for now focus is getting on shit work. --- src/app.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/app.c (limited to 'src/app.c') diff --git a/src/app.c b/src/app.c new file mode 100644 index 0000000..6dd8e10 --- /dev/null +++ b/src/app.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +extern void *apkenv_android_dlopen(const char*, int); +extern void *apkenv_android_dlclose(void*); +extern void *apkenv_android_dlsym(void*, const char*); +extern void apkenv_parse_library_path(const char *path, char *delim); + +int +main(int argc, const char *argv[]) +{ + if (argc < 2) + errx(EXIT_FAILURE, "usage: so-file"); + + dlopen("libpthread.so", RTLD_NOW | RTLD_GLOBAL); + + printf("loading: %s\n", argv[1]); + + char path[4096]; + snprintf(path, sizeof(path), "%s", argv[1]); + apkenv_parse_library_path(dirname(path), ";"); + + void *handle; + if (!(handle = apkenv_android_dlopen(argv[1], RTLD_NOW | RTLD_LOCAL))) + errx(EXIT_FAILURE, "dlopen failed: %s", dlerror()); + + printf("loaded: %s\n", argv[1]); + + void* (*JNI_OnLoad)(void*, void*) = apkenv_android_dlsym(handle, "JNI_OnLoad"); + assert(JNI_OnLoad); + + char data[1024]; + JNI_OnLoad(data, NULL); + + // apkenv_android_dlclose(handle); + return EXIT_SUCCESS; +} -- cgit v1.2.3-70-g09d2