summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/xts_archive.h
blob: 7589b7c386c993594045793b30f2c1b276bdb52e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <array>
#include <vector>
#include "common/common_types.h"
#include "common/swap.h"
#include "core/crypto/key_manager.h"
#include "core/file_sys/vfs/vfs.h"

namespace Loader {
enum class ResultStatus : u16;
}

namespace FileSys {

class NCA;

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);
    ~NAX() override;

    Loader::ResultStatus GetStatus() const;

    VirtualFile GetDecrypted() const;

    std::unique_ptr<NCA> AsNCA() const;

    NAXContentType GetContentType() const;

    std::vector<VirtualFile> GetFiles() const override;

    std::vector<VirtualDir> GetSubdirectories() const override;

    std::string GetName() const override;

    VirtualDir GetParentDirectory() const override;

private:
    Loader::ResultStatus Parse(std::string_view path);

    std::unique_ptr<NAXHeader> header;

    VirtualFile file;
    Loader::ResultStatus status;
    NAXContentType type{};

    VirtualFile dec_file;

    Core::Crypto::KeyManager& keys;
};
} // namespace FileSys