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

Commit

Permalink
update app
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed May 9, 2019
1 parent bb29d1d commit 70af0b6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
28 changes: 19 additions & 9 deletions app/src/main/cpp/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ static jint get_nativeForkSystemServer_calls_count(JNIEnv *env, jobject thiz) {
return -1;
}

static jint get_nativeSpecializeAppProcess_calls_count(JNIEnv *env, jobject thiz) {
static void *sym;
void *handle;
if ((handle = get_handle()) == nullptr) return -1;
if (sym == nullptr) sym = dlsym(handle, "riru_get_nativeSpecializeAppProcess_calls_count");
if (sym) return static_cast<jboolean>(((int (*)()) sym)());
return -1;
}

static jstring get_nativeForkAndSpecialize_signature(JNIEnv *env, jobject thiz) {
static void *sym;
void *handle;
Expand Down Expand Up @@ -138,15 +147,16 @@ static jstring get_nativeForkSystemServer_signature(JNIEnv *env, jobject thiz) {
}

static JNINativeMethod gMethods[] = {
{"init", "()Z", (void *) init},
{"isRiruModuleExists", "(Ljava/lang/String;)Z", (void *) is_riru_module_exists},
{"getRiruVersion", "()I", (void *) get_riru_rersion},
{"isZygoteMethodsReplaced", "()Z", (void *) is_zygote_methods_replaced},
{"getNativeForkAndSpecializeCallsCount", "()I", (void *) get_nativeForkAndSpecialize_calls_count},
{"getNativeForkSystemServerCallsCount", "()I", (void *) get_nativeForkSystemServer_calls_count},
{"getNativeForkAndSpecializeSignature", "()Ljava/lang/String;", (void *) get_nativeForkAndSpecialize_signature},
{"getNativeSpecializeAppProcessSignature", "()Ljava/lang/String;", (void *) get_nativeSpecializeAppProcess_signature},
{"getNativeForkSystemServerSignature", "()Ljava/lang/String;", (void *) get_nativeForkSystemServer_signature},
{"init", "()Z", (void *) init},
{"isRiruModuleExists", "(Ljava/lang/String;)Z", (void *) is_riru_module_exists},
{"getRiruVersion", "()I", (void *) get_riru_rersion},
{"isZygoteMethodsReplaced", "()Z", (void *) is_zygote_methods_replaced},
{"getNativeForkAndSpecializeCallsCount", "()I", (void *) get_nativeForkAndSpecialize_calls_count},
{"getNativeForkSystemServerCallsCount", "()I", (void *) get_nativeForkSystemServer_calls_count},
{"getNativeSpecializeAppProcessCallsCount", "()I", (void *) get_nativeSpecializeAppProcess_calls_count},
{"getNativeForkAndSpecializeSignature", "()Ljava/lang/String;", (void *) get_nativeForkAndSpecialize_signature},
{"getNativeSpecializeAppProcessSignature", "()Ljava/lang/String;", (void *) get_nativeSpecializeAppProcess_signature},
{"getNativeForkSystemServerSignature", "()Ljava/lang/String;", (void *) get_nativeForkSystemServer_signature},
};

static int registerNativeMethods(JNIEnv *env, const char *className,
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/moe/riru/manager/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

boolean init, isZygoteMethodsReplaced;
int version, nativeForkAndSpecializeCallsCount, nativeForkSystemServerCallsCount;
int version, nativeForkAndSpecializeCallsCount, nativeForkSystemServerCallsCount, nativeSpecializeAppProcessCallsCount;
String nativeForkAndSpecializeSignature, nativeSpecializeAppProcessSignature, nativeForkSystemServerSignature;

StringBuilder sb = new StringBuilder();
Expand All @@ -32,6 +32,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
isZygoteMethodsReplaced = NativeHelper.isZygoteMethodsReplaced();
nativeForkAndSpecializeCallsCount = NativeHelper.getNativeForkAndSpecializeCallsCount();
nativeForkSystemServerCallsCount = NativeHelper.getNativeForkSystemServerCallsCount();
nativeSpecializeAppProcessCallsCount = NativeHelper.getNativeSpecializeAppProcessCallsCount();
nativeForkAndSpecializeSignature = NativeHelper.getNativeForkAndSpecializeSignature();
nativeSpecializeAppProcessSignature = NativeHelper.getNativeSpecializeAppProcessSignature();
nativeForkSystemServerSignature = NativeHelper.getNativeForkSystemServerSignature();
Expand All @@ -41,17 +42,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
if (isZygoteMethodsReplaced) {
sb.append("Native methods of Zygote class replaced.").append("<br><br>")
.append("nativeForkAndSpecialize calls count: ").append(nativeForkAndSpecializeCallsCount).append("<br>")
.append("nativeForkSystemServer calls count: ").append(nativeForkSystemServerCallsCount).append("<br>");
.append("nativeForkSystemServer calls count: ").append(nativeForkSystemServerCallsCount).append("<br>")
.append("nativeSpecializeAppProcess calls count: ").append(nativeSpecializeAppProcessCallsCount).append("<br>");

if (nativeForkAndSpecializeCallsCount == 0) {
sb.append("<br>nativeForkAndSpecialize calls count is 0, Riru is not working correctly.<br>This may because Riru's hook is overwritten by other things, please check yourself.");
if (nativeForkAndSpecializeCallsCount <= 0 && nativeSpecializeAppProcessCallsCount <= 0) {
sb.append("<br>nativeForkAndSpecialize/nativeSpecializeAppProcess calls count is 0, Riru is not working correctly.<br>This may because Riru's hook is overwritten by other things, please check yourself.");
} else if (nativeForkSystemServerCallsCount != 0) {
sb.append("<br>Everything looks fine :D");
}
} else {
sb.append("However, native methods of Zygote class not replaced, please contact developer with the following information.").append("<br><br>")
.append("nativeForkAndSpecializeSignature:<br><font face=\"monospace\">").append(nativeForkAndSpecializeSignature).append("</font><br><br>")
.append("getNativeForkSystemServerSignature:<br><font face=\"monospace\">").append(nativeForkSystemServerSignature).append("</font>");
.append("nativeSpecializeAppProcessSignature (from Q beta 3):<br><font face=\"monospace\">").append(nativeSpecializeAppProcessSignature).append("</font><br><br>")
.append("nativeForkSystemServerSignature:<br><font face=\"monospace\">").append(nativeForkSystemServerSignature).append("</font>");
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/moe/riru/manager/utils/BuildUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public class BuildUtils {

public static boolean isQ() {
return "Q".equals(Build.VERSION.RELEASE) || Build.VERSION.SDK_INT >= 29;
return (Build.VERSION.SDK_INT == 28 && Build.VERSION.PREVIEW_SDK_INT > 0) || Build.VERSION.SDK_INT >= 29;
}
}
12 changes: 9 additions & 3 deletions app/src/main/java/moe/riru/manager/utils/NativeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@Keep
public class NativeHelper {

private static final int MAX_VERSION = 19;
private static final int MAX_VERSION = 20;
private static final int V19 = 20;
private static final int V18 = 19;
private static final int V17_1 = 18;

Expand All @@ -27,12 +28,14 @@ public static String versionName(Context context, int versionCode) {
}

switch (versionCode) {
case V19:
return "v19";
case V18:
return "v18";
case V17_1:
return "v17.1";
default:
return "v" + versionCode;
return "unknown (version code " + versionCode + ")";
}
}

Expand All @@ -48,9 +51,12 @@ public static String versionName(Context context, int versionCode) {

public static native int getNativeForkSystemServerCallsCount();

public static native int getNativeSpecializeAppProcessCallsCount();

public static native String getNativeForkAndSpecializeSignature();

public static native String getNativeForkSystemServerSignature();

public static native String getNativeSpecializeAppProcessSignature();

public static native String getNativeForkSystemServerSignature();
}
2 changes: 2 additions & 0 deletions riru-core/jni/main/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ int riru_get_nativeForkAndSpecialize_calls_count() EXPORT;

int riru_get_nativeForkSystemServer_calls_count() EXPORT;

int riru_get_nativeSpecializeAppProcess_calls_count() EXPORT;

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions riru-core/jni/main/jni_native_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ int riru_get_nativeForkSystemServer_calls_count() {
return nativeForkSystemServer_calls_count;
}

int specializeAppProcess_calls_count = 0;
int nativeSpecializeAppProcess_calls_count = 0;

int riru_get_specializeAppProcess_calls_count() {
return specializeAppProcess_calls_count;
int riru_get_nativeSpecializeAppProcess_calls_count() {
return nativeSpecializeAppProcess_calls_count;
}

// -----------------------------------------------------------------
Expand Down Expand Up @@ -133,7 +133,7 @@ static void nativeSpecializeAppProcess_pre(
jboolean startChildZygote, jstring instructionSet, jstring appDataDir, jstring packageName,
jobjectArray packagesForUID, jstring sandboxId) {

specializeAppProcess_calls_count++;
nativeSpecializeAppProcess_calls_count++;

for (auto module : *get_modules()) {
if (!module->specializeAppProcessPre)
Expand Down

0 comments on commit 70af0b6

Please sign in to comment.