def check_for_valid_extension(self, unpacker): # TODO: this method will try to unpack multiple extensions # if they match. Is this the intention? for extension in bangsignatures.extensiontofunction: if bangsignatures.matches_file_pattern(self.fileresult.filename, extension): log( logging.INFO, "TRY extension match %s %s" % (self.fileresult.filename, extension)) unpackresult = unpacker.try_unpack_file_for_extension( self.fileresult, self.scanenvironment, self.fileresult.filename, extension) if unpackresult is None: continue if not unpackresult['status']: # No data could be unpacked for some reason log( logging.DEBUG, "FAIL %s known extension %s: %s" % (self.fileresult.filename, extension, unpackresult['error']['reason'])) # Fatal errors should lead to the program stopping # execution. Ignored for now. if unpackresult['error']['fatal']: pass unpacker.remove_data_unpack_directory_tree() continue # the file could be unpacked successfully, # so log it as such. log( logging.INFO, "SUCCESS %s %s at offset: 0, length: %d" % (self.fileresult.filename, extension, unpackresult['length'])) unpacker.file_unpacked(unpackresult, self.fileresult.filesize) # store any labels that were passed as a result and # add them to the current list of labels self.fileresult.labels.update(unpackresult['labels']) # store lot of information about the unpacked files report = { 'offset': 0, 'extension': extension, 'type': bangsignatures.extensionprettyprint[extension], 'size': unpackresult['length'], 'files': [], } for unpackedfile, unpackedlabel in unpackresult[ 'filesandlabels']: fr = FileResult(pathlib.Path(unpackedfile), self.fileresult.filename, self.fileresult.labels, set(unpackedlabel)) j = ScanJob(fr) self.scanenvironment.scanfilequeue.put(j) report['files'].append( unpackedfile[len(unpacker.get_data_unpack_directory() ) + 1:]) self.fileresult.add_unpackedfile(report)
def check_for_valid_extension(self, unpacker): # TODO: this method will try to unpack multiple extensions # if they match. Is this the intention? for extension, unpackparsers in \ self.scanenvironment.get_unpackparsers_for_extensions().items(): for unpackparser in unpackparsers: if bangsignatures.matches_file_pattern(self.fileresult.filename, extension): log(logging.INFO, "TRYING extension match %s %s" % (self.fileresult.filename, extension)) try: unpackresult = unpacker.try_unpack_file_for_extension( self.fileresult, self.scanenvironment, extension, unpackparser) except UnpackParserException as e: # No data could be unpacked for some reason log(logging.DEBUG, "FAIL %s known extension %s: %s" % (self.fileresult.filename, extension, e.args)) # Fatal errors should lead to the program stopping # execution. Ignored for now. # if unpackresult['error']['fatal']: # pass unpacker.remove_data_unpack_directory_tree() continue # the file could be unpacked successfully, # so log it as such. log(logging.INFO, "SUCCESS %s %s at offset: 0, length: %d" % (self.fileresult.filename, extension, unpackresult.get_length())) unpacker.file_unpacked(unpackresult, self.fileresult.filesize) # store any labels that were passed as a result and # add them to the current list of labels self.fileresult.labels.update(unpackresult.get_labels()) # store lot of information about the unpacked files report = { 'offset': 0, 'extension': extension, 'type': unpackparser.pretty_name, 'size': unpackresult.get_length(), 'files': [], 'relative_files': [], } if unpackresult.get_metadata != {}: self.fileresult.set_metadata(unpackresult.get_metadata()) for unpackedfile in unpackresult.get_unpacked_files(): j = ScanJob(unpackedfile) self.scanenvironment.scanfilequeue.put(j) report['files'].append(unpackedfile.filename) report['relative_files'].append(unpackedfile.filename.relative_to(unpacker.get_data_unpack_directory())) self.fileresult.add_unpackedfile(report)