mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-30 21:40:17 +02:00
refactor(native): hook def
This commit is contained in:
parent
2b85856be0
commit
ba655a0e67
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <android/asset_manager.h>
|
||||||
|
|
||||||
namespace AssetHook {
|
namespace AssetHook {
|
||||||
jmethodID native_lib_on_asset_load;
|
jmethodID native_lib_on_asset_load;
|
||||||
AAsset* (*AAssetManager_open_original)(AAssetManager*, const char*, int) = nullptr;
|
|
||||||
|
|
||||||
AAsset* AAssetManager_open_hook(AAssetManager* mgr, const char* filename, int mode) {
|
HOOK_DEF(AAsset*, AAssetManager_open_hook, AAssetManager* mgr, const char* filename, int mode) {
|
||||||
if (common::native_config->hook_asset_open) {
|
if (common::native_config->hook_asset_open) {
|
||||||
JNIEnv *env = nullptr;
|
JNIEnv *env = nullptr;
|
||||||
common::java_vm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
common::java_vm->GetEnv((void **)&env, JNI_VERSION_1_6);
|
||||||
@ -15,11 +15,11 @@ namespace AssetHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return AAssetManager_open_original(mgr, filename, mode);
|
return AAssetManager_open_hook_original(mgr, filename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(JNIEnv *env) {
|
void init(JNIEnv *env) {
|
||||||
native_lib_on_asset_load = env->GetMethodID(env->GetObjectClass(common::native_lib_object), "shouldLoadAsset", "(Ljava/lang/String;)Z");
|
native_lib_on_asset_load = env->GetMethodID(env->GetObjectClass(common::native_lib_object), "shouldLoadAsset", "(Ljava/lang/String;)Z");
|
||||||
DobbyHook((void *) AAssetManager_open, (void *) AAssetManager_open_hook, (void **) &AAssetManager_open_original);
|
DobbyHook((void *) AAssetManager_open, (void *) AAssetManager_open_hook, (void **) &AAssetManager_open_hook_original);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace FstatHook {
|
namespace FstatHook {
|
||||||
auto fstat_original = (int (*)(int, struct stat *)) nullptr;
|
HOOK_DEF(int, fstat_hook, int fd, struct stat *buf) {
|
||||||
|
|
||||||
int fstat_hook(int fd, struct stat *buf) {
|
|
||||||
char name[256];
|
char name[256];
|
||||||
memset(name, 0, sizeof(name));
|
memset(name, 0, sizeof(name));
|
||||||
snprintf(name, sizeof(name), "/proc/self/fd/%d", fd);
|
snprintf(name, sizeof(name), "/proc/self/fd/%d", fd);
|
||||||
@ -20,10 +18,10 @@ namespace FstatHook {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fstat_original(fd, buf);
|
return fstat_hook_original(fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
DobbyHook((void *)DobbySymbolResolver("libc.so", "fstat"), (void *)fstat_hook, (void **)&fstat_original);
|
DobbyHook((void *)DobbySymbolResolver("libc.so", "fstat"), (void *)fstat_hook, (void **)&fstat_hook_original);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,10 +15,9 @@ namespace SqliteMutexHook {
|
|||||||
} sqlite3;
|
} sqlite3;
|
||||||
|
|
||||||
static std::map<std::string, sqlite3_mutex *> mutex_map = {};
|
static std::map<std::string, sqlite3_mutex *> mutex_map = {};
|
||||||
static int (*sqlite3_open_original)(const char *, sqlite3 **, unsigned int, const char *) = nullptr;
|
|
||||||
|
|
||||||
int sqlite3_open_hook(const char *filename, sqlite3 **ppDb, unsigned int flags, const char *zVfs) {
|
HOOK_DEF(int, sqlite3_open_hook, const char *filename, sqlite3 **ppDb, unsigned int flags, const char *zVfs) {
|
||||||
auto result = sqlite3_open_original(filename, ppDb, flags, zVfs);
|
auto result = sqlite3_open_hook_original(filename, ppDb, flags, zVfs);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
auto mutex = (*ppDb)->mutex;
|
auto mutex = (*ppDb)->mutex;
|
||||||
if (mutex == nullptr) return result;
|
if (mutex == nullptr) return result;
|
||||||
@ -42,6 +41,6 @@ namespace SqliteMutexHook {
|
|||||||
LOGE("sqlite3 openDatabase sig not found");
|
LOGE("sqlite3 openDatabase sig not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DobbyHook((void *) open_database_sig, (void *) sqlite3_open_hook, (void **) &sqlite3_open_original);
|
DobbyHook((void *) open_database_sig, (void *) sqlite3_open_hook, (void **) &sqlite3_open_hook_original);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,14 +19,13 @@ namespace UnaryCallHook {
|
|||||||
} grpc_byte_buffer;
|
} grpc_byte_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *(*unaryCall_original)(void *, const char *, grpc::grpc_byte_buffer **, void *, void *, void *);
|
|
||||||
static jmethodID native_lib_on_unary_call_method;
|
static jmethodID native_lib_on_unary_call_method;
|
||||||
|
|
||||||
void *unaryCall_hook(void *unk1, const char *uri, grpc::grpc_byte_buffer **buffer_ptr, void *unk4, void *unk5, void *unk6) {
|
HOOK_DEF(void *, unaryCall_hook, void *unk1, const char *uri, grpc::grpc_byte_buffer **buffer_ptr, void *unk4, void *unk5, void *unk6) {
|
||||||
// request without reference counter can be hooked using xposed ig
|
// request without reference counter can be hooked using xposed ig
|
||||||
auto slice_buffer = (*buffer_ptr)->slice_buffer;
|
auto slice_buffer = (*buffer_ptr)->slice_buffer;
|
||||||
if (slice_buffer->ref_counter == 0) {
|
if (slice_buffer->ref_counter == 0) {
|
||||||
return unaryCall_original(unk1, uri, buffer_ptr, unk4, unk5, unk6);
|
return unaryCall_hook_original(unk1, uri, buffer_ptr, unk4, unk5, unk6);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEnv *env = nullptr;
|
JNIEnv *env = nullptr;
|
||||||
@ -67,7 +66,7 @@ namespace UnaryCallHook {
|
|||||||
slice_buffer->data = (uint8_t *)((uintptr_t)new_ref_counter + ref_counter_struct_size);
|
slice_buffer->data = (uint8_t *)((uintptr_t)new_ref_counter + ref_counter_struct_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return unaryCall_original(unk1, uri, buffer_ptr, unk4, unk5, unk6);
|
return unaryCall_hook_original(unk1, uri, buffer_ptr, unk4, unk5, unk6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(JNIEnv *env) {
|
void init(JNIEnv *env) {
|
||||||
@ -80,9 +79,9 @@ namespace UnaryCallHook {
|
|||||||
native_lib_on_unary_call_method = env->GetMethodID(env->GetObjectClass(common::native_lib_object), "onNativeUnaryCall", "(Ljava/lang/String;[B)L" BUILD_NAMESPACE "/NativeRequestData;");
|
native_lib_on_unary_call_method = env->GetMethodID(env->GetObjectClass(common::native_lib_object), "onNativeUnaryCall", "(Ljava/lang/String;[B)L" BUILD_NAMESPACE "/NativeRequestData;");
|
||||||
|
|
||||||
if (unaryCall_func != 0) {
|
if (unaryCall_func != 0) {
|
||||||
DobbyHook((void *)unaryCall_func, (void *)unaryCall_hook, (void **)&unaryCall_original);
|
DobbyHook((void *)unaryCall_func, (void *)unaryCall_hook, (void **)&unaryCall_hook_original);
|
||||||
} else {
|
} else {
|
||||||
LOGE("can't find unaryCall signature");
|
LOGE("Can't find unaryCall signature");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <dobby.h>
|
#include <dobby.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <android/asset_manager.h>
|
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -24,7 +23,7 @@ void JNICALL init(JNIEnv *env, jobject clazz) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGD("libclient.so base=0x%0lx, size=0x%0lx", client_module.base, client_module.size);
|
LOGD("libclient.so base=0x%lx, size=0x%zx", client_module.base, client_module.size);
|
||||||
|
|
||||||
AssetHook::init(env);
|
AssetHook::init(env);
|
||||||
UnaryCallHook::init(env);
|
UnaryCallHook::init(env);
|
||||||
|
@ -5,7 +5,5 @@
|
|||||||
#define LOG_TAG "SnapEnhanceNative"
|
#define LOG_TAG "SnapEnhanceNative"
|
||||||
|
|
||||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
||||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
|
||||||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
|
|
||||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define HOOK_DEF(ret, func, ...) ret (*func##_original)(__VA_ARGS__); ret func(__VA_ARGS__)
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uintptr_t base;
|
uintptr_t base;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user