Skip to content

Commit

Permalink
Remove Riru
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimjio committed May 30, 2023
1 parent 805d86a commit ff75f94
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 237 deletions.
38 changes: 2 additions & 36 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,12 @@ android {
buildConfigField("String", "API", "\"$name\"")
}

register("Riru") {
dimension = "api"
externalNativeBuild {
cmake {
arguments += "-DMODULE_VERSION=$moduleVersionCode"
arguments += "-DMODULE_VERSION_NAME:STRING=$moduleVersion"
arguments += "-DRIRU_MODULE=true"
arguments += "-DRIRU_MODULE_API_VERSION=$moduleRiruApiVersion"
arguments += "-DRIRU_MODULE_MIN_API_VERSION=$moduleMinRiruApiVersion"
}
}
}

register("Zygisk") {
dimension = "api"
externalNativeBuild {
cmake {
arguments += "-DMODULE_VERSION=$moduleVersionCode"
arguments += "-DMODULE_VERSION_NAME:STRING=$moduleVersion"
arguments += "-DRIRU_MODULE_API_VERSION=-1"
arguments += "-DRIRU_MODULE_MIN_API_VERSION=-1"
}
}
}
Expand All @@ -68,10 +53,6 @@ repositories {
}

dependencies {
// This is prefab aar which contains "riru.h"
// If you want to use older versions of AGP,
// you can copy this file from https://github.com/RikkaApps/Riru/blob/master/riru/src/main/cpp/include_riru/riru.h
implementation 'dev.rikka.ndk:riru:26.0.0'
}

