2018-08-16 14:08:13 -07:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/swap.h"
|
2018-08-24 19:15:32 -07:00
|
|
|
#include "core/crypto/key_manager.h"
|
2018-08-16 14:08:13 -07:00
|
|
|
#include "core/file_sys/vfs.h"
|
2020-08-23 11:20:37 -07:00
|
|
|
|
|
|
|
namespace Loader {
|
|
|
|
enum class ResultStatus : u16;
|
|
|
|
}
|
2018-08-16 14:08:13 -07:00
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
2020-08-23 11:20:37 -07:00
|
|
|
class NCA;
|
|
|
|
|
2018-08-16 14:08:13 -07:00
|
|
|
struct NAXHeader {
|
|
|
|
std::array<u8, 0x20> hmac;
|
|
|
|
u64_le magic;
|
|
|
|
std::array<Core::Crypto::Key128, 2> key_area;
|
|
|
|
u64_le file_size;
|
|
|
|
INSERT_PADDING_BYTES(0x30);
|
|
|
|
};
|
|
|
|
static_assert(sizeof(NAXHeader) == 0x80, "NAXHeader has incorrect size.");
|
|
|
|
|
|
|
|
enum class NAXContentType : u8 {
|
|
|
|
Save = 0,
|
|
|
|
NCA = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
class NAX : public ReadOnlyVfsDirectory {
|
|
|
|
public:
|
|
|
|
explicit NAX(VirtualFile file);
|
|
|
|
explicit NAX(VirtualFile file, std::array<u8, 0x10> nca_id);
|
2018-09-19 16:19:05 -07:00
|
|
|
~NAX() override;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
2018-08-18 18:14:57 -07:00
|
|
|
Loader::ResultStatus GetStatus() const;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
2018-08-18 18:14:57 -07:00
|
|
|
VirtualFile GetDecrypted() const;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
2018-09-19 11:16:22 -07:00
|
|
|
std::unique_ptr<NCA> AsNCA() const;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
2018-08-18 18:14:57 -07:00
|
|
|
NAXContentType GetContentType() const;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
2020-12-09 22:31:58 -08:00
|
|
|
std::vector<VirtualFile> GetFiles() const override;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
2020-12-09 22:31:58 -08:00
|
|
|
std::vector<VirtualDir> GetSubdirectories() const override;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
|
|
|
std::string GetName() const override;
|
|
|
|
|
2020-12-09 22:31:58 -08:00
|
|
|
VirtualDir GetParentDirectory() const override;
|
2018-08-16 14:08:13 -07:00
|
|
|
|
|
|
|
private:
|
2018-08-18 18:14:57 -07:00
|
|
|
Loader::ResultStatus Parse(std::string_view path);
|
2018-08-16 14:08:13 -07:00
|
|
|
|
|
|
|
std::unique_ptr<NAXHeader> header;
|
|
|
|
|
|
|
|
VirtualFile file;
|
|
|
|
Loader::ResultStatus status;
|
2018-09-19 10:46:32 -07:00
|
|
|
NAXContentType type{};
|
2018-08-16 14:08:13 -07:00
|
|
|
|
|
|
|
VirtualFile dec_file;
|
|
|
|
|
2020-08-23 11:20:37 -07:00
|
|
|
Core::Crypto::KeyManager& keys;
|
2018-08-16 14:08:13 -07:00
|
|
|
};
|
|
|
|
} // namespace FileSys
|