enhanced bmdx decryption (determine key from initial frame, which ought to be all zeroes)

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@559 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2009-01-10 00:07:12 +00:00
parent 6b31139644
commit fd6ca93047
3 changed files with 17 additions and 5 deletions

View File

@ -55,7 +55,6 @@ void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
stream->adpcm_history2_32=hist2;
}
/* first byte is XOR 0xFF, third byte is -2 (so add 2) */
void decode_invert_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int predict_nr, shift_factor, sample;
@ -68,9 +67,7 @@ void decode_invert_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelsp
uint8_t flag;
int framesin = first_sample/28;
//int head = 0xff - read_8bit(stream->offset+framesin*16,stream->streamfile);
int head = 0xff ^ read_8bit(stream->offset+framesin*16,stream->streamfile);
//int head = read_8bit(stream->offset+framesin*16,stream->streamfile);
int head = read_8bit(stream->offset+framesin*16,stream->streamfile) ^ stream->bmdx_xor;
predict_nr = ((head >> 4) & 0xf);
shift_factor = (head & 0xf);
@ -86,7 +83,7 @@ void decode_invert_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelsp
short sample_byte = (short)read_8bit(stream->offset+(framesin*16)+2+i/2,stream->streamfile);
if (i/2 == 0)
sample_byte = (short)(int8_t)(sample_byte+2);
sample_byte = (short)(int8_t)(sample_byte+stream->bmdx_add);
scale = ((i&1 ?
sample_byte >> 4 :

View File

@ -50,6 +50,17 @@ VGMSTREAM * init_vgmstream_ps2_bmdx(STREAMFILE *streamFile) {
start_offset = read_32bitLE(0x08,streamFile);
if (vgmstream->coding_type == coding_invert_PSX)
{
uint8_t xor = read_8bit(start_offset,streamFile);
uint8_t add = (~(uint8_t)read_8bit(start_offset+2,streamFile))+1;
int c;
for (c=0;c<channel_count;c++) {
vgmstream->ch[c].bmdx_xor = xor;
vgmstream->ch[c].bmdx_add = add;
}
}
/* open the file for reading by each channel */
{
for (i=0;i<channel_count;i++) {

View File

@ -407,6 +407,10 @@ typedef struct {
uint16_t adx_xor;
uint16_t adx_mult;
uint16_t adx_add;
/* BMDX encryption */
uint8_t bmdx_xor;
uint8_t bmdx_add;
} VGMSTREAMCHANNEL;
typedef struct {