Skip to content

Commit c938e96

Browse files
Merge pull request #1 from MlgmXyysd/master
Fix samsung service crash
2 parents 8a2714e + bd0673b commit c938e96

File tree

17 files changed

+921
-162
lines changed

17 files changed

+921
-162
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
# Riru - Template
1+
# Riru - MiPushFake
22

3-
[Riru](https://github.com/RikkaApps/Riru) module template.
3+
![License GPL-3.0](https://img.shields.io/badge/license-GPLv3.0-green.svg)
44

5-
## Build
5+
Fake as a Xiaomi device by hook system_property_get.
66

7-
1. Replace all "template" to your name
8-
9-
* `module/build.gradle`: "template" in variable `moduleId`, `moduleProp`
10-
* `module/src/main/cpp/CMakeLists.txt`: "riru_template" in `set(MODULE_NAME )`
11-
* `template/magisk_module/post-fs-data.sh`: `MODULE_ID="template"`
12-
* `template/magisk_module/uninstall.sh`: `MODULE_ID="template"`
7+
Requires Riru - Core v19 or above installed.
138

14-
2. Write you codes
15-
3. Run gradle task `:module:assembleRelease` task from Android Studio or command line, zip will be saved in `out`.
9+
## What does this module do
1610

17-
## Notes
11+
By default, `__system_property_get` (`android::base::GetProperty` on Pie+) will be hooked in packages selected in
12+
MiPushFramework with value map below
1813

19-
* DO NOT overwrite `android.os.SystemProperties#native_set` in core, or your data may be wiped
20-
([Detail info](https://github.com/RikkaApps/Riru/blob/v7/riru-core/jni/main/jni_native_method.cpp#L162-L176))
21-
(If you really need to hook this, remember to clear exception)
22-
* DO NO print log (`__android_log_print`) in `nativeForkAndSpecialize(Pre/Post)` `nativeForkSystemServer(Pre/Post)` when in zygote process, or it may cause zygote not work
23-
(magic not confirmed, [Detail info](https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66))
24-
* Add `-ffixed-x18` to both compiler and linker parameter, or it will cause problems on Android Q (see template)
14+
* `ro.miui.ui.version.name` -> `V11`
15+
* `ro.miui.ui.version.code` -> `9`
16+
* `ro.miui.version.code_time` -> `1570636800`
17+
* `ro.miui.internal.storage` -> `/sdcard/`
18+
* `ro.product.manufacturer` -> `Xiaomi`
19+
* `ro.product.brand` -> `Xiaomi`
20+
* `ro.product.name` -> `Xiaomi`

gradlew

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
#!/usr/bin/env sh
22

3-
#
4-
# Copyright 2015 the original author or authors.
5-
#
6-
# Licensed under the Apache License, Version 2.0 (the "License");
7-
# you may not use this file except in compliance with the License.
8-
# You may obtain a copy of the License at
9-
#
10-
# https://www.apache.org/licenses/LICENSE-2.0
11-
#
12-
# Unless required by applicable law or agreed to in writing, software
13-
# distributed under the License is distributed on an "AS IS" BASIS,
14-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
# See the License for the specific language governing permissions and
16-
# limitations under the License.
17-
#
18-
193
##############################################################################
204
##
215
## Gradle start up script for UN*X
@@ -44,7 +28,7 @@ APP_NAME="Gradle"
4428
APP_BASE_NAME=`basename "$0"`
4529

4630
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
31+
DEFAULT_JVM_OPTS=""
4832

4933
# Use the maximum available, or set MAX_FD != -1 to use that value.
5034
MAX_FD="maximum"
@@ -125,8 +109,8 @@ if $darwin; then
125109
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126110
fi
127111

128-
# For Cygwin or MSYS, switch paths to Windows format before running java
129-
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
112+
# For Cygwin, switch paths to Windows format before running java
113+
if $cygwin ; then
130114
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131115
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132116
JAVACMD=`cygpath --unix "$JAVACMD"`
@@ -154,19 +138,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
154138
else
155139
eval `echo args$i`="\"$arg\""
156140
fi
157-
i=`expr $i + 1`
141+
i=$((i+1))
158142
done
159143
case $i in
160-
0) set -- ;;
161-
1) set -- "$args0" ;;
162-
2) set -- "$args0" "$args1" ;;
163-
3) set -- "$args0" "$args1" "$args2" ;;
164-
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165-
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166-
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167-
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168-
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169-
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
144+
(0) set -- ;;
145+
(1) set -- "$args0" ;;
146+
(2) set -- "$args0" "$args1" ;;
147+
(3) set -- "$args0" "$args1" "$args2" ;;
148+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170154
esac
171155
fi
172156

@@ -175,9 +159,14 @@ save () {
175159
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176160
echo " "
177161
}
178-
APP_ARGS=`save "$@"`
162+
APP_ARGS=$(save "$@")
179163

