feat: Add null checks for JNI method arguments
Adds a null pointer check for the origApkPath and cacheApkPath arguments in the enableOpenatHook native method. Previously, passing nullptr to this method would lead to a potential crash. The added checks ensure the function handles invalid input gracefully by logging an error and returning early, thus preventing a potential crash.
This commit is contained in:
parent
4b8da5c255
commit
5bbef84a43
|
|
@ -2,6 +2,8 @@ name: Build CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
merge_group:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
@ -41,7 +43,7 @@ jobs:
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.ccache
|
path: ~/.ccache
|
||||||
key: ${{ runner.os }}-ccache-${{ github.sha }}
|
key: ${{ runner.os }}-ccache-${{ hashFiles('**/src/**/*.cpp', '**/src/**/*.h', '**/CMakeLists.txt') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-ccache-
|
${{ runner.os }}-ccache-
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// Created by VIP on 2021/4/25.
|
// Created by VIP on 2021/4/25.
|
||||||
// Update by HSSkyBoy on 2025/9/7
|
// Update by HSSkyBoy on 2025/9/11
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "bypass_sig.h"
|
#include "bypass_sig.h"
|
||||||
|
|
@ -17,36 +17,42 @@ using lsplant::operator""_sym;
|
||||||
|
|
||||||
namespace lspd {
|
namespace lspd {
|
||||||
|
|
||||||
std::string apkPath;
|
std::string apkPath;
|
||||||
std::string redirectPath;
|
std::string redirectPath;
|
||||||
|
|
||||||
inline static constexpr const char* kLibCName = "libc.so";
|
inline static constexpr const char* kLibCName = "libc.so";
|
||||||
|
|
||||||
// 修改回傳型別以匹配 kImg 的實際型別
|
// 修改回傳型別以匹配 kImg 的實際型別
|
||||||
std::unique_ptr<SandHook::ElfImg> &GetC(bool release = false) {
|
std::unique_ptr<SandHook::ElfImg> &GetC(bool release = false) {
|
||||||
static auto kImg = std::make_unique<SandHook::ElfImg>(kLibCName);
|
static auto kImg = std::make_unique<SandHook::ElfImg>(kLibCName);
|
||||||
if (release) {
|
if (release) {
|
||||||
kImg.reset();
|
kImg.reset();
|
||||||
kImg = nullptr;
|
kImg = nullptr;
|
||||||
}
|
}
|
||||||
return kImg;
|
return kImg;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static auto __openat_ =
|
inline static auto __openat_ =
|
||||||
"__openat"_sym.hook->*[]<lsplant::Backup auto backup>(int fd, const char *pathname, int flag,
|
"__openat"_sym.hook->*[]<lsplant::Backup auto backup>(int fd, const char *pathname, int flag,
|
||||||
int mode) static -> int {
|
int mode) static -> int {
|
||||||
if (pathname && strcmp(pathname, apkPath.c_str()) == 0) {
|
if (pathname && strcmp(pathname, apkPath.c_str()) == 0) {
|
||||||
return backup(fd, redirectPath.c_str(), flag, mode);
|
return backup(fd, redirectPath.c_str(), flag, mode);
|
||||||
}
|
}
|
||||||
return backup(fd, pathname, flag, mode);
|
return backup(fd, pathname, flag, mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool HookOpenat(const lsplant::HookHandler &handler) { return handler(__openat_); }
|
static bool HookOpenat(const lsplant::HookHandler &handler) { return handler(__openat_); }
|
||||||
|
|
||||||
LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
|
LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
|
||||||
jstring cacheApkPath) {
|
jstring cacheApkPath) {
|
||||||
|
if (origApkPath == nullptr || cacheApkPath == nullptr) {
|
||||||
|
LOGE("Invalid arguments: original or cache path is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lsplant::JUTFString str1(env, origApkPath);
|
lsplant::JUTFString str1(env, origApkPath);
|
||||||
lsplant::JUTFString str2(env, cacheApkPath);
|
lsplant::JUTFString str2(env, cacheApkPath);
|
||||||
|
|
||||||
apkPath = str1.get();
|
apkPath = str1.get();
|
||||||
redirectPath = str2.get();
|
redirectPath = str2.get();
|
||||||
|
|
||||||
|
|
@ -56,7 +62,9 @@ inline static auto __openat_ =
|
||||||
void *bk = nullptr;
|
void *bk = nullptr;
|
||||||
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
|
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
|
||||||
},
|
},
|
||||||
.art_symbol_resolver = [](auto symbol) { return GetC()->getSymbAddress(symbol); },
|
.art_symbol_resolver = [](auto symbol) {
|
||||||
|
return GetC()->getSymbAddress(symbol);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (!r) {
|
if (!r) {
|
||||||
LOGE("Hook __openat fail");
|
LOGE("Hook __openat fail");
|
||||||
|
|
@ -65,9 +73,9 @@ inline static auto __openat_ =
|
||||||
GetC(true);
|
GetC(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod gMethods[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
LSP_NATIVE_METHOD(SigBypass, enableOpenatHook, "(Ljava/lang/String;Ljava/lang/String;)V")};
|
LSP_NATIVE_METHOD(SigBypass, enableOpenatHook, "(Ljava/lang/String;Ljava/lang/String;)V")};
|
||||||
|
|
||||||
void RegisterBypass(JNIEnv *env) { REGISTER_LSP_NATIVE_METHODS(SigBypass); }
|
void RegisterBypass(JNIEnv *env) { REGISTER_LSP_NATIVE_METHODS(SigBypass); }
|
||||||
|
|
||||||
} // namespace lspd
|
} // namespace lspd
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue