Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
support Android R DP4
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed May 8, 2020
1 parent 6f686e4 commit 5fb1bed
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 39 deletions.
6 changes: 3 additions & 3 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import java.security.MessageDigest

apply plugin: 'com.android.library'

def apiVersion = 6
def apiVersion = 7
def moduleProp = [
id : "riru-core",
name : "Riru (Riru - Core)",
version : "v21.1",
versionCode: "34",
version : "v21.2",
versionCode: "35",
author : "Rikka",
description: "Inject zygote process by replace libmemtrack.so, provide interface to other Riru modules."
]
Expand Down
137 changes: 109 additions & 28 deletions module/src/main/cpp/jni_native_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void nativeForkAndSpecialize_pre(
jobjectArray &rlimits, jint &mount_external, jstring &se_info, jstring &se_name,
jintArray &fdsToClose, jintArray &fdsToIgnore, jboolean &is_child_zygote,
jstring &instructionSet, jstring &appDataDir, jboolean &isTopApp, jobjectArray &pkgDataInfoList,
jboolean &bindMountAppStorageDirs) {
jobjectArray &whitelistedDataInfoList, jboolean &bindMountAppDataDirs, jboolean &bindMountAppStorageDirs) {

nativeForkAndSpecialize_calls_count++;

Expand All @@ -79,7 +79,13 @@ static void nativeForkAndSpecialize_pre(
if (!module->shouldSkipUid && shouldSkipUid(uid))
continue;

if (module->apiVersion >= 6) {
if (module->apiVersion >= 7) {
((nativeForkAndSpecialize_pre_v7_t *) module->forkAndSpecializePre)(
env, clazz, &uid, &gid, &gids, &runtime_flags, &rlimits, &mount_external,
&se_info, &se_name, &fdsToClose, &fdsToIgnore, &is_child_zygote,
&instructionSet, &appDataDir, &isTopApp, &pkgDataInfoList, &whitelistedDataInfoList,
&bindMountAppDataDirs, &bindMountAppStorageDirs);
} else if (module->apiVersion == 6) {
((nativeForkAndSpecialize_pre_v6_t *) module->forkAndSpecializePre)(
env, clazz, &uid, &gid, &gids, &runtime_flags, &rlimits, &mount_external,
&se_info, &se_name, &fdsToClose, &fdsToIgnore, &is_child_zygote,
Expand Down Expand Up @@ -148,15 +154,21 @@ static void nativeSpecializeAppProcess_pre(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtimeFlags,
jobjectArray rlimits, jint mountExternal, jstring seInfo, jstring niceName,
jboolean startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean &isTopApp, jobjectArray &pkgDataInfoList, jboolean &bindMountAppStorageDirs) {
jboolean &isTopApp, jobjectArray &pkgDataInfoList, jobjectArray &whitelistedDataInfoList,
jboolean &bindMountAppDataDirs, jboolean &bindMountAppStorageDirs) {

nativeSpecializeAppProcess_calls_count++;

for (auto module : *get_modules()) {
if (!module->specializeAppProcessPre)
continue;

if (module->apiVersion >= 6) {
if (module->apiVersion >= 7) {
((nativeSpecializeAppProcess_pre_v7_t *) module->specializeAppProcessPre)(
env, clazz, &uid, &gid, &gids, &runtimeFlags, &rlimits, &mountExternal, &seInfo,
&niceName, &startChildZygote, &instructionSet, &appDataDir, &isTopApp,
&pkgDataInfoList, &whitelistedDataInfoList, &bindMountAppDataDirs, &bindMountAppStorageDirs);
} else if (module->apiVersion >= 6) {
((nativeSpecializeAppProcess_pre_v6_t *) module->specializeAppProcessPre)(
env, clazz, &uid, &gid, &gids, &runtimeFlags, &rlimits, &mountExternal, &seInfo,
&niceName, &startChildZygote, &instructionSet, &appDataDir, &isTopApp,
Expand Down Expand Up @@ -239,12 +251,14 @@ jint nativeForkAndSpecialize_marshmallow(
jboolean is_child_zygote = JNI_FALSE;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_marshmallow_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -262,12 +276,14 @@ jint nativeForkAndSpecialize_oreo(
jboolean is_child_zygote = JNI_FALSE;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_oreo_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -285,12 +301,14 @@ jint nativeForkAndSpecialize_p(

jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_p_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -305,14 +323,38 @@ jint nativeForkAndSpecialize_r(
jobjectArray rlimits, jint mount_external, jstring se_info, jstring se_name,
jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
jstring instructionSet, jstring appDataDir, jboolean isTopApp, jobjectArray pkgDataInfoList,
jboolean bindMountAppStorageDirs) {
jobjectArray whitelistedDataInfoList, jboolean bindMountAppDataDirs, jboolean bindMountAppStorageDirs) {

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_r_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, se_name,
fdsToClose, fdsToIgnore, is_child_zygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

nativeForkAndSpecialize_post(env, clazz, uid, res);
return res;
}

jint nativeForkAndSpecialize_r_dp3(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags,
jobjectArray rlimits, jint mount_external, jstring se_info, jstring se_name,
jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
jstring instructionSet, jstring appDataDir, jboolean isTopApp, jobjectArray pkgDataInfoList,
jboolean bindMountAppStorageDirs) {

jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_r_dp3_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, se_name,
fdsToClose, fdsToIgnore, is_child_zygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
Expand All @@ -327,12 +369,14 @@ jint nativeForkAndSpecialize_r_dp2(
jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
jstring instructionSet, jstring appDataDir, jboolean isTopApp, jobjectArray pkgDataInfoList) {

jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_r_dp2_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -350,12 +394,14 @@ jint nativeForkAndSpecialize_samsung_p(

jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_samsung_p_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, category,
Expand All @@ -375,12 +421,14 @@ jint nativeForkAndSpecialize_samsung_o(
jboolean is_child_zygote = JNI_FALSE;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_samsung_o_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
Expand All @@ -400,12 +448,14 @@ jint nativeForkAndSpecialize_samsung_n(
jboolean is_child_zygote = JNI_FALSE;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_samsung_n_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
Expand All @@ -424,12 +474,14 @@ jint nativeForkAndSpecialize_samsung_m(
jboolean is_child_zygote = JNI_FALSE;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
instructionSet, appDataDir, isTopApp, pkgDataInfoList, whitelistedDataInfoList,
bindMountAppDataDirs, bindMountAppStorageDirs);

jint res = ((nativeForkAndSpecialize_samsung_m_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
Expand All @@ -448,12 +500,14 @@ void nativeSpecializeAppProcess_q(

jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

((nativeSpecializeAppProcess_q_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
Expand All @@ -466,14 +520,37 @@ void nativeSpecializeAppProcess_r(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtimeFlags,
jobjectArray rlimits, jint mountExternal, jstring seInfo, jstring niceName,
jboolean startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean isTopApp, jobjectArray pkgDataInfoList, jboolean bindMountAppStorageDirs) {
jboolean isTopApp, jobjectArray pkgDataInfoList, jobjectArray whitelistedDataInfoList,
jboolean bindMountAppDataDirs, jboolean bindMountAppStorageDirs) {

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

((nativeSpecializeAppProcess_r_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

nativeSpecializeAppProcess_post(env, clazz);
}

void nativeSpecializeAppProcess_r_dp3(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtimeFlags,
jobjectArray rlimits, jint mountExternal, jstring seInfo, jstring niceName,
jboolean startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean isTopApp, jobjectArray pkgDataInfoList, jboolean bindMountAppStorageDirs) {

jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

((nativeSpecializeAppProcess_r_dp3_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
Expand All @@ -487,12 +564,14 @@ void nativeSpecializeAppProcess_r_dp2(
jboolean startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean isTopApp, jobjectArray pkgDataInfoList) {

jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

((nativeSpecializeAppProcess_r_dp2_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
Expand All @@ -509,12 +588,14 @@ void nativeSpecializeAppProcess_samsung_q(

jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;
jobjectArray whitelistedDataInfoList = nullptr;
jboolean bindMountAppDataDirs = JNI_FALSE;
jboolean bindMountAppStorageDirs = JNI_FALSE;

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList,
bindMountAppStorageDirs);
whitelistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs);

((nativeSpecializeAppProcess_samsung_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, space,
Expand Down
Loading

0 comments on commit 5fb1bed

Please sign in to comment.