diff --git a/.gitattributes b/.gitattributes
index de3806bdc95..edda2b0aed4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -8,3 +8,5 @@
# Denote all files that are truly binary and should not be modified.
*.so binary
*.dex binary
+*.jar binary
+*.png binary
diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml
index 3464b7b1019..e21dbb5b27d 100644
--- a/.github/workflows/core.yml
+++ b/.github/workflows/core.yml
@@ -52,7 +52,7 @@ jobs:
key: gradle-builds-core-${{ github.sha }}
restore-keys: |
gradle-builds
- - name: Cache Cmake
+ - name: Cache Ccache
uses: actions/cache@v2
with:
path: ~/.ccache
@@ -64,6 +64,8 @@ jobs:
ccache -o max_size=2G
ccache -o hash_dir=false
- name: Build with Gradle
+ env:
+ NDK_CCACHE: ccache
run: |
[ $(du -s ~/.gradle/wrapper | awk '{ print $1 }') -gt 250000 ] && rm -rf ~/.gradle/wrapper/* || true
find ~/.gradle/caches -exec touch -d "2 days ago" {} + || true
diff --git a/.gitmodules b/.gitmodules
index 63c33addfd8..25d4c65484e 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,6 +4,3 @@
[submodule "core/src/main/cpp/external/DexBuilder"]
path = core/src/main/cpp/external/DexBuilder
url = https://github.com/LSPosed/DexBuilder.git
-[submodule "core/src/main/cpp/external/Dobby"]
- path = core/src/main/cpp/external/Dobby
- url = https://github.com/LSPosed/Dobby.git
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 2ed493ba3d9..05dd8ce5e84 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -26,7 +26,6 @@ plugins {
id("org.gradle.idea")
id("com.android.application")
id("androidx.navigation.safeargs")
- kotlin("android")
}
// workaround for AS.
@@ -210,7 +209,7 @@ dependencies {
implementation("androidx.fragment:fragment:1.3.4")
implementation("androidx.navigation:navigation-fragment:$navVersion")
implementation("androidx.navigation:navigation-ui:$navVersion")
- implementation("androidx.recyclerview:recyclerview:1.2.0")
+ implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("com.caverock:androidsvg-aar:1.4")
implementation("com.github.bumptech.glide:glide:$glideVersion")
diff --git a/build.gradle.kts b/build.gradle.kts
index 5af00ed1bf5..ba07f5281bb 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -28,7 +28,6 @@ buildscript {
classpath("com.android.tools.build:gradle:7.0.0-beta04")
classpath("org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5")
- classpath(kotlin("gradle-plugin", version = "1.4.32"))
}
}
diff --git a/core/.gitignore b/core/.gitignore
index 2db27e3600f..e14e74c6df5 100644
--- a/core/.gitignore
+++ b/core/.gitignore
@@ -4,3 +4,4 @@
/release
*.iml
/.cxx
+src/main/cpp/main/src/config.cpp
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index 088e18081ae..f06a75d78f9 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -17,8 +17,8 @@
* Copyright (C) 2021 LSPosed Contributors
*/
-import com.android.build.api.variant.impl.ApplicationVariantImpl
import com.android.build.api.component.analytics.AnalyticsEnabledApplicationVariant
+import com.android.build.api.variant.impl.ApplicationVariantImpl
import com.android.build.gradle.BaseExtension
import com.android.ide.common.signing.KeystoreHelper
import org.apache.tools.ant.filters.FixCrLfFilter
@@ -29,7 +29,6 @@ import java.security.MessageDigest
plugins {
id("com.android.application")
- kotlin("android")
}
val moduleName = "LSPosed"
@@ -59,6 +58,7 @@ val verName: String by rootProject.extra
dependencies {
implementation("dev.rikka.ndk:riru:${moduleMinRiruVersionName}")
implementation("dev.rikka.ndk.thirdparty:cxx:1.1.0")
+ implementation("io.github.vvb2060.ndk:dobby:1.0")
implementation("com.android.tools.build:apksig:7.0.0-beta03")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("de.upb.cs.swt:axml:2.1.1")
@@ -87,29 +87,9 @@ android {
multiDexEnabled = false
externalNativeBuild {
- cmake {
- abiFilters("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
- val flags = arrayOf(
- "-ffixed-x18",
- "-Qunused-arguments",
- "-fno-rtti", "-fno-exceptions",
- "-fno-stack-protector",
- "-fomit-frame-pointer",
- "-Wno-builtin-macro-redefined",
- "-Wl,--exclude-libs,ALL",
- "-D__FILE__=__FILE_NAME__",
- "-DRIRU_MODULE",
- "-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
- """-DMODULE_NAME=\"$riruModuleId\"""",
- )
- cppFlags("-std=c++20", *flags)
- cFlags("-std=c18", *flags)
- arguments(
- "-DANDROID_STL=none",
- "-DVERSION_CODE=$verCode",
- "-DVERSION_NAME=$verName",
- )
- targets("lspd")
+ ndkBuild {
+ arguments += "RIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion"
+ arguments += "MODULE_NAME=$riruModuleId"
}
}
@@ -123,56 +103,14 @@ android {
}
buildTypes {
- debug {
- externalNativeBuild {
- cmake {
- arguments.addAll(
- arrayOf(
- "-DCMAKE_CXX_FLAGS_DEBUG=-Og",
- "-DCMAKE_C_FLAGS_DEBUG=-Og"
- )
- )
- }
- }
- }
release {
isMinifyEnabled = true
proguardFiles("proguard-rules.pro")
-
- externalNativeBuild {
- cmake {
- val flags = arrayOf(
- "-fvisibility=hidden",
- "-fvisibility-inlines-hidden",
- "-Wno-unused-value",
- "-ffunction-sections",
- "-fdata-sections",
- "-Wl,--gc-sections",
- "-Wl,--strip-all",
- "-fno-unwind-tables",
- "-fno-asynchronous-unwind-tables"
- )
- cppFlags.addAll(flags)
- cFlags.addAll(flags)
- val configFlags = arrayOf(
- "-Oz",
- "-DNDEBUG"
- ).joinToString(" ")
- arguments.addAll(
- arrayOf(
- "-DCMAKE_CXX_FLAGS_RELEASE=$configFlags",
- "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=$configFlags",
- "-DCMAKE_C_FLAGS_RELEASE=$configFlags",
- "-DCMAKE_C_FLAGS_RELWITHDEBINFO=$configFlags"
- )
- )
- }
- }
}
}
externalNativeBuild {
- cmake {
- path("src/main/cpp/CMakeLists.txt")
+ ndkBuild {
+ path("src/main/cpp/Android.mk")
}
}
@@ -278,8 +216,7 @@ androidComponents.onVariants { v ->
rename(".*\\.apk", "manager.apk")
}
into("lib") {
- from("${buildDir}/intermediates/cmake/$variantLowered/obj")
- exclude("**/*.txt")
+ from("${buildDir}/intermediates/stripped_native_libs/$variantLowered/out/lib")
}
val dexOutPath = if (variantLowered == "release")
"$buildDir/intermediates/dex/$variantLowered/minify${variantCapped}WithR8" else
@@ -342,3 +279,13 @@ androidComponents.onVariants { v ->
}
}
}
+
+val generateVersion = task("generateVersion", Copy::class) {
+ inputs.property("VERSION_CODE", verCode)
+ inputs.property("VERSION_NAME", verName)
+ from("${projectDir}/src/main/cpp/main/template")
+ include("config.cpp")
+ expand("VERSION_CODE" to verCode, "VERSION_NAME" to verName)
+ into("${projectDir}/src/main/cpp/main/src")
+}
+tasks.getByName("preBuild").dependsOn(generateVersion)
diff --git a/core/src/main/cpp/Android.mk b/core/src/main/cpp/Android.mk
new file mode 100644
index 00000000000..cba3d605052
--- /dev/null
+++ b/core/src/main/cpp/Android.mk
@@ -0,0 +1,7 @@
+include src/main/cpp/external/DexBuilder/Android.mk
+include src/main/cpp/external/yahfa/Android.mk
+include src/main/cpp/main/Android.mk
+
+$(call import-module,prefab/cxx)
+$(call import-module,prefab/riru)
+$(call import-module,prefab/dobby)
diff --git a/core/src/main/cpp/Application.mk b/core/src/main/cpp/Application.mk
new file mode 100644
index 00000000000..d538dcca07f
--- /dev/null
+++ b/core/src/main/cpp/Application.mk
@@ -0,0 +1,14 @@
+APP_CFLAGS := -Wall -Wextra
+APP_CFLAGS += -fno-stack-protector -fomit-frame-pointer
+APP_CFLAGS += -Wno-builtin-macro-redefined -D__FILE__=__FILE_NAME__
+APP_CPPFLAGS := -std=c++20
+APP_CONLYFLAGS := -std=c18
+APP_LDFLAGS := -Wl,--exclude-libs,ALL
+APP_STL := none
+
+ifneq ($(NDK_DEBUG),1)
+APP_CFLAGS += -Oz -Wno-unused -Wno-unused-parameter -Werror
+APP_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
+APP_CFLAGS += -fno-unwind-tables -fno-asynchronous-unwind-tables
+APP_LDFLAGS += -Wl,--gc-sections -Wl,--strip-all
+endif
diff --git a/core/src/main/cpp/CMakeLists.txt b/core/src/main/cpp/CMakeLists.txt
deleted file mode 100644
index 3eb0fa0d157..00000000000
--- a/core/src/main/cpp/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-##
-## This file is part of LSPosed.
-##
-## LSPosed is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## LSPosed is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with LSPosed. If not, see .
-##
-## Copyright (C) 2020 EdXposed Contributors
-## Copyright (C) 2021 LSPosed Contributors
-##
-
-project(libcxx)
-cmake_minimum_required(VERSION 3.4.1)
-
-find_program(CCACHE ccache)
-
-if (CCACHE)
- set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
- set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
-endif ()
-
-find_package(cxx REQUIRED CONFIG)
-link_libraries(cxx::cxx)
-
-add_subdirectory(main)
-add_subdirectory(external)
diff --git a/core/src/main/cpp/external/CMakeLists.txt b/core/src/main/cpp/external/CMakeLists.txt
deleted file mode 100644
index 1ba04678b20..00000000000
--- a/core/src/main/cpp/external/CMakeLists.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-cmake_minimum_required(VERSION 3.4.1)
-
-add_subdirectory(yahfa)
-
-add_subdirectory(DexBuilder)
-target_include_directories(dex_builder PUBLIC DexBuilder)
-
-macro(SET_OPTION option value)
- set(${option} ${value} CACHE INTERNAL "" FORCE)
-endmacro()
-
-SET_OPTION(DOBBY_GENERATE_SHARED OFF)
-if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
- SET_OPTION(DOBBY_DEBUG OFF)
-endif (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
-add_subdirectory(Dobby)
-target_include_directories(dobby PUBLIC Dobby/include)
diff --git a/core/src/main/cpp/external/DexBuilder b/core/src/main/cpp/external/DexBuilder
index 41b91718528..9141e5aed87 160000
--- a/core/src/main/cpp/external/DexBuilder
+++ b/core/src/main/cpp/external/DexBuilder
@@ -1 +1 @@
-Subproject commit 41b9171852840cb421d8be22ef73d9467db02799
+Subproject commit 9141e5aed87360fa6926ad05a8ac1511fc6bcbe6
diff --git a/core/src/main/cpp/external/Dobby b/core/src/main/cpp/external/Dobby
deleted file mode 160000
index 2da2c218b0a..00000000000
--- a/core/src/main/cpp/external/Dobby
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 2da2c218b0ae824b3a0e5ef1474223636f7f32a9
diff --git a/core/src/main/cpp/external/yahfa/Android.mk b/core/src/main/cpp/external/yahfa/Android.mk
new file mode 100644
index 00000000000..ec2ad2acf25
--- /dev/null
+++ b/core/src/main/cpp/external/yahfa/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := yahfa
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_SRC_FILES := src/HookMain.cpp src/trampoline.c
+LOCAL_EXPORT_LDLIBS := -llog
+LOCAL_STATIC_LIBRARIES := libcxx
+include $(BUILD_STATIC_LIBRARY)
diff --git a/core/src/main/cpp/main/Android.mk b/core/src/main/cpp/main/Android.mk
new file mode 100644
index 00000000000..203c01b5dae
--- /dev/null
+++ b/core/src/main/cpp/main/Android.mk
@@ -0,0 +1,15 @@
+LOCAL_PATH := $(call my-dir)
+define walk
+ $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))
+endef
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := lspd
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/src
+FILE_LIST := $(filter %.cpp, $(call walk, $(LOCAL_PATH)/src))
+LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
+LOCAL_STATIC_LIBRARIES := cxx yahfa riru dobby dex_builder
+LOCAL_CFLAGS := -DRIRU_MODULE -DRIRU_MODULE_API_VERSION=${RIRU_MODULE_API_VERSION}
+LOCAL_CFLAGS += -DMODULE_NAME=${MODULE_NAME}
+LOCAL_LDLIBS := -llog
+include $(BUILD_SHARED_LIBRARY)
diff --git a/core/src/main/cpp/main/CMakeLists.txt b/core/src/main/cpp/main/CMakeLists.txt
deleted file mode 100644
index 17178cc5517..00000000000
--- a/core/src/main/cpp/main/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-##
-## This file is part of LSPosed.
-##
-## LSPosed is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## LSPosed is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with LSPosed. If not, see .
-##
-## Copyright (C) 2020 EdXposed Contributors
-## Copyright (C) 2021 LSPosed Contributors
-##
-
-cmake_minimum_required(VERSION 3.4.1)
-
-configure_file(template/config.cpp src/config.cpp)
-
-aux_source_directory(src SRC_LIST)
-aux_source_directory(src/jni SRC_JNI_LIST)
-include_directories(include src)
-
-add_library(lspd SHARED ${SRC_LIST} ${SRC_JNI_LIST} ${CMAKE_CURRENT_BINARY_DIR}/src/config.cpp)
-
-find_package(riru REQUIRED CONFIG)
-find_library(log-lib log)
-target_link_libraries(lspd yahfa riru::riru android dobby dex_builder ${log-lib})
-
-add_custom_command(TARGET lspd POST_BUILD
- COMMAND ${CMAKE_STRIP} --remove-section=.comment -g "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/liblspd.so")
diff --git a/core/src/main/cpp/main/src/elf_util.cpp b/core/src/main/cpp/main/src/elf_util.cpp
index ca6cd12424b..f9e4169fd88 100644
--- a/core/src/main/cpp/main/src/elf_util.cpp
+++ b/core/src/main/cpp/main/src/elf_util.cpp
@@ -170,7 +170,7 @@ ElfW(Addr) ElfImg::LinearLookup(std::string_view name) const {
if (symtabs_.empty()) {
symtabs_.reserve(symtab_count);
if (symtab_start != nullptr && symstr_offset_for_symtab != 0) {
- for (int i = 0; i < symtab_count; i++) {
+ for (ElfW(Off) i = 0; i < symtab_count; i++) {
unsigned int st_type = ELF_ST_TYPE(symtab_start[i].st_info);
const char *st_name = offsetOf(header, symstr_offset_for_symtab +
symtab_start[i].st_name);
@@ -260,4 +260,3 @@ bool ElfImg::findModuleBase() {
base = reinterpret_cast(load_addr);
return true;
}
-
diff --git a/core/src/main/cpp/main/src/jni/resources_hook.cpp b/core/src/main/cpp/main/src/jni/resources_hook.cpp
index 7f0d677067a..82379255165 100644
--- a/core/src/main/cpp/main/src/jni/resources_hook.cpp
+++ b/core/src/main/cpp/main/src/jni/resources_hook.cpp
@@ -103,7 +103,7 @@ namespace lspd {
env, class_clazz, "accessFlags", "I");
jint access_flags = env->GetIntField(target_class, java_lang_Class_accessFlags);
env->SetIntField(target_class, java_lang_Class_accessFlags, access_flags & ~kAccFinal);
- for (auto i = 0u; i < env->GetArrayLength(constructors); ++i) {
+ for (auto i = 0; i < env->GetArrayLength(constructors); ++i) {
auto constructor = env->GetObjectArrayElement(constructors, i);
void *method = yahfa::getArtMethod(env, constructor);
uint32_t flags = yahfa::getAccessFlags(method);
diff --git a/core/src/main/cpp/main/src/main.cpp b/core/src/main/cpp/main/src/main.cpp
index 3b5ad99c3a9..f4568b7c2c8 100644
--- a/core/src/main/cpp/main/src/main.cpp
+++ b/core/src/main/cpp/main/src/main.cpp
@@ -115,11 +115,13 @@ namespace lspd {
};
}
+#define str(s) #s
+
RIRU_EXPORT RiruVersionedModuleInfo *init(Riru *riru) {
LOGD("using riru %d", riru->riruApiVersion);
LOGD("module path: %s", riru->magiskModulePath);
lspd::magiskPath = riru->magiskModulePath;
- if (!lspd::isDebug && lspd::magiskPath.find(MODULE_NAME) == std::string::npos) {
+ if (!lspd::isDebug && lspd::magiskPath.find(str(MODULE_NAME)) == std::string::npos) {
LOGE("who am i");
return nullptr;
}
diff --git a/manager-service/build.gradle.kts b/manager-service/build.gradle.kts
index cf061169554..5ed047bbf2f 100644
--- a/manager-service/build.gradle.kts
+++ b/manager-service/build.gradle.kts
@@ -19,7 +19,6 @@
plugins {
id("com.android.library")
- kotlin("android")
}
val androidTargetSdkVersion: Int by rootProject.extra