在做Android逆向的时候,dex文件转成smail文件之后,需要查找哪个smail文件中包含的关键字。下面这段代码:
findCount为查找到的文件个数
findId为要查找的内容
findDir为要查找的文件夹
#encoding: utf-8
import os
findCount = 0
findId = "QString"
findDir = "F:\\calc"
resultFile = os.path.join(findDir,"result.txt")
def writeResultAndPrint(fullPath):
print (fullPath)
file = open(resultFile,'a')
file.write(fullPath)
file.write("\n")
file.close()
def findKey(fullPath):
file = open(fullPath,'r')
content = file.read()
file.close()
isExist = content.find(findId)
if isExist > 0:
global findCount
findCount = findCount + 1
writeResultAndPrint(fullPath)
def findFiles():
for dirPath,dirNames,fileNames in os.walk(findDir):
for file in fileNames:
fullPath = os.path.join(dirPath,file)
findKey(fullPath)
print("找到了字符串个数=" + str(findCount))
def clean():
if os.path.exists(resultFile):
os.remove(resultFile)
clean()
findFiles()