2016-07-06 18:33:05 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
2017-05-19 16:33:21 +00:00
|
|
|
#include <memory>
|
2017-06-04 08:33:14 +00:00
|
|
|
#include <optional>
|
2016-07-06 18:33:05 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/StringUtil.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
|
2017-05-19 16:33:21 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2017-05-19 16:33:21 +00:00
|
|
|
#include "DiscIO/VolumeGC.h"
|
|
|
|
#include "DiscIO/VolumeWad.h"
|
2017-06-06 09:49:01 +00:00
|
|
|
#include "DiscIO/VolumeWii.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
const IOS::ES::TicketReader Volume::INVALID_TICKET{};
|
|
|
|
const IOS::ES::TMDReader Volume::INVALID_TMD{};
|
2019-03-21 22:04:44 +00:00
|
|
|
const std::vector<u8> Volume::INVALID_CERT_CHAIN{};
|
2017-05-20 16:33:36 +00:00
|
|
|
|
2017-11-02 20:05:37 +00:00
|
|
|
std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>& data)
|
2016-07-06 18:33:05 +00:00
|
|
|
{
|
|
|
|
std::map<Language, std::string> names;
|
|
|
|
for (size_t i = 0; i < NUMBER_OF_LANGUAGES; ++i)
|
|
|
|
{
|
2017-11-02 20:05:37 +00:00
|
|
|
const size_t name_start = NAME_CHARS_LENGTH * i;
|
|
|
|
if (name_start + NAME_CHARS_LENGTH <= data.size())
|
2016-07-06 18:33:05 +00:00
|
|
|
{
|
2017-11-02 20:05:37 +00:00
|
|
|
const std::string name = UTF16BEToUTF8(data.data() + name_start, NAME_CHARS_LENGTH);
|
2016-07-06 18:33:05 +00:00
|
|
|
if (!name.empty())
|
|
|
|
names[static_cast<Language>(i)] = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
2017-05-19 16:33:21 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<Volume> CreateVolumeFromFilename(const std::string& filename)
|
2017-05-19 16:33:21 +00:00
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<BlobReader> reader(CreateBlobReader(filename));
|
2017-05-19 16:33:21 +00:00
|
|
|
if (reader == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Check for Wii
|
2017-06-04 08:33:14 +00:00
|
|
|
const std::optional<u32> wii_magic = reader->ReadSwapped<u32>(0x18);
|
|
|
|
if (wii_magic == u32(0x5D1C9EA3))
|
2017-06-06 09:49:01 +00:00
|
|
|
return std::make_unique<VolumeWii>(std::move(reader));
|
2017-05-19 16:33:21 +00:00
|
|
|
|
|
|
|
// Check for WAD
|
|
|
|
// 0x206962 for boot2 wads
|
2017-06-04 08:33:14 +00:00
|
|
|
const std::optional<u32> wad_magic = reader->ReadSwapped<u32>(0x02);
|
|
|
|
if (wad_magic == u32(0x00204973) || wad_magic == u32(0x00206962))
|
2017-06-06 09:49:01 +00:00
|
|
|
return std::make_unique<VolumeWAD>(std::move(reader));
|
2017-05-19 16:33:21 +00:00
|
|
|
|
|
|
|
// Check for GC
|
2017-06-04 08:33:14 +00:00
|
|
|
const std::optional<u32> gc_magic = reader->ReadSwapped<u32>(0x1C);
|
|
|
|
if (gc_magic == u32(0xC2339F3D))
|
2017-06-06 09:49:01 +00:00
|
|
|
return std::make_unique<VolumeGC>(std::move(reader));
|
2017-05-19 16:33:21 +00:00
|
|
|
|
|
|
|
// No known magic words found
|
|
|
|
return nullptr;
|
2016-07-06 18:33:05 +00:00
|
|
|
}
|
2017-05-19 16:33:21 +00:00
|
|
|
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace DiscIO
|