def _fixLastField(self):
        """
        Try to fix last field when we know current field set size.
        Returns new added field if any, or None.
        """
        assert self._size is not None

        # Stop parser
        message = ["stop parser"]
        self._field_generator = None

        # If last field is too big, delete it
        while self._size < self._current_size:
            field = self._deleteField(len(self._fields) - 1)
            message.append("delete field %s" % field.path)
        assert self._current_size <= self._size

        blocks = [(x.absolute_address, x.size) for x in self._fields]
        fields = []
        for start, length in getgaps(self.absolute_address, self._size, blocks):
            self.seekBit(start, relative=False)
            field = createRawField(self, length, "unparsed[]")
            self.setUniqueFieldName(field)
            self._fields.append(field.name, field)
            fields.append(field)
            message.append("found unparsed segment: start %s, length %s" % (start, length))

        self.seekBit(self._size, relative=False)
        message = ", ".join(message)
        if fields:
            self.warning("[Autofix] Fix parser error: " + message)
        return fields
Esempio n. 2
0
    def _fixLastField(self):
        """
        Try to fix last field when we know current field set size.
        Returns new added field if any, or None.
        """
        assert self._size is not None

        # Stop parser
        message = ["stop parser"]
        self._field_generator = None

        # If last field is too big, delete it
        while self._size < self._current_size:
            field = self._deleteField(len(self._fields) - 1)
            message.append("delete field %s" % field.path)
        assert self._current_size <= self._size

        blocks = [(x.absolute_address, x.size) for x in self._fields]
        fields = []
        for start, length in getgaps(self.absolute_address, self._size,
                                     blocks):
            self.seekBit(start, relative=False)
            field = createRawField(self, length, "unparsed[]")
            self.setUniqueFieldName(field)
            self._fields.append(field.name, field)
            fields.append(field)
            message.append("found unparsed segment: start %s, length %s" %
                           (start, length))

        self.seekBit(self._size, relative=False)
        message = ", ".join(message)
        if fields:
            self.warning("[Autofix] Fix parser error: " + message)
        return fields
Esempio n. 3
0
    def _fixLastField(self):
        """
        Try to fix last field when we know current field set size.
        Returns new added field if any, or None.
        """
        assert self._size is not None

        # Stop parser
        message = ["stop parser"]
        self._field_generator = None

        # If last field is too big, delete it
        while self._size < self._current_size:
            field = self._deleteField(len(self._fields) - 1)
            message.append("delete field %s" % field.path)
        assert self._current_size <= self._size

        # If field size current is smaller: add a raw field
        size = self._size - self._current_size
        if size:
            field = createRawField(self, size, "raw[]")
            message.append("add padding")
            self._current_size += field.size
            self._fields.append(field._name, field)
        else:
            field = None
        message = ", ".join(message)
        self.warning("[Autofix] Fix parser error: " + message)
        assert self._current_size == self._size
        return field
Esempio n. 4
0
    def _fixLastField(self):
        """
        Try to fix last field when we know current field set size.
        Returns new added field if any, or None.
        """
        assert self._size is not None

        # Stop parser
        message = ["stop parser"]
        self._field_generator = None

        # If last field is too big, delete it
        while self._size < self._current_size:
            field = self._deleteField(len(self._fields)-1)
            message.append("delete field %s" % field.path)
        assert self._current_size <= self._size

        # If field size current is smaller: add a raw field
        size = self._size - self._current_size
        if size:
            field = createRawField(self, size, "raw[]")
            message.append("add padding")
            self._current_size += field.size
            self._fields.append(field._name, field)
        else:
            field = None
        message = ", ".join(message)
        self.warning("[Autofix] Fix parser error: " + message)
        assert self._current_size == self._size
        return field
Esempio n. 5
0
 def _truncate(self, size):
     assert size > 0
     if size < self._current_size:
         self._size = size
         while True:
             field = self._fields.values[-1]
             if field._address < size:
                 break
             del self._fields[-1]
         self._current_size = field._address
         size -= field._address
         if size < field._size:
             if field.is_field_set:
                 field._truncate(size)
             else:
                 del self._fields[-1]
                 field = createRawField(self, size, "raw[]")
                 self._fields.append(field._name, field)
         self._current_size = self._size
     else:
         assert size < self._size or self._size is None
         self._size = size
     if self._size == self._current_size:
         self._field_generator = None
Esempio n. 6
0
 def _truncate(self, size):
     assert size > 0
     if size < self._current_size:
         self._size = size
         while True:
             field = self._fields.values[-1]
             if field._address < size:
                 break
             del self._fields[-1]
         self._current_size = field._address
         size -= field._address
         if size < field._size:
             if field.is_field_set:
                 field._truncate(size)
             else:
                 del self._fields[-1]
                 field = createRawField(self, size, "raw[]")
                 self._fields.append(field._name, field)
         self._current_size = self._size
     else:
         assert size < self._size or self._size is None
         self._size = size
     if self._size == self._current_size:
         self._field_generator = None