Skip to content

Commit

Permalink
升级 Riru v26
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Aug 10, 2021
1 parent 2d6a292 commit 22dbfe6
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 463 deletions.
6 changes: 4 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.prop text eol=lf
*.sh text eol=lf
* text=auto eol=lf

*.bat text eol=crlf
*.jar binary
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Rikka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ idea.module {

buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.2.2'
}
}

allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
minSdkVersion = 23
targetSdkVersion = 30

outDir = file("$rootDir/out")
}

task clean(type: Delete) {
delete rootProject.buildDir, outDir
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ 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
# Remove this until AGP update prefab version
android.prefabVersion=1.1.3
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Oct 09 23:12:33 CST 2020
#Mon Jul 12 21:05:17 CST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
53 changes: 26 additions & 27 deletions module.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
ext {
// FIXME replace with yours
moduleId = "il2cppdumper"
moduleName = "Il2CppDumper"
moduleAuthor = "Perfare"
moduleDescription = "Il2CppDumper Riru version."
moduleVersion = "v1.1"
moduleVersionCode = 1
/*
This name will be used in the name of the so file ("lib${moduleLibraryName}.so").
*/
moduleLibraryName = "il2cppdumper"

/* Minimal supported Riru API version, used in the version check of riru.sh */
moduleMinRiruApiVersion = 24

/* The version name of minimal supported Riru, used in the version check of riru.sh */
moduleMinRiruVersionName = "v24.0.0"

moduleMinRiruApiVersion = 9
moduleMinRiruVersionName = "v22.0"
moduleRiruApiVersion = 10
/* Maximum supported Riru API version, used in the version check of riru.sh */
moduleRiruApiVersion = 26

moduleProp = [
name : moduleName,
version : moduleVersion,
versionCode: moduleVersionCode.toString(),
author : moduleAuthor,
description: moduleDescription,
minApi : moduleMinRiruApiVersion
]
/*
Magisk module ID
Since Magisk use it to distinguish different modules, you should never change it.
magiskModuleProp = [
id : "riru-${moduleId.replace('_', '-')}",
name : "Riru - ${moduleProp['name']}",
version : moduleProp['version'],
versionCode: moduleProp['versionCode'],
author : moduleProp['author'],
description: moduleProp['description']
]
}
Note, the older version of the template uses '-' instead of '_', if your are upgrading from
the older version, please pay attention.
*/
magiskModuleId = "riru_il2cppdumper"

moduleName = "Il2CppDumper"
moduleAuthor = "Perfare"
moduleDescription = "Il2CppDumper Riru version."
moduleVersion = "v26.0.0"
moduleVersionCode = 26
}
176 changes: 85 additions & 91 deletions module/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import org.apache.tools.ant.filters.FixCrLfFilter
import org.apache.tools.ant.filters.ReplaceTokens

import java.security.MessageDigest

apply plugin: 'com.android.library'
apply from: file(rootProject.file('module.gradle'))

Expand All @@ -8,11 +13,11 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
externalNativeBuild {
cmake {
arguments "-DMODULE_NAME:STRING=riru_$moduleId",
arguments "-DMODULE_NAME:STRING=$moduleLibraryName",
"-DRIRU_MODULE_API_VERSION=$moduleRiruApiVersion",
"-DRIRU_MODULE_VERSION=$moduleVersionCode",
"-DRIRU_MODULE_VERSION_NAME:STRING=\"$moduleVersion\""

"-DRIRU_MODULE_VERSION_NAME:STRING=$moduleVersion",
"-DRIRU_MODULE_MIN_API_VERSION=$moduleMinRiruApiVersion"
}
}
}
Expand All @@ -29,8 +34,6 @@ android {

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

dependencies {
Expand All @@ -39,104 +42,95 @@ dependencies {
// you can copy this file from https://github.com/RikkaApps/Riru/blob/master/riru/src/main/cpp/include_riru/riru.h

// The default version of prefab in AGP has problem to process header only package,
// you may have to add android.prefabVersion=1.1.2 in your gradle.properties.
// you may have to add "android.prefabVersion" in your gradle.properties.
// See https://github.com/google/prefab/issues/122

implementation 'rikka.ndk:riru:10'
implementation 'dev.rikka.ndk:riru:26.0.0'
}

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

afterEvaluate {
android.libraryVariants.forEach { variant ->
def variantCapped = variant.name.capitalize()
def variantLowered = variant.name.toLowerCase()

import org.apache.tools.ant.filters.FixCrLfFilter
def zipName = "${magiskModuleId.replace('_', '-')}-${moduleVersion}-${variantLowered}.zip"
def magiskDir = file("$outDir/magisk_module_$variantLowered")

import java.nio.file.Files
import java.security.MessageDigest
task("prepareMagiskFiles${variantCapped}", type: Sync) {
dependsOn("assemble$variantCapped")

static def calcSha256(file) {
def md = MessageDigest.getInstance("SHA-256")
file.eachByte 4096, { bytes, size ->
md.update(bytes, 0, size);
}
return md.digest().encodeHex()
}
def templatePath = "$rootDir/template/magisk_module"

static def renameOrFail(File from, File to) {
if (!from.renameTo(to)) {
throw new IOException("Unable reanme file $from to $to")
}
}
into magiskDir
from(templatePath) {
exclude 'riru.sh', 'module.prop'
}
from(templatePath) {
include 'riru.sh'
filter(ReplaceTokens.class, tokens: [
"RIRU_MODULE_LIB_NAME" : moduleLibraryName,
"RIRU_MODULE_API_VERSION" : moduleRiruApiVersion.toString(),
"RIRU_MODULE_MIN_API_VERSION" : moduleMinRiruApiVersion.toString(),
"RIRU_MODULE_MIN_RIRU_VERSION_NAME": moduleMinRiruVersionName,
])
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
from(templatePath) {
include 'module.prop'
expand([
id : magiskModuleId,
name : moduleName,
version : moduleVersion,
versionCode: moduleVersionCode.toString(),
author : moduleAuthor,
description: moduleDescription,
])
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
from("$buildDir/intermediates/stripped_native_libs/$variantLowered/out/lib") {
into 'lib'
}
doLast {
fileTree("$magiskDir").visit { f ->
if (f.directory) return
if (f.file.name == '.gitattributes') return

def md = MessageDigest.getInstance("SHA-256")
f.file.eachByte 4096, { bytes, size ->
md.update(bytes, 0, size)
}
file(f.file.path + ".sha256sum").text = md.digest().encodeHex()
}
}
}

android.libraryVariants.all { variant ->
def task = variant.assembleProvider.get()
task.doLast {
// clear
delete { delete magiskDir }

// copy from template
copy {
from "$rootDir/template/magisk_module"
into magiskDir.path
exclude 'riru.sh'
task("zip${variantCapped}", type: Zip) {
dependsOn("prepareMagiskFiles${variantCapped}")
from magiskDir
archiveName zipName
destinationDir outDir
}
// copy riru.sh
copy {
from "$rootDir/template/magisk_module"
into magiskDir.path
include 'riru.sh'
filter { line ->
line.replaceAll('%%%RIRU_MODULE_ID%%%', moduleId)
.replaceAll('%%%RIRU_MODULE_API_VERSION%%%', moduleRiruApiVersion.toString())
.replaceAll('%%%RIRU_MODULE_MIN_API_VERSION%%%', moduleMinRiruApiVersion.toString())
.replaceAll('%%%RIRU_MODULE_MIN_RIRU_VERSION_NAME%%%', moduleMinRiruVersionName)
}
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))

task("push${variantCapped}", type: Exec) {
dependsOn("zip${variantCapped}")
workingDir outDir
commandLine android.adbExecutable, "push", zipName, "/data/local/tmp/"
}

task("flash${variantCapped}", type: Exec) {
dependsOn("push${variantCapped}")
commandLine android.adbExecutable, "shell", "su", "-c",
"magisk --install-module /data/local/tmp/${zipName}"
}
// copy .git files manually since gradle exclude it by default
Files.copy(file("$rootDir/template/magisk_module/.gitattributes").toPath(), file("${magiskDir.path}/.gitattributes").toPath())

// generate module.prop
def modulePropText = ""
magiskModuleProp.each { k, v -> modulePropText += "$k=$v\n" }
modulePropText = modulePropText.trim()
file("$magiskDir/module.prop").text = modulePropText

// generate module.prop for Riru
def riruModulePropText = ""
moduleProp.each { k, v -> riruModulePropText += "$k=$v\n" }
riruModulePropText = riruModulePropText.trim()
file(riruDir).mkdirs()

// module.prop.new will be renamed to module.prop in post-fs-data.sh
file("$riruDir/module.prop.new").text = riruModulePropText

// copy native files
def nativeOutDir = file("build/intermediates/cmake/$variant.name/obj")

file("$magiskDir/system").mkdirs()
file("$magiskDir/system_x86").mkdirs()
renameOrFail(file("$nativeOutDir/arm64-v8a"), file("$magiskDir/system/lib64"))
renameOrFail(file("$nativeOutDir/armeabi-v7a"), file("$magiskDir/system/lib"))
renameOrFail(file("$nativeOutDir/x86_64"), file("$magiskDir/system_x86/lib64"))
renameOrFail(file("$nativeOutDir/x86"), file("$magiskDir/system_x86/lib"))

// generate sha1sum
fileTree("$magiskDir").matching {
exclude "README.md", "META-INF"
}.visit { f ->
if (f.directory) return
file(f.file.path + ".sha256sum").text = calcSha256(f.file)

task("flashAndReboot${variantCapped}", type: Exec) {
dependsOn("flash${variantCapped}")
commandLine android.adbExecutable, "shell", "reboot"
}

variant.assembleProvider.get().finalizedBy("zip${variantCapped}")
}
task.finalizedBy zipMagiskMoudle
}

task zipMagiskMoudle(type: Zip) {
from magiskDir
archiveName zipName
destinationDir outDir
}
Loading

0 comments on commit 22dbfe6

Please sign in to comment.