當前位置: 首頁>>代碼示例>>Python>>正文


Python binaryninja.BinaryView方法代碼示例

本文整理匯總了Python中binaryninja.BinaryView方法的典型用法代碼示例。如果您正苦於以下問題:Python binaryninja.BinaryView方法的具體用法?Python binaryninja.BinaryView怎麽用?Python binaryninja.BinaryView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在binaryninja的用法示例。


在下文中一共展示了binaryninja.BinaryView方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_section_external

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def is_section_external(bv, sect):
  """Returns `True` if the given section contains only external references

  Args:
    bv (binja.BinaryView)
    sect (binja.binaryview.Section)
  """
  if sect.start in _EXT_SECTIONS:
    return True

  if sect.start in _INT_SECTIONS:
    return False

  if is_ELF(bv):
    if re.search(r'\.(got|plt)', sect.name):
      _EXT_SECTIONS.add(sect.start)
      return True

  if is_PE(bv):
    if '.idata' in sect.name:
      _EXT_SECTIONS.add(sect.start)
      return True

  _INT_SECTIONS.add(sect.start)
  return False 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:27,代碼來源:util.py

示例2: recover_ext_var

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def recover_ext_var(bv, pb_mod, sym):
  """ Recover external variable information

  Args:
    bv (binja.BinaryView)
    pb_mod (CFG_pb2.Module)
    sym (binja.types.Symbol)
  """
  if sym.name in EXT_DATA_MAP:
    DEBUG("Recovering external variable {} at {:x}".format(sym.name, sym.address))

    pb_extvar = pb_mod.external_vars.add()
    pb_extvar.name = sym.name
    pb_extvar.ea = sym.address
    pb_extvar.size = EXT_DATA_MAP[sym.name]
    pb_extvar.is_weak = False  # TODO: figure out how to decide this
    pb_extvar.is_thread_local = util.is_tls_section(bv, sym.address)
  else:
    ERROR("Unknown external variable {} at {:x}".format(sym.name, sym.address)) 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:21,代碼來源:cfg.py

示例3: fix_tail_call_targets

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def fix_tail_call_targets(bv, func):
  """
  Binja will "inline" tail calls into the current function, resulting in the
  same blocks appearing in multiple functions. This detects if this happened
  and defines a function at the first inlined block so nothing is duplicated

  Args:
    bv (binja.BinaryView)
    func (binja.Function)
  """
  for block in func.basic_blocks:
    # This will return a list of all basic blocks starting at the same address
    # The same block appearing in different functions (after inlining)
    # will appear as multiple `BasicBlock`s
    all_blocks = bv.get_basic_blocks_at(block.start)

    # There should only be a single block found
    if len(all_blocks) > 1:
      log.debug('Block 0x%x exists in multiple functions, defining a new function here', block.start)

      # Define a function here and reanalyze
      # All blocks contained in this new function will not be picked up
      # in the remainder of this loop after analysis
      bv.add_function(block.start)
      bv.update_analysis_and_wait() 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:27,代碼來源:cfg.py

示例4: _define_selectors

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def _define_selectors(view: BinaryView):
    __objc_selrefs = view.sections.get('__objc_selrefs')

    if __objc_selrefs is None:
        raise KeyError('This binary has no __objc_selrefs section')

    SEL = view.get_type_by_name('SEL')
    if SEL is None:
        raise TypeError('The SEL type is not defined!')

    for addr in range(__objc_selrefs.start, __objc_selrefs.end, SEL.width):
        view.define_user_data_var(addr, SEL)
        selector = int.from_bytes(view.read(addr, SEL.width), "little")
        if selector != 0:
            name = view.get_ascii_string_at(selector, 3)
            if name is not None:
                view.define_user_data_var(name.start, Type.array(Type.char(), name.length+1)) 
開發者ID:trailofbits,項目名稱:ObjCGraphView,代碼行數:19,代碼來源:selectors.py

示例5: __init__

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def __init__(self, data):
        binaryninja.BinaryView.__init__(self, file_metadata=data.file, parent_view=data)
        self.raw = data 
開發者ID:fluxchief,項目名稱:binaryninja_avr,代碼行數:5,代碼來源:__init__.py

