Rizin
unix-like reverse engineering framework and cli tools
|
Range Decoder. More...
#include "range_common.h"
Go to the source code of this file.
Classes | |
struct | lzma_range_decoder |
Macros | |
#define | rc_to_local(range_decoder, in_pos) |
#define | rc_from_local(range_decoder, in_pos) |
Stores the local copes back to the range decoder structure. More... | |
#define | rc_reset(range_decoder) |
Resets the range decoder structure. More... | |
#define | rc_is_finished(range_decoder) ((range_decoder).code == 0) |
#define | rc_normalize(seq) |
#define | rc_if_0(prob, seq) |
#define | rc_update_0(prob) |
#define | rc_update_1(prob) |
#define | rc_bit_last(prob, action0, action1, seq) |
#define | rc_bit(prob, action0, action1, seq) |
#define | rc_bit_case(prob, action0, action1, seq) case seq: rc_bit(prob, action0, action1, seq) |
#define | rc_direct(dest, seq) |
Decode a bit without using a probability. More... | |
Functions | |
static lzma_ret | rc_read_init (lzma_range_decoder *rc, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size) |
Reads the first five bytes to initialize the range decoder. More... | |
Range Decoder.
Definition in file range_decoder.h.
#define rc_bit | ( | prob, | |
action0, | |||
action1, | |||
seq | |||
) |
Decodes one bit, updates "symbol", and runs action0 or action1 depending on the decoded bit.
Definition at line 154 of file range_decoder.h.
#define rc_bit_case | ( | prob, | |
action0, | |||
action1, | |||
seq | |||
) | case seq: rc_bit(prob, action0, action1, seq) |
Like rc_bit() but add "case seq:" as a prefix. This makes the unrolled loops more readable because the code isn't littered with "case" statements. On the other hand this also makes it less readable, since spotting the places where the decoder loop may be restarted is less obvious.
Definition at line 166 of file range_decoder.h.
#define rc_bit_last | ( | prob, | |
action0, | |||
action1, | |||
seq | |||
) |
Decodes one bit and runs action0 or action1 depending on the decoded bit. This macro is used as the last step in bittree reverse decoders since those don't use "symbol" for anything else than indexing the probability arrays.
Definition at line 140 of file range_decoder.h.
#define rc_direct | ( | dest, | |
seq | |||
) |
Decode a bit without using a probability.
Definition at line 171 of file range_decoder.h.
#define rc_from_local | ( | range_decoder, | |
in_pos | |||
) |
Stores the local copes back to the range decoder structure.
Definition at line 61 of file range_decoder.h.
#define rc_if_0 | ( | prob, | |
seq | |||
) |
Start decoding a bit. This must be used together with rc_update_0() and rc_update_1():
rc_if_0(prob, seq) { rc_update_0(prob); // Do something } else { rc_update_1(prob); // Do something else }
Definition at line 111 of file range_decoder.h.
#define rc_is_finished | ( | range_decoder | ) | ((range_decoder).code == 0) |
When decoding has been properly finished, rc.code is always zero unless the input stream is corrupt. So checking this can catch some corrupt files especially if they don't have any other integrity check.
Definition at line 80 of file range_decoder.h.
#define rc_normalize | ( | seq | ) |
Read the next input byte if needed. If more input is needed but there is no more input available, "goto out" is used to jump out of the main decoder loop.
Definition at line 87 of file range_decoder.h.
#define rc_reset | ( | range_decoder | ) |
Resets the range decoder structure.
Definition at line 69 of file range_decoder.h.
#define rc_to_local | ( | range_decoder, | |
in_pos | |||
) |
Makes local copies of range decoder and *in_pos variables. Doing this improves speed significantly. The range decoder macros expect also variables ‘in’ and ‘in_size’ to be defined.
Definition at line 54 of file range_decoder.h.
#define rc_update_0 | ( | prob | ) |
Update the range decoder state and the used probability variable to match a decoded bit of 0.
Definition at line 119 of file range_decoder.h.
#define rc_update_1 | ( | prob | ) |
Update the range decoder state and the used probability variable to match a decoded bit of 1.
Definition at line 128 of file range_decoder.h.
|
inlinestatic |
Reads the first five bytes to initialize the range decoder.
Definition at line 29 of file range_decoder.h.
References lzma_range_decoder::code, in, in_pos, in_size, lzma_range_decoder::init_bytes_left, LZMA_DATA_ERROR, LZMA_OK, and LZMA_STREAM_END.
Referenced by lzma_decode().