Skip to content

Commit

Permalink
Update JingMatrix/LSPosed
Browse files Browse the repository at this point in the history
To avoid a crash in the fisrt launch (#7), we cannot use PLT
.inline_hooker to DisableBackgroundVerification.

Remove ccache to avoid difference between CI builds and local builds.
  • Loading branch information
JingMatrix committed Sep 16, 2024
1 parent a85a0fa commit 557d560
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 192 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ jobs:
with:
gradle-home-cache-cleanup: true

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

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Setup ninja
uses: seanmiddleditch/gha-setup-ninja@master
with:
Expand Down
2 changes: 1 addition & 1 deletion core
Submodule core updated 84 files
+18 −15 .github/dependabot.yml
+19 −27 .github/workflows/core.yml
+10 −1 .gitmodules
+3 −1 README.md
+16 −0 apache/build.gradle.kts
+1 −0 apache/commons-lang
+0 −0 apache/local/org/apache/commons/lang3/reflect/MemberUtilsX.java
+4 −0 app/proguard-rules.pro
+19 −0 app/src/main/java/org/lsposed/manager/ConfigManager.java
+3 −1 app/src/main/java/org/lsposed/manager/ui/fragment/ModulesFragment.java
+7 −0 app/src/main/java/org/lsposed/manager/ui/fragment/SettingsFragment.java
+2 −0 app/src/main/res/values/strings.xml
+8 −0 app/src/main/res/xml/prefs.xml
+2 −2 build.gradle.kts
+1 −1 core/build.gradle.kts
+6 −0 core/proguard-rules.pro
+3 −3 core/src/main/java/de/robv/android/xposed/XposedHelpers.java
+154 −0 core/src/main/java/org/apache/commons/lang3/local/ArrayUtils.java
+1,633 −0 core/src/main/java/org/apache/commons/lang3/local/ClassUtils.java
+73 −0 core/src/main/java/org/apache/commons/lang3/local/StringUtils.java
+55 −0 core/src/main/java/org/apache/commons/lang3/local/mutable/Mutable.java
+121 −0 core/src/main/java/org/apache/commons/lang3/local/mutable/MutableObject.java
+342 −0 core/src/main/java/org/apache/commons/lang3/local/reflect/MemberUtils.java
+31 −0 core/src/main/java/org/apache/commons/lang3/local/reflect/MemberUtilsX.java
+6 −0 core/src/main/java/org/lsposed/lspd/hooker/HandleSystemServerProcessHooker.java
+2 −2 core/src/main/jni/CMakeLists.txt
+4 −3 core/src/main/jni/include/config.h
+4 −0 core/src/main/jni/include/elf_util.h
+9 −23 core/src/main/jni/include/framework/androidfw/resource_types.h
+74 −40 core/src/main/jni/include/native_util.h
+2 −0 core/src/main/jni/include/symbol_cache.h
+0 −452 core/src/main/jni/include/xz/xz.h
+0 −129 core/src/main/jni/include/xz/xz_config.h
+0 −204 core/src/main/jni/include/xz/xz_lzma2.h
+0 −162 core/src/main/jni/include/xz/xz_private.h
+0 −62 core/src/main/jni/include/xz/xz_stream.h
+120 −116 core/src/main/jni/src/elf_util.cpp
+1 −1 core/src/main/jni/src/jni/resources_hook.cpp
+15 −22 core/src/main/jni/src/native_api.cpp
+27 −0 core/src/main/jni/src/native_api.h
+20 −1 core/src/main/jni/src/symbol_cache.cpp
+0 −59 core/src/main/jni/src/xz/xz_crc32.c
+0 −54 core/src/main/jni/src/xz/xz_crc64.c
+0 −622 core/src/main/jni/src/xz/xz_dec_bcj.c
+0 −1,344 core/src/main/jni/src/xz/xz_dec_lzma2.c
+0 −941 core/src/main/jni/src/xz/xz_dec_stream.c
+1 −1 daemon/build.gradle.kts
+1 −0 daemon/src/main/java/org/lsposed/lspd/service/BridgeService.java
+63 −2 daemon/src/main/java/org/lsposed/lspd/service/ConfigManager.java
+31 −117 daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java
+7 −9 daemon/src/main/java/org/lsposed/lspd/service/LSPosedService.java
+8 −0 daemon/src/main/java/org/lsposed/lspd/service/LogcatService.java
+9 −5 daemon/src/main/java/org/lsposed/lspd/service/ServiceManager.java
+13 −3 daemon/src/main/jni/logcat.cpp
+18 −19 dex2oat/src/main/cpp/dex2oat.c
+15 −3 external/CMakeLists.txt
+1 −1 external/dobby
+1 −1 external/fmt
+1 −1 external/lsplant
+1 −0 external/lsplt
+1 −0 external/xz-embedded
+12 −13 gradle/libs.versions.toml
+ gradle/wrapper/gradle-wrapper.jar
+1 −1 gradle/wrapper/gradle-wrapper.properties
+5 −2 gradlew
+2 −0 gradlew.bat
+50 −1 magisk-loader/build.gradle.kts
+11 −0 magisk-loader/magisk_module/customize.sh
+5 −2 magisk-loader/src/main/java/org/lsposed/lspd/core/Main.java
+0 −260 magisk-loader/src/main/java/org/lsposed/lspd/service/ActivityController.java
+28 −47 magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java
+2 −29 magisk-loader/src/main/java/org/lsposed/lspd/util/ParasiticManagerHooker.java
+86 −0 magisk-loader/src/main/java/org/lsposed/lspd/util/ParasiticManagerSystemHooker.java
+1 −1 magisk-loader/src/main/jni/CMakeLists.txt
+1 −0 magisk-loader/src/main/jni/api/riru_main.cpp
+170 −177 magisk-loader/src/main/jni/src/magisk_loader.cpp
+1 −1 magisk-loader/src/main/jni/src/magisk_loader.h
+78 −36 magisk-loader/src/main/jni/src/service.cpp
+0 −2 magisk-loader/src/main/jni/src/service.h
+9 −0 magisk-loader/src/webroot/index.html
+12 −0 magisk-loader/src/webroot/index.js
+3 −1 services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPosedService.aidl
+4 −0 services/manager-service/src/main/aidl/org/lsposed/lspd/ILSPManagerService.aidl
+1 −0 settings.gradle.kts
80 changes: 41 additions & 39 deletions patch-loader/src/main/jni/include/art/runtime/jit/profile_saver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,49 @@
using namespace lsplant;

namespace art {
CREATE_MEM_HOOK_STUB_ENTRY(
"_ZN3art12ProfileSaver20ProcessProfilingInfoEbPt",
bool, ProcessProfilingInfo, (void * thiz, bool, uint16_t *), {
LOGD("skipped profile saving");
return true;
});

CREATE_MEM_HOOK_STUB_ENTRY(
"_ZN3art12ProfileSaver20ProcessProfilingInfoEbbPt",
bool, ProcessProfilingInfoWithBool, (void * thiz, bool, bool, uint16_t *), {
LOGD("skipped profile saving");
return true;
});

CREATE_HOOK_STUB_ENTRY(
"execve",
int, execve, (const char *pathname, const char *argv[], char *const envp[]), {
if (strstr(pathname, "dex2oat")) {
size_t count = 0;
while (argv[count++] != nullptr);
std::unique_ptr<const char *[]> new_args = std::make_unique<const char *[]>(
count + 1);
for (size_t i = 0; i < count - 1; ++i)
new_args[i] = argv[i];
new_args[count - 1] = "--inline-max-code-units=0";
new_args[count] = nullptr;

LOGD("dex2oat by disable inline!");
int ret = backup(pathname, new_args.get(), envp);
return ret;
}
int ret = backup(pathname, argv, envp);
class ProfileSaver {
private:
inline static MemberHooker<"_ZN3art12ProfileSaver20ProcessProfilingInfoEbPt", ProfileSaver,
bool(bool, uint16_t *)>
ProcessProfilingInfo_ = +[](ProfileSaver *thiz, bool a, uint16_t *b) {
LOGD("skipped profile saving");
return true;
};

inline static MemberHooker<"_ZN3art12ProfileSaver20ProcessProfilingInfoEbbPt", ProfileSaver,
bool(bool, bool, uint16_t *)>
ProcessProfilingInfoWithBool_ = +[](ProfileSaver *thiz, bool, bool, uint16_t *) {
LOGD("skipped profile saving");
return true;
};

inline static Hooker<"execve",
int(const char *pathname, const char *argv[], char *const envp[])>
execve_ = +[](const char *pathname, const char *argv[], char *const envp[]) {
if (strstr(pathname, "dex2oat")) {
size_t count = 0;
while (argv[count++] != nullptr);
std::unique_ptr<const char *[]> new_args =
std::make_unique<const char *[]>(count + 1);
for (size_t i = 0; i < count - 1; ++i) new_args[i] = argv[i];
new_args[count - 1] = "--inline-max-code-units=0";
new_args[count] = nullptr;

LOGD("dex2oat by disable inline!");
int ret = execve_(pathname, new_args.get(), envp);
return ret;
});

}
int ret = execve_(pathname, argv, envp);
return ret;
};

public:
static void DisableInline(const HookHandler &handler) {
HookSyms(handler, ProcessProfilingInfo, ProcessProfilingInfoWithBool);
HookSymNoHandle(handler, reinterpret_cast<void*>(&::execve), execve);
handler.hook(ProcessProfilingInfo_);
handler.hook(ProcessProfilingInfoWithBool_);
handler.hook(execve_);
}
}

};
} // namespace art

