def __init__(self, *args, **kwargs): self.pre_load() syntax = Color.yellowify("\nSyntax: ") + self._syntax_ example = Color.yellowify( "\nExample: ") + self._example_ if self._example_ else "" self.__doc__ = self.__doc__.replace(" " * 4, "") + syntax + example self.repeat = False self.repeat_count = 0 self.__last_command = None command_type = kwargs.setdefault("command", gdb.COMMAND_OBSCURE) complete_type = kwargs.setdefault("complete", gdb.COMPLETE_NONE) prefix = kwargs.setdefault("prefix", False) super(GenericCommand, self).__init__(self._cmdline_, command_type, complete_type, prefix) self.post_load() return None
def context_trace(self): self.context_title("trace") nb_backtrace = self.get_setting("nb_lines_backtrace") if nb_backtrace <= 0: return None orig_frame = current_frame = gdb.selected_frame() i = 0 # backward compat for gdb (gdb < 7.10) if not hasattr(gdb, "FrameDecorator"): gdb.execute("backtrace {:d}".format(nb_backtrace)) return None while current_frame: current_frame.select() if not current_frame.is_valid(): continue pc = current_frame.pc() name = current_frame.name() items = [] items.append("{:#x}".format(pc)) if name: frame_args = gdb.FrameDecorator.FrameDecorator( current_frame).frame_args() or [] m = "{}({})".format( Color.greenify(name), ", ".join([ "{}={!s}".format(Color.yellowify(x.sym), x.sym.value(current_frame)) for x in frame_args ])) items.append(m) else: try: insn = next(disass.gef_disassemble(pc, 1)) except gdb.MemoryError: break items.append( Color.redify("{} {}".format(insn.mnemonic, ", ".join(insn.operands)))) print("[{}] {}".format( Color.colorify("#{}".format(i), "bold pink"), config_arrow_right.join(items))) current_frame = current_frame.older() i += 1 nb_backtrace -= 1 if nb_backtrace == 0: break orig_frame.select() return None
def get_pc_context_info(self, pc, line): try: current_block = gdb.block_for_pc(pc) if not current_block.is_valid(): return "" m = collections.OrderedDict() while current_block and not current_block.is_static: for sym in current_block: symbol = sym.name if not sym.is_function and re.search( r"\W{}\W".format(symbol), line): val = gdb.parse_and_eval(symbol) if val.type.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY): addr = int(val.address) addrs = pwngef.chain.examine_mem_value(addr) if len(addrs) > 2: addrs = [addrs[0], "[...]", addrs[-1]] f = " {:s} ".format(config_arrow_right) val = f.join(addrs) elif val.type.code == gdb.TYPE_CODE_INT: val = hex(int(val)) else: continue if symbol not in m: m[symbol] = val current_block = current_block.superblock if m: return "// " + ", ".join([ "{}={}".format(Color.yellowify(a), b) for a, b in m.items() ]) except Exception: pass return ""