1616#include " hook.h"
1717#include " misc.h"
1818
19+
20+ #define CONFIG_PATH " /data/misc/riru/modules/mipush_fake"
21+
22+
1923static char package_name[256 ];
2024static int uid;
21- static int enable_hook = true ;
25+ static int enable_hook;
26+ static std::vector<std::string> packages = {};
27+
28+ int is_app_need_hook (JNIEnv *env, jstring appDataDir) {
29+ if (!appDataDir)
30+ return 0 ;
31+
32+
33+ const char *app_data_dir = env->GetStringUTFChars (appDataDir, NULL );
34+
35+ int user = 0 ;
36+ if (sscanf (app_data_dir, " /data/%*[^/]/%d/%s" , &user, package_name) != 2 ) {
37+ if (sscanf (app_data_dir, " /data/%*[^/]/%s" , package_name) != 1 ) {
38+ package_name[0 ] = ' \0 ' ;
39+ LOGW (" can't parse %s" , app_data_dir);
40+ return 0 ;
41+ }
42+ }
43+
44+ env->ReleaseStringUTFChars (appDataDir, app_data_dir);
45+
46+ if (access (CONFIG_PATH " /packages" , R_OK) != 0 ) {
47+ for (auto &s : packages) {
48+ if (strcmp (s.c_str (), package_name) == 0 )
49+ return 1 ;
50+ }
51+ } else {
52+ char path[PATH_MAX];
53+ snprintf (path, PATH_MAX, CONFIG_PATH " /packages/%s" , package_name);
54+ return access (path, F_OK) == 0 ;
55+ }
56+ return 0 ;
57+ }
58+
59+ void load_config () {
60+ // empty
61+ }
2262
2363void nativeForkAndSpecialize (int res, int enable_hook, const char *package_name, jint uid) {
2464 if (res == 0 && enable_hook) {
@@ -41,6 +81,10 @@ __attribute__((visibility("default"))) void nativeForkAndSpecializePre(JNIEnv *e
4181 jstring instructionSet,
4282 jstring appDataDir) {
4383 uid = _uid;
84+ enable_hook = is_app_need_hook (env, appDataDir);
85+
86+ if (enable_hook)
87+ load_config ();
4488}
4589
4690__attribute__ ((visibility(" default" ))) int nativeForkAndSpecializePost(JNIEnv *env, jclass clazz,
0 commit comments