Esempio n. 1
0
    def main_cmd_enter(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        topush = self.__compute_curr_position()

        self.console.ctx.entry = word
        if not init_entry_addr(self.console.ctx):
            return False
        ad = self.console.ctx.entry_addr

        self.cursor_x = 0

        if self.goto_address(ad, h, w):
            self.saved_stack.clear()
            self.stack.append(topush)
            return True

        if self.mode == MODE_DECOMPILE and not self.dis.mem.is_code(ad):
            self.mode = MODE_DUMP

        ret = self.exec_disasm(ad, h)
        if ret:
            self.cursor_y = 0
            self.win_y = 0
            self.saved_stack.clear()
            self.stack.append(topush)
            self.goto_address(ad, h, w)
        return ret
Esempio n. 2
0
 def __exec_data(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     lines = self.ctx.lines
     if len(args) <= 1:
         self.ctx.entry = None
         error("no address in parameter")
         return
     self.ctx.entry = args[1]
     if len(args) == 3:
         lines = int(args[2])
     self.ctx.print_data = True
     if init_entry_addr(self.ctx):
         if args[0] == "da":
             self.ctx.dis.dump_data_ascii(self.ctx, lines)
         elif args[0] == "db":
             self.ctx.dis.dump_data(self.ctx, lines, 1)
         elif args[0] == "dw":
             self.ctx.dis.dump_data(self.ctx, lines, 2)
         elif args[0] == "dd":
             self.ctx.dis.dump_data(self.ctx, lines, 4)
         elif args[0] == "dq":
             self.ctx.dis.dump_data(self.ctx, lines, 8)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
         self.ctx.print_data = False
Esempio n. 3
0
    def main_cmd_enter(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        topush = self.__compute_curr_position()

        self.console.ctx.entry = word
        if not init_entry_addr(self.console.ctx):
            return False
        ad = self.console.ctx.entry_addr

        self.cursor_x = 0

        if self.goto_address(ad, h, w):
            self.saved_stack.clear()
            self.stack.append(topush)
            return True

        if self.mode == MODE_DECOMPILE and not self.dis.mem.is_code(ad):
            self.mode = MODE_DUMP

        ret = self.exec_disasm(ad, h)
        if ret:
            self.cursor_y = 0
            self.win_y = 0
            self.saved_stack.clear()
            self.stack.append(topush)
            self.goto_address(ad, h, w)
        return ret
Esempio n. 4
0
 def __exec_data(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     lines = self.ctx.lines
     if len(args) <= 1:
         self.ctx.entry = None
         error("no address in parameter")
         return
     self.ctx.entry = args[1]
     if len(args) == 3:
         lines = int(args[2])
     self.ctx.print_data = True
     if init_entry_addr(self.ctx):
         if args[0] == "da":
             self.ctx.dis.dump_data_ascii(self.ctx, lines)
         elif args[0] == "db":
             self.ctx.dis.dump_data(self.ctx, lines, 1)
         elif args[0] == "dw":
             self.ctx.dis.dump_data(self.ctx, lines, 2)
         elif args[0] == "dd":
             self.ctx.dis.dump_data(self.ctx, lines, 4)
         elif args[0] == "dq":
             self.ctx.dis.dump_data(self.ctx, lines, 8)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
         self.ctx.print_data = False
Esempio n. 5
0
 def __exec_calls(self, args):
     if len(args) != 2:
         error("section required")
         return
     if self.ctx.dis is None:
         error("load a file before")
         return
     self.ctx.calls_in_section = args[1]
     if init_entry_addr(self.ctx):
         self.ctx.dis.print_calls(self.ctx)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
     self.ctx.calls_in_section = None
Esempio n. 6
0
 def __exec_x(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         disasm(self.ctx)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 7
0
 def __exec_calls(self, args):
     if len(args) != 2:
         error("section required")
         return
     if self.ctx.dis is None:
         error("load a file before")
         return
     self.ctx.calls_in_section = args[1]
     if init_entry_addr(self.ctx):
         self.ctx.dis.print_calls(self.ctx)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
     self.ctx.calls_in_section = None
Esempio n. 8
0
 def __exec_x(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         disasm(self.ctx)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 9
0
 def __exec_dump(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     lines = self.ctx.lines
     if len(args) == 1:
         self.ctx.entry = None
     else:
         if len(args) == 3:
             lines = int(args[2])
         self.ctx.entry = args[1]
     if init_entry_addr(self.ctx):
         self.ctx.dis.dump_asm(self.ctx, lines)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 10
0
 def __exec_dump(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     lines = self.ctx.lines
     if len(args) == 1:
         self.ctx.entry = None
     else:
         if len(args) == 3:
             lines = int(args[2])
         self.ctx.entry = args[1]
     if init_entry_addr(self.ctx):
         self.ctx.dis.dump_asm(self.ctx, lines)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 11
0
 def __exec_v(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         o = disasm(self.ctx)
         if o is not None:
             Visual(self, self.ctx.dis, o)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 12
0
 def __exec_v(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         o = disasm(self.ctx)
         if o is not None:
             Visual(self, self.ctx.dis, o)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 13
0
 def main_cmd_enter(self, h, w):
     w = self.get_word_under_cursor()
     if w is None:
         return False
     self.interact.ctx.entry = w
     last = self.interact.ctx.entry_addr
     if not init_entry_addr(self.interact.ctx):
         return False
     ret = self.exec_disasm(self.interact.ctx.entry_addr)
     if ret:
         self.saved_stack = []
         self.stack.append((last, self.win_y, self.cursor_y, self.cursor_x))
         self.win_y = 0
         self.cursor_y = 0
         self.cursor_x = 0
     return ret
Esempio n. 14
0
    def __exec_xrefs(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return
        if len(args) == 1:
            self.ctx.entry = None
        else:
            self.ctx.entry = args[1]
        self.ctx.reset_vars()
        if init_entry_addr(self.ctx):

            ad = self.ctx.entry_addr
            if ad not in self.ctx.dis.xrefs:
                return

            self.ctx.dis.dump_xrefs(self.ctx, ad).print()
Esempio n. 15
0
    def __exec_xrefs(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return
        if len(args) == 1:
            self.ctx.entry = None
        else:
            self.ctx.entry = args[1]
        self.ctx.reset_vars()
        if init_entry_addr(self.ctx):

            ad = self.ctx.entry_addr
            if ad not in self.ctx.dis.xrefs:
                return

            self.ctx.dis.dump_xrefs(self.ctx, ad).print()
Esempio n. 16
0
 def __exec_v(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         self.ctx.dump = True
         o = self.ctx.dis.dump_asm(self.ctx, NB_LINES_TO_DISASM)
         self.ctx.dump = False
         if o is not None:
             Visual(self, self.ctx.dis, o)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 17
0
 def __exec_v(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         self.ctx.dump = True
         o = self.ctx.dis.dump_asm(self.ctx, NB_LINES_TO_DISASM)
         self.ctx.dump = False
         if o is not None:
             Visual(self, self.ctx.dis, o)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Esempio n. 18
0
 def __exec_x(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         try:
             o = disasm(self.ctx)
             if o is not None:
                 o.print()
             self.ctx.entry = None
             self.ctx.entry_addr = 0
         except:
             traceback.print_exc()
Esempio n. 19
0
 def __exec_x(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         try:
             o = disasm(self.ctx)
             if o is not None:
                 o.print()
             self.ctx.entry = None
             self.ctx.entry_addr = 0
         except:
             traceback.print_exc()
Esempio n. 20
0
    def main_cmd_enter(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        line = self.win_y + self.cursor_y
        x = self.cursor_x

        if word.startswith("0x"):
            try:
                ad = int(word, 16)
                if self.goto_address(ad, h, w):
                    self.saved_stack = []
                    self.stack.append((line, -1, -1, x, True))
                    return True
            except:
                return False

        elif word in self.console.ctx.labels:
            ad = self.console.ctx.labels[word]
            if self.goto_address(ad, h, w):
                self.saved_stack = []
                self.stack.append((line, -1, -1, x, True))
                return True

        self.console.ctx.entry = word
        last = self.console.ctx.entry_addr
        if not init_entry_addr(self.console.ctx):
            return False

        ret = self.exec_disasm(self.console.ctx.entry_addr)
        if ret:
            self.saved_stack = []
            self.stack.append((
                last,
                self.win_y,
                self.cursor_y,
                self.cursor_x,
                False
            ))
            self.win_y = 0
            self.cursor_y = 0
            self.cursor_x = 0
        return ret
Esempio n. 21
0
    def main_cmd_enter(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        line = self.win_y + self.cursor_y
        x = self.cursor_x

        if word.startswith("0x"):
            try:
                ad = int(word, 16)
                if self.goto_address(ad, h, w):
                    self.saved_stack = []
                    self.stack.append((line, -1, -1, x, True))
                    return True
            except:
                return False

        elif word in self.console.ctx.labels:
            ad = self.console.ctx.labels[word]
            if self.goto_address(ad, h, w):
                self.saved_stack = []
                self.stack.append((line, -1, -1, x, True))
                return True

        self.console.ctx.entry = word
        last = self.console.ctx.entry_addr
        if not init_entry_addr(self.console.ctx):
            return False

        ret = self.exec_disasm(self.console.ctx.entry_addr)
        if ret:
            self.saved_stack = []
            self.stack.append(
                (last, self.win_y, self.cursor_y, self.cursor_x, False))
            self.win_y = 0
            self.cursor_y = 0
            self.cursor_x = 0
        return ret
Esempio n. 22
0
    def main_cmd_enter(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        topush = self.__compute_curr_position()

        if word.startswith("0x"):
            try:
                ad = int(word, 16)
            except:
                return False

        elif word in self.console.ctx.labels:
            ad = self.console.ctx.labels[word]

        else:
            self.console.ctx.entry = word
            if not init_entry_addr(self.console.ctx):
                return False
            ad = self.console.ctx.entry_addr

        self.cursor_x = 0

        if self.goto_address(ad, h, w):
            self.saved_stack.clear()
            self.stack.append(topush)
            return True

        ret = self.exec_disasm(ad, h)
        if ret:
            self.cursor_y = 0
            self.win_y = 0
            self.saved_stack.clear()
            self.stack.append(topush)
            self.goto_address(ad, h, w)
        return ret
Esempio n. 23
0
    def main_cmd_xrefs(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        self.console.ctx.entry = word
        if not init_entry_addr(self.console.ctx):
            return False
        ad = self.console.ctx.entry_addr

        if ad not in self.dis.xrefs:
            self.status_bar("no xrefs", h, True)
            return False

        h2 = int(h * 3 / 4)
        w2 = int(w * 6 / 7)

        x = int((w - w2) / 2) - 1
        y = int((h - h2) / 2) - 1

        # A background with borders
        scr_borders = curses.newwin(h2 + 2, w2 + 2, y, x)
        scr_borders.border()
        title = " xrefs for " + hex(ad)
        scr_borders.addstr(0, int((w2 - len(title)) / 2), title)
        scr_borders.refresh()

        # The message box with xrefs
        o = self.dis.dump_xrefs(self.console.ctx, ad)
        scr = curses.newwin(h2, w2, y + 1, x + 1)
        w = Window(o)
        ret = w.start_view(scr)

        if not ret:
            return True

        # Goto the selected xref

        ad = o.line_addr[w.win_y + w.cursor_y]
        topush = self.__compute_curr_position()
        self.cursor_x = 0

        if self.goto_address(ad, h, w):
            self.saved_stack.clear()
            self.stack.append(topush)
            return True

        ad_disasm = ad

        if self.mode == MODE_DECOMPILE:
            func_id = self.dis.mem.get_func_id(ad)
            nop
            if func_id == -1:
                self.mode = MODE_DUMP
            else:
                ad_disasm = self.dis.func_id[func_id]

        ret = self.exec_disasm(ad_disasm, h)
        if ret:
            self.cursor_y = 0
            self.win_y = 0
            self.saved_stack.clear()
            self.stack.append(topush)
            self.goto_address(ad, h, w)
        return ret
Esempio n. 24
0
    def main_cmd_xrefs(self, h, w):
        word = self.get_word_under_cursor()
        if word is None:
            return False

        self.console.ctx.entry = word
        if not init_entry_addr(self.console.ctx):
            return False
        ad = self.console.ctx.entry_addr

        if ad not in self.dis.xrefs:
            self.status_bar("no xrefs", h, True)
            return False

        h2 = int(h*3/4)
        w2 = int(w*6/7)

        x = int((w - w2)/2) - 1
        y = int((h - h2)/2) - 1

        # A background with borders
        scr_borders = curses.newwin(h2 + 2, w2 + 2, y, x)
        scr_borders.border()
        title = " xrefs for " + hex(ad)
        scr_borders.addstr(0, int((w2 - len(title))/2), title)
        scr_borders.refresh()

        # The message box with xrefs
        o = self.dis.dump_xrefs(self.console.ctx, ad)
        scr = curses.newwin(h2, w2, y + 1, x + 1)
        w = Window(o)
        ret = w.start_view(scr)

        if not ret:
            return True

        # Goto the selected xref

        ad = o.line_addr[w.win_y + w.cursor_y]
        topush = self.__compute_curr_position()
        self.cursor_x = 0

        if self.goto_address(ad, h, w):
            self.saved_stack.clear()
            self.stack.append(topush)
            return True

        ad_disasm = ad

        if self.mode == MODE_DECOMPILE:
            func_id = self.dis.mem.get_func_id(ad)
            nop
            if func_id == -1:
                self.mode = MODE_DUMP
            else:
                ad_disasm = self.dis.func_id[func_id]

        ret = self.exec_disasm(ad_disasm, h)
        if ret:
            self.cursor_y = 0
            self.win_y = 0
            self.saved_stack.clear()
            self.stack.append(topush)
            self.goto_address(ad, h, w)
        return ret