180164
# Collect all arguments for the java command, following the shell quoting and substitution rules
181165
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182166

167+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169+
cd "$(dirname "$0")"
170+
fi
171+
183172
exec "$JAVACMD" "$@"

gradlew.bat

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
@rem
2-
@rem Copyright 2015 the original author or authors.
3-
@rem
4-
@rem Licensed under the Apache License, Version 2.0 (the "License");
5-
@rem you may not use this file except in compliance with the License.
6-
@rem You may obtain a copy of the License at
7-
@rem
8-
@rem https://www.apache.org/licenses/LICENSE-2.0
9-
@rem
10-
@rem Unless required by applicable law or agreed to in writing, software
11-
@rem distributed under the License is distributed on an "AS IS" BASIS,
12-
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
@rem See the License for the specific language governing permissions and
14-
@rem limitations under the License.
15-
@rem
16-
171
@if "%DEBUG%" == "" @echo off
182
@rem ##########################################################################
193
@rem
@@ -30,7 +14,7 @@ set APP_BASE_NAME=%~n0
3014
set APP_HOME=%DIRNAME%
3115

3216
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33-
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
17+
set DEFAULT_JVM_OPTS=
3418

3519
@rem Find java.exe
3620
if defined JAVA_HOME goto findJavaFromJavaHome

module.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ext {
2+
moduleId = "mipush_fake"
3+
riruApiVersion = 4
4+
5+
moduleProp = [
6+
name : "Riru - MiPushFake",
7+
version : "v13.0",
8+
versionCode: "13",
9+
author : "Timothy, MlgmXyysd",
10+
description: "Fake as a Xiaomi device by hook system_property_get. Requires Riru - Core v19 or above installed.",
11+
api : riruApiVersion
12+
]
13+
14+
magiskModuleProp = [
15+
id : "riru-${moduleId.replace('_', '-')}",
16+
name : "Riru - ${moduleProp['name']}",
17+
version : moduleProp['version'],
18+
versionCode: moduleProp['versionCode'],
19+
author : moduleProp['author'],
20+
description: moduleProp['description']
21+
]
22+
}

module/build.gradle

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
apply plugin: 'com.android.library'
2+
apply from: file(rootProject.file('module.gradle'))
23

34
android {
45
compileSdkVersion rootProject.ext.targetSdkVersion
56
defaultConfig {
67
minSdkVersion rootProject.ext.minSdkVersion
78
targetSdkVersion rootProject.ext.targetSdkVersion
9+
externalNativeBuild {
10+
cmake {
11+
arguments "-DMODULE_NAME:STRING=riru_$moduleId"
12+
}
13+
}
814
}
915
externalNativeBuild {
1016
cmake {
@@ -14,29 +20,10 @@ android {
1420
}
1521
}
1622

17-
def moduleId = "mipush_fake"
18-
def moduleProp = [
19-
name : "MiPushFake",
20-
version : "v12.0",
21-
versionCode: "12",
22-
author : "Timothy",
23-
description: "Fake as XiaoMI device by hook system_property_get. Require Riru-Core installed..",
24-
api : 4
25-
]
26-
27-
def magiskModuleProp = [
28-
id : "riru-${moduleId.replace('_', '-')}",
29-
name : "Riru - ${moduleProp['name']}",
30-
version : moduleProp['version'],
31-
versionCode: moduleProp['versionCode'],
32-
author : moduleProp['author'],
33-
description: moduleProp['description']
34-
]
35-
3623
def outDir = file("$rootDir/out")
3724
def magiskDir = file("$outDir/magisk_module")
38-
def zipName = "magisk-${magiskModuleProp['id']}-${magiskModuleProp['version']}.zip"
39-
def riruDir = "$magiskDir/data/misc/riru/modules/${moduleId}"
25+
def zipName = "magisk-${magiskModuleProp['id'].replace('_', '-')}-${magiskModuleProp['version']}.zip"
26+
def riruDir = "$magiskDir/riru"
4027

4128
import java.nio.file.Files
4229
import java.security.MessageDigest
@@ -55,6 +42,8 @@ static def renameOrFail(File from, File to) {
5542
}
5643
}
5744

45+
import org.apache.tools.ant.filters.FixCrLfFilter
46+
5847
android.libraryVariants.all { variant ->
5948
def task = variant.assembleProvider.get()
6049
task.doLast {
@@ -65,6 +54,19 @@ android.libraryVariants.all { variant ->
6554
copy {
6655
from "$rootDir/template/magisk_module"
6756
into magiskDir.path
57+
exclude 'riru.sh'
58+
}
59+
// copy riru.sh
60+
copy {
61+
from "$rootDir/template/magisk_module"
62+
into magiskDir.path
63+
include 'riru.sh'
64+
filter { line ->
65+
line.replaceAll('%%%RIRU_MODULE_ID%%%', moduleId)
66+
.replaceAll('%%%RIRU_MIN_API_VERSION%%%', riruApiVersion.toString())
67+
}
68+
filter(FixCrLfFilter.class,
69+
eol: FixCrLfFilter.CrLf.newInstance("lf"))
6870
}
6971
// copy .git files manually since gradle exclude it by default
7072
Files.copy(file("$rootDir/template/magisk_module/.gitattributes").toPath(), file("${magiskDir.path}/.gitattributes").toPath())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<manifest package="riru.template" />
1+
<manifest package="top.trumeet.mipushframework" />

module/src/main/cpp/hook.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) {
3535
int res = old___system_property_get(key, value);
3636
if (key) {
3737
if (strcmp("ro.miui.ui.version.name", key) == 0) {
38-
strcpy(value, "V9");
38+
strcpy(value, "V11");
3939
//LOGI("system_property_get: %s -> %s", key, value);
4040
} else if (strcmp("ro.miui.ui.version.code", key) == 0) {
41-
strcpy(value, "7");
41+
strcpy(value, "9");
4242
//LOGI("system_property_get: %s -> %s", key, value);
4343
} else if (strcmp("ro.miui.version.code_time", key) == 0) {
44-
strcpy(value, "1527550858");
44+
strcpy(value, "1570636800");
4545
//LOGI("system_property_get: %s -> %s", key, value);
4646
} else if (strcmp("ro.miui.internal.storage", key) == 0) {
4747
strcpy(value, "/sdcard/");
@@ -65,13 +65,13 @@ NEW_FUNC_DEF(std::string, _ZN7android4base11GetPropertyERKNSt3__112basic_stringI
6565
std::string res = old__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_(key, default_value);
6666

6767
if (strcmp("ro.miui.ui.version.name", key.c_str()) == 0) {
68-
res = "V9";
68+
res = "V11";
6969
//LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
7070
} else if (strcmp("ro.miui.ui.version.code", key.c_str()) == 0) {
71-
res = "7";
71+
res = "9";
7272
//LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
7373
} else if (strcmp("ro.miui.version.code_time", key.c_str()) == 0) {
74-
res = "1527550858";
74+
res = "1570636800";
7575
//LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
7676
} else if (strcmp("ro.miui.internal.storage", key.c_str()) == 0) {
7777
res = "/sdcard/";

module/src/main/cpp/main.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,44 @@
77
#include "logging.h"
88
#include "hook.h"
99

10-
#define CONFIG_PATH "/data/misc/riru/modules/mipush_fake"
11-
12-
#define FAKE_CONFIGURATION_GLOBAL "/data/misc/riru/modules/mipush_fake/packages/ALL"
10+
#if PLATFORM_SDK_VERSION >= 24
11+
#define CONFIG_PATH "/data/user_de/0/top.trumeet.mipush"
12+
#else
13+
#define CONFIG_PATH "/data/data/top.trumeet.mipush"
14+
#endif
1315

1416
// You can remove functions you don't need
1517
static char package_name[256];
1618
static bool enable_hook;
1719
static int uid;
1820

19-
static std::vector<std::string> globalPkgBlackList = {"com.google.android",
20-
"de.robv.android.xposed.installer",
21-
"com.xiaomi.xmsf",
22-
"com.tencent.mm",
23-
"top.trumeet.mipush"};
21+
static std::vector<std::string> globalPkgBlackList = {"com.xiaomi.xmsf",
22+
"top.trumeet.mipush",
23+
// Android
24+
"com.google.android",
25+
"android",
26+
"com.android",
27+
// Samsung
28+
"com.bst",
29+
"com.sec",
30+
"com.sem",
31+
"com.sgmc",
32+
"com.dsi.ant",
33+
"com.wsomacp",
34+
"com.samsung",
35+
"com.diotek.sec",
36+
"com.enhance.gameservice",
37+
// XDA
38+
"com.xda",
39+
// Wechat
40+
"com.tencent.mm",
41+
// Quickpay
42+
"com.example",
43+
// Magisk
44+
"com.topjohnwu.magisk",
45+
// Xposed
46+
"org.meowcat.edxposed.manager",
47+
"de.robv.android.xposed.installer"};
2448

2549

2650
bool isAppNeedHook(JNIEnv *pEnv, jstring pJstring);
@@ -173,7 +197,7 @@ bool isAppNeedHook(JNIEnv *env, jstring jAppDataDir) {
173197
}
174198
}
175199

176-
if (access(FAKE_CONFIGURATION_GLOBAL, F_OK) == 0) {
200+
if (access(CONFIG_PATH "/packages/ALL", F_OK) == 0) {
177201
return true;
178202
}
179203

template/magisk_module/.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ META-INF/** text eol=lf
33
*.prop text eol=lf
44
*.sh text eol=lf
55
*.md text eol=lf
6-
sepolicy.rule eol=lf
6+
sepolicy.rule text eol=lf
77

88
# Denote all files that are truly binary and should not be modified.
99
system/** binary

0 commit comments

Comments
 (0)