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

Filter ID mapping to filter-specific functions. More...

#include "filter_encoder.h"
#include "filter_common.h"
#include "lzma_encoder.h"
#include "lzma2_encoder.h"
#include "simple_encoder.h"
#include "delta_encoder.h"

Go to the source code of this file.

Classes

struct  lzma_filter_encoder
 

Functions

static const lzma_filter_encoderencoder_find (lzma_vli id)
 
 LZMA_API (lzma_bool)
 
 LZMA_API (lzma_ret)
 
lzma_ret lzma_raw_encoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter *options)
 
 LZMA_API (uint64_t)
 Calculate approximate memory usage of easy encoder. More...
 
uint64_t lzma_mt_block_size (const lzma_filter *filters)
 

Variables

static const lzma_filter_encoder encoders []
 

Detailed Description

Filter ID mapping to filter-specific functions.

Definition in file filter_encoder.c.

Function Documentation

◆ encoder_find()

static const lzma_filter_encoder* encoder_find ( lzma_vli  id)
static

Definition at line 154 of file filter_encoder.c.

155 {
156  for (size_t i = 0; i < ARRAY_SIZE(encoders); ++i)
157  if (encoders[i].id == id)
158  return encoders + i;
159 
160  return NULL;
161 }
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
static const lzma_filter_encoder encoders[]

References ARRAY_SIZE, encoders, i, and NULL.

Referenced by LZMA_API(), lzma_mt_block_size(), and lzma_raw_encoder_init().

◆ LZMA_API() [1/3]

LZMA_API ( lzma_bool  )

Definition at line 164 of file filter_encoder.c.

166 {
167  return encoder_find(id) != NULL;
168 }
static const lzma_filter_encoder * encoder_find(lzma_vli id)

References encoder_find(), and NULL.

◆ LZMA_API() [2/3]

LZMA_API ( lzma_ret  )

Definition at line 171 of file filter_encoder.c.

173 {
174  if (strm->internal->next.update == NULL)
175  return LZMA_PROG_ERROR;
176 
177  // Validate the filter chain.
178  if (lzma_raw_encoder_memusage(filters) == UINT64_MAX)
179  return LZMA_OPTIONS_ERROR;
180 
181  // The actual filter chain in the encoder is reversed. Some things
182  // still want the normal order chain, so we provide both.
183  size_t count = 1;
184  while (filters[count].id != LZMA_VLI_UNKNOWN)
185  ++count;
186 
187  lzma_filter reversed_filters[LZMA_FILTERS_MAX + 1];
188  for (size_t i = 0; i < count; ++i)
189  reversed_filters[count - i - 1] = filters[i];
190 
191  reversed_filters[count].id = LZMA_VLI_UNKNOWN;
192 
194  strm->allocator, filters, reversed_filters);
195 }
const lzma_filter * filters
Definition: container.h:315
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
#define LZMA_FILTERS_MAX
Maximum number of filters in a chain.
Definition: filter.h:26
static lzma_stream strm
Definition: full_flush.c:20
#define UINT64_MAX
Filter options.
Definition: filter.h:43
lzma_vli id
Filter ID.
Definition: filter.h:54
lzma_next_coder next
The actual coder that should do something useful.
Definition: common.h:198
void * coder
Pointer to coder-specific data.
Definition: common.h:137
lzma_ret(* update)(void *coder, const lzma_allocator *allocator, const lzma_filter *filters, const lzma_filter *reversed_filters)
Definition: common.h:173
lzma_internal * internal
Definition: base.h:505
const lzma_allocator * allocator
Custom memory allocation functions.
Definition: base.h:502
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
Definition: vli.h:39
@ LZMA_PROG_ERROR
Programming error.
Definition: base.h:218
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160

References lzma_stream::allocator, lzma_next_coder_s::coder, count, filters, i, lzma_filter::id, lzma_stream::internal, LZMA_FILTERS_MAX, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR, LZMA_VLI_UNKNOWN, lzma_internal_s::next, NULL, strm, UINT64_MAX, and lzma_next_coder_s::update.

◆ LZMA_API() [3/3]

LZMA_API ( uint64_t  )

Calculate approximate memory usage of easy encoder.

Get the total amount of physical memory (RAM) in bytes.

Calculate approximate memory usage of multithreaded .xz encoder.

Calculate approximate decoder memory usage of a preset.

This function is a wrapper for lzma_raw_encoder_memusage().

