// Copyright (C) 2003 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 #include #include "AES/aes.h" #include "MathUtil.h" #include "FileUtil.h" #include "Log.h" #include "WiiWad.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); } } fclose(pFile); } } CSharedContent::~CSharedContent() {} std::string CSharedContent::GetFilenameFromSHA1(u8* _pHash) { for (size_t i=0; i& GetContent() const { return m_Content; } const u16 GetTitleVersion() const {return m_TileVersion;} const u16 GetNumEntries() const {return m_numEntries;} const DiscIO::IVolume::ECountry GetCountry() const; private: bool m_Valid; u64 m_TitleID; u16 m_IosVersion; u32 m_BootIndex; u16 m_numEntries; u16 m_TileVersion; u8 m_TicketView[TICKET_VIEW_SIZE]; u8 m_TmdHeader[TMD_HEADER_SIZE]; std::vector m_Content; bool CreateFromDirectory(const std::string& _rPath); bool CreateFromWAD(const std::string& _rName); void AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest); void GetKeyFromTicket(u8* pTicket, u8* pTicketKey); bool ParseTMD(u8* pDataApp, u32 pDataAppSize, u8* pTicket, u8* pTMD); }; CNANDContentLoader::CNANDContentLoader(const std::string& _rName) : m_TitleID(-1) , m_BootIndex(-1) , m_Valid(false) , m_IosVersion(0x09) { 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"); } } CNANDContentLoader::~CNANDContentLoader() { for (size_t i=0; isecond; itr++; } m_Map.clear(); } const INANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& _rName) { std::string KeyString(_rName); std::transform(KeyString.begin(), KeyString.end(), KeyString.begin(), (int(*)(int)) toupper); CNANDContentMap::iterator itr = m_Map.find(KeyString); if (itr != m_Map.end()) return *itr->second; m_Map[KeyString] = new CNANDContentLoader(KeyString); return *m_Map[KeyString]; } } // namespace end