def BuildImage(self): """Write the image to a file""" fname = tools.GetOutputFilename(self._filename) with open(fname, 'wb') as fd: fd.write(chr(self._pad_byte) * self._size) for entry in self._entries.values(): data = entry.GetData() fd.seek(self._pad_before + entry.pos - self._skip_at_start) fd.write(data)
def GetData(self): """Write the section to a file""" section_data = chr(self._pad_byte) * self._size for entry in self._entries.values(): data = entry.GetData() base = self._pad_before + entry.pos - self._skip_at_start section_data = (section_data[:base] + data + section_data[base + len(data):]) return section_data
def GetData(self): """Get the contents of the section""" section_data = chr(self._pad_byte) * self._size for entry in self._entries.values(): data = entry.GetData() base = self._pad_before + entry.offset - self._skip_at_start section_data = (section_data[:base] + data + section_data[base + len(data):]) return section_data
def GetContentsByPhandle(self, phandle, source_entry): """Get the data contents of an entry specified by a phandle This uses a phandle to look up a node and and find the entry associated with it. Then it returnst he contents of that entry. Args: phandle: Phandle to look up (integer) source_entry: Entry containing that phandle (used for error reporting) Returns: data from associated entry (as a string), or None if not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node: source_entry.Raise("Cannot find node for phandle %d" % phandle) for entry in self._entries.values(): if entry._node == node: return entry.GetData() source_entry.Raise("Cannot find entry for node '%s'" % node.name)