Finally getting back to this, after using the cipher on the file header I've determined (mostly) the header table to be as such:
1 byte Unknown
3 byte Signature
4*n bytes Sub Table Offsets (values of FFFFFFFF are ignored, stop at a value less than -1 or greater than the header size)
> 2 bytes Number of files
> N bytes Binary map of valid files ceil(num files / 8 )
-> 4 bytes File Offset
-> 4 bytes File Size
After separating the files I can analyze them one by one, and I've managed to figure out how they are encrypted. There's one slight problem though, the scheme changes from file to file.
Explanation:
The cipher is just a repeating cycle of 256 bytes, which can be described by a repeating sequence of the 4 low bits and the 4 high bits. The low bits change every 2 bytes, and the high bits change every 32 bytes. Below are my observations of each file in the bsys archive. Left is the table of low bits (with high bit attached), right is the high bit sequence.
File Low High
0 02 02 00 00 06 06 04 04 (0 2 4 6 8 a c e)
1 1c 1c 1e 1e 18 18 1a 1a (1 3 5 7 9 b d f)
2 18 18 1a 1a 1c 1c 1e 1e (1 3 5 7 9 b d f)
3 55 55 57 57 51 51 53 53 (5 7 1 3 d f 9 b)
4 1e 1e 1c 1c 1a 1a 18 18 (1 3 5 7 9 b d f)
5 4d 4d 4f 4f 49 49 4b 4b (4 6 0 2 c e 8 a)
6 26 26 24 24 22 22 20 20 ??
7 58 58 5a 5a 5c 5c 5e 5e (5 7 1 3 d f 9 b)
8 0a 0a 08 08 0e 0e 0c 0c (0 2 4 6 8 a c e)
And analysis for the se archive
0 02 02 00 00 06 06 04 04 (0 2 4 6 8 a c e)
1 19 19 1b 1b 1d 1d 1f 1f (1 3 5 7 9 b d f)
2 26 26 24 24 22 22 20 20 (2 0 6 4 a 8 e c)
3 29 29 2b 2b 2d 2d 2f 2f (2 0 6 4 a 8 e c)
4 28 28 2a 2a 2c 2c 2e 2e (2 0 6 4 a 8 e c)
5 7b 7b 79 79 7f 7f 7d 7d (7 5 3 1 f d b 9)
6 7a 7a 78 78 7e 7e 7c 7c (7 5 3 1 f d b 9)
7 8f 8f 8d 8d 8b 8b 89 89 (8 a c e 0 2 4 6)
8 44 44 46 46 40 40 42 42 (4 6 0 2 c e 8 a)
... others
As you can see, it is not dependent on file number, which leaves us with a few options
- The archive header
- File sizes
- File offsets
So let's tabulate these
Size Hex Offset
8323098 7F001A 00000000
2425062 2500E6 007F001A
1379478 150C96 00A40100
3492674 354B42 00B90D96
480710 0755C6 00EE58D8
467466 07220A 00F5AE9E
7436438 717896 00FCD0A8
6357958 6103C6 016E493E
1019986 0F9052 01CF4D04
And once more for se
147478 024016 00000000
133534 02099E 00024016
134606 020DCE 000449B4
139438 0220AE 00065782
117454 01CACE 00087830
132462 02056E 000A42FE
132998 020786 000C486C
141046 0226F6 000E4FF2
143726 02316E 001076E8
As you can see the file sizes for the first file in both archives are radically different, but share the same pattern. This leaves us with the file offsets and the header table itself. Unfortunately, looking at the first file of smbgm quickly destroys the possibility of the file offset dependency.
0 0 2 2 4 4 6 6 (5 7 1 3 d f 9 b)
grp
e e c c a a 8 8 (0 2 4 6 8 a c e)
It's easy to check my results because the files in bsys and se have RIFF headers.
http://www.justnopoint.com/lbends/junk/bsys_007_d.wav