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

[WIP] Figure out the confict between LSPlant and LSPlt #10

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
@@ -62,9 +62,6 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Grant Execute Permission for gradlew
run: chmod +x gradlew

- name: Setup ninja
uses: seanmiddleditch/gha-setup-ninja@v5
with:
@@ -75,14 +72,6 @@ jobs:
with:
version: latest

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
max-size: 2G
key: ${{ runner.os }}
restore-keys: ${{ runner.os }}
save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}

- name: Remove Android's cmake
shell: bash
run: rm -rf $ANDROID_HOME/cmake
42 changes: 23 additions & 19 deletions core/src/main/jni/src/native_api.h
Original file line number Diff line number Diff line change
@@ -25,11 +25,12 @@
#ifndef LSPOSED_NATIVE_API_H
#define LSPOSED_NATIVE_API_H

#include <cstdint>
#include <dlfcn.h>
#include <string>
#include <dobby.h>

#include <cstdint>
#include <string>

#include "config.h"
#include "utils/hook_helper.hpp"

@@ -48,33 +49,36 @@ typedef struct {
typedef NativeOnModuleLoaded (*NativeInit)(const NativeAPIEntries *entries);

namespace lspd {
bool InstallNativeAPI(const lsplant::HookHandler& handler);
bool InstallNativeAPI(const lsplant::HookHandler &handler);

void RegisterNativeLib(const std::string &library_name);
void RegisterNativeLib(const std::string &library_name);

inline int HookInline(void *original, void *replace, void **backup) {
if constexpr (isDebug) {
Dl_info info;
if (dladdr(original, &info))
inline int HookInline(void *original, void *replace, void **backup) {
Dl_info info;
if constexpr (isDebug) {
if (dladdr(original, &info))
LOGD("Dobby hooking {} ({}) from {} ({})",
info.dli_sname ? info.dli_sname : "(unknown symbol)",
info.dli_saddr ? info.dli_saddr : original,
info.dli_saddr ? info.dli_saddr : original,
info.dli_fname ? info.dli_fname : "(unknown file)", info.dli_fbase);
}
return DobbyHook(original, reinterpret_cast<dobby_dummy_func_t>(replace), reinterpret_cast<dobby_dummy_func_t *>(backup));
}
if (!info.dli_sname) return 1;
return DobbyHook(original, reinterpret_cast<dobby_dummy_func_t>(replace),
reinterpret_cast<dobby_dummy_func_t *>(backup));
}

inline int UnhookInline(void *original) {
if constexpr (isDebug) {
Dl_info info;
if (dladdr(original, &info))
inline int UnhookInline(void *original) {
Dl_info info;
if constexpr (isDebug) {
if (dladdr(original, &info))
LOGD("Dobby unhooking {} ({}) from {} ({})",
info.dli_sname ? info.dli_sname : "(unknown symbol)",
info.dli_saddr ? info.dli_saddr : original,
info.dli_saddr ? info.dli_saddr : original,
info.dli_fname ? info.dli_fname : "(unknown file)", info.dli_fbase);
}
return DobbyDestroy(original);
}
if (!info.dli_sname) return 1;
return DobbyDestroy(original);
}
} // namespace lspd

#endif //LSPOSED_NATIVE_API_H
#endif // LSPOSED_NATIVE_API_H
37 changes: 18 additions & 19 deletions dex2oat/src/main/cpp/dex2oat.c
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -31,9 +32,9 @@
#include "logging.h"

#if defined(__LP64__)
# define LP_SELECT(lp32, lp64) lp64
#define LP_SELECT(lp32, lp64) lp64
#else
# define LP_SELECT(lp32, lp64) lp32
#define LP_SELECT(lp32, lp64) lp32
#endif

#define ID_VEC(is64, is_debug) (((is64) << 1) | (is_debug))
@@ -50,23 +51,17 @@ static ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags) {

static void *recv_fds(int sockfd, char *cmsgbuf, size_t bufsz, int cnt) {
struct iovec iov = {
.iov_base = &cnt,
.iov_len = sizeof(cnt),
.iov_base = &cnt,
.iov_len = sizeof(cnt),
};
struct msghdr msg = {
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = cmsgbuf,
.msg_controllen = bufsz
};
.msg_iov = &iov, .msg_iovlen = 1, .msg_control = cmsgbuf, .msg_controllen = bufsz};

xrecvmsg(sockfd, &msg, MSG_WAITALL);
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);

if (msg.msg_controllen != bufsz ||
cmsg == NULL ||
cmsg->cmsg_len != CMSG_LEN(sizeof(int) * cnt) ||
cmsg->cmsg_level != SOL_SOCKET ||
if (msg.msg_controllen != bufsz || cmsg == NULL ||
cmsg->cmsg_len != CMSG_LEN(sizeof(int) * cnt) || cmsg->cmsg_level != SOL_SOCKET ||
cmsg->cmsg_type != SCM_RIGHTS) {
return NULL;
}
@@ -78,8 +73,7 @@ static int recv_fd(int sockfd) {
char cmsgbuf[CMSG_SPACE(sizeof(int))];

void *data = recv_fds(sockfd, cmsgbuf, sizeof(cmsgbuf), 1);
if (data == NULL)
return -1;
if (data == NULL) return -1;

int result;
memcpy(&result, data, sizeof(int));
@@ -88,8 +82,7 @@ static int recv_fd(int sockfd) {

static int read_int(int fd) {
int val;
if (read(fd, &val, sizeof(val)) != sizeof(val))
return -1;
if (read(fd, &val, sizeof(val)) != sizeof(val)) return -1;
return val;
}

@@ -105,7 +98,7 @@ int main(int argc, char **argv) {
strlcpy(sock.sun_path + 1, kSockName, sizeof(sock.sun_path) - 1);
int sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
size_t len = sizeof(sa_family_t) + strlen(sock.sun_path + 1) + 1;
if (connect(sock_fd, (struct sockaddr *) &sock, len)) {
if (connect(sock_fd, (struct sockaddr *)&sock, len)) {
PLOGE("failed to connect to %s", sock.sun_path + 1);
return 1;
}
@@ -119,7 +112,13 @@ int main(int argc, char **argv) {
for (int i = 0; i < argc; i++) new_argv[i] = argv[i];
new_argv[argc] = "--inline-max-code-units=0";
new_argv[argc + 1] = NULL;
fexecve(stock_fd, (char **) new_argv, environ);

char const *libenv =
"LD_LIBRARY_PATH=/system/lib64:/system/lib:"
"/apex/com.android.art/lib64:/apex/com.android.art/lib:"
"/apex/com.android.os.statsd/lib64:/apex/com.android.os.statsd/lib";
putenv((char *)libenv);
fexecve(stock_fd, (char **)new_argv, environ);
PLOGE("fexecve failed");
return 2;
}
2 changes: 1 addition & 1 deletion external/lsplant
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.6.0"
kotlin = "2.0.20"
nav = "2.7.7"
nav = "2.8.0"
appcenter = "5.0.4"
libxposed = "100"
glide = "4.16.0"
@@ -35,12 +35,12 @@ rikkax-recyclerview = { module = "dev.rikka.rikkax.recyclerview:recyclerview-ktx
rikkax-widget-borderview = { module = "dev.rikka.rikkax.widget:borderview", version = "1.1.0" }
rikkax-widget-mainswitchbar = { module = "dev.rikka.rikkax.widget:mainswitchbar", version = "1.0.2" }

androidx-activity = { module = "androidx.activity:activity", version = "1.9.1" }
androidx-activity = { module = "androidx.activity:activity", version = "1.9.2" }
androidx-annotation = { module = "androidx.annotation:annotation", version = "1.8.2" }
androidx-browser = { module = "androidx.browser:browser", version = "1.8.0" }
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version = "2.1.4" }
androidx-core = { module = "androidx.core:core", version = "1.13.1" }
androidx-fragment = { module = "androidx.fragment:fragment", version = "1.8.2" }
androidx-fragment = { module = "androidx.fragment:fragment", version = "1.8.3" }
androidx-navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "nav" }
androidx-navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "nav" }
androidx-preference = { module = "androidx.preference:preference", version = "1.2.1" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
12 changes: 6 additions & 6 deletions magisk-loader/src/main/jni/src/magisk_loader.cpp
Original file line number Diff line number Diff line change
@@ -119,13 +119,13 @@ void MagiskLoader::OnNativeForkSystemServerPost(JNIEnv *env) {
.inline_hooker =
[](auto t, auto r) {
void *bk = nullptr;
return HookPLT(t, r, &bk) == 0 ? bk : nullptr;
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
},
.inline_unhooker = [](auto t) { return UnhookPLT(t) == 0; },
.inline_unhooker = [](auto t) { return UnhookInline(t) == 0; },
.art_symbol_resolver = [](auto symbol) { return GetArt()->getSymbAddress(symbol); },
.art_symbol_prefix_resolver =
[](auto symbol) { return GetArt()->getSymbPrefixFirstAddress(symbol); },
.is_plt_hook = true};
};
InitArtHooker(env, initInfo);
InitHooks(env);
SetupEntryClass(env);
@@ -191,13 +191,13 @@ void MagiskLoader::OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name,
.inline_hooker =
[](auto t, auto r) {
void *bk = nullptr;
return HookPLT(t, r, &bk) == 0 ? bk : nullptr;
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
},
.inline_unhooker = [](auto t) { return UnhookPLT(t) == 0; },
.inline_unhooker = [](auto t) { return UnhookInline(t) == 0; },
.art_symbol_resolver = [](auto symbol) { return GetArt()->getSymbAddress(symbol); },
.art_symbol_prefix_resolver =
[](auto symbol) { return GetArt()->getSymbPrefixFirstAddress(symbol); },
.is_plt_hook = true};
};
auto [dex_fd, size] = instance->RequestLSPDex(env, binder);
auto obfs_map = instance->RequestObfuscationMap(env, binder);
ConfigBridge::GetInstance()->obfuscation_map(std::move(obfs_map));