def new_file(self, widget, file=''):
        dialog = file_dialog.FileDialog(self.main, file, False)
        resp = dialog.run()
        if resp == Gtk.ResponseType.DELETE_EVENT or resp == Gtk.ResponseType.REJECT:
            dialog.destroy()
        else:
            self.file = dialog.file

            self.main.load_new_file(dialog, self.file)
            dialog.destroy()
Exemple #2
0
    def new_file(self, widget, file=''):
        dialog = file_dialog.FileDialog(self.dependency_check.HAS_PYEW, self.dependency_check.HAS_RADARE, self.uicore.backend, file)
        resp = dialog.run()
        if resp == gtk.RESPONSE_DELETE_EVENT or resp == gtk.RESPONSE_REJECT:
            dialog.destroy()
        else:
            self.file = dialog.file

            self.main.load_new_file(dialog, self.file)
            dialog.destroy()
Exemple #3
0
    def new_file(self, widget, file=''):
        dialog = file_dialog.FileDialog(False,
                                        self.dependency_check.HAS_RADARE,
                                        'radare', file)
        resp = dialog.run()
        if resp == Gtk.ResponseType.DELETE_EVENT or resp == Gtk.ResponseType.REJECT:
            dialog.destroy()
        else:
            self.file = dialog.file

            self.main.load_new_file(dialog, self.file)
            dialog.destroy()
Exemple #4
0
    def __init__(self, target, backend):

        self.dependency_check = dependency_check

        self.target = target
        self.backend = backend
        self.empty_gui = False
        # Variable to hold the Process object in case we choose to disassemble a binary.
        self.dasm_process = False

        # Check if we have, at least, one core; else: exit
        if not dependency_check.HAS_PYEW and not dependency_check.HAS_RADARE:
            md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, None)
            md.set_markup("<big><b>No backend engines found!</b></big>")
            md.format_secondary_markup("Install either pyew or radare to run bokken:\n\n<b>Pyew:</b>\t\t<a href=\"http://code.google.com/p/pyew/\">http://code.google.com/p/pyew/</a>\n<b>Radare:</b>\t<a href=\"http://radare.org/\">http://radare.org</a>")
            md.run()
            md.destroy()
            sys.exit(1)

        # Launch file selection dialog
        dialog = file_dialog.FileDialog(dependency_check.HAS_PYEW, dependency_check.HAS_RADARE, self.backend, self.target)
        resp = dialog.run()
        if resp == gtk.RESPONSE_DELETE_EVENT or resp == gtk.RESPONSE_REJECT:
            sys.exit(1)
        # Get dialog selected file, backend and options
        self.target = dialog.file
        self.backend = dialog.backend

        # Load selected core
        if self.backend == 'pyew':
            import ui.core as core
            self.uicore = core.Core(dialog.case, dialog.deep, dialog.progress_bar)
        elif self.backend == 'radare':
            import ui.radare_core as radare_core
            self.uicore = radare_core.Core(dialog.radare_lower, dialog.analyze_bin, dialog.asm_syn ,dialog.use_va, dialog.asm_byt, dialog.progress_bar)
        self.uicore.backend = self.backend

        # Check if target name is an URL, pyew stores it as 'raw'
        self.uicore.is_url(self.target)

        if self.target:
            # Just open the target if path is correct or an url
            if self.uicore.core.format != 'URL' and not os.path.isfile(self.target):
                print "Incorrect file argument:", FAIL, self.target, ENDC
                sys.exit(1)

            self.load_file(self.target)

            import ui.core_functions
            ui.core_functions.repaint()

        else:
            self.empty_gui = True

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_focus = True
        self.window.connect("delete_event", self.quit)
        self.window.set_icon_from_file(os.path.dirname(__file__)+os.sep+'data'+os.sep+'bokken.svg')
        gtk.settings_get_default().set_long_property("gtk-button-images", True, "main") 

        # Title
        self.window.set_title(MAINTITLE)

        # Positions
        self.window.resize(800, 600)
        self.window.move(25, 25)
        # Maximize window
        self.window.maximize()

        # Create VBox to contain top buttons and other VBox
        self.supervb = gtk.VBox(False, 1)

        # Menu bar
        self.mbar = menu_bar.MenuBar(self)

        self.supervb.pack_start(self.mbar, False, False, 1)

        # Create top buttons and add to VBox
        if self.backend == 'pyew':
            import ui.pyew_toolbar as toolbar
            self.topbuttons = toolbar.TopButtons(self.uicore, self)
        elif self.backend == 'radare':
            import ui.radare_toolbar as toolbar
            self.topbuttons = toolbar.TopButtons(self.uicore, self)
        self.supervb.pack_start(self.topbuttons, False, True, 1)

        # Create VBox to contain textviews and statusbar
        self.mainvb = gtk.VBox(False, 1)
        self.supervb.pack_start(self.mainvb, True, True, 1)

        # Initialize and add TextViews
        self.tviews = textviews.TextViews(self.uicore, self)
        # Create toolbar show/hide tabs menu
        self.mbar.create_view_menu()

        # Initialize and add Statusbar
        self.sbar = statusbar.Statusbar(self.uicore, self.tviews)
        self.sbar.create_statusbar()

        # Add textviews and statusbar to the VBox
        self.mainvb.pack_start(self.tviews, True, True, 1)
        self.mainvb.pack_start(self.sbar, False, True, 1)

        self.window.add(self.supervb)

        # Disable all until file loads
        self.disable_all()

        if self.empty_gui:
            self.show_empty_gui()

        self.show_file_data()
        self.window.show_all()

        # Hide left tree for plain or unsupported formats
        if self.uicore.core.format in ['Hexdump', 'Plain Text', 'OLE2']:
            self.tviews.left_scrolled_window.hide()
        if self.uicore.backend == 'radare':
            if not self.uicore.do_anal:
                self.topbuttons.diff_tb.set_sensitive(False)

        dialog.destroy()
        # We make sure that we remove the reference to the scrollbar to avoid errors.
        self.uicore.core.progress_bar = None
        gtk.main()
