Beispiel #1
0
    def initUI(self):
        self.locationStack = list()

        self.app.title("PyDA")

        # Set up the Menu Bar
        self.menu_bar = MenuBar(self.app)
        self.menu_bar.addMenu('File')
        self.menu_bar.addMenuItem('File', 'Disassemble File',
                                  self.onDisassembleFile)
        self.menu_bar.addMenuItem('File', 'Load PyDA Save', self.onLoad)
        self.menu_bar.addMenuItem('File', 'Save', self.onSave)
        self.menu_bar.addMenuSeparator('File')
        self.menu_bar.addMenuItem('File', 'Exit', self.onExit)

        # Set up the Tool Bar
        # TODO: Add images to buttons with mouseover text
        self.toolbar = ToolBar(self.app, 'top')
        self.toolbar.addButton('Back', self.onBack, 'left')
        self.toolbar.addVertSeperator('left')
        self.toolbar.addButton('Disassemble File', self.onDisassembleFile,
                               'left')
        self.toolbar.addButton('Load', self.onLoad, 'left')
        self.toolbar.addButton('Save', self.onSave, 'left')
        self.toolbar.addVertSeperator('left')
        self.toolbar.addButton('Share', self.onShare, 'left')

        # Set up the status bar ##
        self.status_bar = ToolBar(self.app,
                                  'bottom',
                                  relief='sunken',
                                  borderwidth=2)
        self.status_bar.addLabel('Status:', 'left')
        self.status_label = self.status_bar.addLabel('Ready', 'left')
        self.progress_bar = self.status_bar.addProgressBar(
            'right', length=200, mode='indeterminate')

        # Set up the vertical paned window
        self.tl_v_window = PanedWindow(self.app,
                                       'top',
                                       borderwidth=1,
                                       relief="sunken",
                                       sashwidth=4,
                                       orient="vertical")

        # Set up the horizontal paned window and add to the vertical window
        self.tl_h_window = self.tl_v_window.addElement(
            PanedWindow(self.tl_v_window,
                        borderwidth=1,
                        relief="sunken",
                        sashwidth=4))

        # Set up the two notebooks
        self.left_notebook = self.tl_h_window.addNotebook()
        self.right_notebook = self.tl_h_window.addNotebook()
        self.bottom_notebook = self.tl_v_window.addNotebook()

        # Set up the functions listbox
        self.functions_listbox = self.left_notebook.addListboxWithScrollbar(
            'Functions',
            background='white',
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')

        self.functions_listbox.bind('<Double-Button-1>',
                                    self.onFunctionDoubleClick)

        # Set up the strings listbox
        self.strings_listbox = self.left_notebook.addListboxWithScrollbar(
            'Strings',
            background='white',
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')

        self.strings_listbox.bind('<Double-Button-1>',
                                  self.onStringDoubleClick)

        # Set up the disassembly textbox
        self.disassembly_textbox = self.right_notebook.addTextboxWithScrollbar(
            'Disassembly',
            tcl_buffer_size=self.TEXTBOX_BUFFER_SIZE,
            tcl_buffer_low_cutoff=self.TEXTBOX_BUFFER_LOW_CUTOFF,
            tcl_buffer_high_cutoff=self.TEXTBOX_BUFFER_HIGH_CUTOFF,
            tcl_moveto_yview=self.TEXTBOX_MOVETO_YVIEW,
            max_lines_jump=self.TEXTBOX_MAX_LINES_JUMP,
            background="white",
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')

        # Set up the data section textbox
        # self.data_sections_textbox = self.right_notebook.addTextboxWithScrollbar(
        #         'Data Sections', background="white", borderwidth=1,
        #         highlightthickness=1, relief='sunken')
        self.data_sections_textbox = self.right_notebook.addTextboxWithScrollbar(
            'Data Sections',
            tcl_buffer_size=self.TEXTBOX_BUFFER_SIZE,
            tcl_buffer_low_cutoff=self.TEXTBOX_BUFFER_LOW_CUTOFF,
            tcl_buffer_high_cutoff=self.TEXTBOX_BUFFER_HIGH_CUTOFF,
            tcl_moveto_yview=self.TEXTBOX_MOVETO_YVIEW,
            max_lines_jump=self.TEXTBOX_MAX_LINES_JUMP,
            background="white",
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')

        # Set up the output window
        debug_frame = self.bottom_notebook.addFrame('Debug')
        debug_frame_2 = debug_frame.addFrame('bottom',
                                             'x',
                                             False,
                                             borderwidth=1)
        debug_frame_1 = debug_frame.addFrame('top',
                                             'both',
                                             True,
                                             borderwidth=1)
        self.debug_textbox = debug_frame_1.addTextboxWithScrollbar(
            background='white',
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')
        self.debug_entry = debug_frame_2.addEntryWithLabel(
            'Command:',
            'bottom',
            'x',
            True,
            background='white',
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')

        self.debug_data_model = TextModel()
        self.debug_textbox.setDataModel(self.debug_data_model)

        # Set up the chat window
        chat_frame = self.bottom_notebook.addFrame('Chat')
        chat_frame_2 = chat_frame.addFrame('bottom', 'x', False, borderwidth=1)
        chat_frame_1 = chat_frame.addFrame('top', 'both', True, borderwidth=1)
        self.chat_textbox = chat_frame_1.addTextboxWithScrollbar(
            background='white',
            borderwidth=1,
            highlightthickness=1,
            relief='sunken')
        self.chat_entry = chat_frame_2.addEntryWithLabel('Send:',
                                                         'bottom',
                                                         'x',
                                                         True,
                                                         background='white',
                                                         borderwidth=1,
                                                         highlightthickness=1,
                                                         relief='sunken')

        self.chat_data_model = TextModel()
        self.chat_textbox.setDataModel(self.chat_data_model)

        # Set up the context menus
        self.section_context_menu = ContextMenu([('Copy', self.onCopyString)])
        self.address_context_menu = ContextMenu([
            ('Copy String', self.onCopyString),
            ('Copy Value', self.onCopyValue)
        ])
        self.disass_comment_context_menu = ContextMenu([(';  Comment',
                                                         self.disassComment)])
        self.data_comment_context_menu = ContextMenu([(';  Comment',
                                                       self.dataComment)])
        self.disass_label_context_menu = ContextMenu([
            ('n  Rename Label', self.disassRenameLabel)
        ])
        self.data_label_context_menu = ContextMenu([('n  Rename Label',
                                                     self.dataRenameLabel)])

        # Force the mouse to always have focus
        self.tk_focusFollowsMouse()

        # Get the appropriate button number based on system
        right_click_button = "<Button-2>" if system(
        ) == "Darwin" else "<Button-3>"

        dis_textbox_context_queue = self.app.createCallbackQueue()
        # Create a context manager for the disassembly textbox
        self.disassembly_textbox_context_manager = WidgetContextManager(
            self.app,
            dis_textbox_context_queue,
            self.disassembly_textbox,
            self.PYDA_SEP,
            self.PYDA_BEGL,
            right_click_button,
            [(self.PYDA_SECTION, 'darkgreen', self.section_context_menu),
             (self.PYDA_ADDRESS, 'black', self.address_context_menu),
             (self.PYDA_MNEMONIC, 'blue', None),
             (self.PYDA_OP_STR, 'darkblue', None),
             (self.PYDA_COMMENT, 'darkgreen',
              self.disass_comment_context_menu),
             (self.PYDA_LABEL, 'saddle brown', self.disass_label_context_menu),
             (self.PYDA_BYTES, 'dark gray', None),
             (self.PYDA_GENERIC, 'black', None),
             (self.PYDA_ENDL, 'black', self.disass_comment_context_menu)],
        )

        self.disassembly_textbox.context_manager = self.disassembly_textbox_context_manager

        self.disassembly_textbox.bind('<Key>', self.keyHandler)

        data_textbox_context_queue = self.app.createCallbackQueue()
        # Create a context manager for the data sections textbox
        self.data_textbox_context_manager = WidgetContextManager(
            self.app, data_textbox_context_queue, self.data_sections_textbox,
            self.PYDA_SEP, self.PYDA_BEGL, right_click_button,
            [(self.PYDA_SECTION, 'darkgreen', None),
             (self.PYDA_MNEMONIC, 'blue', None),
             (self.PYDA_OP_STR, 'darkblue', None),
             (self.PYDA_COMMENT, 'darkgreen', self.data_comment_context_menu),
             (self.PYDA_LABEL, 'saddle brown', self.data_label_context_menu),
             (self.PYDA_BYTES, 'dark gray', None),
             (self.PYDA_GENERIC, 'black', None),
             (self.PYDA_ENDL, 'black', self.data_comment_context_menu)])

        self.data_sections_textbox.context_manager = self.data_textbox_context_manager

        self.data_sections_textbox.bind('<Key>', self.keyHandler)

        # Redirect stdout to the debug window
        if self.REDIR_STDOUT:
            sys.stdout = StdoutRedirector(self.stdoutMessage)
            print "Stdout is being redirected to here"