Skip to content

Commit 1c82fe1

Browse files
mipush fake
1 parent 155d2ed commit 1c82fe1

31 files changed

+4309
-17
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
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 hooking system_property_get.
66

7-
1. Rename `module.example.gradle` to `module.gradle`
8-
2. Replace module info in `module.gradle` (all lines end with `// FIXME replace with yours`)
9-
3. Write you codes
10-
4. Run gradle task `:module:assembleRelease` task from Android Studio or command line, zip will be saved in `out`.
7+
Requires Riru Core installed.
118

12-
## Notes
9+
## What does this module do
1310

14-
* DO NOT overwrite `android.os.SystemProperties#native_set` in core, or your data may be wiped
15-
([Detail info](https://github.com/RikkaApps/Riru/blob/v7/riru-core/jni/main/jni_native_method.cpp#L162-L176))
16-
(If you really need to hook this, remember to clear exception)
17-
* 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
18-
(magic not confirmed, [Detail info](https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66))
19-
* Add `-ffixed-x18` to both compiler and linker parameter, or it will cause problems on Android Q (see template)
11+
By default, `__system_property_get` (`android::base::GetProperty` on Pie+) will be hooked in packages selected in
12+
MiPushFramework with value map below
13+
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`
21+
22+
Thanks
23+
* Timothy Zhang
24+
* MlgmXyysd
25+
* Rikka

README_RIRU.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Riru - Template
2+
3+
[Riru](https://github.com/RikkaApps/Riru) module template.
4+
5+
## Build
6+
7+
1. Rename `module.example.gradle` to `module.gradle`
8+
2. Replace module info in `module.gradle` (all lines end with `// FIXME replace with yours`)
9+
3. Write you codes
10+
4. Run gradle task `:module:assembleRelease` task from Android Studio or command line, zip will be saved in `out`.
11+
12+
## Notes
13+
14+
* DO NOT overwrite `android.os.SystemProperties#native_set` in core, or your data may be wiped
15+
([Detail info](https://github.com/RikkaApps/Riru/blob/v7/riru-core/jni/main/jni_native_method.cpp#L162-L176))
16+
(If you really need to hook this, remember to clear exception)
17+
* 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
18+
(magic not confirmed, [Detail info](https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66))
19+
* Add `-ffixed-x18` to both compiler and linker parameter, or it will cause problems on Android Q (see template)

module.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ext {
2+
moduleId = "mipush_fake" // FIXME replace with yours
3+
riruApiVersion = 6
4+
riruMinVersionName = "v21.0"
5+
6+
moduleProp = [
7+
name : "MiPushFake", // FIXME replace with yours
8+
version : "v14.0", // FIXME replace with yours
9+
versionCode: "14", // FIXME replace with yours
10+
author : "Timothy Zhang", // FIXME replace with yours
11+
description: "Fake as XiaoMI device by hook system_property_get.", // FIXME replace with yours
12+
api : riruApiVersion
13+
]
14+
15+
magiskModuleProp = [
16+
id : "riru-${moduleId.replace('_', '-')}",
17+
name : "Riru - ${moduleProp['name']}",
18+
version : moduleProp['version'],
19+
versionCode: moduleProp['versionCode'],
20+
author : moduleProp['author'],
21+
description: moduleProp['description']
22+
]
23+
}

module/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ android {
2020
}
2121
}
2222

23+
def moduleProp = [
24+
name : "MiPushFake",
25+
version : "v13.0",
26+
versionCode: "13",
27+
author : "Timothy",
28+
description: "Fake as XiaoMI device by hook system_property_get. Require Riru-Core installed..",
29+
api : riruApiVersion
30+
]
31+
32+
def magiskModuleProp = [
33+
id : "riru-${moduleId.replace('_', '-')}",
34+
name : "Riru - ${moduleProp['name']}",
35+
version : moduleProp['version'],
36+
versionCode: moduleProp['versionCode'],
37+
author : moduleProp['author'],
38+
description: moduleProp['description']
39+
]
40+
2341
def outDir = file("$rootDir/out")
2442
def magiskDir = file("$outDir/magisk_module")
2543
def zipName = "magisk-${magiskModuleProp['id'].replace('_', '-')}-${magiskModuleProp['version']}.zip"

module/src/main/cpp/CMakeLists.txt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ cmake_minimum_required(VERSION 3.4.1)
33
if (NOT DEFINED MODULE_NAME)
44
message(FATAL_ERROR "MODULE_NAME is not set")
55
endif ()
6+
SET(XHOOK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/xhook/)
7+
8+
9+
INCLUDE_DIRECTORIES(
10+
${CMAKE_CURRENT_SOURCE_DIR}/include
11+
${XHOOK_PATH}/include
12+
)
13+
14+
LINK_DIRECTORIES(
15+
${XHOOK_PATH}/lib/
16+
)
617

718
message("Build type: ${CMAKE_BUILD_TYPE}")
819

@@ -24,6 +35,22 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS}")
2435
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
2536
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
2637

27-
add_library(${MODULE_NAME} SHARED main.cpp)
28-
target_link_libraries(${MODULE_NAME} log)
38+
39+
SET(XHOOK_OBJS
40+
external/xhook/xhook.c
41+
external/xhook/xh_core.c
42+
external/xhook/xh_elf.c
43+
external/xhook/xh_jni.c
44+
external/xhook/xh_log.c
45+
external/xhook/xh_util.c
46+
external/xhook/xh_version.c
47+
)
48+
ADD_LIBRARY(libxhook STATIC ${XHOOK_OBJS})
49+
set_target_properties(libxhook PROPERTIES LINKER_LANGUAGE CXX C_STANDARD 11 OUTPUT_NAME "xhook")
50+
51+
52+
add_library(${MODULE_NAME} SHARED hook.cpp riru.c main.cpp)
53+
target_link_libraries(${MODULE_NAME} log libxhook)
2954
set_target_properties(${MODULE_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
55+
56+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
include $(CLEAR_VARS)
4+
LOCAL_MODULE := xhook
5+
LOCAL_SRC_FILES := xhook/xhook.c \
6+
xhook/xh_core.c \
7+
xhook/xh_elf.c \
8+
xhook/xh_jni.c \
9+
xhook/xh_log.c \
10+
xhook/xh_util.c \
11+
xhook/xh_version.c
12+
LOCAL_C_INCLUDES := $(LOCAL_PATH)
13+
LOCAL_CFLAGS := -Wall -Wextra -Werror -fvisibility=hidden
14+
LOCAL_CONLYFLAGS := -std=c11
15+
include $(BUILD_STATIC_LIBRARY)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2018-present, iQIYI, Inc. All rights reserved.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
//
21+
22+
// Created by caikelun on 2018-04-11.
23+
24+
#ifndef XHOOK_H
25+
#define XHOOK_H 1
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
#define XHOOK_EXPORT __attribute__((visibility("default")))
32+
33+
int xhook_register(const char *pathname_regex_str, const char *symbol,
34+
void *new_func, void **old_func) XHOOK_EXPORT;
35+
36+
int xhook_ignore(const char *pathname_regex_str, const char *symbol) XHOOK_EXPORT;
37+
38+
int xhook_refresh(int async) XHOOK_EXPORT;
39+
40+
void xhook_clear() XHOOK_EXPORT;
41+
42+
void xhook_enable_debug(int flag) XHOOK_EXPORT;
43+
44+
void xhook_enable_sigsegv_protection(int flag) XHOOK_EXPORT;
45+
46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
50+
#endif

0 commit comments

Comments
 (0)