Rizin
unix-like reverse engineering framework and cli tools
delta_decoder.c
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #include "delta_decoder.h"
14 #include "delta_private.h"
15 
16 
17 static void
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 }
27 
28 
29 static lzma_ret
30 delta_decode(void *coder_ptr, const lzma_allocator *allocator,
31  const uint8_t *restrict in, size_t *restrict in_pos,
32  size_t in_size, uint8_t *restrict out,
33  size_t *restrict out_pos, size_t out_size, lzma_action action)
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 }
49 
50 
51 extern lzma_ret
54 {
55  next->code = &delta_decode;
57 }
58 
59 
60 extern lzma_ret
62  const uint8_t *props, size_t props_size)
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_index ** i
Definition: index.h:629
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
const lzma_filter * filters
Definition: container.h:315
#define NULL
Definition: cris-opc.c:27
@ LZMA_DELTA_TYPE_BYTE
Definition: delta.h:36
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 void decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
Definition: delta_decoder.c:18
lzma_ret lzma_delta_props_decode(void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
Definition: delta_decoder.c:61
lzma_ret lzma_delta_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: delta_decoder.c:52
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
Delta filter decoder.
Private common stuff for Delta encoder and decoder.
const lzma_allocator const uint8_t * props
Definition: filter.h:362
voidpf void uLong size
Definition: ioapi.h:138
#define restrict
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
assert(limit<=UINT32_MAX/2)
unsigned char uint8_t
Definition: sftypes.h:31
Definition: buffer.h:15
Custom functions for memory handling.
Definition: base.h:372
lzma_next_coder next
Next coder in the chain.
Definition: delta_private.h:20
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
Hold data and function pointers of the next filter in the chain.
Definition: common.h:135
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
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_ret
Return values used by several functions in liblzma.
Definition: base.h:57
@ 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
lzma_action
The ‘action’ argument for lzma_code()
Definition: base.h:250