Skip to content

Commit

Permalink
Intermediate central backup
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumges committed Feb 9, 2012
1 parent f6e852e commit 1ffd97a
Show file tree
Hide file tree
Showing 7 changed files with 1,178 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apk_wrapper.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def __finishMainLevel(self, theMainLevel, theMainObj):
theMainObj = {} theMainObj = {}


def __finishSubLevel(self, theSubLevel, theSubObj, theMainObj): def __finishSubLevel(self, theSubLevel, theSubObj, theMainObj):
if theSubLevel == self.Level.INTENT_FILTER: if theSubLevel == self.Level.INTENT_FILTER and theMainObj.has_key('intentFilterList'):
theMainObj['intentFilterList'].append(copy.deepcopy(theSubObj)) theMainObj['intentFilterList'].append(copy.deepcopy(theSubObj))
theSubObj = {} theSubObj = {}


Expand Down
929 changes: 929 additions & 0 deletions helper_analyzer.py

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions helper_rename_apps.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,52 @@
from apk_wrapper import APKWrapper, APKWrapperError
from common import Utils
from optparse import OptionParser

import helper_analyzer

import os
import shutil

def renameApp(theApp, theSdkPath):
apk = APKWrapper(theApp, theSdkPath)

newName = '%s/%s-%s.apk' % (apk.getApkPath(), apk.getPackage(), apk.getMd5Hash())
print '- Rename from %s to %s' % (theApp, newName)
shutil.move(theApp, newName)

def main():
# Get directory
parser = OptionParser(usage='usage: %prog [options] dir targetDir')
parser.add_option('-m', '--mode', metavar='#', default=0)
parser.add_option('', '--sdkPath', metavar='<path>', default='', help='Set path to Android SDK')
(options, args) = parser.parse_args()

if len(args) < 1:
raise ValueError('Provide a directory')
aDir = args[0]
targetDir = None
if len(args) > 1:
targetDir = args[1]

# Get app names
if int(options.mode) == 0:
appNameList = Utils._getAppListInDirectory(aDir)
print 'Get APK Wrapper of %d apps' % len(appNameList)
for appName in appNameList:
renameApp(appName, options.sdkPath)

# Goodware
if int(options.mode) == 1:
if targetDir is None:
raise ValueError('Provide a target directory')
analyzer = helper_analyzer.Analyzer([aDir], theSdkPath=options.sdkPath)
analyzer.baseAppDir = '/home/daniel/Documents/MarketApps/apps'
appList = analyzer.generateList()
for app in appList:
oldName = os.path.join('/home/daniel/Documents/MarketApps/apps', app[1].getApkFileName())
newName = os.path.join(targetDir, app[0])
print '- Copy app form %s to %s' % (oldName, newName)
shutil.copy2(oldName, newName)

