patch/reboot.c patch/svc.c patch/module.c patch/emunand.c \
std/fs.c std/draw.c std/memory.c std/abort.c \
firm/util.c firm/keys.c firm/firmlaunch.c firm/version.c firm/firm.c firm/decryptor.c \
- configback/file-dat.c
+ configback/file-dat.c ../common/lzss.c
-#ifndef __LZSS_H
-#define __LZSS_H
+#include <stdint.h>
-static int
-lzss_decompress(u8 *buffer)
+
+int
+lzss_decompress(uint8_t *buffer)
{
// This WAS originally a decompilation in @yifan_lu's repo; it was rewritten
// for readability following ctrtool's namings.
+
+ // This implementation is particularly interesting in that it's an in-place
+ // decompressor.
+
+ // LZSS is performed in the reverse direction,
+ // and the last four bytes are the decompressed size.
+ // Presumably, Nintendo did as such so decompression can occur in-place without need for temporary buffers.
+
unsigned int decompSize, v15;
- u8 *compressEndOff, *index, *stopIndex;
+ uint8_t *compressEndOff, *index, *stopIndex;
char control;
int v9, v13, v14, v16;
int ret = 0;
return 0;
// v1=decompressedSize, v2=compressedSize, v3=index, v4=stopIndex
- decompSize = *((u32 *)buffer - 2);
- compressEndOff = &buffer[*((u32 *)buffer - 1)];
+ decompSize = *((uint32_t *)buffer - 2);
+ compressEndOff = &buffer[*((uint32_t *)buffer - 1)];
index = &buffer[-(decompSize >> 24)]; // FIXME - The integer negation is due
// to a compiler optimization. It's
// probably okay, but...
v13 = *(index - 1);
v14 = *(index - 2);
index -= 2;
- v15 = ((v14 | (v13 << 8)) & 0xFFFF0FFF) + 2;
+ v15 = (((unsigned int)v14 | ((unsigned int)v13 << 8)) & 0xFFFF0FFF) + 2;
v16 = v13 + 32;
do {
ret = compressEndOff[v15];
return ret;
}
-
-#endif