Skip to content

Commit 441620c

Browse files
sync to latest Riru v8, sync code from Riru-LocationReportEnabler
1 parent 603ac6f commit 441620c

File tree

8 files changed

+163
-7
lines changed

8 files changed

+163
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ android {
2222

2323
task zip(type: Exec) {
2424
workingDir '..'
25-
commandLine 'sh', 'build.sh', project.name, 'v5'
25+
commandLine 'sh', 'build.sh', project.name, 'v6'
2626
}

jni/main/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ LOCAL_STATIC_LIBRARIES := xhook
1010
LOCAL_LDLIBS += -ldl -llog
1111
LOCAL_LDFLAGS := -Wl
1212

13-
LOCAL_SRC_FILES:= main.cpp hook.cpp misc.cpp
13+
LOCAL_SRC_FILES:= main.cpp hook.cpp misc.cpp riru.c
1414

1515
include $(BUILD_SHARED_LIBRARY)

jni/main/hook.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <sys/system_properties.h>
1313
#include <xhook/xhook.h>
1414

15+
#include "riru.h"
1516
#include "logging.h"
1617

1718
#define XHOOK_REGISTER(NAME) \
@@ -86,11 +87,26 @@ void install_hook(const char *package_name, int user) {
8687
XHOOK_REGISTER(__system_property_get);
8788

8889
char sdk[PROP_VALUE_MAX + 1];
89-
if (__system_property_get("ro.build.version.sdk", sdk) > 0 && atoi(sdk) >= 28)
90+
int sdkLevel = 0;
91+
if (__system_property_get("ro.build.version.sdk", sdk) > 0 && (sdkLevel = atoi(sdk)) >= 28)
9092
XHOOK_REGISTER(_ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_);
9193

9294
if (xhook_refresh(0) == 0)
9395
xhook_clear();
9496
else
9597
LOGE("failed to refresh hook");
98+
99+
100+
if (riru_get_version() >= 8) {
101+
void *f = riru_get_func("__system_property_get");
102+
if (f != nullptr) old___system_property_get = (int (*)(const char *, char *)) f;
103+
riru_set_func("__system_property_get", (void *) new___system_property_get);
104+
if (sdkLevel >= 28) {
105+
f = riru_get_func("_ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_");
106+
if (f != nullptr) old__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ = (std::string (*)(const std::string &, const std::string &)) f;
107+
riru_set_func("_ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_",
108+
(void *) new__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_);
109+
}
110+
}
111+
96112
}

jni/main/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
#include "logging.h"
1616
#include "hook.h"
1717
#include "misc.h"
18+
#include <riru.h>
1819

1920

2021
#define CONFIG_PATH "/data/misc/riru/modules/mipush_fake"
2122

23+
#define FAKE_CONFIGURATION_GLOBAL "/data/misc/riru/modules/mipush_fake/packages/ALL"
24+
2225

2326
static char package_name[256];
2427
static int uid;
@@ -43,6 +46,10 @@ int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
4346

4447
env->ReleaseStringUTFChars(appDataDir, app_data_dir);
4548

49+
if (access(FAKE_CONFIGURATION_GLOBAL, F_OK) == 0) {
50+
return 1;
51+
}
52+
4653
if (access(CONFIG_PATH "/packages", R_OK) != 0) {
4754
for (auto &s : packages) {
4855
if (strcmp(s.c_str(), package_name) == 0)

jni/main/riru.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <dlfcn.h>
2+
#include <memory.h>
3+
#include <logging.h>
4+
5+
#ifdef __LP64__
6+
#define LIB "/system/lib64/libmemtrack.so"
7+
#else
8+
#define LIB "/system/lib/libmemtrack.so"
9+
#endif
10+
11+
static void *riru_handle;
12+
static char *riru_module_name;
13+
14+
static void *get_handle() {
15+
if (riru_handle == NULL)
16+
riru_handle = dlopen(LIB, RTLD_NOW | RTLD_GLOBAL);
17+
18+
return riru_handle;
19+
}
20+
21+
const char *riru_get_module_name() {
22+
return riru_module_name;
23+
}
24+
25+
void riru_set_module_name(const char *name) {
26+
riru_module_name = strdup(name);
27+
}
28+
29+
int riru_get_version() {
30+
static void **sym;
31+
void *handle;
32+
if ((handle = get_handle()) == NULL) return -1;
33+
if (sym == NULL) sym = dlsym(handle, "riru_get_version");
34+
if (sym) return ((int (*)()) sym)();
35+
return -1;
36+
}
37+
38+
void *riru_get_func(const char *name) {
39+
static void **sym;
40+
void *handle;
41+
if ((handle = get_handle()) == NULL) return NULL;
42+
if (sym == NULL) sym = dlsym(handle, "riru_get_func");
43+
if (sym) return ((void *(*)(const char *, const char *)) sym)(riru_get_module_name(), name);
44+
return NULL;
45+
}
46+
47+
void *riru_get_native_method_func(const char *className, const char *name, const char *signature) {
48+
static void **sym;
49+
void *handle;
50+
if ((handle = get_handle()) == NULL) return NULL;
51+
if (sym == NULL) sym = dlsym(handle, "riru_get_native_method_func");
52+
if (sym)
53+
return ((void *(*)(const char *, const char *, const char *, const char *)) sym)(
54+
riru_get_module_name(), className, name, signature);
55+
return NULL;
56+
}
57+
58+
void riru_set_func(const char *name, void *func) {
59+
static void **sym;
60+
void *handle;
61+
if ((handle = get_handle()) == NULL) return;
62+
if (sym == NULL) sym = dlsym(handle, "riru_set_func");
63+
if (sym)
64+
((void *(*)(const char *, const char *, void *)) sym)(riru_get_module_name(), name, func);
65+
}
66+
67+
void riru_set_native_method_func(const char *className, const char *name, const char *signature,
68+
void *func) {
69+
static void **sym;
70+
void *handle;
71+
if ((handle = get_handle()) == NULL) return;
72+
if (sym == NULL) sym = dlsym(handle, "riru_set_native_method_func");
73+
if (sym)
74+
((void *(*)(const char *, const char *, const char *, const char *, void *)) sym)(
75+
riru_get_module_name(), className, name, signature, func);
76+
}

jni/main/riru.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef RIRU_H
2+
#define RIRU_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
__attribute__((visibility("default"))) void riru_set_module_name(const char *name);
8+
9+
/**
10+
* Get Riru version.
11+
*
12+
* @return Riru version
13+
*/
14+
int riru_get_version();
15+
16+
/*
17+
* Get new_func address from last module which hook func.
18+
* Use this as your old_func if you want to hook func.
19+
*
20+
* @param name a unique name
21+
* @return new_func from last module or null
22+
*/
23+
void *riru_get_func(const char *name);
24+
25+
/*
26+
* Java native version of riru_get_func.
27+
*
28+
* @param className class name
29+
* @param name method name
30+
* @param signature method signature
31+
* @return new_func address from last module or original address
32+
*/
33+
void *riru_get_native_method_func(const char *className, const char *name, const char *signature);
34+
35+
/*
36+
* Set new_func address for next module which wants to hook func.
37+
*
38+
* @param name a unique name
39+
* @param func your new_func address
40+
*/
41+
void riru_set_func(const char *name, void *func);
42+
43+
/*
44+
* Java native method version of riru_set_func.
45+
*
46+
* @param className class name
47+
* @param name method name
48+
* @param signature method signature
49+
* @param func your new_func address
50+
*/
51+
void riru_set_native_method_func(const char *className, const char *name, const char *signature,
52+
void *func);
53+
#ifdef __cplusplus
54+
}
55+
#endif
56+
57+
#endif

template_override/module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id=mipush_fake
22
name=Riru - MiPushFakeModule
3-
version=v5
4-
versionCode=5
3+
version=v6
4+
versionCode=6
55
author=Timothy
66
description=Fake as XiaoMI device by hook system_property_get. Require Riru - Core installed.
77
minMagisk=1500

template_override/riru_module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Riru - MiPushFakeModule
2-
version=v5
3-
versionCode=5
2+
version=v6
3+
versionCode=6
44
author=Timothy
55
description=Fake as XiaoMI device by hook system_property_get. Require Riru - Core installed.

0 commit comments

Comments
 (0)