fix 正常应用隐藏失败,增加LOG日志方便排查,已经正式机型测试成功
This commit is contained in:
@@ -77,7 +77,9 @@ void load_so(const char *game_data_dir, JavaVM *vm, const char *soname) {
|
|||||||
if (handle) {
|
if (handle) {
|
||||||
LOGI("Successfully loaded %s", new_so_path);
|
LOGI("Successfully loaded %s", new_so_path);
|
||||||
load = true;
|
load = true;
|
||||||
riru_hide(soname);
|
char new_soname[256];
|
||||||
|
sprintf(new_soname, "%s.so", soname);
|
||||||
|
riru_hide(new_soname);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
LOGE("Failed to load %s: %s", new_so_path, dlerror());
|
LOGE("Failed to load %s: %s", new_so_path, dlerror());
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ static int get_prot(const procmaps_struct *procstruct) {
|
|||||||
__typeof__(exp) _rc; \
|
__typeof__(exp) _rc; \
|
||||||
_rc = (exp); \
|
_rc = (exp); \
|
||||||
if (_rc == failure_value) { \
|
if (_rc == failure_value) { \
|
||||||
PLOGE(#exp); \
|
LOGE(#exp); \
|
||||||
return 1; \
|
return 1; \
|
||||||
} \
|
} \
|
||||||
_rc; })
|
_rc; })
|
||||||
@@ -100,7 +100,7 @@ int riru_hide(const char *name) {
|
|||||||
|
|
||||||
// Match the memory regions we want to hide
|
// Match the memory regions we want to hide
|
||||||
if (!matched) continue;
|
if (!matched) continue;
|
||||||
|
LOGI("matched %s", maps_tmp->pathname);
|
||||||
auto start = (uintptr_t) maps_tmp->addr_start;
|
auto start = (uintptr_t) maps_tmp->addr_start;
|
||||||
auto end = (uintptr_t) maps_tmp->addr_end;
|
auto end = (uintptr_t) maps_tmp->addr_end;
|
||||||
if (maps_tmp->is_r || maps_tmp->is_x) { // If memory is readable or executable
|
if (maps_tmp->is_r || maps_tmp->is_x) { // If memory is readable or executable
|
||||||
@@ -117,6 +117,7 @@ int riru_hide(const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < data_count; ++i) {
|
for (int i = 0; i < data_count; ++i) {
|
||||||
|
LOGI("do_hide %d", i);
|
||||||
do_hide(&data[i]);
|
do_hide(&data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,26 +11,7 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include "pmparser.h"
|
#include "pmparser.h"
|
||||||
#include "android/log.h"
|
#include "android/log.h"
|
||||||
|
#include "log.h"
|
||||||
#ifndef LOG_TAG
|
|
||||||
#ifdef __LP64__
|
|
||||||
#define LOG_TAG "Riru64"
|
|
||||||
#else
|
|
||||||
#define LOG_TAG "Riru"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
|
|
||||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define LOGV(...)
|
|
||||||
#define LOGD(...)
|
|
||||||
#endif
|
|
||||||
#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 PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int riru_hide(const char *name) EXPORT;
|
int riru_hide(const char *name) EXPORT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ implied warranty.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pmparser.h"
|
#include "pmparser.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gobal variables
|
* gobal variables
|
||||||
@@ -20,81 +21,160 @@ implied warranty.
|
|||||||
//procmaps_struct* g_current=NULL;
|
//procmaps_struct* g_current=NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procmaps_iterator* pmparser_parse(int pid){
|
procmaps_iterator* pmparser_parse(int pid){
|
||||||
procmaps_iterator* maps_it = static_cast<procmaps_iterator *>(malloc(
|
LOGI("pmparser_parse called with pid: %d", pid);
|
||||||
sizeof(procmaps_iterator)));
|
|
||||||
|
procmaps_iterator* maps_it = (procmaps_iterator *)malloc(sizeof(procmaps_iterator));
|
||||||
|
if (!maps_it) {
|
||||||
|
LOGI("Failed to allocate memory for procmaps_iterator");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
LOGI("Allocated memory for procmaps_iterator: %p", maps_it);
|
||||||
|
|
||||||
char maps_path[500];
|
char maps_path[500];
|
||||||
if(pid >= 0 ){
|
if(pid >= 0 ){
|
||||||
sprintf(maps_path,"/proc/%d/maps",pid);
|
snprintf(maps_path, sizeof(maps_path), "/proc/%d/maps", pid);
|
||||||
|
LOGI("Constructed maps_path for pid: %s", maps_path);
|
||||||
} else {
|
} else {
|
||||||
sprintf(maps_path,"/proc/self/maps");
|
snprintf(maps_path, sizeof(maps_path), "/proc/self/maps");
|
||||||
|
LOGI("Constructed maps_path for self: %s", maps_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* file = fopen(maps_path, "r");
|
FILE* file = fopen(maps_path, "r");
|
||||||
if(!file){
|
if(!file){
|
||||||
fprintf(stderr,"pmparser : cannot open the memory maps, %s\n",strerror(errno));
|
LOGI("pmparser: cannot open the memory maps, %s", strerror(errno));
|
||||||
|
free(maps_it);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int ind=0;char buf[PROCMAPS_LINE_MAX_LENGTH];
|
LOGI("Opened maps file: %s", maps_path);
|
||||||
int c;
|
|
||||||
|
int ind = 0;
|
||||||
|
char buf[PROCMAPS_LINE_MAX_LENGTH];
|
||||||
procmaps_struct* list_maps = NULL;
|
procmaps_struct* list_maps = NULL;
|
||||||
procmaps_struct* tmp;
|
procmaps_struct* tmp;
|
||||||
procmaps_struct* current_node=list_maps;
|
procmaps_struct* current_node = NULL;
|
||||||
char addr1[20], addr2[20], perm[8], offset[20], dev[10], inode[30], pathname[PATH_MAX];
|
char addr1[20], addr2[20], perm[8], offset[20], dev[10], inode[30], pathname[PATH_MAX];
|
||||||
while( !feof(file) ){
|
|
||||||
if (fgets(buf,PROCMAPS_LINE_MAX_LENGTH,file) == NULL && errno){
|
while (fgets(buf, PROCMAPS_LINE_MAX_LENGTH, file)) {
|
||||||
fprintf(stderr,"pmparser : fgets failed, %s\n",strerror(errno));
|
LOGI("Read line %d: %s", ind + 1, buf);
|
||||||
|
|
||||||
|
// 分配一个新的节点
|
||||||
|
tmp = (procmaps_struct*)malloc(sizeof(procmaps_struct));
|
||||||
|
if (!tmp) {
|
||||||
|
LOGI("Failed to allocate memory for procmaps_struct at line %d", ind + 1);
|
||||||
|
fclose(file);
|
||||||
|
// 需要释放已分配的节点,避免内存泄漏
|
||||||
|
procmaps_struct* iter = list_maps;
|
||||||
|
while (iter) {
|
||||||
|
procmaps_struct* next = iter->next;
|
||||||
|
free(iter);
|
||||||
|
iter = next;
|
||||||
|
}
|
||||||
|
free(maps_it);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
//allocate a node
|
LOGI("Allocated memory for procmaps_struct: %p", tmp);
|
||||||
tmp=(procmaps_struct*)malloc(sizeof(procmaps_struct));
|
|
||||||
//fill the node
|
// 填充节点
|
||||||
_pmparser_split_line(buf, addr1, addr2, perm, offset, dev, inode, pathname);
|
_pmparser_split_line(buf, addr1, addr2, perm, offset, dev, inode, pathname);
|
||||||
//printf("#%s",buf);
|
LOGI("Parsed line %d - addr1: %s, addr2: %s, perm: %s, offset: %s, dev: %s, inode: %s, pathname: %s",
|
||||||
//printf("%s-%s %s %s %s %s\t%s\n",addr1,addr2,perm,offset,dev,inode,pathname);
|
ind + 1, addr1, addr2, perm, offset, dev, inode, pathname);
|
||||||
//addr_start & addr_end
|
|
||||||
unsigned long l_addr_start;
|
// 使用临时变量解析地址
|
||||||
sscanf(addr1,"%lx",(long unsigned *)&tmp->addr_start );
|
unsigned long tmp_addr_start_ul, tmp_addr_end_ul;
|
||||||
sscanf(addr2,"%lx",(long unsigned *)&tmp->addr_end );
|
if (sscanf(addr1, "%lx", &tmp_addr_start_ul) != 1) {
|
||||||
|
LOGI("Failed to parse addr_start at line %d", ind + 1);
|
||||||
|
free(tmp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (sscanf(addr2, "%lx", &tmp_addr_end_ul) != 1) {
|
||||||
|
LOGI("Failed to parse addr_end at line %d", ind + 1);
|
||||||
|
free(tmp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOGI("Parsed addresses - addr_start: 0x%lx, addr_end: 0x%lx", tmp_addr_start_ul, tmp_addr_end_ul);
|
||||||
|
|
||||||
|
tmp->addr_start = (void*)tmp_addr_start_ul;
|
||||||
|
tmp->addr_end = (void*)tmp_addr_end_ul;
|
||||||
|
|
||||||
// size
|
// size
|
||||||
tmp->length = (unsigned long)((char*)tmp->addr_end - (char*)tmp->addr_start); //perm
|
tmp->length = (unsigned long)((char*)tmp->addr_end - (char*)tmp->addr_start);
|
||||||
strcpy(tmp->perm,perm);
|
LOGI("Calculated length: %lu", tmp->length);
|
||||||
|
|
||||||
|
// perm
|
||||||
|
strncpy(tmp->perm, perm, sizeof(tmp->perm) - 1);
|
||||||
|
tmp->perm[sizeof(tmp->perm) - 1] = '\0';
|
||||||
tmp->is_r = (perm[0] == 'r');
|
tmp->is_r = (perm[0] == 'r');
|
||||||
tmp->is_w = (perm[1] == 'w');
|
tmp->is_w = (perm[1] == 'w');
|
||||||
tmp->is_x = (perm[2] == 'x');
|
tmp->is_x = (perm[2] == 'x');
|
||||||
tmp->is_p = (perm[3] == 'p');
|
tmp->is_p = (perm[3] == 'p');
|
||||||
|
LOGI("Permissions - is_r: %d, is_w: %d, is_x: %d, is_p: %d", tmp->is_r, tmp->is_w, tmp->is_x, tmp->is_p);
|
||||||
|
|
||||||
// offset
|
// offset
|
||||||
sscanf(offset,"%lx",&tmp->offset );
|
if (sscanf(offset, "%lx", &tmp->offset) != 1) {
|
||||||
|
LOGI("Failed to parse offset at line %d", ind + 1);
|
||||||
|
free(tmp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOGI("Parsed offset: 0x%lx", tmp->offset);
|
||||||
|
|
||||||
// device
|
// device
|
||||||
strcpy(tmp->dev,dev);
|
strncpy(tmp->dev, dev, sizeof(tmp->dev) - 1);
|
||||||
|
tmp->dev[sizeof(tmp->dev) - 1] = '\0';
|
||||||
|
LOGI("Device: %s", tmp->dev);
|
||||||
|
|
||||||
// inode
|
// inode
|
||||||
tmp->inode = atoi(inode);
|
tmp->inode = atoi(inode);
|
||||||
|
LOGI("Inode: %d", tmp->inode);
|
||||||
|
|
||||||
// pathname
|
// pathname
|
||||||
strcpy(tmp->pathname,pathname);
|
strncpy(tmp->pathname, pathname, sizeof(tmp->pathname) - 1);
|
||||||
|
tmp->pathname[sizeof(tmp->pathname) - 1] = '\0';
|
||||||
|
LOGI("Pathname: %s", tmp->pathname);
|
||||||
|
|
||||||
tmp->next = NULL;
|
tmp->next = NULL;
|
||||||
//attach the node
|
|
||||||
|
// 连接节点到链表
|
||||||
if(ind == 0){
|
if(ind == 0){
|
||||||
list_maps = tmp;
|
list_maps = tmp;
|
||||||
list_maps->next=NULL;
|
|
||||||
current_node = list_maps;
|
current_node = list_maps;
|
||||||
|
LOGI("Initialized list_maps with first node: %p", list_maps);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
current_node->next = tmp;
|
current_node->next = tmp;
|
||||||
current_node = tmp;
|
current_node = tmp;
|
||||||
|
LOGI("Appended node to list_maps: %p", tmp);
|
||||||
|
}
|
||||||
ind++;
|
ind++;
|
||||||
//printf("%s",buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//close file
|
if (ferror(file)) {
|
||||||
|
LOGI("Error occurred while reading the maps file");
|
||||||
|
// 释放已分配的节点和 maps_it
|
||||||
|
procmaps_struct* iter = list_maps;
|
||||||
|
while (iter) {
|
||||||
|
procmaps_struct* next = iter->next;
|
||||||
|
free(iter);
|
||||||
|
iter = next;
|
||||||
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
free(maps_it);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭文件
|
||||||
|
fclose(file);
|
||||||
|
LOGI("Closed maps file: %s", maps_path);
|
||||||
|
|
||||||
//g_last_head=list_maps;
|
// 设置迭代器
|
||||||
maps_it->head = list_maps;
|
maps_it->head = list_maps;
|
||||||
maps_it->current = list_maps;
|
maps_it->current = list_maps;
|
||||||
|
LOGI("Initialized procmaps_iterator - head: %p, current: %p", maps_it->head, maps_it->current);
|
||||||
|
|
||||||
return maps_it;
|
return maps_it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
procmaps_struct* pmparser_next(procmaps_iterator* p_procmaps_it){
|
procmaps_struct* pmparser_next(procmaps_iterator* p_procmaps_it){
|
||||||
if(p_procmaps_it->current == NULL)
|
if(p_procmaps_it->current == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user