Skip to content

Commit

Permalink
Update JingMatrix/LSPosed
Browse files Browse the repository at this point in the history
Fix proguard rules for release build
  • Loading branch information
JingMatrix committed Sep 5, 2024
1 parent 90880f9 commit b409cd3
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 97 deletions.
2 changes: 1 addition & 1 deletion core
Submodule core updated 69 files
+18 −15 .github/dependabot.yml
+23 −20 .github/workflows/core.yml
+7 −1 .gitmodules
+3 −1 README.md
+4 −0 app/proguard-rules.pro
+2 −2 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
+1 −1 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
+13 −20 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 −0 daemon/src/main/java/org/lsposed/lspd/service/BridgeService.java
+44 −2 daemon/src/main/java/org/lsposed/lspd/service/ConfigManager.java
+21 −117 daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java
+7 −9 daemon/src/main/java/org/lsposed/lspd/service/LSPosedService.java
+1 −1 daemon/src/main/jni/logcat.cpp
+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 −12 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
+43 −38 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
1 change: 1 addition & 0 deletions manager/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}

-keep class com.beust.jcommander.** { *; }
-keep class org.lsposed.lspatch.database.** { *; }
-keep class org.lsposed.lspatch.Patcher$Options { *; }
-keep class org.lsposed.lspatch.share.LSPConfig { *; }
-keep class org.lsposed.lspatch.share.PatchConfig { *; }
Expand Down
79 changes: 40 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,48 @@
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_, ProcessProfilingInfoWithBool_);
handler.hook(execve_);
}
}

};
} // namespace art

#endif //LSPATCH_PROFILE_SAVER_H
#endif // LSPATCH_PROFILE_SAVER_H
44 changes: 24 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,43 @@
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_, RunBackgroundVerification_);
}
}
}

};
} // namespace art

#endif //LSPATCH_OAT_FILE_MANAGER_H
#endif // LSPATCH_OAT_FILE_MANAGER_H
72 changes: 40 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 @@ -3,6 +3,8 @@
//

#include "bypass_sig.h"

#include "../src/native_api.h"
#include "elf_util.h"
#include "logging.h"
#include "native_util.h"
Expand All @@ -12,40 +14,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_, true); }

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 HookFunction(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
10 changes: 5 additions & 5 deletions patch-loader/src/main/jni/src/patch_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ namespace lspd {
void PatchLoader::InitArtHooker(JNIEnv* env, const InitInfo& initInfo) {
Context::InitArtHooker(env, initInfo);
handler = initInfo;
art::DisableInline(initInfo);
art::DisableBackgroundVerification(initInfo);
art::ProfileSaver::DisableInline(initInfo);
art::FileManager::DisableBackgroundVerification(initInfo);
}

void PatchLoader::InitHooks(JNIEnv* env) {
Expand All @@ -95,13 +95,13 @@ namespace lspd {
lsplant::InitInfo initInfo {
.inline_hooker = [](auto t, auto r) {
void* bk = nullptr;
return HookFunction(t, r, &bk) == RS_SUCCESS ? bk : nullptr;
return HookArtFunction(t, r, &bk) == 0 ? bk : nullptr;
},
.inline_unhooker = [](auto t) {
return UnhookFunction(t) == RT_SUCCESS;
return UnhookArtFunction(t) == 0;
},
.art_symbol_resolver = [](auto symbol) {
return GetArt()->getSymbAddress<void*>(symbol);
return GetArt()->getSymbAddress(symbol);
},
.art_symbol_prefix_resolver = [](auto symbol) {
return GetArt()->getSymbPrefixFirstAddress(symbol);
Expand Down

0 comments on commit b409cd3

Please sign in to comment.