#endif //LSPATCH_PROFILE_SAVER_H
#endif // LSPATCH_PROFILE_SAVER_H
47 changes: 27 additions & 20 deletions patch-loader/src/main/jni/include/art/runtime/oat_file_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,46 @@
using namespace lsplant;

namespace art {
CREATE_MEM_HOOK_STUB_ENTRY(
"_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobjectPKc",
void, RunBackgroundVerificationWithContext,
(void * thiz, const std::vector<const void *> &dex_files,
jobject class_loader,
const char *class_loader_context), {
class FileManager {
public:
inline static MemberHooker<
"_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__"
"16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobjectPKc",
FileManager, void(const std::vector<const void *> &, jobject, const char *)>
RunBackgroundVerificationWithContext_ =
+[](FileManager *thiz, const std::vector<const void *> &dex_files, jobject class_loader,
const char *class_loader_context) {
if (lspd::Context::GetInstance()->GetCurrentClassLoader() == nullptr) {
LOGD("Disabled background verification");
return;
}
backup(thiz, dex_files, class_loader, class_loader_context);
});
RunBackgroundVerificationWithContext_(thiz, dex_files, class_loader,
class_loader_context);
};

CREATE_MEM_HOOK_STUB_ENTRY(
"_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobject",
void, RunBackgroundVerification,
(void * thiz, const std::vector<const void *> &dex_files,
jobject class_loader), {
inline static MemberHooker<
"_ZN3art14OatFileManager25RunBackgroundVerificationERKNSt3__"
"16vectorIPKNS_7DexFileENS1_9allocatorIS5_EEEEP8_jobject",
FileManager, void(const std::vector<const void *> &, jobject)>
RunBackgroundVerification_ =
+[](FileManager *thiz, const std::vector<const void *> &dex_files,
jobject class_loader) {
if (lspd::Context::GetInstance()->GetCurrentClassLoader() == nullptr) {
LOGD("Disabled background verification");
return;
}
backup(thiz, dex_files, class_loader);
});

RunBackgroundVerification_(thiz, dex_files, class_loader);
};

public:
static void DisableBackgroundVerification(const lsplant::HookHandler &handler) {
const int api_level = lspd::GetAndroidApiLevel();
if (api_level >= __ANDROID_API_Q__) {
HookSyms(handler, RunBackgroundVerificationWithContext, RunBackgroundVerification);
handler.hook(RunBackgroundVerificationWithContext_);
handler.hook(RunBackgroundVerification_);
}
}
}

};
} // namespace art

