Android(安卓)内存修改
16lz
2021-01-24
Android在内部机制上并不提供进程间的越界数据访问,所以通过Java完全无法实现越界数据的访问和修改,我们只能使用Linux上提供的ptrace()函数实现越界访问,其中还要用到waitpid()函数等待进程连接。
http://linux.die.net/man/2/ptrace
http://linux.die.net/man/2/waitpid
具体使用方式如下:
#include<sys/ptrace.h>//Forptrace()#include<sys/wait.h>//Forwaitpid()intmain(){intpid=1337;//Theprocessidyouwishtoattachtointaddress=0x13371337;//Theaddressyouwishtoreadintheprocess//First,attachtotheprocess//Allptrace()operationsthatfailreturn-1,theexceptionsare//PTRACE_PEEK*operationsif(ptrace(PTRACE_ATTACH,pid,NULL,NULL)==-1){//Readthevalueoferrnofordetails.//Togetahumanreadable,callstrerror()//strerror(errno)<--Returnsahumanreadableversionofthe//errorthatoccurredreturn0;}//Now,attachingdoesn'tmeanwecanreadthevaluestraightaway//Wehavetowaitfortheprocesstostopintstatus;//waitpid()returns-1onfailure//W.I.F,notW.T.F//WIFSTOPPED()returnstrueiftheprocesswasstoppedwhenweattachedtoitif(waitpid(pid,&status,0)==-1||!WIFSTOPPED(status)){//Failed,readthevalueoferrnoorstrerror(errno)return0;}errno=0;//Seterrnotozero//WeareabouttoperformaPTRACE_PEEK*operation,itispossiblethatthevalue//wereadattheaddressis-1,ifso,ptrace()willreturn-1EVENTHOUGHitsucceeded!//Thisiswhyweneedto'clear'thevalueoferrno.intvalue=ptrace(PTRACE_PEEKDATA,pid,(void*)addr,NULL);if(value==-1&&errno!=0){//Failed,readthevalueoferrnoorstrerror(errno)return0;}else{//Success!Readthevalue}//Now,wehavetodetachfromtheprocessptrace(PTRACE_DETACH,pid,NULL,NULL);return0;}
ptrace()函数需要root权限,这也是为什么所有的内存数据修改器都需要root权限
ptrace()函数是用于debug功能的系统函数,有夸进程随意访问数据的能力。
其他设想:
我们平时使用的debug功能可以详细到使用变量名获取当前数据,不知是否也能通过ptrace()函数实现此类数据搜索。
Android所提供的IBinder我们能否通过这个实现内存修改,IBinder又是通过什么实现的进程间数据共享。
以上内容来源:http://stackoverflow.com/questions/22852672/scanning-and-editing-android-app-memory-values-programmatically?answertab=votes#tab-top
更多相关文章
- C语言函数的递归(上)
- Android(安卓)数据存储---SharedPreference
- Android(安卓)实现联网(四)——TCP/UDP
- Android(安卓)-- Vold机制简要分析
- Android(安卓)App Widget中如何调用RemoteView中的函数
- android 4.0 StatusBar 架构
- 选中菜单android中的显示跳转和隐式跳转
- Android音频编解码和混音实现
- Android(安卓)应用程序之间数据共享—ContentProvider