def load_image_fobj(self, fobj): """load a BinImage from a hunk file given via file obj""" # read the hunk blocks bf = HunkBlockFile() bf.read(fobj, isLoadSeg=True) # derive load seg file lsf = HunkLoadSegFile() lsf.parse_block_file(bf) # convert load seg file return self.create_image_from_load_seg_file(lsf)
def is_image_fobj(self, fobj): """check if a given fobj is a hunk LoadSeg file""" bf = HunkBlockFile() bf_type = bf.peek_type(fobj) return bf_type == Hunk.TYPE_LOADSEG
add = num_longs * 4 - n if add > 0: s += '\0' * add f.write(s) def _read_long(self, buf, pos): return struct.unpack_from(">I", buf, pos)[0] def _write_long(self, f, v): data = struct.pack(">I", v) f.write(data) # ----- mini test ----- if __name__ == '__main__': import sys from HunkBlockFile import HunkBlockFile, HunkDebugBlock hd = HunkDebug() for a in sys.argv[1:]: hbf = HunkBlockFile() hbf.read_path(a) for blk in hbf.get_blocks(): if isinstance(blk, HunkDebugBlock): # decode debug data dd = hd.decode(blk.debug_data) print(a, "->", dd.tag) # now encode again new_debug_data = hd.encode(dd) # compare! assert new_debug_data == blk.debug_data
add = num_longs * 4 - n if add > 0: s += '\0' * add f.write(s) def _read_long(self, buf, pos): return struct.unpack_from(">I",buf,pos)[0] def _write_long(self, f, v): data = struct.pack(">I",v) f.write(data) # ----- mini test ----- if __name__ == '__main__': import sys from HunkBlockFile import HunkBlockFile, HunkDebugBlock hd = HunkDebug() for a in sys.argv[1:]: hbf = HunkBlockFile() hbf.read_path(a) for blk in hbf.get_blocks(): if isinstance(blk, HunkDebugBlock): # decode debug data dd = hd.decode(blk.debug_data) print(a,"->",dd.tag) # now encode again new_debug_data = hd.encode(dd) # compare! assert new_debug_data == blk.debug_data