示例6: __init__

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def __init__(self, parent, name, data):
		if not type(data) == BinaryView:
			raise Exception('expected widget data to be a BinaryView')

		self.bv = data

		QWidget.__init__(self, parent)
		DockContextHandler.__init__(self, self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)

		self.table = QTableView(self)
		self.model = DebugThreadsListModel(self.table)
		self.table.setModel(self.model)
		self.table.clicked.connect(self.threadRowClicked)

		self.item_delegate = DebugThreadsItemDelegate(self)
		self.table.setItemDelegate(self.item_delegate)

		# self.table.setSortingEnabled(True)
		self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
		self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)

		self.table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
		self.table.verticalHeader().setVisible(False)

		self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
		self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)

		self.table.resizeColumnsToContents()
		self.table.resizeRowsToContents()

		for i in range(len(self.model.columns)):
			self.table.setColumnWidth(i, self.item_delegate.sizeHint(self.table.viewOptions(), self.model.index(-1, i, QModelIndex())).width())
		self.table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)

		layout = QVBoxLayout()
		layout.setContentsMargins(0, 0, 0, 0)
		layout.setSpacing(0)
		layout.addWidget(self.table)
		self.setLayout(layout) 
開發者ID:Vector35,項目名稱:debugger,代碼行數:43,代碼來源:ThreadsWidget.py

示例7: __init__

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def __init__(self, parent, name, data):
		if not type(data) == BinaryView:
			raise Exception('expected widget data to be a BinaryView')

		self.bv = data

		QWidget.__init__(self, parent)
		DockContextHandler.__init__(self, self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)

		self.table = QTableView(self)
		self.model = DebugStackModel(self.table, data)
		self.table.setModel(self.model)

		self.item_delegate = DebugStackItemDelegate(self)
		self.table.setItemDelegate(self.item_delegate)

		# self.table.setSortingEnabled(True)
		self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
		self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)

		self.table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
		self.table.verticalHeader().setVisible(False)

		self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
		self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)

		self.table.resizeColumnsToContents()
		self.table.resizeRowsToContents()

		for i in range(len(self.model.columns)):
			self.table.setColumnWidth(i, self.item_delegate.sizeHint(self.table.viewOptions(), self.model.index(-1, i, QModelIndex())).width())

		layout = QVBoxLayout()
		layout.setContentsMargins(0, 0, 0, 0)
		layout.setSpacing(0)
		layout.addWidget(self.table)
		self.setLayout(layout) 
開發者ID:Vector35,項目名稱:debugger,代碼行數:41,代碼來源:StackWidget.py

示例8: __init__

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def __init__(self, parent, name, data):
		if not type(data) == BinaryView:
			raise Exception('expected widget data to be a BinaryView')

		self.bv = data

		QWidget.__init__(self, parent)
		DockContextHandler.__init__(self, self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)

		self.table = QTableView(self)
		self.model = DebugBreakpointsListModel(self.table, data)
		self.table.setModel(self.model)

		self.item_delegate = DebugBreakpointsItemDelegate(self)
		self.table.setItemDelegate(self.item_delegate)

		# self.table.setSortingEnabled(True)
		self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
		self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)

		self.table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
		self.table.verticalHeader().setVisible(False)

		self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
		self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)

		self.table.resizeColumnsToContents()
		self.table.resizeRowsToContents()

		for i in range(len(self.model.columns)):
			self.table.setColumnWidth(i, self.item_delegate.sizeHint(self.table.viewOptions(), self.model.index(-1, i, QModelIndex())).width())
		self.table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)

		layout = QVBoxLayout()
		layout.setContentsMargins(0, 0, 0, 0)
		layout.setSpacing(0)
		layout.addWidget(self.table)
		self.setLayout(layout) 
開發者ID:Vector35,項目名稱:debugger,代碼行數:42,代碼來源:BreakpointsWidget.py

