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

Delta filter decoder. More...

#include "delta_decoder.h"
#include "delta_private.h"

Go to the source code of this file.

Functions

static void decode_buffer (lzma_delta_coder *coder, uint8_t *buffer, size_t size)
 
static lzma_ret delta_decode (void *coder_ptr, const lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action)
 
lzma_ret lzma_delta_decoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 
lzma_ret lzma_delta_props_decode (void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
 

Detailed Description

Delta filter decoder.

Definition in file delta_decoder.c.

Function Documentation

◆ decode_buffer()

static void decode_buffer ( lzma_delta_coder coder,
uint8_t buffer,
size_t  size 
)
static

Definition at line 18 of file delta_decoder.c.

19 {
20  const size_t distance = coder->distance;
21 
22  for (size_t i = 0; i < size; ++i) {
23  buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
24  coder->history[coder->pos-- & 0xFF] = buffer[i];
25  }
26 }
lzma_index ** i
Definition: index.h:629
voidpf void uLong size
Definition: ioapi.h:138
Definition: buffer.h:15
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

References lzma_delta_coder::distance, lzma_delta_coder::history, i, and lzma_delta_coder::pos.

Referenced by delta_decode().

◆ delta_decode()

static lzma_ret delta_decode ( void *  coder_ptr,
const lzma_allocator allocator,
const uint8_t *restrict  in,
size_t *restrict  in_pos,
size_t  in_size,
uint8_t *restrict  out,
size_t *restrict  out_pos,
size_t  out_size,
lzma_action  action 
)
static

Definition at line 30 of file delta_decoder.c.

34 {
35  lzma_delta_coder *coder = coder_ptr;
36 
37  assert(coder->next.code != NULL);
38 
39  const size_t out_start = *out_pos;
40 
41  const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
42  in, in_pos, in_size, out, out_pos, out_size,
43  action);
44 
45  decode_buffer(coder, out + out_start, *out_pos - out_start);
46 
47  return ret;
48 }
const lzma_allocator const uint8_t size_t uint8_t size_t * out_pos
Definition: block.h:528
const lzma_allocator const uint8_t size_t * in_pos
Definition: block.h:579
const lzma_allocator const uint8_t size_t in_size
Definition: block.h:527
const lzma_allocator * allocator
Definition: block.h:377
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define NULL
Definition: cris-opc.c:27
static void decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
Definition: delta_decoder.c:18
assert(limit<=UINT32_MAX/2)
lzma_next_coder next
Next coder in the chain.
Definition: delta_private.h:20
lzma_code_function code
Pointer to function to do the actual coding.
Definition: common.h:150
void * coder
Pointer to coder-specific data.
Definition: common.h:137
lzma_ret
Return values used by several functions in liblzma.
Definition: base.h:57

References test-lz4-speed::action, allocator, assert(), lzma_next_coder_s::code, lzma_next_coder_s::coder, decode_buffer(), in, in_pos, in_size, lzma_delta_coder::next, NULL, out, and out_pos.

Referenced by lzma_delta_decoder_init().

◆ lzma_delta_decoder_init()

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

Definition at line 52 of file delta_decoder.c.

54 {
55  next->code = &delta_decode;
57 }
const lzma_filter * filters
Definition: container.h:315
lzma_ret lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: delta_common.c:28
static lzma_ret delta_decode(void *coder_ptr, const lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action)
Definition: delta_decoder.c:30

References allocator, lzma_next_coder_s::code, delta_decode(), filters, and lzma_delta_coder_init().

◆ lzma_delta_props_decode()

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

Definition at line 61 of file delta_decoder.c.

63 {
64  if (props_size != 1)
65  return LZMA_OPTIONS_ERROR;
66 
69  if (opt == NULL)
70  return LZMA_MEM_ERROR;
71 
73  opt->dist = props[0] + 1U;
74 
75  *options = opt;
76 
77  return LZMA_OK;
78 }
@ LZMA_DELTA_TYPE_BYTE
Definition: delta.h:36
const lzma_allocator const uint8_t * props
Definition: filter.h:362
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
Options for the Delta filter.
Definition: delta.h:45
uint32_t dist
Delta distance.
Definition: delta.h:59
lzma_delta_type type
Definition: delta.h:47
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
@ 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

References allocator, lzma_options_delta::dist, lzma_alloc(), LZMA_DELTA_TYPE_BYTE, LZMA_MEM_ERROR, LZMA_OK, LZMA_OPTIONS_ERROR, NULL, options, props, and lzma_options_delta::type.