def unpack(self, buffer: bytes) -> bytes: """ buffer: remove common header uncompress file """ tool = self.command if tool: tmp = tempfile.mkdtemp(dir=os.environ.get('tmp')) ToolInputFile = os.path.join(tmp, "unpack_sec_file") ToolOuputFile = os.path.join(tmp, "unpack_uncompress_sec_file") try: file = open(ToolInputFile, "wb") file.write(buffer) file.close() command = [tool, '-d', '-o', ToolOuputFile, ToolInputFile] ExecuteCommand(command) buf = open(ToolOuputFile, "rb") res_buffer = buf.read() except Exception as msg: logger.error(msg) return "" else: buf.close() if os.path.exists(tmp): shutil.rmtree(tmp) return res_buffer else: logger.error( "Error parsing section: EFI_SECTION_GUID_DEFINED cannot be parsed at this time." ) logger.info("Its GUID is: %s" % self.guid) return ""
def dump(self,layoutdict: dict, layoutlist: list, outputfile: str=None) -> None: logger.info('Binary Layout Info is saved in {} file.'.format(outputfile)) with open(outputfile, "w") as f: for item in layoutlist: f.writelines(item + '\n')