def draw(self): # Draw the status bar self.screen.move(self.height, 0) self.screen.clrtoeol() line = self.win_y + self.cursor_y if line in self.output.line_addr: ad = self.output.line_addr[line] self.last_curr_line_ad = ad else: ad = self.last_curr_line_ad if ad is not None: s = self.dis.binary.get_section(ad) self.screen.addstr(self.height, 0, s.name, curses.A_BOLD) if self.db.mem.is_code(ad): fid = self.db.mem.get_func_id(ad) if fid != -1: func_ad = self.db.func_id[fid] name = self.api.get_symbol(func_ad) if self.width - len(name) - 1 < 0: self.screen.insstr(self.height, 0, name) else: self.screen.insstr(self.height, self.width - len(name) - 1, name) # Draw lines Listbox.draw(self)
def main_k_top(self): self.stack.append(self.__compute_curr_position()) self.saved_stack.clear() if self.mode == MODE_DUMP: top = self.dis.binary.get_first_addr() if self.first_addr != top: self.exec_disasm(top) Listbox.k_top(self) self.last_curr_line_ad = self.first_addr return True
def popup_text(title, output, par_widget): """ It opens a centered popup. output is an instance of the class Output. Returns (bool, line number of the cursor) """ h2 = par_widget.height * 3 // 4 w2 = par_widget.width * 6 // 7 x = (par_widget.width - w2) // 2 - 1 y = (par_widget.height - h2) // 2 - 1 # A background with borders borders = curses.newwin(h2 + 2, w2 + 2, par_widget.y + y, par_widget.x + x) borders.border() borders.addstr(0, (w2 - len(title)) // 2, " %s " % title) borders.refresh() w = Window() w.screen = borders w.widgets.append(Listbox(par_widget.x + x + 1, par_widget.y + y + 1, w2, h2, output)) ret = w.start_view(w.screen) return (ret, w.widgets[0].win_y + w.widgets[0].cursor_y)
def cmd_highlight_current_word(self, from_mouse_event=False): r = Listbox.cmd_highlight_current_word(self, from_mouse_event) if r and self.gctx.dis.binary.arch in ("x86", "x64"): w = self.search_hi[0] i = myindex(X86_REG_HIGHLIGHT_64, w) if i == -1: i = myindex(X86_REG_HIGHLIGHT_32, w) if i == -1: i = myindex(X86_REG_HIGHLIGHT_16, w) for j, lst in enumerate(X86_REG_HIGHLIGHT_8): if w in lst: i = j break if i != -1: self.search_hi.clear() self.search_hi.append(X86_REG_HIGHLIGHT_64[i]) self.search_hi.append(X86_REG_HIGHLIGHT_32[i]) self.search_hi.append(X86_REG_HIGHLIGHT_16[i]) if i <= 3: self.search_hi += X86_REG_HIGHLIGHT_8[i] return r
def main_k_bottom(self): self.stack.append(self.__compute_curr_position()) self.saved_stack.clear() self.cursor_x = 0 if self.mode == MODE_DUMP: bottom = self.dis.binary.get_last_addr() if self.last_addr - 1 != bottom: self.exec_disasm(bottom) self.dump_update_up(self.win_y) self.win_y = 0 self.cursor_y = 0 Listbox.k_bottom(self) self.last_curr_line_ad = self.last_addr - 1 return True
def get_y_scroll(self): if self.mode == MODE_DECOMPILE or self.last_curr_line_ad is None: return Listbox.get_y_scroll(self) h8 = self.height * 8 ad = self.last_curr_line_ad s = self.api.get_section(ad) ad_normalized = self.section_normalized[s.start] + ad - s.start return ad_normalized * h8 // self.total_size
def __init__(self, x, y, w, h, gctx, ad, analyzer, api, mode=MODE_DUMP, until=-1, update_position=True): self.gctx = gctx self.dis = gctx.dis self.db = gctx.db self.analyzer = analyzer self.api = api self.last_curr_line_ad = None # Disassemble self.ctx = self.gctx.get_addr_context(ad) if not self.ctx: return ad = self.ctx.entry ad_disasm = ad if mode == MODE_DECOMPILE: if self.db.mem.is_code(ad_disasm): fid = self.db.mem.get_func_id(ad_disasm) if fid != -1: self.ctx.entry = self.db.func_id[fid] else: mode = MODE_DUMP else: mode = MODE_DUMP if mode == MODE_DUMP: self.ctx.output = self.ctx.dump_asm(until=until) else: self.ctx.output = self.ctx.decompile() self.mode = mode Listbox.__init__(self, x, y, w, h, self.ctx.output) self.height = h - 1 # Last/first address printed (only in MODE_DUMP) self.set_last_addr() self.set_first_addr() self.stack = [] self.saved_stack = [] # Note: all these functions should return a boolean. The value is true # if the screen must be refreshed (not re-drawn, in this case call # explictly self.draw or self.reload_asm if the output changed). new_mapping = { b"z": self.main_cmd_line_middle, b"g": self.main_k_top, b"G": self.main_k_bottom, b";": self.view_inline_comment_editor, b"%": self.main_cmd_next_bracket, b"\t": self.main_cmd_switch_mode, b"{": self.main_k_prev_paragraph, b"}": self.main_k_next_paragraph, b"x": self.main_cmd_xrefs, b"r": self.main_cmd_rename, b"I": self.main_cmd_inst_output, b"M": self.main_cmd_show_mangling, b"B": self.main_cmd_show_bytes, b"/": self.main_cmd_search, b"n": self.main_cmd_search_forward, b"N": self.main_cmd_search_backward, b"j": self.main_cmd_jump_to, b"c": self.main_cmd_set_code, b"p": self.main_cmd_set_function, b"b": self.main_cmd_set_byte, b"w": self.main_cmd_set_word, b"d": self.main_cmd_set_dword, b"Q": self.main_cmd_set_qword, b"a": self.main_cmd_set_ascii, b"o": self.main_cmd_set_offset, b"*": self.main_cmd_set_array, b"U": self.main_cmd_undefine, b"S": self.main_cmd_set_frame_size, b"\n": self.main_cmd_enter, b"\x1b": self.main_cmd_escape, # I wanted ctrl-enter but it cannot be mapped on my terminal b"u": self.main_cmd_reenter, # u for undo } self.mapping.update(new_mapping) # Init some y coordinate, used to compute the cursor position self.init_section_coords() if update_position: self.win_y = self.dump_update_up(self.win_y) self.goto_address(ad) self.main_cmd_line_middle()
def __init__(self, x, y, w, h, gctx, ad, analyzer, api, mode=MODE_DUMP, until=-1, update_position=True): self.gctx = gctx self.dis = gctx.dis self.db = gctx.db self.analyzer = analyzer self.api = api self.last_curr_line_ad = None # Disassemble self.ctx = self.gctx.get_addr_context(ad) if not self.ctx: return ad = self.ctx.entry ad_disasm = ad if mode == MODE_DECOMPILE: if self.db.mem.is_code(ad_disasm): fid = self.db.mem.get_func_id(ad_disasm) if fid != -1: self.ctx.entry = self.db.func_id[fid] else: mode = MODE_DUMP else: mode = MODE_DUMP if mode == MODE_DUMP: self.ctx.output = self.ctx.dump_asm(until=until) else: self.ctx.output = self.ctx.decompile() self.mode = mode Listbox.__init__(self, x, y, w, h, self.ctx.output) self.height = h - 1 # Last/first address printed (only in MODE_DUMP) self.set_last_addr() self.set_first_addr() self.stack = [] self.saved_stack = [] # Note: all these functions should return a boolean. The value is true # if the screen must be refreshed (not re-drawn, in this case call # explictly self.draw or self.reload_asm if the output changed). new_mapping = { b"z": self.main_cmd_line_middle, b"g": self.main_k_top, b"G": self.main_k_bottom, b";": self.view_inline_comment_editor, b"%": self.main_cmd_next_bracket, b"\t": self.main_cmd_switch_mode, b"{": self.main_k_prev_paragraph, b"}": self.main_k_next_paragraph, b"x": self.main_cmd_xrefs, b"r": self.main_cmd_rename, b"I": self.main_cmd_inst_output, b"M": self.main_cmd_show_mangling, b"B": self.main_cmd_show_bytes, b"/": self.main_cmd_search, b"n": self.main_cmd_search_forward, b"N": self.main_cmd_search_backward, b"j": self.main_cmd_jump_to, b"F": self.main_cmd_functions, b"i": self.main_cmd_invert_cond, b"c": self.main_cmd_set_code, b"p": self.main_cmd_set_function, b"b": self.main_cmd_set_byte, b"w": self.main_cmd_set_word, b"d": self.main_cmd_set_dword, b"Q": self.main_cmd_set_qword, b"a": self.main_cmd_set_ascii, b"o": self.main_cmd_set_offset, b"*": self.main_cmd_set_array, b"U": self.main_cmd_undefine, b"S": self.main_cmd_set_frame_size, b"\n": self.main_cmd_enter, b"\x1b": self.main_cmd_escape, # I wanted ctrl-enter but it cannot be mapped on my terminal b"u": self.main_cmd_reenter, # u for undo } self.mapping.update(new_mapping) # Init some y coordinate, used to compute the cursor position self.init_section_coords() if update_position: self.win_y = self.dump_update_up(self.win_y) self.goto_address(ad) self.main_cmd_line_middle()