Rizin
unix-like reverse engineering framework and cli tools
|
Go to the source code of this file.
Macros | |
#define | BITS_TYPE struct lzxd_stream |
#define | BITS_VAR lzx |
#define | BITS_ORDER_MSB |
#define | READ_BYTES |
#define | TABLEBITS(tbl) LZX_##tbl##_TABLEBITS |
#define | MAXSYMBOLS(tbl) LZX_##tbl##_MAXSYMBOLS |
#define | HUFF_TABLE(tbl, idx) lzx->tbl##_table[idx] |
#define | HUFF_LEN(tbl, idx) lzx->tbl##_len[idx] |
#define | HUFF_ERROR return lzx->error = MSPACK_ERR_DECRUNCH |
#define | BUILD_TABLE(tbl) |
#define | BUILD_TABLE_MAYBE_EMPTY(tbl) |
#define | READ_LENGTHS(tbl, first, last) |
Functions | |
static int | lzxd_read_lens (struct lzxd_stream *lzx, unsigned char *lens, unsigned int first, unsigned int last) |
static void | lzxd_reset_state (struct lzxd_stream *lzx) |
struct lzxd_stream * | lzxd_init (struct mspack_system *system, struct mspack_file *input, struct mspack_file *output, int window_bits, int reset_interval, int input_buffer_size, off_t output_length, char is_delta) |
int | lzxd_set_reference_data (struct lzxd_stream *lzx, struct mspack_system *system, struct mspack_file *input, unsigned int length) |
void | lzxd_set_output_length (struct lzxd_stream *lzx, off_t out_bytes) |
int | lzxd_decompress (struct lzxd_stream *lzx, off_t out_bytes) |
void | lzxd_free (struct lzxd_stream *lzx) |
Variables | |
static const unsigned int | position_slots [11] |
static const unsigned char | extra_bits [36] |
static const unsigned int | position_base [290] |
#define BITS_TYPE struct lzxd_stream |
#define BUILD_TABLE | ( | tbl | ) |
#define BUILD_TABLE_MAYBE_EMPTY | ( | tbl | ) |
#define HUFF_ERROR return lzx->error = MSPACK_ERR_DECRUNCH |
#define READ_BYTES |
#define READ_LENGTHS | ( | tbl, | |
first, | |||
last | |||
) |
int lzxd_decompress | ( | struct lzxd_stream * | lzx, |
off_t | out_bytes | ||
) |
Decompresses entire or partial LZX streams.
The number of bytes of data that should be decompressed is given as the out_bytes parameter. If more bytes are decoded than are needed, they will be kept over for a later invocation.
The output bytes will be passed to the system->write() function given in lzxd_init(), using the output file handle given in lzxd_init(). More than one call may be made to system->write().
Input bytes will be read in as necessary using the system->read() function given in lzxd_init(), using the input file handle given in lzxd_init(). This will continue until system->read() returns 0 bytes, or an error. Errors will be passed out of the function as MSPACK_ERR_READ errors. Input streams should convey an "end of input stream" by refusing to supply all the bytes that LZX asks for when they reach the end of the stream, rather than return an error code.
If any error code other than MSPACK_ERR_OK is returned, the stream should be considered unusable and lzxd_decompress() should not be called again on this stream.
lzx | LZX decompression state, as allocated by lzxd_init(). |
out_bytes | the number of bytes of data to decompress. |
Definition at line 393 of file lzxd.c.
void lzxd_free | ( | struct lzxd_stream * | lzx | ) |
Frees all state associated with an LZX data stream. This will call system->free() using the system pointer given in lzxd_init().
lzx | LZX decompression state to free. |
Definition at line 800 of file lzxd.c.
struct lzxd_stream* lzxd_init | ( | struct mspack_system * | system, |
struct mspack_file * | input, | ||
struct mspack_file * | output, | ||
int | window_bits, | ||
int | reset_interval, | ||
int | input_buffer_size, | ||
off_t | output_length, | ||
char | is_delta | ||
) |
Allocates and initialises LZX decompression state for decoding an LZX stream.
This routine uses system->alloc() to allocate memory. If memory allocation fails, or the parameters to this function are invalid, NULL is returned.
system | an mspack_system structure used to read from the input stream and write to the output stream, also to allocate and free memory. |
input | an input stream with the LZX data. |
output | an output stream to write the decoded data to. |
window_bits | the size of the decoding window, which must be between 15 and 21 inclusive for regular LZX data, or between 17 and 25 inclusive for LZX DELTA data. |
reset_interval | the interval at which the LZX bitstream is reset, in multiples of LZX frames (32678 bytes), e.g. a value of 2 indicates the input stream resets after every 65536 output bytes. A value of 0 indicates that the bitstream never resets, such as in CAB LZX streams. |
input_buffer_size | the number of bytes to use as an input bitstream buffer. |
output_length | the length in bytes of the entirely decompressed output stream, if known in advance. It is used to correctly perform the Intel E8 transformation, which must stop 6 bytes before the very end of the decompressed stream. It is not otherwise used or adhered to. If the full decompressed length is known in advance, set it here. If it is NOT known, use the value 0, and call lzxd_set_output_length() once it is known. If never set, 4 of the final 6 bytes of the output stream may be incorrect. |
is_delta | should be zero for all regular LZX data, non-zero for LZX DELTA encoded data. |
Definition at line 279 of file lzxd.c.
|
static |
Definition at line 138 of file lzxd.c.
References BUILD_TABLE, i, MSPACK_ERR_OK, lzxd_stream::PRETREE_len, READ_BITS, READ_HUFFSYM, RESTORE_BITS, STORE_BITS, and x.
|
static |
Definition at line 262 of file lzxd.c.
References lzxd_stream::block_remaining, lzxd_stream::block_type, lzxd_stream::header_read, i, lzxd_stream::LENGTH_len, LZX_BLOCKTYPE_INVALID, LZX_LENGTH_MAXSYMBOLS, LZX_MAINTREE_MAXSYMBOLS, lzxd_stream::MAINTREE_len, lzxd_stream::R0, lzxd_stream::R1, and lzxd_stream::R2.
Referenced by lzxd_decompress(), and lzxd_init().
void lzxd_set_output_length | ( | struct lzxd_stream * | lzx, |
off_t | out_bytes | ||
) |
int lzxd_set_reference_data | ( | struct lzxd_stream * | lzx, |
struct mspack_system * | system, | ||
struct mspack_file * | input, | ||
unsigned int | length | ||
) |
Reads LZX DELTA reference data into the window and allows lzxd_decompress() to reference it.
Call this before the first call to lzxd_decompress().
lzx | the LZX stream to apply this reference data to |
system | an mspack_system implementation to use with the input param. Only read() will be called. |
input | an input file handle to read reference data using system->read(). |
length | the length of the reference data. Cannot be longer than the LZX window size. |
Definition at line 353 of file lzxd.c.
Definition at line 217 of file lzxd.c.
Referenced by lzxd_decompress().
Definition at line 221 of file lzxd.c.
Referenced by lzxd_decompress().