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

Commit

Permalink
v10
Browse files Browse the repository at this point in the history
Support Samsung devices (tested on 8.0)
  • Loading branch information
RikkaW committed Nov 28, 2018
1 parent 1a14b3b commit 7246374
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 125 deletions.
2 changes: 1 addition & 1 deletion riru-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ android {

task zip(type: Exec) {
workingDir '..'
commandLine 'sh', 'build.sh', project.name, 'v9'
commandLine 'sh', 'build.sh', project.name, 'v10'
}
26 changes: 15 additions & 11 deletions riru-core/jni/main/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,29 @@ void onRegisterZygote(JNIEnv *env, const char *className, const JNINativeMethod

gZygoteMethods[0].name = method.name;
gZygoteMethods[0].signature = method.signature;
gZygoteMethods[0].fnPtr = nullptr;

if (strncmp(nativeForkAndSpecialize_marshmallow_sig, method.signature,
strlen(nativeForkAndSpecialize_marshmallow_sig)) == 0)
if (strcmp(nativeForkAndSpecialize_marshmallow_sig, method.signature) == 0)
gZygoteMethods[0].fnPtr = (void *) nativeForkAndSpecialize_marshmallow;
else if (strncmp(nativeForkAndSpecialize_oreo_sig, method.signature,
strlen(nativeForkAndSpecialize_oreo_sig)) == 0)
else if (strcmp(nativeForkAndSpecialize_oreo_sig, method.signature) == 0)
gZygoteMethods[0].fnPtr = (void *) nativeForkAndSpecialize_oreo;
else if (strncmp(nativeForkAndSpecialize_p_sig, method.signature,
strlen(nativeForkAndSpecialize_p_sig)) == 0)
else if (strcmp(nativeForkAndSpecialize_p_sig, method.signature) == 0)
gZygoteMethods[0].fnPtr = (void *) nativeForkAndSpecialize_p;
else if (strcmp(nativeForkAndSpecialize_samsung_o_sig, method.signature) == 0)
gZygoteMethods[0].fnPtr = (void *) nativeForkAndSpecialize_samsung_o;
else
LOGW("found nativeForkAndSpecialize but signature %s mismatch", method.signature);
} else if (strcmp(method.name, "nativeForkSystemServer") == 0) {
_nativeForkSystemServer = method.fnPtr;

gZygoteMethods[1].name = method.name;
gZygoteMethods[1].signature = method.signature;
gZygoteMethods[1].fnPtr = nullptr;

if (strncmp(nativeForkSystemServer_sig, method.signature,
strlen(nativeForkSystemServer_sig)) == 0)
if (strcmp(nativeForkSystemServer_sig, method.signature) == 0)
gZygoteMethods[1].fnPtr = (void *) nativeForkSystemServer;
else
LOGW("found nativeForkSystemServer but signature %s mismatch", method.signature);
}
}

