State-of-the-art binary code analysis tools
bytevec_t Class Reference

Detailed Description

Vector of bytes (use for dynamic memory)

Inherits qvector< uchar >.

Inherited by relobj_t, and reloc_info_t.

Public Member Functions

 bytevec_t ()
 Constructor.
 
 bytevec_t (const void *buf, size_t sz)
 Constructor - fill bytevec with 'sz' bytes from 'buf'.
 
bytevec_tappend (const void *buf, size_t sz)
 Append bytes to the bytevec. More...
 
void pack_db (uint8 x)
 Pack a byte and append the result to the bytevec.
 
void pack_dw (uint16 x)
 Pack a word and append the result to the bytevec.
 
void pack_dd (uint32 x)
 Pack a dword and append the result to the bytevec.
 
void pack_dq (uint64 x)
 Pack a quadword and append the result to the bytevec.
 
void pack_ea (ea_t x)
 Pack an ea value and append the result to the bytevec.
 
void pack_ea64 (ea64_t ea)
 Pack an ea value (64bits) and append the result to the bytevec We pass ea_t as a 64-bit quantity (to be able to debug 32-bit programs with ida64) adding 1 to the address ensures that BADADDR is passed correctly. More...
 
void pack_ds (const char *x)
 Pack a string (length+contents) and append the result to the bytevec.
 
void pack_str (const char *str)
 Pack a string (zero-terminated) and append the result to the bytevec.
 
void pack_str (const qstring &s)
 Pack a string (zero-terminated) and append the result to the bytevec.
 
void pack_buf (const void *buf, size_t len)
 Pack an object of size 'len' and append the result to the bytevec.
 
void pack_bytevec (const bytevec_t &b)
 Pack an object of size 'len' and append the result to the bytevec.
 
void pack_eavec (ea_t ea, const eavec_t &vec)
 Pack an eavec and append the result to the bytevec. More...
 
bytevec_tgrowfill (size_t sz, uchar filler=0)
 Grow the bytevec and fill with a value. More...
 
void inject (void *buf, size_t len)
 See qvector::inject(T *, size_t)
 
void tohex (qstring *out) const
 Append the hexadecimal representation of bytes to the string.
 
bool fromhex (const qstring &str)
 Initialize from a hexadecimal string It returns 'false' if the string is invalid.
 
bool test_bit (size_t bit) const
 Is the specified bit set in the bytevec?
 
void set_bit (size_t bit)
 Set the specified bit.
 
void clear_bit (size_t bit)
 Clear the specified bit.
 
void set_all_bits (size_t nbits)
 See set_all_bits(uchar *, size_t)
 
void clear_all_bits (size_t nbits)
 See clear_all_bits(uchar *, size_t)
 
void set_bits (const bytevec_t &b)
 For each bit that is set in 'b', set the corresponding bit in this bytevec.
 
void set_bits (size_t low, size_t high)
 Set each bit between [low, high)
 
void clear_bits (const bytevec_t &b)
 For each bit that is set in 'b', the clear the corresponding bit in this bytevec.
 
void clear_bits (size_t low, size_t high)
 Clear each bit between [low, high)
 
- Public Member Functions inherited from qvector< uchar >
 qvector (void)
 Constructor.
 
 qvector (const qvector< uchar > &x)
 Constructor - creates a new qvector identical to 'x'.
 
 qvector (qvector< uchar > &&x) noexcept
 Move constructor.
 
 ~qvector (void)
 Destructor.
 
void push_back (const uchar &x)
 Append a new element to the end the qvector.
 
void push_back (uchar &&x)
 Append a new element to the end the qvector with a move semantics.
 
ucharpush_back (void)
 Append a new empty element to the end of the qvector. More...
 
void pop_back (void)
 Remove the last element in the qvector.
 
size_t size (void) const
 Get the number of elements in the qvector.
 
bool empty (void) const
 Does the qvector have 0 elements?
 
const ucharoperator[] (size_t _idx) const
 Allows use of typical c-style array indexing for qvectors.
 
ucharoperator[] (size_t _idx)
 Allows use of typical c-style array indexing for qvectors.
 
const ucharat (size_t _idx) const
 Get element at index '_idx'.
 
ucharat (size_t _idx)
 Get element at index '_idx'.
 
const ucharfront (void) const
 Get the first element in the qvector.
 
ucharfront (void)
 Get the first element in the qvector.
 
const ucharback (void) const
 Get the last element in the qvector.
 
ucharback (void)
 Get the last element in the qvector.
 
void qclear (void)
 Destroy all elements but do not free memory.
 
