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

LZMA1 and LZMA2 filters. More...

Go to the source code of this file.

Classes

struct  lzma_options_lzma
 Options specific to the LZMA1 and LZMA2 filters. More...
 

Macros

#define LZMA_FILTER_LZMA1   LZMA_VLI_C(0x4000000000000001)
 LZMA1 Filter ID. More...
 
#define LZMA_FILTER_LZMA2   LZMA_VLI_C(0x21)
 LZMA2 Filter ID. More...
 
#define LZMA_DICT_SIZE_MIN   UINT32_C(4096)
 
#define LZMA_DICT_SIZE_DEFAULT   (UINT32_C(1) << 23)
 
#define LZMA_LCLP_MIN   0
 
#define LZMA_LCLP_MAX   4
 
#define LZMA_LC_DEFAULT   3
 
#define LZMA_LP_DEFAULT   0
 
#define LZMA_PB_MIN   0
 
#define LZMA_PB_MAX   4
 
#define LZMA_PB_DEFAULT   2
 

Enumerations

enum  lzma_match_finder {
  LZMA_MF_HC3 = 0x03 , LZMA_MF_HC4 = 0x04 , LZMA_MF_BT2 = 0x12 , LZMA_MF_BT3 = 0x13 ,
  LZMA_MF_BT4 = 0x14
}
 Match finders. More...
 
enum  lzma_mode { LZMA_MODE_FAST = 1 , LZMA_MODE_NORMAL = 2 }
 Compression modes. More...
 

Functions

 LZMA_API (lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder) lzma_nothrow lzma_attr_const
 Test if given match finder is supported. More...
 

Variables

uint32_t preset lzma_nothrow
 

Detailed Description

LZMA1 and LZMA2 filters.

Definition in file lzma12.h.

Macro Definition Documentation

◆ LZMA_DICT_SIZE_DEFAULT

#define LZMA_DICT_SIZE_DEFAULT   (UINT32_C(1) << 23)

Definition at line 219 of file lzma12.h.

◆ LZMA_DICT_SIZE_MIN

#define LZMA_DICT_SIZE_MIN   UINT32_C(4096)

Definition at line 218 of file lzma12.h.

◆ LZMA_FILTER_LZMA1

#define LZMA_FILTER_LZMA1   LZMA_VLI_C(0x4000000000000001)

LZMA1 Filter ID.

LZMA1 is the very same thing as what was called just LZMA in LZMA Utils, 7-Zip, and LZMA SDK. It's called LZMA1 here to prevent developers from accidentally using LZMA when they actually want LZMA2.

LZMA1 shouldn't be used for new applications unless you really know what you are doing. LZMA2 is almost always a better choice.

Definition at line 30 of file lzma12.h.

◆ LZMA_FILTER_LZMA2

#define LZMA_FILTER_LZMA2   LZMA_VLI_C(0x21)

LZMA2 Filter ID.

Usually you want this instead of LZMA1. Compared to LZMA1, LZMA2 adds support for LZMA_SYNC_FLUSH, uncompressed chunks (smaller expansion when trying to compress uncompressible data), possibility to change lc/lp/pb in the middle of encoding, and some other internal improvements.

Definition at line 40 of file lzma12.h.

◆ LZMA_LC_DEFAULT

#define LZMA_LC_DEFAULT   3

Definition at line 284 of file lzma12.h.

◆ LZMA_LCLP_MAX

#define LZMA_LCLP_MAX   4

Definition at line 283 of file lzma12.h.

◆ LZMA_LCLP_MIN

#define LZMA_LCLP_MIN   0

Definition at line 282 of file lzma12.h.

◆ LZMA_LP_DEFAULT

#define LZMA_LP_DEFAULT   0

Definition at line 294 of file lzma12.h.

◆ LZMA_PB_DEFAULT

#define LZMA_PB_DEFAULT   2

Definition at line 319 of file lzma12.h.

◆ LZMA_PB_MAX

#define LZMA_PB_MAX   4

Definition at line 318 of file lzma12.h.

