def update_object(self, new_object=None, old_object=None): update_dictionary = { 'processed_analysis': self._update_processed_analysis(new_object, old_object), 'files_included': update_included_files(new_object, old_object), 'virtual_file_path': update_virtual_file_path(new_object, old_object), 'analysis_tags': update_analysis_tags(new_object, old_object), } if type(new_object) == Firmware: update_dictionary.update({ 'version': new_object.version, 'device_name': new_object.device_name, 'device_class': new_object.device_class, 'vendor': new_object.vendor, 'release_date': convert_str_to_time(new_object.release_date), 'tags': new_object.tags, }) collection = self.firmwares else: update_dictionary.update({ 'parent_firmware_uids': list(set.union(set(old_object['parent_firmware_uids']), new_object.parent_firmware_uids)) }) collection = self.file_objects collection.update_one({'_id': new_object.get_uid()}, {'$set': update_dictionary})
def build_firmware_dict(self, firmware): analysis = self.sanitize_analysis( analysis_dict=firmware.processed_analysis, uid=firmware.get_uid()) entry = { '_id': firmware.get_uid(), 'file_path': firmware.file_path, 'file_name': firmware.file_name, 'device_part': firmware.part, 'virtual_file_path': firmware.virtual_file_path, 'version': firmware.version, 'md5': firmware.md5, 'sha256': firmware.sha256, 'processed_analysis': analysis, 'files_included': list(firmware.files_included), 'device_name': firmware.device_name, 'size': firmware.size, 'device_class': firmware.device_class, 'vendor': firmware.vendor, 'release_date': convert_str_to_time(firmware.release_date), 'submission_date': time(), 'analysis_tags': firmware.analysis_tags, 'tags': firmware.tags } if hasattr(firmware, 'comments'): # for backwards compatibility entry['comments'] = firmware.comments return entry
def convert_release_dates_to_date_object_format(db_service): query = db_service.firmwares.find({}, {"_id": 1, "release_date": 1}) for entry in query: firmware_id = entry["_id"] date = entry["release_date"] if type(date) == str: logging.debug("converting date of {}".format(firmware_id)) try: updated_entry = convert_str_to_time(date) db_service.update_object_field(uid=firmware_id, field="release_date", value=updated_entry) except Exception as e: logging.error("could not convert release date entry: {} {}".format(sys.exc_info()[0].__name__, e))
def update_object(self, new_object=None, old_object=None): old_pa = self.retrieve_analysis(old_object['processed_analysis']) new_pa = new_object.processed_analysis for key in new_pa.keys(): old_pa[key] = new_pa[key] old_pa = self.sanitize_analysis(analysis_dict=old_pa, uid=new_object.get_uid()) old_vfp = old_object['virtual_file_path'] new_vfp = new_object.virtual_file_path for key in new_vfp.keys(): old_vfp[key] = new_vfp[key] old_fi = old_object['files_included'] new_fi = new_object.files_included old_fi.extend(new_fi) old_fi = list(set(old_fi)) if type(new_object) == Firmware: try: self.firmwares.update_one({'_id': new_object.get_uid()}, { '$set': {'processed_analysis': old_pa, 'files_included': old_fi, 'virtual_file_path': old_vfp, 'version': new_object.version, 'device_name': new_object.device_name, 'device_class': new_object.device_class, 'vendor': new_object.vendor, 'release_date': convert_str_to_time(new_object.release_date), 'comments': new_object.comments}}) except Exception as e: logging.error('Could not update firmware: {} - {}'.format(sys.exc_info()[0].__name__, e)) else: parent_firmware_uids = set.union(set(old_object['parent_firmware_uids']), new_object.parent_firmware_uids) try: self.file_objects.update_one({'_id': new_object.get_uid()}, { '$set': {'processed_analysis': old_pa, 'files_included': old_fi, 'virtual_file_path': old_vfp, 'comments': new_object.comments, 'parent_firmware_uids': list(parent_firmware_uids)}}) except Exception as e: logging.error('Could not update file: {} - {}'.format(sys.exc_info()[0].__name__, e))