Skip to content

Commit 64eb1dc

Browse files
FEAT: add support for Android Q
1 parent 43debbb commit 64eb1dc

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

whale/src/android/android_build.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define ANDROID_O 26
2121
#define ANDROID_O_MR1 27
2222
#define ANDROID_P 28
23+
#define ANDROID_Q 29
2324

2425
static inline int32_t GetAndroidApiLevel() {
2526
char prop_value[PROP_VALUE_MAX];

whale/src/android/art/art_runtime.cc

+21-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool ArtRuntime::OnLoad(JavaVM *vm, JNIEnv *env, jclass java_class) {
5454
}
5555
api_level_ = GetAndroidApiLevel();
5656
PreLoadRequiredStuff(env);
57-
const char *art_path = kLibArtPath;
57+
const char *art_path = api_level_ >= ANDROID_Q ? kLibArtPath_Q : kLibArtPath;
5858
art_elf_image_ = WDynamicLibOpen(art_path);
5959
if (art_elf_image_ == nullptr) {
6060
LOG(ERROR) << "Unable to read data from libart.so.";
@@ -70,6 +70,8 @@ bool ArtRuntime::OnLoad(JavaVM *vm, JNIEnv *env, jclass java_class) {
7070
size_t entrypoint_filed_size = (api_level_ <= ANDROID_LOLLIPOP) ? 8
7171
: kPointerSize;
7272
u4 expected_access_flags = kAccPrivate | kAccStatic | kAccNative;
73+
if (api_level_ >= ANDROID_Q)
74+
expected_access_flags |= kAccPublicApi;
7375
jmethodID reserved0 = env->GetStaticMethodID(java_class, kMethodReserved0, "()V");
7476
jmethodID reserved1 = env->GetStaticMethodID(java_class, kMethodReserved1, "()V");
7577

@@ -235,6 +237,9 @@ ArtRuntime::HookMethod(JNIEnv *env, jclass decl_class, jobject hooked_java_metho
235237
if (api_level_ >= ANDROID_P) {
236238
access_flags &= ~kAccCriticalNative_P;
237239
}
240+
if (api_level_ >= ANDROID_Q) {
241+
access_flags &= ~kAccFastInterpreterToInterpreterInvoke;
242+
}
238243
hooked_method.SetAccessFlags(access_flags);
239244
hooked_method.SetEntryPointFromQuickCompiledCode(
240245
class_linker_objects_.quick_generic_jni_trampoline_
@@ -457,6 +462,21 @@ ALWAYS_INLINE bool ArtRuntime::EnforceDisableHiddenAPIPolicyImpl() {
457462
if (symbol) {
458463
WInlineHookFunction(symbol, reinterpret_cast<void *>(OnInvokeHiddenAPI), nullptr);
459464
}
465+
// Android Q : Release version
466+
symbol = WDynamicLibSymbol(
467+
art_elf_image_,
468+
"_ZN3art9hiddenapi6detail28ShouldDenyAccessToMemberImplINS_8ArtFieldEEEbPT_NS0_7ApiListENS0_12AccessMethodE"
469+
);
470+
if (symbol) {
471+
WInlineHookFunction(symbol, reinterpret_cast<void *>(OnInvokeHiddenAPI), nullptr);
472+
}
473+
symbol = WDynamicLibSymbol(
474+
art_elf_image_,
475+
"_ZN3art9hiddenapi6detail28ShouldDenyAccessToMemberImplINS_9ArtMethodEEEbPT_NS0_7ApiListENS0_12AccessMethodE"
476+
);
477+
if (symbol) {
478+
WInlineHookFunction(symbol, reinterpret_cast<void *>(OnInvokeHiddenAPI), nullptr);
479+
}
460480
return symbol != nullptr;
461481
}
462482

whale/src/android/art/art_runtime.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
static constexpr const char *kAndroidLibDir = "/system/lib64/";
1818
static constexpr const char *kLibNativeBridgePath = "/system/lib64/libnativebridge.so";
1919
static constexpr const char *kLibArtPath = "/system/lib64/libart.so";
20+
static constexpr const char *kLibArtPath_Q = "/apex/com.android.runtime/lib64/libart.so";
2021
static constexpr const char *kLibAocPath = "/system/lib64/libaoc.so";
2122
static constexpr const char *kLibHoudiniArtPath = "/system/lib64/arm64/libart.so";
2223
#else
2324
static constexpr const char *kAndroidLibDir = "/system/lib/";
2425
static constexpr const char *kLibArtPath = "/system/lib/libart.so";
26+
static constexpr const char *kLibArtPath_Q = "/apex/com.android.runtime/lib/libart.so";
2527
static constexpr const char *kLibAocPath = "/system/lib/libaoc.so";
2628
static constexpr const char *kLibHoudiniArtPath = "/system/lib/arm/libart.so";
2729
#endif

whale/src/android/art/modifiers.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static constexpr uint32_t kAccFastNative = 0x00080000u; // method (dex only)
3838
static constexpr uint32_t kAccPreverified = kAccFastNative; // class (runtime)
3939
static constexpr uint32_t kAccSkipAccessChecks = kAccPreverified;
4040
static constexpr uint32_t kAccCriticalNative_P = 0x00200000; // method (runtime; native only)
41+
static constexpr uint32_t kAccFastInterpreterToInterpreterInvoke = 0x40000000;
4142
// Android M only
4243
static constexpr uint32_t kAccDontInline = 0x00400000u; // method (dex only)
4344
// Android N or later. Set by the verifier for a method we do not want the compiler to compile.

whale/src/platform/linux/process_map.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ForeachMemoryRange(std::function<bool(uintptr_t, uintptr_t, char *, char *)> cal
5858
break;
5959
sscanf(buf, "%lx-%lx %s %lx %s %ld %s", &begin, &end, perm,
6060
&foo, dev, &inode, mapname);
61-
if (!callback(begin, end, perm, mapname)) {
61+
if (!callback(begin - foo, end - foo, perm, mapname)) {
6262
break;
6363
}
6464
}

0 commit comments

Comments
 (0)