Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit bbb29f7

Browse files
authored
Merge pull request #29 from MonwF/master
适配Riru 22
2 parents 5d7b449 + b17e2ba commit bbb29f7

File tree

18 files changed

+167
-77
lines changed

18 files changed

+167
-77
lines changed

build.gradle

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
jcenter()
1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:3.6.4'
15+
classpath 'com.android.tools.build:gradle:4.1.1'
1616
}
1717
}
1818

@@ -29,5 +29,5 @@ task clean(type: Delete) {
2929

3030
ext {
3131
minSdkVersion = 23
32-
targetSdkVersion = 29
32+
targetSdkVersion = 30
3333
}

gradle.properties

100755100644
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ org.gradle.jvmargs=-Xmx1536m
1717
android.useAndroidX=true
1818
# Automatically convert third-party libraries to use AndroidX
1919
android.enableJetifier=true
20+
# https://github.com/google/prefab/issues/122
21+
android.prefabVersion=1.1.2

gradle/wrapper/gradle-wrapper.jar

100755100644
File mode changed.

gradle/wrapper/gradle-wrapper.properties

100755100644
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Fri Oct 09 23:12:33 CST 2020
12
distributionBase=GRADLE_USER_HOME
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
24
distributionPath=wrapper/dists
3-
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
6+
zipStoreBase=GRADLE_USER_HOME

gradlew.bat

100755100644
File mode changed.

module.gradle

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
ext {
2+
23
moduleId = "module_xfingerprint_pay_wechat"
3-
riruApiVersion = 7
4-
riruMinVersionName = "v21.2"
4+
moduleName = "指纹支付 - 微信"
5+
moduleAuthor = "Jason Eric"
6+
moduleDescription = "让微信支持指纹支付 Fingerprint pay for WeChat."
7+
moduleVersion = "v3.9.21"
8+
moduleVersionCode = 2
9+
10+
moduleMinRiruApiVersion = 9
11+
moduleMinRiruVersionName = "v22.0"
12+
moduleMaxRiruApiVersion = 10
513

614
moduleProp = [
7-
name : "指纹支付 - 微信",
8-
version : "v3.9.20",
9-
versionCode: "1",
10-
author : "Jason Eric",
11-
description: "让微信支持指纹支付 Fingerprint pay for WeChat.",
12-
api : riruApiVersion
15+
name : moduleName,
16+
version : moduleVersion,
17+
versionCode: moduleVersionCode.toString(),
18+
author : moduleAuthor,
19+
description: moduleDescription,
20+
minApi : moduleMinRiruApiVersion
1321
]
1422

1523
magiskModuleProp = [

module/build.gradle

100755100644
Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,45 @@ android {
66
defaultConfig {
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
9-
109
externalNativeBuild {
1110
cmake {
12-
arguments "-DMODULE_NAME:STRING=riru_$moduleId"
11+
arguments "-DMODULE_NAME:STRING=riru_$moduleId",
12+
"-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
13+
"-DRIRU_MODULE_VERSION=$moduleVersionCode",
14+
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$moduleVersion\""
15+
1316
}
1417
}
15-
ndk {
16-
abiFilters "armeabi-v7a", 'arm64-v8a', 'x86', 'x86_64'
17-
}
18+
}
19+
buildFeatures {
20+
prefab true
1821
}
1922
externalNativeBuild {
2023
cmake {
2124
path "src/main/cpp/CMakeLists.txt"
22-
version "3.9.1"
25+
version "3.10.2"
2326
}
2427
}
2528
}
2629

30+
repositories {
31+
mavenLocal()
32+
jcenter()
33+
maven { url 'https://dl.bintray.com/rikkaw/Libraries' }
34+
}
35+
36+
dependencies {
37+
implementation 'rikka.ndk:riru:10'
38+
}
39+
2740
def outDir = file("$rootDir/out")
2841
def magiskDir = file("$outDir/magisk_module")
29-
def zipName = "magisk-${magiskModuleProp['id'].replace('_', '-')}-${magiskModuleProp['version']}.zip"
42+
def zipName = "${magiskModuleProp['id'].replace('_', '-')}-${magiskModuleProp['version']}.zip"
3043
def riruDir = "$magiskDir/riru"
3144

45+
46+
import org.apache.tools.ant.filters.FixCrLfFilter
47+
3248
import java.nio.file.Files
3349
import java.security.MessageDigest
3450

@@ -46,8 +62,6 @@ static def renameOrFail(File from, File to) {
4662
}
4763
}
4864

49-
import org.apache.tools.ant.filters.FixCrLfFilter
50-
5165
android.libraryVariants.all { variant ->
5266
def task = variant.assembleProvider.get()
5367
task.doLast {
@@ -67,8 +81,8 @@ android.libraryVariants.all { variant ->
6781
include 'riru.sh'
6882
filter { line ->
6983
line.replaceAll('%%%RIRU_MODULE_ID%%%', moduleId)
70-
.replaceAll('%%%RIRU_MIN_API_VERSION%%%', riruApiVersion.toString())
71-
.replaceAll('%%%RIRU_MIN_VERSION_NAME%%%', riruMinVersionName)
84+
.replaceAll('%%%RIRU_MIN_API_VERSION%%%', moduleMinRiruApiVersion.toString())
85+
.replaceAll('%%%RIRU_MIN_VERSION_NAME%%%', moduleMinRiruVersionName)
7286
}
7387
filter(FixCrLfFilter.class,
7488
eol: FixCrLfFilter.CrLf.newInstance("lf"))

module/src/main/AndroidManifest.xml

100755100644
File mode changed.

module/src/main/cpp/CMakeLists.txt

100755100644
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ if (NOT DEFINED MODULE_NAME)
44
message(FATAL_ERROR "MODULE_NAME is not set")
55
endif ()
66

7+
add_definitions(-DRIRU_MODULE)
8+
add_definitions(-DRIRU_MODULE_API_VERSION=${RIRU_MODULE_API_VERSION})
9+
add_definitions(-DRIRU_MODULE_VERSION=${RIRU_MODULE_VERSION})
10+
add_definitions(-DRIRU_MODULE_VERSION_NAME=${RIRU_MODULE_VERSION_NAME})
11+
712
message("Build type: ${CMAKE_BUILD_TYPE}")
813

914
set(CMAKE_CXX_STANDARD 11)
@@ -24,6 +29,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS}")
2429
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
2530
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
2631

32+
find_package(riru REQUIRED CONFIG)
33+
2734
add_library(${MODULE_NAME} SHARED main.cpp)
28-
target_link_libraries(${MODULE_NAME} log)
35+
target_link_libraries(${MODULE_NAME} log riru::riru)
2936
set_target_properties(${MODULE_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)

module/src/main/cpp/main.cpp

100755100644
Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <unistd.h>
44
#include <jni.h>
55
#include <sys/types.h>
6+
#include <riru.h>
7+
#include <malloc.h>
8+
#include <cstring>
69

710
#include "log.h"
811

@@ -128,32 +131,26 @@ static void post(JNIEnv *env) {
128131
}
129132
}
130133

131-
// You can remove functions you don't need
132-
133-
extern "C" {
134-
#define EXPORT __attribute__((visibility("default"))) __attribute__((used))
135-
EXPORT void nativeForkAndSpecializePre(
134+
static void forkAndSpecializePre(
136135
JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtimeFlags,
137136
jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
138137
jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote,
139138
jstring *instructionSet, jstring *appDataDir, jboolean *isTopApp, jobjectArray *pkgDataInfoList,
140139
jobjectArray *whitelistedDataInfoList, jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) {
141-
// packageName, packagesForUID, sandboxId are added from Android Q beta 2, removed from beta 5
142140
pre(env, appDataDir, niceName);
143141
}
144142

145-
EXPORT int nativeForkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
143+
static void forkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
146144
if (res == 0) {
147145
// in app process
148146
post(env);
149147
} else {
150148
// in zygote process, res is child pid
151149
// don't print log here, see https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66
152150
}
153-
return 0;
154151
}
155152

156-
EXPORT __attribute__((visibility("default"))) void specializeAppProcessPre(
153+
static void specializeAppProcessPre(
157154
JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtimeFlags,
158155
jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
159156
jboolean *startChildZygote, jstring *instructionSet, jstring *appDataDir,
@@ -163,36 +160,114 @@ EXPORT __attribute__((visibility("default"))) void specializeAppProcessPre(
163160
pre(env, appDataDir, niceName);
164161
}
165162

166-
EXPORT __attribute__((visibility("default"))) int specializeAppProcessPost(
163+
static void specializeAppProcessPost(
167164
JNIEnv *env, jclass clazz) {
168165
// added from Android 10, but disabled at least in Google Pixel devices
169166
post(env);
170-
return 0;
171167
}
172168

173-
EXPORT void nativeForkSystemServerPre(
169+
static void forkSystemServerPre(
174170
JNIEnv *env, jclass clazz, uid_t *uid, gid_t *gid, jintArray *gids, jint *runtimeFlags,
175171
jobjectArray *rlimits, jlong *permittedCapabilities, jlong *effectiveCapabilities) {
176172

177173
}
178174

179-
EXPORT int nativeForkSystemServerPost(JNIEnv *env, jclass clazz, jint res) {
175+
static void forkSystemServerPost(JNIEnv *env, jclass clazz, jint res) {
180176
if (res == 0) {
181177
// in system server process
182178
} else {
183179
// in zygote process, res is child pid
184180
// don't print log here, see https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66
185181
}
186-
return 0;
187182
}
188183

189-
EXPORT int shouldSkipUid(int uid) {
184+
static int shouldSkipUid(int uid) {
190185
// by default, Riru only call module functions in "normal app processes" (10000 <= uid % 100000 <= 19999)
191186
// false = don't skip
192187
return false;
193188
}
194189

195-
EXPORT void onModuleLoaded() {
190+
static void onModuleLoaded() {
196191
// called when the shared library of Riru core is loaded
197192
}
193+
194+
extern "C" {
195+
196+
int riru_api_version;
197+
RiruApiV9 *riru_api_v9;
198+
199+
/*
200+
* Init will be called three times.
201+
*
202+
* The first time:
203+
* Returns the highest version number supported by both Riru and the module.
204+
*
205+
* arg: (int *) Riru's API version
206+
* returns: (int *) the highest possible API version
207+
*
208+
* The second time:
209+
* Returns the RiruModuleX struct created by the module.
210+
* (X is the return of the first call)
211+
*
212+
* arg: (RiruApiVX *) RiruApi strcut, this pointer can be saved for further use
213+
* returns: (RiruModuleX *) RiruModule strcut
214+
*
215+
* The second time:
216+
* Let the module to cleanup (such as RiruModuleX struct created before).
217+
*
218+
* arg: null
219+
* returns: (ignored)
220+
*
221+
*/
222+
void *init(void *arg) {
223+
static int step = 0;
224+
step += 1;
225+
226+
static void *_module;
227+
228+
switch (step) {
229+
case 1: {
230+
auto core_max_api_version = *(int *) arg;
231+
riru_api_version = core_max_api_version <= RIRU_MODULE_API_VERSION ? core_max_api_version : RIRU_MODULE_API_VERSION;
232+
return &riru_api_version;
233+
}
234+
case 2: {
235+
switch (riru_api_version) {
236+
// RiruApiV10 and RiruModuleInfoV10 are equal to V9
237+
case 10:
238+
case 9: {
239+
riru_api_v9 = (RiruApiV9 *) arg;
240+
241+
auto module = (RiruModuleInfoV9 *) malloc(sizeof(RiruModuleInfoV9));
242+
memset(module, 0, sizeof(RiruModuleInfoV9));
243+
_module = module;
244+
245+
module->supportHide = true;
246+
247+
module->version = RIRU_MODULE_VERSION;
248+
module->versionName = RIRU_MODULE_VERSION_NAME;
249+
module->onModuleLoaded = onModuleLoaded;
250+
module->shouldSkipUid = shouldSkipUid;
251+
module->forkAndSpecializePre = forkAndSpecializePre;
252+
module->forkAndSpecializePost = forkAndSpecializePost;
253+
module->specializeAppProcessPre = specializeAppProcessPre;
254+
module->specializeAppProcessPost = specializeAppProcessPost;
255+
module->forkSystemServerPre = forkSystemServerPre;
256+
module->forkSystemServerPost = forkSystemServerPost;
257+
return module;
258+
}
259+
default: {
260+
return nullptr;
261+
}
262+
}
263+
}
264+
case 3: {
265+
free(_module);
266+
return nullptr;
267+
}
268+
default: {
269+
return nullptr;
270+
}
271+
}
272+
}
198273
}

0 commit comments

Comments
 (0)