mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-13 15:59:23 +01:00
restructured NAND application loading... it isn't complete but an improvement
i have changed the update of the IPC too... update for the command queues and update of the devices are split in two functions now git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2455 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
d37d71c1b8
commit
c76c477a6d
@ -30,7 +30,7 @@
|
|||||||
// Dirs in User
|
// Dirs in User
|
||||||
#define GC_USER_DIR "GC"
|
#define GC_USER_DIR "GC"
|
||||||
#define WII_USER_DIR "Wii"
|
#define WII_USER_DIR "Wii"
|
||||||
#define WII_SYSCONF_DIR "shared2/sys"
|
#define WII_SYSCONF_DIR "shared2/sys"
|
||||||
#define CONFIG_DIR "Config"
|
#define CONFIG_DIR "Config"
|
||||||
#define GAMECONFIG_DIR "GameConfig"
|
#define GAMECONFIG_DIR "GameConfig"
|
||||||
#define MAPS_DIR "Maps"
|
#define MAPS_DIR "Maps"
|
||||||
@ -76,7 +76,6 @@
|
|||||||
// Shorts - dirs
|
// Shorts - dirs
|
||||||
// User dirs
|
// User dirs
|
||||||
#define FULL_USERDATA_DIR ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP
|
#define FULL_USERDATA_DIR ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP
|
||||||
|
|
||||||
#define FULL_GC_USER_DIR FULL_USERDATA_DIR GC_USER_DIR DIR_SEP
|
#define FULL_GC_USER_DIR FULL_USERDATA_DIR GC_USER_DIR DIR_SEP
|
||||||
//#define GC_USER_EUR_DIR FULL_GC_USER_DIR EUR_DIR
|
//#define GC_USER_EUR_DIR FULL_GC_USER_DIR EUR_DIR
|
||||||
//#define GC_USER_USA_DIR FULL_GC_USER_DIR USA_DIR
|
//#define GC_USER_USA_DIR FULL_GC_USER_DIR USA_DIR
|
||||||
@ -126,4 +125,6 @@
|
|||||||
#define WII_JAP_SETTING_FILE FULL_WII_SYS_DIR WII_JAP_SETTING
|
#define WII_JAP_SETTING_FILE FULL_WII_SYS_DIR WII_JAP_SETTING
|
||||||
#define WII_SYSCONF_FILE FULL_WII_USER_DIR WII_SYSCONF_DIR DIR_SEP WII_SYSCONF
|
#define WII_SYSCONF_FILE FULL_WII_USER_DIR WII_SYSCONF_DIR DIR_SEP WII_SYSCONF
|
||||||
|
|
||||||
|
#define FULL_WII_MENU_DIR FULL_WII_USER_DIR "title" DIR_SEP "00000001" DIR_SEP "00000002" DIR_SEP "content"
|
||||||
|
|
||||||
#endif // PATHS_H
|
#endif // PATHS_H
|
||||||
|
@ -292,7 +292,7 @@ bool CBoot::BootUp()
|
|||||||
|
|
||||||
// Wii WAD
|
// Wii WAD
|
||||||
// ===================================================================================
|
// ===================================================================================
|
||||||
case SCoreStartupParameter::BOOT_WIIWAD:
|
case SCoreStartupParameter::BOOT_WII_NAND:
|
||||||
Boot_WiiWAD(_StartupPara.m_strFilename.c_str());
|
Boot_WiiWAD(_StartupPara.m_strFilename.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -20,167 +20,11 @@
|
|||||||
#include "../HLE/HLE.h"
|
#include "../HLE/HLE.h"
|
||||||
#include "../HW/Memmap.h"
|
#include "../HW/Memmap.h"
|
||||||
#include "../ConfigManager.h"
|
#include "../ConfigManager.h"
|
||||||
#include "Blob.h"
|
#include "../IPC_HLE/WII_IPC_HLE.h"
|
||||||
#include "MappedFile.h"
|
|
||||||
#include "Boot_DOL.h"
|
#include "NANDContentLoader.h"
|
||||||
#include "Boot_WiiWAD.h"
|
|
||||||
#include "AES/aes.h"
|
|
||||||
#include "MathUtil.h"
|
|
||||||
#include "FileUtil.h"
|
#include "FileUtil.h"
|
||||||
|
#include "Boot_DOL.h"
|
||||||
class CBlobBigEndianReader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CBlobBigEndianReader(DiscIO::IBlobReader& _rReader) : m_rReader(_rReader) {}
|
|
||||||
|
|
||||||
u32 Read32(u64 _Offset)
|
|
||||||
{
|
|
||||||
u32 Temp;
|
|
||||||
m_rReader.Read(_Offset, 4, (u8*)&Temp);
|
|
||||||
return(Common::swap32(Temp));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
DiscIO::IBlobReader& m_rReader;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<STileMetaContent> m_TileMetaContent;
|
|
||||||
u16 m_BootIndex = -1;
|
|
||||||
u64 m_TitleID = -1;
|
|
||||||
|
|
||||||
void AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest)
|
|
||||||
{
|
|
||||||
AES_KEY AESKey;
|
|
||||||
|
|
||||||
AES_set_decrypt_key(_pKey, 128, &AESKey);
|
|
||||||
AES_cbc_encrypt(_pSrc, _pDest, _Size, &AESKey, _IV, AES_DECRYPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
u8* CreateWADEntry(DiscIO::IBlobReader& _rReader, u32 _Size, u64 _Offset)
|
|
||||||
{
|
|
||||||
if (_Size > 0)
|
|
||||||
{
|
|
||||||
u8* pTmpBuffer = new u8[_Size];
|
|
||||||
_dbg_assert_msg_(BOOT, pTmpBuffer!=0, "WiiWAD: Cant allocate memory for WAD entry");
|
|
||||||
|
|
||||||
if (!_rReader.Read(_Offset, _Size, pTmpBuffer))
|
|
||||||
{
|
|
||||||
PanicAlert("WiiWAD: Could not read from file");
|
|
||||||
}
|
|
||||||
return pTmpBuffer;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetKeyFromTicket(u8* pTicket, u8* pTicketKey)
|
|
||||||
{
|
|
||||||
u8 CommonKey[16] = {0xeb,0xe4,0x2a,0x22,0x5e,0x85,0x93,0xe4,0x48,0xd9,0xc5,0x45,0x73,0x81,0xaa,0xf7};
|
|
||||||
u8 IV[16];
|
|
||||||
memset(IV, 0, sizeof IV);
|
|
||||||
memcpy(IV, pTicket + 0x01dc, 8);
|
|
||||||
AESDecode(CommonKey, IV, pTicket + 0x01bf, 16, pTicketKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ParseTMD(u8* pDataApp, u32 pDataAppSize, u8* pTicket, u8* pTMD)
|
|
||||||
{
|
|
||||||
u8 DecryptTitleKey[16];
|
|
||||||
u8 IV[16];
|
|
||||||
|
|
||||||
GetKeyFromTicket(pTicket, DecryptTitleKey);
|
|
||||||
|
|
||||||
u32 numEntries = Common::swap16(pTMD + 0x01de);
|
|
||||||
m_BootIndex = Common::swap16(pTMD + 0x01e0);
|
|
||||||
m_TitleID = Common::swap64(pTMD + 0x018C);
|
|
||||||
|
|
||||||
u8* p = pDataApp;
|
|
||||||
|
|
||||||
m_TileMetaContent.resize(numEntries);
|
|
||||||
|
|
||||||
for (u32 i=0; i<numEntries; i++)
|
|
||||||
{
|
|
||||||
STileMetaContent& rContent = m_TileMetaContent[i];
|
|
||||||
|
|
||||||
rContent.m_ContentID = Common::swap32(pTMD + 0x01e4 + 0x24*i);
|
|
||||||
rContent.m_Index = Common::swap16(pTMD + 0x01e8 + 0x24*i);
|
|
||||||
rContent.m_Type = Common::swap16(pTMD + 0x01ea + 0x24*i);
|
|
||||||
rContent.m_Size= (u32)Common::swap64(pTMD + 0x01ec + 0x24*i);
|
|
||||||
rContent.m_RoundedSize= ROUND_UP(rContent.m_Size, 0x40);
|
|
||||||
rContent.m_pData = new u8[rContent.m_RoundedSize];
|
|
||||||
|
|
||||||
memset(IV, 0, sizeof IV);
|
|
||||||
memcpy(IV, pTMD + 0x01e8 + 0x24*i, 2);
|
|
||||||
AESDecode(DecryptTitleKey, IV, p, rContent.m_RoundedSize, rContent.m_pData);
|
|
||||||
|
|
||||||
p += rContent.m_RoundedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ParseWAD(DiscIO::IBlobReader& _rReader)
|
|
||||||
{
|
|
||||||
CBlobBigEndianReader ReaderBig(_rReader);
|
|
||||||
|
|
||||||
// get header size
|
|
||||||
u32 HeaderSize = ReaderBig.Read32(0);
|
|
||||||
if (HeaderSize != 0x20)
|
|
||||||
{
|
|
||||||
_dbg_assert_msg_(BOOT, (HeaderSize==0x20), "WiiWAD: Header size != 0x20");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get header
|
|
||||||
u8 Header[0x20];
|
|
||||||
_rReader.Read(0, HeaderSize, Header);
|
|
||||||
u32 HeaderType = ReaderBig.Read32(0x4);
|
|
||||||
if ((0x49730000 != HeaderType) && (0x69620000 != HeaderType))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
u32 CertificateChainSize = ReaderBig.Read32(0x8);
|
|
||||||
u32 Reserved = ReaderBig.Read32(0xC);
|
|
||||||
u32 TicketSize = ReaderBig.Read32(0x10);
|
|
||||||
u32 TMDSize = ReaderBig.Read32(0x14);
|
|
||||||
u32 DataAppSize = ReaderBig.Read32(0x18);
|
|
||||||
u32 FooterSize = ReaderBig.Read32(0x1C);
|
|
||||||
_dbg_assert_msg_(BOOT, Reserved==0x00, "WiiWAD: Reserved must be 0x00");
|
|
||||||
|
|
||||||
u32 Offset = 0x40;
|
|
||||||
u8* pCertificateChain = CreateWADEntry(_rReader, CertificateChainSize, Offset); Offset += ROUND_UP(CertificateChainSize, 0x40);
|
|
||||||
u8* pTicket = CreateWADEntry(_rReader, TicketSize, Offset); Offset += ROUND_UP(TicketSize, 0x40);
|
|
||||||
u8* pTMD = CreateWADEntry(_rReader, TMDSize, Offset); Offset += ROUND_UP(TMDSize, 0x40);
|
|
||||||
u8* pDataApp = CreateWADEntry(_rReader, DataAppSize, Offset); Offset += ROUND_UP(DataAppSize, 0x40);
|
|
||||||
u8* pFooter = CreateWADEntry(_rReader, FooterSize, Offset); Offset += ROUND_UP(FooterSize, 0x40);
|
|
||||||
|
|
||||||
bool Result = ParseTMD(pDataApp, DataAppSize, pTicket, pTMD);
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CBoot::IsWiiWAD(const char* _pFileName)
|
|
||||||
{
|
|
||||||
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_pFileName);
|
|
||||||
if (pReader == NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CBlobBigEndianReader Reader(*pReader);
|
|
||||||
bool Result = false;
|
|
||||||
|
|
||||||
// check for wii wad
|
|
||||||
if (Reader.Read32(0x00) == 0x20)
|
|
||||||
{
|
|
||||||
u32 WADTYpe = Reader.Read32(0x04);
|
|
||||||
switch(WADTYpe)
|
|
||||||
{
|
|
||||||
case 0x49730000:
|
|
||||||
case 0x69620000:
|
|
||||||
Result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete pReader;
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SetupWiiMem()
|
void SetupWiiMem()
|
||||||
@ -238,53 +82,40 @@ void SetupWiiMem()
|
|||||||
{
|
{
|
||||||
Memory::Write_U32(0x00000000, 0x80000000 + i);
|
Memory::Write_U32(0x00000000, 0x80000000 + i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CBoot::IsWiiWAD(const char *filename)
|
||||||
|
{
|
||||||
// create Home directory
|
return DiscIO::CNANDContentLoader::IsWiiWAD(filename);
|
||||||
{
|
|
||||||
char Path[260+1];
|
|
||||||
char* pTitleID = (char*)&m_TitleID;
|
|
||||||
sprintf(Path, FULL_WII_USER_DIR "title//%02x%02x%02x%02x/%02x%02x%02x%02x/data/nocopy/",
|
|
||||||
(u8)pTitleID[7], (u8)pTitleID[6], (u8)pTitleID[5], (u8)pTitleID[4],
|
|
||||||
(u8)pTitleID[3], (u8)pTitleID[2], (u8)pTitleID[1], (u8)pTitleID[0]);
|
|
||||||
File::CreateDirectoryStructure(Path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This is some kind of consistency check that is compared to the 0x00
|
|
||||||
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. */
|
|
||||||
|
|
||||||
|
|
||||||
Memory::Write_U64(m_TitleID, 0x0000318c); // NAND Load Title ID
|
|
||||||
|
|
||||||
// VolumeHandler::ReadToPtr(Memory::GetPointer(0x3180), 0, 4);
|
|
||||||
// Memory::Write_U8(0x80, 0x00003184);
|
|
||||||
// ================
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBoot::Boot_WiiWAD(const char* _pFilename)
|
bool CBoot::Boot_WiiWAD(const char* _pFilename)
|
||||||
{
|
{
|
||||||
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_pFilename);
|
DiscIO::CNANDContentLoader ContentLoader(_pFilename);
|
||||||
if (pReader == NULL)
|
if (ContentLoader.IsValid() == false)
|
||||||
return false;
|
|
||||||
|
|
||||||
bool Result = ParseWAD(*pReader);
|
|
||||||
delete pReader;
|
|
||||||
|
|
||||||
if (!Result)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SetupWiiMem();
|
SetupWiiMem();
|
||||||
|
|
||||||
// DOL
|
// create Home directory
|
||||||
STileMetaContent& rContent = m_TileMetaContent[m_BootIndex];
|
char Path[260+1];
|
||||||
CDolLoader DolLoader(rContent.m_pData, rContent.m_RoundedSize);
|
u64 TitleID = ContentLoader.GetTitleID();
|
||||||
|
char* pTitleID = (char*)&TitleID;
|
||||||
|
sprintf(Path, FULL_WII_USER_DIR "title//%02x%02x%02x%02x/%02x%02x%02x%02x/data/nocopy/",
|
||||||
|
(u8)pTitleID[7], (u8)pTitleID[6], (u8)pTitleID[5], (u8)pTitleID[4],
|
||||||
|
(u8)pTitleID[3], (u8)pTitleID[2], (u8)pTitleID[1], (u8)pTitleID[0]);
|
||||||
|
File::CreateDirectoryStructure(Path);
|
||||||
|
|
||||||
|
Memory::Write_U64( ContentLoader.GetTitleID(), 0x0000318c); // NAND Load Title ID
|
||||||
|
|
||||||
|
// DOL
|
||||||
|
DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(ContentLoader.GetBootIndex());
|
||||||
|
if (pContent == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
WII_IPC_HLE_Interface::SetDefaultContentFile(_pFilename);
|
||||||
|
|
||||||
|
CDolLoader DolLoader(pContent->m_pData, pContent->m_Size);
|
||||||
PC = DolLoader.GetEntryPoint() | 0x80000000;
|
PC = DolLoader.GetEntryPoint() | 0x80000000;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,22 +17,3 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
struct STileMetaContent
|
|
||||||
{
|
|
||||||
u32 m_ContentID;
|
|
||||||
u16 m_Index;
|
|
||||||
u16 m_Type;
|
|
||||||
u32 m_Size;
|
|
||||||
u32 m_RoundedSize;
|
|
||||||
|
|
||||||
u8* m_pData;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// [TODO]: this global internal stuff sux... the whole data should be inside the ES
|
|
||||||
// but this is the easiest way atm
|
|
||||||
extern std::vector<STileMetaContent> m_TileMetaContent;
|
|
||||||
extern u64 m_TitleID;
|
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "FileUtil.h"
|
#include "FileUtil.h"
|
||||||
#include "StringUtil.h"
|
#include "StringUtil.h"
|
||||||
#include "CDUtils.h"
|
#include "CDUtils.h"
|
||||||
|
#include "NANDContentLoader.h"
|
||||||
|
|
||||||
#include "VolumeCreator.h" // DiscIO
|
#include "VolumeCreator.h" // DiscIO
|
||||||
|
|
||||||
@ -126,14 +127,6 @@ bool SCoreStartupParameter::AutoSetup(EBootBios _BootBios)
|
|||||||
m_BootType = BOOT_ELF;
|
m_BootType = BOOT_ELF;
|
||||||
bNTSC = true;
|
bNTSC = true;
|
||||||
}
|
}
|
||||||
else if ((!strcasecmp(Extension.c_str(), ".wad")) &&
|
|
||||||
CBoot::IsWiiWAD(m_strFilename.c_str()))
|
|
||||||
{
|
|
||||||
bWii = true;
|
|
||||||
Region = EUR_DIR;
|
|
||||||
m_BootType = BOOT_WIIWAD;
|
|
||||||
bNTSC = false;
|
|
||||||
}
|
|
||||||
else if (!strcasecmp(Extension.c_str(), ".dol"))
|
else if (!strcasecmp(Extension.c_str(), ".dol"))
|
||||||
{
|
{
|
||||||
bWii = CDolLoader::IsDolWii(m_strFilename.c_str());
|
bWii = CDolLoader::IsDolWii(m_strFilename.c_str());
|
||||||
@ -141,6 +134,13 @@ bool SCoreStartupParameter::AutoSetup(EBootBios _BootBios)
|
|||||||
m_BootType = BOOT_DOL;
|
m_BootType = BOOT_DOL;
|
||||||
bNTSC = true;
|
bNTSC = true;
|
||||||
}
|
}
|
||||||
|
else if (DiscIO::CNANDContentLoader(m_strFilename).IsValid())
|
||||||
|
{
|
||||||
|
bWii = true;
|
||||||
|
Region = EUR_DIR;
|
||||||
|
m_BootType = BOOT_WII_NAND;
|
||||||
|
bNTSC = false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PanicAlert("Could not recognize ISO file %s", m_strFilename.c_str());
|
PanicAlert("Could not recognize ISO file %s", m_strFilename.c_str());
|
||||||
|
@ -90,7 +90,7 @@ struct SCoreStartupParameter
|
|||||||
BOOT_ISO,
|
BOOT_ISO,
|
||||||
BOOT_ELF,
|
BOOT_ELF,
|
||||||
BOOT_DOL,
|
BOOT_DOL,
|
||||||
BOOT_WIIWAD,
|
BOOT_WII_NAND,
|
||||||
BOOT_BIOS
|
BOOT_BIOS
|
||||||
};
|
};
|
||||||
EBootType m_BootType;
|
EBootType m_BootType;
|
||||||
|
@ -44,30 +44,45 @@ void HLE_OSReport()
|
|||||||
{
|
{
|
||||||
std::string ReportMessage;
|
std::string ReportMessage;
|
||||||
GetStringVA(ReportMessage);
|
GetStringVA(ReportMessage);
|
||||||
|
NPC = LR;
|
||||||
|
|
||||||
|
u32 hackPC = PC;
|
||||||
|
PC = LR;
|
||||||
|
|
||||||
// PanicAlert("(PC=%08x) OSReport: %s", LR, ReportMessage.c_str());
|
PanicAlert("(PC=%08x) OSReport: %s", LR, ReportMessage.c_str());
|
||||||
|
LOGV(OSREPORT,0,"(PC=%08x) OSReport: %s", LR, ReportMessage.c_str());
|
||||||
|
|
||||||
LOG(OSREPORT,"(PC=%08x) OSReport: %s", LR, ReportMessage.c_str());
|
PC = hackPC;
|
||||||
NPC = LR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HLE_vprintf()
|
void HLE_vprintf()
|
||||||
{
|
{
|
||||||
std::string ReportMessage;
|
std::string ReportMessage;
|
||||||
GetStringVA(ReportMessage);
|
GetStringVA(ReportMessage);
|
||||||
|
NPC = LR;
|
||||||
|
|
||||||
LOG(OSREPORT,"(PC=%08x) VPrintf: %s", LR, ReportMessage.c_str());
|
u32 hackPC = PC;
|
||||||
NPC = LR;
|
PC = LR;
|
||||||
|
|
||||||
|
PanicAlert("(PC=%08x) VPrintf: %s", LR, ReportMessage.c_str());
|
||||||
|
LOG(OSREPORT,"(PC=%08x) VPrintf: %s", LR, ReportMessage.c_str());
|
||||||
|
|
||||||
|
PC = hackPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HLE_printf()
|
void HLE_printf()
|
||||||
{
|
{
|
||||||
std::string ReportMessage;
|
std::string ReportMessage;
|
||||||
GetStringVA(ReportMessage);
|
GetStringVA(ReportMessage);
|
||||||
|
NPC = LR;
|
||||||
|
|
||||||
LOG(OSREPORT,"(PC=%08x) Printf: %s ", LR, ReportMessage.c_str());
|
u32 hackPC = PC;
|
||||||
NPC = LR;
|
PC = LR;
|
||||||
|
|
||||||
|
PanicAlert("(PC=%08x) Printf: %s ", LR, ReportMessage.c_str());
|
||||||
|
LOG(OSREPORT,"(PC=%08x) Printf: %s ", LR, ReportMessage.c_str());
|
||||||
|
|
||||||
|
PC = hackPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetStringVA(std::string& _rOutBuffer)
|
void GetStringVA(std::string& _rOutBuffer)
|
||||||
|
@ -173,12 +173,13 @@ void AudioFifoCallback(u64 userdata, int cyclesLate)
|
|||||||
|
|
||||||
void IPC_HLE_UpdateCallback(u64 userdata, int cyclesLate)
|
void IPC_HLE_UpdateCallback(u64 userdata, int cyclesLate)
|
||||||
{
|
{
|
||||||
WII_IPC_HLE_Interface::Update();
|
WII_IPC_HLE_Interface::UpdateDevices();
|
||||||
CoreTiming::ScheduleEvent(IPC_HLE_PERIOD-cyclesLate, et_IPC_HLE);
|
CoreTiming::ScheduleEvent(IPC_HLE_PERIOD-cyclesLate, et_IPC_HLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VICallback(u64 userdata, int cyclesLate)
|
void VICallback(u64 userdata, int cyclesLate)
|
||||||
{
|
{
|
||||||
|
WII_IPC_HLE_Interface::Update();
|
||||||
VideoInterface::Update();
|
VideoInterface::Update();
|
||||||
CoreTiming::ScheduleEvent(VI_PERIOD-cyclesLate, et_VI);
|
CoreTiming::ScheduleEvent(VI_PERIOD-cyclesLate, et_VI);
|
||||||
}
|
}
|
||||||
@ -212,6 +213,9 @@ void DecrementerSet()
|
|||||||
|
|
||||||
void AdvanceCallback(int cyclesExecuted)
|
void AdvanceCallback(int cyclesExecuted)
|
||||||
{
|
{
|
||||||
|
if (PowerPC::GetState() != PowerPC::CPU_RUNNING)
|
||||||
|
return;
|
||||||
|
|
||||||
fakeDec -= cyclesExecuted;
|
fakeDec -= cyclesExecuted;
|
||||||
u64 timebase_ticks = CoreTiming::GetTicks() / TIMER_RATIO; //works since we are little endian and TL comes first :)
|
u64 timebase_ticks = CoreTiming::GetTicks() / TIMER_RATIO; //works since we are little endian and TL comes first :)
|
||||||
*(u64*)&TL = timebase_ticks + startTimeBaseTicks;
|
*(u64*)&TL = timebase_ticks + startTimeBaseTicks;
|
||||||
|
@ -38,8 +38,13 @@ void HWCALL Read32(u32& _rReturnValue, const u32 _Address)
|
|||||||
{
|
{
|
||||||
// NAND Loader ... no idea
|
// NAND Loader ... no idea
|
||||||
case 0x018:
|
case 0x018:
|
||||||
LOGV(WII_IOB, 0, "IOP: Read32 from 0x18 = 0x%08x", _Address);
|
LOGV(WII_IOB, 0, "IOP: Read32 from 0x18 = 0x%08x (NANDLoader)", _Address);
|
||||||
break;
|
break;
|
||||||
|
// WiiMenu... no idea
|
||||||
|
case 0x24:
|
||||||
|
LOGV(WII_IOB, 0, "IOP: Read32 from 0x18 = 0x%08x (WiiMenu)", _Address);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 0xc0: // __VISendI2CData
|
case 0xc0: // __VISendI2CData
|
||||||
_rReturnValue = 0;
|
_rReturnValue = 0;
|
||||||
@ -96,9 +101,13 @@ void HWCALL Write32(const u32 _Value, const u32 _Address)
|
|||||||
{
|
{
|
||||||
switch(_Address & 0xFFFF)
|
switch(_Address & 0xFFFF)
|
||||||
{
|
{
|
||||||
// NAND Loader ... no idea
|
// NANDLoader ... no idea
|
||||||
case 0x18:
|
case 0x18:
|
||||||
LOGV(WII_IOB, 0, "IOP: Write32 0x%08x to 0x%08x", _Value, _Address);
|
LOGV(WII_IOB, 0, "IOP: Write32 0x%08x to 0x%08x (NANDLoader)", _Value, _Address);
|
||||||
|
break;
|
||||||
|
// WiiMenu... no idea
|
||||||
|
case 0x24:
|
||||||
|
LOGV(WII_IOB, 0, "IOP: Write32 0x%08x to 0x%08x (WiiMenu)", _Value, _Address);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xc0: // __VISendI2CData
|
case 0xc0: // __VISendI2CData
|
||||||
|
@ -78,6 +78,8 @@ u32 g_AckNumber = 0;
|
|||||||
std::queue<std::pair<u32,std::string> > g_ReplyQueue;
|
std::queue<std::pair<u32,std::string> > g_ReplyQueue;
|
||||||
void ExecuteCommand(u32 _Address);
|
void ExecuteCommand(u32 _Address);
|
||||||
|
|
||||||
|
std::string g_DefaultContentFile;
|
||||||
|
|
||||||
// General IPC functions
|
// General IPC functions
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
@ -99,7 +101,7 @@ void Reset()
|
|||||||
g_ReplyQueue.pop();
|
g_ReplyQueue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_Ack.clear();
|
g_Ack.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
@ -107,6 +109,13 @@ void Shutdown()
|
|||||||
Reset();
|
Reset();
|
||||||
g_LastDeviceID = 0x13370000;
|
g_LastDeviceID = 0x13370000;
|
||||||
g_AckNumber = 0;
|
g_AckNumber = 0;
|
||||||
|
g_DefaultContentFile.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set default content file
|
||||||
|
void SetDefaultContentFile(const std::string& _rFilename)
|
||||||
|
{
|
||||||
|
g_DefaultContentFile = _rFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetDeviceIDByName(const std::string& _rDeviceName)
|
u32 GetDeviceIDByName(const std::string& _rDeviceName)
|
||||||
@ -185,7 +194,7 @@ IWII_IPC_HLE_Device* CreateDevice(u32 _DeviceID, const std::string& _rDeviceName
|
|||||||
}
|
}
|
||||||
else if (_rDeviceName.c_str() == std::string("/dev/es"))
|
else if (_rDeviceName.c_str() == std::string("/dev/es"))
|
||||||
{
|
{
|
||||||
pDevice = new CWII_IPC_HLE_Device_es(_DeviceID, _rDeviceName);
|
pDevice = new CWII_IPC_HLE_Device_es(_DeviceID, _rDeviceName, g_DefaultContentFile);
|
||||||
}
|
}
|
||||||
else if (_rDeviceName.find("/dev/usb/oh1/57e/305") != std::string::npos)
|
else if (_rDeviceName.find("/dev/usb/oh1/57e/305") != std::string::npos)
|
||||||
{
|
{
|
||||||
@ -463,22 +472,28 @@ void ExecuteCommand(u32 _Address)
|
|||||||
/* This is called continuously from SystemTimers.cpp and WII_IPCInterface::IsReady()
|
/* This is called continuously from SystemTimers.cpp and WII_IPCInterface::IsReady()
|
||||||
is controlled from WII_IPC.cpp. */
|
is controlled from WII_IPC.cpp. */
|
||||||
// ----------------
|
// ----------------
|
||||||
|
void UpdateDevices()
|
||||||
|
{
|
||||||
|
if (WII_IPCInterface::IsReady())
|
||||||
|
{
|
||||||
|
// check if an executed must be updated
|
||||||
|
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
|
||||||
|
while(itr != g_DeviceMap.end())
|
||||||
|
{
|
||||||
|
u32 CommandAddr = itr->second->Update();
|
||||||
|
if (CommandAddr != 0)
|
||||||
|
{
|
||||||
|
g_ReplyQueue.push(std::pair<u32, std::string>(CommandAddr, itr->second->GetDeviceName()));
|
||||||
|
}
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (WII_IPCInterface::IsReady())
|
if (WII_IPCInterface::IsReady())
|
||||||
{
|
{
|
||||||
// check if an executed must be updated
|
|
||||||
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
|
|
||||||
while(itr != g_DeviceMap.end())
|
|
||||||
{
|
|
||||||
u32 CommandAddr = itr->second->Update();
|
|
||||||
if (CommandAddr != 0)
|
|
||||||
{
|
|
||||||
g_ReplyQueue.push(std::pair<u32, std::string>(CommandAddr, itr->second->GetDeviceName()));
|
|
||||||
}
|
|
||||||
++itr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we have to execute an acknowledge command...
|
// Check if we have to execute an acknowledge command...
|
||||||
if (!g_ReplyQueue.empty())
|
if (!g_ReplyQueue.empty())
|
||||||
{
|
{
|
||||||
|
@ -30,9 +30,15 @@ void Shutdown();
|
|||||||
// Reset
|
// Reset
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
|
// Set default content file
|
||||||
|
void SetDefaultContentFile(const std::string& _rFilename);
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
// Update Devices
|
||||||
|
void UpdateDevices();
|
||||||
|
|
||||||
// Acknowledge command
|
// Acknowledge command
|
||||||
bool AckCommand(u32 _Address);
|
bool AckCommand(u32 _Address);
|
||||||
|
|
||||||
|
@ -200,10 +200,9 @@ CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
|
|||||||
|
|
||||||
if (m_pFileHandle)
|
if (m_pFileHandle)
|
||||||
{
|
{
|
||||||
fwrite(Memory::GetPointer(Address), Size, 1, m_pFileHandle);
|
size_t Result = fwrite(Memory::GetPointer(Address), Size, 1, m_pFileHandle);
|
||||||
|
_dbg_assert_msg_(WII_IPC_FILEIO, Result == 1, "fwrite failed");
|
||||||
// Write always return the written bytes for success
|
ReturnValue = Size;
|
||||||
ReturnValue = Size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);
|
Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);
|
||||||
|
@ -164,6 +164,10 @@ s32 CWII_IPC_HLE_Device_net_kd_request::ExecuteCommand(u32 _Parameter, u32 _Buff
|
|||||||
case IOCTL_NWC24_STARTUP:
|
case IOCTL_NWC24_STARTUP:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case IOCTL_SO_GETSOCKOPT: // WiiMenu
|
||||||
|
case IOCTL_SO_SETSOCKOPT:
|
||||||
|
return 0;
|
||||||
|
|
||||||
case 0xf: // NWC24iRequestGenerateUserId (Input: none, Output: 32 bytes)
|
case 0xf: // NWC24iRequestGenerateUserId (Input: none, Output: 32 bytes)
|
||||||
//Memory::Write_U32(0, _BufferOut);
|
//Memory::Write_U32(0, _BufferOut);
|
||||||
return -1;
|
return -1;
|
||||||
@ -209,6 +213,15 @@ bool CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(u32 _CommandAddress)
|
|||||||
|
|
||||||
switch (CommandBuffer.Parameter)
|
switch (CommandBuffer.Parameter)
|
||||||
{
|
{
|
||||||
|
// WiiMenu
|
||||||
|
case 0x03:
|
||||||
|
case 0x04:
|
||||||
|
case 0x05:
|
||||||
|
case 0x06:
|
||||||
|
case 0x07:
|
||||||
|
case 0x08:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG(WII_IPC_NET, "NET_NCD_MANAGE IOCtlV: %i", CommandBuffer.Parameter);
|
LOG(WII_IPC_NET, "NET_NCD_MANAGE IOCtlV: %i", CommandBuffer.Parameter);
|
||||||
_dbg_assert_msg_(WII_IPC_NET, 0, "NET_NCD_MANAGE IOCtlV: %i", CommandBuffer.Parameter);
|
_dbg_assert_msg_(WII_IPC_NET, 0, "NET_NCD_MANAGE IOCtlV: %i", CommandBuffer.Parameter);
|
||||||
|
@ -1147,6 +1147,18 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="NAND"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Src\NANDContentLoader.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Src\NANDContentLoader.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Src\SConscript"
|
RelativePath=".\Src\SConscript"
|
||||||
>
|
>
|
||||||
|
282
Source/Core/DiscIO/Src/NANDContentLoader.cpp
Normal file
282
Source/Core/DiscIO/Src/NANDContentLoader.cpp
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
// Copyright (C) 2003-2008 Dolphin Project.
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 2.0.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License 2.0 for more details.
|
||||||
|
|
||||||
|
// A copy of the GPL 2.0 should have been included with the program.
|
||||||
|
// If not, see http://www.gnu.org/licenses/
|
||||||
|
|
||||||
|
// Official SVN repository and contact information can be found at
|
||||||
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "NANDContentLoader.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "AES/aes.h"
|
||||||
|
#include "MathUtil.h"
|
||||||
|
#include "FileUtil.h"
|
||||||
|
|
||||||
|
namespace DiscIO
|
||||||
|
{
|
||||||
|
|
||||||
|
class CBlobBigEndianReader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CBlobBigEndianReader(DiscIO::IBlobReader& _rReader) : m_rReader(_rReader) {}
|
||||||
|
|
||||||
|
u32 Read32(u64 _Offset)
|
||||||
|
{
|
||||||
|
u32 Temp;
|
||||||
|
m_rReader.Read(_Offset, 4, (u8*)&Temp);
|
||||||
|
return(Common::swap32(Temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DiscIO::IBlobReader& m_rReader;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CNANDContentLoader::CNANDContentLoader(const std::string& _rName)
|
||||||
|
: m_TitleID(-1)
|
||||||
|
, m_BootIndex(-1)
|
||||||
|
, m_Valid(false)
|
||||||
|
{
|
||||||
|
if (File::IsDirectory(_rName.c_str()))
|
||||||
|
{
|
||||||
|
m_Valid = CreateFromDirectory(_rName);
|
||||||
|
}
|
||||||
|
else if (File::Exists(_rName.c_str()))
|
||||||
|
{
|
||||||
|
m_Valid = CreateFromWAD(_rName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// _dbg_assert_msg_(BOOT, 0, "CNANDContentLoader loads neither folder nor file");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SNANDContent* CNANDContentLoader::GetContentByIndex(int _Index)
|
||||||
|
{
|
||||||
|
for (size_t i=0; i<m_TileMetaContent.size(); i++)
|
||||||
|
{
|
||||||
|
if (m_TileMetaContent[i].m_Index == _Index)
|
||||||
|
return &m_TileMetaContent[i];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CNANDContentLoader::CreateFromWAD(const std::string& _rName)
|
||||||
|
{
|
||||||
|
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rName.c_str());
|
||||||
|
if (pReader == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!ParseWAD(*pReader))
|
||||||
|
{
|
||||||
|
delete pReader;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
delete pReader;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool CNANDContentLoader::CreateFromDirectory(const std::string& _rPath)
|
||||||
|
{
|
||||||
|
std::string TMDFileName(_rPath);
|
||||||
|
TMDFileName += "/title.tmd";
|
||||||
|
|
||||||
|
FILE* pTMDFile = fopen(TMDFileName.c_str(), "rb");
|
||||||
|
if (pTMDFile == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
u64 Size = File::GetSize(TMDFileName.c_str());
|
||||||
|
u8* pTMD = new u8[Size];
|
||||||
|
fread(pTMD, Size, 1, pTMDFile);
|
||||||
|
fclose(pTMDFile);
|
||||||
|
|
||||||
|
//////
|
||||||
|
u32 numEntries = Common::swap16(pTMD + 0x01de);
|
||||||
|
m_BootIndex = Common::swap16(pTMD + 0x01e0);
|
||||||
|
m_TitleID = Common::swap64(pTMD + 0x018C);
|
||||||
|
|
||||||
|
|
||||||
|
m_TileMetaContent.resize(numEntries);
|
||||||
|
|
||||||
|
for (u32 i=0; i<numEntries; i++)
|
||||||
|
{
|
||||||
|
SNANDContent& rContent = m_TileMetaContent[i];
|
||||||
|
|
||||||
|
rContent.m_ContentID = Common::swap32(pTMD + 0x01e4 + 0x24*i);
|
||||||
|
rContent.m_Index = Common::swap16(pTMD + 0x01e8 + 0x24*i);
|
||||||
|
rContent.m_Type = Common::swap16(pTMD + 0x01ea + 0x24*i);
|
||||||
|
rContent.m_Size= (u32)Common::swap64(pTMD + 0x01ec + 0x24*i);
|
||||||
|
rContent.m_pData = NULL;
|
||||||
|
|
||||||
|
char szFilename[1024];
|
||||||
|
sprintf(szFilename, "%s\\%08x.app", _rPath.c_str(), rContent.m_ContentID);
|
||||||
|
|
||||||
|
FILE* pFile = fopen(szFilename, "rb");
|
||||||
|
// i have seen TMD which index to app which doesn't exist...
|
||||||
|
if (pFile != NULL)
|
||||||
|
{
|
||||||
|
u64 Size = File::GetSize(szFilename);
|
||||||
|
rContent.m_pData = new u8[Size];
|
||||||
|
|
||||||
|
_dbg_assert_msg_(BOOT, rContent.m_Size==Size, "TMDLoader: Filesize doesnt fit (%s %i)", szFilename, i);
|
||||||
|
|
||||||
|
fread(rContent.m_pData, Size, 1, pFile);
|
||||||
|
fclose(pFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CNANDContentLoader::IsWiiWAD(const std::string& _rName)
|
||||||
|
{
|
||||||
|
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rName.c_str());
|
||||||
|
if (pReader == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CBlobBigEndianReader Reader(*pReader);
|
||||||
|
bool Result = false;
|
||||||
|
|
||||||
|
// check for wii wad
|
||||||
|
if (Reader.Read32(0x00) == 0x20)
|
||||||
|
{
|
||||||
|
u32 WADTYpe = Reader.Read32(0x04);
|
||||||
|
switch(WADTYpe)
|
||||||
|
{
|
||||||
|
case 0x49730000:
|
||||||
|
case 0x69620000:
|
||||||
|
Result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete pReader;
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void CNANDContentLoader::AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest)
|
||||||
|
{
|
||||||
|
AES_KEY AESKey;
|
||||||
|
|
||||||
|
AES_set_decrypt_key(_pKey, 128, &AESKey);
|
||||||
|
AES_cbc_encrypt(_pSrc, _pDest, _Size, &AESKey, _IV, AES_DECRYPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
u8* CNANDContentLoader::CreateWADEntry(DiscIO::IBlobReader& _rReader, u32 _Size, u64 _Offset)
|
||||||
|
{
|
||||||
|
if (_Size > 0)
|
||||||
|
{
|
||||||
|
u8* pTmpBuffer = new u8[_Size];
|
||||||
|
_dbg_assert_msg_(BOOT, pTmpBuffer!=0, "WiiWAD: Cant allocate memory for WAD entry");
|
||||||
|
|
||||||
|
if (!_rReader.Read(_Offset, _Size, pTmpBuffer))
|
||||||
|
{
|
||||||
|
PanicAlert("WiiWAD: Could not read from file");
|
||||||
|
}
|
||||||
|
return pTmpBuffer;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNANDContentLoader::GetKeyFromTicket(u8* pTicket, u8* pTicketKey)
|
||||||
|
{
|
||||||
|
u8 CommonKey[16] = {0xeb,0xe4,0x2a,0x22,0x5e,0x85,0x93,0xe4,0x48,0xd9,0xc5,0x45,0x73,0x81,0xaa,0xf7};
|
||||||
|
u8 IV[16];
|
||||||
|
memset(IV, 0, sizeof IV);
|
||||||
|
memcpy(IV, pTicket + 0x01dc, 8);
|
||||||
|
AESDecode(CommonKey, IV, pTicket + 0x01bf, 16, pTicketKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CNANDContentLoader::ParseTMD(u8* pDataApp, u32 pDataAppSize, u8* pTicket, u8* pTMD)
|
||||||
|
{
|
||||||
|
u8 DecryptTitleKey[16];
|
||||||
|
u8 IV[16];
|
||||||
|
|
||||||
|
GetKeyFromTicket(pTicket, DecryptTitleKey);
|
||||||
|
|
||||||
|
u32 numEntries = Common::swap16(pTMD + 0x01de);
|
||||||
|
m_BootIndex = Common::swap16(pTMD + 0x01e0);
|
||||||
|
m_TitleID = Common::swap64(pTMD + 0x018C);
|
||||||
|
|
||||||
|
u8* p = pDataApp;
|
||||||
|
|
||||||
|
m_TileMetaContent.resize(numEntries);
|
||||||
|
|
||||||
|
for (u32 i=0; i<numEntries; i++)
|
||||||
|
{
|
||||||
|
SNANDContent& rContent = m_TileMetaContent[i];
|
||||||
|
|
||||||
|
rContent.m_ContentID = Common::swap32(pTMD + 0x01e4 + 0x24*i);
|
||||||
|
rContent.m_Index = Common::swap16(pTMD + 0x01e8 + 0x24*i);
|
||||||
|
rContent.m_Type = Common::swap16(pTMD + 0x01ea + 0x24*i);
|
||||||
|
rContent.m_Size= (u32)Common::swap64(pTMD + 0x01ec + 0x24*i);
|
||||||
|
|
||||||
|
u32 RoundedSize = ROUND_UP(rContent.m_Size, 0x40);
|
||||||
|
rContent.m_pData = new u8[RoundedSize];
|
||||||
|
|
||||||
|
memset(IV, 0, sizeof IV);
|
||||||
|
memcpy(IV, pTMD + 0x01e8 + 0x24*i, 2);
|
||||||
|
AESDecode(DecryptTitleKey, IV, p, RoundedSize, rContent.m_pData);
|
||||||
|
|
||||||
|
p += RoundedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CNANDContentLoader::ParseWAD(DiscIO::IBlobReader& _rReader)
|
||||||
|
{
|
||||||
|
CBlobBigEndianReader ReaderBig(_rReader);
|
||||||
|
|
||||||
|
// get header size
|
||||||
|
u32 HeaderSize = ReaderBig.Read32(0);
|
||||||
|
if (HeaderSize != 0x20)
|
||||||
|
{
|
||||||
|
_dbg_assert_msg_(BOOT, (HeaderSize==0x20), "WiiWAD: Header size != 0x20");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get header
|
||||||
|
u8 Header[0x20];
|
||||||
|
_rReader.Read(0, HeaderSize, Header);
|
||||||
|
u32 HeaderType = ReaderBig.Read32(0x4);
|
||||||
|
if ((0x49730000 != HeaderType) && (0x69620000 != HeaderType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
u32 CertificateChainSize = ReaderBig.Read32(0x8);
|
||||||
|
u32 Reserved = ReaderBig.Read32(0xC);
|
||||||
|
u32 TicketSize = ReaderBig.Read32(0x10);
|
||||||
|
u32 TMDSize = ReaderBig.Read32(0x14);
|
||||||
|
u32 DataAppSize = ReaderBig.Read32(0x18);
|
||||||
|
u32 FooterSize = ReaderBig.Read32(0x1C);
|
||||||
|
_dbg_assert_msg_(BOOT, Reserved==0x00, "WiiWAD: Reserved must be 0x00");
|
||||||
|
|
||||||
|
u32 Offset = 0x40;
|
||||||
|
u8* pCertificateChain = CreateWADEntry(_rReader, CertificateChainSize, Offset); Offset += ROUND_UP(CertificateChainSize, 0x40);
|
||||||
|
u8* pTicket = CreateWADEntry(_rReader, TicketSize, Offset); Offset += ROUND_UP(TicketSize, 0x40);
|
||||||
|
u8* pTMD = CreateWADEntry(_rReader, TMDSize, Offset); Offset += ROUND_UP(TMDSize, 0x40);
|
||||||
|
u8* pDataApp = CreateWADEntry(_rReader, DataAppSize, Offset); Offset += ROUND_UP(DataAppSize, 0x40);
|
||||||
|
u8* pFooter = CreateWADEntry(_rReader, FooterSize, Offset); Offset += ROUND_UP(FooterSize, 0x40);
|
||||||
|
|
||||||
|
bool Result = ParseTMD(pDataApp, DataAppSize, pTicket, pTMD);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
80
Source/Core/DiscIO/Src/NANDContentLoader.h
Normal file
80
Source/Core/DiscIO/Src/NANDContentLoader.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Copyright (C) 2003-2008 Dolphin Project.
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 2.0.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License 2.0 for more details.
|
||||||
|
|
||||||
|
// A copy of the GPL 2.0 should have been included with the program.
|
||||||
|
// If not, see http://www.gnu.org/licenses/
|
||||||
|
|
||||||
|
// Official SVN repository and contact information can be found at
|
||||||
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
|
||||||
|
#ifndef _NAND_CONTENT_LOADER_H
|
||||||
|
#define _NAND_CONTENT_LOADER_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "Common.h"
|
||||||
|
#include "Blob.h"
|
||||||
|
|
||||||
|
namespace DiscIO
|
||||||
|
{
|
||||||
|
|
||||||
|
struct SNANDContent
|
||||||
|
{
|
||||||
|
u32 m_ContentID;
|
||||||
|
u16 m_Index;
|
||||||
|
u16 m_Type;
|
||||||
|
u32 m_Size;
|
||||||
|
|
||||||
|
u8* m_pData;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CNANDContentLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
CNANDContentLoader(const std::string& _rName);
|
||||||
|
|
||||||
|
bool IsValid() const { return m_Valid; }
|
||||||
|
|
||||||
|
u64 GetTitleID() const { return m_TitleID; }
|
||||||
|
|
||||||
|
u32 GetBootIndex() const { return m_BootIndex; }
|
||||||
|
|
||||||
|
size_t GetContentSize() const { return m_TileMetaContent.size(); }
|
||||||
|
|
||||||
|
SNANDContent* GetContentByIndex(int _Index);
|
||||||
|
|
||||||
|
static bool IsWiiWAD(const std::string& _rName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool m_Valid;
|
||||||
|
u64 m_TitleID;
|
||||||
|
u32 m_BootIndex;
|
||||||
|
|
||||||
|
std::vector<SNANDContent> m_TileMetaContent;
|
||||||
|
|
||||||
|
bool CreateFromDirectory(const std::string& _rPath);
|
||||||
|
bool CreateFromWAD(const std::string& _rName);
|
||||||
|
|
||||||
|
bool ParseWAD(DiscIO::IBlobReader& _rReader);
|
||||||
|
|
||||||
|
void AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest);
|
||||||
|
|
||||||
|
u8* CreateWADEntry(DiscIO::IBlobReader& _rReader, u32 _Size, u64 _Offset);
|
||||||
|
|
||||||
|
void GetKeyFromTicket(u8* pTicket, u8* pTicketKey);
|
||||||
|
|
||||||
|
bool ParseTMD(u8* pDataApp, u32 pDataAppSize, u8* pTicket, u8* pTMD);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -255,6 +255,7 @@ EVT_MENU(IDM_CONFIG_DSP_PLUGIN, CFrame::OnPluginDSP)
|
|||||||
EVT_MENU(IDM_CONFIG_PAD_PLUGIN, CFrame::OnPluginPAD)
|
EVT_MENU(IDM_CONFIG_PAD_PLUGIN, CFrame::OnPluginPAD)
|
||||||
EVT_MENU(IDM_CONFIG_WIIMOTE_PLUGIN, CFrame::OnPluginWiimote)
|
EVT_MENU(IDM_CONFIG_WIIMOTE_PLUGIN, CFrame::OnPluginWiimote)
|
||||||
|
|
||||||
|
|
||||||
#ifdef MUSICMOD
|
#ifdef MUSICMOD
|
||||||
EVT_MENU(IDM_MUTE, CFrame::MM_OnMute)
|
EVT_MENU(IDM_MUTE, CFrame::MM_OnMute)
|
||||||
EVT_MENU(IDM_MUSIC_PLAY, CFrame::MM_OnPause)
|
EVT_MENU(IDM_MUSIC_PLAY, CFrame::MM_OnPause)
|
||||||
@ -267,11 +268,13 @@ EVT_MENU(IDM_MEMCARD, CFrame::OnMemcard)
|
|||||||
EVT_MENU(IDM_CHEATS, CFrame::OnShow_CheatsWindow)
|
EVT_MENU(IDM_CHEATS, CFrame::OnShow_CheatsWindow)
|
||||||
EVT_MENU(IDM_CHANGEDISC, CFrame::OnChangeDisc)
|
EVT_MENU(IDM_CHANGEDISC, CFrame::OnChangeDisc)
|
||||||
EVT_MENU(IDM_SDCARD, CFrame::OnShow_SDCardWindow)
|
EVT_MENU(IDM_SDCARD, CFrame::OnShow_SDCardWindow)
|
||||||
|
EVT_MENU(IDM_LOAD_WII_MENU, CFrame::OnLoadWiiMenu)
|
||||||
EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
|
EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
|
||||||
EVT_MENU(IDM_TOGGLE_DUALCORE, CFrame::OnToggleDualCore)
|
EVT_MENU(IDM_TOGGLE_DUALCORE, CFrame::OnToggleDualCore)
|
||||||
EVT_MENU(IDM_TOGGLE_SKIPIDLE, CFrame::OnToggleSkipIdle)
|
EVT_MENU(IDM_TOGGLE_SKIPIDLE, CFrame::OnToggleSkipIdle)
|
||||||
EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
|
EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
|
||||||
EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
|
EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
|
||||||
|
|
||||||
EVT_MENU_RANGE(IDM_LOADSLOT1, IDM_LOADSLOT10, CFrame::OnLoadState)
|
EVT_MENU_RANGE(IDM_LOADSLOT1, IDM_LOADSLOT10, CFrame::OnLoadState)
|
||||||
EVT_MENU_RANGE(IDM_SAVESLOT1, IDM_SAVESLOT10, CFrame::OnSaveState)
|
EVT_MENU_RANGE(IDM_SAVESLOT1, IDM_SAVESLOT10, CFrame::OnSaveState)
|
||||||
EVT_MENU_RANGE(IDM_DRIVE1, IDM_DRIVE24, CFrame::OnBootDrive)
|
EVT_MENU_RANGE(IDM_DRIVE1, IDM_DRIVE24, CFrame::OnBootDrive)
|
||||||
|
@ -207,6 +207,7 @@ class CFrame : public wxFrame
|
|||||||
void OnMemcard(wxCommandEvent& event); // Misc
|
void OnMemcard(wxCommandEvent& event); // Misc
|
||||||
void OnShow_CheatsWindow(wxCommandEvent& event);
|
void OnShow_CheatsWindow(wxCommandEvent& event);
|
||||||
void OnShow_SDCardWindow(wxCommandEvent& event);
|
void OnShow_SDCardWindow(wxCommandEvent& event);
|
||||||
|
void OnLoadWiiMenu(wxCommandEvent& event);
|
||||||
|
|
||||||
void OnGameListCtrl_ItemActivated(wxListEvent& event);
|
void OnGameListCtrl_ItemActivated(wxListEvent& event);
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ be accessed from Core::GetWindowHandle().
|
|||||||
#include "HW/DVDInterface.h"
|
#include "HW/DVDInterface.h"
|
||||||
#include "State.h"
|
#include "State.h"
|
||||||
#include "VolumeHandler.h"
|
#include "VolumeHandler.h"
|
||||||
|
#include "NANDContentLoader.h"
|
||||||
|
|
||||||
#include <wx/datetime.h> // wxWidgets
|
#include <wx/datetime.h> // wxWidgets
|
||||||
|
|
||||||
@ -159,6 +160,12 @@ void CFrame::CreateMenu()
|
|||||||
miscMenu->Append(IDM_MEMCARD, _T("&Memcard Manager"));
|
miscMenu->Append(IDM_MEMCARD, _T("&Memcard Manager"));
|
||||||
miscMenu->Append(IDM_CHEATS, _T("Action &Replay Manager"));
|
miscMenu->Append(IDM_CHEATS, _T("Action &Replay Manager"));
|
||||||
// miscMenu->Append(IDM_SDCARD, _T("Mount &SDCard")); // Disable for now
|
// miscMenu->Append(IDM_SDCARD, _T("Mount &SDCard")); // Disable for now
|
||||||
|
|
||||||
|
if (DiscIO::CNANDContentLoader(FULL_WII_MENU_DIR).IsValid())
|
||||||
|
{
|
||||||
|
miscMenu->Append(IDM_LOAD_WII_MENU, _T("Load Wii Menu"));
|
||||||
|
}
|
||||||
|
|
||||||
m_pMenuBar->Append(miscMenu, _T("&Misc"));
|
m_pMenuBar->Append(miscMenu, _T("&Misc"));
|
||||||
|
|
||||||
// Help menu
|
// Help menu
|
||||||
@ -675,6 +682,11 @@ void CFrame::OnShow_SDCardWindow(wxCommandEvent& WXUNUSED (event))
|
|||||||
wxSDCardWindow SDWindow(this);
|
wxSDCardWindow SDWindow(this);
|
||||||
SDWindow.ShowModal();
|
SDWindow.ShowModal();
|
||||||
}
|
}
|
||||||
|
void CFrame::OnLoadWiiMenu(wxCommandEvent& WXUNUSED (event))
|
||||||
|
{
|
||||||
|
BootManager::BootCore(FULL_WII_MENU_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
/* Toogle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover
|
/* Toogle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover
|
||||||
the entire screen (when we render to the main window). */
|
the entire screen (when we render to the main window). */
|
||||||
void CFrame::OnToggleFullscreen(wxCommandEvent& WXUNUSED (event))
|
void CFrame::OnToggleFullscreen(wxCommandEvent& WXUNUSED (event))
|
||||||
|
@ -62,6 +62,7 @@ enum
|
|||||||
IDM_CHANGEDISC,
|
IDM_CHANGEDISC,
|
||||||
IDM_PROPERTIES,
|
IDM_PROPERTIES,
|
||||||
IDM_SDCARD,
|
IDM_SDCARD,
|
||||||
|
IDM_LOAD_WII_MENU,
|
||||||
|
|
||||||
IDM_HELPABOUT, // Help menu
|
IDM_HELPABOUT, // Help menu
|
||||||
IDM_HELPWEBSITE,
|
IDM_HELPWEBSITE,
|
||||||
|
@ -69,6 +69,7 @@ IUCode* UCodeFactory(u32 _CRC, CMailHandler& _rMailHandler)
|
|||||||
// WII CRCs
|
// WII CRCs
|
||||||
case 0x6c3f6f94: // zelda - PAL
|
case 0x6c3f6f94: // zelda - PAL
|
||||||
case 0xd643001f: // mario galaxy - PAL
|
case 0xd643001f: // mario galaxy - PAL
|
||||||
|
case 0xd9c4bf34: // WiiMenu ... pray
|
||||||
Console::Print("Zelda Wii ucode chosen\n");
|
Console::Print("Zelda Wii ucode chosen\n");
|
||||||
return new CUCode_Zelda(_rMailHandler);
|
return new CUCode_Zelda(_rMailHandler);
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ IUCode* UCodeFactory(u32 _CRC, CMailHandler& _rMailHandler)
|
|||||||
case 0xfa450138: // wii sports - PAL
|
case 0xfa450138: // wii sports - PAL
|
||||||
case 0xadbc06bd: // Elebits
|
case 0xadbc06bd: // Elebits
|
||||||
case 0xb7eb9a9c: // Wii Pikmin - JAP
|
case 0xb7eb9a9c: // Wii Pikmin - JAP
|
||||||
case 0x4cc52064: // Bleach: Versus Crusade
|
case 0x4cc52064: // Bleach: Versus Crusade
|
||||||
Console::Print("Wii - AXWii chosen\n");
|
Console::Print("Wii - AXWii chosen\n");
|
||||||
return new CUCode_AXWii(_rMailHandler, _CRC);
|
return new CUCode_AXWii(_rMailHandler, _CRC);
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ void SendEvent(SEvent& _rEvent)
|
|||||||
g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset);
|
g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset);
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
ReadDebugging(false, Buffer, Offset);
|
// ReadDebugging(false, Buffer, Offset);
|
||||||
}
|
}
|
||||||
/////////////////////
|
/////////////////////
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user