예제 #1
0
  def disasm(self, fname):
    # TODO (re)use the dasm enhance generator
    ro = re.compile(r'^\s*0*(?P<addr>[{}]+):'.format(string.hexdigits))
    funcs = { t[0]:t[2] for t in dasmutil.func_addresses(self.binary) }
    bbs = { t[0]:tuple(t[1:])
              for t in dasmutil.bb_addresses(self.binary, True) }
    capture = False
    func_sizes = set( hex(int(k,16)-4)[2:] for k in funcs )
    with open(fname,'w') as f:
      for line in dasmutil.disassemble(self.binary):
        mo = ro.match(line)
        if mo:
          addr = mo.group(1)
          if addr in func_sizes:
            continue # ignore fsizes
          if addr in funcs:
            capture = (funcs[addr] in self.observe_list)
            if capture:
              f.write('='*100+'\n') # separator
              f.write(hold) # function name
              f.write('-'*(len(hold)-1)+'\n')

          if capture and addr in bbs:
            lbl = bbs[addr][1].split('#')
            f.write('#'.join(lbl[2:])+':\n')
        else:
          if len(line.strip())>0: # hold
            hold = line
            continue

        if capture: f.write(line)
    assert(f.closed)
예제 #2
0
    def disasm(self, fname):
        # TODO (re)use the dasm enhance generator
        ro = re.compile(r'^\s*0*(?P<addr>[{}]+):'.format(string.hexdigits))
        funcs = {t[0]: t[2] for t in dasmutil.func_addresses(self.binary)}
        bbs = {
            t[0]: tuple(t[1:])
            for t in dasmutil.bb_addresses(self.binary, True)
        }
        capture = False
        func_sizes = set(hex(int(k, 16) - 4)[2:] for k in funcs)
        with open(fname, 'w') as f:
            for line in dasmutil.disassemble(self.binary):
                mo = ro.match(line)
                if mo:
                    addr = mo.group(1)
                    if addr in func_sizes:
                        continue  # ignore fsizes
                    if addr in funcs:
                        capture = (funcs[addr] in self.observe_list)
                        if capture:
                            f.write('=' * 100 + '\n')  # separator
                            f.write(hold)  # function name
                            f.write('-' * (len(hold) - 1) + '\n')

                    if capture and addr in bbs:
                        lbl = bbs[addr][1].split('#')
                        f.write('#'.join(lbl[2:]) + ':\n')
                else:
                    if len(line.strip()) > 0:  # hold
                        hold = line
                        continue

                if capture: f.write(line)
        assert (f.closed)
예제 #3
0
  def func_map(self):
    """Return a map of addr: func info

    Format:
      addr: (hexaddr, fname, size)

    where addr and size are of type int, in bytes
    """
    return { int(t[0],16) : (t[0], t[2], int(t[1],16))
                for t in dasmutil.func_addresses(self.binary) }
예제 #4
0
    def func_map(self):
        """Return a map of addr: func info

    Format:
      addr: (hexaddr, fname, size)

    where addr and size are of type int, in bytes
    """
        return {
            int(t[0], 16): (t[0], t[2], int(t[1], 16))
            for t in dasmutil.func_addresses(self.binary)
        }