def validate(self, operation, odb_file): """" Validate the type fits at the given address. """ vma = operation.vma # determine the size of this defined data size = operation.size # Verify there is not something already defined here for dd in odb_file.get_structure_list(DefinedData): if dd.overlaps(vma, size): raise DefineDataCollisionException( 'Data collides with existing data %s' % dd.var_name) # Verify there is enough room in the parcel parcels = ParcelList(odb_file.get_structure_list(Parcel)) parcel = parcels.find_parcel_by_vma(vma) if not parcel: raise ValidationError('Cannot define data at bad address 0x%x' % vma) elif parcel.is_code: raise ValidationError('Cannot define data in code region') if not parcel.contains_vma(vma + size - 1): raise ValidationError('Not enough room to define data')
def validate(self, operation, odb_file): type_kind = operation.type_kind type_name = operation.type_name supported_type_names = [] if type_kind == CStruct.kind: supported_type_names =\ [t.name for t in odb_file.get_structure_list(CStruct)] elif type_kind == BuiltinType.kind: supported_type_names = BuiltinTypeNames() else: raise ValidationError('Invalid type kind %s' % type_kind) if type_name not in supported_type_names: raise ValidationError('Invalid type name %s' % type_name)
def execute(self, operation): operation.validate(self) result = operation.operate(self) dup_op = next( (op for op in self.operations if op.object_id == operation.object_id), None) if dup_op: raise ValidationError('Duplicate Operation') self.operations.append(operation) return result
def validate(self, operation, odb_file): # TODO: Validate against parcel ranges vma = operation.vma if vma < 0: # or greater than max? raise ValidationError("VMA not valid on item")
def validate(self, operation, odb_file): for (field_type, field_name) in zip(operation.field_types, operation.field_names): field = instantiate_field(odb_file, field_type, field_name) if not field: raise ValidationError("Field is not a valid type")
def validate(self, operation, odb_file): for t in odb_file.get_structure_list(DefinedData): if t.var_name == operation.var_name: raise ValidationError('Cannot define duplicate name %s' % operation.var_name)
def validate(self, operation, odb_file): v = next((f for f in odb_file.get_structure_list(Function) if f.vma == operation.vma), None) if v is not None: raise ValidationError('Function already exists at address 0x%x' % operation.vma)
def validate(self, operation, odb_file): v = next((f for f in odb_file.get_structure_list(Function) if f.name == operation.name), None) if v is not None: raise ValidationError('Cannot Use Duplicate Function Name')