◆ LZMA_PB_MIN

#define LZMA_PB_MIN   0

Definition at line 317 of file lzma12.h.

Enumeration Type Documentation

◆ lzma_match_finder

Match finders.

Match finder has major effect on both speed and compression ratio. Usually hash chains are faster than binary trees.

If you will use LZMA_SYNC_FLUSH often, the hash chains may be a better choice, because binary trees get much higher compression ratio penalty with LZMA_SYNC_FLUSH.

The memory usage formulas are only rough estimates, which are closest to reality when dict_size is a power of two. The formulas are more complex in reality, and can also change a little between liblzma versions. Use lzma_raw_encoder_memusage() to get more accurate estimate of memory usage.

Enumerator
LZMA_MF_HC3 

Hash Chain with 2- and 3-byte hashing.

Minimum nice_len: 3

Memory usage:

  • dict_size <= 16 MiB: dict_size * 7.5
  • dict_size > 16 MiB: dict_size * 5.5 + 64 MiB
LZMA_MF_HC4 

Hash Chain with 2-, 3-, and 4-byte hashing.

Minimum nice_len: 4

Memory usage:

  • dict_size <= 32 MiB: dict_size * 7.5
  • dict_size > 32 MiB: dict_size * 6.5
LZMA_MF_BT2 

Binary Tree with 2-byte hashing.

Minimum nice_len: 2

Memory usage: dict_size * 9.5

LZMA_MF_BT3 

Binary Tree with 2- and 3-byte hashing.

Minimum nice_len: 3

Memory usage:

  • dict_size <= 16 MiB: dict_size * 11.5
  • dict_size > 16 MiB: dict_size * 9.5 + 64 MiB
LZMA_MF_BT4 

Binary Tree with 2-, 3-, and 4-byte hashing.

Minimum nice_len: 4

Memory usage:

  • dict_size <= 32 MiB: dict_size * 11.5
  • dict_size > 32 MiB: dict_size * 10.5

Definition at line 58 of file lzma12.h.

58  {
59  LZMA_MF_HC3 = 0x03,
70  LZMA_MF_HC4 = 0x04,
81  LZMA_MF_BT2 = 0x12,
90  LZMA_MF_BT3 = 0x13,
101  LZMA_MF_BT4 = 0x14
lzma_match_finder
Match finders.
Definition: lzma12.h:58
@ LZMA_MF_HC4
Hash Chain with 2-, 3-, and 4-byte hashing.
Definition: lzma12.h:70
@ LZMA_MF_BT4
Binary Tree with 2-, 3-, and 4-byte hashing.
Definition: lzma12.h:101
@ LZMA_MF_HC3
Hash Chain with 2- and 3-byte hashing.
Definition: lzma12.h:59
@ LZMA_MF_BT2
Binary Tree with 2-byte hashing.
Definition: lzma12.h:81
@ LZMA_MF_BT3
Binary Tree with 2- and 3-byte hashing.
Definition: lzma12.h:90

◆ lzma_mode

enum lzma_mode

Compression modes.

This selects the function used to analyze the data produced by the match finder.

Enumerator
LZMA_MODE_FAST 

Fast compression.

Fast mode is usually at its best when combined with a hash chain match finder.

LZMA_MODE_NORMAL 

Normal compression.

This is usually notably slower than fast mode. Use this together with binary tree match finders to expose the full potential of the LZMA1 or LZMA2 encoder.

Definition at line 138 of file lzma12.h.

138  {
139  LZMA_MODE_FAST = 1,
147  LZMA_MODE_NORMAL = 2
155 } lzma_mode;
lzma_mode
Compression modes.
Definition: lzma12.h:138
@ LZMA_MODE_FAST
Fast compression.
Definition: lzma12.h:139
@ LZMA_MODE_NORMAL
Normal compression.
Definition: lzma12.h:147

Function Documentation

◆ LZMA_API()

LZMA_API ( lzma_bool  )

Test if given match finder is supported.

Test if the given Filter ID is supported for encoding.

Test if the given Check ID is supported.

Set a compression preset to lzma_options_lzma structure.

Test if given compression mode is supported.

Return true if the given match finder is supported by this liblzma build. Otherwise false is returned. It is safe to call this with a value that isn't listed in lzma_match_finder enumeration; the return value will be false.

There is no way to list which match finders are available in this particular liblzma version and build. It would be useless, because a new match finder, which the application developer wasn't aware, could require giving additional options to the encoder that the older match finders don't need.

Return true if the given compression mode is supported by this liblzma build. Otherwise false is returned. It is safe to call this with a value that isn't listed in lzma_mode enumeration; the return value will be false.

There is no way to list which modes are available in this particular liblzma version and build. It would be useless, because a new compression mode, which the application developer wasn't aware, could require giving additional options to the encoder that the older modes don't need.

0 is the fastest and 9 is the slowest. These match the switches -0 .. -9 of the xz command line tool. In addition, it is possible to bitwise-or flags to the preset. Currently only LZMA_PRESET_EXTREME is supported. The flags are defined in container.h, because the flags are used also with lzma_easy_encoder().

The preset values are subject to changes between liblzma versions.

This function is available only if LZMA1 or LZMA2 encoder has been enabled when building liblzma.

Returns
On success, false is returned. If the preset is not supported, true is returned.

Definition at line 81 of file index.c.

1211 {
1212  const lzma_index *i = iter->internal[ITER_INDEX].p;
1213 
1214  // If the target is past the end of the file, return immediately.
1215  if (i->uncompressed_size <= target)
1216  return true;
1217 
1218  // Locate the Stream containing the target offset.
1219  const index_stream *stream = index_tree_locate(&i->streams, target);
1220  assert(stream != NULL);
1221  target -= stream->node.uncompressed_base;
1222 
1223  // Locate the group containing the target offset.
1224  const index_group *group = index_tree_locate(&stream->groups, target);
1225  assert(group != NULL);
1226 
1227  // Use binary search to locate the exact Record. It is the first
1228  // Record whose uncompressed_sum is greater than target.
1229  // This is because we want the rightmost Record that fullfills the
1230  // search criterion. It is possible that there are empty Blocks;
1231  // we don't want to return them.
1232  size_t left = 0;
1233  size_t right = group->last;
1234 
1235  while (left < right) {
1236  const size_t pos = left + (right - left) / 2;
1237  if (group->records[pos].uncompressed_sum <= target)
1238  left = pos + 1;
1239  else
1240  right = pos;
1241  }
1242 
1243  iter->internal[ITER_STREAM].p = stream;
1244  iter->internal[ITER_GROUP].p = group;
1245  iter->internal[ITER_RECORD].s = left;
1246 
1248 
1249  return false;
1250 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
@ ITER_RECORD
Definition: index.c:964
@ ITER_STREAM
Definition: index.c:962
@ ITER_INDEX
Definition: index.c:961
@ ITER_GROUP
Definition: index.c:963
static void iter_set_info(lzma_index_iter *iter)
Definition: index.c:978
static void * index_tree_locate(const index_tree *tree, lzma_vli target)
Definition: index.c:315
voidpf stream
Definition: ioapi.h:138
assert(limit<=UINT32_MAX/2)
size_t last
Index of the last Record in use.
Definition: index.c:82
index_record records[]
Definition: index.c:102
lzma_vli uncompressed_sum
Definition: index.c:66
index_tree streams
Definition: index.c:149
lzma_vli uncompressed_size
Uncompressed size of all the Blocks in the Stream(s)
Definition: index.c:152
int pos
Definition: main.c:11

References assert(), i, index_tree_locate(), ITER_GROUP, ITER_INDEX, ITER_RECORD, iter_set_info(), ITER_STREAM, index_group::last, NULL, pos, index_group::records, lzma_index_s::streams, lzma_index_s::uncompressed_size, and index_record::uncompressed_sum.

Variable Documentation

◆ lzma_nothrow

uint32_t preset lzma_nothrow

Definition at line 420 of file lzma12.h.