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

Integrity checks. More...

Go to the source code of this file.

Macros

#define LZMA_CHECK_ID_MAX   15
 Maximum valid Check ID. More...
 
#define LZMA_CHECK_SIZE_MAX   64
 Maximum size of a Check field. More...
 

Enumerations

enum  lzma_check { LZMA_CHECK_NONE = 0 , LZMA_CHECK_CRC32 = 1 , LZMA_CHECK_CRC64 = 4 , LZMA_CHECK_SHA256 = 10 }
 Type of the integrity check (Check ID) More...
 

Functions

 LZMA_API (lzma_bool) lzma_check_is_supported(lzma_check check) lzma_nothrow lzma_attr_const
 Test if the given Check ID is supported. More...
 
 LZMA_API (uint32_t) lzma_check_size(lzma_check check) lzma_nothrow lzma_attr_const
 Get the size of the Check field with the given Check ID. More...
 
 LZMA_API (uint64_t) lzma_crc64(const uint8_t *buf
 Calculate CRC64. More...
 
 LZMA_API (lzma_check) lzma_get_check(const lzma_stream *strm) lzma_nothrow
 Get the type of the integrity check. More...
 

Variables

size_t size
 
size_t uint32_t crc lzma_nothrow lzma_attr_pure
 

Detailed Description

Integrity checks.

Definition in file check.h.

Macro Definition Documentation

◆ LZMA_CHECK_ID_MAX

#define LZMA_CHECK_ID_MAX   15

Maximum valid Check ID.

The .xz file format specification specifies 16 Check IDs (0-15). Some of them are only reserved, that is, no actual Check algorithm has been assigned. When decoding, liblzma still accepts unknown Check IDs for future compatibility. If a valid but unsupported Check ID is detected, liblzma can indicate a warning; see the flags LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, and LZMA_TELL_ANY_CHECK in container.h.

Definition at line 68 of file check.h.

◆ LZMA_CHECK_SIZE_MAX

#define LZMA_CHECK_SIZE_MAX   64

Maximum size of a Check field.

Definition at line 102 of file check.h.

Enumeration Type Documentation

◆ lzma_check

enum lzma_check

Type of the integrity check (Check ID)

The .xz format supports multiple types of checks that are calculated from the uncompressed data. They vary in both speed and ability to detect errors.

Enumerator
LZMA_CHECK_NONE 

No Check is calculated.

Size of the Check field: 0 bytes

LZMA_CHECK_CRC32 

CRC32 using the polynomial from the IEEE 802.3 standard

Size of the Check field: 4 bytes

LZMA_CHECK_CRC64 

CRC64 using the polynomial from the ECMA-182 standard

Size of the Check field: 8 bytes

LZMA_CHECK_SHA256 

SHA-256

Size of the Check field: 32 bytes

Definition at line 27 of file check.h.

27  {
28  LZMA_CHECK_NONE = 0,
35  LZMA_CHECK_CRC32 = 1,
42  LZMA_CHECK_CRC64 = 4,
55 } lzma_check;
lzma_check
Type of the integrity check (Check ID)
Definition: check.h:27
@ LZMA_CHECK_CRC32
Definition: check.h:35
@ LZMA_CHECK_NONE
Definition: check.h:28
@ LZMA_CHECK_CRC64
Definition: check.h:42
@ LZMA_CHECK_SHA256
Definition: check.h:49

Function Documentation

◆ LZMA_API() [1/4]

LZMA_API ( lzma_bool  ) const

Test if the given Check ID is supported.

Set a compression preset to lzma_options_lzma structure.

Test if given compression mode is supported.

Locate a Block.

Test if the given Filter ID is supported for decoding.

Return true if the given Check ID is supported by this liblzma build. Otherwise false is returned. It is safe to call this with a value that is not in the range [0, 15]; in that case the return value is always false.

You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always supported (even if liblzma is built with limited features).

Return true if the give Filter ID is supported for decoding by this liblzma build. Otherwise false is returned.

If it is possible to seek in the .xz file, it is possible to parse the Index field(s) and use lzma_index_iter_locate() to do random-access reading with granularity of Block size.

Parameters
iterIterator that was earlier initialized with lzma_index_iter_init().
targetUncompressed target offset which the caller would like to locate from the Stream

If the target is smaller than the uncompressed size of the Stream (can be checked with lzma_index_uncompressed_size()):

  • Information about the Stream and Block containing the requested uncompressed offset is stored into *iter.
  • Internal state of the iterator is adjusted so that lzma_index_iter_next() can be used to read subsequent Blocks or Streams.
  • This function returns false.

If target is greater than the uncompressed size of the Stream, *iter is not modified, and this function returns true.

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.

Test if the given Check ID is supported.

Locate a Block.

Parameters
iterIterator initialized with lzma_index_iter_init()
modeSpecify what kind of information the caller wants to get. See lzma_index_iter_mode for details.
Returns
If next Block or Stream matching the mode was found, *iter is updated and this function returns false. If no Block or Stream matching the mode is found, *iter is not modified and this function returns true. If mode is set to an unknown value, *iter is not modified and this function returns true.

If it is possible to seek in the .xz file, it is possible to parse the Index field(s) and use lzma_index_iter_locate() to do random-access reading with granularity of Block size.

Parameters
iterIterator that was earlier initialized with lzma_index_iter_init().
targetUncompressed target offset which the caller would like to locate from the Stream

If the target is smaller than the uncompressed size of the Stream (can be checked with lzma_index_uncompressed_size()):

  • Information about the Stream and Block containing the requested uncompressed offset is stored into *iter.
  • Internal state of the iterator is adjusted so that lzma_index_iter_next() can be used to read subsequent Blocks or Streams.
  • This function returns false.

If target is greater than the uncompressed size of the Stream, *iter is not modified, and this function returns true.

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 1209 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.

◆ LZMA_API() [2/4]

LZMA_API ( lzma_check  ) const

Get the type of the integrity check.

This function can be called only immediately after lzma_code() has returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK. Calling this function in any other situation has undefined behavior.

◆ LZMA_API() [3/4]

LZMA_API ( uint32_t  )

Get the size of the Check field with the given Check ID.

Get the number of bytes required to encode a VLI.

Run-time version number as an integer.

Get the number of processor cores or threads.

Calculate CRC32.

Although not all Check IDs have a check algorithm associated, the size of every Check is already frozen. This function returns the size (in bytes) of the Check field with the specified Check ID. The values are: { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }

If the argument is not in the range [0, 15], UINT32_MAX is returned.

Calculate CRC32 using the polynomial from the IEEE 802.3 standard.

Parameters
bufPointer to the input buffer
sizeSize of the input buffer
crcPreviously returned CRC value. This is used to calculate the CRC of a big buffer in smaller chunks. Set to zero when starting a new calculation.
Returns
Updated CRC value, which can be passed to this function again to continue CRC calculation.

◆ LZMA_API() [4/4]

LZMA_API ( uint64_t  ) const

Calculate CRC64.

Get the size of the Index field as bytes.

Calculate approximate memory requirements for raw encoder.

Calculate Unpadded Size.

Get the memory usage of decoder filter chain.

Calculate CRC64 using the polynomial from the ECMA-182 standard.

This function is used similarly to lzma_crc32(). See its documentation.

Definition at line 624 of file block_util.c.

83 {
84  lzma_vli unpadded_size = lzma_block_unpadded_size(block);
85 
88 
89  return unpadded_size;
90 }
const lzma_allocator lzma_vli unpadded_size
Definition: index.h:345
static lzma_vli vli_ceil4(lzma_vli vli)
Round the variable-length integer to the next multiple of four.
Definition: index.h:39
uint64_t lzma_vli
Variable-length integer type.
Definition: vli.h:63
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
Definition: vli.h:39

References LZMA_VLI_UNKNOWN, unpadded_size, and vli_ceil4().

Variable Documentation

◆ lzma_attr_pure

size_t uint64_t crc lzma_nothrow lzma_attr_pure

Definition at line 121 of file check.h.

◆ size

Definition at line 120 of file check.h.