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

Private definitions for so called simple filters. More...

#include "simple_coder.h"

Go to the source code of this file.

Classes

struct  lzma_simple_coder
 

Functions

lzma_ret lzma_simple_coder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, size_t(*filter)(void *simple, uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size), size_t simple_size, size_t unfiltered_max, uint32_t alignment, bool is_encoder)
 

Detailed Description

Private definitions for so called simple filters.

Definition in file simple_private.h.

Function Documentation

◆ lzma_simple_coder_init()

lzma_ret lzma_simple_coder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter_info filters,
size_t(*)(void *simple, uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size filter,
size_t  simple_size,
size_t  unfiltered_max,
uint32_t  alignment,
bool  is_encoder 
)

Definition at line 235 of file simple_coder.c.

241 {
242  // Allocate memory for the lzma_simple_coder structure if needed.
243  lzma_simple_coder *coder = next->coder;
244  if (coder == NULL) {
245  // Here we allocate space also for the temporary buffer. We
246  // need twice the size of unfiltered_max, because then it
247  // is always possible to filter at least unfiltered_max bytes
248  // more data in coder->buffer[] if it can be filled completely.
249  coder = lzma_alloc(sizeof(lzma_simple_coder)
250  + 2 * unfiltered_max, allocator);
251  if (coder == NULL)
252  return LZMA_MEM_ERROR;
253 
254  next->coder = coder;
255  next->code = &simple_code;
256  next->end = &simple_coder_end;
257  next->update = &simple_coder_update;
258 
259  coder->next = LZMA_NEXT_CODER_INIT;
260  coder->filter = filter;
261  coder->allocated = 2 * unfiltered_max;
262 
263  // Allocate memory for filter-specific data structure.
264  if (simple_size > 0) {
265  coder->simple = lzma_alloc(simple_size, allocator);
266  if (coder->simple == NULL)
267  return LZMA_MEM_ERROR;
268  } else {
269  coder->simple = NULL;
270  }
271  }
272 
273  if (filters[0].options != NULL) {
274  const lzma_options_bcj *simple = filters[0].options;
275  coder->now_pos = simple->start_offset;
276  if (coder->now_pos & (alignment - 1))
277  return LZMA_OPTIONS_ERROR;
278  } else {
279  coder->now_pos = 0;
280  }
281 
282  // Reset variables.
283  coder->is_encoder = is_encoder;
284  coder->end_was_reached = false;
285  coder->pos = 0;
286  coder->filtered = 0;
287  coder->size = 0;
288 
289  return lzma_next_filter_init(&coder->next, allocator, filters + 1);
290 }
const lzma_allocator * allocator
Definition: block.h:377
const lzma_filter * filters
Definition: container.h:315
#define NULL
Definition: cris-opc.c:27
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
Definition: filter.c:185
static lzma_ret simple_coder_update(void *coder_ptr, const lzma_allocator *allocator, const lzma_filter *filters_null lzma_attribute((__unused__)), const lzma_filter *reversed_filters)
Definition: simple_coder.c:222
static lzma_ret simple_code(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: simple_coder.c:69
static void simple_coder_end(void *coder_ptr, const lzma_allocator *allocator)
Definition: simple_coder.c:211
void * options
Pointer to filter-specific options structure.
Definition: filter.h:63
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_end_function end
Definition: common.h:155
lzma_ret(* update)(void *coder, const lzma_allocator *allocator, const lzma_filter *filters, const lzma_filter *reversed_filters)
Definition: common.h:173
Options for BCJ filters.
Definition: bcj.h:73
uint32_t start_offset
Start offset for conversions.
Definition: bcj.h:88
size_t(* filter)(void *simple, uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size)
size_t allocated
Size of the memory allocated for the buffer.
lzma_next_coder next
Next filter in the chain.
bool end_was_reached
True if the next coder in the chain has returned LZMA_STREAM_END.
#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.
@ 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 lzma_simple_coder::allocated, allocator, lzma_next_coder_s::code, lzma_next_coder_s::coder, lzma_next_coder_s::end, lzma_simple_coder::end_was_reached, filter(), lzma_simple_coder::filter, lzma_simple_coder::filtered, filters, lzma_simple_coder::is_encoder, lzma_alloc(), LZMA_MEM_ERROR, LZMA_NEXT_CODER_INIT, lzma_next_filter_init(), LZMA_OPTIONS_ERROR, lzma_simple_coder::next, lzma_simple_coder::now_pos, NULL, options, lzma_filter::options, lzma_simple_coder::pos, lzma_simple_coder::simple, simple_code(), simple_coder_end(), simple_coder_update(), lzma_simple_coder::size, lzma_options_bcj::start_offset, and lzma_next_coder_s::update.

Referenced by arm_coder_init(), armthumb_coder_init(), ia64_coder_init(), powerpc_coder_init(), sparc_coder_init(), and x86_coder_init().