Accept ADX keystring/keycode in .adxkey

This commit is contained in:
bnnm 2019-08-25 20:16:06 +02:00
parent 59c0510c5f
commit e473e7aba9
2 changed files with 38 additions and 8 deletions

View File

@ -202,8 +202,8 @@ have total samples after those.
Certain formats have encrypted data, and need a key to decrypt. vgmstream Certain formats have encrypted data, and need a key to decrypt. vgmstream
will try to find the correct key from a list, but it can be provided by will try to find the correct key from a list, but it can be provided by
a companion file: a companion file:
- .adx: .adxkey (derived 6 byte key, in start/mult/add format) - .adx: .adxkey (keystring, keycode, or derived 6 byte start/mult/add key)
- .ahx: .ahxkey (derived 6 byte key, in start/mult/add format) - .ahx: .ahxkey (derived 6 byte start/mult/add key)
- .hca: .hcakey (8 byte decryption key, a 64-bit number) - .hca: .hcakey (8 byte decryption key, a 64-bit number)
- May be followed by 2 byte AWB scramble key for newer HCA - May be followed by 2 byte AWB scramble key for newer HCA
- .fsb: .fsbkey (decryption key, in hex) - .fsb: .fsbkey (decryption key, in hex)

View File

@ -256,14 +256,44 @@ static int find_adx_key(STREAMFILE *streamFile, uint8_t type, uint16_t *xor_star
/* try to find key in external file first */ /* try to find key in external file first */
{ {
uint8_t keybuf[6]; uint8_t keybuf[0x20+1] = {0}; /* +1 extra null for keystrings */
size_t key_size;
if (read_key_file(keybuf, 6, streamFile) == 6) { /* handle type8 keystrings, key9 keycodes and derived keys too */
*xor_start = get_16bitBE(keybuf+0); key_size = read_key_file(keybuf,0x20, streamFile);
*xor_mult = get_16bitBE(keybuf+2);
*xor_add = get_16bitBE(keybuf+4); if (key_size > 0) {
return 1; int i, is_ascii = 0;
/* keystrings should be ASCII, also needed to tell apart 0x06 strings from derived keys */
if (type == 8) {
is_ascii = 1;
for (i = 0; i < key_size; i++) {
if (keybuf[i] < 0x20 || keybuf[i] > 0x7f) {
is_ascii = 0;
break;
}
}
}
if (key_size == 0x06 && !is_ascii) {
*xor_start = get_16bitBE(keybuf + 0x00);
*xor_mult = get_16bitBE(keybuf + 0x02);
*xor_add = get_16bitBE(keybuf + 0x04);
return 1;
}
else if (type == 8 && is_ascii) {
const char * keystring = (const char *)keybuf;
derive_adx_key8(keystring, xor_start, xor_mult, xor_add);
return 1;
}
else if (type == 9 && key_size == 0x08) {
uint64_t keycode = (uint64_t)get_64bitBE(keybuf);
derive_adx_key9(keycode, xor_start, xor_mult, xor_add);
return 1;
}
} }
/* no key set or unknown format, try list */
} }
/* setup totals */ /* setup totals */