监控android内存被dump实现

46 篇文章 9 订阅
12 篇文章 0 订阅

监控原理

通常加固会在程序运行前完成对text的解密,所以脱壳可以通过
/proc/pid/mem或/proc/pid/pagemap或/proc/pid/maps,获取到加固后解密的代码内容。

可以通过Inotify系列api来监控mem或pagemap的打开或访问事件,
一旦发生触发了事件就结束进程来阻止android的内存被dump。

代码实现

//监控内存是否被修改事件
void thread_watchIntifyDump()
{
char dirName[NAME_MAX]={0};
//用于监控/proc/pid/maps的数据
snprintf(dirName,NAME_MAX,"/proc/%d/maps",getpid());

int fd = inotify_init();
if (fd < 0)
{
LOGA("inotify_init err.\n");
return;

}

int wd = inotify_add_watch(fd,dirName,IN_ALL_EVENTS);
if (wd < 0)
{
LOGA("inotify_add_watch err.\n");
close(fd);

return;

}

const int buflen=sizeof(struct inotify_event) * 0x100;
char buf[buflen]={0};
fd_set readfds;

while(1)
{

FD_ZERO(&readfds);
FD_SET(fd, &readfds);

int iRet = select(fd+1,&readfds,0,0,0); // 此处阻塞
LOGB("iRet的返回值:%d\n",iRet);
if(-1==iRet)
break;

if (iRet)
{

memset(buf,0,buflen);
int len = read(fd,buf,buflen);

int i=0;

while(i < len)
{

struct inotify_event *event = (struct inotify_even

t*)&buf[i];

LOGB("1 event mask的数值为:%d\n",event->mask);

if( (event->mask==IN_OPEN) )
{

// 此处判定为有true,执行崩溃.

LOGB("2 有人打开pagemap,第%d次.\n\n",i);

}i += sizeof (struct inotify_event) + event->len;

}

}
}

inotify_rm_watch(fd,wd);
close(fd);


return;

}




//接口函数调用
void main()
{

// 监控/proc/pid/mem

pthread_t ptMem,t,ptPageMap;

int iRet=0;

// 监控/proc/pid/pagemap

iRet=pthread_create(&ptPageMap,NULL,(PPP)thread_watchInotifyDump,NULL);

if (0!=iRet)
{

LOGA("Create,thread_watchDumpPagemap,error!\n");

return;

}

iRet=pthread_detach(ptPageMap);

if (0!=iRet)
{

LOGA("pthread_detach,thread_watchDumpPagemap,error!\n");
return;

}

LOGB("pid:%d\n",getpid());

return;

}
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小道安全

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值