void clear (void)
 Destroy all elements and free memory.
 
qvector< uchar > & operator= (const qvector< uchar > &x)
 Allow assignment of one qvector to another using '='.
 
qvector< uchar > & operator= (qvector< uchar > &&x) noexcept
 Move assignment operator.
 
void resize (size_t _newsize, const uchar &x)
 Resize to the given size. More...
 
void resize (size_t _newsize)
 Same as resize(size_t, const T &), but extra space is filled with empty elements.
 
void resize_noinit (size_t _newsize)
 
void grow (const uchar &x=uchar())
 Add an element to the end of the qvector, which will be a new T() if x is not given.
 
size_t capacity (void) const
 Get the number of elements that this qvector can contain - not the same as the number of elements currently in the qvector (size())
 
void reserve (size_t cnt)
 Increase the capacity of the qvector. More...
 
void truncate (void)
 Shrink the capacity down to the current number of elements.
 
void swap (qvector< uchar > &r) noexcept
 Replace all attributes of this qvector with that of 'r', and vice versa. More...
 
ucharextract (void)
 Empty the qvector and return a pointer to it's contents. More...
 
void inject (uchar *s, size_t len)
 Populate the qvector with dynamic memory. More...
 
bool operator== (const qvector< uchar > &r) const
 Allow ability to test the equality of two qvectors using '=='.
 
bool operator != (const qvector< uchar > &r) const
 Allow ability to test equality of two qvectors using '!='.
 
iterator begin (void)
 Get an iterator that points to the first element in the qvector.
 
const_iterator begin (void) const
 Get a const iterator that points to the first element in the qvector.
 
iterator end (void)
 Get an iterator that points to the end of the qvector (NOT the last element)
 
const_iterator end (void) const
 Get a const iterator that points to the end of the qvector (NOT the last element)
 
iterator insert (iterator it, const uchar &x)
 Insert an element into the qvector at a specified position. More...
 
iterator insert (iterator it, uchar &&x)
 Insert an element into the qvector with a move semantics.
 
iterator insert (iterator it, it2 first, it2 last)
 Insert a several elements to the qvector at a specified position. More...
 
iterator erase (iterator it)
 Remove an element from the qvector. More...
 
iterator erase (iterator first, iterator last)
 Remove a subset of the qvector. More...
 
iterator find (const uchar &x)
 Find an element in the qvector. More...
 
const_iterator find (const uchar &x) const
 Find an element in the qvector. More...
 
ssize_t index (const uchar &x) const
 Find index of the specified value or return -1.
 
void add (const uchar &x)
 Add an element to the end of the qvector.
 
void add (uchar &&x)
 
bool has (const uchar &x) const
 Does the qvector contain x?
 
bool add_unique (const uchar &x)
 Add an element to the end of the qvector - only if it isn't already present. More...
 
bool del (const uchar &x)
 Find an element and remove it. More...
 
const char * dstr (void) const
 

Additional Inherited Members

- Public Types inherited from qvector< uchar >
typedef uchar value_type
 the type of objects contained in this qvector
 
typedef uchariterator
 
typedef const ucharconst_iterator
 

Member Function Documentation

◆ append()

bytevec_t& bytevec_t::append ( const void *  buf,
size_t  sz 
)
inline

Append bytes to the bytevec.

Parameters
bufpointer to buffer that will be appended
szsize of buffer

◆ pack_ea64()

void bytevec_t::pack_ea64 ( ea64_t  ea)
inline

Pack an ea value (64bits) and append the result to the bytevec We pass ea_t as a 64-bit quantity (to be able to debug 32-bit programs with ida64) adding 1 to the address ensures that BADADDR is passed correctly.

without it, 32-bit server would return 0xffffffff and ida64 would not consider it as a BADADDR.

◆ pack_eavec()

void bytevec_t::pack_eavec ( ea_t  ea,
const eavec_t vec 
)
inline

Pack an eavec and append the result to the bytevec.

Also see unpack_eavec().

Parameters
eawhen we pack an eavec, we only store the differences between each value and this parameter.
This is because groups of ea values will likely be similar, and therefore the differences will usually be small.
A good example is packing the addresses of a function prologue.
One can pass the start ea of the function as this parameter, which results in a quick and efficient packing/unpacking.
(Just be sure to use the func's start ea when unpacking, of course)
veceavec to pack

◆ growfill()

bytevec_t& bytevec_t::growfill ( size_t  sz,
uchar  filler = 0 
)
inline

Grow the bytevec and fill with a value.

Parameters
sznumber of bytes to add to bytevec
fillerfiller value

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