Rizin
unix-like reverse engineering framework and cli tools
compression.c File Reference
#include <rz_util.h>
#include <zlib.h>

Go to the source code of this file.

Macros

#define MAXOUT   50000000
 

Functions

RZ_API ut8rz_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, and use MAX_WBITS as the window size logarithm. More...
 
RZ_API ut8rz_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. More...
 
RZ_API ut8rz_inflatew (RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
 
RZ_API ut8rz_deflatew (RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
 
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_inflatew_buf (RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
 
RZ_API ut8rz_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. More...
 
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. More...
 
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. More...
 
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_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. More...
 
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. More...
 

Macro Definition Documentation

◆ MAXOUT

#define MAXOUT   50000000

Definition at line 12 of file compression.c.

Function Documentation

◆ lzma_action_buf()

static bool lzma_action_buf ( RZ_NONNULL RzBuffer src,
RZ_NONNULL RzBuffer dst,
ut64  block_size,
ut8 src_consumed,
bool  encode 
)
static

Definition at line 449 of file compression.c.

449  {
450  return false;
451 }

Referenced by rz_lzma_dec_buf(), and rz_lzma_enc_buf().

◆ rz_deflate()

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.

See also
rz_deflatew()

Definition at line 340 of file compression.c.

340  {
342  rz_return_val_if_fail(srcLen > 0, NULL);
343  return rz_deflatew(src, srcLen, srcConsumed, dstLen, MAX_WBITS + 16);
344 }
lzma_index * src
Definition: index.h:567
RZ_API ut8 * rz_deflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
Definition: compression.c:323
#define NULL
Definition: cris-opc.c:27
#define MAX_WBITS
Definition: flirt.c:105
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References MAX_WBITS, NULL, rz_deflatew(), rz_return_val_if_fail, and src.

◆ rz_deflate_buf()

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.

See also
rz_deflatew_buf()

Definition at line 350 of file compression.c.

350  {
351  rz_return_val_if_fail(src && dst, false);
352  rz_return_val_if_fail(block_size > 0, false);
353  return rz_deflatew_buf(src, dst, block_size, src_consumed, MAX_WBITS + 16);
354 }
RZ_API bool rz_deflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
Definition: compression.c:327
char * dst
Definition: lz4.h:724

References dst, MAX_WBITS, rz_deflatew_buf(), rz_return_val_if_fail, and src.

Referenced by rz_file_deflate().

◆ rz_deflatew()

RZ_API ut8* rz_deflatew ( RZ_NONNULL const ut8 src,
int  srcLen,
int srcConsumed,
int dstLen,
int  wbits 
)

Definition at line 323 of file compression.c.

323  {
324  return NULL;
325 }

References NULL.

Referenced by rz_deflate().

◆ rz_deflatew_buf()

RZ_API bool rz_deflatew_buf ( RZ_NONNULL RzBuffer src,
RZ_NONNULL RzBuffer dst,
ut64  block_size,
ut8 src_consumed,
int  wbits 
)

Definition at line 327 of file compression.c.

327  {
328  return false;
329 }

Referenced by rz_deflate_buf(), and rz_sign_flirt_write_compressed_pattern_to_buffer().

◆ rz_inflate()

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, and use MAX_WBITS as the window size logarithm.

See also
rz_inflatew()

Definition at line 18 of file compression.c.

18  {
20  rz_return_val_if_fail(srcLen > 0, NULL);
21  return rz_inflatew(src, srcLen, srcConsumed, dstLen, MAX_WBITS + 32);
22 }
RZ_API ut8 * rz_inflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
Definition: compression.c:319

References MAX_WBITS, NULL, rz_inflatew(), rz_return_val_if_fail, and src.

Referenced by __open(), rz_cmd_print(), rz_file_gzslurp(), and rz_sign_flirt_parse_compressed_pattern_from_buffer().

◆ rz_inflate_buf()

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.

See also
rz_inflatew_buf()

Definition at line 360 of file compression.c.

360  {
361  rz_return_val_if_fail(src && dst, false);
362  rz_return_val_if_fail(block_size > 0, false);
363  return rz_inflatew_buf(src, dst, block_size, src_consumed, MAX_WBITS + 32);
364 }
RZ_API bool rz_inflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits)
Definition: compression.c:331

References dst, MAX_WBITS, rz_inflatew_buf(), rz_return_val_if_fail, and src.

Referenced by rz_file_inflate().

◆ rz_inflate_ignore_header()

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.

See also
rz_inflatew()

Definition at line 28 of file compression.c.

28  {
30  rz_return_val_if_fail(srcLen > 0, NULL);
31  return rz_inflatew(src, srcLen, srcConsumed, dstLen, -MAX_WBITS);
32 }

References MAX_WBITS, NULL, rz_inflatew(), rz_return_val_if_fail, and src.

Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer().

◆ rz_inflatew()

RZ_API ut8* rz_inflatew ( RZ_NONNULL const ut8 src,
int  srcLen,
int srcConsumed,
int dstLen,
int  wbits 
)

Definition at line 319 of file compression.c.

319  {
320  return NULL;
321 }

References NULL.

Referenced by rz_inflate(), and rz_inflate_ignore_header().

◆ rz_inflatew_buf()

RZ_API bool rz_inflatew_buf ( RZ_NONNULL RzBuffer src,
RZ_NONNULL RzBuffer dst,
ut64  block_size,
ut8 src_consumed,
int  wbits 
)

Definition at line 331 of file compression.c.

331  {
332  return false;
333 }

Referenced by rz_inflate_buf().

◆ rz_lzma_dec_buf()

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.

Parameters
srcWhere to read the compressed data from
dstWhere to write the decompressed data to
block_sizeDecompression can happen block after block. Specify the size of the block here.
Returns
true if decompression was successful, false otherwise

Definition at line 462 of file compression.c.

462  {
463  return lzma_action_buf(src, dst, block_size, src_consumed, false);
464 }
static bool lzma_action_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, bool encode)
Definition: compression.c:449

References dst, lzma_action_buf(), and src.

Referenced by get_gnu_debugdata_elf_symbols().

◆ rz_lzma_enc_buf()

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.

Parameters
srcWhere to read the decompressed data from
dstWhere to write the compressed data to
block_sizeCompression can happen block after block. Specify the size of the block here.
Returns
true if compression was successful, false otherwise

Definition at line 474 of file compression.c.

474  {
475  return lzma_action_buf(src, dst, block_size, src_consumed, true);
476 }

References dst, lzma_action_buf(), and src.