Skip to content

Commit 95ed02d

Browse files
committed
Update JingMatrix/LSPosed
Users of Android 16 beta 3 has reported LSPlant failure, for which we should thus update LSPosed. See issue JingMatrix/LSPlant#2. Files are reformatted.
1 parent 9703dc4 commit 95ed02d

File tree

10 files changed

+88
-82
lines changed

10 files changed

+88
-82
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ jobs:
5656
- name: Setup Gradle
5757
uses: gradle/actions/setup-gradle@v4
5858

59+
- name: Setup Android SDK
60+
uses: android-actions/setup-android@v3
61+
5962
- name: Setup ninja
6063
uses: seanmiddleditch/gha-setup-ninja@master
6164
with:

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ val coreVerName by extra(coreLatestTag)
5353
val androidMinSdkVersion by extra(28)
5454
val androidTargetSdkVersion by extra(35)
5555
val androidCompileSdkVersion by extra(35)
56-
val androidCompileNdkVersion by extra("27.1.12297006")
56+
val androidCompileNdkVersion by extra("29.0.13113456")
5757
val androidBuildToolsVersion by extra("35.0.0")
5858
val androidSourceCompatibility by extra(JavaVersion.VERSION_21)
5959
val androidTargetCompatibility by extra(JavaVersion.VERSION_21)

gradle/wrapper/gradle-wrapper.jar

