def GetPaddedDataForEntry(self, entry, entry_data): """Get the data for an entry including any padding Gets the entry data and uses the section pad-byte value to add padding before and after as defined by the pad-before and pad-after properties. This does not consider alignment. Args: entry: Entry to check Returns: Contents of the entry along with any pad bytes before and after it (bytes) """ pad_byte = (entry._pad_byte if isinstance(entry, Entry_section) else self._pad_byte) data = bytearray() # Handle padding before the entry if entry.pad_before: data += tools.get_bytes(self._pad_byte, entry.pad_before) # Add in the actual entry data data += entry_data # Handle padding after the entry if entry.pad_after: data += tools.get_bytes(self._pad_byte, entry.pad_after) if entry.size: data += tools.get_bytes(pad_byte, entry.size - len(data)) self.Detail('GetPaddedDataForEntry: size %s' % to_hex_size(self.data)) return data
def GetData(self, required=True): """Get the contents of an entry Args: required: True if the data must be present, False if it is OK to return None Returns: bytes content of the entry, excluding any padding. If the entry is compressed, the compressed data is returned """ self.Detail('GetData: size %s' % to_hex_size(self.data)) return self.data
def _AddEntries(areas, entry): entries = entry.GetEntries() tout.debug("fmap: Add entry '%s' type '%s' (%s subentries)" % (entry.GetPath(), entry.etype, to_hex_size(entries))) if entries and entry.etype != 'cbfs': # Create an area for the section, which encompasses all entries # within it if entry.image_pos is None: pos = 0 else: pos = entry.image_pos - entry.GetRootSkipAtStart() # Drop @ symbols in name name = entry.name.replace('@', '') areas.append(fmap_util.FmapArea(pos, entry.size or 0, name, 0)) for subentry in entries.values(): _AddEntries(areas, subentry) else: pos = entry.image_pos if pos is not None: pos -= entry.section.GetRootSkipAtStart() areas.append( fmap_util.FmapArea(pos or 0, entry.size or 0, entry.name, 0))