部分应用会采用svc调用,直接hook libc 的 open会无法得到想要的信息,这时候需要从内核下手,高版本内核直接上ebpf,低版本麻烦一点,手动插装:
1 下载aosp 及 机型 对应的内核源码
2 打桩(fs/open.c):
// add start
extern long strncpy_from_user(char *, const char __user *, long);
// add end
long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
{
struct open_flags op;
int fd = build_open_flags(flags, mode, &op);
struct filename *tmp;
// add start
char bufname[256]={0};
int pid=current->pid;
// add end
if (fd)
return fd;
tmp = getname(filename);
if (IS_ERR(tmp))
return PTR_ERR(tmp);
fd = get_unused_fd_flags(flags);
if (fd >= 0) {
struct file *f = do_filp_open(dfd, tmp, &op);
if (IS_ERR(f)) {
put_unused_fd(fd);
fd = PTR_ERR(f);
} else {
fsnotify_open(f);
fd_install(fd, f);
}
}
putname(tmp);
// add start
if(pid>2000){
//dump_stack();
strncpy_from_user(bufname,filename,255);
printk("YoohaLog: {\"Type\":\"KernelLog\",\"Pid\":\"%d\",\"Info\":\"__NR_openat fd=%d filename=%s flags=%d return=%d\"}", pid, dfd, bufname, flags, fd);
}
// add end
return fd;
}
效果: