检测app使用了多少个xib和js的脚本(python)
by 伍雪颖
#!/usr/bin/env python
# coding=utf-8
import
os, sys
def
countTargetFile(targetDir):
resultStr =
‘‘
targetTypes = [‘.nib‘,
‘.m‘,
‘.js‘]
for targetType
in targetTypes:
targetCount =
0
for root, dirs, files
in
os.walk(targetDir):
for file
in files:
if file.endswith(targetType):
print os.path.join(root, file)
targetCount +=
1
oneResult =
‘type = ‘ + targetType +
‘, target count = ‘
+ str(targetCount)
print oneResult
resultStr += oneResult +
‘\n‘
return resultStr
def
deal(baseDir, filename):
print
‘process file:‘ + baseDir + filename
tmpDir = os.getcwd() +
‘/unzip_folders/‘ + filename.replace(‘ ‘,
‘_‘)
print tmpDir
try:
os.mkdir(tmpDir)
zipFile = tmpDir +
‘/‘ +
‘tmp.zip‘
command =
‘cp ‘ + baseDir + filename.replace(‘ ‘,
‘\ ‘) +
‘ ‘
+ zipFile
os.system(command)
command =
‘unzip ‘ + zipFile +
‘ -d ‘
+ tmpDir
print command
os.system(command)
except OSError:
print
‘file exist, ignore‘
resultStr = countTargetFile(tmpDir +
‘/Payload‘)
file = open(tmpDir.replace(‘.ipa‘,‘‘)
+
‘_result.txt‘,
‘w‘)
file.write(filename +
‘:\n‘)
file.write(resultStr)
file.write(‘\n‘)
file.close()
def
process():
baseDir = os.getcwd()
targetFiles = os.listdir(‘./ipa_folders‘)
print targetFiles
for oneFile
in targetFiles:
if oneFile.endswith(‘.ipa‘):
deal(baseDir +
‘/ipa_folders/‘, oneFile)
if
__name__ ==
‘__main__‘:
process()
print
‘over‘
版权声明:本文为博主原创文章,未经博主允许不得转载。