def _convert_to_firmware(self, entry, analysis_filter=None):
        firmware = Firmware()
        firmware.uid = entry['_id']
        firmware.size = entry['size']
        firmware.set_name(entry['file_name'])
        firmware.set_device_name(entry['device_name'])
        firmware.set_device_class(entry['device_class'])
        firmware.set_release_date(convert_time_to_str(entry['release_date']))
        firmware.set_vendor(entry['vendor'])
        firmware.set_firmware_version(entry['version'])
        firmware.processed_analysis = self.retrieve_analysis(
            entry['processed_analysis'], analysis_filter=analysis_filter)
        firmware.files_included = set(entry['files_included'])
        firmware.virtual_file_path = entry['virtual_file_path']
        firmware.tags = entry['tags'] if 'tags' in entry else dict()
        firmware.analysis_tags = entry[
            'analysis_tags'] if 'analysis_tags' in entry else dict()

        try:  # for backwards compatibility
            firmware.set_part_name(entry['device_part'])
        except KeyError:
            firmware.set_part_name('complete')

        if 'comments' in entry:  # for backwards compatibility
            firmware.comments = entry['comments']
        return firmware
Exemple #2
0
 def test_add_firmware_to_current_analyses(self):
     self.scheduler.currently_running = {}
     fw = Firmware(binary=b'foo')
     fw.files_included = ['foo', 'bar']
     self.scheduler._add_to_current_analyses(fw)
     assert fw.uid in self.scheduler.currently_running
     assert self.scheduler.currently_running[fw.uid]['file_list'] == ['foo', 'bar']
     assert self.scheduler.currently_running[fw.uid]['analyzed_files_count'] == 0
     assert self.scheduler.currently_running[fw.uid]['total_files_count'] == 2
Exemple #3
0
 def test_add_firmware_to_current_analyses(self):
     self.status.currently_running = {}
     fw = Firmware(binary=b'foo')
     fw.files_included = ['foo', 'bar']
     self.status.add_to_current_analyses(fw)
     assert fw.uid in self.status.currently_running
     result = self.status.currently_running[fw.uid]
     assert result['files_to_unpack'] == ['foo', 'bar']
     assert result['files_to_analyze'] == [fw.uid]
     assert result['unpacked_files_count'] == 1
     assert result['analyzed_files_count'] == 0
     assert result['total_files_count'] == 3
 def _convert_to_firmware(self, entry, analysis_filter=None):
     firmware = Firmware()
     firmware.uid = entry['_id']
     firmware.size = entry['size']
     firmware.set_name(entry['file_name'])
     firmware.set_device_name(entry['device_name'])
     firmware.set_device_class(entry['device_class'])
     firmware.set_release_date(convert_time_to_str(entry['release_date']))
     firmware.set_vendor(entry['vendor'])
     firmware.set_firmware_version(entry['version'])
     firmware.processed_analysis = self.retrieve_analysis(entry['processed_analysis'], analysis_filter=analysis_filter)
     firmware.files_included = set(entry['files_included'])
     firmware.virtual_file_path = entry['virtual_file_path']
     if "comments" in entry:  # for backwards compatibility
         firmware.comments = entry["comments"]
     return firmware
Exemple #5
0
    def _convert_to_firmware(self, entry: dict, analysis_filter: List[str] = None) -> Firmware:
        firmware = Firmware()
        firmware.uid = entry['_id']
        firmware.size = entry['size']
        firmware.file_name = entry['file_name']
        firmware.device_name = entry['device_name']
        firmware.device_class = entry['device_class']
        firmware.release_date = convert_time_to_str(entry['release_date'])
        firmware.vendor = entry['vendor']
        firmware.version = entry['version']
        firmware.processed_analysis = self.retrieve_analysis(entry['processed_analysis'], analysis_filter=analysis_filter)
        firmware.files_included = set(entry['files_included'])
        firmware.virtual_file_path = entry['virtual_file_path']
        firmware.tags = entry['tags'] if 'tags' in entry else dict()
        firmware.analysis_tags = self._collect_analysis_tags_from_children(firmware.uid)

        try:  # for backwards compatibility
            firmware.set_part_name(entry['device_part'])
        except KeyError:
            firmware.set_part_name('complete')

        if 'comments' in entry:  # for backwards compatibility
            firmware.comments = entry['comments']
        return firmware
 def test_add_firmware_to_current_analyses(self):
     self.scheduler.currently_running = {}
     fw = Firmware(binary=b'foo')
     fw.files_included = ['foo', 'bar']
     self.scheduler._add_to_current_analyses(fw)
     assert self.scheduler.currently_running == {fw.uid: ['foo', 'bar']}