def extract(self, task): target = fs.join(task.directory, task.name) basicstring = printer.format('extracter', printer.Color.CAN) extractstring = printer.format('extracting', printer.Color.YEL) print('[{0}] {1} {2}'.format(basicstring, extractstring, task.name)) if self.is_tar(task.url): ttar = tarfile.open(target, 'r') ttar.extractall(path=task.directory) elif self.is_zip(task.url): tzip = zipfile.ZipFile(target, 'r') tzip.extractall(task.directory) tzip.close() elif self.is_gzip(task.url): with gzip.open(target, 'rb') as f_in: with open(task.directory, 'wb') as f_out: fs.cp(f_in, f_out) else: return finishedstring = printer.format('extracted', printer.Color.GRN) print('[{0}] {1} {2}'.format(basicstring, finishedstring, task.name)) fs.rm(fs.join(task.directory, task.name)) dircontents = fs.ls(task.directory) if len(dircontents) == 1 and fs.isdir(task.directory, dircontents[0]): subdircontents = fs.ls(task.directory, dircontents[0]) for file in subdircontents: path = fs.join(task.directory, dircontents[0]) fs.mv(fs.join(path, file), task.directory) fs.rm(task.directory, dircontents[0], ignore_errors=True)
def download(self, task): basicstring = printer.format('downloader', printer.Color.CAN) downloadstring = printer.format('downloading', printer.Color.YEL) print('[{0}] {1} {2}'.format(basicstring, downloadstring, task.name)) u = urllib.request.urlopen(task.url) with open(fs.join(task.directory, task.name), 'wb') as out_file: out_file.write(u.read()) finishedstring = printer.format('downloaded', printer.Color.GRN) print('[{0}] {1} {2}'.format(basicstring, finishedstring, task.name))
def print_finish(comp, apk_name, warnings, success, timeout): color_comp = printer.format(comp, printer.Color.CAN) basicstring = '[{0}] Finished analysis of {1}'.format(color_comp, apk_name) if success: color_success = printer.format('with success', printer.Color.GRN) successstring = '{0} {1}'.format(basicstring, color_success) if warnings: print('{0} (and warnings)'.format(successstring)) else: print(successstring) elif timeout: color_timeout = printer.format('with timeout', printer.Color.PRP) print('{0} {1}'.format(basicstring, color_timeout)) else: color_error = printer.format('with errors', printer.Color.RED) print('{0} {1}'.format(basicstring, color_error))
def print_finish(comp, apk_name, is_malware, analysis_malware): color_comp = printer.format(comp, printer.Color.CAN) basicstring = '[{0}] Finished outcome-analysis of {1}'.format( color_comp, apk_name) if is_malware == analysis_malware: color_success = printer.format('with match', printer.Color.GRN) successstring = '{0} {1}'.format(basicstring, color_success) if analysis_malware: print('{0} (confirmed malware)'.format(successstring)) else: print('{0} (confirmed non-malware)'.format(successstring)) else: color_error = printer.format('with mismatch', printer.Color.RED) part1string = '{0} {1}'.format(basicstring, color_error) if is_malware: part2string = '(is malware but undetected)' else: part2string = '(is not malware but detected)' print('{0} {1}'.format(part1string, part2string))
def print_start(comp, apk_name): color_comp = printer.format(comp, printer.Color.CAN) print('[{0}] Starting outcome-analysis of {1}'.format( color_comp, apk_name))