if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions report_generator.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def generateAppReport(theFileName, theResultEntry):
else: else:
ReportGenerator.__generateReportLogTable(report, ReportGenerator.__generateReportLogTable(report,
'Call', 'Call',
['DialString', 'Timestamp', 'StackTrace'], ['Tag', 'DialString', 'Timestamp', 'StackTrace'],
log.getLogEntryList(theType=CallActionLogEntry) log.getLogEntryList(theType=CallActionLogEntry)
) )
ReportGenerator.__generateReportLogTable(report, ReportGenerator.__generateReportLogTable(report,
Expand All @@ -90,12 +90,12 @@ def generateAppReport(theFileName, theResultEntry):
) )
ReportGenerator.__generateReportLogTable(report, ReportGenerator.__generateReportLogTable(report,
'FileSystem', 'FileSystem',
['Tag', 'Action', 'File', 'Data', 'Timestamp', 'StackTrace'], ['Tag', 'Action', 'File', 'Id', 'Data', 'Timestamp', 'StackTrace'],
log.getLogEntryList(theType=FileSystemLogEntry) log.getLogEntryList(theType=FileSystemLogEntry)
) )
ReportGenerator.__generateReportLogTable(report, ReportGenerator.__generateReportLogTable(report,
'Network', 'Network',
['Tag', 'Action', 'Destination', 'Data', 'Timestamp', 'StackTrace'], ['Tag', 'Action', 'Destination', 'Id', 'Data', 'Timestamp', 'StackTrace'],
log.getLogEntryList(theType=NetworkSendLogEntry) log.getLogEntryList(theType=NetworkSendLogEntry)
) )
ReportGenerator.__generateReportLogTable(report, ReportGenerator.__generateReportLogTable(report,
Expand Down
20 changes: 15 additions & 5 deletions taintdroid_runner.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def _cleanUpImageDir(self, theImageDirPath):
except OSError, ose: except OSError, ose:
self.log.error('Error during cleaning up image dir \'%s\': %s' % (theImageDirPath, ose)) self.log.error('Error during cleaning up image dir \'%s\': %s' % (theImageDirPath, ose))


def _storeLogcatAsFile(self, theLogcatDirPath, theSampleId, theFileName, theLog): def _getLogcatFileName(self, theLogcatDirPath, theSampleId, theFileName):
""" """
Store logcat in file. Generates logcat file name
""" """
if theLogcatDirPath != '': if theLogcatDirPath != '':
if not os.path.exists(theLogcatDirPath): if not os.path.exists(theLogcatDirPath):
Expand All @@ -227,6 +227,13 @@ def _storeLogcatAsFile(self, theLogcatDirPath, theSampleId, theFileName, theLog)
else: else:
break break
self.log.debug('Store logcat in %s' % logcatFileName) self.log.debug('Store logcat in %s' % logcatFileName)
return logcatFileName

def _storeLogcatAsFile(self, theLogcatDirPath, theSampleId, theFileName, theLog):
"""
Store logcat in file.
"""
logcatFileName = self._getLogcatFileName(theLogcatDirPath, theSampleId, theFileName)
logFile = open(logcatFileName, "w") logFile = open(logcatFileName, "w")
logFile.write(theLog) logFile.write(theLog)


Expand Down Expand Up @@ -355,12 +362,15 @@ def runApp(self, theEmulator, theApp, theSteps):
# Store log in logfile # Store log in logfile
#log = theEmulator.getLog() #log = theEmulator.getLog()
theEmulator.stopLogcatRedirect() theEmulator.stopLogcatRedirect()
log = theEmulator.getLogcatRedirectFile(logcatRedirectFile) #log = theEmulator.getLogcatRedirectFile(logcatRedirectFile)
self._storeLogcatAsFile(self.tdRunnerMain._getLogDirPath(), theApp.getId(), theApp.getApkName(), log) #self._storeLogcatAsFile(self.tdRunnerMain._getLogDirPath(), theApp.getId(), theApp.getApkName(), log)
logcatFileName = self._getLogcatFileName(self.tdRunnerMain._getLogDirPath(), theApp.getId(), theApp.getApkName())
theEmulator.storeLogcatRedirectFile(logcatRedirectFile, logcatFileName)


# Build LogAnalyzer # Build LogAnalyzer
logAnalyzer = TaintLogAnalyzer(theLogger=self.log) logAnalyzer = TaintLogAnalyzer(theLogger=self.log)
logAnalyzer.setLogString(log) #logAnalyzer.setLogString(log)
logAnalyzer.setLogFile(logcatFileName)
logAnalyzer.extractLogEntries() logAnalyzer.extractLogEntries()
logAnalyzer.postProcessLogObjects() logAnalyzer.postProcessLogObjects()
self.result['errorList'].extend(logAnalyzer.getJson2PyFailedErrorList()) self.result['errorList'].extend(logAnalyzer.getJson2PyFailedErrorList())
Expand Down
56 changes: 46 additions & 10 deletions taintlog_analyzer.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ def postProcessLogObjects(self, theDeleteStaleObjectsFlag=True):
isinstance(logEntry, SendSmsLogEntry): isinstance(logEntry, SendSmsLogEntry):
stackTrace = logEntry.stackTraceStr.split('||') stackTrace = logEntry.stackTraceStr.split('||')
logEntry.stackTrace = stackTrace[:len(stackTrace)-1] logEntry.stackTrace = stackTrace[:len(stackTrace)-1]

# Filter log entry?
if self.__removeLogObjectByFilter(logEntry):
filteredLogEntryList.append(logEntryIndex)


# Cipher cleaning (combine inputs and outputs) # Cipher cleaning (combine inputs and outputs)
if isinstance(logEntry, CipherUsageLogEntry): if isinstance(logEntry, CipherUsageLogEntry):
Expand Down Expand Up @@ -246,23 +242,63 @@ def postProcessLogObjects(self, theDeleteStaleObjectsFlag=True):
delLogEntryIdxList.extend(logEntry[1]) delLogEntryIdxList.extend(logEntry[1])


# Do drop # Do drop
delLogEntryIdxList.sort() self.__deleteStaleLogObjects(delLogEntryIdxList)
for i in xrange(len(delLogEntryIdxList)):
del self.logEntryList[delLogEntryIdxList[i] - i]




# Add cleaned cipher usage objects # Add cleaned cipher usage objects
for id, logEntry in cipherUsageDict.iteritems(): for id, logEntry in cipherUsageDict.iteritems():
self.logEntryList.append(logEntry[0]) self.logEntryList.append(logEntry[0])


def __deleteStaleLogObjects(self, theDelLogEntryIdxList):
"""
Delete all log entries whose indices are included in the provided
delete log entry index list.
"""
theDelLogEntryIdxList.sort()
for i in xrange(len(theDelLogEntryIdxList)):
del self.logEntryList[theDelLogEntryIdxList[i] - i]



def __removeLogObjectByFilter(self, theLogObject): def filterLogObjects(self, theFilterList):
"""
Remove entries which match to one of the provided patterns.
"""
delLogEntryIdxList = []
logEntryIndex = 0
for logEntry in self.logEntryList:
if self.__matches(logEntry, theFilterList):
delLogEntryIdxList.append(logEntryIndex)
logEntryIndex += 1
self.__deleteStaleLogObjects(delLogEntryIdxList)

def __matches(self, theLogObject, thePatternList):
""" """
Returns if log object should be filtered. Returns if log object should be filtered.
""" """
return False for pattern in thePatternList:

if theLogObject.doesMatch(pattern):
return True

def getMatchingLogEntries(self, thePatternList):
"""
Returns a list of log entries matching with one of the provided patterns
"""
logEntryList = []
for logEntry in self.logEntryList:
if self.__matches(logEntry, thePatternList):
logEntryList.append(logEntry)
return logEntryList


def doesMatch(self, thePatternList):
"""
Returns if there are any log entries matching to one of the provided
patterns.
"""
for logEntry in self.logEntryList:
if self.__matches(logEntry, thePatternList):
return True
return False

def printOverview(self): def printOverview(self):
""" """
Print overview. Print overview.
Expand Down
Loading

0 comments on commit 1ffd97a

Please sign in to comment.