2014-06-17 03:57:09 +01:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-06-17 03:57:09 +01:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-05-06 08:06:12 +01:00
|
|
|
#include <memory>
|
|
|
|
#include "common/common_types.h"
|
2015-05-04 04:01:16 +01:00
|
|
|
#include "common/swap.h"
|
2017-09-25 07:17:38 +01:00
|
|
|
#include "core/file_sys/ncch_container.h"
|
2014-06-18 23:58:09 +01:00
|
|
|
#include "core/loader/loader.h"
|
|
|
|
|
2014-06-17 03:57:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-06-18 23:58:09 +01:00
|
|
|
// Loader namespace
|
2014-06-17 03:57:09 +01:00
|
|
|
|
|
|
|
namespace Loader {
|
|
|
|
|
2014-06-18 23:58:09 +01:00
|
|
|
/// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
|
2014-07-04 18:20:40 +01:00
|
|
|
class AppLoader_NCCH final : public AppLoader {
|
2014-06-18 23:58:09 +01:00
|
|
|
public:
|
2015-07-11 23:16:33 +01:00
|
|
|
AppLoader_NCCH(FileUtil::IOFile&& file, const std::string& filepath)
|
2017-12-11 00:50:45 +00:00
|
|
|
: AppLoader(std::move(file)), base_ncch(filepath), overlay_ncch(&base_ncch),
|
|
|
|
filepath(filepath) {}
|
2014-06-18 23:58:09 +01:00
|
|
|
|
2015-01-06 23:10:13 +00:00
|
|
|
/**
|
|
|
|
* Returns the type of the file
|
|
|
|
* @param file FileUtil::IOFile open file
|
|
|
|
* @return FileType found, or FileType::Error if this loader doesn't know it
|
|
|
|
*/
|
|
|
|
static FileType IdentifyType(FileUtil::IOFile& file);
|
|
|
|
|
2016-05-17 23:30:44 +01:00
|
|
|
FileType GetFileType() override {
|
|
|
|
return IdentifyType(file);
|
|
|
|
}
|
|
|
|
|
2019-03-23 20:04:19 +00:00
|
|
|
ResultStatus Load(std::shared_ptr<Kernel::Process>& process) override;
|
2014-06-18 23:58:09 +01:00
|
|
|
|
2016-11-20 01:40:04 +00:00
|
|
|
/**
|
|
|
|
* Loads the Exheader and returns the system mode for this application.
|
2017-06-02 22:03:38 +01:00
|
|
|
* @returns A pair with the optional system mode, and and the status.
|
2016-11-20 01:40:04 +00:00
|
|
|
*/
|
2018-10-05 11:37:55 +01:00
|
|
|
std::pair<std::optional<u32>, ResultStatus> LoadKernelSystemMode() override;
|
2016-11-20 01:40:04 +00:00
|
|
|
|
2020-02-29 18:48:27 +00:00
|
|
|
std::pair<std::optional<u8>, ResultStatus> LoadKernelN3dsMode() override;
|
|
|
|
|
2019-09-07 09:52:18 +01:00
|
|
|
ResultStatus IsExecutable(bool& out_executable) override;
|
|
|
|
|
2015-07-11 23:16:33 +01:00
|
|
|
ResultStatus ReadCode(std::vector<u8>& buffer) override;
|
2014-06-18 23:58:09 +01:00
|
|
|
|
2015-07-11 23:16:33 +01:00
|
|
|
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
|
2014-06-18 23:58:09 +01:00
|
|
|
|
2015-07-11 23:16:33 +01:00
|
|
|
ResultStatus ReadBanner(std::vector<u8>& buffer) override;
|
2014-06-22 20:40:21 +01:00
|
|
|
|
2015-07-11 23:16:33 +01:00
|
|
|
ResultStatus ReadLogo(std::vector<u8>& buffer) override;
|
2014-06-22 20:40:21 +01:00
|
|
|
|
2016-12-15 09:54:25 +00:00
|
|
|
ResultStatus ReadProgramId(u64& out_program_id) override;
|
|
|
|
|
2018-09-16 05:48:39 +01:00
|
|
|
ResultStatus ReadExtdataId(u64& out_extdata_id) override;
|
|
|
|
|
2018-07-28 16:30:54 +01:00
|
|
|
ResultStatus ReadRomFS(std::shared_ptr<FileSys::RomFSReader>& romfs_file) override;
|
2014-06-22 20:40:21 +01:00
|
|
|
|
2018-07-28 16:30:54 +01:00
|
|
|
ResultStatus ReadUpdateRomFS(std::shared_ptr<FileSys::RomFSReader>& romfs_file) override;
|
2017-09-25 07:17:38 +01:00
|
|
|
|
2020-02-09 12:59:31 +00:00
|
|
|
ResultStatus DumpRomFS(const std::string& target_path) override;
|
|
|
|
|
|
|
|
ResultStatus DumpUpdateRomFS(const std::string& target_path) override;
|
|
|
|
|
2017-08-02 00:51:44 +01:00
|
|
|
ResultStatus ReadTitle(std::string& title) override;
|
|
|
|
|
2014-06-22 20:40:21 +01:00
|
|
|
private:
|
2014-06-18 23:58:09 +01:00
|
|
|
/**
|
|
|
|
* Loads .code section into memory for booting
|
2017-09-27 00:17:47 +01:00
|
|
|
* @param process The newly created process
|
2014-06-18 23:58:09 +01:00
|
|
|
* @return ResultStatus result of function
|
|
|
|
*/
|
2019-03-23 20:04:19 +00:00
|
|
|
ResultStatus LoadExec(std::shared_ptr<Kernel::Process>& process);
|
2014-06-18 23:58:09 +01:00
|
|
|
|
2016-11-30 09:32:09 +00:00
|
|
|
/// Reads the region lockout info in the SMDH and send it to CFG service
|
|
|
|
void ParseRegionLockoutInfo();
|
|
|
|
|
2023-01-23 09:51:57 +00:00
|
|
|
/// Detects whether the NCCH contains GBA Virtual Console.
|
|
|
|
bool IsGbaVirtualConsole(const std::vector<u8>& code);
|
|
|
|
|
2017-09-25 07:17:38 +01:00
|
|
|
FileSys::NCCHContainer base_ncch;
|
|
|
|
FileSys::NCCHContainer update_ncch;
|
|
|
|
FileSys::NCCHContainer* overlay_ncch;
|
2015-07-09 22:55:23 +01:00
|
|
|
|
2016-09-18 01:38:01 +01:00
|
|
|
std::string filepath;
|
2014-06-18 23:58:09 +01:00
|
|
|
};
|
2014-06-17 03:57:09 +01:00
|
|
|
|
|
|
|
} // namespace Loader
|