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

Commit

Permalink
+ 3.9.21 适配Riru v22 困死了 又困又累
Browse files Browse the repository at this point in the history
  • Loading branch information
eritpchy committed Dec 3, 2020
1 parent 3bf522c commit cb11107
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 74 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.android.tools.build:gradle:4.1.1'
}
}

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

ext {
minSdkVersion = 23
targetSdkVersion = 29
targetSdkVersion = 30
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# https://github.com/google/prefab/issues/122
android.prefabVersion=1.1.2
Empty file modified gradle/wrapper/gradle-wrapper.jar
100755 → 100644
Empty file.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Oct 09 23:12:33 CST 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
zipStoreBase=GRADLE_USER_HOME
24 changes: 16 additions & 8 deletions module.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
ext {

moduleId = "module_xfingerprint_pay_alipay"
riruApiVersion = 7
riruMinVersionName = "v21.2"
moduleName = "指纹支付 - 支付宝"
moduleAuthor = "Jason Eric"
moduleDescription = "让支付宝支持指纹支付 Fingerprint pay for Alipay."
moduleVersion = "v3.9.21"
moduleVersionCode = 2

moduleMinRiruApiVersion = 9
moduleMinRiruVersionName = "v22.0"
moduleMaxRiruApiVersion = 10

moduleProp = [
name : "指纹支付 - 支付宝",
version : "v3.9.20",
versionCode: "1",
author : "Jason Eric",
description: "让支付宝支持指纹支付 Fingerprint pay for Alipay.",
api : riruApiVersion
name : moduleName,
version : moduleVersion,
versionCode: moduleVersionCode.toString(),
author : moduleAuthor,
description: moduleDescription,
minApi : moduleMinRiruApiVersion
]

magiskModuleProp = [
Expand Down
36 changes: 25 additions & 11 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,45 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion

externalNativeBuild {
cmake {
arguments "-DMODULE_NAME:STRING=riru_$moduleId"
arguments "-DMODULE_NAME:STRING=riru_$moduleId",
"-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
"-DRIRU_MODULE_VERSION=$moduleVersionCode",
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$moduleVersion\""

}
}
ndk {
abiFilters "armeabi-v7a", 'arm64-v8a', 'x86', 'x86_64'
}
}
buildFeatures {
prefab true
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.9.1"
version "3.10.2"
}
}
}

repositories {
mavenLocal()
jcenter()
maven { url 'https://dl.bintray.com/rikkaw/Libraries' }
}

dependencies {
implementation 'rikka.ndk:riru:10'
}

def outDir = file("$rootDir/out")
def magiskDir = file("$outDir/magisk_module")
def zipName = "magisk-${magiskModuleProp['id'].replace('_', '-')}-${magiskModuleProp['version']}.zip"
def zipName = "${magiskModuleProp['id'].replace('_', '-')}-${magiskModuleProp['version']}.zip"
def riruDir = "$magiskDir/riru"


import org.apache.tools.ant.filters.FixCrLfFilter

import java.nio.file.Files
import java.security.MessageDigest

Expand All @@ -46,8 +62,6 @@ static def renameOrFail(File from, File to) {
}
}

import org.apache.tools.ant.filters.FixCrLfFilter

android.libraryVariants.all { variant ->
def task = variant.assembleProvider.get()
task.doLast {
Expand All @@ -67,8 +81,8 @@ android.libraryVariants.all { variant ->
include 'riru.sh'
filter { line ->
line.replaceAll('%%%RIRU_MODULE_ID%%%', moduleId)
.replaceAll('%%%RIRU_MIN_API_VERSION%%%', riruApiVersion.toString())
.replaceAll('%%%RIRU_MIN_VERSION_NAME%%%', riruMinVersionName)
.replaceAll('%%%RIRU_MIN_API_VERSION%%%', moduleMinRiruApiVersion.toString())
.replaceAll('%%%RIRU_MIN_VERSION_NAME%%%', moduleMinRiruVersionName)
}
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
Expand Down
Binary file modified module/libs/fingerprint-pay-alipay-magisk.apk
Binary file not shown.
9 changes: 8 additions & 1 deletion module/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ if (NOT DEFINED MODULE_NAME)
message(FATAL_ERROR "MODULE_NAME is not set")
endif ()

add_definitions(-DRIRU_MODULE)
add_definitions(-DRIRU_MODULE_API_VERSION=${RIRU_MODULE_API_VERSION})
add_definitions(-DRIRU_MODULE_VERSION=${RIRU_MODULE_VERSION})
add_definitions(-DRIRU_MODULE_VERSION_NAME=${RIRU_MODULE_VERSION_NAME})

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

set(CMAKE_CXX_STANDARD 11)
Expand All @@ -24,6 +29,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")

find_package(riru REQUIRED CONFIG)

add_library(${MODULE_NAME} SHARED main.cpp)
target_link_libraries(${MODULE_NAME} log)
target_link_libraries(${MODULE_NAME} log riru::riru)
set_target_properties(${MODULE_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
107 changes: 91 additions & 16 deletions module/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <unistd.h>
#include <jni.h>
#include <sys/types.h>
#include <riru.h>
#include <malloc.h>
#include <cstring>

#include "log.h"

Expand Down Expand Up @@ -128,32 +131,26 @@ static void post(JNIEnv *env) {
}
}

// You can remove functions you don't need

extern "C" {
#define EXPORT __attribute__((visibility("default"))) __attribute__((used))
EXPORT void nativeForkAndSpecializePre(
static void forkAndSpecializePre(
JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtimeFlags,
jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote,
jstring *instructionSet, jstring *appDataDir, jboolean *isTopApp, jobjectArray *pkgDataInfoList,
jobjectArray *whitelistedDataInfoList, jboolean *bindMountAppDataDirs, jboolean *bindMountAppStorageDirs) {
// packageName, packagesForUID, sandboxId are added from Android Q beta 2, removed from beta 5
pre(env, appDataDir, niceName);
}

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

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

EXPORT __attribute__((visibility("default"))) int specializeAppProcessPost(
static void specializeAppProcessPost(
JNIEnv *env, jclass clazz) {
// added from Android 10, but disabled at least in Google Pixel devices
post(env);
return 0;
}

EXPORT void nativeForkSystemServerPre(
static void forkSystemServerPre(
JNIEnv *env, jclass clazz, uid_t *uid, gid_t *gid, jintArray *gids, jint *runtimeFlags,
jobjectArray *rlimits, jlong *permittedCapabilities, jlong *effectiveCapabilities) {

}

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

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

EXPORT void onModuleLoaded() {
static void onModuleLoaded() {
// called when the shared library of Riru core is loaded
}

extern "C" {

int riru_api_version;
RiruApiV9 *riru_api_v9;

/*
* Init will be called three times.
*
* The first time:
* Returns the highest version number supported by both Riru and the module.
*
* arg: (int *) Riru's API version
* returns: (int *) the highest possible API version
*
* The second time:
* Returns the RiruModuleX struct created by the module.
* (X is the return of the first call)
*
* arg: (RiruApiVX *) RiruApi strcut, this pointer can be saved for further use
* returns: (RiruModuleX *) RiruModule strcut
*
* The second time:
* Let the module to cleanup (such as RiruModuleX struct created before).
*
* arg: null
* returns: (ignored)
*
*/
void *init(void *arg) {
static int step = 0;
step += 1;

static void *_module;

switch (step) {
case 1: {
auto core_max_api_version = *(int *) arg;
riru_api_version = core_max_api_version <= RIRU_MODULE_API_VERSION ? core_max_api_version : RIRU_MODULE_API_VERSION;
return &riru_api_version;
}
case 2: {
switch (riru_api_version) {
// RiruApiV10 and RiruModuleInfoV10 are equal to V9
case 10:
case 9: {
riru_api_v9 = (RiruApiV9 *) arg;

auto module = (RiruModuleInfoV9 *) malloc(sizeof(RiruModuleInfoV9));
memset(module, 0, sizeof(RiruModuleInfoV9));
_module = module;

module->supportHide = true;

module->version = RIRU_MODULE_VERSION;
module->versionName = RIRU_MODULE_VERSION_NAME;
module->onModuleLoaded = onModuleLoaded;
module->shouldSkipUid = shouldSkipUid;
module->forkAndSpecializePre = forkAndSpecializePre;
module->forkAndSpecializePost = forkAndSpecializePost;
module->specializeAppProcessPre = specializeAppProcessPre;
module->specializeAppProcessPost = specializeAppProcessPost;
module->forkSystemServerPre = forkSystemServerPre;
module->forkSystemServerPost = forkSystemServerPost;
return module;
}
default: {
return nullptr;
}
}
}
case 3: {
free(_module);
return nullptr;
}
default: {
return nullptr;
}
}
}
}
19 changes: 5 additions & 14 deletions template/magisk_module/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,13 @@ fi
ui_print "- Extracting extra libraries"
extract "$ZIPFILE" "system/framework/libriru_$RIRU_MODULE_ID.dex" "$MODPATH"

# Riru files
ui_print "- Extracting extra files"
[ -d "$RIRU_MODULE_PATH" ] || mkdir -p "$RIRU_MODULE_PATH" || abort_clean "! Can't create $RIRU_MODULE_PATH"
set_perm_recursive "$MODPATH" 0 0 0755 0644

# set permission just in case
set_perm "$RIRU_PATH" 0 0 0700
set_perm "$RIRU_PATH/modules" 0 0 0700
set_perm "$RIRU_MODULE_PATH" 0 0 0700
set_perm "$RIRU_MODULE_PATH/bin" 0 0 0700
# extract Riru files
ui_print "- Extracting extra files"
[ -d "$RIRU_MODULE_PATH" ] || mkdir -p "$RIRU_MODULE_PATH" || abort "! Can't create $RIRU_MODULE_PATH"

rm -f "$RIRU_MODULE_PATH/module.prop.new"
extract "$ZIPFILE" 'riru/module.prop.new' "$RIRU_MODULE_PATH" true
set_perm "$RIRU_MODULE_PATH/module.prop.new" 0 0 0600

cp -f "$RIRU_MODULE_PATH/module.prop.new" "$RIRU_MODULE_PATH/module.prop"

# set permissions
ui_print "- Setting permissions"
set_perm_recursive "$MODPATH" 0 0 0755 0644
set_perm "$RIRU_MODULE_PATH/module.prop.new" 0 0 0600 $RIRU_SECONTEXT
3 changes: 0 additions & 3 deletions template/magisk_module/post-fs-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ MODDIR=${0%/*}
[ ! -f "$MODDIR/riru.sh" ] && exit 1
. $MODDIR/riru.sh

# Reset context jsut in case
chcon -R u:object_r:system_file:s0 "$MODDIR"

# Rename module.prop.new
if [ -f "$RIRU_MODULE_PATH/module.prop.new" ]; then
rm "$RIRU_MODULE_PATH/module.prop"
Expand Down
Loading

0 comments on commit cb11107

Please sign in to comment.