Skip to content

Commit

Permalink
Fix log formatting of __openat hook
Browse files Browse the repository at this point in the history
  • Loading branch information
JingMatrix committed Sep 16, 2024
1 parent 557d560 commit 332d997
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions patch-loader/src/main/jni/src/jni/bypass_sig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Created by VIP on 2021/4/25.
//

#include "../src/native_api.h"
#include "bypass_sig.h"

#include "../src/native_api.h"
#include "elf_util.h"
#include "logging.h"
#include "native_util.h"
Expand All @@ -16,10 +17,22 @@ namespace lspd {
std::string apkPath;
std::string redirectPath;

inline static lsplant::Hooker<"__openat", int(int, const char*, int flag, int)> __openat_ =
inline static constexpr auto kLibCName = "libc.so";

std::unique_ptr<const SandHook::ElfImg>& GetC(bool release = false) {
static std::unique_ptr<const SandHook::ElfImg> kImg = nullptr;
if (release) {
kImg.reset();
} else if (!kImg) {
kImg = std::make_unique<SandHook::ElfImg>(kLibCName);
}
return kImg;
}

inline static lsplant::Hooker<"__openat", int(int, const char*, int, int)> __openat_ =
+[](int fd, const char* pathname, int flag, int mode) {
if (pathname == apkPath) {
LOGD("redirect openat");
LOGD("Redirect openat from {} to {}", pathname, redirectPath);
return __openat_(fd, redirectPath.c_str(), flag, mode);
}
return __openat_(fd, pathname, flag, mode);
Expand All @@ -35,8 +48,7 @@ LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
void* bk = nullptr;
return HookInline(t, r, &bk) == 0 ? bk : nullptr;
},
.art_symbol_resolver =
[](auto symbol) { return SandHook::ElfImg("libc.so").getSymbAddress(symbol); },
.art_symbol_resolver = [](auto symbol) { return GetC()->getSymbAddress(symbol); },
});
if (!r) {
LOGE("Hook __openat fail");
Expand All @@ -46,8 +58,9 @@ LSP_DEF_NATIVE_METHOD(void, SigBypass, enableOpenatHook, jstring origApkPath,
lsplant::JUTFString str2(env, cacheApkPath);
apkPath = str1.get();
redirectPath = str2.get();
LOGD("apkPath %s", apkPath.c_str());
LOGD("redirectPath %s", redirectPath.c_str());
LOGD("apkPath {}", apkPath.c_str());
LOGD("redirectPath {}", redirectPath.c_str());
GetC(true);
}

static JNINativeMethod gMethods[] = {
Expand Down

0 comments on commit 332d997

Please sign in to comment.