Rizin
unix-like reverse engineering framework and cli tools
stream_flags_decoder.c File Reference

Decodes Stream Header and Stream Footer from .xz files. More...

Go to the source code of this file.

Functions

static bool stream_flags_decode (lzma_stream_flags *options, const uint8_t *in)
 
 LZMA_API (lzma_ret)
 

Detailed Description

Decodes Stream Header and Stream Footer from .xz files.

Definition in file stream_flags_decoder.c.

Function Documentation

◆ LZMA_API()

LZMA_API ( lzma_ret  )

Definition at line 30 of file stream_flags_decoder.c.

32 {
33  // Magic
34  if (memcmp(in, lzma_header_magic, sizeof(lzma_header_magic)) != 0)
35  return LZMA_FORMAT_ERROR;
36 
37  // Verify the CRC32 so we can distinguish between corrupt
38  // and unsupported files.
39  const uint32_t crc = lzma_crc32(in + sizeof(lzma_header_magic),
41  if (crc != read32le(in + sizeof(lzma_header_magic)
43  return LZMA_DATA_ERROR;
44 
45  // Stream Flags
47  return LZMA_OPTIONS_ERROR;
48 
49  // Set Backward Size to indicate unknown value. That way
50  // lzma_stream_flags_compare() can be used to compare Stream Header
51  // and Stream Footer while keeping it useful also for comparing
52  // two Stream Footers.
53  options->backward_size = LZMA_VLI_UNKNOWN;
54 
55  return LZMA_OK;
56 }
const lzma_allocator const uint8_t * in
Definition: block.h:527
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
unsigned int uint32_t
Definition: sftypes.h:29
const uint8_t lzma_header_magic[6]
#define LZMA_STREAM_FLAGS_SIZE
Size of the Stream Flags field.
static bool stream_flags_decode(lzma_stream_flags *options, const uint8_t *in)
static uint32_t read32le(const uint8_t *buf)
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
Definition: vli.h:39
@ LZMA_DATA_ERROR
Data is corrupt.
Definition: base.h:172
@ LZMA_FORMAT_ERROR
Memory usage limit was reached.
Definition: base.h:150
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58

References in, LZMA_DATA_ERROR, LZMA_FORMAT_ERROR, lzma_header_magic, LZMA_OK, LZMA_OPTIONS_ERROR, LZMA_STREAM_FLAGS_SIZE, LZMA_VLI_UNKNOWN, options, read32le(), and stream_flags_decode().

◆ stream_flags_decode()

static bool stream_flags_decode ( lzma_stream_flags options,
const uint8_t in 
)
static

Definition at line 17 of file stream_flags_decoder.c.

18 {
19  // Reserved bits must be unset.
20  if (in[0] != 0x00 || (in[1] & 0xF0))
21  return true;
22 
23  options->version = 0;
24  options->check = in[1] & 0x0F;
25 
26  return false;
27 }

References in, and options.

Referenced by LZMA_API().