This is the code I used for decompression. It uses Crush32.cs from https://github.com/cyberjunk/meridian59-dotnet/blob/c45a65552333509220b11b41ecc46d75023b5acd/Meridian59/Files/BGF/BgfBitmap.cs and Kaitai Struct (https://kaitai.io/) to slice the files. It should work for book.bbi and probably for other formats as well, it's been a long time so I don't exactly remember all the difficulties I ran into while decompressing and tinkering with these files.
foreach (string dir in Directory.EnumerateDirectories(@"F:\database\komatsu")) {
foreach (string file in Directory.EnumerateFiles(dir, "book.bbi")) {
Console.WriteLine("Decompressing " + file);
Bbi03 page = Bbi03.FromFile(file);
byte[] decompressedData = new byte[(int)page.UncompressedLength1];
bool status = Crush32.Decompress(page.Data, 0, decompressedData, 0, (int)page.UncompressedLength1, (int)page.CompressedLength);
Console.WriteLine(status);
File.WriteAllBytes(@"saa6d1jc\" + Path.GetFileNameWithoutExtension(file) + ".bin", decompressedData);
}
}
And here are the .ksy files:
book_bbi.ksy
meta:
id: book_bbi
endian: le
encoding: ASCII
seq:
- id: file_header
type: str
size: 22
- id: date
type: str
size: 16
- id: magic
# bbi 03-04.030: [0xff, 0x7f, 0xff, 0x7f]
# bbi 04.100: [0x88, 0x03, 0xca, 0x03]
size: 4
- id: data_header_start
contents: [0x02, 0x00]
- id: compressed_length_with_header
type: u4
- id: uncompressed_length
type: u4
- id: uncompressed_length_2
type: u2
- id: compressed_length
type: u2
- id: data_header_end
contents: [0x00, 0x00]
- id: data
size: compressed_length
bli_03.ksy
meta:
id: bli_03
endian: le
encoding: ASCII
seq:
- id: file_header
type: str
size: 22
- id: date
type: str
size: 16
- id: data_header_start
contents: [0x02, 0x00]
- id: compressed_length_with_header
type: u4
- id: uncompressed_length_1
type: u4
- id: uncompressed_length_2
type: u2
- id: compressed_length
type: u2
- id: data_header_end
contents: [0x00, 0x00]
- id: data
size: compressed_length
ilg_00.ksy
meta:
id: ilg_00
endian: le
encoding: ASCII
seq:
- id: header
type: str
size: 22
size: 16
- id: smth1
size: 4
- id: width
type: u2
- id: height
type: u2
- id: bits_per_pixel
type: u2
- id: dpi
type: u2
- id: smth2
size: 12
- id: data_length
type: u4
- id: smth3
size: 12
- id: data
size: data_length
ilg_03.ksy
meta:
id: ilg_03
endian: le
encoding: ASCII
seq:
- id: header
type: str
size: 22
- id: date
type: str
size: 16
- id: smth1
size: 4
- id: width
type: u2
- id: height
type: u2
- id: bits_per_pixel
type: u2
- id: dpi
type: u2
- id: smth2
size: 12
- id: data_length
type: u4
- id: smth3
size: 12
- id: data
size: data_length