1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <err.h>
#include <dlfcn.h>
#include <err.h>
#include "jvm/jni.h"
jstring
java_lang_System_getProperty(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
char value[92];
const char *key = (*env)->GetStringUTFChars(env, va_arg(args, jstring), NULL);
union {
void *ptr;
int (*fun)(const char*, char*);
} __system_property_get;
if (!(__system_property_get.ptr = dlsym(RTLD_DEFAULT, "__system_property_get")))
return NULL;
__system_property_get.fun(key, value);
return (*env)->NewStringUTF(env, value);
}
void
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);
struct {
union {
void *ptr;
void* (*fun)(const char*, int);
} open;
union {
void *ptr;
void* (*fun)(void*, const char*);
} sym;
} dl;
if (!(dl.open.ptr = dlsym(RTLD_DEFAULT, "bionic_dlopen")) || !(dl.sym.ptr = dlsym(RTLD_DEFAULT, "bionic_dlsym"))) {
dl.open.fun = dlopen;
dl.sym.fun = dlsym;
}
void *handle;
if (!(handle = dl.open.fun(lib, RTLD_NOW | RTLD_GLOBAL))) {
warnx("java/lang/System/load: failed to dlopen `%s`", lib);
return;
}
union {
void *ptr;
void* (*fun)(void*, void*);
} JNI_OnLoad;
if ((JNI_OnLoad.ptr = dl.sym.fun(handle, "JNI_OnLoad"))) {
JavaVM *vm;
(*env)->GetJavaVM(env, &vm);
JNI_OnLoad.fun(vm, NULL);
}
}
jobject
java_lang_ClassLoader_findLibrary(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
XXX
char lib[255];
snprintf(lib, sizeof(lib), "lib%s.so", (*env)->GetStringUTFChars(env, va_arg(args, jstring), NULL));
return (*env)->NewStringUTF(env, lib);
}
jobject
java_lang_Class_getClassLoader(JNIEnv *env, jobject object)
{
assert(env && object);
static jobject sv;
return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/lang/ClassLoader"))));
}
jclass
java_lang_Class_forName(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
jstring str = va_arg(args, jstring);
const char *utf = (*env)->GetStringUTFChars(env, str, NULL);
return (*env)->FindClass(env, utf);
}
jstring
java_lang_Class_getName(JNIEnv *env, jobject object)
{
assert(env && object);
{
struct {
union {
void *ptr;
struct jvm* (*fun)(JNIEnv*);
} jnienv_get_jvm;
union {
void *ptr;
const char* (*fun)(const struct jvm*, jobject);
} jvm_get_class_name;
} jvm;
if ((jvm.jnienv_get_jvm.ptr = dlsym(RTLD_DEFAULT, "jnienv_get_jvm")) && (jvm.jvm_get_class_name.ptr = dlsym(RTLD_DEFAULT, "jvm_get_class_name"))) {
struct jvm *jvm_ = jvm.jnienv_get_jvm.fun(env);
return (*env)->NewStringUTF(env, jvm.jvm_get_class_name.fun(jvm_, object));
}
}
warnx("%s: returning NULL, as running in unknown JVM and don't know how to get class name", __func__);
return NULL;
}
jclass
java_lang_Object_getClass(JNIEnv *env, jobject object)
{
assert(env && object);
return (*env)->GetObjectClass(env, object);
}
jstring
java_io_File_getPath(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
FIXME
#if WOLF
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.swiftappskom.thewolfrpg/files");
#elif STARLIGHT
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/jp.co.bandainamcoent.BNEI0242/files");
#elif SHADOWVERSE
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.cygames.Shadowverse/files");
#elif HEARTHSTONE
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.blizzard.wtcg.hearthstone/files");
#else
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.miHoYo.bh3oversea/files");
#endif
}
jstring
java_io_File_getParent(JNIEnv *env, jobject object, va_list args)
{
#if WOLF
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.swiftappskom.thewolfrpg");
#elif STARLIGHT
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/jp.co.bandainamcoent.BNEI0242");
#elif SHADOWVERSE
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.cygames.Shadowverse");
#elif HEARTHSTONE
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.blizzard.wtcg.hearthstone");
#else
return (*env)->NewStringUTF(env, "/mnt/media/dev/android2gnulinux/local/data/com.miHoYo.bh3oversea");
#endif
}
jboolean
java_lang_String_equals(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
jstring str = va_arg(args, jstring);
const char *utf1 = (*env)->GetStringUTFChars(env, object, NULL);
const char *utf2 = (*env)->GetStringUTFChars(env, str, NULL);
const jboolean equal = (utf1 == utf2 || (utf1 && utf2 && !strcmp(utf1, utf2)));
(*env)->ReleaseStringUTFChars(env, object, utf1);
(*env)->ReleaseStringUTFChars(env, str, utf2);
return equal;
}
jbyteArray
java_lang_String_getBytes(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
const char *utf = (*env)->GetStringUTFChars(env, object, NULL);
const size_t len = strlen(utf);
jbyteArray bytes = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)utf);
return bytes;
}
jstring
java_util_Locale_getLanguage(JNIEnv *env, jobject object)
{
assert(env && object);
return (*env)->NewStringUTF(env, "en");
}
jstring
java_util_Locale_getCountry(JNIEnv *env, jobject object)
{
assert(env && object);
return (*env)->NewStringUTF(env, "US");
}
|