binaryninja.binaryview.BinaryReader

class binaryninja.binaryview.BinaryReader(view, endian=None)[source]

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 = BinaryViewType['Mach-O'].open("/bin/ls")
>>> br = BinaryReader(bv)
>>> hex(br.read32())
'0xfeedfacfL'
>>>

Or using the optional endian parameter

>>> from binaryninja import *
>>> br = BinaryReader(bv, Endianness.BigEndian)
>>> hex(br.read32())
'0xcffaedfeL'
>>>
__init__(view, endian=None)[source]

Methods

__init__(view[, endian])
read(length) read returns length bytes read from the current offset, adding length to offset.
read16() read16 returns a two byte integer from offet incrementing the offset by two, using specified endianness.
read16be() read16be returns a two byte big endian integer from offet incrementing the offset by two.
read16le() read16le returns a two byte little endian integer from offet incrementing the offset by two.
read32() read32 returns a four byte integer from offet incrementing the offset by four, using specified endianness.
read32be() read32be returns a four byte big endian integer from offet incrementing the offset by four.
read32le() read32le returns a four byte little endian integer from offet incrementing the offset by four.
read64() read64 returns an eight byte integer from offet incrementing the offset by eight, using specified endianness.
read64be() read64be returns an eight byte big endian integer from offet incrementing the offset by eight.
read64le() read64le returns an eight byte little endian integer from offet incrementing the offset by eight.
read8() read8 returns a one byte integer from offet incrementing the offset.
seek(offset) seek update internal offset to offset.
seek_relative(offset) seek_relative updates the internal offset by offset.

Attributes

endianness The Endianness to read data.
eof Is end of file (read-only)
offset The current read offset (read/write).