summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--src/app.c1
-rw-r--r--src/jvm/jvm.c3
-rw-r--r--src/libjvm-android.c29
-rw-r--r--src/libjvm-java.c45
5 files changed, 78 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 951bca5..8597504 100644
--- a/Makefile
+++ b/Makefile
@@ -39,8 +39,9 @@ runtime/libandroid.so: runtime src/libandroid.c
runtime/liblog.so: runtime src/liblog.c
native: runtime/libc.so runtime/libpthread.so runtime/libandroid.so runtime/liblog.so
+runtime/libjvm-java.so: runtime src/libjvm-java.c
runtime/libjvm-android.so: runtime src/libjvm-android.c
-java: runtime/libjvm-android.so
+java: runtime/libjvm-java.so runtime/libjvm-android.so
linker.a: CFLAGS += -D_GNU_SOURCE -DANDROID_X86_LINKER -DLINKER_DEBUG=1
linker.a: CFLAGS += -Wno-pedantic -Wno-variadic-macros -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
diff --git a/src/app.c b/src/app.c
index 4e425d7..9a0d07e 100644
--- a/src/app.c
+++ b/src/app.c
@@ -20,6 +20,7 @@ main(int argc, const char *argv[])
printf("loading runtime\n");
if (!dlopen("libpthread.so", RTLD_NOW | RTLD_GLOBAL) ||
+ !dlopen("libjvm-java.so", RTLD_NOW | RTLD_GLOBAL) ||
!dlopen("libjvm-android.so", RTLD_NOW | RTLD_GLOBAL))
errx(EXIT_FAILURE, "%s", dlerror());
diff --git a/src/jvm/jvm.c b/src/jvm/jvm.c
index 6c1b244..130c017 100644
--- a/src/jvm/jvm.c
+++ b/src/jvm/jvm.c
@@ -175,7 +175,7 @@ jvm_find_object(struct jvm *jvm, const struct jvm_object *o)
return (jobject)(i + 1);
}
- return 0;
+ return NULL;
}
static jclass
@@ -493,6 +493,7 @@ jvm_form_symbol(struct jvm *jvm, jmethodID method_id, char *symbol, const size_t
printf("%s::%s::%s\n", jvm_get_object(jvm, method->klass)->klass.name.data, method->name.data, method->signature.data);
snprintf(symbol, symbol_sz, "%s_%s", jvm_get_object(jvm, method->klass)->klass.name.data, method->name.data);
cstr_replace(symbol, '/', '_');
+ cstr_replace(symbol, '$', '_');
}
static jobject
diff --git a/src/libjvm-android.c b/src/libjvm-android.c
index e633347..7cece38 100644
--- a/src/libjvm-android.c
+++ b/src/libjvm-android.c
@@ -17,5 +17,32 @@ android_content_Context_getSharedPreferences(JNIEnv *env, jobject object, va_lis
jstring str = va_arg(args, jstring);
printf("%s::%d\n", (*env)->GetStringUTFChars(env, str, NULL), va_arg(args, jint));
va_end(args);
- return (*env)->AllocObject(env, (*env)->FindClass(env, "android/content/SharedPreferences"));
+ static jobject sv;
+ return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "android/content/SharedPreferences"))));
+}
+
+jobject
+android_content_SharedPreferences_edit(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ static jobject sv;
+ return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "android/content/SharedPreferences/Editor"))));
+}
+
+jobject
+android_content_SharedPreferences_getAll(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ static jobject sv;
+ return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/util/Map"))));
+}
+
+jobject
+android_content_SharedPreferences_Editor_putInt(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ jstring str = va_arg(args, jstring);
+ printf("%s::%d\n", (*env)->GetStringUTFChars(env, str, NULL), va_arg(args, jint));
+ va_end(args);
+ return object;
}
diff --git a/src/libjvm-java.c b/src/libjvm-java.c
new file mode 100644
index 0000000..64dee13
--- /dev/null
+++ b/src/libjvm-java.c
@@ -0,0 +1,45 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <assert.h>
+#include "jvm/jni.h"
+
+jclass
+java_lang_Object_getClass(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ return (*env)->GetObjectClass(env, object);
+}
+
+jobject
+java_lang_Class_getClassLoader(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ static jobject sv;
+ return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/lang/ClassLoader"))));
+}
+
+jobject
+java_lang_ClassLoader_findLibrary(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ jstring str = va_arg(args, jstring);
+ printf("%s\n", (*env)->GetStringUTFChars(env, str, NULL));
+ va_end(args);
+ return NULL;
+}
+
+jobject
+java_util_Map_entrySet(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ static jobject sv;
+ return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/util/Set"))));
+}
+
+jobject
+java_util_Set_iterator(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ static jobject sv;
+ return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/util/Iterator"))));
+}