Rizin
unix-like reverse engineering framework and cli tools
lzma_common.h File Reference

Private definitions common to LZMA encoder and decoder. More...

#include "common.h"
#include "range_common.h"

Go to the source code of this file.

Macros

#define POS_STATES_MAX   (1 << LZMA_PB_MAX)
 
#define STATES   12
 Total number of states. More...
 
#define LIT_STATES   7
 The lowest 7 states indicate that the previous state was a literal. More...
 
#define update_literal(state)
 Indicate that the latest state was a literal. More...
 
#define update_match(state)    state = ((state) < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH)
 Indicate that the latest state was a match. More...
 
#define update_long_rep(state)    state = ((state) < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP)
 Indicate that the latest state was a long repeated match. More...
 
#define update_short_rep(state)    state = ((state) < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP)
 Indicate that the latest state was a short match. More...
 
#define is_literal_state(state)    ((state) < LIT_STATES)
 Test if the previous state was a literal. More...
 
#define LITERAL_CODER_SIZE   0x300
 
#define LITERAL_CODERS_MAX   (1 << LZMA_LCLP_MAX)
 Maximum number of literal coders. More...
 
#define literal_subcoder(probs, lc, lp_mask, pos, prev_byte)
 
#define MATCH_LEN_MIN   2
 
#define LEN_LOW_BITS   3
 
#define LEN_LOW_SYMBOLS   (1 << LEN_LOW_BITS)
 
#define LEN_MID_BITS   3
 
#define LEN_MID_SYMBOLS   (1 << LEN_MID_BITS)
 
#define LEN_HIGH_BITS   8
 
#define LEN_HIGH_SYMBOLS   (1 << LEN_HIGH_BITS)
 
#define LEN_SYMBOLS   (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
 
#define MATCH_LEN_MAX   (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
 
#define DIST_STATES   4
 
#define get_dist_state(len)
 
#define DIST_SLOT_BITS   6
 
#define DIST_SLOTS   (1 << DIST_SLOT_BITS)
 
#define DIST_MODEL_START   4
 
#define DIST_MODEL_END   14
 
#define FULL_DISTANCES_BITS   (DIST_MODEL_END / 2)
 
#define FULL_DISTANCES   (1 << FULL_DISTANCES_BITS)
 
#define ALIGN_BITS   4
 
#define ALIGN_SIZE   (1 << ALIGN_BITS)
 
#define ALIGN_MASK   (ALIGN_SIZE - 1)
 
#define REPS   4
 

Enumerations

enum  lzma_lzma_state {
  STATE_LIT_LIT , STATE_MATCH_LIT_LIT , STATE_REP_LIT_LIT , STATE_SHORTREP_LIT_LIT ,
  STATE_MATCH_LIT , STATE_REP_LIT , STATE_SHORTREP_LIT , STATE_LIT_MATCH ,
  STATE_LIT_LONGREP , STATE_LIT_SHORTREP , STATE_NONLIT_MATCH , STATE_NONLIT_REP
}
 

Functions

static bool is_lclppb_valid (const lzma_options_lzma *options)
 Validates lc, lp, and pb. More...
 
static void literal_init (probability(*probs)[LITERAL_CODER_SIZE], uint32_t lc, uint32_t lp)
 

Detailed Description

Private definitions common to LZMA encoder and decoder.

Definition in file lzma_common.h.

Macro Definition Documentation

◆ ALIGN_BITS

#define ALIGN_BITS   4

Definition at line 217 of file lzma_common.h.

◆ ALIGN_MASK

#define ALIGN_MASK   (ALIGN_SIZE - 1)

Definition at line 219 of file lzma_common.h.

◆ ALIGN_SIZE

#define ALIGN_SIZE   (1 << ALIGN_BITS)

Definition at line 218 of file lzma_common.h.

◆ DIST_MODEL_END

#define DIST_MODEL_END   14

Definition at line 209 of file lzma_common.h.

◆ DIST_MODEL_START

#define DIST_MODEL_START   4

Definition at line 198 of file lzma_common.h.

◆ DIST_SLOT_BITS

#define DIST_SLOT_BITS   6

Definition at line 189 of file lzma_common.h.

◆ DIST_SLOTS

#define DIST_SLOTS   (1 << DIST_SLOT_BITS)

Definition at line 190 of file lzma_common.h.

◆ DIST_STATES

#define DIST_STATES   4