Parameters
presetCompression preset (level and possible flags)
Returns
Number of bytes of memory required for the given preset when encoding. If an error occurs, for example due to unsupported preset, UINT64_MAX is returned.

This function is a wrapper for lzma_raw_decoder_memusage().

Parameters
presetCompression preset (level and possible flags)
Returns
Number of bytes of memory required to decompress a file that was compressed using the given preset. If an error occurs, for example due to unsupported preset, UINT64_MAX is returned.

Since doing the encoding in threaded mode doesn't affect the memory requirements of single-threaded decompressor, you can use lzma_easy_decoder_memusage(options->preset) or lzma_raw_decoder_memusage(options->filters) to calculate the decompressor memory requirements.

Parameters
optionsCompression options
Returns
Number of bytes of memory required for encoding with the given options. If an error occurs, for example due to unsupported preset or filter chain, UINT64_MAX is returned.

Calculate approximate memory usage of easy encoder.

Get the uncompressed size of the file.

Get the total size of the file.

Get the total size of the Blocks.

Get the total size of the Stream.

Get the size of the Index field as bytes.

Get the number of Blocks.

Get the number of Streams.

Calculate the memory usage of an existing lzma_index.

On disk, the size of the Index field depends on both the number of Records stored and how big values the Records store (due to variable-length integer encoding). When the Index is kept in lzma_index structure, the memory usage depends only on the number of Records/Blocks stored in the Index(es), and in case of concatenated lzma_indexes, the number of Streams. The size in RAM is almost always significantly bigger than in the encoded form on disk.

This function calculates an approximate amount of memory needed hold the given number of Streams and Blocks in lzma_index structure. This value may vary between CPU architectures and also between liblzma versions if the internal implementation is modified.

This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), lzma_index_block_count(i)).

This returns the total number of Blocks in lzma_index. To get number of Blocks in individual Streams, use lzma_index_iter.

This is needed to verify the Backward Size field in the Stream Footer.

If multiple lzma_indexes have been combined, this works as if the Blocks were in a single Stream. This is useful if you are going to combine Blocks from multiple Streams into a single new Stream.

This doesn't include the Stream Header, Stream Footer, Stream Padding, or Index fields.

When no lzma_indexes have been combined with lzma_index_cat() and there is no Stream Padding, this function is identical to lzma_index_stream_size(). If multiple lzma_indexes have been combined, this includes also the headers of each separate Stream and the possible Stream Padding fields.

Definition at line 221 of file filter_encoder.c.

223 {
226 }
uint64_t lzma_raw_coder_memusage(lzma_filter_find coder_find, const lzma_filter *filters)
const lzma_filter_coder *(* lzma_filter_find)(lzma_vli id)
Definition: filter_common.h:35

References encoder_find(), filters, and lzma_raw_coder_memusage().

◆ lzma_mt_block_size()

uint64_t lzma_mt_block_size ( const lzma_filter filters)

Definition at line 230 of file filter_encoder.c.

231 {
232  uint64_t max = 0;
233 
234  for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
235  const lzma_filter_encoder *const fe
236  = encoder_find(filters[i].id);
237  if (fe->block_size != NULL) {
238  const uint64_t size
239  = fe->block_size(filters[i].options);
240  if (size == 0)
241  return 0;
242 
243  if (size > max)
244  max = size;
245  }
246  }
247 
248  return max;
249 }
int max
Definition: enough.c:225
voidpf void uLong size
Definition: ioapi.h:138
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
unsigned long uint64_t
Definition: sftypes.h:28
uint64_t(* block_size)(const void *options)

References lzma_filter_encoder::block_size, encoder_find(), filters, i, lzma_filter::id, LZMA_VLI_UNKNOWN, max, NULL, and options.

Referenced by get_options().

◆ lzma_raw_encoder_init()

lzma_ret lzma_raw_encoder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter options 
)

Definition at line 199 of file filter_encoder.c.

201 {
202  return lzma_raw_coder_init(next, allocator,
204 }
const lzma_allocator * allocator
Definition: block.h:377
lzma_ret lzma_raw_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter *options, lzma_filter_find coder_find, bool is_encoder)

References allocator, encoder_find(), lzma_raw_coder_init(), and options.

Referenced by block_encode_normal(), LZMA_API(), and lzma_block_encoder_init().

Variable Documentation

◆ encoders

const lzma_filter_encoder encoders[]
static

Definition at line 56 of file filter_encoder.c.

Referenced by encoder_find().