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
Browse files Browse the repository at this point in the history
also remove things only for old Q beta
  • Loading branch information
RikkaW committed Apr 21, 2020
1 parent b00c901 commit 63b470f
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 103 deletions.
4 changes: 2 additions & 2 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def apiVersion = 5
def moduleProp = [
id : "riru-core",
name : "Riru (Riru - Core)",
version : "v20.0",
versionCode: "31",
version : "v20.1",
versionCode: "32",
author : "Rikka",
description: "Inject zygote process by replace libmemtrack.so, provide interface to other Riru modules."
]
Expand Down
139 changes: 68 additions & 71 deletions module/src/main/cpp/jni_native_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ static void nativeForkAndSpecialize_pre(
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, jstring &packageName,
jobjectArray &packagesForUID, jstring &sandboxId) {
jstring &instructionSet, jstring &appDataDir, jboolean &isTopApp, jobjectArray &pkgDataInfoList) {

nativeForkAndSpecialize_calls_count++;

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

if (module->apiVersion >= 3) {
if (module->apiVersion >= 5) {
((nativeForkAndSpecialize_pre_v5_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);
} else if (module->apiVersion >= 3) {
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;

((nativeForkAndSpecialize_pre_v3_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 @@ -133,17 +141,26 @@ static void nativeForkAndSpecialize_post(JNIEnv *env, jclass clazz, jint uid, ji
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, jstring packageName,
jobjectArray packagesForUID, jstring sandboxId) {
jboolean startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean &isTopApp, jobjectArray &pkgDataInfoList) {

nativeSpecializeAppProcess_calls_count++;

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

if (module->apiVersion >= 4) {
((nativeSpecializeAppProcess_pre_t *) module->specializeAppProcessPre)(
if (module->apiVersion >= 5) {
((nativeSpecializeAppProcess_pre_v5_t *) module->specializeAppProcessPre)(
env, clazz, &uid, &gid, &gids, &runtimeFlags, &rlimits, &mountExternal, &seInfo,
&niceName, &startChildZygote, &instructionSet, &appDataDir, &isTopApp,
&pkgDataInfoList);
} else if (module->apiVersion >= 4) {
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;

((nativeSpecializeAppProcess_pre_v4_t *) module->specializeAppProcessPre)(
env, clazz, &uid, &gid, &gids, &runtimeFlags, &rlimits, &mountExternal, &seInfo,
&niceName, &startChildZygote, &instructionSet, &appDataDir, &packageName,
&packagesForUID, &sandboxId);
Expand Down Expand Up @@ -209,14 +226,12 @@ jint nativeForkAndSpecialize_marshmallow(

jintArray fdsToIgnore = nullptr;
jboolean is_child_zygote = JNI_FALSE;
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_marshmallow_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -232,14 +247,12 @@ jint nativeForkAndSpecialize_oreo(
jintArray fdsToClose, jintArray fdsToIgnore, jstring instructionSet, jstring appDataDir) {

jboolean is_child_zygote = JNI_FALSE;
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_oreo_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -255,14 +268,12 @@ jint nativeForkAndSpecialize_p(
jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
jstring instructionSet, jstring appDataDir) {

jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_p_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, se_name,
Expand All @@ -272,22 +283,19 @@ jint nativeForkAndSpecialize_p(
return res;
}

jint nativeForkAndSpecialize_q_beta4(
jint nativeForkAndSpecialize_r(
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, jstring packageName,
jobjectArray packagesForUID, jstring sandboxId) {
jstring instructionSet, jstring appDataDir, jboolean isTopApp, jobjectArray pkgDataInfoList) {

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_q_beta4_t *) _nativeForkAndSpecialize)(
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, packageName,
packagesForUID, sandboxId);
fdsToClose, fdsToIgnore, is_child_zygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList);

nativeForkAndSpecialize_post(env, clazz, uid, res);
return res;
Expand All @@ -299,14 +307,12 @@ jint nativeForkAndSpecialize_samsung_p(
jstring se_name, jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
jstring instructionSet, jstring appDataDir) {

jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_samsung_p_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, category,
Expand All @@ -324,14 +330,12 @@ jint nativeForkAndSpecialize_samsung_o(
jstring appDataDir) {

jboolean is_child_zygote = JNI_FALSE;
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_samsung_o_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
Expand All @@ -349,14 +353,12 @@ jint nativeForkAndSpecialize_samsung_n(

jintArray fdsToIgnore = nullptr;
jboolean is_child_zygote = JNI_FALSE;
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_samsung_n_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
Expand All @@ -373,14 +375,12 @@ jint nativeForkAndSpecialize_samsung_m(

jintArray fdsToIgnore = nullptr;
jboolean is_child_zygote = JNI_FALSE;
jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
instructionSet, appDataDir, isTopApp, pkgDataInfoList);

jint res = ((nativeForkAndSpecialize_samsung_m_t *) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
Expand All @@ -392,57 +392,54 @@ jint nativeForkAndSpecialize_samsung_m(

// -----------------------------------------------------------------

void nativeSpecializeAppProcess_q_beta4(
void nativeSpecializeAppProcess(
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, jstring packageName,
jobjectArray packagesForUID, jstring sandboxId) {
jboolean startChildZygote, jstring instructionSet, jstring appDataDir) {

jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList);

((nativeSpecializeAppProcess_q_beta4_t *) _nativeSpecializeAppProcess)(
((nativeSpecializeAppProcess_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, packageName, packagesForUID,
sandboxId);
startChildZygote, instructionSet, appDataDir);

nativeSpecializeAppProcess_post(env, clazz);
}

void nativeSpecializeAppProcess(
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) {

jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean isTopApp, jobjectArray pkgDataInfoList) {

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, packageName, packagesForUID, sandboxId);
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList);

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

nativeSpecializeAppProcess_post(env, clazz);
}


void nativeSpecializeAppProcess_samsung(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtimeFlags,
jobjectArray rlimits, jint mountExternal, jstring seInfo, jint space, jint accessInfo,
jstring niceName, jboolean startChildZygote, jstring instructionSet, jstring appDataDir) {

jstring packageName = nullptr;
jobjectArray packagesForUID = nullptr;
jstring sandboxId = nullptr;
jboolean isTopApp = JNI_FALSE;
jobjectArray pkgDataInfoList = nullptr;

nativeSpecializeAppProcess_pre(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName,
startChildZygote, instructionSet, appDataDir, packageName, packagesForUID, sandboxId);
startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList);

((nativeSpecializeAppProcess_samsung_t *) _nativeSpecializeAppProcess)(
env, clazz, uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, space,
Expand Down
35 changes: 16 additions & 19 deletions module/src/main/cpp/jni_native_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@ jint nativeForkAndSpecialize_p(
jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
jstring instructionSet, jstring appDataDir);

// removed from beta5
const static char *nativeForkAndSpecialize_q_beta4_sig = "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)I";
const static char *nativeForkAndSpecialize_r_sig ="(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;)I";

using nativeForkAndSpecialize_q_beta4_t = jint(
using nativeForkAndSpecialize_r_t = jint(
JNIEnv *, jclass, jint, jint, jintArray, jint, jobjectArray, jint, jstring, jstring,
jintArray, jintArray, jboolean, jstring, jstring, jstring, jobjectArray, jstring);
jintArray, jintArray, jboolean, jstring, jstring, jboolean, jobjectArray);

jint nativeForkAndSpecialize_q_beta4(
jint nativeForkAndSpecialize_r(
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, jstring packageName,
jobjectArray packagesForUID, jstring sandboxId);
jstring instructionSet, jstring appDataDir, jboolean isTopApp, jobjectArray pkgDataInfoList);

const static char *nativeForkAndSpecialize_samsung_p_sig = "(II[II[[IILjava/lang/String;IILjava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I";

Expand Down Expand Up @@ -107,29 +105,28 @@ jint nativeForkAndSpecialize_samsung_m(

// -----------------------------------------------------------------

// removed from beta5
const static char *nativeSpecializeAppProcess_sig_q_beta4 = "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V";
const static char *nativeSpecializeAppProcess_sig = "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V";

using nativeSpecializeAppProcess_q_beta4_t = void(
using nativeSpecializeAppProcess_t = void(
JNIEnv *, jclass, jint, jint, jintArray, jint, jobjectArray, jint, jstring, jstring,
jboolean, jstring, jstring, jstring, jobjectArray, jstring);
jboolean, jstring, jstring);

void nativeSpecializeAppProcess_q_beta4(
void nativeSpecializeAppProcess(
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, jstring packageName,
jobjectArray packagesForUID, jstring sandboxId);
jboolean startChildZygote, jstring instructionSet, jstring appDataDir);

const static char *nativeSpecializeAppProcess_sig = "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V";
const static char *nativeSpecializeAppProcess_r_sig = "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;)V";

using nativeSpecializeAppProcess_t = void(
using nativeSpecializeAppProcess_r_t = void(
JNIEnv *, jclass, jint, jint, jintArray, jint, jobjectArray, jint, jstring, jstring,
jboolean, jstring, jstring);
jboolean, jstring, jstring, jboolean, jobjectArray);

void nativeSpecializeAppProcess(
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 startChildZygote, jstring instructionSet, jstring appDataDir,
jboolean isTopApp, jobjectArray pkgDataInfoList);

const static char *nativeSpecializeAppProcess_sig_samsung ="(II[II[[IILjava/lang/String;IILjava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V";

Expand Down
Loading

0 comments on commit 63b470f

Please sign in to comment.