summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--src/jvm/jvm.c20
-rw-r--r--src/libjvm-android.c138
-rw-r--r--src/libjvm-java.c27
-rw-r--r--src/libjvm-jnibridge.c11
-rw-r--r--src/wrapper/wrapper.c3
6 files changed, 27 insertions, 178 deletions
diff --git a/Makefile b/Makefile
index 898decf..b21f2e6 100644
--- a/Makefile
+++ b/Makefile
@@ -51,12 +51,10 @@ jvm.a: wrapper.a src/jvm/jvm.c
runtime/libjvm-java.so: private CPPFLAGS += -D_GNU_SOURCE
runtime/libjvm-java.so: runtime verbose src/libjvm-java.c
runtime/libjvm-android.so: runtime verbose src/libjvm-android.c
-runtime/libjvm-unity.so: runtime verbose src/libjvm-unity.c
-runtime/libjvm-jnibridge.so: runtime src/libjvm-jnibridge.c
-java: runtime/libjvm-java.so runtime/libjvm-android.so runtime/libjvm-unity.so runtime/libjvm-jnibridge.so
+java: runtime/libjvm-java.so runtime/libjvm-android.so
app: private LDLIBS += -ldl -Wl,-rpath,runtime runtime/libdl.so runtime/libpthread.so
-app: private LDLIBS += runtime/libjvm-java.so runtime/libjvm-android.so runtime/libjvm-unity.so runtime/libjvm-jnibridge.so
+app: private LDLIBS += runtime/libjvm-java.so runtime/libjvm-android.so
app: wrapper.a src/app.c native jvm.a java
install-bin: $(bins)
diff --git a/src/jvm/jvm.c b/src/jvm/jvm.c
index 8c1e44e..701f876 100644
--- a/src/jvm/jvm.c
+++ b/src/jvm/jvm.c
@@ -503,7 +503,7 @@ JNIEnv_CallObjectMethodV(JNIEnv *p0, jobject p1, jmethodID p2, va_list p3)
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), p2, symbol, sizeof(symbol));
jobject (*fun)(JNIEnv*, jobject, va_list) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- return fun(p0, p1, p3);
+ return (fun ? fun(p0, p1, p3) : NULL);
}
static jobject
@@ -533,7 +533,7 @@ JNIEnv_CallBooleanMethodV(JNIEnv* p0, jobject p1, jmethodID p2, va_list p3)
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), p2, symbol, sizeof(symbol));
jboolean (*fun)(JNIEnv*, jobject, va_list) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- return fun(p0, p1, p3);
+ return (fun ? fun(p0, p1, p3) : false);
}
static jboolean
@@ -653,7 +653,7 @@ JNIEnv_CallIntMethodV(JNIEnv* p0, jobject p1, jmethodID p2, va_list p3)
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), p2, symbol, sizeof(symbol));
jint (*fun)(JNIEnv*, jobject, va_list) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- return fun(p0, p1, p3);
+ return (fun ? fun(p0, p1, p3) : 0);
}
static jint
@@ -771,8 +771,9 @@ JNIEnv_CallVoidMethodV(JNIEnv* p0, jobject p1, jmethodID p2, va_list p3)
assert(p0 && p1 && p2);
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), p2, symbol, sizeof(symbol));
- void (*fun)(JNIEnv*, jobject, va_list) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- fun(p0, p1, p3);
+ void (*fun)(JNIEnv*, jobject, va_list);
+ if ((fun = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol))))
+ fun(p0, p1, p3);
}
static void
@@ -1211,7 +1212,7 @@ JNIEnv_CallStaticObjectMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), p2, symbol, sizeof(symbol));
jobject (*fun)(JNIEnv*, jobject, va_list) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- return fun(p0, p1, p3);
+ return (fun ? fun(p0, p1, p3) : NULL);
}
static jobject
@@ -1479,8 +1480,9 @@ JNIEnv_CallStaticVoidMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
assert(p0 && p1 && p2);
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), p2, symbol, sizeof(symbol));
- void (*fun)(JNIEnv*, jobject, va_list) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- fun(p0, p1, p3);
+ void (*fun)(JNIEnv*, jobject, va_list);
+ if ((fun = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol))))
+ fun(p0, p1, p3);
}
static void
@@ -1505,7 +1507,7 @@ JNIEnv_GetStaticObjectField(JNIEnv* p0, jclass p1, jfieldID p2)
char symbol[255];
jvm_form_symbol(jnienv_get_jvm(p0), (jmethodID)p2, symbol, sizeof(symbol));
jobject (*fun)(JNIEnv*, jobject) = wrapper_create(symbol, dlsym(RTLD_DEFAULT, symbol));
- return fun(p0, p1);
+ return (fun ? fun(p0, p1) : NULL);
}
static jboolean
diff --git a/src/libjvm-android.c b/src/libjvm-android.c
index dda4dd7..60219db 100644
--- a/src/libjvm-android.c
+++ b/src/libjvm-android.c
@@ -2,7 +2,6 @@
#include <stdio.h>
#include <assert.h>
#include "jvm/jni.h"
-#include "wrapper/verbose.h"
jstring
android_os_Build_MANUFACTURER(JNIEnv *env, jobject object)
@@ -24,121 +23,37 @@ android_os_Build_PRODUCT(JNIEnv *env, jobject object)
}
jstring
-android_content_Context_getPackageName(JNIEnv *env, jobject object, va_list args)
+android_os_Build_ID(JNIEnv *env, jobject object)
{
- assert(env && object);
- return (*env)->NewStringUTF(env, "com.gnu.linux");
+ return android_os_Build_MANUFACTURER(env, object);
}
jstring
-android_content_Context_getPackageCodePath(JNIEnv *env, jobject object, va_list args)
+android_os_Build_VERSION_RELEASE(JNIEnv *env, jobject object)
{
assert(env && object);
- return (*env)->NewStringUTF(env, ".");
+ return (*env)->NewStringUTF(env, "4.4.4");
}
jstring
-android_content_Context_POWER_SERVICE(JNIEnv *env, jobject object)
+android_os_Build_VERSION_INCREMENTAL(JNIEnv *env, jobject object)
{
assert(env && object);
- return (*env)->NewStringUTF(env, "power");
+ return (*env)->NewStringUTF(env, "0"); // XXX: maybe git sha of this repo
}
jstring
-android_content_Context_WINDOW_SERVICE(JNIEnv *env, jobject object)
-{
- assert(env && object);
- return (*env)->NewStringUTF(env, "window");
-}
-
-jobject
-android_content_Context_getSystemService(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jstring str = va_arg(args, jstring);
- (*env)->GetStringUTFChars(env, str, NULL);
- return NULL;
-}
-
-jint
-android_content_Context_checkCallingOrSelfPermission(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jstring str = va_arg(args, jstring);
- (*env)->GetStringUTFChars(env, str, NULL);
- return -1; // PERMISSION_DENIED
-}
-
-jobject
-android_content_Context_getPackageManager(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/pm/PackageManager"))));
-}
-
-jobject
-android_content_pm_PackageManager_getApplicationInfo(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jstring str = va_arg(args, jstring);
- verbose("%s::%d", (*env)->GetStringUTFChars(env, str, NULL), va_arg(args, jint));
- static jobject sv;
- return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "android/content/pm/ApplicationInfo"))));
-}
-
-jobject
-android_content_Context_getSharedPreferences(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jstring str = va_arg(args, jstring);
- (*env)->GetStringUTFChars(env, str, NULL);
- verbose("%d", va_arg(args, jint));
- va_end(args);
- static jobject sv;
- return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "android/content/SharedPreferences"))));
-}
-
-jint
-android_content_SharedPreferences_getInt(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jstring str = va_arg(args, jstring);
- verbose("%s::%d", (*env)->GetStringUTFChars(env, str, NULL), va_arg(args, jint));
- va_end(args);
- return 0;
-}
-
-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)
+android_content_Context_getPackageName(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
- jstring str = va_arg(args, jstring);
- verbose("%s::%d", (*env)->GetStringUTFChars(env, str, NULL), va_arg(args, jint));
- va_end(args);
- return object;
+ return (*env)->NewStringUTF(env, "com.miHoYo.bh3oversea");
}
-void
-android_content_SharedPreferences_Editor_apply(JNIEnv *env, jobject object, va_list args)
+jstring
+android_content_Context_getPackageCodePath(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
+ return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/apks/honkai");
}
jobject
@@ -149,7 +64,6 @@ android_content_Context_getExternalFilesDir(JNIEnv *env, jobject object, va_list
// use `$XDG_DATA_HOME/android2gnulinux/appid` for the path
jstring str = va_arg(args, jstring);
(*env)->GetStringUTFChars(env, str, NULL);
- va_end(args);
static jobject sv;
return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/io/File"))));
}
@@ -161,33 +75,3 @@ android_content_Context_getFilesDir(JNIEnv *env, jobject object, va_list args)
static jobject sv;
return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/io/File"))));
}
-
-jobject
-android_app_ApplicationErrorReport_getErrorReportReceiver(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jobject obj = va_arg(args, jobject); // android.content.Context
- jstring str = va_arg(args, jstring);
- jint flags = va_arg(args, jint);
- (*env)->GetStringUTFChars(env, str, NULL);
- verbose("%p, %d", obj, flags);
- va_end(args);
- static jobject sv;
- return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "android/content/ComponentName"))));
-}
-
-jstring
-android_app_Activity_getPackageName(JNIEnv *env, jobject object, va_list args)
-{
- // FIXME: Maybe we should be able to handle java inheritance somehow
- // so we don't have to create these wrapper functions.
- return android_content_Context_getPackageName(env, object, args);
-}
-
-jstring
-android_net_Uri_encode(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- jstring str = va_arg(args, jstring);
- return str;
-}
diff --git a/src/libjvm-java.c b/src/libjvm-java.c
index a043a30..4e0902d 100644
--- a/src/libjvm-java.c
+++ b/src/libjvm-java.c
@@ -14,7 +14,6 @@ java_lang_System_load(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
const char *lib = (*env)->GetStringUTFChars(env, va_arg(args, jstring), NULL);
- va_end(args);
verbose("%s", lib);
void *handle = bionic_dlopen(lib, RTLD_NOW | RTLD_GLOBAL);
@@ -55,37 +54,13 @@ java_lang_ClassLoader_findLibrary(JNIEnv *env, jobject object, va_list args)
// fix if breaks anything because of this.
char lib[255];
snprintf(lib, sizeof(lib), "lib%s.so", (*env)->GetStringUTFChars(env, va_arg(args, jstring), NULL));
- va_end(args);
return (*env)->NewStringUTF(env, lib);
}
-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"))));
-}
-
-jboolean
-java_util_Iterator_hasNext(JNIEnv *env, jobject object, va_list args)
-{
- assert(env && object);
- return false;
-}
-
jstring
java_io_File_getPath(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
// FIXME: see comment on `android_content_Context_getExternalFilesDir`
- return (*env)->NewStringUTF(env, "tmp");
+ return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.miHoYo.bh3oversea/files");
}
diff --git a/src/libjvm-jnibridge.c b/src/libjvm-jnibridge.c
deleted file mode 100644
index b8c8592..0000000
--- a/src/libjvm-jnibridge.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#include <assert.h>
-#include "jvm/jni.h"
-
-jobject
-bitter_jnibridge_JNIBridge_newInterfaceProxy(JNIEnv *env, jobject object, va_list args)
-{
- static jobject sv;
- return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/lang/reflect/Proxy"))));
-}
diff --git a/src/wrapper/wrapper.c b/src/wrapper/wrapper.c
index a78026d..44e0802 100644
--- a/src/wrapper/wrapper.c
+++ b/src/wrapper/wrapper.c
@@ -59,7 +59,8 @@ trace(const char *const symbol)
void*
wrapper_create(const char *const symbol, void *function)
{
- assert(symbol && function);
+ assert(symbol);
+
#ifdef WRAPPER_TRACE
if (!__cxa_demangle.ptr)
__cxa_demangle.ptr = dlsym(RTLD_DEFAULT, "__cxa_demangle");