diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index fa297d70e6..142bf56208 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -39,7 +39,7 @@ void CBoot::Load_FST(bool _bIsWii) return; // copy first 20 bytes of disc to start of Mem 1 - VolumeHandler::ReadToPtr(Memory::GetPointer(0x80000000), 0, 0x20); + VolumeHandler::ReadToPtr(Memory::GetPointer(0x80000000), 0, 0x20, false); // copy of game id Memory::Write_U32(Memory::Read_U32(0x80000000), 0x80003180); @@ -48,15 +48,15 @@ void CBoot::Load_FST(bool _bIsWii) if (_bIsWii) shift = 2; - u32 fstOffset = VolumeHandler::Read32(0x0424) << shift; - u32 fstSize = VolumeHandler::Read32(0x0428) << shift; - u32 maxFstSize = VolumeHandler::Read32(0x042c) << shift; + u32 fstOffset = VolumeHandler::Read32(0x0424, _bIsWii) << shift; + u32 fstSize = VolumeHandler::Read32(0x0428, _bIsWii) << shift; + u32 maxFstSize = VolumeHandler::Read32(0x042c, _bIsWii) << shift; u32 arenaHigh = ROUND_DOWN(0x817FFFFF - maxFstSize, 0x20); Memory::Write_U32(arenaHigh, 0x00000034); // load FST - VolumeHandler::ReadToPtr(Memory::GetPointer(arenaHigh), fstOffset, fstSize); + VolumeHandler::ReadToPtr(Memory::GetPointer(arenaHigh), fstOffset, fstSize, _bIsWii); Memory::Write_U32(arenaHigh, 0x00000038); Memory::Write_U32(maxFstSize, 0x0000003c); } diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 49915e41c1..c6ee46af1d 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -56,7 +56,7 @@ bool CBoot::EmulatedBS2_GC() // Write necessary values // Here we write values to memory that the apploader does not take care of. Game info goes // to 0x80000000 according to YAGCD 4.2. - DVDInterface::DVDRead(0x00000000, 0x80000000, 0x20); // write disc info + DVDInterface::DVDRead(0x00000000, 0x80000000, 0x20, false); // write disc info Memory::Write_U32(0x0D15EA5E, 0x80000020); // Booted from bootrom. 0xE5207C22 = booted from jtag Memory::Write_U32(Memory::REALRAM_SIZE, 0x80000028); // Physical Memory Size (24MB on retail) @@ -84,14 +84,14 @@ bool CBoot::EmulatedBS2_GC() // Load Apploader to Memory - The apploader is hardcoded to begin at 0x2440 on the disc, // but the size can differ between discs. Compare with YAGCD chap 13. u32 iAppLoaderOffset = 0x2440; - u32 iAppLoaderEntry = VolumeHandler::Read32(iAppLoaderOffset + 0x10); - u32 iAppLoaderSize = VolumeHandler::Read32(iAppLoaderOffset + 0x14) + VolumeHandler::Read32(iAppLoaderOffset + 0x18); + u32 iAppLoaderEntry = VolumeHandler::Read32(iAppLoaderOffset + 0x10, false); + u32 iAppLoaderSize = VolumeHandler::Read32(iAppLoaderOffset + 0x14, false) + VolumeHandler::Read32(iAppLoaderOffset + 0x18, false); if ((iAppLoaderEntry == (u32)-1) || (iAppLoaderSize == (u32)-1)) { INFO_LOG(BOOT, "GC BS2: Not running apploader!"); return false; } - VolumeHandler::ReadToPtr(Memory::GetPointer(0x81200000), iAppLoaderOffset + 0x20, iAppLoaderSize); + VolumeHandler::ReadToPtr(Memory::GetPointer(0x81200000), iAppLoaderOffset + 0x20, iAppLoaderSize, false); // Setup pointers like real BS2 does if (SConfig::GetInstance().m_LocalCoreStartupParameter.bNTSC) @@ -142,7 +142,7 @@ bool CBoot::EmulatedBS2_GC() u32 iDVDOffset = Memory::ReadUnchecked_U32(0x8130000c); INFO_LOG(MASTER_LOG, "DVDRead: offset: %08x memOffset: %08x length: %i", iDVDOffset, iRamAddress, iLength); - DVDInterface::DVDRead(iDVDOffset, iRamAddress, iLength); + DVDInterface::DVDRead(iDVDOffset, iRamAddress, iLength, false); } while (PowerPC::ppcState.gpr[3] != 0x00); @@ -241,50 +241,50 @@ bool CBoot::SetupWiiMemory(IVolume::ECountry country) 0x80000060 Copyright code */ - DVDInterface::DVDRead(0x00000000, 0x00000000, 0x20); // Game Code - Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word - Memory::Write_U32(0x00000001, 0x00000024); // Unknown - Memory::Write_U32(Memory::REALRAM_SIZE, 0x00000028); // MEM1 size 24MB - Memory::Write_U32(0x00000023, 0x0000002c); // Production Board Model - Memory::Write_U32(0x00000000, 0x00000030); // Init - Memory::Write_U32(0x817FEC60, 0x00000034); // Init + DVDInterface::DVDRead(0x00000000, 0x00000000, 0x20, false); // Game Code + Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word + Memory::Write_U32(0x00000001, 0x00000024); // Unknown + Memory::Write_U32(Memory::REALRAM_SIZE, 0x00000028); // MEM1 size 24MB + Memory::Write_U32(0x00000023, 0x0000002c); // Production Board Model + Memory::Write_U32(0x00000000, 0x00000030); // Init + Memory::Write_U32(0x817FEC60, 0x00000034); // Init // 38, 3C should get start, size of FST through apploader - Memory::Write_U32(0x38a00040, 0x00000060); // Exception init - Memory::Write_U32(0x8008f7b8, 0x000000e4); // Thread Init - Memory::Write_U32(Memory::REALRAM_SIZE, 0x000000f0); // "Simulated memory size" (debug mode?) - Memory::Write_U32(0x8179b500, 0x000000f4); // __start - Memory::Write_U32(0x0e7be2c0, 0x000000f8); // Bus speed - Memory::Write_U32(0x2B73A840, 0x000000fc); // CPU speed - Memory::Write_U16(0x0000, 0x000030e6); // Console type - Memory::Write_U32(0x00000000, 0x000030c0); // EXI - Memory::Write_U32(0x00000000, 0x000030c4); // EXI - Memory::Write_U32(0x00000000, 0x000030dc); // Time - Memory::Write_U32(0x00000000, 0x000030d8); // Time - Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable - Memory::Write_U32(0x00000000, 0x000030f0); // Apploader - Memory::Write_U32(0x01800000, 0x00003100); // BAT - Memory::Write_U32(0x01800000, 0x00003104); // BAT - Memory::Write_U32(0x00000000, 0x0000310c); // Init - Memory::Write_U32(0x8179d500, 0x00003110); // Init - Memory::Write_U32(0x04000000, 0x00003118); // Unknown - Memory::Write_U32(0x04000000, 0x0000311c); // BAT - Memory::Write_U32(0x93400000, 0x00003120); // BAT - Memory::Write_U32(0x90000800, 0x00003124); // Init - MEM2 low - Memory::Write_U32(0x93ae0000, 0x00003128); // Init - MEM2 high - Memory::Write_U32(0x93ae0000, 0x00003130); // IOS MEM2 low - Memory::Write_U32(0x93b00000, 0x00003134); // IOS MEM2 high - Memory::Write_U32(0x00000012, 0x00003138); // Console type + Memory::Write_U32(0x38a00040, 0x00000060); // Exception init + Memory::Write_U32(0x8008f7b8, 0x000000e4); // Thread Init + Memory::Write_U32(Memory::REALRAM_SIZE, 0x000000f0); // "Simulated memory size" (debug mode?) + Memory::Write_U32(0x8179b500, 0x000000f4); // __start + Memory::Write_U32(0x0e7be2c0, 0x000000f8); // Bus speed + Memory::Write_U32(0x2B73A840, 0x000000fc); // CPU speed + Memory::Write_U16(0x0000, 0x000030e6); // Console type + Memory::Write_U32(0x00000000, 0x000030c0); // EXI + Memory::Write_U32(0x00000000, 0x000030c4); // EXI + Memory::Write_U32(0x00000000, 0x000030dc); // Time + Memory::Write_U32(0x00000000, 0x000030d8); // Time + Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable + Memory::Write_U32(0x00000000, 0x000030f0); // Apploader + Memory::Write_U32(0x01800000, 0x00003100); // BAT + Memory::Write_U32(0x01800000, 0x00003104); // BAT + Memory::Write_U32(0x00000000, 0x0000310c); // Init + Memory::Write_U32(0x8179d500, 0x00003110); // Init + Memory::Write_U32(0x04000000, 0x00003118); // Unknown + Memory::Write_U32(0x04000000, 0x0000311c); // BAT + Memory::Write_U32(0x93400000, 0x00003120); // BAT + Memory::Write_U32(0x90000800, 0x00003124); // Init - MEM2 low + Memory::Write_U32(0x93ae0000, 0x00003128); // Init - MEM2 high + Memory::Write_U32(0x93ae0000, 0x00003130); // IOS MEM2 low + Memory::Write_U32(0x93b00000, 0x00003134); // IOS MEM2 high + Memory::Write_U32(0x00000012, 0x00003138); // Console type // 40 is copied from 88 after running apploader - Memory::Write_U32(0x00090204, 0x00003140); // IOS revision (IOS9, v2.4) - Memory::Write_U32(0x00062507, 0x00003144); // IOS date in USA format (June 25, 2007) - Memory::Write_U16(0x0113, 0x0000315e); // Apploader - Memory::Write_U32(0x0000FF16, 0x00003158); // DDR ram vendor code - Memory::Write_U32(0x00000000, 0x00003160); // Init semaphore (sysmenu waits for this to clear) - Memory::Write_U32(0x00090204, 0x00003188); // Expected IOS revision + Memory::Write_U32(0x00090204, 0x00003140); // IOS revision (IOS9, v2.4) + Memory::Write_U32(0x00062507, 0x00003144); // IOS date in USA format (June 25, 2007) + Memory::Write_U16(0x0113, 0x0000315e); // Apploader + Memory::Write_U32(0x0000FF16, 0x00003158); // DDR ram vendor code + Memory::Write_U32(0x00000000, 0x00003160); // Init semaphore (sysmenu waits for this to clear) + Memory::Write_U32(0x00090204, 0x00003188); // Expected IOS revision - Memory::Write_U8(0x80, 0x0000315c); // OSInit - Memory::Write_U16(0x0000, 0x000030e0); // PADInit - Memory::Write_U32(0x80000000, 0x00003184); // GameID Address + Memory::Write_U8(0x80, 0x0000315c); // OSInit + Memory::Write_U16(0x0000, 0x000030e0); // PADInit + Memory::Write_U32(0x80000000, 0x00003184); // GameID Address // Fake the VI Init of the IPL Memory::Write_U32(SConfig::GetInstance().m_LocalCoreStartupParameter.bNTSC ? 0 : 1, 0x000000CC); @@ -316,7 +316,7 @@ bool CBoot::EmulatedBS2_Wii() // values as the game boots. This location keep the 4 byte ID for as long // as the game is running. The 6 byte ID at 0x00 is overwritten sometime // after this check during booting. - VolumeHandler::ReadToPtr(Memory::GetPointer(0x3180), 0, 4); + VolumeHandler::ReadToPtr(Memory::GetPointer(0x3180), 0, 4, true); // Execute the apploader bool apploaderRan = false; @@ -349,14 +349,14 @@ bool CBoot::EmulatedBS2_Wii() u32 iAppLoaderOffset = 0x2440; // 0x1c40; // Load Apploader to Memory - u32 iAppLoaderEntry = VolumeHandler::Read32(iAppLoaderOffset + 0x10); - u32 iAppLoaderSize = VolumeHandler::Read32(iAppLoaderOffset + 0x14); + u32 iAppLoaderEntry = VolumeHandler::Read32(iAppLoaderOffset + 0x10, true); + u32 iAppLoaderSize = VolumeHandler::Read32(iAppLoaderOffset + 0x14, true); if ((iAppLoaderEntry == (u32)-1) || (iAppLoaderSize == (u32)-1)) { ERROR_LOG(BOOT, "Invalid apploader. Probably your image is corrupted."); return false; } - VolumeHandler::ReadToPtr(Memory::GetPointer(0x81200000), iAppLoaderOffset + 0x20, iAppLoaderSize); + VolumeHandler::ReadToPtr(Memory::GetPointer(0x81200000), iAppLoaderOffset + 0x20, iAppLoaderSize, true); //call iAppLoaderEntry DEBUG_LOG(BOOT, "Call iAppLoaderEntry"); @@ -394,7 +394,7 @@ bool CBoot::EmulatedBS2_Wii() u32 iDVDOffset = Memory::ReadUnchecked_U32(0x8130000c) << 2; INFO_LOG(BOOT, "DVDRead: offset: %08x memOffset: %08x length: %i", iDVDOffset, iRamAddress, iLength); - DVDInterface::DVDRead(iDVDOffset, iRamAddress, iLength); + DVDInterface::DVDRead(iDVDOffset, iRamAddress, iLength, true); } while (PowerPC::ppcState.gpr[3] != 0x00); // iAppLoaderClose diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp index be88dd2f0a..dc064f1093 100644 --- a/Source/Core/Core/HW/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVDInterface.cpp @@ -258,7 +258,7 @@ void GenerateDIInterrupt(DIInterruptType _DVDInterrupt); void WriteImmediate(u32 value, u32 output_address, bool write_to_DIIMMBUF); DVDCommandResult ExecuteReadCommand(u64 DVD_offset, u32 output_address, - u32 DVD_length, u32 output_length, bool raw = false); + u32 DVD_length, u32 output_length, bool decrypt); u64 SimulateDiscReadTime(u64 offset, u32 length); s64 CalculateRawDiscReadTime(u64 offset, s64 length); @@ -328,7 +328,7 @@ static u32 ProcessDTKSamples(short *tempPCM, u32 num_samples) u8 tempADPCM[NGCADPCM::ONE_BLOCK_SIZE]; // TODO: What if we can't read from AudioPos? - VolumeHandler::ReadToPtr(tempADPCM, AudioPos, sizeof(tempADPCM)); + VolumeHandler::ReadToPtr(tempADPCM, AudioPos, sizeof(tempADPCM), false); AudioPos += sizeof(tempADPCM); NGCADPCM::DecodeBlock(tempPCM + samples_processed * 2, tempADPCM); samples_processed += NGCADPCM::SAMPLES_PER_BLOCK; @@ -467,12 +467,9 @@ void SetLidOpen(bool _bOpen) GenerateDIInterrupt(INT_CVRINT); } -bool DVDRead(u64 _iDVDOffset, u32 _iRamAddress, u32 _iLength, bool raw) +bool DVDRead(u64 _iDVDOffset, u32 _iRamAddress, u32 _iLength, bool decrypt) { - if (raw) - return VolumeHandler::RAWReadToPtr(Memory::GetPointer(_iRamAddress), _iDVDOffset, _iLength); - else - return VolumeHandler::ReadToPtr(Memory::GetPointer(_iRamAddress), _iDVDOffset, _iLength); + return VolumeHandler::ReadToPtr(Memory::GetPointer(_iRamAddress), _iDVDOffset, _iLength, decrypt); } void RegisterMMIO(MMIO::Mapping* mmio, u32 base) @@ -615,7 +612,7 @@ void WriteImmediate(u32 value, u32 output_address, bool write_to_DIIMMBUF) } DVDCommandResult ExecuteReadCommand(u64 DVD_offset, u32 output_address, - u32 DVD_length, u32 output_length, bool raw) + u32 DVD_length, u32 output_length, bool decrypt) { if (DVD_length > output_length) { @@ -633,7 +630,7 @@ DVDCommandResult ExecuteReadCommand(u64 DVD_offset, u32 output_address, return result; } - if (!DVDRead(DVD_offset, output_address, DVD_length, raw)) + if (!DVDRead(DVD_offset, output_address, DVD_length, decrypt)) PanicAlertT("Can't read from DVD_Plugin - DVD-Interface: Fatal Error"); result.interrupt_type = INT_TCINT; @@ -690,13 +687,13 @@ DVDCommandResult ExecuteCommand(u32 command_0, u32 command_1, u32 command_2, // Only seems to be used from WII_IPC, not through direct access case DVDLowReadDiskID: INFO_LOG(DVDINTERFACE, "DVDLowReadDiskID"); - result = ExecuteReadCommand(0, output_address, 0x20, output_length, true); + result = ExecuteReadCommand(0, output_address, 0x20, output_length, false); break; - // Only seems to be used from WII_IPC, not through direct access + // Only used from WII_IPC. This is the only read command that decrypts data case DVDLowRead: INFO_LOG(DVDINTERFACE, "DVDLowRead: DVDAddr: 0x%09" PRIx64 ", Size: 0x%x", (u64)command_2 << 2, command_1); - result = ExecuteReadCommand((u64)command_2 << 2, output_address, command_1, output_length); + result = ExecuteReadCommand((u64)command_2 << 2, output_address, command_1, output_length, true); break; // Probably only used by Wii @@ -779,7 +776,7 @@ DVDCommandResult ExecuteCommand(u32 command_0, u32 command_1, u32 command_2, (command_2 > 0x7ed40000 && command_2 < 0x7ed40008) || (((command_2 + command_1) > 0x7ed40000) && (command_2 + command_1) < 0x7ed40008))) { - result = ExecuteReadCommand((u64)command_2 << 2, output_address, command_1, output_length, true); + result = ExecuteReadCommand((u64)command_2 << 2, output_address, command_1, output_length, false); } else { @@ -875,13 +872,13 @@ DVDCommandResult ExecuteCommand(u32 command_0, u32 command_1, u32 command_2, } } - result = ExecuteReadCommand(iDVDOffset, output_address, command_2, output_length, true); + result = ExecuteReadCommand(iDVDOffset, output_address, command_2, output_length, false); } break; case 0x40: // Read DiscID INFO_LOG(DVDINTERFACE, "Read DiscID %08x", Memory::Read_U32(output_address)); - result = ExecuteReadCommand(0, output_address, 0x20, output_length, true); + result = ExecuteReadCommand(0, output_address, 0x20, output_length, false); break; default: diff --git a/Source/Core/Core/HW/DVDInterface.h b/Source/Core/Core/HW/DVDInterface.h index 6add475e95..5b8a249fee 100644 --- a/Source/Core/Core/HW/DVDInterface.h +++ b/Source/Core/Core/HW/DVDInterface.h @@ -103,7 +103,7 @@ bool IsDiscInside(); void ChangeDisc(const std::string& fileName); // DVD Access Functions -bool DVDRead(u64 _iDVDOffset, u32 _iRamAddress, u32 _iLength, bool raw = false); +bool DVDRead(u64 _iDVDOffset, u32 _iRamAddress, u32 _iLength, bool decrypt); extern bool g_bStream; DVDCommandResult ExecuteCommand(u32 command_0, u32 command_1, u32 command_2, u32 output_address, u32 output_length, bool write_to_DIIMMBUF); diff --git a/Source/Core/Core/VolumeHandler.cpp b/Source/Core/Core/VolumeHandler.cpp index c57dbf161e..9245d66d7c 100644 --- a/Source/Core/Core/VolumeHandler.cpp +++ b/Source/Core/Core/VolumeHandler.cpp @@ -53,29 +53,21 @@ void SetVolumeDirectory(const std::string& _rFullPath, bool _bIsWii, const std:: g_pVolume = DiscIO::CreateVolumeFromDirectory(_rFullPath, _bIsWii, _rApploader, _rDOL); } -u32 Read32(u64 _Offset) +u32 Read32(u64 _Offset, bool decrypt) { if (g_pVolume != nullptr) { u32 Temp; - g_pVolume->Read(_Offset, 4, (u8*)&Temp); + g_pVolume->Read(_Offset, 4, (u8*)&Temp, decrypt); return Common::swap32(Temp); } return 0; } -bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength) +bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength, bool decrypt) { if (g_pVolume != nullptr && ptr) - return g_pVolume->Read(_dwOffset, _dwLength, ptr); - - return false; -} - -bool RAWReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength) -{ - if (g_pVolume != nullptr && ptr) - return g_pVolume->RAWRead(_dwOffset, _dwLength, ptr); + return g_pVolume->Read(_dwOffset, _dwLength, ptr, decrypt); return false; } diff --git a/Source/Core/Core/VolumeHandler.h b/Source/Core/Core/VolumeHandler.h index 2a6e8f9b90..56048e9b24 100644 --- a/Source/Core/Core/VolumeHandler.h +++ b/Source/Core/Core/VolumeHandler.h @@ -19,9 +19,10 @@ namespace VolumeHandler bool SetVolumeName(const std::string& _rFullPath); void SetVolumeDirectory(const std::string& _rFullPath, bool _bIsWii, const std::string& _rApploader = "", const std::string& _rDOL = ""); -u32 Read32(u64 _Offset); -bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength); -bool RAWReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength); +// decrypt parameter must be false if not reading a Wii disc +u32 Read32(u64 _Offset, bool decrypt); +// decrypt parameter must be false if not reading a Wii disc +bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength, bool decrypt); bool IsValid(); bool IsWii(); diff --git a/Source/Core/DiscIO/DiscScrubber.cpp b/Source/Core/DiscIO/DiscScrubber.cpp index 03a45616a4..cc4c5a5698 100644 --- a/Source/Core/DiscIO/DiscScrubber.cpp +++ b/Source/Core/DiscIO/DiscScrubber.cpp @@ -73,10 +73,8 @@ static SPartitionGroup PartitionGroup[4]; void MarkAsUsed(u64 _Offset, u64 _Size); void MarkAsUsedE(u64 _PartitionDataOffset, u64 _Offset, u64 _Size); -void ReadFromDisc(u64 _Offset, u64 _Length, u32& _Buffer); -void ReadFromDisc(u64 _Offset, u64 _Length, u64& _Buffer); -void ReadFromVolume(u64 _Offset, u64 _Length, u32& _Buffer); -void ReadFromVolume(u64 _Offset, u64 _Length, u64& _Buffer); +void ReadFromVolume(u64 _Offset, u64 _Length, u32& _Buffer, bool _Decrypt); +void ReadFromVolume(u64 _Offset, u64 _Length, u64& _Buffer, bool _Decrypt); bool ParseDisc(); bool ParsePartitionData(SPartition& _rPartition); u32 GetDOLSize(u64 _DOLOffset); @@ -190,27 +188,15 @@ void MarkAsUsedE(u64 _PartitionDataOffset, u64 _Offset, u64 _Size) MarkAsUsed(Offset, Size); } -// Helper functions for RAW reading the BE discs -void ReadFromDisc(u64 _Offset, u64 _Length, u32& _Buffer) -{ - m_Disc->RAWRead(_Offset, _Length, (u8*)&_Buffer); - _Buffer = Common::swap32(_Buffer); -} -void ReadFromDisc(u64 _Offset, u64 _Length, u64& _Buffer) -{ - m_Disc->RAWRead(_Offset, _Length, (u8*)&_Buffer); - _Buffer = Common::swap32((u32)_Buffer); - _Buffer <<= 2; -} // Helper functions for reading the BE volume -void ReadFromVolume(u64 _Offset, u64 _Length, u32& _Buffer) +void ReadFromVolume(u64 _Offset, u64 _Length, u32& _Buffer, bool _Decrypt) { - m_Disc->Read(_Offset, _Length, (u8*)&_Buffer); + m_Disc->Read(_Offset, _Length, (u8*)&_Buffer, _Decrypt); _Buffer = Common::swap32(_Buffer); } -void ReadFromVolume(u64 _Offset, u64 _Length, u64& _Buffer) +void ReadFromVolume(u64 _Offset, u64 _Length, u64& _Buffer, bool _Decrypt) { - m_Disc->Read(_Offset, _Length, (u8*)&_Buffer); + m_Disc->Read(_Offset, _Length, (u8*)&_Buffer, _Decrypt); _Buffer = Common::swap32((u32)_Buffer); _Buffer <<= 2; } @@ -222,8 +208,8 @@ bool ParseDisc() for (int x = 0; x < 4; x++) { - ReadFromDisc(0x40000 + (x * 8) + 0, 4, PartitionGroup[x].numPartitions); - ReadFromDisc(0x40000 + (x * 8) + 4, 4, PartitionGroup[x].PartitionsOffset); + ReadFromVolume(0x40000 + (x * 8) + 0, 4, PartitionGroup[x].numPartitions, false); + ReadFromVolume(0x40000 + (x * 8) + 4, 4, PartitionGroup[x].PartitionsOffset, false); // Read all partitions for (u32 i = 0; i < PartitionGroup[x].numPartitions; i++) @@ -233,16 +219,16 @@ bool ParseDisc() Partition.GroupNumber = x; Partition.Number = i; - ReadFromDisc(PartitionGroup[x].PartitionsOffset + (i * 8) + 0, 4, Partition.Offset); - ReadFromDisc(PartitionGroup[x].PartitionsOffset + (i * 8) + 4, 4, Partition.Type); + ReadFromVolume(PartitionGroup[x].PartitionsOffset + (i * 8) + 0, 4, Partition.Offset, false); + ReadFromVolume(PartitionGroup[x].PartitionsOffset + (i * 8) + 4, 4, Partition.Type, false); - ReadFromDisc(Partition.Offset + 0x2a4, 4, Partition.Header.TMDSize); - ReadFromDisc(Partition.Offset + 0x2a8, 4, Partition.Header.TMDOffset); - ReadFromDisc(Partition.Offset + 0x2ac, 4, Partition.Header.CertChainSize); - ReadFromDisc(Partition.Offset + 0x2b0, 4, Partition.Header.CertChainOffset); - ReadFromDisc(Partition.Offset + 0x2b4, 4, Partition.Header.H3Offset); - ReadFromDisc(Partition.Offset + 0x2b8, 4, Partition.Header.DataOffset); - ReadFromDisc(Partition.Offset + 0x2bc, 4, Partition.Header.DataSize); + ReadFromVolume(Partition.Offset + 0x2a4, 4, Partition.Header.TMDSize, false); + ReadFromVolume(Partition.Offset + 0x2a8, 4, Partition.Header.TMDOffset, false); + ReadFromVolume(Partition.Offset + 0x2ac, 4, Partition.Header.CertChainSize, false); + ReadFromVolume(Partition.Offset + 0x2b0, 4, Partition.Header.CertChainOffset, false); + ReadFromVolume(Partition.Offset + 0x2b4, 4, Partition.Header.H3Offset, false); + ReadFromVolume(Partition.Offset + 0x2b8, 4, Partition.Header.DataOffset, false); + ReadFromVolume(Partition.Offset + 0x2bc, 4, Partition.Header.DataSize, false); PartitionGroup[x].PartitionsVec.push_back(Partition); } @@ -293,8 +279,8 @@ bool ParsePartitionData(SPartition& _rPartition) // Mark things as used which are not in the filesystem // Header, Header Information, Apploader - ReadFromVolume(0x2440 + 0x14, 4, _rPartition.Header.ApploaderSize); - ReadFromVolume(0x2440 + 0x18, 4, _rPartition.Header.ApploaderTrailerSize); + ReadFromVolume(0x2440 + 0x14, 4, _rPartition.Header.ApploaderSize, true); + ReadFromVolume(0x2440 + 0x18, 4, _rPartition.Header.ApploaderTrailerSize, true); MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset , 0 @@ -303,7 +289,7 @@ bool ParsePartitionData(SPartition& _rPartition) + _rPartition.Header.ApploaderTrailerSize); // DOL - ReadFromVolume(0x420, 4, _rPartition.Header.DOLOffset); + ReadFromVolume(0x420, 4, _rPartition.Header.DOLOffset, true); _rPartition.Header.DOLSize = GetDOLSize(_rPartition.Header.DOLOffset); MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset @@ -311,8 +297,8 @@ bool ParsePartitionData(SPartition& _rPartition) , _rPartition.Header.DOLSize); // FST - ReadFromVolume(0x424, 4, _rPartition.Header.FSTOffset); - ReadFromVolume(0x428, 4, _rPartition.Header.FSTSize); + ReadFromVolume(0x424, 4, _rPartition.Header.FSTOffset, true); + ReadFromVolume(0x428, 4, _rPartition.Header.FSTSize, true); MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset , _rPartition.Header.FSTOffset @@ -348,8 +334,8 @@ u32 GetDOLSize(u64 _DOLOffset) // Iterate through the 7 code segments for (u8 i = 0; i < 7; i++) { - ReadFromVolume(_DOLOffset + 0x00 + i * 4, 4, offset); - ReadFromVolume(_DOLOffset + 0x90 + i * 4, 4, size); + ReadFromVolume(_DOLOffset + 0x00 + i * 4, 4, offset, true); + ReadFromVolume(_DOLOffset + 0x90 + i * 4, 4, size, true); if (offset + size > max) max = offset + size; } @@ -357,8 +343,8 @@ u32 GetDOLSize(u64 _DOLOffset) // Iterate through the 11 data segments for (u8 i = 0; i < 11; i++) { - ReadFromVolume(_DOLOffset + 0x1c + i * 4, 4, offset); - ReadFromVolume(_DOLOffset + 0xac + i * 4, 4, size); + ReadFromVolume(_DOLOffset + 0x1c + i * 4, 4, offset, true); + ReadFromVolume(_DOLOffset + 0xac + i * 4, 4, size, true); if (offset + size > max) max = offset + size; } diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index d39d803e11..f9b1fa10e3 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -23,7 +23,7 @@ CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume) : IFileSystem(_rVolume) , m_Initialized(false) , m_Valid(false) - , m_OffsetShift(0) + , m_Wii(false) { m_Valid = DetectFileSystem(); } @@ -78,7 +78,7 @@ u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size DEBUG_LOG(DISCIO, "Filename: %s. Offset: %" PRIx64 ". Size: %" PRIx64, _rFullPath.c_str(), pFileInfo->m_Offset, pFileInfo->m_FileSize); - m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer); + m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer, m_Wii); return pFileInfo->m_FileSize; } @@ -108,7 +108,7 @@ bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath, const std::stri std::vector buffer(readSize); - result = m_rVolume->Read(fileOffset, readSize, &buffer[0]); + result = m_rVolume->Read(fileOffset, readSize, &buffer[0], m_Wii); if (!result) break; @@ -130,7 +130,7 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const DEBUG_LOG(DISCIO,"AppSize -> %x", AppSize); std::vector buffer(AppSize); - if (m_rVolume->Read(0x2440, AppSize, &buffer[0])) + if (m_rVolume->Read(0x2440, AppSize, &buffer[0], m_Wii)) { std::string exportName(_rExportFolder + "/apploader.img"); @@ -147,7 +147,7 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const u32 CFileSystemGCWii::GetBootDOLSize() const { - u32 DolOffset = Read32(0x420) << m_OffsetShift; + u32 DolOffset = Read32(0x420) << GetOffsetShift(); u32 DolSize = 0, offset = 0, size = 0; // Iterate through the 7 code segments @@ -172,17 +172,17 @@ u32 CFileSystemGCWii::GetBootDOLSize() const bool CFileSystemGCWii::GetBootDOL(u8* &buffer, u32 DolSize) const { - u32 DolOffset = Read32(0x420) << m_OffsetShift; - return m_rVolume->Read(DolOffset, DolSize, buffer); + u32 DolOffset = Read32(0x420) << GetOffsetShift(); + return m_rVolume->Read(DolOffset, DolSize, buffer, m_Wii); } bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const { - u32 DolOffset = Read32(0x420) << m_OffsetShift; + u32 DolOffset = Read32(0x420) << GetOffsetShift(); u32 DolSize = GetBootDOLSize(); std::vector buffer(DolSize); - if (m_rVolume->Read(DolOffset, DolSize, &buffer[0])) + if (m_rVolume->Read(DolOffset, DolSize, &buffer[0], m_Wii)) { std::string exportName(_rExportFolder + "/boot.dol"); @@ -200,7 +200,7 @@ bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const u32 CFileSystemGCWii::Read32(u64 _Offset) const { u32 Temp = 0; - m_rVolume->Read(_Offset, 4, (u8*)&Temp); + m_rVolume->Read(_Offset, 4, (u8*)&Temp, m_Wii); return Common::swap32(Temp); } @@ -208,7 +208,7 @@ std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const { std::string data; data.resize(255); - m_rVolume->Read(_Offset, data.size(), (u8*)&data[0]); + m_rVolume->Read(_Offset, data.size(), (u8*)&data[0], m_Wii); data.erase(std::find(data.begin(), data.end(), 0x00), data.end()); // TODO: Should we really always use SHIFT-JIS? @@ -248,12 +248,12 @@ bool CFileSystemGCWii::DetectFileSystem() { if (Read32(0x18) == 0x5D1C9EA3) { - m_OffsetShift = 2; // Wii file system + m_Wii = true; return true; } else if (Read32(0x1c) == 0xC2339F3D) { - m_OffsetShift = 0; // GC file system + m_Wii = false; return true; } @@ -265,7 +265,7 @@ void CFileSystemGCWii::InitFileSystem() m_Initialized = true; // read the whole FST - u64 FSTOffset = (u64)Read32(0x424) << m_OffsetShift; + u64 FSTOffset = (u64)Read32(0x424) << GetOffsetShift(); // u32 FSTSize = Read32(0x428); // u32 FSTMaxSize = Read32(0x42C); @@ -273,7 +273,7 @@ void CFileSystemGCWii::InitFileSystem() // read all fileinfos SFileInfo Root; Root.m_NameOffset = Read32(FSTOffset + 0x0); - Root.m_Offset = (u64)Read32(FSTOffset + 0x4) << m_OffsetShift; + Root.m_Offset = (u64)Read32(FSTOffset + 0x4) << GetOffsetShift(); Root.m_FileSize = Read32(FSTOffset + 0x8); if (Root.IsDirectory()) @@ -288,7 +288,7 @@ void CFileSystemGCWii::InitFileSystem() SFileInfo sfi; u64 Offset = FSTOffset + (i * 0xC); sfi.m_NameOffset = Read32(Offset + 0x0); - sfi.m_Offset = (u64)Read32(Offset + 0x4) << m_OffsetShift; + sfi.m_Offset = (u64)Read32(Offset + 0x4) << GetOffsetShift(); sfi.m_FileSize = Read32(Offset + 0x8); m_FileInfoVector.push_back(sfi); @@ -325,4 +325,9 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _ return CurrentIndex; } +u32 CFileSystemGCWii::GetOffsetShift() const +{ + return m_Wii ? 2 : 0; +} + } // namespace diff --git a/Source/Core/DiscIO/FileSystemGCWii.h b/Source/Core/DiscIO/FileSystemGCWii.h index a807358b32..24a1c65ab3 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.h +++ b/Source/Core/DiscIO/FileSystemGCWii.h @@ -35,7 +35,7 @@ public: private: bool m_Initialized; bool m_Valid; - u32 m_OffsetShift; // WII offsets are all shifted + bool m_Wii; std::vector m_FileInfoVector; u32 Read32(u64 _Offset) const; @@ -44,6 +44,7 @@ private: bool DetectFileSystem(); void InitFileSystem(); size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, u64 _NameTableOffset); + u32 GetOffsetShift() const; }; } // namespace diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 6162e0db8f..097da655bc 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -18,8 +18,9 @@ public: IVolume() {} virtual ~IVolume() {} - virtual bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const = 0; - virtual bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const = 0; + // decrypt parameter must be false if not reading a Wii disc + virtual bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const = 0; + virtual bool GetTitleID(u8*) const { return false; } virtual std::unique_ptr GetTMD(u32 *_sz) const { diff --git a/Source/Core/DiscIO/VolumeCreator.cpp b/Source/Core/DiscIO/VolumeCreator.cpp index 24fa75909e..73feb93780 100644 --- a/Source/Core/DiscIO/VolumeCreator.cpp +++ b/Source/Core/DiscIO/VolumeCreator.cpp @@ -123,7 +123,7 @@ IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii, bool IsVolumeWiiDisc(const IVolume *_rVolume) { u32 MagicWord = 0; - _rVolume->Read(0x18, 4, (u8*)&MagicWord); + _rVolume->Read(0x18, 4, (u8*)&MagicWord, false); return (Common::swap32(MagicWord) == 0x5D1C9EA3); //GameCube 0xc2339f3d @@ -132,7 +132,7 @@ bool IsVolumeWiiDisc(const IVolume *_rVolume) bool IsVolumeWadFile(const IVolume *_rVolume) { u32 MagicWord = 0; - _rVolume->Read(0x02, 4, (u8*)&MagicWord); + _rVolume->Read(0x02, 4, (u8*)&MagicWord, false); return (Common::swap32(MagicWord) == 0x00204973 || Common::swap32(MagicWord) == 0x00206962); } diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 66803018fe..9c88f3c415 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -64,16 +64,23 @@ bool CVolumeDirectory::IsValidDirectory(const std::string& _rDirectory) return File::IsDirectory(directoryName); } -bool CVolumeDirectory::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const +bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const { - if (VolumeHandler::IsWii()) - return false; - else - return Read(_Offset, _Length, _pBuffer); -} + bool wii = VolumeHandler::IsWii(); + + if (!decrypt && (_Offset + _Length >= 0x400) && wii) + { + // Fully supporting this would require re-encrypting every file that's read. + // Only supporting the areas that IOS allows software to read could be more feasible. + // Currently, only the header (up to 0x400) is supported, though we're cheating a bit + // with it by reading the header inside the current partition instead. Supporting the + // header is enough for booting games, but not for running things like the Disc Channel. + return false; + } + + if (decrypt && !wii) + PanicAlertT("Tried to decrypt data from a non-Wii volume"); -bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const -{ // header if (_Offset < DISKHEADERINFO_ADDRESS) { diff --git a/Source/Core/DiscIO/VolumeDirectory.h b/Source/Core/DiscIO/VolumeDirectory.h index 9e0c8ba74c..53ebb1acd2 100644 --- a/Source/Core/DiscIO/VolumeDirectory.h +++ b/Source/Core/DiscIO/VolumeDirectory.h @@ -32,8 +32,7 @@ public: static bool IsValidDirectory(const std::string& _rDirectory); - bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const override; - bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const override; + bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override; std::string GetUniqueID() const override; void SetUniqueID(const std::string& _ID); diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 57303b13e7..984a82ce3b 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -24,8 +24,11 @@ CVolumeGC::~CVolumeGC() { } -bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const +bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const { + if (decrypt) + PanicAlertT("Tried to decrypt data from a non-Wii volume"); + if (m_pReader == nullptr) return false; @@ -34,11 +37,6 @@ bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const return m_pReader->Read(_Offset, _Length, _pBuffer); } -bool CVolumeGC::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const -{ - return Read(_Offset, _Length, _pBuffer); -} - std::string CVolumeGC::GetUniqueID() const { static const std::string NO_UID("NO_UID"); diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h index 436de0d5a0..bc79e535c4 100644 --- a/Source/Core/DiscIO/VolumeGC.h +++ b/Source/Core/DiscIO/VolumeGC.h @@ -23,8 +23,7 @@ class CVolumeGC : public IVolume public: CVolumeGC(IBlobReader* _pReader); ~CVolumeGC(); - bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const override; - bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const override; + bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override; std::string GetUniqueID() const override; std::string GetRevisionSpecificUniqueID() const override; std::string GetMakerID() const override; diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index fd189c39c1..014792fc75 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -44,8 +44,11 @@ CVolumeWAD::~CVolumeWAD() { } -bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const +bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const { + if (decrypt) + PanicAlertT("Tried to decrypt data from a non-Wii volume"); + if (m_pReader == nullptr) return false; diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h index ce03850a49..93ed22949e 100644 --- a/Source/Core/DiscIO/VolumeWad.h +++ b/Source/Core/DiscIO/VolumeWad.h @@ -25,8 +25,7 @@ class CVolumeWAD : public IVolume public: CVolumeWAD(IBlobReader* _pReader); ~CVolumeWAD(); - bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const override; - bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const override { return false; } + bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override; bool GetTitleID(u8* _pBuffer) const override; std::string GetUniqueID() const override; std::string GetMakerID() const override; diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 0f44230476..80dc53a123 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -54,21 +54,13 @@ CVolumeWiiCrypted::~CVolumeWiiCrypted() m_pBuffer = nullptr; } -bool CVolumeWiiCrypted::RAWRead( u64 _Offset, u64 _Length, u8* _pBuffer ) const -{ - // HyperIris: hack for DVDLowUnencryptedRead - // Medal Of Honor Heroes 2 read this DVD offset for PartitionsInfo - // and, PartitionsInfo is not encrypted, let's read it directly. - if (!m_pReader->Read(_Offset, _Length, _pBuffer)) - return(false); - else - return true; -} - -bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer) const +bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool decrypt) const { if (m_pReader == nullptr) - return(false); + return false; + + if (!decrypt) + return m_pReader->Read(_ReadOffset, _Length, _pBuffer); FileMon::FindFilename(_ReadOffset); @@ -110,7 +102,7 @@ bool CVolumeWiiCrypted::GetTitleID(u8* _pBuffer) const { // Tik is at m_VolumeOffset size 0x2A4 // TitleID offset in tik is 0x1DC - return RAWRead(m_VolumeOffset + 0x1DC, 8, _pBuffer); + return Read(m_VolumeOffset + 0x1DC, 8, _pBuffer, false); } std::unique_ptr CVolumeWiiCrypted::GetTMD(u32 *size) const @@ -119,8 +111,8 @@ std::unique_ptr CVolumeWiiCrypted::GetTMD(u32 *size) const u32 tmd_size; u32 tmd_address; - RAWRead(m_VolumeOffset + 0x2a4, sizeof(u32), (u8*)&tmd_size); - RAWRead(m_VolumeOffset + 0x2a8, sizeof(u32), (u8*)&tmd_address); + Read(m_VolumeOffset + 0x2a4, sizeof(u32), (u8*)&tmd_size, false); + Read(m_VolumeOffset + 0x2a8, sizeof(u32), (u8*)&tmd_address, false); tmd_size = Common::swap32(tmd_size); tmd_address = Common::swap32(tmd_address) << 2; @@ -135,7 +127,7 @@ std::unique_ptr CVolumeWiiCrypted::GetTMD(u32 *size) const } std::unique_ptr buf{ new u8[tmd_size] }; - RAWRead(m_VolumeOffset + tmd_address, tmd_size, buf.get()); + Read(m_VolumeOffset + tmd_address, tmd_size, buf.get(), false); *size = tmd_size; return buf; } @@ -147,7 +139,7 @@ std::string CVolumeWiiCrypted::GetUniqueID() const char ID[7]; - if (!Read(0, 6, (u8*)ID)) + if (!Read(0, 6, (u8*)ID, false)) return std::string(); ID[6] = '\0'; @@ -174,7 +166,7 @@ std::string CVolumeWiiCrypted::GetMakerID() const char makerID[3]; - if (!Read(0x4, 0x2, (u8*)&makerID)) + if (!Read(0x4, 0x2, (u8*)&makerID, false)) return std::string(); makerID[2] = '\0'; @@ -201,7 +193,7 @@ std::vector CVolumeWiiCrypted::GetNames() const auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry()); char name[0xFF] = {}; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name)) + if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name, true)) names.push_back(string_decoder(name)); return names; @@ -214,7 +206,7 @@ u32 CVolumeWiiCrypted::GetFSTSize() const u32 size; - if (!Read(0x428, 0x4, (u8*)&size)) + if (!Read(0x428, 0x4, (u8*)&size, true)) return 0; return size; @@ -227,7 +219,7 @@ std::string CVolumeWiiCrypted::GetApploaderDate() const char date[16]; - if (!Read(0x2440, 0x10, (u8*)&date)) + if (!Read(0x2440, 0x10, (u8*)&date, true)) return std::string(); date[10] = '\0'; @@ -255,7 +247,7 @@ bool CVolumeWiiCrypted::CheckIntegrity() const { // Get partition data size u32 partSizeDiv4; - RAWRead(m_VolumeOffset + 0x2BC, 4, (u8*)&partSizeDiv4); + Read(m_VolumeOffset + 0x2BC, 4, (u8*)&partSizeDiv4, false); u64 partDataSize = (u64)Common::swap32(partSizeDiv4) * 4; u32 nClusters = (u32)(partDataSize / 0x8000); @@ -292,7 +284,7 @@ bool CVolumeWiiCrypted::CheckIntegrity() const continue; u8 clusterData[0x7C00]; - if (!Read((u64)clusterID * 0x7C00, 0x7C00, clusterData)) + if (!Read((u64)clusterID * 0x7C00, 0x7C00, clusterData, true)) { NOTICE_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read data", clusterID); return false; diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index cd4fb5599d..fd397e19c3 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -24,8 +24,7 @@ class CVolumeWiiCrypted : public IVolume public: CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset, const unsigned char* _pVolumeKey); ~CVolumeWiiCrypted(); - bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const override; - bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const override; + bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override; bool GetTitleID(u8* _pBuffer) const override; virtual std::unique_ptr GetTMD(u32 *_sz) const override; std::string GetUniqueID() const override;