读取.dex文件中的所有字符串
来源:互联网 发布:linux怎么无法退出vim 编辑:程序博客网 时间:2024/06/05 03:06
import structimport os#这里定义一个读取字符串长度的函数def DecUnsignedLEB128(file): result = struct.unpack("i", file.read(4))[0]#读取4字节中的第一个字节 result = result&0x000000ff file.seek(-3, 1) #倒退回前面的第三个字节 # 不能直接从1字节强转为4字节,所以先取4字节,再清空3字节 if (result > 0x7f): next = struct.unpack("i", file.read(4))[0] next = next&0x000000ff #第一位是个位 file.seek(-3, 1) result = (result&0x7f) | (next&0x7f)<<7 if(next > 0x7f): next = struct.unpack("i", file.read(4))[0] next = next&0x000000ff #加入十位 file.seek(-3, 1) result = result | (next&0x7f)<<14 if(next > 0x7f): next = struct.unpack("i", file.read(4))[0] next = next&0x000000ff file.seek(-3, 1) result = result | (next&0x7f)<<21 if(next > 0x7f): next = struct.unpack("i", file.read(4))[0] next = next&0x000000ff file.seek(-3, 1) result = result | next<<28 #print "result:", result return resultdex = open("imissTest.dex", 'rb') #rb的意思是 read and write in binary filedex.seek(0x38, 0)#string table的偏移tmp = dex.read(8)string_count, string_table_off = struct.unpack("II", tmp) #"II"是分别读取的意思print ("size:", string_count, " off:", string_table_off)dex.seek(string_table_off, 0)DexStrOffList = []count = 0while(count<string_count): DexStrOffList.append(struct.unpack("i", dex.read(4))[0])#unpack返回一个tuple 取第0个元素 count+=1DexStrList = []nonullcount = 0for stroff in DexStrOffList: dex.seek(stroff, 0) strlen = DecUnsignedLEB128(dex) if(strlen == 0): continue input = dex.read(strlen) DexStrList.append(struct.unpack(str(strlen)+"s", input)) #解析不定长的字符串 nonullcount+=1outputfile = open("string.txt", "w")count = 0print ("string:",string_count)for i in DexStrList: outputfile.write('%s\n'%i) #将元组中的元素写入文件outputfile.close()dex.close()
0 0
- 读取.dex文件中的所有字符串
- 读取文件中的所有数据
- 替换路径下所有文件中的字符串
- 读取文件中的文本并返回字符串
- PHP读取文件所有内容到字符串 file_get_contents
- java递归读取文件夹中的所有文件以及路径
- [QTP]通过vbscript读取一个文件中的所有内容
- 统计dex或jar文件中的方法
- 查找和替换目录中所有文件中的某个字符串
- 查找和替换目录中所有文件中的某个字符串
- day-11:读取项目中的所有pom.xml文件中所有的version标签
- java读取文件夹下所有文件并替换文件每一行中指定的字符串
- matlab一次读取多幅图片的方法////////////读取文件夹中的所有图片or文件
- C#读取Win32标准DLL文件中的字符串资源
- C#读取app.config文件中的连接字符串的方法
- 读取文件中的单个字符串(4种方法)
- 读取字符串中的数字
- 读取文件夹下所有文件
- 队列,广搜 nyoj 21 三个水杯
- 2015里程碑
- 一天一段scala代码(十五)
- debug
- week6--4月7日
- 读取.dex文件中的所有字符串
- android之java.lang.thread学习
- Android面试题目及其答案
- IOS 全局常量
- Leetcode: Binary Tree Right Side View
- QT中用socket接收图像数据(JPEG)后立即解码显示
- c++ Vector
- JAVA重载(overload)和覆盖(override)中你所不知道的陷阱
- 安卓开发经验分享:资源、UI、函数库、测试、构建一个都不能少