#endif //LSPATCH_OAT_FILE_MANAGER_H
#endif // LSPATCH_OAT_FILE_MANAGER_H
71 changes: 39 additions & 32 deletions patch-loader/src/main/jni/src/jni/bypass_sig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by VIP on 2021/4/25.
//

#include "../src/native_api.h"
#include "bypass_sig.h"
#include "elf_util.h"
#include "logging.h"
Expand All @@ -12,40 +13,46 @@

namespace lspd {

std::string apkPath;
std::string redirectPath;

CREATE_HOOK_STUB_ENTRY(
"__openat",
int, __openat,
(int fd, const char* pathname, int flag, int mode), {
if (pathname == apkPath) {
LOGD("redirect openat");
return backup(fd, redirectPath.c_str(), flag, mode);
}
return backup(fd, pathname, flag, mode);
});

LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath, jstring cacheApkPath) {
auto sym_openat = SandHook::ElfImg("libc.so").getSymbAddress<void *>("__openat");
auto r = HookSymNoHandle(handler, sym_openat, __openat);
if (!r) {
LOGE("Hook __openat fail");
return;
}
lsplant::JUTFString str1(env, origApkPath);
lsplant::JUTFString str2(env, cacheApkPath);
apkPath = str1.get();
redirectPath = str2.get();
LOGD("apkPath %s", apkPath.c_str());
LOGD("redirectPath %s", redirectPath.c_str());
}
std::string apkPath;
std::string redirectPath;

