def seekBit(self, address, name="padding[]", description=None, relative=True, null=False): """ Create a field to seek to specified address, or None if it's not needed. May raise an (ParserError) exception if address is invalid. """ if relative: nbits = address - self._current_size else: nbits = address - (self.absolute_address + self._current_size) if nbits < 0: raise ParserError("Seek error, unable to go back!") if 0 < nbits: if null: return createNullField(self, nbits, name, description) else: return createPaddingField(self, nbits, name, description) else: return None
def seek(self, offset): """ Seek to byte address relative to parent address. """ padding = offset - (self.address + self.current_size)/8 if 0 < padding: return createPaddingField(self, padding*8) else: return None
def seek(self, offset): """ Seek to byte address relative to parent address. """ padding = offset - (self.address + self.current_size) / 8 if 0 < padding: return createPaddingField(self, padding * 8) else: return None
def writeFieldsIn(self, old_field, address, new_fields): """ Can only write in existing fields (address < self._current_size) """ # Check size total_size = sum(field.size for field in new_fields) if old_field.size < total_size: raise ParserError( \ "Unable to write fields at address %s " \ "(too big)!" % (address)) # Need padding before? replace = [] size = address - old_field.address assert 0 <= size if 0 < size: padding = createPaddingField(self, size) padding._address = old_field.address replace.append(padding) # Set fields address for field in new_fields: field._address = address address += field.size replace.append(field) # Need padding after? size = (old_field.address + old_field.size) - address assert 0 <= size if 0 < size: padding = createPaddingField(self, size) padding._address = address replace.append(padding) self.replaceField(old_field.name, replace)
def writeFieldsIn(self, old_field, address, new_fields): """ Can only write in existing fields (address < self._current_size) """ # Check size total_size = sum( field.size for field in new_fields ) if old_field.size < total_size: raise ParserError( \ "Unable to write fields at address %s " \ "(too big)!" % (address)) # Need padding before? replace = [] size = address - old_field.address assert 0 <= size if 0 < size: padding = createPaddingField(self, size) padding._address = old_field.address replace.append(padding) # Set fields address for field in new_fields: field._address = address address += field.size replace.append(field) # Need padding after? size = (old_field.address + old_field.size) - address assert 0 <= size if 0 < size: padding = createPaddingField(self, size) padding._address = address replace.append(padding) self.replaceField(old_field.name, replace)
def createFields(self): for x in xrange(self._width): yield self._pixel(self, "pixel[]") size = self.size - self.current_size if size: yield createPaddingField(self, size)
def createFields(self): yield Bytes(self, "data", self.datasize / 8) padding = self._size - self.current_size if padding: yield createPaddingField(self, padding)
def createFields(self): yield Bytes(self, "data", self.datasize/8) padding = self._size - self.current_size if padding: yield createPaddingField(self, padding)