Skip to content

Commit

Permalink
Refactor core to use LSPlant as the ART hook framework (LSPosed#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 authored Mar 14, 2022
1 parent 2a258e3 commit 0bf0948
Show file tree
Hide file tree
Showing 102 changed files with 1,178 additions and 3,618 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
with:
path: |
~/.gradle/caches/build-cache-*
~/.gradle/buildOutputCleanup/cache.properties
key: gradle-builds-core-${{ github.sha }}
restore-keys: |
gradle-builds
Expand All @@ -66,8 +67,6 @@ jobs:
ccache -o compiler_check='%compiler% -dumpmachine; %compiler% -dumpversion'
ccache -zp
- 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
Expand Down Expand Up @@ -117,6 +116,13 @@ jobs:
path: |
core/build/outputs/mapping
app/build/outputs/mapping
- name: Upload symbols
uses: actions/upload-artifact@v2
with:
name: symbols
path: |
core/build/symbols
daemon/build/symbols
- name: Post to channel
if: ${{ github.event_name != 'pull_request' && success() && github.ref == 'refs/heads/master' }}
env:
Expand Down
12 changes: 9 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[submodule "service"]
path = service
url = https://github.com/libxposed/XposedService.git
[submodule "core/src/main/cpp/external/DexBuilder"]
path = core/src/main/cpp/external/DexBuilder
url = https://github.com/LSPosed/DexBuilder.git
[submodule "external/cxx"]
path = external/cxx
url = https://github.com/LSPosed/libcxx.git
[submodule "external/lsplant"]
path = external/lsplant
url = https://github.com/LSPosed/LSPlant.git
[submodule "external/dobby"]
path = external/dobby
url = https://github.com/LSPosed/Dobby.git
3 changes: 2 additions & 1 deletion core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build
/release
/src/main/cpp/main/api/config.cpp
/src/main/cpp/api/config.cpp
/.cxx
115 changes: 85 additions & 30 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,32 @@ android {
multiDexEnabled = false

externalNativeBuild {
ndkBuild {
arguments += "INJECTED_AID=$injectedPackageUid"
arguments += "VERSION_CODE=$verCode"
arguments += "VERSION_NAME=$verName"
arguments += "-j${Runtime.getRuntime().availableProcessors()}"
cmake {
arguments += "-DEXTERNAL_ROOT=${File(rootDir.absolutePath, "external")}"
abiFilters("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
val flags = arrayOf(
"-Wall",
"-Qunused-arguments",
"-Wno-gnu-string-literal-operator-template",
"-fno-rtti",
"-fvisibility=hidden",
"-fvisibility-inlines-hidden",
"-fno-exceptions",
"-fno-stack-protector",
"-fomit-frame-pointer",
"-Wno-builtin-macro-redefined",
"-Wno-unused-value",
"-D__FILE__=__FILE_NAME__",
"-DINJECTED_AID=$injectedPackageUid",
)
cppFlags("-std=c++20", *flags)
cFlags("-std=c18", *flags)
arguments(
"-DANDROID_STL=none",
"-DVERSION_CODE=$verCode",
"-DVERSION_NAME=$verName",
)
targets("lspd")
}
}

Expand All @@ -97,14 +118,58 @@ 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(
"-Wl,--exclude-libs,ALL",
"-ffunction-sections",
"-fdata-sections",
"-Wl,--gc-sections",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
"-flto=thin",
"-Wl,--thinlto-cache-policy,cache_size_bytes=300m",
"-Wl,--thinlto-cache-dir=${buildDir.absolutePath}/.lto-cache",
)
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",
"-DDEBUG_SYMBOLS_PATH=${buildDir.absolutePath}/symbols",
)
)
}
}
}
}

externalNativeBuild {
ndkBuild {
path("src/main/cpp/Android.mk")
cmake {
path("src/main/jni/CMakeLists.txt")
}
}

Expand All @@ -113,22 +178,12 @@ android {
sourceCompatibility(androidSourceCompatibility)
}

buildTypes {
all {
externalNativeBuild {
ndkBuild {
arguments += "NDK_OUT=${File(buildDir, ".cxx/$name").absolutePath}"
}
}
}
}

productFlavors {
all {
externalNativeBuild {
ndkBuild {
arguments += "MODULE_NAME=${name.toLowerCase()}_$moduleBaseId"
arguments += "API=${name.toLowerCase()}"
cmake {
arguments += "-DMODULE_NAME=${name.toLowerCase()}_$moduleBaseId"
arguments += "-DAPI=${name.toLowerCase()}"
}
}
buildConfigField("String", "API", """"$name"""")
Expand All @@ -137,17 +192,17 @@ android {
create("Riru") {
dimension = "api"
externalNativeBuild {
ndkBuild {
arguments += "API_VERSION=$moduleMaxRiruApiVersion"
cmake {
arguments += "-DAPI_VERSION=$moduleMaxRiruApiVersion"
}
}
}

create("Zygisk") {
dimension = "api"
externalNativeBuild {
ndkBuild {
arguments += "API_VERSION=1"
cmake {
arguments += "-DAPI_VERSION=1"
}
}
}
Expand All @@ -157,10 +212,6 @@ android {


dependencies {
// keep this dep since it affects ccache
implementation("dev.rikka.ndk:riru:26.0.0")
implementation("dev.rikka.ndk.thirdparty:cxx:1.2.0")
implementation("io.github.vvb2060.ndk:dobby:1.2")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("de.upb.cs.swt:axml:2.1.2")
compileOnly("androidx.annotation:annotation:1.3.0")
Expand Down Expand Up @@ -247,8 +298,12 @@ fun afterEval() = android.applicationVariants.forEach { variant ->
rename(".*\\.apk", "daemon.apk")
}
into("lib") {
from("${buildDir}/intermediates/stripped_native_libs/$variantCapped/out/lib")
from("${project(":daemon").buildDir}/intermediates/ndkBuild/$buildTypeLowered/obj/local")
from("${buildDir}/intermediates/cmake/$variantCapped/obj") {
include("**/liblspd.so")
}
from("${project(":daemon").buildDir}/intermediates/cmake/$buildTypeLowered/obj") {
include("**/libdaemon.so")
}
}
val dexOutPath = if (buildTypeLowered == "release")
"$buildDir/intermediates/dex/$variantCapped/minify${variantCapped}WithR8" else
Expand Down
3 changes: 0 additions & 3 deletions core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;
}
-keepclasseswithmembers class org.lsposed.lspd.nativebridge.ClassLinker {
public static void onPostFixupStaticTrampolines(java.lang.Class);
}
-keepclasseswithmembers class org.lsposed.lspd.service.BridgeService {
public static boolean *(android.os.IBinder, int, long, long, int);
}
Expand Down
60 changes: 0 additions & 60 deletions core/src/main/cpp/.clang-tidy

This file was deleted.

7 changes: 0 additions & 7 deletions core/src/main/cpp/Android.mk

This file was deleted.

15 changes: 0 additions & 15 deletions core/src/main/cpp/Application.mk

This file was deleted.

1 change: 0 additions & 1 deletion core/src/main/cpp/external/DexBuilder
Submodule DexBuilder deleted from 6273ec
10 changes: 0 additions & 10 deletions core/src/main/cpp/external/yahfa/Android.mk

This file was deleted.

34 changes: 0 additions & 34 deletions core/src/main/cpp/external/yahfa/include/HookMain.h

This file was deleted.

14 changes: 0 additions & 14 deletions core/src/main/cpp/external/yahfa/include/trampoline.h

This file was deleted.

Loading

0 comments on commit 0bf0948

Please sign in to comment.