2018-07-27 22:55:23 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-07-29 18:00:09 -05:00
|
|
|
#include <array>
|
2018-09-03 20:58:19 -05:00
|
|
|
#include <memory>
|
2018-07-27 22:55:23 -05:00
|
|
|
#include <vector>
|
2018-07-29 18:00:09 -05:00
|
|
|
#include "common/common_types.h"
|
2018-07-27 22:55:23 -05:00
|
|
|
#include "common/swap.h"
|
2018-11-01 19:23:38 -05:00
|
|
|
#include "core/crypto/key_manager.h"
|
2018-07-27 22:55:23 -05:00
|
|
|
#include "core/file_sys/vfs.h"
|
2018-09-03 20:58:19 -05:00
|
|
|
|
|
|
|
namespace Loader {
|
|
|
|
enum class ResultStatus : u16;
|
|
|
|
}
|
2018-07-27 22:55:23 -05:00
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
2018-09-03 20:58:19 -05:00
|
|
|
class NCA;
|
|
|
|
enum class NCAContentType : u8;
|
2018-08-25 21:42:54 -05:00
|
|
|
class NSP;
|
2018-09-03 20:58:19 -05:00
|
|
|
|
2018-07-27 22:55:23 -05:00
|
|
|
enum class GamecardSize : u8 {
|
|
|
|
S_1GB = 0xFA,
|
|
|
|
S_2GB = 0xF8,
|
|
|
|
S_4GB = 0xF0,
|
|
|
|
S_8GB = 0xE0,
|
|
|
|
S_16GB = 0xE1,
|
|
|
|
S_32GB = 0xE2,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GamecardInfo {
|
2018-11-20 17:40:50 -06:00
|
|
|
u64_le firmware_version;
|
|
|
|
u32_le access_control_flags;
|
|
|
|
u32_le read_wait_time1;
|
|
|
|
u32_le read_wait_time2;
|
|
|
|
u32_le write_wait_time1;
|
|
|
|
u32_le write_wait_time2;
|
|
|
|
u32_le firmware_mode;
|
|
|
|
u32_le cup_version;
|
|
|
|
std::array<u8, 4> reserved1;
|
|
|
|
u64_le update_partition_hash;
|
|
|
|
u64_le cup_id;
|
|
|
|
std::array<u8, 0x38> reserved2;
|
2018-07-27 22:55:23 -05:00
|
|
|
};
|
|
|
|
static_assert(sizeof(GamecardInfo) == 0x70, "GamecardInfo has incorrect size.");
|
|
|
|
|
|
|
|
struct GamecardHeader {
|
|
|
|
std::array<u8, 0x100> signature;
|
|
|
|
u32_le magic;
|
|
|
|
u32_le secure_area_start;
|
|
|
|
u32_le backup_area_start;
|
|
|
|
u8 kek_index;
|
|
|
|
GamecardSize size;
|
|
|
|
u8 header_version;
|
|
|
|
u8 flags;
|
|
|
|
u64_le package_id;
|
|
|
|
u64_le valid_data_end;
|
|
|
|
u128 info_iv;
|
|
|
|
u64_le hfs_offset;
|
|
|
|
u64_le hfs_size;
|
|
|
|
std::array<u8, 0x20> hfs_header_hash;
|
|
|
|
std::array<u8, 0x20> initial_data_hash;
|
|
|
|
u32_le secure_mode_flag;
|
|
|
|
u32_le title_key_flag;
|
|
|
|
u32_le key_flag;
|
|
|
|
u32_le normal_area_end;
|
|
|
|
GamecardInfo info;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(GamecardHeader) == 0x200, "GamecardHeader has incorrect size.");
|
|
|
|
|
|
|
|
enum class XCIPartition : u8 { Update, Normal, Secure, Logo };
|
|
|
|
|
|
|
|
class XCI : public ReadOnlyVfsDirectory {
|
|
|
|
public:
|
|
|
|
explicit XCI(VirtualFile file);
|
2018-09-03 20:58:19 -05:00
|
|
|
~XCI() override;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
|
|
|
Loader::ResultStatus GetStatus() const;
|
2018-08-16 15:57:00 -05:00
|
|
|
Loader::ResultStatus GetProgramNCAStatus() const;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
2019-09-22 20:50:29 -05:00
|
|
|
u8 GetFormatVersion();
|
|
|
|
|
|
|
|
VirtualDir GetPartition(XCIPartition partition);
|
|
|
|
std::vector<VirtualDir> GetPartitions();
|
2018-07-27 22:55:23 -05:00
|
|
|
|
2018-08-25 10:48:23 -05:00
|
|
|
std::shared_ptr<NSP> GetSecurePartitionNSP() const;
|
2019-09-22 20:50:29 -05:00
|
|
|
VirtualDir GetSecurePartition();
|
|
|
|
VirtualDir GetNormalPartition();
|
|
|
|
VirtualDir GetUpdatePartition();
|
|
|
|
VirtualDir GetLogoPartition();
|
|
|
|
|
2019-09-22 20:51:46 -05:00
|
|
|
VirtualFile GetPartitionRaw(XCIPartition partition) const;
|
|
|
|
VirtualFile GetSecurePartitionRaw() const;
|
|
|
|
VirtualFile GetStoragePartition0() const;
|
|
|
|
VirtualFile GetStoragePartition1() const;
|
|
|
|
VirtualFile GetNormalPartitionRaw() const;
|
|
|
|
VirtualFile GetUpdatePartitionRaw() const;
|
|
|
|
VirtualFile GetLogoPartitionRaw() const;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
2018-09-03 17:47:23 -05:00
|
|
|
u64 GetProgramTitleID() const;
|
2019-04-10 11:12:49 -05:00
|
|
|
u32 GetSystemUpdateVersion();
|
|
|
|
u64 GetSystemUpdateTitleID() const;
|
2018-09-03 17:47:23 -05:00
|
|
|
|
2018-10-16 10:36:55 -05:00
|
|
|
bool HasProgramNCA() const;
|
2018-08-25 10:48:23 -05:00
|
|
|
VirtualFile GetProgramNCAFile() const;
|
2018-08-09 19:51:14 -05:00
|
|
|
const std::vector<std::shared_ptr<NCA>>& GetNCAs() const;
|
2018-07-27 22:55:23 -05:00
|
|
|
std::shared_ptr<NCA> GetNCAByType(NCAContentType type) const;
|
|
|
|
VirtualFile GetNCAFileByType(NCAContentType type) const;
|
|
|
|
|
2018-08-12 02:57:06 -05:00
|
|
|
std::vector<VirtualFile> GetFiles() const override;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
2018-08-12 02:57:06 -05:00
|
|
|
std::vector<VirtualDir> GetSubdirectories() const override;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
|
|
|
std::string GetName() const override;
|
|
|
|
|
2018-08-12 02:57:06 -05:00
|
|
|
VirtualDir GetParentDirectory() const override;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
2019-04-10 11:13:27 -05:00
|
|
|
// Creates a directory that contains all the NCAs in the gamecard
|
|
|
|
VirtualDir ConcatenatedPseudoDirectory();
|
|
|
|
|
|
|
|
std::array<u8, 0x200> GetCertificate() const;
|
|
|
|
|
2018-07-27 22:55:23 -05:00
|
|
|
private:
|
|
|
|
Loader::ResultStatus AddNCAFromPartition(XCIPartition part);
|
|
|
|
|
|
|
|
VirtualFile file;
|
|
|
|
GamecardHeader header{};
|
|
|
|
|
|
|
|
Loader::ResultStatus status;
|
2018-08-16 15:57:00 -05:00
|
|
|
Loader::ResultStatus program_nca_status;
|
2018-07-27 22:55:23 -05:00
|
|
|
|
|
|
|
std::vector<VirtualDir> partitions;
|
2019-09-22 20:50:29 -05:00
|
|
|
std::vector<VirtualFile> partitions_raw;
|
2018-08-25 10:48:23 -05:00
|
|
|
std::shared_ptr<NSP> secure_partition;
|
|
|
|
std::shared_ptr<NCA> program;
|
2018-07-27 22:55:23 -05:00
|
|
|
std::vector<std::shared_ptr<NCA>> ncas;
|
2018-11-01 19:23:38 -05:00
|
|
|
|
2019-04-10 11:12:49 -05:00
|
|
|
u64 update_normal_partition_end;
|
|
|
|
|
2020-06-30 23:28:49 -05:00
|
|
|
Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance();
|
2018-07-27 22:55:23 -05:00
|
|
|
};
|
|
|
|
} // namespace FileSys
|