My friend would like to add: "I have probably not been clear enough when discussing the LZS file format, earlier. Here a few hints to decompress the "font.lzs" file:
+ the correct MD5 for the decompressed "font.txf" file is "bb0ba777897592907c95ba6aac750407"
+ its header (first 16 bytes) is "0c 01 01 01 04 00 08 e0 00 01 00 00 00 47 00 00"
Here is the code, if you feel like using it:
Code:
#!/usr/bin/perl
use strict;
if ((scalar @ARGV) != 2) {
print "Usage: d4unlzs SRC.lzs DEST\n";
exit(1);
}
my $infile;
my $outfile;
if (!open($infile, "<$ARGV[0]")) {
print "Error: cannot open input file.\n";
exit(1);
}
binmode ($infile);
my $dest_size;
my $src_size;
my $flag;
# Parsing 16-byte header:
# ----------------------
sub readU32Le {
my $c;
my $rv = 0;
read($infile, $c, 1); $rv += ord($c);
read($infile, $c, 1); $rv += ord($c) * 256;
read($infile, $c, 1); $rv += ord($c) * 256 * 256;
read($infile, $c, 1); $rv += ord($c) * 256 * 256 * 256;
return $rv;
}
&readU32Le; # Extension and unused byte -- safe to ignore
$dest_size = &readU32Le; # Uncompressed size
$src_size = &readU32Le; # Compressed size (file size - 4 bytes)
$flag = &readU32Le; # Flag
if ($flag > 255) {
print "Error: flag not valid. Bad LZS file?\n";
exit(1);
}
# Opening output file:
# -------------------
if (!open($outfile, ">$ARGV[1]")) {
print "Error: cannot open output file.\n";
exit(1);
}
binmode ($outfile);
# Uncompression loop:
# ------------------
my $pos = 0;
my $c;
my $val;
my @dest = ();
for (my $i = 0; $i < ($src_size - 12); ++$i) {
read($infile, $c, 1) or die "File too short!\n";
$val = ord($c);
if ($val == $flag) {
read($infile, $c, 1) or die "File too short!\n";
$val = ord($c);
$i++;
if ($val == $flag) {
push @dest, $val;
} else {
my $jump = $val;
my $n_copied;
$jump-- if ($jump > $flag);
read($infile, $c, 1) or die "File too short!\n";
$n_copied = ord($c);
$i++;
for (my $j = 0; $j < $n_copied; ++$j) {
my $idx = (scalar @dest) - $jump;
push @dest, $dest[$idx];
}
}
} else {
push @dest, $val;
}
}
# Writing output file:
# -------------------
foreach (@dest) {
print $outfile pack('C', $_);
} And to answer Tidus' question: for lines containing and odd-number of characters, adding a space after the last character seems to work well enough."