summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-02-19 13:12:57 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-02-19 13:12:57 +0200
commit535779b6ff5cd21590e5ed3aff3c9ae4c785e34d (patch)
tree0de3478713ad5c33d90f00194702e9520e33af7a /src
parent12f987e88031c5cbd9ff6534b9279b11219510ac (diff)
jvm: Implement more java apis
Diffstat (limited to 'src')
-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
4 files changed, 76 insertions, 2 deletions
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"))));
+}