Permalink
Browse files

Intermediate central backup

  • Loading branch information...
1 parent f6e852e commit 1ffd97ac38e89683d46156a56cf9fa7379da2981 @dbaeumges committed Feb 9, 2012
Showing with 1,178 additions and 23 deletions.
  1. +1 −1 apk_wrapper.py
  2. +929 −0 helper_analyzer.py
  3. +52 −0 helper_rename_apps.py
  4. +3 −3 report_generator.py
  5. +15 −5 taintdroid_runner.py
  6. +46 −10 taintlog_analyzer.py
  7. +132 −4 taintlog_json.py
View
@@ -483,7 +483,7 @@ def __finishMainLevel(self, theMainLevel, theMainObj):
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))
theSubObj = {}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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()
View
@@ -80,7 +80,7 @@ def generateAppReport(theFileName, theResultEntry):
else:
ReportGenerator.__generateReportLogTable(report,
'Call',
- ['DialString', 'Timestamp', 'StackTrace'],
+ ['Tag', 'DialString', 'Timestamp', 'StackTrace'],
log.getLogEntryList(theType=CallActionLogEntry)
)
ReportGenerator.__generateReportLogTable(report,
@@ -90,12 +90,12 @@ def generateAppReport(theFileName, theResultEntry):
)
ReportGenerator.__generateReportLogTable(report,
'FileSystem',
- ['Tag', 'Action', 'File', 'Data', 'Timestamp', 'StackTrace'],
+ ['Tag', 'Action', 'File', 'Id', 'Data', 'Timestamp', 'StackTrace'],
log.getLogEntryList(theType=FileSystemLogEntry)
)
ReportGenerator.__generateReportLogTable(report,
'Network',
- ['Tag', 'Action', 'Destination', 'Data', 'Timestamp', 'StackTrace'],
+ ['Tag', 'Action', 'Destination', 'Id', 'Data', 'Timestamp', 'StackTrace'],
log.getLogEntryList(theType=NetworkSendLogEntry)
)
ReportGenerator.__generateReportLogTable(report,
View
@@ -209,9 +209,9 @@ def _cleanUpImageDir(self, theImageDirPath):
except OSError, 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 not os.path.exists(theLogcatDirPath):
@@ -227,6 +227,13 @@ def _storeLogcatAsFile(self, theLogcatDirPath, theSampleId, theFileName, theLog)
else:
break
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.write(theLog)
@@ -355,12 +362,15 @@ def runApp(self, theEmulator, theApp, theSteps):
# Store log in logfile
#log = theEmulator.getLog()
theEmulator.stopLogcatRedirect()
- log = theEmulator.getLogcatRedirectFile(logcatRedirectFile)
- self._storeLogcatAsFile(self.tdRunnerMain._getLogDirPath(), theApp.getId(), theApp.getApkName(), log)
+ #log = theEmulator.getLogcatRedirectFile(logcatRedirectFile)
+ #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
logAnalyzer = TaintLogAnalyzer(theLogger=self.log)
- logAnalyzer.setLogString(log)
+ #logAnalyzer.setLogString(log)
+ logAnalyzer.setLogFile(logcatFileName)
logAnalyzer.extractLogEntries()
logAnalyzer.postProcessLogObjects()
self.result['errorList'].extend(logAnalyzer.getJson2PyFailedErrorList())
View
@@ -188,10 +188,6 @@ def postProcessLogObjects(self, theDeleteStaleObjectsFlag=True):
isinstance(logEntry, SendSmsLogEntry):
stackTrace = logEntry.stackTraceStr.split('||')
logEntry.stackTrace = stackTrace[:len(stackTrace)-1]
-
- # Filter log entry?
- if self.__removeLogObjectByFilter(logEntry):
- filteredLogEntryList.append(logEntryIndex)
# Cipher cleaning (combine inputs and outputs)
if isinstance(logEntry, CipherUsageLogEntry):
@@ -246,23 +242,63 @@ def postProcessLogObjects(self, theDeleteStaleObjectsFlag=True):
delLogEntryIdxList.extend(logEntry[1])
# Do drop
- delLogEntryIdxList.sort()
- for i in xrange(len(delLogEntryIdxList)):
- del self.logEntryList[delLogEntryIdxList[i] - i]
+ self.__deleteStaleLogObjects(delLogEntryIdxList)
# Add cleaned cipher usage objects
for id, logEntry in cipherUsageDict.iteritems():
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.
"""
- 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):
"""
Print overview.
Oops, something went wrong.

0 comments on commit 1ffd97a

Please sign in to comment.