mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-18 15:54:05 +01:00
Add encrypted .scd [Final Fantasy XI (X360)]
This commit is contained in:
parent
b5be2e81eb
commit
bae8e1b06e
@ -139,6 +139,7 @@
|
||||
<ClInclude Include="meta\riff_ogg_streamfile.h" />
|
||||
<ClInclude Include="meta\sfh_streamfile.h" />
|
||||
<ClInclude Include="meta\sqex_streamfile.h" />
|
||||
<ClInclude Include="meta\sscf_encrypted.h" />
|
||||
<ClInclude Include="meta\txth_streamfile.h" />
|
||||
<ClInclude Include="meta\ubi_bao_streamfile.h" />
|
||||
<ClInclude Include="meta\ubi_sb_streamfile.h" />
|
||||
@ -269,6 +270,7 @@
|
||||
<ClCompile Include="meta\sqex_scd.c" />
|
||||
<ClCompile Include="meta\sqex_scd_sscf.c" />
|
||||
<ClCompile Include="meta\sqex_sead.c" />
|
||||
<ClCompile Include="meta\sscf_encrypted.c" />
|
||||
<ClCompile Include="meta\sspr.c" />
|
||||
<ClCompile Include="meta\sthd.c" />
|
||||
<ClCompile Include="meta\alp.c" />
|
||||
|
@ -176,6 +176,9 @@
|
||||
<ClInclude Include="meta\sqex_streamfile.h">
|
||||
<Filter>meta\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="meta\sscf_encrypted.h">
|
||||
<Filter>meta\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="meta\txth_streamfile.h">
|
||||
<Filter>meta\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -1702,6 +1705,9 @@
|
||||
<ClCompile Include="meta\sqex_sead.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="meta\sscf_encrypted.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="meta\sspr.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -993,4 +993,6 @@ VGMSTREAM* init_vgmstream_vab(STREAMFILE* sf);
|
||||
|
||||
VGMSTREAM* init_vgmstream_bigrp(STREAMFILE* sf);
|
||||
|
||||
VGMSTREAM* init_vgmstream_sscf_encrypted(STREAMFILE* sf);
|
||||
|
||||
#endif /*_META_H*/
|
||||
|
@ -112,62 +112,3 @@ fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* SSCF X360 - updated SCD with encrypted data [Final Fantasy XI (360), PlayOnline Viewer (X360)] */
|
||||
VGMSTREAM * init_vgmstream_scd_sscf_x360(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset, meta_offset, stream_offset;
|
||||
size_t stream_size;
|
||||
int loop_flag, channel_count, sample_rate;
|
||||
int total_subsongs, target_subsong = streamFile->stream_index;
|
||||
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "scd"))
|
||||
goto fail;
|
||||
|
||||
if (read_32bitBE(0x00,streamFile) != 0x53534346) /* "SSCF" "*/
|
||||
goto fail;
|
||||
if (read_32bitBE(0x04,streamFile) != 0x20050300)/* version? */
|
||||
goto fail;
|
||||
/* 0x08: file size, except for a few files that with a weird value */
|
||||
/* 0x0c: null */
|
||||
/* 0x10: file id? */
|
||||
/* 0x14: encryption key (different files with the same value encrypt the same) */
|
||||
|
||||
/* 0x1c: entry count */
|
||||
|
||||
/* ~0x20: entries start? */
|
||||
/* 0x40: num samples? */
|
||||
/* 0x44: loop start? */
|
||||
/* 0x50: channels */
|
||||
/* 0x54: sample rate */
|
||||
|
||||
/* 0x80: encrypted RIFF data */
|
||||
|
||||
|
||||
loop_flag = 0;
|
||||
channel_count = 1;
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->sample_rate = sample_rate;
|
||||
vgmstream->num_samples = ...;
|
||||
|
||||
vgmstream->meta_type = meta_SCD_SSCF;
|
||||
vgmstream->coding_type = coding_...;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
49
src/meta/sscf_encrypted.c
Normal file
49
src/meta/sscf_encrypted.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include "meta.h"
|
||||
#include "sscf_encrypted.h"
|
||||
|
||||
/* SSCF - Square-Enix games, older version of .scd with encrypted data [Final Fantasy XI (360), PlayOnline Viewer (X360)] */
|
||||
VGMSTREAM* init_vgmstream_sscf_encrypted(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
STREAMFILE* temp_sf = NULL;
|
||||
uint32_t xorkey;
|
||||
|
||||
|
||||
/* checks */
|
||||
if (!is_id32be(0x00,sf, "SSCF"))
|
||||
goto fail;
|
||||
if (!check_extensions(sf, "scd"))
|
||||
goto fail;
|
||||
|
||||
/* LE header even though X360 */
|
||||
/* 0x04: version? (0x0003xxxx)*/
|
||||
/* 0x08: file size, except for a few files that with a weird value */
|
||||
/* 0x0c: null */
|
||||
|
||||
/* 0x10: file id */
|
||||
xorkey = read_u32le(0x14,sf);
|
||||
/* 0x18: null */
|
||||
/* 0x1c: always 1 */
|
||||
/* 0x20~0x40: null */
|
||||
|
||||
/* 0x40: num samples? */
|
||||
/* 0x48: loop start? */
|
||||
/* 0x50: channels */
|
||||
/* 0x54: sample rate */
|
||||
/* rest: null */
|
||||
|
||||
/* 0x80: encrypted RIFF data */
|
||||
|
||||
temp_sf = setup_sscf_streamfile(sf, xorkey);
|
||||
if (!temp_sf) goto fail;
|
||||
|
||||
vgmstream = init_vgmstream_xma(temp_sf);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
close_streamfile(temp_sf);
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_streamfile(temp_sf);
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
46
src/meta/sscf_encrypted.h
Normal file
46
src/meta/sscf_encrypted.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef _SQEX_SCD_SSCF_ENCRYPTED_H_
|
||||
#define _SQEX_SCD_SSCF_ENCRYPTED_H_
|
||||
#include "../streamfile.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t key[0x800];
|
||||
} sscf_io;
|
||||
|
||||
|
||||
static size_t sscf_io_read(STREAMFILE* sf, uint8_t* dest, off_t offset, size_t length, sscf_io* io) {
|
||||
int i;
|
||||
size_t bytes = read_streamfile(dest, offset, length, sf);
|
||||
|
||||
for (i = 0; i < bytes; i++) {
|
||||
dest[i] ^= io->key[(offset + i) % sizeof(io->key)];
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/* Decrypts SSCF streams */
|
||||
static STREAMFILE* setup_sscf_streamfile(STREAMFILE* sf, uint32_t xorkey) {
|
||||
STREAMFILE *new_sf = NULL;
|
||||
sscf_io io = {0};
|
||||
int i;
|
||||
uint32_t stream_offset = 0x80;
|
||||
uint32_t stream_size = get_streamfile_size(sf) - stream_offset;
|
||||
|
||||
/* setup key */
|
||||
xorkey = (xorkey >> 21) | (xorkey << 11);
|
||||
for (i = 0; i < sizeof(io.key); i += 4) {
|
||||
put_u32le(io.key + i, xorkey);
|
||||
xorkey += (xorkey >> 29) | (xorkey << 3);
|
||||
}
|
||||
|
||||
new_sf = open_wrap_streamfile(sf);
|
||||
new_sf = open_io_streamfile_f(new_sf, &io, sizeof(sscf_io), sscf_io_read, NULL);
|
||||
if (new_sf) {
|
||||
stream_size = read_u32le(0x84, new_sf) + 0x08; /* RIFF size */
|
||||
}
|
||||
new_sf = open_clamp_streamfile_f(new_sf, stream_offset, stream_size);
|
||||
new_sf = open_fakename_streamfile_f(new_sf, NULL, "xma");
|
||||
return new_sf;
|
||||
}
|
||||
|
||||
#endif
|
@ -525,6 +525,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
|
||||
init_vgmstream_sndz,
|
||||
init_vgmstream_vab,
|
||||
init_vgmstream_bigrp,
|
||||
init_vgmstream_sscf_encrypted,
|
||||
|
||||
/* lower priority metas (no clean header identity, somewhat ambiguous, or need extension/companion file to identify) */
|
||||
init_vgmstream_scd_pcm,
|
||||
|
Loading…
x
Reference in New Issue
Block a user