From bf7d3da39a2905f242cc08dd2883e433abcf4eb5 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 4 Dec 2016 14:12:23 +0100 Subject: [PATCH] Load HCA encryption keys from external file (songname.extkey or .extkey) --- src/meta/hca.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/meta/hca.c b/src/meta/hca.c index 574f8537..93232b56 100644 --- a/src/meta/hca.c +++ b/src/meta/hca.c @@ -9,9 +9,8 @@ VGMSTREAM * init_vgmstream_hca(STREAMFILE *streamFile) { } VGMSTREAM * init_vgmstream_hca_offset(STREAMFILE *streamFile, uint64_t start, uint64_t size) { - /* These I don't know about... */ - static const unsigned int ciphKey1=0x30DBE1AB; - static const unsigned int ciphKey2=0xCC554639; + unsigned int ciphKey1; + unsigned int ciphKey2; char filename[PATH_LIMIT]; @@ -51,6 +50,20 @@ VGMSTREAM * init_vgmstream_hca_offset(STREAMFILE *streamFile, uint64_t start, ui hca = (clHCA *)(hca_file + 1); + /* try to find key in external file */ + { + uint8_t keybuf[8]; + + if ( read_key_file(keybuf, 8, streamFile) ) { + ciphKey2 = get_32bitBE(keybuf+0); + ciphKey1 = get_32bitBE(keybuf+4); + } else { + /* PSO2 */ + ciphKey2=0xCC554639; + ciphKey1=0x30DBE1AB; + } + } + clHCA_clear(hca, ciphKey1, ciphKey2); if (clHCA_Decode(hca, hca_data, header_size, 0) < 0) goto fail;