Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
        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
Exemplo n.º 6
0
    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