MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / BinaryReader

Class BinaryReader

python/binaryview.py:10103–10484  ·  view source on GitHub ↗

``class BinaryReader`` is a convenience class for reading binary data. BinaryReader can be instantiated as follows and the rest of the document will start from this context :: >>> from binaryninja import * >>> bv = load("/bin/ls") >>> br = BinaryReader(bv) >>> hex(br.read32()) '0xfeed

Source from the content-addressed store, hash-verified

10101 return result, StringType(string_type.value)
10102
10103class BinaryReader:
10104 """
10105 ``class BinaryReader`` is a convenience class for reading binary data.
10106
10107 BinaryReader can be instantiated as follows and the rest of the document will start from this context ::
10108
10109 >>> from binaryninja import *
10110 >>> bv = load("/bin/ls")
10111 >>> br = BinaryReader(bv)
10112 >>> hex(br.read32())
10113 '0xfeedfacfL'
10114 >>>
10115
10116 Or using the optional endian parameter ::
10117
10118 >>> from binaryninja import *
10119 >>> br = BinaryReader(bv, Endianness.BigEndian)
10120 >>> hex(br.read32())
10121 '0xcffaedfeL'
10122 >>>
10123 """
10124 def __init__(self, view: 'BinaryView', endian: Optional[Endianness] = None, address: Optional[int] = None):
10125 _handle = core.BNCreateBinaryReader(view.handle)
10126 assert _handle is not None, "core.BNCreateBinaryReader returned None"
10127 self._handle = _handle
10128 if endian is None:
10129 core.BNSetBinaryReaderEndianness(self._handle, view.endianness)
10130 else:
10131 core.BNSetBinaryReaderEndianness(self._handle, endian)
10132
10133 if address is not None:
10134 self.seek(address)
10135
10136 def __del__(self):
10137 if core is not None:
10138 core.BNFreeBinaryReader(self._handle)
10139
10140 def __eq__(self, other):
10141 if not isinstance(other, self.__class__):
10142 return NotImplemented
10143 return ctypes.addressof(self._handle.contents) == ctypes.addressof(other._handle.contents)
10144
10145 def __ne__(self, other):
10146 if not isinstance(other, self.__class__):
10147 return NotImplemented
10148 return not (self == other)
10149
10150 def __hash__(self):
10151 return hash(ctypes.addressof(self._handle.contents))
10152
10153 @property
10154 def endianness(self) -> Endianness:
10155 """
10156 The Endianness to read data. (read/write)
10157
10158 :getter: returns the endianness of the reader
10159 :setter: sets the endianness of the reader (BigEndian or LittleEndian)
10160 :type: Endianness

Callers 15

get_ascii_string_atMethod · 0.70
readerMethod · 0.70
BaseClassDescriptorMethod · 0.50
BaseClassArrayMethod · 0.50
TypeDescriptorMethod · 0.50
CompleteObjectLocatorMethod · 0.50
ProcessVFTMethod · 0.50
ProcessRTTIMethod · 0.50
GetTypeInfoFunction · 0.50
SIClassTypeInfoMethod · 0.50
BaseClassTypeInfoMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected