这是我用来解压的代码。它采用Crush32.cs从https://github.com/cyberjunk/meridian59-dotnet/blob/c45a65552333509220b11b41ecc46d75023b5acd/Meridian59/Files/BGF/BgfBitmap.cs和开泰结构(https://kaitai.io/)裁文件. 它应该适用于 book.bbi 并且可能也适用于其他格式,已经很长时间了,所以我不记得在解压缩和修改这些文件时遇到的所有困难。
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);
}
}
这是 .ksy 文件:
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