修改$AOSP/bionic/libc/bionic/fork.c,让程序fork失败即可,修改的代码如下:
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include "pthread_internal.h"
#include "bionic_pthread.h"
#include "cpuacct.h"
extern int __fork(void);
#define BUF_LEN 512
int block()
{
char buf[BUF_LEN] = {0};
char cmd[128] = {0};
sprintf(cmd , "/proc/%d/cmdline" , getpid());
int fd = open(cmd , O_RDONLY);
read(fd , buf , BUF_LEN);
close(fd);
char targetPath[BUF_LEN] = {0};
sprintf(targetPath , "/data/data/%s" , buf);
if (access(targetPath , F_OK) == 0)
{
return 1;
}
return 0;
}
int fork(void)
{
int ret;
if (block())
{
return -1;
}
//......
}
虽然这种小技巧很容易在以后的加固版本会被针对,但是至少目前是有效的