summaryrefslogtreecommitdiff
path: root/src/core/loader
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/elf.cpp3
-rw-r--r--src/core/loader/loader.h4
-rw-r--r--src/core/loader/nro.cpp7
-rw-r--r--src/core/loader/nso.cpp7
-rw-r--r--src/core/loader/smdh.cpp51
-rw-r--r--src/core/loader/smdh.h81
6 files changed, 10 insertions, 143 deletions
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 9969a8c39..9ba913dbe 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -5,6 +5,7 @@
5#include <cstring> 5#include <cstring>
6#include <memory> 6#include <memory>
7#include <string> 7#include <string>
8#include "common/common_funcs.h"
8#include "common/common_types.h" 9#include "common/common_types.h"
9#include "common/file_util.h" 10#include "common/file_util.h"
10#include "common/logging/log.h" 11#include "common/logging/log.h"
@@ -376,7 +377,7 @@ FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) {
376 if (1 != file.ReadArray<u16>(&machine, 1)) 377 if (1 != file.ReadArray<u16>(&machine, 1))
377 return FileType::Error; 378 return FileType::Error;
378 379
379 if (MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine) 380 if (Common::MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine)
380 return FileType::ELF; 381 return FileType::ELF;
381 382
382 return FileType::Error; 383 return FileType::Error;
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index ac4e7acc2..dd6bb4e64 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -75,10 +75,6 @@ enum class ResultStatus {
75 ErrorEncrypted, 75 ErrorEncrypted,
76}; 76};
77 77
78constexpr u32 MakeMagic(char a, char b, char c, char d) {
79 return a | b << 8 | c << 16 | d << 24;
80}
81
82/// Interface for loading an application 78/// Interface for loading an application
83class AppLoader : NonCopyable { 79class AppLoader : NonCopyable {
84public: 80public:
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 24c2c55a9..b37c3a092 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -4,6 +4,7 @@
4 4
5#include <vector> 5#include <vector>
6 6
7#include "common/common_funcs.h"
7#include "common/logging/log.h" 8#include "common/logging/log.h"
8#include "common/swap.h" 9#include "common/swap.h"
9#include "core/hle/kernel/process.h" 10#include "core/hle/kernel/process.h"
@@ -51,7 +52,7 @@ FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file) {
51 if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) { 52 if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) {
52 return FileType::Error; 53 return FileType::Error;
53 } 54 }
54 if (nro_header.magic == MakeMagic('N', 'R', 'O', '0')) { 55 if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) {
55 return FileType::NRO; 56 return FileType::NRO;
56 } 57 }
57 return FileType::Error; 58 return FileType::Error;
@@ -87,7 +88,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
87 if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) { 88 if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) {
88 return {}; 89 return {};
89 } 90 }
90 if (nro_header.magic != MakeMagic('N', 'R', 'O', '0')) { 91 if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) {
91 return {}; 92 return {};
92 } 93 }
93 94
@@ -109,7 +110,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
109 u32 bss_size{Memory::PAGE_SIZE}; // Default .bss to page size if MOD0 section doesn't exist 110 u32 bss_size{Memory::PAGE_SIZE}; // Default .bss to page size if MOD0 section doesn't exist
110 std::memcpy(&mod_header, program_image.data() + nro_header.module_header_offset, 111 std::memcpy(&mod_header, program_image.data() + nro_header.module_header_offset,
111 sizeof(ModHeader)); 112 sizeof(ModHeader));
112 const bool has_mod_header{mod_header.magic == MakeMagic('M', 'O', 'D', '0')}; 113 const bool has_mod_header{mod_header.magic == Common::MakeMagic('M', 'O', 'D', '0')};
113 if (has_mod_header) { 114 if (has_mod_header) {
114 // Resize program image to include .bss section and page align each section 115 // Resize program image to include .bss section and page align each section
115 bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); 116 bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset);
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 5ebbde19a..0d16d4b8c 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -5,6 +5,7 @@
5#include <vector> 5#include <vector>
6#include <lz4.h> 6#include <lz4.h>
7 7
8#include "common/common_funcs.h"
8#include "common/logging/log.h" 9#include "common/logging/log.h"
9#include "common/swap.h" 10#include "common/swap.h"
10#include "core/hle/kernel/process.h" 11#include "core/hle/kernel/process.h"
@@ -50,7 +51,7 @@ FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file) {
50 return FileType::Error; 51 return FileType::Error;
51 } 52 }
52 53
53 if (MakeMagic('N', 'S', 'O', '0') == magic) { 54 if (Common::MakeMagic('N', 'S', 'O', '0') == magic) {
54 return FileType::NSO; 55 return FileType::NSO;
55 } 56 }
56 57
@@ -96,7 +97,7 @@ VAddr AppLoader_NSO::LoadNso(const std::string& path, VAddr load_base, bool relo
96 if (sizeof(NsoHeader) != file.ReadBytes(&nso_header, sizeof(NsoHeader))) { 97 if (sizeof(NsoHeader) != file.ReadBytes(&nso_header, sizeof(NsoHeader))) {
97 return {}; 98 return {};
98 } 99 }
99 if (nso_header.magic != MakeMagic('N', 'S', 'O', '0')) { 100 if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0')) {
100 return {}; 101 return {};
101 } 102 }
102 103
@@ -121,7 +122,7 @@ VAddr AppLoader_NSO::LoadNso(const std::string& path, VAddr load_base, bool relo
121 ModHeader mod_header{}; 122 ModHeader mod_header{};
122 u32 bss_size{Memory::PAGE_SIZE}; // Default .bss to page size if MOD0 section doesn't exist 123 u32 bss_size{Memory::PAGE_SIZE}; // Default .bss to page size if MOD0 section doesn't exist
123 std::memcpy(&mod_header, program_image.data() + module_offset, sizeof(ModHeader)); 124 std::memcpy(&mod_header, program_image.data() + module_offset, sizeof(ModHeader));
124 const bool has_mod_header{mod_header.magic == MakeMagic('M', 'O', 'D', '0')}; 125 const bool has_mod_header{mod_header.magic == Common::MakeMagic('M', 'O', 'D', '0')};
125 if (has_mod_header) { 126 if (has_mod_header) {
126 // Resize program image to include .bss section and page align each section 127 // Resize program image to include .bss section and page align each section
127 bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); 128 bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset);
diff --git a/src/core/loader/smdh.cpp b/src/core/loader/smdh.cpp
deleted file mode 100644
index ccbeb7961..000000000
--- a/src/core/loader/smdh.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstring>
6#include <vector>
7#include "common/common_types.h"
8#include "core/loader/loader.h"
9#include "core/loader/smdh.h"
10#include "video_core/utils.h"
11
12namespace Loader {
13
14bool IsValidSMDH(const std::vector<u8>& smdh_data) {
15 if (smdh_data.size() < sizeof(Loader::SMDH))
16 return false;
17
18 u32 magic;
19 memcpy(&magic, smdh_data.data(), sizeof(u32));
20
21 return Loader::MakeMagic('S', 'M', 'D', 'H') == magic;
22}
23
24std::vector<u16> SMDH::GetIcon(bool large) const {
25 u32 size;
26 const u8* icon_data;
27
28 if (large) {
29 size = 48;
30 icon_data = large_icon.data();
31 } else {
32 size = 24;
33 icon_data = small_icon.data();
34 }
35
36 std::vector<u16> icon(size * size);
37 for (u32 x = 0; x < size; ++x) {
38 for (u32 y = 0; y < size; ++y) {
39 u32 coarse_y = y & ~7;
40 const u8* pixel = icon_data + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * size * 2;
41 icon[x + size * y] = (pixel[1] << 8) + pixel[0];
42 }
43 }
44 return icon;
45}
46
47std::array<u16, 0x40> SMDH::GetShortTitle(Loader::SMDH::TitleLanguage language) const {
48 return titles[static_cast<int>(language)].short_title;
49}
50
51} // namespace
diff --git a/src/core/loader/smdh.h b/src/core/loader/smdh.h
deleted file mode 100644
index ac7726c8f..000000000
--- a/src/core/loader/smdh.h
+++ /dev/null
@@ -1,81 +0,0 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <vector>
9#include "common/common_funcs.h"
10#include "common/common_types.h"
11#include "common/swap.h"
12
13namespace Loader {
14
15/**
16 * Tests if data is a valid SMDH by its length and magic number.
17 * @param smdh_data data buffer to test
18 * @return bool test result
19 */
20bool IsValidSMDH(const std::vector<u8>& smdh_data);
21
22/// SMDH data structure that contains titles, icons etc. See https://www.3dbrew.org/wiki/SMDH
23struct SMDH {
24 u32_le magic;
25 u16_le version;
26 INSERT_PADDING_BYTES(2);
27
28 struct Title {
29 std::array<u16, 0x40> short_title;
30 std::array<u16, 0x80> long_title;
31 std::array<u16, 0x40> publisher;
32 };
33 std::array<Title, 16> titles;
34
35 std::array<u8, 16> ratings;
36 u32_le region_lockout;
37 u32_le match_maker_id;
38 u64_le match_maker_bit_id;
39 u32_le flags;
40 u16_le eula_version;
41 INSERT_PADDING_BYTES(2);
42 float_le banner_animation_frame;
43 u32_le cec_id;
44 INSERT_PADDING_BYTES(8);
45
46 std::array<u8, 0x480> small_icon;
47 std::array<u8, 0x1200> large_icon;
48
49 /// indicates the language used for each title entry
50 enum class TitleLanguage {
51 Japanese = 0,
52 English = 1,
53 French = 2,
54 German = 3,
55 Italian = 4,
56 Spanish = 5,
57 SimplifiedChinese = 6,
58 Korean = 7,
59 Dutch = 8,
60 Portuguese = 9,
61 Russian = 10,
62 TraditionalChinese = 11
63 };
64
65 /**
66 * Gets game icon from SMDH
67 * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24)
68 * @return vector of RGB565 data
69 */
70 std::vector<u16> GetIcon(bool large) const;
71
72 /**
73 * Gets the short game title from SMDH
74 * @param language title language
75 * @return UTF-16 array of the short title
76 */
77 std::array<u16, 0x40> GetShortTitle(Loader::SMDH::TitleLanguage language) const;
78};
79static_assert(sizeof(SMDH) == 0x36C0, "SMDH structure size is wrong");
80
81} // namespace