Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge #73

Merged
merged 48 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c249ebe
use cmake instead of ndk-build
5ec1cff Oct 30, 2023
f78c217
init-sigstop-based ptrace zygisk
5ec1cff Oct 31, 2023
f5e0a41
WIP
5ec1cff Nov 3, 2023
f958e57
Get rid of binder-rs & Refine watchdog
5ec1cff Nov 3, 2023
5e2a211
min api is 26
5ec1cff Nov 3, 2023
1c79932
comment out useless code
5ec1cff Nov 3, 2023
ac53ef1
refactor jni hooks
5ec1cff Nov 4, 2023
add1c65
make compiler happy
5ec1cff Nov 4, 2023
070aa5f
fix pure 64 bit support
5ec1cff Nov 6, 2023
ba8c313
Merge branch 'art2' into new-pt
5ec1cff Nov 8, 2023
0406433
init monitor
5ec1cff Nov 12, 2023
0ac9bb8
add controller command
5ec1cff Nov 12, 2023
889a44c
inject non-stop signal by default
5ec1cff Nov 12, 2023
36dcec0
fix wrong entry break addr on arm32
5ec1cff Nov 12, 2023
3e541ec
prevent from bootloop
5ec1cff Nov 12, 2023
fd6a454
fix compatibility on lower android version
5ec1cff Nov 13, 2023
fd9f879
refine tracing logic
5ec1cff Nov 13, 2023
47a17d2
run zygisk-cp on post-fs-data
5ec1cff Nov 13, 2023
c59a788
refine tracing logic
5ec1cff Nov 13, 2023
5aea51c
Revert "run zygisk-cp on post-fs-data"
5ec1cff Nov 13, 2023
c205893
set max retry count to 5
5ec1cff Nov 13, 2023
9e48f18
Randomize tmp path
5ec1cff Nov 27, 2023
9c34c67
restart zygiskd when zygote restart
5ec1cff Dec 8, 2023
bcb65c4
run companion in standalone process
5ec1cff Dec 8, 2023
b34015b
strip by ourselves
5ec1cff Dec 8, 2023
0254623
fix check_unix_socket
5ec1cff Dec 8, 2023
c4163c9
generate debug info for release
5ec1cff Dec 8, 2023
4f81f09
randomize init control socket & add shortcut (/data/adb/modules/zygis…
5ec1cff Dec 8, 2023
d66dba2
upload zygiskd debug symbols
5ec1cff Dec 8, 2023
a88d7a5
fix CI
5ec1cff Dec 8, 2023
0e2bc75
Add version info to logs
5ec1cff Dec 11, 2023
ba1f90c
Upload CI builds to telegram
5ec1cff Dec 11, 2023
9904869
rename uploaded symbol filename
5ec1cff Dec 11, 2023
5d95f62
don't use Result on handle_daemon_action
5ec1cff Dec 11, 2023
ad8510d
show root impl
5ec1cff Dec 11, 2023
993b187
daemon launched by monitor & show daemon status in module.prop
5ec1cff Dec 11, 2023
db60c31
show injection status
5ec1cff Dec 11, 2023
faf074b
don't show inject status if not tracing
5ec1cff Dec 11, 2023
f101ffb
add emoji to status
5ec1cff Dec 12, 2023
b45d55e
change some logs level to V
5ec1cff Dec 12, 2023
483987b
fix companion exec failed
5ec1cff Dec 12, 2023
feb34c7
show loaded modules
5ec1cff Dec 12, 2023
75495de
Indicate wrong root implementation
5ec1cff Dec 12, 2023
370bb08
Indicate root implementation
5ec1cff Dec 12, 2023
0569004
separate error info and normal info of daemons
5ec1cff Dec 12, 2023
49886d9
Fixes for Android 14 QPR2 B2 (https://github.com/topjohnwu/Magisk/pul…
5ec1cff Dec 12, 2023
12f57d6
log if jni hook failed
5ec1cff Dec 12, 2023
1999ef7
fix ci upload (https://core.telegram.org/bots/api#markdownv2-style) t…
5ec1cff Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/scripts/telegram_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json
import os
import urllib.parse

url = f'https://api.telegram.org/bot{os.environ["BOT_TOKEN"]}'
url += f'/sendMediaGroup?chat_id={urllib.parse.quote(os.environ["CHANNEL_ID"])}&media='

# https://core.telegram.org/bots/api#markdownv2-style
msg = os.environ["COMMIT_MESSAGE"]
for c in ['\\', '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!']:
msg = msg.replace(c, f'\\{c}')
commit_url = os.environ["COMMIT_URL"]
commit_id = os.environ["COMMIT_ID"][:7]

caption = f"[{commit_id}]({commit_url})\n{msg}"[:1024]

data = json.dumps([
{"type": "document", "media": "attach://Release"},
{"type": "document", "media":"attach://Debug"},
{"type": "document", "media": "attach://ReleaseSymbol"},
{"type": "document", "media": "attach://DebugSymbol","caption": caption,"parse_mode":"MarkdownV2"}
])

url += urllib.parse.quote(data)
print(url)
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: CI

on:
workflow_dispatch:
inputs:
post_telegram:
description: 'Post to Telegram'
required: true
type: boolean
push:
branches: [ master ]
tags: [ v* ]
Expand Down Expand Up @@ -75,6 +80,12 @@ jobs:
debugName=`ls module/build/outputs/release/Zygisk-Next-v*-debug.zip | awk -F '(/|.zip)' '{print $5}'` && echo "debugName=$debugName" >> $GITHUB_OUTPUT
unzip module/build/outputs/release/Zygisk-Next-v*-release.zip -d zksu-release
unzip module/build/outputs/release/Zygisk-Next-v*-debug.zip -d zksu-debug
releaseSymbolName="SYMBOLS-$releaseName.zip"
debugSymbolName="SYMBOLS-$debugName.zip"
echo "releaseSymbolName=$releaseSymbolName" >> $GITHUB_OUTPUT
echo "debugSymbolName=$debugSymbolName" >> $GITHUB_OUTPUT
zip -r $releaseSymbolName zygiskd/build/symbols/release
zip -r $debugSymbolName zygiskd/build/symbols/debug

- name: Upload release
uses: actions/upload-artifact@v3
Expand All @@ -87,3 +98,34 @@ jobs:
with:
name: ${{ steps.prepareArtifact.outputs.debugName }}
path: "./zksu-debug/*"

- name: Upload release symbols
uses: actions/upload-artifact@v3
with:
name: ${{ steps.prepareArtifact.outputs.releaseName }}-symbols
path: "zygiskd/build/symbols/release"

- name: Upload debug symbols
uses: actions/upload-artifact@v3
with:
name: ${{ steps.prepareArtifact.outputs.debugName }}-symbols
path: "zygiskd/build/symbols/debug"

- name: Post to channel
if: ${{ success() && github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.ref_type != 'tag' && inputs.post_telegram != 'false' }}
env:
CHANNEL_ID: ${{ secrets.CHANNEL_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
COMMIT_URL: ${{ github.event.head_commit.url }}
COMMIT_ID: ${{ github.event.head_commit.id }}
run: |
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
OUTPUT="module/build/outputs/release"
export Release=$(find $OUTPUT -name "Zygisk-Next-v*-release.zip")
export Debug=$(find $OUTPUT -name "Zygisk-Next-v*-debug.zip")
export ReleaseSymbol="${{ steps.prepareArtifact.outputs.releaseSymbolName }}"
export DebugSymbol="${{ steps.prepareArtifact.outputs.debugSymbolName }}"
URL=$(python3 .github/scripts/telegram_url.py)
curl -v "$URL" -F Release="@$Release" -F Debug="@$Debug" -F ReleaseSymbol="@$ReleaseSymbol" -F DebugSymbol="@$DebugSymbol"
fi
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "loader/src/external/lsplt"]
path = loader/src/external/lsplt
url = https://github.com/LSPosed/lsplt
[submodule "loader/src/external/parallel-hashmap"]
path = loader/src/external/parallel-hashmap
url = https://github.com/greg7mdp/parallel-hashmap
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val minKsudVersion by extra(10942)
val maxKsuVersion by extra(20000)
val minMagiskVersion by extra(26300)

val androidMinSdkVersion by extra(29)
val androidMinSdkVersion by extra(26)
val androidTargetSdkVersion by extra(34)
val androidCompileSdkVersion by extra(34)
val androidBuildToolsVersion by extra("34.0.0")
Expand Down
52 changes: 44 additions & 8 deletions loader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ plugins {
alias(libs.plugins.agp.lib)
}

val verCode: Int by rootProject.extra
val verName: String by rootProject.extra
val commitHash: String by rootProject.extra

fun Project.findInPath(executable: String, property: String): String? {
val pathEnv = System.getenv("PATH")
return pathEnv.split(File.pathSeparator).map { folder ->
Expand All @@ -15,29 +19,61 @@ fun Project.findInPath(executable: String, property: String): String? {
}?.absolutePath ?: properties.getOrDefault(property, null) as? String?
}

val ccachePatch by lazy {
val ccachePath by lazy {
project.findInPath("ccache", "ccache.path")?.also {
println("loader: Use ccache: $it")
}
}

val defaultCFlags = arrayOf(
"-Wall", "-Wextra",
"-fno-rtti", "-fno-exceptions",
"-fno-stack-protector", "-fomit-frame-pointer",
"-Wno-builtin-macro-redefined", "-D__FILE__=__FILE_NAME__"
)

val releaseFlags = arrayOf(
"-Oz", "-flto",
"-Wno-unused", "-Wno-unused-parameter",
"-fvisibility=hidden", "-fvisibility-inlines-hidden",
"-fno-unwind-tables", "-fno-asynchronous-unwind-tables",
"-Wl,--exclude-libs,ALL", "-Wl,--gc-sections", "-Wl,--strip-all"
)

android {
buildFeatures {
androidResources = false
buildConfig = false
prefab = true
}

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

defaultConfig {
externalNativeBuild {
ndkBuild {
ccachePatch?.let {
arguments += "NDK_CCACHE=$it"
}
externalNativeBuild.cmake {
arguments += "-DANDROID_STL=none"
arguments += "-DLSPLT_STANDALONE=ON"
cFlags("-std=c18", *defaultCFlags)
cppFlags("-std=c++20", *defaultCFlags)
ccachePath?.let {
arguments += "-DNDK_CCACHE=$it"
}
}
}

buildTypes {
debug {
externalNativeBuild.cmake {
arguments += "-DZKSU_VERSION=$verName-$verCode-$commitHash-debug"
}
}
release {
externalNativeBuild.cmake {
cFlags += releaseFlags
cppFlags += releaseFlags
arguments += "-DZKSU_VERSION=$verName-$verCode-$commitHash-release"
}
}
}
Expand Down
26 changes: 0 additions & 26 deletions loader/src/Android.mk

This file was deleted.

14 changes: 0 additions & 14 deletions loader/src/Application.mk

This file was deleted.

23 changes: 23 additions & 0 deletions loader/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.22.1)
project("loader")

find_package(cxx REQUIRED CONFIG)

add_definitions(-DZKSU_VERSION=\"${ZKSU_VERSION}\")

aux_source_directory(common COMMON_SRC_LIST)
add_library(common STATIC ${COMMON_SRC_LIST})
target_include_directories(common PRIVATE include)
target_link_libraries(common cxx::cxx log)

aux_source_directory(injector INJECTOR_SRC_LIST)
add_library(zygisk SHARED ${INJECTOR_SRC_LIST})
target_include_directories(zygisk PRIVATE include)
target_link_libraries(zygisk cxx::cxx log common lsplt_static phmap)

aux_source_directory(ptracer PTRACER_SRC_LIST)
add_executable(libzygisk_ptrace.so ${PTRACER_SRC_LIST})
target_include_directories(libzygisk_ptrace.so PRIVATE include)
target_link_libraries(libzygisk_ptrace.so cxx::cxx log common)

add_subdirectory(external)
31 changes: 27 additions & 4 deletions loader/src/common/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@
#include "socket_utils.h"

namespace zygiskd {
static std::string zygisk_path;
void Init(const char *path) {
LOGI("zygisk path set to %s", path);
zygisk_path = path;
}

int Connect(uint8_t retry) {
int fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
struct sockaddr_un addr{
.sun_family = AF_UNIX,
.sun_path={0},
};
strcpy(addr.sun_path, kCPSocketPath);
auto socket_path = zygisk_path + kCPSocketName;
strcpy(addr.sun_path, socket_path.c_str());
socklen_t socklen = sizeof(addr);

while (retry--) {
int r = connect(fd, reinterpret_cast<struct sockaddr*>(&addr), socklen);
if (r == 0) return fd;
LOGW("Retrying to connect to zygiskd, sleep 1s");
sleep(1);
if (retry) {
PLOGE("Retrying to connect to zygiskd, sleep 1s");
sleep(1);
}
}

close(fd);
Expand Down Expand Up @@ -93,7 +101,7 @@ namespace zygiskd {
}

int GetModuleDir(size_t index) {
int fd = Connect(1);
UniqueFd fd = Connect(1);
if (fd == -1) {
PLOGE("GetModuleDir");
return -1;
Expand All @@ -102,4 +110,19 @@ namespace zygiskd {
socket_utils::write_usize(fd, index);
return socket_utils::recv_fd(fd);
}

void ZygoteRestart() {
UniqueFd fd = Connect(1);
if (fd == -1) {
if (errno == ENOENT) {
LOGD("Could not notify ZygoteRestart (maybe it hasn't been created)");
} else {
PLOGE("Could not notify ZygoteRestart");
}
return;
}
if (!socket_utils::write_u8(fd, (uint8_t) SocketAction::ZygoteRestart)) {
PLOGE("Failed to request ZygoteRestart");
}
}
}
2 changes: 1 addition & 1 deletion loader/src/common/dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void* DlopenMem(int fd, int flags) {

auto* handle = android_dlopen_ext("/jit-cache", flags, &info);
if (handle) {
LOGD("dlopen fd %d: %p", fd, handle);
LOGV("dlopen fd %d: %p", fd, handle);
} else {
LOGE("dlopen fd %d: %s", fd, dlerror());
}
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions loader/src/common/socket_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ namespace socket_utils {
read_sz += ret;
} while (read_sz != count && ret != 0);
if (read_sz != count) {
PLOGE("read (%d != %d)", count, read_sz);
PLOGE("read (%zu != %zu)", count, read_sz);
}
return read_sz;
}

ssize_t xwrite(int fd, const void* buf, size_t count) {
size_t xwrite(int fd, const void* buf, size_t count) {
size_t write_sz = 0;
ssize_t ret;
do {
ret = write(fd, (std::byte*) buf + write_sz, count - write_sz);
if (ret < 0) {
if (errno == EINTR) continue;
PLOGE("write");
return ret;
return write_sz;
}
write_sz += ret;
} while (write_sz != count && ret != 0);
if (write_sz != count) {
PLOGE("write (%d != %d)", count, write_sz);
PLOGE("write (%zu != %zu)", count, write_sz);
}
return write_sz;
}
Expand Down
21 changes: 0 additions & 21 deletions loader/src/external/Android.mk

This file was deleted.

8 changes: 8 additions & 0 deletions loader/src/external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project(external)

OPTION(LSPLT_BUILD_SHARED OFF)
add_subdirectory(lsplt/lsplt/src/main/jni)

add_library(phmap INTERFACE)
target_include_directories(phmap INTERFACE parallel-hashmap)
target_compile_options(phmap INTERFACE -Wno-unused-value)
1 change: 0 additions & 1 deletion loader/src/external/parallel-hashmap
Submodule parallel-hashmap deleted from 55725d
1 change: 1 addition & 0 deletions loader/src/include/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ namespace zygisk {
jobjectArray *const whitelisted_data_info_list;
jboolean *const mount_data_dirs;
jboolean *const mount_storage_dirs;
jboolean *const mount_sysprop_overrides;

AppSpecializeArgs() = delete;
};
Expand Down
Loading