summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/kernel_executable.h
blob: d5b9199b56dac2c40528fccd47726a5065335e86 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <array>
#include <string>
#include <vector>

#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/swap.h"
#include "core/file_sys/vfs_types.h"

namespace Loader {
enum class ResultStatus : u16;
}

namespace FileSys {

struct KIPSectionHeader {
    u32_le offset;
    u32_le decompressed_size;
    u32_le compressed_size;
    u32_le attribute;
};
static_assert(sizeof(KIPSectionHeader) == 0x10, "KIPSectionHeader has incorrect size.");

struct KIPHeader {
    u32_le magic;
    std::array<char, 0xC> name;
    u64_le title_id;
    u32_le process_category;
    u8 main_thread_priority;
    u8 default_core;
    INSERT_PADDING_BYTES(1);
    u8 flags;
    std::array<KIPSectionHeader, 6> sections;
    std::array<u32, 0x20> capabilities;
};
static_assert(sizeof(KIPHeader) == 0x100, "KIPHeader has incorrect size.");

struct INIHeader {
    u32_le magic;
    u32_le size;
    u32_le kip_count;
    INSERT_PADDING_BYTES(0x4);
};
static_assert(sizeof(INIHeader) == 0x10, "INIHeader has incorrect size.");

// Kernel Internal Process
class KIP {
public:
    explicit KIP(const VirtualFile& file);

    Loader::ResultStatus GetStatus() const;

    std::string GetName() const;
    u64 GetTitleID() const;
    std::vector<u8> GetSectionDecompressed(u8 index) const;

    // Executable Flags
    bool Is64Bit() const;
    bool Is39BitAddressSpace() const;
    bool IsService() const;

    std::vector<u32> GetKernelCapabilities() const;

    s32 GetMainThreadPriority() const;
    u32 GetMainThreadStackSize() const;
    u32 GetMainThreadCpuCore() const;

    const std::vector<u8>& GetTextSection() const;
    const std::vector<u8>& GetRODataSection() const;
    const std::vector<u8>& GetDataSection() const;

    u32 GetTextOffset() const;
    u32 GetRODataOffset() const;
    u32 GetDataOffset() const;

    u32 GetBSSSize() const;
    u32 GetBSSOffset() const;

private:
    Loader::ResultStatus status;

    KIPHeader header{};
    std::array<std::vector<u8>, 6> decompressed_sections;
};

class INI {
public:
    explicit INI(const VirtualFile& file);

    Loader::ResultStatus GetStatus() const;

    const std::vector<KIP>& GetKIPs() const;

private:
    Loader::ResultStatus status;

    INIHeader header{};
    std::vector<KIP> kips;
};

} // namespace FileSys