From a464b7624cf66bb2300c5eefe0a2fff03cc9ddd1 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 5 Apr 2020 22:36:08 +0200 Subject: [PATCH] Add some encrypted files [The Pirate's Fate (PC)] --- src/libvgmstream.vcproj | 4 ++ src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/encrypted.c | 83 ++++++++++++++++++++++++++++++++ src/meta/meta.h | 2 + src/vgmstream.c | 1 + 6 files changed, 94 insertions(+) create mode 100644 src/meta/encrypted.c diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index fb2b2030..9b1c8de5 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -667,6 +667,10 @@ + + + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index ffcad061..f75204d9 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -451,6 +451,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/encrypted.c b/src/meta/encrypted.c new file mode 100644 index 00000000..0de62161 --- /dev/null +++ b/src/meta/encrypted.c @@ -0,0 +1,83 @@ +#include "meta.h" +#include "../coding/coding.h" +#include "ogg_vorbis_streamfile.h" + +//todo fuse ogg encryptions and use generic names + + +static const uint8_t tpf_key[] = { + 0x0a,0x2b,0x36,0x6f,0x0b,0x0a,0x2b,0x36,0x6f,0x0B +}; + +static void load_key(ogg_vorbis_io_config_data* cfg, const uint8_t* key, size_t size) { + cfg->is_encrypted = 1; + cfg->key_len = size; + memcpy(cfg->key, key, size); +} + +/* parser for various encrypted games */ +VGMSTREAM* init_vgmstream_encrypted(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* temp_sf = NULL; + ogg_vorbis_io_config_data cfg = {0}; + uint32_t id; + + + /* checks */ + id = read_u32be(0x00, sf); + + if (check_extensions(sf,"ogg,logg")) { + /* The Pirate's Fate (PC) */ + if (id == 0x454C513C) { /* "OggS" xored */ + load_key(&cfg, tpf_key, sizeof(tpf_key)); + } + else { + goto fail; + } + + temp_sf = setup_ogg_vorbis_streamfile(sf, cfg); + if (!temp_sf) goto fail; + VGM_LOG("2\n"); + vgmstream = init_vgmstream_ogg_vorbis(temp_sf); + close_streamfile(temp_sf); + return vgmstream; + } + + if (check_extensions(sf,"mp3")) { + /* The Pirate's Fate (PC) */ + if ((id & 0xFFFFFF00) == 0x436F0500) { /* "ID3\0" xored */ + load_key(&cfg, tpf_key, sizeof(tpf_key)); + } + else { + goto fail; + } + + temp_sf = setup_ogg_vorbis_streamfile(sf, cfg); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_ffmpeg(temp_sf); + close_streamfile(temp_sf); + return vgmstream; + } + + if (check_extensions(sf,"wav,lwav")) { + /* The Pirate's Fate (PC) */ + if (id == 0x58627029) { /* "RIFF" xored */ + load_key(&cfg, tpf_key, sizeof(tpf_key)); + } + else { + goto fail; + } + + temp_sf = setup_ogg_vorbis_streamfile(sf, cfg); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_riff(temp_sf); + close_streamfile(temp_sf); + return vgmstream; + } + + +fail: + return NULL; +} diff --git a/src/meta/meta.h b/src/meta/meta.h index 2b4e9f78..2a88778d 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -891,4 +891,6 @@ VGMSTREAM * init_vgmstream_lrmd(STREAMFILE* sf); VGMSTREAM* init_vgmstream_bkhd(STREAMFILE* sf); VGMSTREAM* init_vgmstream_bkhd_fx(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_encrypted(STREAMFILE* sf); + #endif /*_META_H*/ diff --git a/src/vgmstream.c b/src/vgmstream.c index 326a6bae..455ea347 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -495,6 +495,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */ + init_vgmstream_encrypted, /* encrypted stuff */ init_vgmstream_raw_int, /* .int raw PCM */ init_vgmstream_ps_headerless, /* tries to detect a bunch of PS-ADPCM formats */ init_vgmstream_raw_snds, /* .snds raw SNDS IMA (*after* ps_headerless) */