This commit is contained in:
neauoire 2023-11-15 14:21:05 -08:00
parent 165783bb1e
commit 4cd8512399
1 changed files with 18 additions and 25 deletions

View File

@ -1,9 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
char *ptr;
char *mem;
/* cc ulzdec.c -o ulzdec && ./ulzdec compressed.bin */
static int
@ -13,28 +10,25 @@ error(const char *name, const char *msg)
return 0;
}
char *mem, *ptr;
void
decode_byte(FILE *fp, char c)
decode_ulz(FILE *fp)
{
short i, length, offset;
/* DICT */
if(c & 0x80) {
if(c & 0x40)
length = (c & 0x3f) << 8 | getc(fp);
else
length = c & 0x3f;
length += 4, offset = getc(fp) + 1;
printf("DICT %04x, %02x\n", length, offset);
}
/* LIT */ else {
length = c + 1;
printf("LIT%02x ", length);
for(i = 0; i < length; ++i) {
unsigned char c2 = getc(fp);
printf("%c", c2 == '\n' ? ' ' : c2);
*(ptr++) = c2;
}
printf("\n");
char *dict;
short i, length;
while((c = getc(src)) != EOF) {
if(c & 0x80) { /* DICT */
if(c & 0x40)
length = (c & 0x3f) << 8 | getc(src);
else
length = c & 0x3f;
dict = ptr - (getc(src) + 1);
for(i = 0; i < length + 4; i++)
*(ptr++) = *(dict++);
} else /* LIT */
for(i = 0; i < c + 1; i++)
*(ptr++) = getc(src);
}
}
@ -51,8 +45,7 @@ main(int argc, char *argv[])
return !error("Invalid input", argv[1]);
mem = malloc(0x10000);
ptr = mem;
while((c = getc(src)) != EOF)
decode_byte(src, c);
decode_ulz(src);
*(ptr) = 0;
printf("%s\n", mem);
return 0;