afterEvaluate {
Expand All @@ -94,7 +75,7 @@ afterEvaluate {
into magiskDir

from(templatePath) {
exclude "riru.sh", "module.prop", 'system.prop', "customize.sh", "service.sh"
exclude "module.prop", 'system.prop', "customize.sh", "service.sh"
}
from(templatePath) {
include 'module.prop'
Expand All @@ -106,8 +87,7 @@ afterEvaluate {
author : moduleAuthor,
description: "$moduleDescription $flavorCapped version.",
updateJson : "${moduleUpdateJson}-${flavorLowered}.json",
requirement: flavorLowered == "riru" ? "Requires Riru $moduleMinRiruVersionName or above installed" :
flavorLowered == "zygisk" ? "Requires Magisk 24.0+ and Zygisk enabled" : null,
requirement: "Requires Magisk 24.0+ and Zygisk enabled",
api : flavorCapped
])
filter(FixCrLfFilter.class,
Expand Down Expand Up @@ -140,20 +120,6 @@ afterEvaluate {
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
if (flavorLowered == "riru") {
from(templatePath) {
include "riru.sh"
filter(ReplaceTokens.class, tokens: [
"MODULE_LIB_NAME" : moduleLibraryName,
"RIRU_MODULE_API_VERSION" : moduleRiruApiVersion.toString(),
"RIRU_MODULE_MIN_API_VERSION" : moduleMinRiruApiVersion.toString(),
"RIRU_MODULE_MIN_RIRU_VERSION_NAME": moduleMinRiruVersionName,
"RIRU_MODULE_DEBUG" : buildTypeLowered == "debug" ? "true" : "false"
])
filter(FixCrLfFilter.class,
eol: FixCrLfFilter.CrLf.newInstance("lf"))
}
}
from("$buildDir/intermediates/stripped_native_libs/$variantLowered/out/lib") {
into 'lib'
}
Expand Down
16 changes: 2 additions & 14 deletions module/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ else ()
project(${MODULE_NAME})
endif ()

add_definitions(-DRIRU_MODULE)

configure_file(template/config.cpp config.cpp)

macro(SET_OPTION option value)
Expand Down Expand Up @@ -62,18 +60,8 @@ target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
target_compile_definitions(sqlite3 PUBLIC SQLITE_TEMP_STORE=3)
target_compile_definitions(sqlite3 PUBLIC SQLITE_USE_URI=1)

if (${API} STREQUAL "zygisk")
add_library(${MODULE_NAME} SHARED main_zygisk.cpp hook.cpp il2cpp/il2cpp_symbols.cpp il2cpp_hook.cpp localify/localify.cpp jwt/jwt.cpp logger/logger.cpp notifier/notifier.cpp elf_util.cpp zygoteloader/serializer.c zygoteloader/dex.cpp zygoteloader/main.c ${CMAKE_CURRENT_BINARY_DIR}/config.cpp)
target_link_libraries(${MODULE_NAME} log dobby SQLiteCpp sqlite3 lsplant_static hmac_sha256 httplib)
elseif (${API} STREQUAL "riru")
find_package(riru REQUIRED CONFIG)

add_library(${MODULE_NAME} SHARED main_riru.cpp hook.cpp il2cpp/il2cpp_symbols.cpp il2cpp_hook.cpp localify/localify.cpp jwt/jwt.cpp logger/logger.cpp notifier/notifier.cpp elf_util.cpp zygoteloader/serializer.c zygoteloader/dex.cpp zygoteloader/main.c ${CMAKE_CURRENT_BINARY_DIR}/config.cpp)
target_link_libraries(${MODULE_NAME} log dobby SQLiteCpp sqlite3 lsplant_static hmac_sha256 httplib riru::riru)
else ()
add_library(${MODULE_NAME} SHARED main_zygisk.cpp hook.cpp il2cpp/il2cpp_symbols.cpp il2cpp_hook.cpp localify/localify.cpp jwt/jwt.cpp logger/logger.cpp notifier/notifier.cpp elf_util.cpp zygoteloader/serializer.c zygoteloader/dex.cpp zygoteloader/main.c ${CMAKE_CURRENT_BINARY_DIR}/config.cpp)
target_link_libraries(${MODULE_NAME} log dobby SQLiteCpp sqlite3 lsplant_static hmac_sha256 httplib)
endif ()
add_library(${MODULE_NAME} SHARED main.cpp hook.cpp il2cpp/il2cpp_symbols.cpp il2cpp_hook.cpp localify/localify.cpp jwt/jwt.cpp logger/logger.cpp notifier/notifier.cpp elf_util.cpp zygoteloader/serializer.c zygoteloader/dex.cpp zygoteloader/main.c ${CMAKE_CURRENT_BINARY_DIR}/config.cpp)
target_link_libraries(${MODULE_NAME} log dobby SQLiteCpp sqlite3 lsplant_static hmac_sha256 httplib)

if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_command(TARGET ${MODULE_NAME} POST_BUILD
Expand Down
7 changes: 0 additions & 7 deletions module/src/main/cpp/include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@ namespace Module {
extern const int moduleVersionCode;
extern const char *const moduleVersionName;
}

#ifdef RIRU_MODULE
namespace riru {
extern const int moduleApiVersion;
extern const int moduleMinApiVersion;
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#include "zygoteloader/dex.hpp"
#include "zygoteloader/main.h"

#define _uintval(p) reinterpret_cast<uintptr_t>(p)
#define _ptr(p) reinterpret_cast<void *>(p)
#define _u_int_val(p) reinterpret_cast<uintptr_t>(p)
#define _ptr(p) (reinterpret_cast<void *>(p))
#define _align_up(x, n) (((x) + ((n) - 1)) & ~((n) - 1))
#define _align_down(x, n) ((x) & -(n))
#define _page_size 4096
#define _page_align(n) _align_up(static_cast<uintptr_t>(n), _page_size)
#define _ptr_align(x) _ptr(_align_down(reinterpret_cast<uintptr_t>(x), _page_size))
#define _make_rwx(p, n) ::mprotect(_ptr_align(p), \
_page_align(_uintval(p) + n) != _page_align(_uintval(p)) ? _page_align(n) + _page_size : _page_align(n), \
#define make_rwx(p, n) ::mprotect(_ptr_align(p), \
_page_align(_u_int_val(p) + (n)) != _page_align(_u_int_val(p)) ? _page_align(n) + _page_size : _page_align(n), \
PROT_READ | PROT_WRITE | PROT_EXEC)

enum FileCommand : int {
Expand All @@ -33,10 +33,8 @@ using zygisk::Api;
using zygisk::AppSpecializeArgs;
using zygisk::ServerSpecializeArgs;

string moduleApi = "zygisk";

void *InlineHooker(void *target, void *hooker) {
_make_rwx(target, _page_size);
make_rwx(target, _page_size);
void *origin_call;
if (DobbyHook(target, hooker, &origin_call) == RS_SUCCESS) {
return origin_call;
Expand All @@ -49,7 +47,7 @@ bool InlineUnhooker(void *func) {
return DobbyDestroy(func) == RT_SUCCESS;
}

static void handleFileRequest(int client) {
void handleFileRequest(int client) {
static pthread_mutex_t initializeLock = PTHREAD_MUTEX_INITIALIZER;
static int classesDex = -1;
static int moduleDirectory = -1;
Expand Down Expand Up @@ -108,7 +106,7 @@ class Module : public zygisk::ModuleBase {
env->ReleaseStringUTFChars(args->nice_name, pkgNm);
}

void postAppSpecialize(const AppSpecializeArgs *args) override {
void postAppSpecialize(const AppSpecializeArgs *) override {
if (enable_hack /* || enable_settings_hack */) {
/*if (enable_hack && Game::currentGameRegion == Game::Region::KOR) {
SandHook::ElfImg art("libart.so");
Expand All @@ -130,19 +128,20 @@ class Module : public zygisk::ModuleBase {
}
}*/
int ret;
pthread_t ntid;
if ((ret = pthread_create(&ntid, nullptr,
reinterpret_cast<void *(*)(void *)>(/* enable_settings_hack
pthread_t t;
ret = pthread_create(&t, nullptr,
reinterpret_cast<void *(*)(void *)>(/* enable_settings_hack
? hack_settings_thread
: */hack_thread),
classesDex))) {
classesDex);
if (ret != 0) {
LOGE("can't create thread: %s\n", strerror(ret));
}
}
}

void fetchResources() {
int remote = api->connectCompanion();
const int remote = api->connectCompanion();
serializer_write_int(remote, GET_RESOURCES);
int classesDexFd = -1;
serializer_read_file_descriptor(remote, &classesDexFd);
Expand All @@ -157,7 +156,7 @@ class Module : public zygisk::ModuleBase {
Resource *classesDex{};

bool isInitialized() {
int remote = api->connectCompanion();
const int remote = api->connectCompanion();

serializer_write_int(remote, IS_INITIALIZED);

Expand All @@ -170,9 +169,9 @@ class Module : public zygisk::ModuleBase {
}

void initialize() {
int remote = api->connectCompanion();
const int remote = api->connectCompanion();

int moduleDir = api->getModuleDir();
const int moduleDir = api->getModuleDir();

serializer_write_int(remote, INITIALIZE);
serializer_write_file_descriptor(remote, moduleDir);
Expand All @@ -183,8 +182,9 @@ REGISTER_ZYGISK_MODULE(Module)

REGISTER_ZYGISK_COMPANION(handleFileRequest)

extern "C" {
[[gnu::visibility("default")]] [[gnu::used]]
static void hook() __attribute__((constructor));
void hook() __attribute__((constructor));

void hook() {
if (IsRunningOnNativeBridge()) {
Expand All @@ -194,10 +194,12 @@ void hook() {
return;
}
int ret;
pthread_t ntid;
if ((ret = pthread_create(&ntid, nullptr,
reinterpret_cast<void *(*)(void *)>(hack_thread), nullptr))) {
pthread_t t;
ret = pthread_create(&t, nullptr,
reinterpret_cast<void *(*)(void *)>(hack_thread), nullptr);
if (ret != 0) {
LOGE("can't create thread: %s\n", strerror(ret));
}
}
}
}
140 changes: 0 additions & 140 deletions module/src/main/cpp/main_riru.cpp

This file was deleted.

Loading

0 comments on commit ff75f94

Please sign in to comment.