コード例 #1
0
    def unpack(self, buf, offset):
        """Unpack an element header from an FFFF header buffer

        Unpacks an element header from an FFFF header buffer at the specified
        offset.  Returns a flag indicating if the unpacked element is an
        end-of-table marker
        """
        element_hdr = unpack_from("<LLLLL", buf, offset)
        type_class = element_hdr[0]
        self.element_type = type_class & 0x000000ff
        self.element_class = (type_class >> 8) & 0x00ffffff
        self.element_id = element_hdr[1]
        self.element_length = element_hdr[2]
        self.element_location = element_hdr[3]
        self.element_generation = element_hdr[4]

        # Get the element data into our tftf_blob
        if self.element_type != FFFF_ELEMENT_END_OF_ELEMENT_TABLE:
            # Create a TFTF blob and load the contents from the specified
            # TFTF file
            span_start = self.element_location
            span_end = span_start + self.element_length
            self.tftf_blob = Tftf(0, None)
            span_start = self.element_location
            span_end = span_start + self.element_length
            self.tftf_blob.load_tftf_from_buffer(buf[span_start:span_end])
            return False
        else:
            # EOT is always valid
            self.in_range = True
            self.aligned = True
            self.valid_type = True
            return True
コード例 #2
0
    def init(self):
        """FFFF Element post-constructor initializer

        Loads the element from TFTF file, setting the element length to
        that of the file.  Returns a success flag if the file was loaded
        (no file is treated as success).
        """
        success = True
        # Try to size it from the TFTF file
        if self.filename and not self.tftf_blob:
            # Create a TFTF blob and load the contents from the specified
            # TFTF file
            self.tftf_blob = Tftf(0, self.filename)
            success = self.tftf_blob.load_tftf_file(self.filename)
            if success and self.tftf_blob.is_good():
                # element_length must be that of the entire TFTF blob,
                # not just the TFTF's "load_length" or "expanded_length".
                self.element_length = self.tftf_blob.tftf_length
            else:
                raise ValueError("Bad TFTF file: {0:x}".format(self.filename))
        return True