2.4 添加open有关函数进行参数打印
目的
打印文件open相关函数 ,用于方便定位调试
修改步骤
路径 <aosp>\bionic\libc\bionic\open.cpp 增加以下代码
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h> // 新增
#include "private/bionic_fdtrack.h"
#include "private/bionic_fortify.h"
#include <android/log.h> // 新增
#include <string.h> // 新增
int open(const char* pathname, int flags, ...) {
mode_t mode = 0;
if (needs_mode(flags)) {
va_list args;
va_start(args, flags);
mode = static_cast<mode_t>(va_arg(args, int));
va_end(args);
}
// 新增
int uid = getuid();
int pid = getpid();
if (uid > 10000)
{
char buffer[256];
snprintf(buffer, sizeof(buffer), "file=%s uid=%d pid=%d", pathname, uid, pid);
clogi("open",buffer);
}
if (uid > 10000 && contains_keyword(pathname)) {
clogi("open-replace", pathname);
return FDTRACK_CREATE(__openat(AT_FDCWD, "/bin/non_exist", force_O_LARGEFILE(flags), mode));
}
return FDTRACK_CREATE(__openat(AT_FDCWD, pathname, force_O_LARGEFILE(flags), mode));
}
int openat(int fd, const char *pathname, int flags, ...) {
mode_t mode = 0;
if (needs_mode(flags)) {
va_list args;
va_start(args, flags);
mode = static_cast<mode_t>(va_arg(args, int));
va_end(args);
}
// 新增
int uid = getuid();
int pid = getpid();
if (uid > 10000)
{
char buffer[256];
snprintf(buffer, sizeof(buffer), "file=%s uid=%d pid=%d", pathname, uid, pid);
clogi("openat",buffer);
}
if (uid > 10000 && contains_keyword(pathname)) {
clogi("openat-replace", pathname);
return FDTRACK_CREATE_NAME("openat", __openat(fd, "/bin/non_exist", force_O_LARGEFILE(flags), mode));
}
return FDTRACK_CREATE_NAME("openat", __openat(fd, pathname, force_O_LARGEFILE(flags), mode));
}
实现效果
2.5 定制su名字隐藏root
目的
需要修改的文件有如下几个
<aosp>\system\extras\su
<aosp>\system\extras\su\Android.mk
<aosp>\system\core\libcutils\fs_cofnig.cpp
<aosp>\system\sepolicy\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\30.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\29.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\28.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\27.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\26.0\private\file_contexts
<aosp>\build\make\target\product\base_system.mk
su文件夹
自定义su文件名字,规避root检查。
环境:Pixel 3
目标:修改su为xu,命名可以是其他。
修改方式
mv \system\extras\su -> \system\extras\xu
替换字符串 \system\extras\xu[Android.mk](android.mk/) `LOCAL_MO… := su->LOCAL_MODULE := xu 替换字符串 <aosp>\system\core\libcutils\fs_cofnig.cppsystem/xbin/su->system/xbin/xu`
file_contexts
<aosp>\system\sepolicy\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\30.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\29.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\28.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\27.0\private\file_contexts
<aosp>\system\sepolicy\prebuilts\api\26.0\private\file_contexts
统一将 system/xbin/su -> system/xbin/xu
替换字符串 \build\make\target\product[base_system.mk](http://base_system.mk/) su -> xu