summaryrefslogtreecommitdiffstats
path: root/src/core/loader/loader.h
blob: 002af1f607a18f9ca0b80a8fd785ba1e0c4cc5bd (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.

#pragma once

#include <vector>

#include "common/common.h"

////////////////////////////////////////////////////////////////////////////////////////////////////
// Loader namespace

namespace Loader {

/// File types supported by CTR
enum class FileType {
    Error,
    Unknown,
    CCI,
    CXI,
    CIA,
    ELF,
};

/// Return type for functions in Loader namespace
enum class ResultStatus {
    Success,
    Error,
    ErrorInvalidFormat,
    ErrorNotImplemented,
    ErrorNotLoaded,
    ErrorNotUsed,
    ErrorAlreadyLoaded,
};

/// Interface for loading an application
class AppLoader : NonCopyable {
public:
    AppLoader() { }
    virtual ~AppLoader() { }

    /**
     * Load the application
     * @return ResultStatus result of function
     */
    virtual ResultStatus Load() = 0;

    /**
     * Get the code (typically .code section) of the application
     * @param error ResultStatus result of function
     * @return Reference to code buffer
     */
    virtual const std::vector<u8>& GetCode(ResultStatus& error) const {
        error = ResultStatus::ErrorNotImplemented;
        return code;
    }

    /**
     * Get the icon (typically .icon section) of the application
     * @param error ResultStatus result of function
     * @return Reference to icon buffer
     */
    virtual const std::vector<u8>& GetIcon(ResultStatus& error) const {
        error = ResultStatus::ErrorNotImplemented;
        return icon;
    }

    /**
     * Get the banner (typically .banner section) of the application
     * @param error ResultStatus result of function
     * @return Reference to banner buffer
     */
    virtual const std::vector<u8>& GetBanner(ResultStatus& error) const {
        error = ResultStatus::ErrorNotImplemented;
        return banner;
    }

    /**
     * Get the logo (typically .logo section) of the application
     * @param error ResultStatus result of function
     * @return Reference to logo buffer
     */
    virtual const std::vector<u8>& GetLogo(ResultStatus& error) const {
        error = ResultStatus::ErrorNotImplemented;
        return logo;
    }

    /**
     * Get the RomFs archive of the application
     * @param error ResultStatus result of function
     * @return Reference to RomFs archive buffer
     */
    virtual const std::vector<u8>& GetRomFs(ResultStatus error) const {
        error = ResultStatus::ErrorNotImplemented;
        return romfs;
    }

protected:
    std::vector<u8> code;   ///< ExeFS .code section
    std::vector<u8> icon;   ///< ExeFS .icon section
    std::vector<u8> banner; ///< ExeFS .banner section
    std::vector<u8> logo;   ///< ExeFS .logo section
    std::vector<u8> romfs;  ///< RomFs archive
};

/**
 * Identifies the type of a bootable file
 * @param filename String filename of bootable file
 * @return FileType of file
 */
FileType IdentifyFile(const std::string &filename);

/**
 * Identifies and loads a bootable file
 * @param filename String filename of bootable file
 * @return ResultStatus result of function
 */
ResultStatus LoadFile(const std::string& filename);

} // namespace