Header menu logo B2R2

ByteArray Module

Provides several useful functions to deal with byte arrays (i.e., ByteArray).

Functions and values

Function or value Description

ByteArray.extractCString bytes offset

Full Usage: ByteArray.extractCString bytes offset

Parameters:
Returns: string

Extracts a C-string (string that ends with a NULL char) from a byte array.

bytes : ByteArray
offset : int
Returns: string

ByteArray.extractCStringFromSpan span offset

Full Usage: ByteArray.extractCStringFromSpan span offset

Parameters:
Returns: string

Extracts a C-string (string that ends with a NULL char) from a ReadOnlySpan.

span : ReadOnlySpan<byte>
offset : int
Returns: string

ByteArray.findIdxs offset pattern buf

Full Usage: ByteArray.findIdxs offset pattern buf

Parameters:
    offset : uint64
    pattern : byte array
    buf : ByteArray

Returns: uint64 list

Finds and returns the absolute offsets of all positions in buf where pattern occurs. The offset parameter is added to each result to convert a buffer-relative index to an absolute address, which is useful when buf is a slice of a larger address space.

offset : uint64
pattern : byte array
buf : ByteArray
Returns: uint64 list

ByteArray.ofHexString s

Full Usage: ByteArray.ofHexString s

Parameters:
    s : string

Returns: byte array

Converts a hex string to a byte array. The input must not have a "0x" prefix and must contain an even number of hex characters. If the length is odd, the last character is silently ignored.

s : string
Returns: byte array

ByteArray.readInt32 bs offset

Full Usage: ByteArray.readInt32 bs offset

Parameters:
Returns: Result<int, ErrorCase>

Reads int32 from the given byte array at the given offset.

bs : ByteArray
offset : int
Returns: Result<int, ErrorCase>

ByteArray.toHexString bs

Full Usage: ByteArray.toHexString bs

Parameters:
Returns: string

Converts a byte array to a hex string. Only the first 32 bytes are converted to avoid producing a very long string in case of a large byte array.

bs : ByteArray
Returns: string

ByteArray.tryFindIdx offset pattern buf

Full Usage: ByteArray.tryFindIdx offset pattern buf

Parameters:
    offset : uint64
    pattern : byte array
    buf : ByteArray

Returns: uint64 option

Finds a matching byte position. If there is no match, this function will return None.

offset : uint64
pattern : byte array
buf : ByteArray
Returns: uint64 option

Type something to start searching.