83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
#include <cstring>
|
|
#include <cstdio>
|
|
#include <android/log.h>
|
|
#include <jni.h>
|
|
#include "main.h"
|
|
#include "util/util.h"
|
|
#include <unistd.h>
|
|
#include <unwind.h>
|
|
#include <dlfcn.h>
|
|
#include <execinfo.h>
|
|
#include <link.h>
|
|
#include <sstream>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include "util/armhook.h"
|
|
#include "util/armhooks.h"
|
|
|
|
void* libapp_base = NULL;
|
|
|
|
static int find_lib_callback(struct dl_phdr_info* info, size_t size, void* data) {
|
|
if (strstr(info->dlpi_name, "libapp.so")) {
|
|
libapp_base = (void*)info->dlpi_addr;
|
|
LOGD("Found libapp.so at base: 0x%08X", (uintptr_t)libapp_base);
|
|
return 1; // Останавливаем перебор
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
bool get_libapp_base() {
|
|
dl_iterate_phdr(find_lib_callback, NULL);
|
|
if (!libapp_base) {
|
|
Log("libapp.so not found in memory!");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
int (*sub_4087CC)() = nullptr;
|
|
int HOOK_sub_4087CC() {
|
|
Log("Its hooked sub_4087CC()!");
|
|
return sub_4087CC();
|
|
}
|
|
|
|
uintptr_t get_library_base(const char* lib_name) {
|
|
FILE* maps = fopen("/proc/self/maps", "r");
|
|
if (!maps) return 0;
|
|
|
|
char line[512];
|
|
uintptr_t base = 0;
|
|
|
|
while (fgets(line, sizeof(line), maps)) {
|
|
if (strstr(line, lib_name)) {
|
|
base = (uintptr_t)strtoul(strtok(line, "-"), NULL, 16);
|
|
break;
|
|
}
|
|
}
|
|
|
|
fclose(maps);
|
|
return base;
|
|
}
|
|
|
|
bool is_address_executable(void* addr) {
|
|
uintptr_t page = (uintptr_t)addr & ~(getpagesize() - 1);
|
|
return msync((void*)page, getpagesize(), MS_ASYNC) == 0;
|
|
}
|
|
|
|
bool is_memory_writable(void* addr, size_t size) {
|
|
uintptr_t page_start = (uintptr_t)addr & ~(getpagesize() - 1);
|
|
return mprotect((void*)page_start, size, PROT_READ | PROT_WRITE | PROT_EXEC) == 0;
|
|
}
|
|
|
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
|
|
|
get_libapp_base();
|
|
|
|
|
|
return JNI_VERSION_1_6;
|
|
}
|
|
|
|
extern "C"
|
|
JNIEXPORT void JNICALL
|
|
Java_nfs_mod_mpcore_MultiplayerCore_bumpBackTraceToLogcat(JNIEnv *env, jobject thiz) {
|
|
//backtraceToLogcat();
|
|
} |