summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/VolumeCreator.cpp
diff options
context:
space:
mode:
authormagumagu <magumagu9@gmail.com>2014-05-29 03:38:39 -0700
committerJosJuice <josjuice@gmail.com>2014-11-30 16:01:05 +0100
commitb1df4e598669860ede1234c07e6aa1a34970ea91 (patch)
tree430fb6ab97f5ac17247aa570dc4dfd7055bd9221 /Source/Core/DiscIO/VolumeCreator.cpp
parentd4125231f39924c7393f594288d3480e040579b4 (diff)
Make DVDLowOpenPartition actually change partitions.
Diffstat (limited to 'Source/Core/DiscIO/VolumeCreator.cpp')
-rw-r--r--Source/Core/DiscIO/VolumeCreator.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/Source/Core/DiscIO/VolumeCreator.cpp b/Source/Core/DiscIO/VolumeCreator.cpp
index 4e740554f6..24fa75909e 100644
--- a/Source/Core/DiscIO/VolumeCreator.cpp
+++ b/Source/Core/DiscIO/VolumeCreator.cpp
@@ -69,7 +69,7 @@ static const unsigned char s_master_key_korean[16] = {
0x13,0xf2,0xfe,0xfb,0xba,0x4c,0x9b,0x7e
};
-static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum, bool Korean);
+static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum);
EDiscType GetDiscType(IBlobReader& _rReader);
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup, u32 _VolumeNum)
@@ -89,10 +89,7 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionG
case DISC_TYPE_WII_CONTAINER:
{
- u8 region;
- pReader->Read(0x3,1,&region);
-
- IVolume* pVolume = CreateVolumeFromCryptedWiiImage(*pReader, _PartitionGroup, 0, _VolumeNum, region == 'K');
+ IVolume* pVolume = CreateVolumeFromCryptedWiiImage(*pReader, _PartitionGroup, 0, _VolumeNum);
if (pVolume == nullptr)
{
@@ -140,7 +137,32 @@ bool IsVolumeWadFile(const IVolume *_rVolume)
return (Common::swap32(MagicWord) == 0x00204973 || Common::swap32(MagicWord) == 0x00206962);
}
-static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum, bool Korean)
+void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
+{
+ CBlobBigEndianReader Reader(_rReader);
+
+ u8 SubKey[16];
+ _rReader.Read(offset + 0x1bf, 16, SubKey);
+
+ u8 IV[16];
+ memset(IV, 0, 16);
+ _rReader.Read(offset + 0x44c, 8, IV);
+
+ bool usingKoreanKey = false;
+ // Issue: 6813
+ // Magic value is at partition's offset + 0x1f1 (1byte)
+ // If encrypted with the Korean key, the magic value would be 1
+ // Otherwise it is zero
+ if (Reader.Read8(0x3) == 'K' && Reader.Read8(offset + 0x1f1) == 1)
+ usingKoreanKey = true;
+
+ aes_context AES_ctx;
+ aes_setkey_dec(&AES_ctx, (usingKoreanKey ? s_master_key_korean : s_master_key), 128);
+
+ aes_crypt_cbc(&AES_ctx, AES_DECRYPT, 16, IV, SubKey, VolumeKey);
+}
+
+static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum)
{
CBlobBigEndianReader Reader(_rReader);
@@ -184,32 +206,11 @@ static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _Part
{
const SPartition& rPartition = PartitionGroup[_PartitionGroup].PartitionsVec.at(i);
- if (rPartition.Type == _VolumeType || i == _VolumeNum)
+ if ((rPartition.Type == _VolumeType && (int)_VolumeNum == -1) || i == _VolumeNum)
{
- u8 SubKey[16];
- _rReader.Read(rPartition.Offset + 0x1bf, 16, SubKey);
-
- u8 IV[16];
- memset(IV, 0, 16);
- _rReader.Read(rPartition.Offset + 0x44c, 8, IV);
-
- bool usingKoreanKey = false;
- // Issue: 6813
- // Magic value is at partition's offset + 0x1f1 (1byte)
- // If encrypted with the Korean key, the magic value would be 1
- // Otherwise it is zero
- if (Korean && Reader.Read8(rPartition.Offset + 0x1f1) == 1)
- usingKoreanKey = true;
-
- aes_context AES_ctx;
- aes_setkey_dec(&AES_ctx, (usingKoreanKey ? s_master_key_korean : s_master_key), 128);
-
u8 VolumeKey[16];
- aes_crypt_cbc(&AES_ctx, AES_DECRYPT, 16, IV, SubKey, VolumeKey);
-
- // -1 means the caller just wanted the partition with matching type
- if ((int)_VolumeNum == -1 || i == _VolumeNum)
- return new CVolumeWiiCrypted(&_rReader, rPartition.Offset, VolumeKey);
+ VolumeKeyForParition(_rReader, rPartition.Offset, VolumeKey);
+ return new CVolumeWiiCrypted(&_rReader, rPartition.Offset, VolumeKey);
}
}