def radare_dependency_check(): '''We need to verify the presence of radare2''' '''FIXME: I don't think this is the right way of doing it as we are duplicating code here and ui/radare_core.py. We should just try to init an r2 core and then get uicore.version.''' print('\tRadare availability...', end='') try: import r2.r_core print(common.console_color('\tOK', 'green')) glob.has_radare = True except: print(common.console_color("\tD'oh!", 'red')) print('You need radare and radare2 Python bindings to use the r2 ' 'backend. Download them from its web:\n' ' - http://www.radare.org\n') return if common.version_gt(glob.min_radare_version, r2.r_core.R2_VERSION): print(common.console_color("\tD'oh!", 'red')) print( common.console_color( ('Your version of r2 (%s) is not supported! ' 'It must be equal or greater than %s.' % (r2.r_core.R2_VERSION, glob.min_radare_version)), 'red')) print('Everything from here may break at any time. If you feel that ' 'this check is wrong, please file a bug at ' 'http://bokken.inguma.eu')
def radare_dependency_check(): '''We need to verify the presence of radare2''' '''FIXME: I don't think this is the right way of doing it as we are duplicating code here and ui/radare_core.py. We should just try to init an r2 core and then get uicore.version.''' print('\tRadare availability...', end='') try: import r2.r_core print(common.console_color('\tOK', 'green')) glob.has_radare = True except: print(common.console_color("\tD'oh!", 'red')) print('You need radare and radare2 Python bindings to use the r2 ' 'backend. Download them from its web:\n' ' - http://www.radare.org\n') return if common.version_gt(glob.min_radare_version, r2.r_core.R2_VERSION): print(common.console_color("\tD'oh!", 'red')) print(common.console_color(('Your version of r2 (%s) is not supported! ' 'It must be equal or greater than %s.' % (r2.r_core.R2_VERSION, glob.min_radare_version)), 'red')) print('Everything from here may break at any time. If you feel that ' 'this check is wrong, please file a bug at ' 'http://bokken.inguma.eu')
def gtkui_dependency_check(): ''' This function verifies that the dependencies that are needed by the GTK user interface are met. ''' print('\tGTK UI dependencies...', end='') # Check Gtk try: import pygtk pygtk.require('2.0') import gtk, gobject assert gtk.gtk_version >= (2, 12) assert gtk.pygtk_version >= (2, 12) print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print('You have to install GTK and PyGTK versions >=2.12 to be able to ' 'run the GTK user interface.\n' ' - On Debian-based distributions: apt-get install python-gtk2\n' ' - On Mac: sudo port install py25-gtk') sys.exit(1) # Check GtkSourceView2 try: print('\tGtkSourceView2...', end='') import gtksourceview2 print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print('GtkSourceView2 not installed! Install it for your platform:\n' ' - On Debian-based distributions: apt-get install python-gtksourceview2') sys.exit(1)
def pyew_dependency_check(): '''We need to verify the presence of pyew''' print('Checking:') print('\tPyew availability... ', end='') try: import pyew.pyew print(common.console_color('\tOK', 'green')) glob.has_pyew = True except: print(common.console_color("\tD'oh!", 'red')) print('You need pyew in order to use the pyew backend in binaries and ' 'PDFs. Download it from its web:\n' ' - http://code.google.com/p/pyew/\n') return if common.version_gt(glob.min_pyew_version, pyew.pyew.HUMAN_VERSION): print(common.console_color("\tD'oh!", 'red')) print(common.console_color(('Your version of pyew (%s) is not supported! ' 'It must be equal or greater than %s.' % (pyew.pyew.HUMAN_VERSION, glob.min_pyew_version)), 'red')) print('Everything from here may break at any time. If you feel that ' 'this check is wrong, please file a bug at ' 'http://bokken.inguma.eu')
def python_version(): print('\tPython version...', end='') if sys.version_info[0] == 3: print(common.console_color("\tD'oh!", 'red')) sys.stderr.write("Python3 not supported, install python 2.7 to run Bokken") exit(1) else: print(common.console_color('\tOK', 'green'))
def python_version(): print('\tPython version...', end='') if sys.version_info[0] == 3: print(common.console_color("\tD'oh!", 'red')) sys.stderr.write( "Python3 not supported, install python 2.7 to run Bokken") exit(1) else: print(common.console_color('\tOK', 'green'))
def tidy_dependency_check(): '''Try to use tidy''' print('\tTidy availability...', end='') try: import tidy print(common.console_color('\tOK', 'green')) except ImportError: print(common.console_color("\tD'oh!", 'red')) msg = 'No tidy module found. HTTP code won\'t be properly formatted\n' print(msg)
def psyco_dependency_check(): '''Try to use psyco''' print('\tPsyco availability...', end='') try: import psyco psyco.log() psyco.full() print(common.console_color('\tOK', 'green')) except ImportError: print(common.console_color("\tD'oh!", 'red')) print("No psyco module found. It's recommended to use it to improve performance\n")
def graphviz_dependency_check(): # Check Graphviz print("\tGraphviz binaries...", end="") if os.environ.has_key('PATH'): for path in os.environ['PATH'].split(os.pathsep): progs = __find_executables(path) if progs is not None: #print(progs) print(common.console_color('\tOK', 'green')) return print(common.console_color("\tD'oh!", 'red')) print('Graphviz not installed! Install it for your platform:\n' ' - On Debian-based distributions: apt-get install graphviz') sys.exit(1)
def graphviz_dependency_check(): # Check Graphviz print("\tGraphviz binaries...", end="") if os.environ.has_key('PATH'): for path in os.environ['PATH'].split(os.pathsep): progs = __find_executables(path) if progs is not None : #print(progs) print(common.console_color('\tOK', 'green')) return print(common.console_color("\tD'oh!", 'red')) print('Graphviz not installed! Install it for your platform:\n' ' - On Debian-based distributions: apt-get install graphviz') sys.exit( 1 )
def load_new_file(self, dialog, target): self.window.hide() self.disable_all() self.target = target # 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(common.console_color('Incorrect file argument: ' % self.target, 'red')) #sys.exit(1) # Get dialog selected file, backend and options self.backend = dialog.backend # Set user selected options self.uicore.set_options(dialog) self.uicore.backend = self.backend self.uicore.clean_fullvars() self.load_file(self.target) ui.gtk2.common.repaint() # Clean UI self.topbuttons.menu.delete_view_menu() self.tviews.left_buttons.remove_all() self.tviews.right_notebook.remove_tabs() self.tviews.left_treeview.remove_columns() self.sbar.remove_all() # Add new content self.tviews.right_notebook.create_tabs() self.topbuttons.menu.create_view_menu() self.show_file_data() self.uicore.core.progress_bar = None # Hide left tree for plain or unsupported formats if self.uicore.core.format in ['Hexdump', 'Plain Text', 'OLE2']: self.tviews.left_scrolled_window.hide() # Show UI self.enable_all() self.sbar.show_all() self.tviews.right_notebook.show_all() if self.backend == 'radare': if not self.uicore.do_anal: self.topbuttons.diff_tb.set_sensitive(False) self.window.show() dialog.destroy()
def load_new_file(self, dialog, target): self.window.hide() self.disable_all() self.target = target 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: ' % self.target, 'red')) #sys.exit(1) # Get dialog selected file, backend and options self.backend = 'radare' # Set user selected options self.uicore.set_options(dialog) self.uicore.backend = self.backend self.uicore.clean_fullvars() self.load_file(self.target) ui.gtk3.common.repaint() # Clean UI self.topbuttons.menu.delete_view_menu() self.tviews.left_buttons.remove_all() self.tviews.right_notebook.remove_tabs() self.tviews.left_treeview.remove_columns() self.sbar.remove_all() # Add new content self.tviews.right_notebook.create_tabs() self.topbuttons.menu.create_view_menu() self.show_file_data() self.uicore.core.progress_bar = None # Hide left tree for plain or unsupported formats if self.uicore.core.format == 'Hexdump': self.tviews.left_scrolled_window.hide() # Show UI self.enable_all() self.sbar.show_all() self.tviews.right_notebook.show_all() self.window.show() dialog.destroy()
def gtkui_dependency_check(): ''' This function verifies that the dependencies that are needed by the GTK user interface are met. ''' print('\tGTK UI dependencies...', end='') # Check Gtk try: import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import GObject assert Gtk.get_major_version() >= 3 print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print( 'You have to install GTK+3 and PyGObject version >= 3.0 to be able to ' 'run the GTK user interface.\n' ' - On Debian-based distributions: apt-get install python-gi\n' ' - On Mac: brew install pygobject3') sys.exit(1) # Check GtkSourceView try: print('\tGtkSourceView3...', end='') gi.require_version('GtkSource', '3.0') from gi.repository import GtkSource print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print( 'GtkSourceView3 not installed! Install it for your platform:\n' ' - On Debian-based distributions: apt-get install gir1.2-gtksource-3.0' ) sys.exit(1) # Check PyCairo for GTK+. try: print('\tPython Cairo bindings...', end='') gi.require_version('PangoCairo', '1.0') from gi.repository import PangoCairo print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print( 'Python Cairo bindings for GObject not installed! Install them for your platform:\n' ' - On Debian-based distributions: apt-get install python-gi-cairo' ) sys.exit(1)
def gtkui_dependency_check(): ''' This function verifies that the dependencies that are needed by the GTK user interface are met. ''' print('\tGTK UI dependencies...', end='') # Check Gtk try: import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import GObject assert Gtk.get_major_version() >= 3 print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print('You have to install GTK+3 and PyGObject version >= 3.0 to be able to ' 'run the GTK user interface.\n' ' - On Debian-based distributions: apt-get install python-gi\n' ' - On Mac: brew install pygobject3') sys.exit(1) # Check GtkSourceView try: print('\tGtkSourceView3...', end='') gi.require_version('GtkSource', '3.0') from gi.repository import GtkSource print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print('GtkSourceView3 not installed! Install it for your platform:\n' ' - On Debian-based distributions: apt-get install gir1.2-gtksource-3.0') sys.exit(1) # Check PyCairo for GTK+. try: print('\tPython Cairo bindings...', end='') gi.require_version('PangoCairo', '1.0') from gi.repository import PangoCairo print(common.console_color('\tOK', 'green')) except: print(common.console_color("\tD'oh!", 'red')) print('Python Cairo bindings for GObject not installed! Install them for your platform:\n' ' - On Debian-based distributions: apt-get install python-gi-cairo') sys.exit(1)
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()
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. if not glob.has_pyew and not glob.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) # 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 # Launch file selection dialog dialog = file_dialog.FileDialog(glob.has_pyew, glob.has_radare, self.backend, self.target, True) resp = dialog.run() if resp == gtk.RESPONSE_DELETE_EVENT or resp == gtk.RESPONSE_REJECT: return None # Get dialog selected file, backend and options self.target = dialog.file self.backend = dialog.backend # Load selected core if self.backend == 'pyew': import ui.pyew_core as core elif self.backend == 'radare': import ui.radare_core as core else: print 'Unknown backend: %s' % self.backend sys.exit(1) self.uicore = core.Core(dialog) # Create a global object under glob. glob.core = self.uicore # 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(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.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_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.gtk2.common.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) ui.gtk2.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) # 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) # 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.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.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()