compression

cmp_cri

C implementation of the CRILAYLA compression scheme used by CPK archives.

hacktools.cmp_cri.compressCRILAYLA(indata)

Compress data with the CRILAYLA scheme used by CPK archives.

The first 0x100 bytes of the input are stored uncompressed after the compressed stream, so the input must be at least 0x100 bytes long.

Parameters:

indata (bytes) – Data to compress.

Returns:

The compressed data, starting with the CRILAYLA signature.

Return type:

bytes

hacktools.cmp_cri.decompressCRILAYLA(indata)

Decompress CRILAYLA-compressed data.

Parameters:

indata (bytes) – Compressed data, starting with the CRILAYLA signature.

Returns:

The decompressed data.

Return type:

bytes

cmp_huff

C implementation of the Huffman coding scheme used by the GBA and NDS BIOS.

hacktools.cmp_huff.compressHuffman(indata, numbits=8, little=True)

Compress data with Huffman coding, as used by the GBA and NDS BIOS.

The output starts with the tree size and the tree itself, followed by the 32-bit codeword stream. The 4-byte header with compression type and length is not included and should be written separately.

Parameters:
  • indata (bytes) – Data to compress.

  • numbits (int) – Data size in bits, 8 or 4.

  • little (bool) – Whether nibbles are ordered low-first when numbits is 4.

Returns:

The compressed data.

Return type:

bytes

hacktools.cmp_huff.decompressHuffman(rawdata, decomplength, numbits=8, little=True)

Decompress Huffman-coded data, as used by the GBA and NDS BIOS.

The data is expected to start with the tree size and the tree itself, followed by the 32-bit codeword stream, without the 4-byte header with compression type and length.

Parameters:
  • rawdata (bytes) – Compressed data to read.

  • decomplength (int) – Length of the decompressed data.

  • numbits (int) – Data size in bits, 8 or 4.

  • little (bool) – Whether nibbles are ordered low-first when numbits is 4.

Returns:

The decompressed data.

Return type:

bytes

cmp_lzss

C implementations of the LZ10 and LZ11 compression schemes, LZSS variants used by the GBA and NDS BIOS.

hacktools.cmp_lzss.compressLZ10(indata, mindisp)

Compress data with the LZ10 scheme.

Parameters:
  • indata (bytes) – Data to compress.

  • mindisp (int) – Minimum displacement for references, usually 1.

Returns:

The compressed data, without the 4-byte header.

Return type:

bytes

hacktools.cmp_lzss.compressLZ11(indata, mindisp)

Compress data with the LZ11 scheme.

Parameters:
  • indata (bytes) – Data to compress.

  • mindisp (int) – Minimum displacement for references, usually 1.

Returns:

The compressed data, without the 4-byte header.

Return type:

bytes

hacktools.cmp_lzss.decompressLZ10(data, decomplength, dispextra)

Decompress LZ10-compressed data.

Parameters:
  • data (bytes) – Compressed data to read, without the 4-byte header.

  • decomplength (int) – Length of the decompressed data.

  • dispextra (int) – Value added to the read displacements, usually 1.

Returns:

The decompressed data.

Return type:

bytes

hacktools.cmp_lzss.decompressLZ11(data, decomplength, dispextra)

Decompress LZ11-compressed data.

Parameters:
  • data (bytes) – Compressed data to read, without the 4-byte header.

  • decomplength (int) – Length of the decompressed data.

  • dispextra (int) – Value added to the read displacements, usually 1.

Returns:

The decompressed data.

Return type:

bytes

cmp_misc

C implementations of miscellaneous compression schemes.

hacktools.cmp_misc.compressRLE(indata)

Compress data with the RLE scheme, as used by the GBA and NDS BIOS.

Parameters:

indata (bytes) – Data to compress.

Returns:

The compressed data, without the 4-byte header.

Return type:

bytes

hacktools.cmp_misc.decompressRLE(data, decomplength)

Decompress RLE-compressed data, as used by the GBA and NDS BIOS.

Parameters:
  • data (bytes) – Compressed data to read, without the 4-byte header.

  • decomplength (int) – Length of the decompressed data.

Returns:

The decompressed data.

Return type:

bytes

cmp_prs

C implementation of the PRS compression scheme, an LZ77 variant.

hacktools.cmp_prs.compressPRS(indata)

Compress data with the PRS scheme, an LZ77 variant.

Parameters:

indata (bytes) – Data to compress.

Returns:

The compressed data.

Return type:

bytes

hacktools.cmp_prs.decompressPRS(data, decomplength)

Decompress PRS data, an LZ77 variant.

Parameters:
  • data (bytes) – Compressed data to read.

  • decomplength (int) – Length of the decompressed data.

Returns:

The decompressed data.

Return type:

bytes

cmp_racjin

C implementation of the compression scheme used by Racjin games.

hacktools.cmp_racjin.compressRACJIN(indata)

Compress data with the scheme used by Racjin games.

Parameters:

indata (bytes) – Data to compress.

Returns:

The compressed data.

Return type:

bytes

hacktools.cmp_racjin.decompressRACJIN(indata, decomplength)

Decompress Racjin-compressed data.

Parameters:
  • indata (bytes) – Compressed data to read.

  • decomplength (int) – Length of the decompressed data.

Returns:

The decompressed data.

Return type:

bytes