Rizin
unix-like reverse engineering framework and cli tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Macros Modules Pages
readbits.h File Reference

Go to the source code of this file.

Macros

#define CHAR_BIT   (8)
 
#define BITBUF_WIDTH   (sizeof(bit_buffer) * CHAR_BIT)
 
#define INIT_BITS
 
#define STORE_BITS
 
#define RESTORE_BITS
 
#define ENSURE_BITS(nbits)
 
#define READ_BITS(val, nbits)
 
#define READ_MANY_BITS(val, bits)
 
#define PEEK_BITS(nbits)   (bit_buffer & ((1 << (nbits))-1))
 
#define REMOVE_BITS(nbits)   ((bit_buffer >>= (nbits)), (bits_left -= (nbits)))
 
#define INJECT_BITS(bitdata, nbits)
 
#define READ_IF_NEEDED
 

Functions

static int read_input (BITS_TYPE *p)
 

Macro Definition Documentation

◆ BITBUF_WIDTH

#define BITBUF_WIDTH   (sizeof(bit_buffer) * CHAR_BIT)

Definition at line 101 of file readbits.h.

◆ CHAR_BIT

#define CHAR_BIT   (8)

Definition at line 99 of file readbits.h.

◆ ENSURE_BITS

#define ENSURE_BITS (   nbits)
Value:
do { \
while (bits_left < (nbits)) READ_BYTES; \
} while (0)
#define READ_BYTES
Definition: lzxd.c:86

Definition at line 125 of file readbits.h.

◆ INIT_BITS

#define INIT_BITS
Value:
do { \
BITS_VAR->i_ptr = &BITS_VAR->inbuf[0]; \
BITS_VAR->i_end = &BITS_VAR->inbuf[0]; \
BITS_VAR->bit_buffer = 0; \
BITS_VAR->bits_left = 0; \
BITS_VAR->input_end = 0; \
} while (0)
#define BITS_VAR
Definition: lzxd.c:84

Definition at line 103 of file readbits.h.

◆ INJECT_BITS

#define INJECT_BITS (   bitdata,
  nbits 
)
Value:
((bit_buffer |= \
(bitdata) << bits_left), (bits_left += (nbits)))

Definition at line 155 of file readbits.h.

◆ PEEK_BITS

#define PEEK_BITS (   nbits)    (bit_buffer & ((1 << (nbits))-1))

Definition at line 153 of file readbits.h.

◆ READ_BITS

#define READ_BITS (   val,
  nbits 
)
Value:
do { \
ENSURE_BITS(nbits); \
(val) = PEEK_BITS(nbits); \
REMOVE_BITS(nbits); \
} while (0)
ut16 val
Definition: armass64_const.h:6
#define PEEK_BITS(nbits)
Definition: readbits.h:153

Definition at line 129 of file readbits.h.

◆ READ_IF_NEEDED

#define READ_IF_NEEDED
Value:
do { \
if (i_ptr >= i_end) { \
return BITS_VAR->error; \
i_ptr = BITS_VAR->i_ptr; \
i_end = BITS_VAR->i_end; \
} \
} while (0)
static int read_input(BITS_TYPE *p)
Definition: readbits.h:183

Definition at line 174 of file readbits.h.

◆ READ_MANY_BITS

#define READ_MANY_BITS (   val,
  bits 
)
Value:
do { \
unsigned char needed = (bits), bitrun; \
(val) = 0; \
while (needed > 0) { \
if (bits_left <= (BITBUF_WIDTH - 16)) READ_BYTES; \
bitrun = (bits_left < needed) ? bits_left : needed; \
(val) = ((val) << bitrun) | PEEK_BITS(bitrun); \
REMOVE_BITS(bitrun); \
needed -= bitrun; \
} \
} while (0)
int bits(struct state *s, int need)
Definition: blast.c:72
#define BITBUF_WIDTH
Definition: readbits.h:101
#define REMOVE_BITS(nbits)
Definition: readbits.h:154
while(len< limit &&buf1[len]==buf2[len])++len

Definition at line 135 of file readbits.h.

◆ REMOVE_BITS

#define REMOVE_BITS (   nbits)    ((bit_buffer >>= (nbits)), (bits_left -= (nbits)))

Definition at line 154 of file readbits.h.

◆ RESTORE_BITS

#define RESTORE_BITS
Value:
do { \
i_ptr = BITS_VAR->i_ptr; \
i_end = BITS_VAR->i_end; \
bit_buffer = BITS_VAR->bit_buffer; \
bits_left = BITS_VAR->bits_left; \
} while (0)

Definition at line 118 of file readbits.h.

◆ STORE_BITS

#define STORE_BITS
Value:
do { \
BITS_VAR->i_ptr = i_ptr; \
BITS_VAR->i_end = i_end; \
BITS_VAR->bit_buffer = bit_buffer; \
BITS_VAR->bits_left = bits_left; \
} while (0)

Definition at line 111 of file readbits.h.

Function Documentation

◆ read_input()

static int read_input ( BITS_TYPE p)
static

Definition at line 183 of file readbits.h.

183  {
184  int read = p->sys->read(p->input, &p->inbuf[0], (int)p->inbuf_size);
185  if (read < 0) return p->error = MSPACK_ERR_READ;
186 
187  /* we might overrun the input stream by asking for bits we don't use,
188  * so fake 2 more bytes at the end of input */
189  if (read == 0) {
190  if (p->input_end) {
191  D(("out of input bytes"))
192  return p->error = MSPACK_ERR_READ;
193  }
194  else {
195  read = 2;
196  p->inbuf[0] = p->inbuf[1] = 0;
197  p->input_end = 1;
198  }
199  }
200 
201  /* update i_ptr and i_end */
202  p->i_ptr = &p->inbuf[0];
203  p->i_end = &p->inbuf[read];
204  return MSPACK_ERR_OK;
205 }
#define D
Definition: block.c:38
#define MSPACK_ERR_OK
Definition: mspack.h:485
#define MSPACK_ERR_READ
Definition: mspack.h:491
void * p
Definition: libc.cpp:67
void error(const char *msg)
Definition: untgz.c:593
else
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References D, MSPACK_ERR_OK, MSPACK_ERR_READ, p, and read().