其他
某类抽取加固APP的脱壳与修复
>>>> 脱壳
脱壳
char dexfilepath[100]={0};
int pid=getpid();
sprintf(dexfilepath,"/sdcard/%d_%d_OpenFile.dex",(int)(size),pid);
//fopen
int fd=open(dexfilepath,O_CREAT|O_RDWR,0666);
if(fd>0)
{
write(fd,base,size);
close(fd);
}
刷机成功后,安装并给予应用存储权限,然后运行App,并在sdcard目录下使用grep命令过滤dex,最终得到脱壳后的文件如下。
>>>> 修复
修复
修复方式1
最终修复效果:
修复方式2
# -*- coding: utf-8 -*-
def delblankline():
global insfilename
infopen = open(insfilename, 'r',encoding="utf-8")
outfopen = open(insfilename + '_out', 'w',encoding="utf-8")
db = infopen.read()
outfopen.write(db.replace(';','\n'))
outfopen.close()
infopen.close()
f.close()
def read_one_line(line):
#print(line)
frags = line.split(',')
if len(frags) == 5:
_name = frags[0].split(':')[1]
_method_idx = int(frags[1].split(':')[1])
_offset = int(frags[2].split(':')[1])
_code_item_len = int(frags[3].split(':')[1])
_ins = frags[4].split(':')[1].replace("}\n", "")
return _name,_method_idx,_offset,_code_item_len,_ins
else:
return '',-1,-1,-1,''
#print(dex.base64_decode())
#data = json.loads(line,encoding = 'utf-8')
#print(data)
class dex_method:
name = ''
method_idx = 0
offset = 0
code_item_len = 0
ins_raw = ''
ins = b''
def __init__(self,_name,_method_idx,_offset,_code_item_len,_ins):
self.ins_raw = _ins
self.name,self.method_idx,self.offset,self.code_item_len,self.ins = _name,_method_idx,_offset,_code_item_len,base64.b64decode(_ins)
#print(_name,_method_idx,_offset,_code_item_len,self.ins_raw)
def repair_dex(self,fd):
if self.offset > 0:
fd.seek(self.offset, 0)
if len(self.ins) == self.code_item_len:
#print('reapir method = ',self.name,'repair code = ',self.ins_raw)
fd.write(self.ins)
def main():
init()
global filename
global insfilename
global method_name
global all_methods
delblankline()
dex_file = open(filename,'rb+')
#bin_file =
if all_methods:
with open(insfilename + '_out',encoding='utf-8') as f:
for line in f:
_name,_method_idx,_offset,_code_item_len,_ins = read_one_line(line)
method = dex_method(_name, _method_idx, _offset, _code_item_len, _ins)
method.repair_dex(dex_file)
else:
found = False
with open(insfilename + '_out',encoding='utf-8') as f:
for line in f:
_name,_method_idx,_offset,_code_item_len,_ins = read_one_line(line)
if method_name in _name:
found = True
method = dex_method(_name, _method_idx, _offset, _code_item_len, _ins)
print('find method = ' + method.name)
method.repair_dex(dex_file)
else:
pass
if found == False:
print('don\'t find method = ',method_name)
#break
if __name__ == '__main__':
main()
看雪ID:小白abc
https://bbs.pediy.com/user-715334.htm
推荐文章++++
好书推荐