// 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" #include "Log.h" namespace DiscIO { class CSharedContent { public: static CSharedContent& AccessInstance() { return m_Instance; } std::string GetFilenameFromSHA1(u8* _pHash); private: CSharedContent(); virtual ~CSharedContent(); struct SElement { u8 FileName[8]; u8 SHA1Hash[20]; }; std::vector m_Elements; static CSharedContent m_Instance; }; CSharedContent CSharedContent::m_Instance; CSharedContent::CSharedContent() { char szFilename[1024]; sprintf(szFilename, "%sshared1/content.map", FULL_WII_USER_DIR); if (File::Exists(szFilename)) { FILE* pFile = fopen(szFilename, "rb"); while(!feof(pFile)) { SElement Element; if (fread(&Element, sizeof(SElement), 1, pFile) == 1) { m_Elements.push_back(Element); } } } } CSharedContent::~CSharedContent() {} std::string CSharedContent::GetFilenameFromSHA1(u8* _pHash) { for (size_t i=0; i 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)) { ERROR_LOG(DISCIO, "WiiWAD: Could not read from file"); 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_Content.resize(numEntries); for (u32 i=0; i