12 #define MAXOUT 50000000
35 static const char *gzerr(
int n) {
36 const char *errors[] = {
41 "insufficient memory",
43 "incompatible version",
83 if (
stream.avail_out == 0) {
89 out_size += srcLen * 2;
94 stream.avail_out = srcLen * 2;
104 *dstLen =
stream.total_out;
151 if (
stream.avail_out == 0) {
162 stream.avail_out = srcLen;
172 *dstLen =
stream.total_out;
202 ut64 dst_cursor = 0, src_cursor = 0;
203 ut64 src_readlen = 0;
216 ut8 *src_tmpbuf =
malloc(block_size), *dst_tmpbuf =
malloc(block_size);
219 while ((src_readlen =
rz_buf_read_at(
src, src_cursor, src_tmpbuf, block_size)) > 0) {
220 src_cursor += src_readlen;
221 stream.avail_in = src_readlen;
223 stream.next_out = dst_tmpbuf;
224 stream.avail_out = block_size;
227 if (src_readlen < block_size) {
241 *src_consumed = src_cursor;
269 ut64 src_readlen = 0;
282 int comp_factor = 1032;
283 ut8 *src_tmpbuf =
malloc(block_size), *dst_tmpbuf =
malloc(comp_factor * block_size);
285 while ((src_readlen =
rz_buf_read_at(
src, src_cursor, src_tmpbuf, block_size)) > 0) {
286 src_cursor += src_readlen;
287 stream.avail_in = src_readlen;
289 stream.next_out = dst_tmpbuf;
290 stream.avail_out = comp_factor * block_size;
293 if (src_readlen < block_size) {
307 *src_consumed = src_cursor;
374 const ut64 memusage_limit = 0x1000000;
375 ret = lzma_stream_decoder(&
strm, memusage_limit, 0);
387 ut64 src_readlen = 0;
398 if (src_readlen < 0) {
402 if (src_readlen == 0) {
407 src_cursor += src_readlen;
437 *src_consumed = src_cursor;
RZ_API bool rz_inflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
inflate compressed data in RzBbuffer, use MAX_WBITS as the window size logarithm.
RZ_API ut8 * rz_deflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
deflate uncompressed data to zlib or gzipped, use MAX_WBITS as the window size logarithm.
RZ_API ut8 * rz_inflate_ignore_header(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
inflate zlib compressed or gzipped. The input must be a raw stream with no header or trailer.
RZ_API bool rz_lzma_enc_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
Compress the src buffer with LZMA algorithm and put the compressed data in dst.
RZ_API bool rz_deflate_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
deflate uncompressed data in RzBbuffer to zlib or gzipped, use MAX_WBITS as the window size logarithm...
static bool lzma_action_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, bool encode)
RZ_API bool rz_inflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
RZ_API ut8 * rz_inflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
RZ_API ut8 * rz_inflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
inflate zlib compressed or gzipped, automatically accepts either the zlib or gzip format,...
RZ_API bool rz_deflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
RZ_API bool rz_lzma_dec_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed)
Decompress the src buffer with LZMA algorithm and put the decompressed data in dst.
RZ_API ut8 * rz_deflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
#define LZMA_PRESET_DEFAULT
Default compression preset.
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
static void encode(size_t size, lzma_action action)
unsigned char outbuf[SIZE]
unsigned char inbuf[SIZE]
RZ_API void Ht_() free(HtName_(Ht) *ht)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateEnd(z_streamp strm)
return memset(p, 0, total)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
The public API of liblzma data compression library.
#define rz_return_val_if_fail(expr, val)
RZ_API ut64 rz_buf_tell(RZ_NONNULL RzBuffer *b)
Return the current cursor position.
RZ_API bool rz_buf_resize(RZ_NONNULL RzBuffer *b, ut64 newsize)
Resize the buffer size.
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
RZ_API st64 rz_buf_write(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the cursor.
#define RZ_LOG_ERROR(fmtstr,...)
Passing data to and from liblzma.
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_OK
Operation completed successfully.
lzma_action
The ‘action’ argument for lzma_code()
@ LZMA_FINISH
Finish the coding operation.
@ LZMA_RUN
Continue coding.
#define LZMA_STREAM_INIT
Initialization for lzma_stream.
#define Z_DEFAULT_STRATEGY
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
#define inflateInit2(strm, windowBits)
#define Z_DEFAULT_COMPRESSION