Expand Down Expand Up @@ -317,7 +321,7 @@ void *riru_get_func(const char *module_name, const char *name) {

index -= 1;

LOGI("get_func %s %s", module_name, name);
LOGV("get_func %s %s", module_name, name);

// find if it is set by previous modules
if (index != 0) {
Expand All @@ -342,7 +346,7 @@ void *riru_get_native_method_func(const char *module_name, const char *className

index -= 1;

LOGI("get_func %s %s %s %s", module_name, className, name, signature);
LOGV("get_func %s %s %s %s", module_name, className, name, signature);

// find if it is set by previous modules
if (index != 0) {
Expand All @@ -365,7 +369,7 @@ void riru_set_func(const char *module_name, const char *name, void* func) {
if (index == 0)
return;

LOGI("set_func %s %s %p", module_name, name, func);
LOGV("set_func %s %s %p", module_name, name, func);

auto module = get_modules()->at(index - 1);
(*module->funcs)[name] = func;
Expand Down
141 changes: 69 additions & 72 deletions riru-core/jni/main/jni_native_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ int shouldSkipUid(int uid) {
return 1;
}

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) {
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) {
if (shouldSkipUid(uid))
return;

Expand All @@ -33,14 +31,9 @@ void nativeForkAndSpecialize_pre(JNIEnv *env, jclass clazz, jint uid, jint gid,
continue;

//LOGV("%s: forkAndSpecializePre", module->name);
((nativeForkAndSpecialize_pre_t) module->forkAndSpecializePre)(env, clazz, uid, gid,
gids, runtime_flags,
rlimits, mount_external,
se_info, se_name,
fdsToClose, fdsToIgnore,
is_child_zygote,
instructionSet,
appDataDir);
((nativeForkAndSpecialize_pre_t) module->forkAndSpecializePre)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info,
se_name, fdsToClose, fdsToIgnore, is_child_zygote, instructionSet, appDataDir);
}
}

Expand Down Expand Up @@ -69,18 +62,17 @@ void nativeForkAndSpecialize_post(JNIEnv *env, jclass clazz, jint uid, jint res)
}
}

void nativeForkSystemServer_pre(JNIEnv *env, jclass clazz, uid_t uid, gid_t gid, jintArray gids,
jint debug_flags, jobjectArray rlimits, jlong permittedCapabilities,
jlong effectiveCapabilities) {
void nativeForkSystemServer_pre(
JNIEnv *env, jclass clazz, uid_t uid, gid_t gid, jintArray gids, jint debug_flags,
jobjectArray rlimits, jlong permittedCapabilities, jlong effectiveCapabilities) {
for (auto module : *get_modules()) {
if (!module->forkSystemServerPre)
continue;

//LOGV("%s: forkSystemServerPre", module->name);
((nativeForkSystemServer_pre_t) module->forkSystemServerPre)(env, clazz, uid, gid, gids,
debug_flags, rlimits,
permittedCapabilities,
effectiveCapabilities);
((nativeForkSystemServer_pre_t) module->forkSystemServerPre)(
env, clazz, uid, gid, gids, debug_flags, rlimits, permittedCapabilities,
effectiveCapabilities);
}
}

Expand All @@ -95,78 +87,83 @@ void nativeForkSystemServer_post(JNIEnv *env, jclass clazz, jint res) {
}


jint nativeForkAndSpecialize_marshmallow(JNIEnv *env, jclass clazz, jint uid, jint gid,
jintArray gids, jint debug_flags, jobjectArray rlimits,
jint mount_external, jstring se_info, jstring se_name,
jintArray fdsToClose, jstring instructionSet,
jstring appDataDir) {
jint nativeForkAndSpecialize_marshmallow(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint debug_flags,
jobjectArray rlimits, jint mount_external, jstring se_info, jstring se_name,
jintArray fdsToClose, jstring instructionSet, jstring appDataDir) {
nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, nullptr, 0, instructionSet,
appDataDir);

jint res = ((nativeForkAndSpecialize_marshmallow_t) _nativeForkAndSpecialize)(env, clazz, uid,
gid, gids,
debug_flags,
rlimits,
mount_external,
se_info,
se_name,
fdsToClose,
instructionSet,
appDataDir);
jint res = ((nativeForkAndSpecialize_marshmallow_t) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, se_name,
fdsToClose, instructionSet, appDataDir);

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

jint nativeForkAndSpecialize_oreo(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids,
jint debug_flags, jobjectArray rlimits, jint mount_external,
jstring se_info, jstring se_name, jintArray fdsToClose,
jintArray fdsToIgnore, jstring instructionSet,
jstring appDataDir) {
jint nativeForkAndSpecialize_oreo(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint debug_flags,
jobjectArray rlimits, jint mount_external, jstring se_info, jstring se_name,
jintArray fdsToClose, jintArray fdsToIgnore, jstring instructionSet, jstring appDataDir) {
nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, 0, instructionSet,
appDataDir);
jint res = ((nativeForkAndSpecialize_oreo_t) _nativeForkAndSpecialize)(env, clazz, uid, gid,
gids,
debug_flags, rlimits,
mount_external, se_info,
se_name, fdsToClose,
fdsToIgnore,
instructionSet,
appDataDir);

jint res = ((nativeForkAndSpecialize_oreo_t) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, se_name,
fdsToClose, fdsToIgnore, instructionSet, appDataDir);

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

jint nativeForkAndSpecialize_p(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) {
jint nativeForkAndSpecialize_p(
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) {
nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, is_child_zygote,
instructionSet, appDataDir);
jint res = ((nativeForkAndSpecialize_p_t) _nativeForkAndSpecialize)(env, clazz, uid, gid, gids,
runtime_flags, rlimits,
mount_external, se_info,
se_name, fdsToClose,
fdsToIgnore,
is_child_zygote,
instructionSet, appDataDir);

jint res = ((nativeForkAndSpecialize_p_t) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, se_name,
fdsToClose, fdsToIgnore, is_child_zygote, instructionSet, appDataDir);

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

jint nativeForkAndSpecialize_samsung_o(
JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint debug_flags,
jobjectArray rlimits, jint mount_external, jstring se_info, jint category, jint accessInfo,
jstring se_name, jintArray fdsToClose, jintArray fdsToIgnore, jstring instructionSet,
jstring appDataDir) {
nativeForkAndSpecialize_pre(env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external,
se_info, se_name, fdsToClose, fdsToIgnore, 0, instructionSet,
appDataDir);

jint res = ((nativeForkAndSpecialize_samsung_o_t) _nativeForkAndSpecialize)(
env, clazz, uid, gid, gids, debug_flags, rlimits, mount_external, se_info, category,
accessInfo, se_name, fdsToClose, fdsToIgnore, instructionSet, appDataDir);

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

jint nativeForkSystemServer(JNIEnv *env, jclass clazz, uid_t uid, gid_t gid, jintArray gids,
jint debug_flags, jobjectArray rlimits, jlong permittedCapabilities,
jlong effectiveCapabilities) {
nativeForkSystemServer_pre(env, clazz, uid, gid, gids, debug_flags, rlimits,
permittedCapabilities,
effectiveCapabilities);
jint res = ((nativeForkSystemServer_t) _nativeForkSystemServer)(env, clazz, uid, gid, gids,
debug_flags, rlimits,
permittedCapabilities,
effectiveCapabilities);
jint nativeForkSystemServer(
JNIEnv *env, jclass clazz, uid_t uid, gid_t gid, jintArray gids, jint debug_flags,
jobjectArray rlimits, jlong permittedCapabilities, jlong effectiveCapabilities) {
nativeForkSystemServer_pre(
env, clazz, uid, gid, gids, debug_flags, rlimits, permittedCapabilities,
effectiveCapabilities);

jint res = ((nativeForkSystemServer_t) _nativeForkSystemServer)(
env, clazz, uid, gid, gids, debug_flags, rlimits, permittedCapabilities,
effectiveCapabilities);

nativeForkSystemServer_post(env, clazz, res);
return res;
}
Expand Down
Loading

0 comments on commit 7246374

Please sign in to comment.