示例9: __init__

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def __init__(self, parent, name, data):
		if not type(data) == BinaryView:
			raise Exception('expected widget data to be a BinaryView')

		self.bv = data

		QWidget.__init__(self, parent)
		DockContextHandler.__init__(self, self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)

		self.table = QTableView(self)
		self.model = DebugRegistersListModel(self.table, data)
		self.table.setModel(self.model)

		self.item_delegate = DebugRegistersItemDelegate(self)
		self.table.setItemDelegate(self.item_delegate)

		# self.table.setSortingEnabled(True)
		self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
		self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)

		self.table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
		self.table.verticalHeader().setVisible(False)

		self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
		self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)

		self.table.resizeColumnsToContents()
		self.table.resizeRowsToContents()

		for i in range(len(self.model.columns)):
			self.table.setColumnWidth(i, self.item_delegate.sizeHint(self.table.viewOptions(), self.model.index(-1, i, QModelIndex())).width())

		layout = QVBoxLayout()
		layout.setContentsMargins(0, 0, 0, 0)
		layout.setSpacing(0)
		layout.addWidget(self.table)
		self.setLayout(layout) 
開發者ID:Vector35,項目名稱:debugger,代碼行數:41,代碼來源:RegistersWidget.py

示例10: read_dword

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def read_dword(bv, addr):
  # type: (binja.BinaryView, int) -> int
  # Pad the data if fewer than 4 bytes are read
  endianness = ENDIAN_TO_STRUCT[bv.endianness]
  data = bv.read(addr, 4)
  padded_data = '{{:\x00{}4s}}'.format(endianness).format(data)
  fmt = '{}L'.format(endianness)
  return struct.unpack(fmt, padded_data)[0] 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:10,代碼來源:util.py

示例11: read_qword

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def read_qword(bv, addr):
  # type: (binja.BinaryView, int) -> int
  # Pad the data if fewer than 8 bytes are read
  endianness = ENDIAN_TO_STRUCT[bv.endianness]
  data = bv.read(addr, 8)
  padded_data = '{{:\x00{}8s}}'.format(endianness).format(data)
  fmt = '{}Q'.format(endianness)
  return struct.unpack(fmt, padded_data)[0] 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:10,代碼來源:util.py

示例12: find_symbol_name

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def find_symbol_name(bv, addr):
  """Attempt to find a symbol for a given address

  Args:
    bv (binja.BinaryView)
    addr (int): Address the symbol should point to

  Returns:
    (str): Symbol name if found, empty string otherwise

  """
  sym = bv.get_symbol_at(addr)
  if sym is not None:
    return sym.name
  return '' 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:17,代碼來源:util.py

示例13: get_func_containing

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def get_func_containing(bv, addr):
  """ Finds the function, if any, containing the given address
  Args:
    bv (binja.BinaryView)
    addr (int)

  Returns:
    binja.Function
  """
  funcs = bv.get_functions_containing(addr)
  return funcs[0] if funcs is not None else None 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:13,代碼來源:util.py

示例14: recover_section_vars

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def recover_section_vars(bv, pb_seg, sect_start, sect_end):
  """ Gather any symbols that point to data in this section

  Args:x
    bv (binja.BinaryView)
    pb_seg (CFG_pb2.Segment)
    sect_start (int)
    sect_end (int)
  """

  DEBUG("Recovering variables in [{:x}, {:x}) of section {}".format(
      sect_start, sect_end, pb_seg.name))
  DEBUG_PUSH()
  for sym in bv.get_symbols():
    # Ignore functions and externals
    if sym.type in [SymbolType.FunctionSymbol,
            SymbolType.ImportedFunctionSymbol,
            SymbolType.ImportedDataSymbol,
            SymbolType.ImportAddressSymbol]:
      continue

    if sect_start <= sym.address < sect_end:
      DEBUG("Adding variable {} at {:x}".format(sym.name, sym.address))
      pb_segvar = pb_seg.vars.add()
      pb_segvar.ea = sym.address
      pb_segvar.name = sym.name

  DEBUG_POP() 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:30,代碼來源:cfg.py

示例15: read_inst_bytes

# 需要導入模塊: import binaryninja [as 別名]
# 或者: from binaryninja import BinaryView [as 別名]
def read_inst_bytes(bv, il):
  """ Get the opcode bytes for an instruction
  Args:
    bv (binja.BinaryView)
    il (binja.LowLevelILInstruction)
  Returns:
    str
  """
  inst_len = bv.get_instruction_length(il.address)
  return bv.read(il.address, inst_len) 
開發者ID:lifting-bits,項目名稱:mcsema,代碼行數:12,代碼來源:cfg.py


注:本文中的binaryninja.BinaryView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。