Latest available version: IDA and decompilers v8.4.240320sp1 see all releases
Hex-Rays logo State-of-the-art binary code analysis tools
email icon
bitrange_t Class Reference

This class manages the offset and size of a value that occupies a number of contiguous bits within some container - generally a byte array. More...

#include <bitrange.hpp>

Public Member Functions

 bitrange_t (uint16 bit_ofs=0, uint16 size_in_bits=0)
 Constructor.
 
void init (uint16 bit_ofs, uint16 size_in_bits)
 Initialize offset and size to given values.
 
void reset ()
 Make the bitrange empty.
 
bool empty () const
 Is the bitrange empty?
 
uint bitoff () const
 Get offset of 1st bit.
 
uint bitsize () const
 Get size of the value in bits.
 
uint bytesize () const
 Size of the value in bytes.
 
uint64 mask64 () const
 Convert to mask of 64 bits.
 
bool has_common (const bitrange_t &r) const
 Does have common bits with another bitrange?
 
bool apply_mask (const bitrange_t &subrange)
 Apply mask to a bitrange. More...
 
void intersect (const bitrange_t &r)
 Intersect two ranges.
 
void create_union (const bitrange_t &r)
 Create union of 2 ranges including the hole between them.
 
bool sub (const bitrange_t &r)
 Subtract a bitrange.
 
void shift_down (uint cnt)
 Shift range down (left)
 
void shift_up (uint cnt)
 Shift range up (right)
 
template<class T >
void assign_max_nonzero (T mask)
 Initialize bitrange_t with offset/size defined by given mask.
 
Extract

Extract a value from 'src' according to the bitrange

Parameters
dstvector the extracted value will be stored to
srcsource buffer
src_sizesize of source buffer
is_mfis Msb First? (TRUE-big endian, FALSE-little endian)
bool extract (bytevec_t *dst, const void *src, size_t src_size, bool is_mf) const
 
bool extract (void *dst, size_t dst_size, const void *src, size_t src_size, bool is_mf) const
 
Inject

Inject a value into 'dst' according to the bitrange

Parameters
dsta buffer the value will be injected into
dst_sizesize of buffer
srcsource value
is_mfis Msb First? (TRUE-big endian, FALSE-little endian)
bool inject (void *dst, size_t dst_size, const void *src, size_t src_size, bool is_mf) const
 
bool inject (void *dst, size_t dst_size, const bytevec_t &src, bool is_mf) const
 

Detailed Description

This class manages the offset and size of a value that occupies a number of contiguous bits within some container - generally a byte array.

A special state - empty range (both offset and size are zeroes) - determines the value as all bits of the container.

Member Function Documentation

◆ apply_mask()

bool bitrange_t::apply_mask ( const bitrange_t subrange)
inline

Apply mask to a bitrange.

Parameters
subrangerange *inside* the main bitrange to keep After this operation the main bitrange will be truncated to have only the bits that are specified by subrange. Example: [off=8,nbits=4], subrange[off=1,nbits=2] => [off=9,nbits=2]
Returns
success

The documentation for this class was generated from the following file: