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

Common stuff for Delta encoder and decoder. More...

#include "delta_common.h"
#include "delta_private.h"

Go to the source code of this file.

Functions

static void delta_coder_end (void *coder_ptr, const lzma_allocator *allocator)
 
lzma_ret lzma_delta_coder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 
uint64_t lzma_delta_coder_memusage (const void *options)
 

Detailed Description

Common stuff for Delta encoder and decoder.

Definition in file delta_common.c.

Function Documentation

◆ delta_coder_end()

static void delta_coder_end ( void *  coder_ptr,
const lzma_allocator allocator 
)
static

Definition at line 18 of file delta_common.c.

19 {
20  lzma_delta_coder *coder = coder_ptr;
21  lzma_next_end(&coder->next, allocator);
22  lzma_free(coder, allocator);
23  return;
24 }
const lzma_allocator * allocator
Definition: block.h:377
lzma_next_coder next
Next coder in the chain.
Definition: delta_private.h:20
void lzma_free(void *ptr, const lzma_allocator *allocator)
Frees memory.
Definition: common.c:78
void lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
Definition: common.c:145

References allocator, lzma_free(), lzma_next_end(), and lzma_delta_coder::next.

Referenced by lzma_delta_coder_init().

◆ lzma_delta_coder_init()

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

Definition at line 28 of file delta_common.c.

30 {
31  // Allocate memory for the decoder if needed.
32  lzma_delta_coder *coder = next->coder;
33  if (coder == NULL) {
34  coder = lzma_alloc(sizeof(lzma_delta_coder), allocator);
35  if (coder == NULL)
36  return LZMA_MEM_ERROR;
37 
38  next->coder = coder;
39 
40  // End function is the same for encoder and decoder.
41  next->end = &delta_coder_end;
42  coder->next = LZMA_NEXT_CODER_INIT;
43  }
44 
45  // Validate the options.
47  return LZMA_OPTIONS_ERROR;
48 
49  // Set the delta distance.
50  const lzma_options_delta *opt = filters[0].options;
51  coder->distance = opt->dist;
52 
53  // Initialize the rest of the variables.
54  coder->pos = 0;
56 
57  // Initialize the next decoder in the chain, if any.
58  return lzma_next_filter_init(&coder->next, allocator, filters + 1);
59 }
const lzma_filter * filters
Definition: container.h:315
#define NULL
Definition: cris-opc.c:27
#define LZMA_DELTA_DIST_MAX
Definition: delta.h:61
static void delta_coder_end(void *coder_ptr, const lzma_allocator *allocator)
Definition: delta_common.c:18
uint64_t lzma_delta_coder_memusage(const void *options)
Definition: delta_common.c:63
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
#define UINT64_MAX
uint8_t pos
Position in history[].
Definition: delta_private.h:26
uint8_t history[LZMA_DELTA_DIST_MAX]
Buffer to hold history of the original data.
Definition: delta_private.h:29
size_t distance
Delta distance.
Definition: delta_private.h:23
void * options
Pointer to filter-specific options structure.
Definition: filter.h:63
void * coder
Pointer to coder-specific data.
Definition: common.h:137
lzma_end_function end
Definition: common.h:155
Options for the Delta filter.
Definition: delta.h:45
uint32_t dist
Delta distance.
Definition: delta.h:59
#define LZMA_NEXT_CODER_INIT
Macro to initialize lzma_next_coder structure.
Definition: common.h:180
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
#define memzero(s, n)
Definition: sysdefs.h:180
@ LZMA_MEM_ERROR
Cannot allocate memory.
Definition: base.h:128
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160
lzma_ret lzma_next_filter_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: common.c:116

References allocator, lzma_next_coder_s::coder, delta_coder_end(), lzma_options_delta::dist, lzma_delta_coder::distance, lzma_next_coder_s::end, filters, lzma_delta_coder::history, lzma_alloc(), lzma_delta_coder_memusage(), LZMA_DELTA_DIST_MAX, LZMA_MEM_ERROR, LZMA_NEXT_CODER_INIT, lzma_next_filter_init(), LZMA_OPTIONS_ERROR, memzero, lzma_delta_coder::next, NULL, options, lzma_filter::options, lzma_delta_coder::pos, and UINT64_MAX.

Referenced by lzma_delta_decoder_init(), and lzma_delta_encoder_init().

◆ lzma_delta_coder_memusage()

uint64_t lzma_delta_coder_memusage ( const void *  options)

Definition at line 63 of file delta_common.c.

64 {
65  const lzma_options_delta *opt = options;
66 
67  if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE
68  || opt->dist < LZMA_DELTA_DIST_MIN
69  || opt->dist > LZMA_DELTA_DIST_MAX)
70  return UINT64_MAX;
71 
72  return sizeof(lzma_delta_coder);
73 }
@ LZMA_DELTA_TYPE_BYTE
Definition: delta.h:36
#define LZMA_DELTA_DIST_MIN
Definition: delta.h:60
lzma_delta_type type
Definition: delta.h:47

References lzma_options_delta::dist, LZMA_DELTA_DIST_MAX, LZMA_DELTA_DIST_MIN, LZMA_DELTA_TYPE_BYTE, NULL, options, lzma_options_delta::type, and UINT64_MAX.

Referenced by lzma_delta_coder_init(), and lzma_delta_props_encode().