Rizin
unix-like reverse engineering framework and cli tools
|
Go to the source code of this file.
Classes | |
struct | lzxd_stream |
Functions | |
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) |
void | lzxd_set_output_length (struct lzxd_stream *lzx, off_t output_length) |
int | lzxd_set_reference_data (struct lzxd_stream *lzx, struct mspack_system *system, struct mspack_file *input, unsigned int length) |
int | lzxd_decompress (struct lzxd_stream *lzx, off_t out_bytes) |
void | lzxd_free (struct lzxd_stream *lzx) |
#define LZX_ALIGNED_MAXSYMBOLS (LZX_ALIGNED_NUM_ELEMENTS) |
#define LZX_ALIGNED_NUM_ELEMENTS (8) /* aligned offset tree #elements */ |
#define LZX_BLOCKTYPE_INVALID (0) /* also blocktypes 4-7 invalid */ |
#define LZX_LENGTH_MAXSYMBOLS (LZX_NUM_SECONDARY_LENGTHS+1) |
#define LZX_LENTABLE_SAFETY (64) /* table decoding overruns are allowed */ |
#define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 290*8) |
#define LZX_NUM_PRIMARY_LENGTHS (7) /* this one missing from spec! */ |
#define LZX_NUM_SECONDARY_LENGTHS (249) /* length tree #elements */ |
#define LZX_PRETREE_MAXSYMBOLS (LZX_PRETREE_NUM_ELEMENTS) |
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.
References lzxd_stream::ALIGNED_len, lzxd_stream::bit_buffer, lzxd_stream::bits_left, lzxd_stream::block_length, lzxd_stream::block_remaining, lzxd_stream::block_type, BUILD_TABLE, BUILD_TABLE_MAYBE_EMPTY, mspack_system::copy, D, lzxd_stream::e8_buf, ENSURE_BITS, lzxd_stream::error, extra_bits, lzxd_stream::frame, lzxd_stream::frame_posn, lzxd_stream::header_read, i, lzxd_stream::i_end, lzxd_stream::i_ptr, int, lzxd_stream::intel_filesize, lzxd_stream::intel_started, lzxd_stream::is_delta, lzxd_stream::length, LENGTH, lzxd_stream::LENGTH_empty, LZX_BLOCKTYPE_ALIGNED, LZX_BLOCKTYPE_UNCOMPRESSED, LZX_BLOCKTYPE_VERBATIM, LZX_FRAME_SIZE, LZX_MAX_MATCH, LZX_MIN_MATCH, LZX_NUM_CHARS, LZX_NUM_PRIMARY_LENGTHS, LZX_NUM_SECONDARY_LENGTHS, lzxd_reset_state(), lzxd_stream::MAINTREE_len, mspack_system::message, MSPACK_ERR_ARGS, MSPACK_ERR_DECRUNCH, MSPACK_ERR_OK, MSPACK_ERR_WRITE, NULL, lzxd_stream::num_offsets, lzxd_stream::o_end, lzxd_stream::o_ptr, lzxd_stream::offset, lzxd_stream::output, PEEK_BITS, position_base, lzxd_stream::R0, R0, lzxd_stream::R1, lzxd_stream::R2, R2, READ_BITS, READ_HUFFSYM, READ_IF_NEEDED, READ_LENGTHS, lzxd_stream::ref_data_size, REMOVE_BITS, lzxd_stream::reset_interval, RESTORE_BITS, STORE_BITS, lzxd_stream::sys, lzxd_stream::window, lzxd_stream::window_posn, lzxd_stream::window_size, and mspack_system::write.
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.
References mspack_system::free, lzxd_stream::inbuf, lzxd_stream::sys, and lzxd_stream::window.
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.
References mspack_system::alloc, D, lzxd_stream::e8_buf, lzxd_stream::error, lzxd_stream::frame, lzxd_stream::frame_posn, mspack_system::free, lzxd_stream::inbuf, lzxd_stream::inbuf_size, INIT_BITS, lzxd_stream::input, input(), lzxd_stream::intel_filesize, lzxd_stream::intel_started, lzxd_stream::is_delta, lzxd_stream::length, lzxd_reset_state(), MSPACK_ERR_OK, NULL, lzxd_stream::num_offsets, lzxd_stream::o_end, lzxd_stream::o_ptr, lzxd_stream::offset, lzxd_stream::output, output, position_slots, lzxd_stream::ref_data_size, lzxd_stream::reset_interval, lzxd_stream::sys, lzxd_stream::window, lzxd_stream::window_posn, and lzxd_stream::window_size.
void lzxd_set_output_length | ( | struct lzxd_stream * | lzx, |
off_t | output_length | ||
) |
Definition at line 389 of file lzxd.c.
References lzxd_stream::length.
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.
References bytes, D, input(), lzxd_stream::is_delta, length, MSPACK_ERR_ARGS, MSPACK_ERR_OK, MSPACK_ERR_READ, lzxd_stream::offset, pos, mspack_system::read, lzxd_stream::ref_data_size, lzxd_stream::window, and lzxd_stream::window_size.