Definition at line 179 of file lzma_common.h.

◆ FULL_DISTANCES

#define FULL_DISTANCES   (1 << FULL_DISTANCES_BITS)

Definition at line 213 of file lzma_common.h.

◆ FULL_DISTANCES_BITS

#define FULL_DISTANCES_BITS   (DIST_MODEL_END / 2)

Definition at line 212 of file lzma_common.h.

◆ get_dist_state

#define get_dist_state (   len)
Value:
: DIST_STATES - 1)
size_t len
Definition: 6502dis.c:15
#define MATCH_LEN_MIN
Definition: lzma_common.h:150
#define DIST_STATES
Definition: lzma_common.h:179

Definition at line 182 of file lzma_common.h.

◆ is_literal_state

#define is_literal_state (   state)     ((state) < LIT_STATES)

Test if the previous state was a literal.

Definition at line 100 of file lzma_common.h.

◆ LEN_HIGH_BITS

#define LEN_HIGH_BITS   8

Definition at line 162 of file lzma_common.h.

◆ LEN_HIGH_SYMBOLS

#define LEN_HIGH_SYMBOLS   (1 << LEN_HIGH_BITS)

Definition at line 163 of file lzma_common.h.

◆ LEN_LOW_BITS

#define LEN_LOW_BITS   3

Definition at line 158 of file lzma_common.h.

◆ LEN_LOW_SYMBOLS

#define LEN_LOW_SYMBOLS   (1 << LEN_LOW_BITS)

Definition at line 159 of file lzma_common.h.

◆ LEN_MID_BITS

#define LEN_MID_BITS   3

Definition at line 160 of file lzma_common.h.

◆ LEN_MID_SYMBOLS

#define LEN_MID_SYMBOLS   (1 << LEN_MID_BITS)

Definition at line 161 of file lzma_common.h.

◆ LEN_SYMBOLS

#define LEN_SYMBOLS   (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)

Definition at line 164 of file lzma_common.h.

◆ LIT_STATES

#define LIT_STATES   7

The lowest 7 states indicate that the previous state was a literal.

Definition at line 76 of file lzma_common.h.

◆ LITERAL_CODER_SIZE

#define LITERAL_CODER_SIZE   0x300

Each literal coder is divided in three sections:

  • 0x001-0x0FF: Without match byte
  • 0x101-0x1FF: With match byte; match bit is 0
  • 0x201-0x2FF: With match byte; match bit is 1

Match byte is used when the previous LZMA symbol was something else than a literal (that is, it was some kind of match).

Definition at line 115 of file lzma_common.h.

◆ LITERAL_CODERS_MAX

#define LITERAL_CODERS_MAX   (1 << LZMA_LCLP_MAX)

Maximum number of literal coders.

Definition at line 118 of file lzma_common.h.

◆ literal_subcoder

#define literal_subcoder (   probs,
  lc,
  lp_mask,
  pos,
  prev_byte 
)
Value:
((probs)[(((pos) & (lp_mask)) << (lc)) \
+ ((uint32_t)(prev_byte) >> (8U - (lc)))])
unsigned int uint32_t
Definition: sftypes.h:29
int pos
Definition: main.c:11

Locate the literal coder for the next literal byte. The choice depends on

  • the lowest literal_pos_bits bits of the position of the current byte; and
  • the highest literal_context_bits bits of the previous byte.

Definition at line 124 of file lzma_common.h.

◆ MATCH_LEN_MAX

#define MATCH_LEN_MAX   (MATCH_LEN_MIN + LEN_SYMBOLS - 1)

Definition at line 168 of file lzma_common.h.

◆ MATCH_LEN_MIN

#define MATCH_LEN_MIN   2

Definition at line 150 of file lzma_common.h.

◆ POS_STATES_MAX

#define POS_STATES_MAX   (1 << LZMA_PB_MAX)

Maximum number of position states. A position state is the lowest pos bits number of bits of the current uncompressed offset. In some places there are different sets of probabilities for different pos states.

Definition at line 28 of file lzma_common.h.

◆ REPS

#define REPS   4

Definition at line 223 of file lzma_common.h.

◆ STATES

#define STATES   12

Total number of states.

Definition at line 73 of file lzma_common.h.

◆ update_literal

#define update_literal (   state)
Value:
? (state) - 3 \
: (state) - 6))
@ STATE_LIT_LIT
Definition: lzma_common.h:57
@ STATE_LIT_SHORTREP
Definition: lzma_common.h:66
@ STATE_SHORTREP_LIT_LIT
Definition: lzma_common.h:60
Definition: dis.h:43

Indicate that the latest state was a literal.

Definition at line 80 of file lzma_common.h.

◆ update_long_rep

#define update_long_rep (   state)     state = ((state) < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP)

Indicate that the latest state was a long repeated match.

Definition at line 92 of file lzma_common.h.

◆ update_match

#define update_match (   state)     state = ((state) < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH)

Indicate that the latest state was a match.

Definition at line 88 of file lzma_common.h.

◆ update_short_rep

#define update_short_rep (   state)     state = ((state) < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP)

Indicate that the latest state was a short match.

Definition at line 96 of file lzma_common.h.

Enumeration Type Documentation

◆ lzma_lzma_state

This enum is used to track which events have occurred most recently and in which order. This information is used to predict the next event.

Events:

  • Literal: One 8-bit byte
  • Match: Repeat a chunk of data at some distance
  • Long repeat: Multi-byte match at a recently seen distance
  • Short repeat: One-byte repeat at a recently seen distance

The event names are in from STATE_oldest_older_previous. REP means either short or long repeated match, and NONLIT means any non-literal.

Enumerator
STATE_LIT_LIT 
STATE_MATCH_LIT_LIT 
STATE_REP_LIT_LIT 
STATE_SHORTREP_LIT_LIT 
STATE_MATCH_LIT 
STATE_REP_LIT 
STATE_SHORTREP_LIT 
STATE_LIT_MATCH 
STATE_LIT_LONGREP 
STATE_LIT_SHORTREP 
STATE_NONLIT_MATCH 
STATE_NONLIT_REP 

Definition at line 56 of file lzma_common.h.

56  {
lzma_lzma_state
Definition: lzma_common.h:56
@ STATE_MATCH_LIT_LIT
Definition: lzma_common.h:58
@ STATE_NONLIT_MATCH
Definition: lzma_common.h:67
@ STATE_LIT_LONGREP
Definition: lzma_common.h:65
@ STATE_SHORTREP_LIT
Definition: lzma_common.h:63
@ STATE_NONLIT_REP
Definition: lzma_common.h:68
@ STATE_REP_LIT_LIT
Definition: lzma_common.h:59
@ STATE_LIT_MATCH
Definition: lzma_common.h:64
@ STATE_REP_LIT
Definition: lzma_common.h:62
@ STATE_MATCH_LIT
Definition: lzma_common.h:61

Function Documentation

◆ is_lclppb_valid()

static bool is_lclppb_valid ( const lzma_options_lzma options)
inlinestatic

Validates lc, lp, and pb.

Definition at line 33 of file lzma_common.h.

34 {
35  return options->lc <= LZMA_LCLP_MAX && options->lp <= LZMA_LCLP_MAX
36  && options->lc + options->lp <= LZMA_LCLP_MAX
37  && options->pb <= LZMA_PB_MAX;
38 }
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
#define LZMA_PB_MAX
Definition: lzma12.h:318
#define LZMA_LCLP_MAX
Definition: lzma12.h:283

References LZMA_LCLP_MAX, LZMA_PB_MAX, and options.

Referenced by is_options_valid(), lzma_decoder_init(), lzma_lzma_decoder_memusage(), and lzma_lzma_lclppb_encode().

◆ literal_init()

static void literal_init ( probability(*)  probs[LITERAL_CODER_SIZE],
uint32_t  lc,
uint32_t  lp 
)
inlinestatic

Definition at line 130 of file lzma_common.h.

132 {
133  assert(lc + lp <= LZMA_LCLP_MAX);
134 
135  const uint32_t coders = 1U << (lc + lp);
136 
137  for (uint32_t i = 0; i < coders; ++i)
138  for (uint32_t j = 0; j < LITERAL_CODER_SIZE; ++j)
139  bit_reset(probs[i][j]);
140 
141  return;
142 }
lzma_index ** i
Definition: index.h:629
#define LITERAL_CODER_SIZE
Definition: lzma_common.h:115
assert(limit<=UINT32_MAX/2)
#define bit_reset(prob)
Definition: range_common.h:37

References assert(), bit_reset, i, LITERAL_CODER_SIZE, and LZMA_LCLP_MAX.

Referenced by lzma_decoder_reset(), and lzma_lzma_encoder_reset().