def __exit__(self, exc_type, exc_val, exc_tb): # UI builds have their own license manager if binaryninja.core_ui_enabled(): return # Don't release if we got one from keychain if self.acquired_license: release_license()
def _rebase_bv(bv: BinaryView, dbg: DebugAdapter.DebugAdapter) -> BinaryView: """Get a rebased BinaryView for support of ASLR compatible binaries.""" new_base = dbg.target_base() if core_ui_enabled() and new_base != bv.start: dbg.quit() raise Exception('[!] Can\'t do necessary rebase in GUI, try headless operation') new_bv = bv.rebase(new_base) if new_bv is None: # None if rebasing is unecessary return bv print('[*] Rebasing bv from 0x%x to 0x%x' % (bv.start, new_base)) new_bv.update_analysis_and_wait() # required after rebase return new_bv
def run_unlock(view: BinaryView, function: Function): u = UnlockVisitor(function, function.start) u.start() if not core_ui_enabled(): import time from datetime import timedelta dot_count = 0 start = time.time() while not u.finished: time.sleep(1) print( f'[{timedelta(seconds=(time.time() - start))}] Running{"."*dot_count:<4s}\r', end="", ) dot_count = (dot_count + 1) % 4 u.join() print(f"{view.functions}")
def __enter__(self): # UI builds have their own license manager if binaryninja.core_ui_enabled(): return if not is_connected(): connect() got_auth = False if not is_authenticated(): try: # Try Keychain authenticate_with_method("Keychain", False) got_auth = True except RuntimeError: pass if not got_auth and \ os.environ.get('BN_ENTERPRISE_USERNAME') is not None and \ os.environ.get('BN_ENTERPRISE_PASSWORD') is not None: try: authenticate_with_credentials( os.environ['BN_ENTERPRISE_USERNAME'], os.environ['BN_ENTERPRISE_PASSWORD']) got_auth = True except RuntimeError: pass if not got_auth: raise RuntimeError( "Could not checkout a license: Not authenticated. Try one of the following: \n" " - Log in and check out a license for an extended time\n" " - Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n" " - Use binaryninja.enterprise.authenticate_with_credentials or authenticate_with_method in your code" ) # Keychain auth can activate a license if we have one in the keychain if not is_license_still_activated(): acquire_license(self.desired_duration) self.acquired_license = True
import os import re import time import platform import sys import traceback import tempfile from binaryninja import Architecture, BinaryView, Symbol, SymbolType, Type, Structure, StructureType, FunctionGraphType, LowLevelILOperation, MediumLevelILOperation, core_ui_enabled from . import DebugAdapter, ProcessView, dbgeng, gdblike, QueuedAdapter if core_ui_enabled(): try: # create the widgets, debugger, etc. from . import ui ui.initialize_ui() have_ui = True except (ModuleNotFoundError, ImportError, IndexError) as e: have_ui = False print(e) print("Could not initialize UI, using headless mode only") else: have_ui = False #------------------------------------------------------------------------------ # Globals #------------------------------------------------------------------------------ def get_state(bv):
def headless(self): return not(binaryninja.core_ui_enabled())
Envisioned use case: When static analysis doesn't yield a perfect call tree or a call tree for a specific input is desired. Written for well-behaved targets. """ import os import sys import time from typing import Optional, List, Tuple, Set, Dict from binaryninja.binaryview import BinaryViewType, BinaryView from binaryninja import core_ui_enabled, user_plugin_path # Add path for debugger import, needed in standalone headless execution if not core_ui_enabled(): sys.path.append(user_plugin_path()) from debugger import DebugAdapter def _get_debug_adapter() -> DebugAdapter.DebugAdapter: """Helper to define type and encapsulate this in case of changes.""" return DebugAdapter.get_adapter_for_current_system() def _get_pc(dbg: DebugAdapter.DebugAdapter) -> int: pc_names = ['rip', 'eip', 'pc'] for reg_name in pc_names: if reg_name in dbg.reg_list(): return dbg.reg_read(reg_name) raise Exception('[!] No program counter name (%s) found in registers: %s' %
return for addy, tag in tags: bv.remove_user_data_tag(addy, tag) def analyze_delphi_vmts(bv: BinaryView): type_name = 'Delphi VMTs' tt = bv.tag_types[ type_name] if type_name in bv.tag_types else bv.create_tag_type( type_name, '🔍') result = modal.show_delphi_modal(bv) if result is None: return clear_tags(bv, type_name) t = AnalyzeDelphiVmtsTask(bv, tt, result['delphi_version'], result['offset_ptr_size'], result['start'], result['end']) t.start() if binaryninja.core_ui_enabled(): PluginCommand.register('DelphiNinja\\Analyze current binary', 'Search and define strutures for Delphi VMTs', analyze_delphi_vmts)