Exemple #5
0
    def __init__(self, target, backend):

        import time

        # Allow only the main thread to touch the GUI (gtk) part, while letting
        # other threads do background work.
        GObject.threads_init()

        self.target = target
        self.backend = backend
        self.empty_gui = False
        # Variable to hold the Process object in case we choose to disassemble a binary.
        self.dasm_process = False

        # Check if we have, at least, one available core; otherwise exit.
        # TODO: Should be removed? now with one core and dependency_check doing the core check... 
        if not glob.has_radare:
            md = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, None)
            md.set_markup("<big><b>No backend engine found!</b></big>")
            md.format_secondary_markup((
                    'Install radare to run bokken:\n\n'
                    '<b>Radare:</b>\t<a href="http://radare.org/">'
                    'http://radare.org</a>'))
            md.run()
            md.destroy()
            sys.exit(1)

        # Start up the HTTP server.
        if glob.http_server:
            import lib.http as httpd
            http = httpd.BokkenHttpServer(glob.http_server_bind_address,
                   glob.http_server_port)
            print("\nBringing up HTTP server on %s:%d." %
                   (glob.http_server_bind_address, glob.http_server_port))
            # We start the thread.
            http.start()
            time.sleep(0.2)
            if not http.is_alive():
                print('Unable to bind to %s:%d.' %
                        (glob.http_server_bind_address, glob.http_server_port))
                return None
            # We put the http structure in glob to have it accessible in the
            # global __main__ handler.
            glob.http = http

        # Create a main window before anything else.
        self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
        self.window.set_focus = True
        self.window.connect("delete_event", self.quit)
        ui.gtk3.common.set_bokken_icon(self.window)
        Gtk.Settings.get_default().set_long_property("gtk-button-images", True, "main")

        # Title
        self.window.set_title(MAINTITLE + glob.version + " - " + self.target)

        # Launch file selection dialog
        dialog = file_dialog.FileDialog(self, self.target, True)
        resp = dialog.run()
        if resp == Gtk.ResponseType.DELETE_EVENT or resp == Gtk.ResponseType.REJECT:
            return None
        # Get dialog selected file, backend and options
        self.target = dialog.file
        self.backend = 'radare'      # I'm leaving that as may be needed in the future

        # Load core
        import ui.radare_core as core
        self.uicore = core.Core(dialog)

        # Create a global object under glob.
        glob.core = self.uicore

        if self.target:
            # Just open the target if path is correct or an url
            if not os.path.isfile(self.target):
                print(common.console_color('Incorrect file argument: %s' %
                        self.target, 'red'))
                sys.exit(1)

            self.load_file(self.target)
            if not self.uicore.file_loaded:
                error_msg = "Error opening file " + self.target
                md = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, None)
                md.set_markup("<big><b>File open error!</b></big>")
                md.format_secondary_markup(error_msg)
                md.run()
                md.destroy()
                print(error_msg)
                sys.exit(1)

            ui.gtk3.common.repaint()

        else:
            self.empty_gui = True

        # Positions
        #self.window.resize(1000, 700)
        #self.window.move(25, 25)
        self.window.set_position(Gtk.WindowPosition.CENTER)
        # Maximize window
        #self.window.maximize()

        # Create LanguageManager object to handle all the syntax highlighting.
        # Every textview in the app will use it.
        self.lm = GtkSource.LanguageManager.get_default()
        # Add UI data dir to language paths
        paths = self.lm.get_search_path()
        paths.append(common.datafile_path())
        self.lm.set_search_path(paths)

        # Create VBox to contain top buttons and other VBox
        self.supervb = Gtk.VBox(False, 1)

        # Create top buttons and add to VBox
        import ui.radare_toolbar as toolbar
        self.topbuttons = toolbar.TopButtons(self.uicore, self)
        self.supervb.pack_start(self.topbuttons, False, True, 1)

        # Create VBox to contain textviews and statusbar
        self.mainvb = Gtk.VBox(False, 1)
        self.supervb.pack_start(self.mainvb, True, True, 1)

        # Initialize and add TextViews
        self.tviews = textviews.TextViews(self)
        # Create toolbar show/hide tabs menu
        self.topbuttons.menu.create_view_menu()

        # Initialize and add Statusbar
        self.sbar = statusbar.Statusbar(self.uicore, self.tviews)
        self.sbar.create_statusbar()

        # Add textviews and statusbar to the VBox
        self.mainvb.pack_start(self.tviews, True, True, 1)
        self.mainvb.pack_start(self.sbar, False, True, 1)

        self.window.add(self.supervb)

        # Disable all until file loads
        self.disable_all()

        if self.empty_gui:
            self.show_empty_gui()

        self.show_file_data()
        self.tviews.console.add_message('Bokken ' + glob.version + ' ready')
        self.tviews.console.add_message('Starting background analysis')
        self.window.show_all()

        # Hide left tree for plain or unsupported formats
        if self.uicore.core.format == 'Hexdump':
            self.tviews.left_scrolled_window.hide()
        if not self.uicore.do_anal:
            self.topbuttons.diff_tb.set_sensitive(False)
            self.topbuttons.sections_tb.set_sensitive(False)

        dialog.destroy()
        # We make sure that we remove the reference to the scrollbar to avoid errors.
        self.uicore.core.progress_bar = None
        Gtk.main()