122 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ done
8686
# shellcheck disable=SC2034
8787
APP_BASE_NAME=${0##*/}
8888
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89-
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90-
' "$PWD" ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
9190

9291
# Use the maximum available, or set MAX_FD != -1 to use that value.
9392
MAX_FD=maximum
@@ -206,7 +205,7 @@ fi
206205
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207206

208207
# Collect all arguments for the java command:
209-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
208+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210209
# and any embedded shellness will be escaped.
211210
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212211
# treated as '${Hostname}' itself on the command line.

patch-loader/src/main/jni/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
project(lspatch)
22
cmake_minimum_required(VERSION 3.4.1)
33

4+
set(CMAKE_CXX_STANDARD 23)
45
add_subdirectory(${CORE_ROOT} core)
56

67
aux_source_directory(src SRC_LIST)

patch-loader/src/main/jni/include/art/runtime/jit/profile_saver.h

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,44 @@ using namespace lsplant;
1212
namespace art {
1313
class ProfileSaver {
1414
private:
15-
inline static MemberHooker<"_ZN3art12ProfileSaver20ProcessProfilingInfoEbPt", ProfileSaver,
16-
bool(bool, uint16_t *)>
17-
ProcessProfilingInfo_ = +[](ProfileSaver *thiz, bool a, uint16_t *b) {
18-
LOGD("skipped profile saving");
19-
return true;
20-
};
21-
22-
inline static MemberHooker<"_ZN3art12ProfileSaver20ProcessProfilingInfoEbbPt", ProfileSaver,
23-
bool(bool, bool, uint16_t *)>
24-
ProcessProfilingInfoWithBool_ = +[](ProfileSaver *thiz, bool, bool, uint16_t *) {
25-
LOGD("skipped profile saving");
26-
return true;
27-
};
28-
29-
inline static Hooker<"execve",
30-
int(const char *pathname, const char *argv[], char *const envp[])>
31-
execve_ = +[](const char *pathname, const char *argv[], char *const envp[]) {
32-
if (strstr(pathname, "dex2oat")) {
33-
size_t count = 0;
34-
while (argv[count++] != nullptr);
35-
std::unique_ptr<const char *[]> new_args =
36-
std::make_unique<const char *[]>(count + 1);
37-
for (size_t i = 0; i < count - 1; ++i) new_args[i] = argv[i];
38-
new_args[count - 1] = "--inline-max-code-units=0";
39-
new_args[count] = nullptr;
40-
41-
LOGD("dex2oat by disable inline!");
42-
int ret = execve_(pathname, new_args.get(), envp);
43-
return ret;
44-
}
45-
int ret = execve_(pathname, argv, envp);
15+
inline static auto ProcessProfilingInfo_ =
16+
"_ZN3art12ProfileSaver20ProcessProfilingInfoEbPt"_sym.hook->*
17+
[]<MemBackup auto backup>(ProfileSaver *thiz, bool a, uint16_t *b) static -> bool {
18+
LOGD("skipped profile saving");
19+
return true;
20+
};
21+
22+
inline static auto ProcessProfilingInfoWithBool_ =
23+
"_ZN3art12ProfileSaver20ProcessProfilingInfoEbbPt"_sym.hook->*
24+
[]<MemBackup auto backup>(ProfileSaver *thiz, bool, bool, uint16_t *) static -> bool {
25+
LOGD("skipped profile saving");
26+
return true;
27+
};
28+
29+
inline static auto execve_ =
30+
"execve"_sym.hook->*[]<Backup auto backup>(const char *pathname, const char *argv[],
31+
char *const envp[]) static -> int {
32+
if (strstr(pathname, "dex2oat")) {
33+
size_t count = 0;
34+
while (argv[count++] != nullptr);
35+
std::unique_ptr<const char *[]> new_args = std::make_unique<const char *[]>(count + 1);
36+
for (size_t i = 0; i < count - 1; ++i) new_args[i] = argv[i];
37+
new_args[count - 1] = "--inline-max-code-units=0";
38+
new_args[count] = nullptr;
39+
40+
LOGD("dex2oat by disable inline!");
41+
int ret = backup(pathname, new_args.get(), envp);
4642
return ret;
47-
};
43+
}
44+
int ret = backup(pathname, argv, envp);
45+
return ret;
46+
};
4847

4948
public:
5049
static void DisableInline(const HookHandler &handler) {
51-
handler.hook(ProcessProfilingInfo_);
52-
handler.hook(ProcessProfilingInfoWithBool_);
53-
handler.hook(execve_);
50+
handler(ProcessProfilingInfo_);
51+
handler(ProcessProfilingInfoWithBool_);
52+
handler(execve_);
5453
}
5554
};
5655
} // namespace art

patch-loader/src/main/jni/include/art/runtime/oat_file_manager.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifndef LSPATCH_OAT_FILE_MANAGER_H
2121
#define LSPATCH_OAT_FILE_MANAGER_H
2222

23+
#include <vector>
24+
2325
#include "context.h"
2426
#include "utils/hook_helper.hpp"
2527

@@ -28,41 +30,40 @@ using namespace lsplant;
2830
namespace art {
2931
class FileManager {
3032
public:
31-
inline static MemberHooker<
32-
"_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__"
33-
"16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobjectPKc",
34-
FileManager, void(const std::vector<const void *> &, jobject, const char *)>
35-
RunBackgroundVerificationWithContext_ =
36-
+[](FileManager *thiz, const std::vector<const void *> &dex_files, jobject class_loader,
37-
const char *class_loader_context) {
38-
if (lspd::Context::GetInstance()->GetCurrentClassLoader() == nullptr) {
39-
LOGD("Disabled background verification");
40-
return;
41-
}
42-
RunBackgroundVerificationWithContext_(thiz, dex_files, class_loader,
43-
class_loader_context);
44-
};
33+
inline static auto RunBackgroundVerificationWithContext_ =
34+
("_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__"_sym |
35+
"16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobjectPKc"_sym)
36+
.hook
37+
->*[]<MemBackup auto backup>(
38+
FileManager *thiz, const std::vector<const void *> &dex_files,
39+
jobject class_loader, const char *class_loader_context) static -> void {
40+
if (lspd::Context::GetInstance()->GetCurrentClassLoader() == nullptr) {
41+
LOGD("Disabled background verification");
42+
return;
43+
}
44+
backup(thiz, dex_files, class_loader, class_loader_context);
45+
};
4546

46-
inline static MemberHooker<
47-
"_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__"
48-
"16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobject",
49-
FileManager, void(const std::vector<const void *> &, jobject)>
50-
RunBackgroundVerification_ =
51-
+[](FileManager *thiz, const std::vector<const void *> &dex_files,
52-
jobject class_loader) {
53-
if (lspd::Context::GetInstance()->GetCurrentClassLoader() == nullptr) {
54-
LOGD("Disabled background verification");
55-
return;
56-
}
57-
RunBackgroundVerification_(thiz, dex_files, class_loader);
58-
};
47+
inline static auto RunBackgroundVerification_ =
48+
("_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__"_sym |
49+
"16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobject"_sym)
50+
.hook
51+
->*
52+
[]<MemBackup auto backup>(FileManager *thiz, const std::vector<const void *> &dex_files,
53+
jobject class_loader) static -> void {
54+
if (lspd::Context::GetInstance()->GetCurrentClassLoader() == nullptr) {
55+
LOGD("Disabled background verification");
56+
return;
57+
}
58+
backup(thiz, dex_files, class_loader);
59+
};
5960

6061
public:
6162
static void DisableBackgroundVerification(const lsplant::HookHandler &handler) {
6263
const int api_level = lspd::GetAndroidApiLevel();
6364
if (api_level >= __ANDROID_API_Q__) {
64-
handler.hook(RunBackgroundVerificationWithContext_);
65-
handler.hook(RunBackgroundVerification_);
65+
handler(RunBackgroundVerificationWithContext_);
66+
handler(RunBackgroundVerification_);
6667
}
6768
}
6869
};

patch-loader/src/main/jni/src/jni/bypass_sig.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
#include "utils/hook_helper.hpp"
1313
#include "utils/jni_helper.hpp"
1414

15+
using lsplant::operator""_sym;
16+
1517
namespace lspd {
1618

1719
std::string apkPath;
1820
std::string redirectPath;
1921

2022
inline static constexpr auto kLibCName = "libc.so";
2123

22-
std::unique_ptr<const SandHook::ElfImg>& GetC(bool release = false) {
24+
std::unique_ptr<const SandHook::ElfImg> &GetC(bool release = false) {
2325
static std::unique_ptr<const SandHook::ElfImg> kImg = nullptr;
2426
if (release) {
2527
kImg.reset();
@@ -29,23 +31,24 @@ std::unique_ptr<const SandHook::ElfImg>& GetC(bool release = false) {
2931
return kImg;
3032
}
3133

32-
inline static lsplant::Hooker<"__openat", int(int, const char*, int, int)> __openat_ =
33-
+[](int fd, const char* pathname, int flag, int mode) {
34-
if (pathname == apkPath) {
35-
LOGD("Redirect openat from {} to {}", pathname, redirectPath);
36-
return __openat_(fd, redirectPath.c_str(), flag, mode);
37-
}
38-
return __openat_(fd, pathname, flag, mode);
39-
};
34+
inline static auto __openat_ =
35+
"__openat"_sym.hook->*[]<lsplant::Backup auto backup>(int fd, const char *pathname, int flag,
36+
int mode) static -> int {
37+
if (pathname == apkPath) {
38+
LOGD("Redirect openat from {} to {}", pathname, redirectPath);
39+
return backup(fd, redirectPath.c_str(), flag, mode);
40+
}
41+
return backup(fd, pathname, flag, mode);
42+
};
4043

41-
bool HookOpenat(const lsplant::HookHandler& handler) { return handler.hook(__openat_); }
44+
bool HookOpenat(const lsplant::HookHandler &handler) { return handler(__openat_); }
4245

4346
LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
4447
jstring cacheApkPath) {
4548
auto r = HookOpenat(lsplant::InitInfo{
4649
.inline_hooker =
4750
[](auto t, auto r) {
48-
void* bk = nullptr;
51+
void *bk = nullptr;
4952
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
5053
},
5154
.art_symbol_resolver = [](auto symbol) { return GetC()->getSymbAddress(symbol); },
@@ -66,6 +69,6 @@ LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
6669
static JNINativeMethod gMethods[] = {
6770
LSP_NATIVE_METHOD(SigBypass, enableOpenatHook, "(Ljava/lang/String;Ljava/lang/String;)V")};
6871

69-
void RegisterBypass(JNIEnv* env) { REGISTER_LSP_NATIVE_METHODS(SigBypass); }
72+
void RegisterBypass(JNIEnv *env) { REGISTER_LSP_NATIVE_METHODS(SigBypass); }
7073

7174
} // namespace lspd

0 commit comments

Comments
 (0)