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

Commit

Permalink
Changes for Riru 25
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Mar 22, 2021
1 parent 6c81e6b commit ad34d71
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 460 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ idea.module {

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

allprojects {
repositories {
mavenLocal()
google()
jcenter()
}
Expand Down
8 changes: 1 addition & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn

android.useAndroidX=true
android.enableJetifier=false
org.gradle.parallel=true

# https://github.com/google/prefab/issues/122
android.prefabVersion=1.1.2
37 changes: 18 additions & 19 deletions module.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
ext {
gitCommitId = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
gitCommitCount = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim())

moduleMinRiruApiVersion = 25
moduleMinRiruVersionName = "v25.0.0"
moduleRiruApiVersion = 25

moduleId = "location_report_enabler"
moduleName = "Location Report Enabler"
moduleAuthor = "Rikka"
moduleDescription = "Enable Google Feed & Timeline & Location reprot in unsupported regions by changing system properties in related packages."
moduleVersion = "v10.2"
moduleVersionCode = 15
moduleMinRiruApiVersion = 9
moduleMinRiruVersionName = "v23.0"
moduleRiruApiVersion = 10

moduleProp = [
name : moduleName,
version : moduleVersion,
versionCode: moduleVersionCode.toString(),
author : moduleAuthor,
description: moduleDescription,
minApi : moduleMinRiruApiVersion
]
moduleVersionMajor = 11
moduleVersionMinor = 0
moduleVersionPatch = 0
moduleVersion = "v${moduleVersionMajor}.${moduleVersionMinor}.${moduleVersionPatch}"
moduleVersionCode = gitCommitCount

magiskModuleProp = [
moduleProp = [
id : "riru_$moduleId",
name : "Riru - ${moduleProp['name']}",
version : moduleProp['version'],
versionCode: moduleProp['versionCode'],
author : moduleProp['author'],
description: moduleProp['description']
name : "Riru - ${moduleName}",
version : "${moduleVersion}.r${gitCommitCount}.${gitCommitId}",
versionCode: moduleVersionCode,
author : moduleAuthor,
description: moduleDescription
]
}
103 changes: 60 additions & 43 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
externalNativeBuild {
cmake {
arguments "-DMODULE_NAME:STRING=riru_$moduleId",
arguments "-DMODULE_NAME:STRING=$moduleId",
"-DRIRU_MODULE_ID=$moduleId",
"-DRIRU_MODULE_API_VERSION=$moduleRiruApiVersion",
"-DRIRU_MODULE_VERSION=$moduleVersionCode",
Expand All @@ -29,23 +29,14 @@ android {
}
}

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

dependencies {
implementation 'rikka.ndk:riru:10'
implementation 'rikka.ndk.thirdparty:xhook:1.2.0'
implementation 'rikka.ndk.thirdparty:nativehelper:20201111'
implementation 'dev.rikka.ndk:riru:25.0.0'
implementation 'dev.rikka.ndk.thirdparty:xhook:1.2.0'
implementation 'dev.rikka.ndk.thirdparty:nativehelper:1.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"


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

Expand All @@ -60,15 +51,23 @@ static def calcSha256(file) {
return md.digest().encodeHex()
}

static def renameOrFail(File from, File to) {
if (!from.renameTo(to)) {
throw new IOException("Unable reanme file $from to $to")
android.libraryVariants.all { variant ->
def variantCapped = variant.name.capitalize()
def variantLowered = variant.name.toLowerCase()

def zipName = "${moduleId}-${moduleVersion}-${variantLowered}.zip"

def is_windows = org.gradle.internal.os.OperatingSystem.current().isWindows()

task("zip${variantCapped}", type: Zip) {
dependsOn("assemble${variantCapped}")
from magiskDir
archiveName zipName
destinationDir outDir
}
}

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

Expand Down Expand Up @@ -97,28 +96,17 @@ android.libraryVariants.all { variant ->

// generate module.prop
def modulePropText = ""
magiskModuleProp.each { k, v -> modulePropText += "$k=$v\n" }
moduleProp.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"))
copy {
from "$nativeOutDir"
into "$magiskDir/lib"
exclude "**/*.txt"
}

// generate sha1sum
fileTree("$magiskDir").matching {
Expand All @@ -127,12 +115,41 @@ android.libraryVariants.all { variant ->
if (f.directory) return
file(f.file.path + ".sha256sum").text = calcSha256(f.file)
}

task.finalizedBy("zip${variantCapped}")
}

task("push${variantCapped}", type: Exec) {
dependsOn("assemble${variantCapped}")
workingDir outDir
def commands = [android.adbExecutable, "push",
zipName,
"/data/local/tmp/"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}

task("flash${variantCapped}", type: Exec) {
dependsOn("push${variantCapped}")
def commands = [android.adbExecutable, "shell", "su", "-c",
"magisk --install-module /data/local/tmp/${zipName}"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}
task.finalizedBy zipMagiskMoudle
}

task zipMagiskMoudle(type: Zip) {
from magiskDir
archiveName zipName
destinationDir outDir
task("flashAndReoot${variantCapped}", type: Exec) {
dependsOn("flash${variantCapped}")
def commands = [android.adbExecutable, "shell", "reboot"]
if (is_windows) {
commandLine 'cmd', '/c', commands.join(" ")
} else {
commandLine commands
}
}
}
6 changes: 3 additions & 3 deletions module/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ add_definitions(-DRIRU_MODULE_VERSION_NAME=${RIRU_MODULE_VERSION_NAME})

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

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(LINKER_FLAGS "-ffixed-x18 -Wl,--hash-style=both")
set(C_FLAGS "-Werror=format -fdata-sections -ffunction-sections")
set(C_FLAGS "-Werror=format -fdata-sections -ffunction-sections -fno-exceptions -fno-rtti -fno-threadsafe-statics")

if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(C_FLAGS "${C_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden")
Expand All @@ -35,6 +35,6 @@ find_package(riru REQUIRED CONFIG)
find_package(nativehelper REQUIRED CONFIG)
find_package(xhook REQUIRED CONFIG)

add_library(${MODULE_NAME} SHARED main.cpp hook.cpp android.cpp misc.cpp config.cpp socket.cpp rirud.cpp)
add_library(${MODULE_NAME} SHARED main.cpp hook.cpp android.cpp misc.cpp config.cpp tinynew.cpp)
target_link_libraries(${MODULE_NAME} log riru::riru nativehelper::nativehelper_header_only xhook::xhook)
set_target_properties(${MODULE_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
64 changes: 17 additions & 47 deletions module/src/main/cpp/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/system_properties.h>
#include <riru.h>
#include "config.h"
#include "misc.h"
#include "logging.h"
#include "rirud.h"

using namespace Config;

Expand All @@ -25,10 +25,6 @@ namespace Config {
}


#define CONFIG_PATH "/data/adb/riru/modules/" RIRU_MODULE_ID "/config"
#define PROPS_PATH CONFIG_PATH "/properties"
#define PACKAGES_PATH CONFIG_PATH "/packages"

static std::map<std::string, Property *> props;
static std::vector<std::string> packages;

Expand Down Expand Up @@ -66,51 +62,25 @@ void Packages::Add(const char *name) {
}

void Config::Load() {
auto rirud_fd = rirud::OpenSocket();
if (rirud_fd != -1) {
LOGD("try read from rirud");

std::vector<std::string> prop_dirs, package_dirs;
if (rirud::ReadDir(rirud_fd, PROPS_PATH, prop_dirs)
&& rirud::ReadDir(rirud_fd, PACKAGES_PATH, package_dirs)) {
LOGD("read from rirud succeed");

for (const auto &name : prop_dirs) {
char path[PATH_MAX];
std::string *content;

snprintf(path, PATH_MAX, "%s/%s", PROPS_PATH, name.c_str());
char buf[PATH_MAX];

if (rirud::ReadFile(rirud_fd, path, &content)) {
Properties::Put(name.c_str(), (*content).c_str());
}
}
snprintf(buf, PATH_MAX, "%s/config/properties", riru_get_magisk_module_path());
foreach_dir(buf, [](int dirfd, struct dirent *entry, bool *) {
auto name = entry->d_name;
int fd = openat(dirfd, name, O_RDONLY);
if (fd == -1) return;

for (const auto &name : package_dirs) {
Packages::Add(name.c_str());
}
char buf[PROP_VALUE_MAX]{0};
if (read(fd, buf, PROP_VALUE_MAX) >= 0) {
Properties::Put(name, buf);
}

close(rirud_fd);
} else {
LOGD("read from rirud failed");
close(fd);
});

foreach_dir(PROPS_PATH, [](int dirfd, struct dirent *entry, bool *) {
auto name = entry->d_name;
int fd = openat(dirfd, name, O_RDONLY);
if (fd == -1) return;

char buf[PROP_VALUE_MAX]{0};
if (read(fd, buf, PROP_VALUE_MAX) >= 0) {
Properties::Put(name, buf);
}

close(fd);
});

foreach_dir(PACKAGES_PATH, [](int, struct dirent *entry, bool *) {
auto name = entry->d_name;
Packages::Add(name);
});
}
snprintf(buf, PATH_MAX, "%s/config/packages", riru_get_magisk_module_path());
foreach_dir(buf, [](int, struct dirent *entry, bool *) {
auto name = entry->d_name;
Packages::Add(name);
});
}
2 changes: 1 addition & 1 deletion module/src/main/cpp/hook.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <cstring>
#include <unistd.h>
#include <sys/system_properties.h>
#include <xhook/xhook.h>
#include <xhook.h>

#include "riru.h"
#include "logging.h"
Expand Down
Loading

0 comments on commit ad34d71

Please sign in to comment.