mrcrowbar.bits module¶
-
class
mrcrowbar.bits.BitStream(buffer: BytesReadType | None = None, start_offset: int | tuple[int, int] | None = None, bytes_reverse: bool = False, bit_endian: EndianEncoding = 'big', io_endian: EndianEncoding = 'big')[source]¶ Bases:
objectCreate a BitStream instance.
- buffer
- Target byte array to read/write from. Defaults to an empty array.
- start_offset
- Position in the target to start reading from. Can be an integer byte offset, or a tuple containing the byte and bit offsets. Defaults to the start of the stream, depending on the endianness and ordering options.
- bytes_reverse
- If enabled, fetch successive bytes from the source in reverse order.
- bit_endian
- Endianness of the backing storage; either ‘big’ or ‘little’. Defaults to big (i.e. starting from the most-significant bit (0x80) through least-significant bit (0x10)).
- io_endian
- Endianness of data returned from read/write; either ‘big’ or ‘little’. Defaults to big (i.e. starting from the most-significant bit (0x80) through least-significant bit (0x10)).
-
in_bounds() → bool[source]¶ Returns True if the current position is within the bounds of the target.
-
seek(offset: int | tuple[int, int], origin: str = 'start') → None[source]¶ Seek to a location in the target.
- offset
- Relative offset in the target to move to. Can be an integer byte offset, or a tuple containing the byte and bit offsets.
- origin
- Position to measure the offset from. Can be either “start”, “current” or “end”. Defaults to “start”.
-
mrcrowbar.bits.mask(size)¶
-
mrcrowbar.bits.pack_bits(longbits: int) → int[source]¶ Crunch a 64-bit int (8 bool bytes) into a bitfield.
-
mrcrowbar.bits.read_bits(buffer: Union[bytes, bytearray, mmap.mmap, memoryview], byte_offset: int, bit_offset: int, size: int, bytes_reverse: bool = False, bit_endian: typing_extensions.Literal['big', 'little'][big, little] = 'big', io_endian: typing_extensions.Literal['big', 'little'][big, little] = 'big') → int[source]¶
-
mrcrowbar.bits.reverse_bytes(buffer: Union[bytes, bytearray, mmap.mmap, memoryview]) → bytes[source]¶
-
mrcrowbar.bits.unpack_bits(byte: int) → int[source]¶ Expand a bitfield into a 64-bit int (8 bool bytes).
-
mrcrowbar.bits.write_bits(value: int, buffer: bytearray, byte_offset: int, bit_offset: int, size: int, bytes_reverse: bool = False, bit_endian: typing_extensions.Literal['big', 'little'][big, little] = 'big', io_endian: typing_extensions.Literal['big', 'little'][big, little] = 'big') → None[source]¶