Rizin
unix-like reverse engineering framework and cli tools
filter_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 "filter_decoder.h"
14 #include "filter_common.h"
15 #include "lzma_decoder.h"
16 #include "lzma2_decoder.h"
17 #include "simple_decoder.h"
18 #include "delta_decoder.h"
19 
20 
21 typedef struct {
24 
28 
31  uint64_t (*memusage)(const void *options);
32 
38  lzma_ret (*props_decode)(
39  void **options, const lzma_allocator *allocator,
40  const uint8_t *props, size_t props_size);
41 
43 
44 
45 static const lzma_filter_decoder decoders[] = {
46 #ifdef HAVE_DECODER_LZMA1
47  {
49  .init = &lzma_lzma_decoder_init,
50  .memusage = &lzma_lzma_decoder_memusage,
51  .props_decode = &lzma_lzma_props_decode,
52  },
53 #endif
54 #ifdef HAVE_DECODER_LZMA2
55  {
56  .id = LZMA_FILTER_LZMA2,
57  .init = &lzma_lzma2_decoder_init,
58  .memusage = &lzma_lzma2_decoder_memusage,
59  .props_decode = &lzma_lzma2_props_decode,
60  },
61 #endif
62 #ifdef HAVE_DECODER_X86
63  {
64  .id = LZMA_FILTER_X86,
66  .memusage = NULL,
67  .props_decode = &lzma_simple_props_decode,
68  },
69 #endif
70 #ifdef HAVE_DECODER_POWERPC
71  {
72  .id = LZMA_FILTER_POWERPC,
74  .memusage = NULL,
75  .props_decode = &lzma_simple_props_decode,
76  },
77 #endif
78 #ifdef HAVE_DECODER_IA64
79  {
80  .id = LZMA_FILTER_IA64,
82  .memusage = NULL,
83  .props_decode = &lzma_simple_props_decode,
84  },
85 #endif
86 #ifdef HAVE_DECODER_ARM
87  {
88  .id = LZMA_FILTER_ARM,
90  .memusage = NULL,
91  .props_decode = &lzma_simple_props_decode,
92  },
93 #endif
94 #ifdef HAVE_DECODER_ARMTHUMB
95  {
98  .memusage = NULL,
99  .props_decode = &lzma_simple_props_decode,
100  },
101 #endif
102 #ifdef HAVE_DECODER_SPARC
103  {
104  .id = LZMA_FILTER_SPARC,
106  .memusage = NULL,
107  .props_decode = &lzma_simple_props_decode,
108  },
109 #endif
110 #ifdef HAVE_DECODER_DELTA
111  {
112  .id = LZMA_FILTER_DELTA,
113  .init = &lzma_delta_decoder_init,
114  .memusage = &lzma_delta_coder_memusage,
115  .props_decode = &lzma_delta_props_decode,
116  },
117 #endif
118 };
119 
120 
121 static const lzma_filter_decoder *
123 {
124  for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i)
125  if (decoders[i].id == id)
126  return decoders + i;
127 
128  return NULL;
129 }
130 
131 
133 lzma_filter_decoder_is_supported(lzma_vli id)
134 {
135  return decoder_find(id) != NULL;
136 }
137 
138 
139 extern lzma_ret
141  const lzma_filter *options)
142 {
143  return lzma_raw_coder_init(next, allocator,
145 }
146 
147 
149 lzma_raw_decoder(lzma_stream *strm, const lzma_filter *options)
150 {
152 
155 
156  return LZMA_OK;
157 }
158 
159 
161 lzma_raw_decoder_memusage(const lzma_filter *filters)
162 {
165 }
166 
167 
168 extern LZMA_API(lzma_ret)
169 lzma_properties_decode(lzma_filter *filter, const lzma_allocator *allocator,
170  const uint8_t *props, size_t props_size)
171 {
172  // Make it always NULL so that the caller can always safely free() it.
173  filter->options = NULL;
174 
175  const lzma_filter_decoder *const fd = decoder_find(filter->id);
176  if (fd == NULL)
177  return LZMA_OPTIONS_ERROR;
178 
179  if (fd->props_decode == NULL)
180  return props_size == 0 ? LZMA_OK : LZMA_OPTIONS_ERROR;
181 
182  return fd->props_decode(
183  &filter->options, allocator, props, props_size);
184 }
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
lzma_ret lzma_simple_armthumb_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: armthumb.c:71
#define LZMA_FILTER_IA64
Definition: bcj.h:32
#define LZMA_FILTER_ARM
Definition: bcj.h:37
#define LZMA_FILTER_SPARC
Definition: bcj.h:47
#define LZMA_FILTER_ARMTHUMB
Definition: bcj.h:42
#define LZMA_FILTER_X86
Definition: bcj.h:22
#define LZMA_FILTER_POWERPC
Definition: bcj.h:27
const lzma_allocator * allocator
Definition: block.h:377
const lzma_filter * filters
Definition: container.h:315
#define NULL
Definition: cris-opc.c:27
#define LZMA_FILTER_DELTA
Filter ID.
Definition: delta.h:25
uint64_t lzma_delta_coder_memusage(const void *options)
Definition: delta_common.c:63
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
Delta filter decoder.
const lzma_allocator const uint8_t * props
Definition: filter.h:362
uint64_t lzma_raw_coder_memusage(lzma_filter_find coder_find, const lzma_filter *filters)
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)
Filter-specific stuff common for both encoder and decoder.
const lzma_filter_coder *(* lzma_filter_find)(lzma_vli id)
Definition: filter_common.h:35
static const lzma_filter_decoder decoders[]
LZMA_API(lzma_bool)
lzma_ret lzma_raw_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter *options)
static const lzma_filter_decoder * decoder_find(lzma_vli id)
Filter ID mapping to filter-specific functions.
static lzma_stream strm
Definition: full_flush.c:20
lzma_ret lzma_simple_ia64_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: ia64.c:107
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
#define LZMA_FILTER_LZMA2
LZMA2 Filter ID.
Definition: lzma12.h:40
#define LZMA_FILTER_LZMA1
LZMA1 Filter ID.
Definition: lzma12.h:30
lzma_ret lzma_lzma2_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
uint64_t lzma_lzma2_decoder_memusage(const void *options)
lzma_ret lzma_lzma2_props_decode(void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
LZMA2 decoder.
lzma_ret lzma_lzma_props_decode(void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
uint64_t lzma_lzma_decoder_memusage(const void *options)
lzma_ret lzma_lzma_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Allocates and initializes LZMA decoder.
Definition: lzma_decoder.c:987
LZMA decoder API.
lzma_ret lzma_simple_powerpc_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: powerpc.c:71
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
lzma_ret lzma_simple_x86_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: x86.c:154
lzma_ret lzma_simple_sparc_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: sparc.c:78
lzma_ret lzma_simple_props_decode(void **options, const lzma_allocator *allocator, const uint8_t *props, size_t props_size)
Properties decoder for simple filters.
Custom functions for memory handling.
Definition: base.h:372
lzma_init_function init
lzma_vli id
Filter ID.
Filter options.
Definition: filter.h:43
bool supported_actions[LZMA_ACTION_MAX+1]
Indicates which lzma_action values are allowed by next.code.
Definition: common.h:220
Hold data and function pointers of the next filter in the chain.
Definition: common.h:135
Passing data to and from liblzma.
Definition: base.h:485
lzma_internal * internal
Definition: base.h:505
#define lzma_next_strm_init(func, strm,...)
Definition: common.h:303
lzma_ret(* lzma_init_function)(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Type of a function used to initialize a filter encoder or decoder.
Definition: common.h:97
lzma_ret lzma_simple_arm_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
Definition: arm.c:66
uint64_t lzma_vli
Variable-length integer type.
Definition: vli.h:63
lzma_ret
Return values used by several functions in liblzma.
Definition: base.h:57
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58
@ LZMA_FINISH
Finish the coding operation.
Definition: base.h:328
@ LZMA_RUN
Continue coding.
Definition: base.h:251
unsigned char lzma_bool
Boolean.
Definition: base.h:29
static const z80_opcode fd[]
Definition: z80_tab.h:997