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

LZMA decoder API. More...

#include "common.h"

Go to the source code of this file.

Functions

lzma_ret lzma_lzma_decoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 Allocates and initializes LZMA decoder. More...
 
uint64_t lzma_lzma_decoder_memusage (const void *options)
 
lzma_ret lzma_lzma_props_decode (void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
 
bool lzma_lzma_lclppb_decode (lzma_options_lzma *options, uint8_t byte)
 Decodes the LZMA Properties byte (lc/lp/pb) More...
 

Detailed Description

LZMA decoder API.

Definition in file lzma_decoder.h.

Function Documentation

◆ lzma_lzma_decoder_init()

lzma_ret lzma_lzma_decoder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter_info filters 
)

Allocates and initializes LZMA decoder.

Definition at line 987 of file lzma_decoder.c.

989 {
990  // LZMA can only be the last filter in the chain. This is enforced
991  // by the raw_decoder initialization.
992  assert(filters[1].init == NULL);
993 
994  return lzma_lz_decoder_init(next, allocator, filters,
996 }
const lzma_allocator * allocator
Definition: block.h:377
const lzma_filter * filters
Definition: container.h:315
#define NULL
Definition: cris-opc.c:27
lzma_ret lzma_lz_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, lzma_ret(*lz_init)(lzma_lz_decoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options))
Definition: lz_decoder.c:212
static lzma_ret lzma_decoder_init(lzma_lz_decoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options)
Definition: lzma_decoder.c:970
assert(limit<=UINT32_MAX/2)
bool init
Definition: core.c:77

References allocator, assert(), filters, init, lzma_decoder_init(), lzma_lz_decoder_init(), and NULL.

Referenced by alone_decode().

◆ lzma_lzma_decoder_memusage()

uint64_t lzma_lzma_decoder_memusage ( const void *  options)

Definition at line 1025 of file lzma_decoder.c.

1026 {
1027  if (!is_lclppb_valid(options))
1028  return UINT64_MAX;
1029 
1031 }
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
static bool is_lclppb_valid(const lzma_options_lzma *options)
Validates lc, lp, and pb.
Definition: lzma_common.h:33
uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options)
#define UINT64_MAX

References is_lclppb_valid(), lzma_lzma_decoder_memusage_nocheck(), options, and UINT64_MAX.

Referenced by alone_decode().

◆ lzma_lzma_lclppb_decode()

bool lzma_lzma_lclppb_decode ( lzma_options_lzma options,
uint8_t  byte 
)

Decodes the LZMA Properties byte (lc/lp/pb)

Returns
true if error occurred, false on success

Definition at line 1000 of file lzma_decoder.c.

1001 {
1002  if (byte > (4 * 5 + 4) * 9 + 8)
1003  return true;
1004 
1005  // See the file format specification to understand this.
1006  options->pb = byte / (9 * 5);
1007  byte -= options->pb * 9 * 5;
1008  options->lp = byte / 9;
1009  options->lc = byte - options->lp * 9;
1010 
1011  return options->lc + options->lp > LZMA_LCLP_MAX;
1012 }
#define LZMA_LCLP_MAX
Definition: lzma12.h:283

References LZMA_LCLP_MAX, and options.

Referenced by alone_decode(), lzma2_decode(), and lzma_lzma_props_decode().

◆ lzma_lzma_props_decode()

lzma_ret lzma_lzma_props_decode ( void **  options,
const lzma_allocator allocator,
const uint8_t props,
size_t  props_size 
)

Definition at line 1035 of file lzma_decoder.c.

1037 {
1038  if (props_size != 5)
1039  return LZMA_OPTIONS_ERROR;
1040 
1041  lzma_options_lzma *opt
1043  if (opt == NULL)
1044  return LZMA_MEM_ERROR;
1045 
1046  if (lzma_lzma_lclppb_decode(opt, props[0]))
1047  goto error;
1048 
1049  // All dictionary sizes are accepted, including zero. LZ decoder
1050  // will automatically use a dictionary at least a few KiB even if
1051  // a smaller dictionary is requested.
1052  opt->dict_size = read32le(props + 1);
1053 
1054  opt->preset_dict = NULL;
1055  opt->preset_dict_size = 0;
1056 
1057  *options = opt;
1058 
1059  return LZMA_OK;
1060 
1061 error:
1062  lzma_free(opt, allocator);
1063  return LZMA_OPTIONS_ERROR;
1064 }
const lzma_allocator const uint8_t * props
Definition: filter.h:362
bool lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte)
Decodes the LZMA Properties byte (lc/lp/pb)
Options specific to the LZMA1 and LZMA2 filters.
Definition: lzma12.h:185
const uint8_t * preset_dict
Pointer to an initial dictionary.
Definition: lzma12.h:240
uint32_t preset_dict_size
Size of the preset dictionary.
Definition: lzma12.h:254
uint32_t dict_size
Dictionary size in bytes.
Definition: lzma12.h:217
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
static uint32_t read32le(const uint8_t *buf)
void error(const char *msg)
Definition: untgz.c:593
@ LZMA_MEM_ERROR
Cannot allocate memory.
Definition: base.h:128
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58
void lzma_free(void *ptr, const lzma_allocator *allocator)
Frees memory.
Definition: common.c:78

References allocator, lzma_options_lzma::dict_size, error(), lzma_alloc(), lzma_free(), lzma_lzma_lclppb_decode(), LZMA_MEM_ERROR, LZMA_OK, LZMA_OPTIONS_ERROR, NULL, options, lzma_options_lzma::preset_dict, lzma_options_lzma::preset_dict_size, props, and read32le().