static JNINativeMethod gMethods[] = {
LSP_NATIVE_METHOD(SigBypass, enableOpenatHook, "(Ljava/lang/String;Ljava/lang/String;)V")
inline static lsplant::Hooker<"__openat", int(int, const char*, int flag, int)> __openat_ =
+[](int fd, const char* pathname, int flag, int mode) {
if (pathname == apkPath) {
LOGD("redirect openat");
return __openat_(fd, redirectPath.c_str(), flag, mode);
}
return __openat_(fd, pathname, flag, mode);
};

void RegisterBypass(JNIEnv* env) {
REGISTER_LSP_NATIVE_METHODS(SigBypass);
bool HookOpenat(const lsplant::HookHandler& handler) { return handler.hook(__openat_); }

LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
jstring cacheApkPath) {
auto r = HookOpenat(lsplant::InitInfo{
.inline_hooker =
[](auto t, auto r) {
void* bk = nullptr;
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
},
.art_symbol_resolver =
[](auto symbol) { return SandHook::ElfImg("libc.so").getSymbAddress(symbol); },
});
if (!r) {
LOGE("Hook __openat fail");
return;
}
lsplant::JUTFString str1(env, origApkPath);
lsplant::JUTFString str2(env, cacheApkPath);
apkPath = str1.get();
redirectPath = str2.get();
LOGD("apkPath %s", apkPath.c_str());
LOGD("redirectPath %s", redirectPath.c_str());
}

static JNINativeMethod gMethods[] = {
LSP_NATIVE_METHOD(SigBypass, enableOpenatHook, "(Ljava/lang/String;Ljava/lang/String;)V")};

void RegisterBypass(JNIEnv* env) { REGISTER_LSP_NATIVE_METHODS(SigBypass); }

} // namespace lspd
Loading

0 comments on commit 557d560

Please sign in to comment.