mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-19 02:36:27 +01:00
Merge pull request #2932 from lioncash/disc
VolumeCreator: Use a unique_ptr in CreateVolumeFromFilename
This commit is contained in:
commit
0ba7a65f08
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <polarssl/aes.h>
|
#include <polarssl/aes.h>
|
||||||
@ -69,35 +71,26 @@ static const unsigned char s_master_key_korean[16] = {
|
|||||||
0x13,0xf2,0xfe,0xfb,0xba,0x4c,0x9b,0x7e
|
0x13,0xf2,0xfe,0xfb,0xba,0x4c,0x9b,0x7e
|
||||||
};
|
};
|
||||||
|
|
||||||
static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum);
|
static IVolume* CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum);
|
||||||
EDiscType GetDiscType(IBlobReader& _rReader);
|
EDiscType GetDiscType(IBlobReader& _rReader);
|
||||||
|
|
||||||
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup, u32 _VolumeNum)
|
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup, u32 _VolumeNum)
|
||||||
{
|
{
|
||||||
IBlobReader* pReader = CreateBlobReader(_rFilename);
|
std::unique_ptr<IBlobReader> reader(CreateBlobReader(_rFilename));
|
||||||
if (pReader == nullptr)
|
if (reader == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
switch (GetDiscType(*pReader))
|
switch (GetDiscType(*reader))
|
||||||
{
|
{
|
||||||
case DISC_TYPE_WII:
|
case DISC_TYPE_WII:
|
||||||
case DISC_TYPE_GC:
|
case DISC_TYPE_GC:
|
||||||
return new CVolumeGC(pReader);
|
return new CVolumeGC(std::move(reader));
|
||||||
|
|
||||||
case DISC_TYPE_WAD:
|
case DISC_TYPE_WAD:
|
||||||
return new CVolumeWAD(pReader);
|
return new CVolumeWAD(std::move(reader));
|
||||||
|
|
||||||
case DISC_TYPE_WII_CONTAINER:
|
case DISC_TYPE_WII_CONTAINER:
|
||||||
{
|
return CreateVolumeFromCryptedWiiImage(std::move(reader), _PartitionGroup, 0, _VolumeNum);
|
||||||
IVolume* pVolume = CreateVolumeFromCryptedWiiImage(*pReader, _PartitionGroup, 0, _VolumeNum);
|
|
||||||
|
|
||||||
if (pVolume == nullptr)
|
|
||||||
{
|
|
||||||
delete pReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
case DISC_TYPE_UNK:
|
case DISC_TYPE_UNK:
|
||||||
default:
|
default:
|
||||||
@ -106,7 +99,6 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionG
|
|||||||
Filename += ext;
|
Filename += ext;
|
||||||
NOTICE_LOG(DISCIO, "%s does not have the Magic word for a gcm, wiidisc or wad file\n"
|
NOTICE_LOG(DISCIO, "%s does not have the Magic word for a gcm, wiidisc or wad file\n"
|
||||||
"Set Log Verbosity to Warning and attempt to load the game again to view the values", Filename.c_str());
|
"Set Log Verbosity to Warning and attempt to load the game again to view the values", Filename.c_str());
|
||||||
delete pReader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -128,7 +120,7 @@ bool IsVolumeWadFile(const IVolume *_rVolume)
|
|||||||
return (Common::swap32(MagicWord) == 0x00204973 || Common::swap32(MagicWord) == 0x00206962);
|
return (Common::swap32(MagicWord) == 0x00204973 || Common::swap32(MagicWord) == 0x00206962);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
|
void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
|
||||||
{
|
{
|
||||||
CBlobBigEndianReader Reader(_rReader);
|
CBlobBigEndianReader Reader(_rReader);
|
||||||
|
|
||||||
@ -153,12 +145,12 @@ void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
|
|||||||
aes_crypt_cbc(&AES_ctx, AES_DECRYPT, 16, IV, SubKey, VolumeKey);
|
aes_crypt_cbc(&AES_ctx, AES_DECRYPT, 16, IV, SubKey, VolumeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum)
|
static IVolume* CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum)
|
||||||
{
|
{
|
||||||
CBlobBigEndianReader Reader(_rReader);
|
CBlobBigEndianReader big_endian_reader(*reader);
|
||||||
|
|
||||||
u32 numPartitions = Reader.Read32(0x40000 + (_PartitionGroup * 8));
|
u32 numPartitions = big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8));
|
||||||
u64 PartitionsOffset = (u64)Reader.Read32(0x40000 + (_PartitionGroup * 8) + 4) << 2;
|
u64 PartitionsOffset = (u64)big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8) + 4) << 2;
|
||||||
|
|
||||||
// Check if we're looking for a valid partition
|
// Check if we're looking for a valid partition
|
||||||
if ((int)_VolumeNum != -1 && _VolumeNum > numPartitions)
|
if ((int)_VolumeNum != -1 && _VolumeNum > numPartitions)
|
||||||
@ -184,8 +176,8 @@ static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _Part
|
|||||||
for (u32 i = 0; i < numPartitions; i++)
|
for (u32 i = 0; i < numPartitions; i++)
|
||||||
{
|
{
|
||||||
SPartition Partition;
|
SPartition Partition;
|
||||||
Partition.Offset = ((u64)Reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
|
Partition.Offset = ((u64)big_endian_reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
|
||||||
Partition.Type = Reader.Read32(PartitionsOffset + (i * 8) + 4);
|
Partition.Type = big_endian_reader.Read32(PartitionsOffset + (i * 8) + 4);
|
||||||
group.PartitionsVec.push_back(Partition);
|
group.PartitionsVec.push_back(Partition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,8 +192,8 @@ static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _Part
|
|||||||
if ((rPartition.Type == _VolumeType && (int)_VolumeNum == -1) || i == _VolumeNum)
|
if ((rPartition.Type == _VolumeType && (int)_VolumeNum == -1) || i == _VolumeNum)
|
||||||
{
|
{
|
||||||
u8 VolumeKey[16];
|
u8 VolumeKey[16];
|
||||||
VolumeKeyForParition(_rReader, rPartition.Offset, VolumeKey);
|
VolumeKeyForPartition(*reader, rPartition.Offset, VolumeKey);
|
||||||
return new CVolumeWiiCrypted(&_rReader, rPartition.Offset, VolumeKey);
|
return new CVolumeWiiCrypted(std::move(reader), rPartition.Offset, VolumeKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,6 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionG
|
|||||||
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii, const std::string& _rApploader = "", const std::string& _rDOL = "");
|
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii, const std::string& _rApploader = "", const std::string& _rDOL = "");
|
||||||
bool IsVolumeWiiDisc(const IVolume *_rVolume);
|
bool IsVolumeWiiDisc(const IVolume *_rVolume);
|
||||||
bool IsVolumeWadFile(const IVolume *_rVolume);
|
bool IsVolumeWadFile(const IVolume *_rVolume);
|
||||||
void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey);
|
void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/ColorUtil.h"
|
#include "Common/ColorUtil.h"
|
||||||
@ -20,8 +21,8 @@
|
|||||||
|
|
||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
CVolumeGC::CVolumeGC(IBlobReader* _pReader)
|
CVolumeGC::CVolumeGC(std::unique_ptr<IBlobReader> reader)
|
||||||
: m_pReader(_pReader)
|
: m_pReader(std::move(reader))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CVolumeGC::~CVolumeGC()
|
CVolumeGC::~CVolumeGC()
|
||||||
|
@ -22,7 +22,7 @@ class IBlobReader;
|
|||||||
class CVolumeGC : public IVolume
|
class CVolumeGC : public IVolume
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CVolumeGC(IBlobReader* _pReader);
|
CVolumeGC(std::unique_ptr<IBlobReader> reader);
|
||||||
~CVolumeGC();
|
~CVolumeGC();
|
||||||
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override;
|
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override;
|
||||||
std::string GetUniqueID() const override;
|
std::string GetUniqueID() const override;
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
@ -18,8 +20,8 @@
|
|||||||
|
|
||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
CVolumeWAD::CVolumeWAD(IBlobReader* _pReader)
|
CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader)
|
||||||
: m_pReader(_pReader), m_offset(0), m_tmd_offset(0), m_opening_bnr_offset(0),
|
: m_pReader(std::move(reader)), m_offset(0), m_tmd_offset(0), m_opening_bnr_offset(0),
|
||||||
m_hdr_size(0), m_cert_size(0), m_tick_size(0), m_tmd_size(0), m_data_size(0)
|
m_hdr_size(0), m_cert_size(0), m_tick_size(0), m_tmd_size(0), m_data_size(0)
|
||||||
{
|
{
|
||||||
// Source: http://wiibrew.org/wiki/WAD_files
|
// Source: http://wiibrew.org/wiki/WAD_files
|
||||||
|
@ -24,7 +24,7 @@ class IBlobReader;
|
|||||||
class CVolumeWAD : public IVolume
|
class CVolumeWAD : public IVolume
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CVolumeWAD(IBlobReader* _pReader);
|
CVolumeWAD(std::unique_ptr<IBlobReader> reader);
|
||||||
~CVolumeWAD();
|
~CVolumeWAD();
|
||||||
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override;
|
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override;
|
||||||
bool GetTitleID(u8* _pBuffer) const override;
|
bool GetTitleID(u8* _pBuffer) const override;
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <polarssl/aes.h>
|
#include <polarssl/aes.h>
|
||||||
#include <polarssl/sha1.h>
|
#include <polarssl/sha1.h>
|
||||||
@ -25,9 +27,9 @@
|
|||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
|
|
||||||
CVolumeWiiCrypted::CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset,
|
CVolumeWiiCrypted::CVolumeWiiCrypted(std::unique_ptr<IBlobReader> reader, u64 _VolumeOffset,
|
||||||
const unsigned char* _pVolumeKey)
|
const unsigned char* _pVolumeKey)
|
||||||
: m_pReader(_pReader),
|
: m_pReader(std::move(reader)),
|
||||||
m_AES_ctx(new aes_context),
|
m_AES_ctx(new aes_context),
|
||||||
m_pBuffer(nullptr),
|
m_pBuffer(nullptr),
|
||||||
m_VolumeOffset(_VolumeOffset),
|
m_VolumeOffset(_VolumeOffset),
|
||||||
@ -44,7 +46,7 @@ bool CVolumeWiiCrypted::ChangePartition(u64 offset)
|
|||||||
m_LastDecryptedBlockOffset = -1;
|
m_LastDecryptedBlockOffset = -1;
|
||||||
|
|
||||||
u8 volume_key[16];
|
u8 volume_key[16];
|
||||||
DiscIO::VolumeKeyForParition(*m_pReader, offset, volume_key);
|
DiscIO::VolumeKeyForPartition(*m_pReader, offset, volume_key);
|
||||||
aes_setkey_dec(m_AES_ctx.get(), volume_key, 128);
|
aes_setkey_dec(m_AES_ctx.get(), volume_key, 128);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class IBlobReader;
|
|||||||
class CVolumeWiiCrypted : public IVolume
|
class CVolumeWiiCrypted : public IVolume
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset, const unsigned char* _pVolumeKey);
|
CVolumeWiiCrypted(std::unique_ptr<IBlobReader> reader, u64 _VolumeOffset, const unsigned char* _pVolumeKey);
|
||||||
~CVolumeWiiCrypted();
|
~CVolumeWiiCrypted();
|
||||||
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override;
|
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override;
|
||||||
bool GetTitleID(u8* _pBuffer) const override;
|
bool GetTitleID(u8* _pBuffer) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user