summaryrefslogtreecommitdiff
path: root/src/core/loader
diff options
context:
space:
mode:
authorGravatar bunnei2014-06-16 18:03:13 -0400
committerGravatar bunnei2014-06-16 18:03:13 -0400
commit0aca202ae936d3fccbab34f36d9246e0598849a5 (patch)
treefff4a16ed505ebddcc3048cf734db0237839d338 /src/core/loader
parentLoader: Added stubbed detection of CXI and CCI files. (diff)
downloadyuzu-0aca202ae936d3fccbab34f36d9246e0598849a5.tar.gz
yuzu-0aca202ae936d3fccbab34f36d9246e0598849a5.tar.xz
yuzu-0aca202ae936d3fccbab34f36d9246e0598849a5.zip
Loader: Moved elf and loader modules to a "loader" subdirectory.
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/elf_reader.cpp190
-rw-r--r--src/core/loader/elf_reader.h75
-rw-r--r--src/core/loader/elf_types.h281
-rw-r--r--src/core/loader/loader.cpp205
-rw-r--r--src/core/loader/loader.h54
5 files changed, 805 insertions, 0 deletions
diff --git a/src/core/loader/elf_reader.cpp b/src/core/loader/elf_reader.cpp
new file mode 100644
index 000000000..123747f8e
--- /dev/null
+++ b/src/core/loader/elf_reader.cpp
@@ -0,0 +1,190 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <string>
6
7#include "common/common.h"
8
9#include "common/symbols.h"
10#include "core/mem_map.h"
11#include "core/loader/elf_reader.h"
12
13//void bswap(Elf32_Word &w) {w = Common::swap32(w);}
14//void bswap(Elf32_Half &w) {w = Common::swap16(w);}
15
16#define bswap(w) w // Dirty bswap disable for now... 3DS is little endian, anyway
17
18static void byteswapHeader(Elf32_Ehdr &ELF_H)
19{
20 bswap(ELF_H.e_type);
21 bswap(ELF_H.e_machine);
22 bswap(ELF_H.e_ehsize);
23 bswap(ELF_H.e_phentsize);
24 bswap(ELF_H.e_phnum);
25 bswap(ELF_H.e_shentsize);
26 bswap(ELF_H.e_shnum);
27 bswap(ELF_H.e_shstrndx);
28 bswap(ELF_H.e_version);
29 bswap(ELF_H.e_entry);
30 bswap(ELF_H.e_phoff);
31 bswap(ELF_H.e_shoff);
32 bswap(ELF_H.e_flags);
33}
34
35static void byteswapSegment(Elf32_Phdr &sec)
36{
37 bswap(sec.p_align);
38 bswap(sec.p_filesz);
39 bswap(sec.p_flags);
40 bswap(sec.p_memsz);
41 bswap(sec.p_offset);
42 bswap(sec.p_paddr);
43 bswap(sec.p_vaddr);
44 bswap(sec.p_type);
45}
46
47static void byteswapSection(Elf32_Shdr &sec)
48{
49 bswap(sec.sh_addr);
50 bswap(sec.sh_addralign);
51 bswap(sec.sh_entsize);
52 bswap(sec.sh_flags);
53 bswap(sec.sh_info);
54 bswap(sec.sh_link);
55 bswap(sec.sh_name);
56 bswap(sec.sh_offset);
57 bswap(sec.sh_size);
58 bswap(sec.sh_type);
59}
60
61ElfReader::ElfReader(void *ptr)
62{
63 base = (char*)ptr;
64 base32 = (u32 *)ptr;
65 header = (Elf32_Ehdr*)ptr;
66 byteswapHeader(*header);
67
68 segments = (Elf32_Phdr *)(base + header->e_phoff);
69 sections = (Elf32_Shdr *)(base + header->e_shoff);
70
71 entryPoint = header->e_entry;
72
73 LoadSymbols();
74}
75
76const char *ElfReader::GetSectionName(int section) const
77{
78 if (sections[section].sh_type == SHT_NULL)
79 return nullptr;
80
81 int nameOffset = sections[section].sh_name;
82 char *ptr = (char*)GetSectionDataPtr(header->e_shstrndx);
83
84 if (ptr)
85 return ptr + nameOffset;
86 else
87 return nullptr;
88}
89
90bool ElfReader::LoadInto(u32 vaddr)
91{
92 DEBUG_LOG(MASTER_LOG,"String section: %i", header->e_shstrndx);
93
94 // Should we relocate?
95 bRelocate = (header->e_type != ET_EXEC);
96
97 if (bRelocate)
98 {
99 DEBUG_LOG(MASTER_LOG,"Relocatable module");
100 entryPoint += vaddr;
101 }
102 else
103 {
104 DEBUG_LOG(MASTER_LOG,"Prerelocated executable");
105 }
106
107 INFO_LOG(MASTER_LOG,"%i segments:", header->e_phnum);
108
109 // First pass : Get the bits into RAM
110 u32 segmentVAddr[32];
111
112 u32 baseAddress = bRelocate?vaddr:0;
113
114 for (int i = 0; i < header->e_phnum; i++)
115 {
116 Elf32_Phdr *p = segments + i;
117
118 INFO_LOG(MASTER_LOG, "Type: %i Vaddr: %08x Filesz: %i Memsz: %i ", p->p_type, p->p_vaddr, p->p_filesz, p->p_memsz);
119
120 if (p->p_type == PT_LOAD)
121 {
122 segmentVAddr[i] = baseAddress + p->p_vaddr;
123 u32 writeAddr = segmentVAddr[i];
124
125 const u8 *src = GetSegmentPtr(i);
126 u8 *dst = Memory::GetPointer(writeAddr);
127 u32 srcSize = p->p_filesz;
128 u32 dstSize = p->p_memsz;
129 u32 *s = (u32*)src;
130 u32 *d = (u32*)dst;
131 for (int j = 0; j < (int)(srcSize + 3) / 4; j++)
132 {
133 *d++ = /*_byteswap_ulong*/(*s++);
134 }
135 if (srcSize < dstSize)
136 {
137 //memset(dst + srcSize, 0, dstSize-srcSize); //zero out bss
138 }
139 INFO_LOG(MASTER_LOG,"Loadable Segment Copied to %08x, size %08x", writeAddr, p->p_memsz);
140 }
141 }
142
143
144 INFO_LOG(MASTER_LOG,"Done loading.");
145 return true;
146}
147
148SectionID ElfReader::GetSectionByName(const char *name, int firstSection) const
149{
150 for (int i = firstSection; i < header->e_shnum; i++)
151 {
152 const char *secname = GetSectionName(i);
153
154 if (secname != nullptr && strcmp(name, secname) == 0)
155 return i;
156 }
157 return -1;
158}
159
160bool ElfReader::LoadSymbols()
161{
162 bool hasSymbols = false;
163 SectionID sec = GetSectionByName(".symtab");
164 if (sec != -1)
165 {
166 int stringSection = sections[sec].sh_link;
167 const char *stringBase = (const char *)GetSectionDataPtr(stringSection);
168
169 //We have a symbol table!
170 Elf32_Sym *symtab = (Elf32_Sym *)(GetSectionDataPtr(sec));
171 int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
172 for (int sym = 0; sym < numSymbols; sym++)
173 {
174 int size = symtab[sym].st_size;
175 if (size == 0)
176 continue;
177
178 // int bind = symtab[sym].st_info >> 4;
179 int type = symtab[sym].st_info & 0xF;
180
181 const char *name = stringBase + symtab[sym].st_name;
182
183 Symbols::Add(symtab[sym].st_value, name, size, type);
184
185 hasSymbols = true;
186 }
187 }
188
189 return hasSymbols;
190}
diff --git a/src/core/loader/elf_reader.h b/src/core/loader/elf_reader.h
new file mode 100644
index 000000000..6f0ad84b3
--- /dev/null
+++ b/src/core/loader/elf_reader.h
@@ -0,0 +1,75 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/loader/elf_types.h"
8
9enum KnownElfTypes
10{
11 KNOWNELF_PSP = 0,
12 KNOWNELF_DS = 1,
13 KNOWNELF_GBA = 2,
14 KNOWNELF_GC = 3,
15};
16
17typedef int SectionID;
18
19class ElfReader
20{
21private:
22 char *base;
23 u32 *base32;
24
25 Elf32_Ehdr *header;
26 Elf32_Phdr *segments;
27 Elf32_Shdr *sections;
28
29 u32 *sectionAddrs;
30 bool bRelocate;
31 u32 entryPoint;
32
33public:
34 ElfReader(void *ptr);
35 ~ElfReader() { }
36
37 u32 Read32(int off) const { return base32[off>>2]; }
38
39 // Quick accessors
40 ElfType GetType() const { return (ElfType)(header->e_type); }
41 ElfMachine GetMachine() const { return (ElfMachine)(header->e_machine); }
42 u32 GetEntryPoint() const { return entryPoint; }
43 u32 GetFlags() const { return (u32)(header->e_flags); }
44 bool LoadInto(u32 vaddr);
45 bool LoadSymbols();
46
47 int GetNumSegments() const { return (int)(header->e_phnum); }
48 int GetNumSections() const { return (int)(header->e_shnum); }
49 const u8 *GetPtr(int offset) const { return (u8*)base + offset; }
50 const char *GetSectionName(int section) const;
51 const u8 *GetSectionDataPtr(int section) const
52 {
53 if (section < 0 || section >= header->e_shnum)
54 return nullptr;
55 if (sections[section].sh_type != SHT_NOBITS)
56 return GetPtr(sections[section].sh_offset);
57 else
58 return nullptr;
59 }
60 bool IsCodeSection(int section) const
61 {
62 return sections[section].sh_type == SHT_PROGBITS;
63 }
64 const u8 *GetSegmentPtr(int segment)
65 {
66 return GetPtr(segments[segment].p_offset);
67 }
68 u32 GetSectionAddr(SectionID section) const { return sectionAddrs[section]; }
69 int GetSectionSize(SectionID section) const { return sections[section].sh_size; }
70 SectionID GetSectionByName(const char *name, int firstSection = 0) const; //-1 for not found
71
72 bool DidRelocate() {
73 return bRelocate;
74 }
75};
diff --git a/src/core/loader/elf_types.h b/src/core/loader/elf_types.h
new file mode 100644
index 000000000..f1bf3db72
--- /dev/null
+++ b/src/core/loader/elf_types.h
@@ -0,0 +1,281 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7// ELF Header Constants
8
9// File type
10enum ElfType
11{
12 ET_NONE = 0,
13 ET_REL = 1,
14 ET_EXEC = 2,
15 ET_DYN = 3,
16 ET_CORE = 4,
17 ET_LOPROC = 0xFF00,
18 ET_HIPROC = 0xFFFF,
19};
20
21// Machine/Architecture
22enum ElfMachine
23{
24 EM_NONE = 0,
25 EM_M32 = 1,
26 EM_SPARC = 2,
27 EM_386 = 3,
28 EM_68K = 4,
29 EM_88K = 5,
30 EM_860 = 7,
31 EM_MIPS = 8
32};
33
34// File version
35#define EV_NONE 0
36#define EV_CURRENT 1
37
38// Identification index
39#define EI_MAG0 0
40#define EI_MAG1 1
41#define EI_MAG2 2
42#define EI_MAG3 3
43#define EI_CLASS 4
44#define EI_DATA 5
45#define EI_VERSION 6
46#define EI_PAD 7
47#define EI_NIDENT 16
48
49// Magic number
50#define ELFMAG0 0x7F
51#define ELFMAG1 'E'
52#define ELFMAG2 'L'
53#define ELFMAG3 'F'
54
55// File class
56#define ELFCLASSNONE 0
57#define ELFCLASS32 1
58#define ELFCLASS64 2
59
60// Encoding
61#define ELFDATANONE 0
62#define ELFDATA2LSB 1
63#define ELFDATA2MSB 2
64
65
66
67// Sections constants
68
69// Section indexes
70#define SHN_UNDEF 0
71#define SHN_LORESERVE 0xFF00
72#define SHN_LOPROC 0xFF00
73#define SHN_HIPROC 0xFF1F
74#define SHN_ABS 0xFFF1
75#define SHN_COMMON 0xFFF2
76#define SHN_HIRESERVE 0xFFFF
77
78// Section types
79#define SHT_NULL 0
80#define SHT_PROGBITS 1
81#define SHT_SYMTAB 2
82#define SHT_STRTAB 3
83#define SHT_RELA 4
84#define SHT_HASH 5
85#define SHT_DYNAMIC 6
86#define SHT_NOTE 7
87#define SHT_NOBITS 8
88#define SHT_REL 9
89#define SHT_SHLIB 10
90#define SHT_DYNSYM 11
91#define SHT_LOPROC 0x70000000
92#define SHT_HIPROC 0x7FFFFFFF
93#define SHT_LOUSER 0x80000000
94#define SHT_HIUSER 0xFFFFFFFF
95
96// Custom section types
97#define SHT_PSPREL 0x700000a0
98
99
100// Section flags
101enum ElfSectionFlags
102{
103 SHF_WRITE = 0x1,
104 SHF_ALLOC = 0x2,
105 SHF_EXECINSTR = 0x4,
106 SHF_MASKPROC = 0xF0000000,
107};
108
109// Symbol binding
110#define STB_LOCAL 0
111#define STB_GLOBAL 1
112#define STB_WEAK 2
113#define STB_LOPROC 13
114#define STB_HIPROC 15
115
116// Symbol types
117#define STT_NOTYPE 0
118#define STT_OBJECT 1
119#define STT_FUNC 2
120#define STT_SECTION 3
121#define STT_FILE 4
122#define STT_LOPROC 13
123#define STT_HIPROC 15
124
125// Undefined name
126#define STN_UNDEF 0
127
128// Relocation types
129#define R_386_NONE 0
130#define R_386_32 1
131#define R_386_PC32 2
132#define R_386_GOT32 3
133#define R_386_PLT32 4
134#define R_386_COPY 5
135#define R_386_GLOB_DAT 6
136#define R_386_JMP_SLOT 7
137#define R_386_RELATIVE 8
138#define R_386_GOTOFF 9
139#define R_386_GOTPC 10
140
141// Segment types
142#define PT_NULL 0
143#define PT_LOAD 1
144#define PT_DYNAMIC 2
145#define PT_INTERP 3
146#define PT_NOTE 4
147#define PT_SHLIB 5
148#define PT_PHDR 6
149#define PT_LOPROC 0x70000000
150#define PT_HIPROC 0x7FFFFFFF
151
152// Segment flags
153#define PF_X 1
154#define PF_W 2
155#define PF_R 4
156
157// Dynamic Array Tags
158#define DT_NULL 0
159#define DT_NEEDED 1
160#define DT_PLTRELSZ 2
161#define DT_PLTGOT 3
162#define DT_HASH 4
163#define DT_STRTAB 5
164#define DT_SYMTAB 6
165#define DT_RELA 7
166#define DT_RELASZ 8
167#define DT_RELAENT 9
168#define DT_STRSZ 10
169#define DT_SYMENT 11
170#define DT_INIT 12
171#define DT_FINI 13
172#define DT_SONAME 14
173#define DT_RPATH 15
174#define DT_SYMBOLIC 16
175#define DT_REL 17
176#define DT_RELSZ 18
177#define DT_RELENT 19
178#define DT_PLTREL 20
179#define DT_DEBUG 21
180#define DT_TEXTREL 22
181#define DT_JMPREL 23
182#define DT_LOPROC 0x70000000
183#define DT_HIPROC 0x7FFFFFFF
184
185typedef unsigned int Elf32_Addr;
186typedef unsigned short Elf32_Half;
187typedef unsigned int Elf32_Off;
188typedef signed int Elf32_Sword;
189typedef unsigned int Elf32_Word;
190
191
192// ELF file header
193struct Elf32_Ehdr
194{
195 unsigned char e_ident[EI_NIDENT];
196 Elf32_Half e_type;
197 Elf32_Half e_machine;
198 Elf32_Word e_version;
199 Elf32_Addr e_entry;
200 Elf32_Off e_phoff;
201 Elf32_Off e_shoff;
202 Elf32_Word e_flags;
203 Elf32_Half e_ehsize;
204 Elf32_Half e_phentsize;
205 Elf32_Half e_phnum;
206 Elf32_Half e_shentsize;
207 Elf32_Half e_shnum;
208 Elf32_Half e_shstrndx;
209};
210
211// Section header
212struct Elf32_Shdr
213{
214 Elf32_Word sh_name;
215 Elf32_Word sh_type;
216 Elf32_Word sh_flags;
217 Elf32_Addr sh_addr;
218 Elf32_Off sh_offset;
219 Elf32_Word sh_size;
220 Elf32_Word sh_link;
221 Elf32_Word sh_info;
222 Elf32_Word sh_addralign;
223 Elf32_Word sh_entsize;
224};
225
226// Segment header
227struct Elf32_Phdr
228{
229 Elf32_Word p_type;
230 Elf32_Off p_offset;
231 Elf32_Addr p_vaddr;
232 Elf32_Addr p_paddr;
233 Elf32_Word p_filesz;
234 Elf32_Word p_memsz;
235 Elf32_Word p_flags;
236 Elf32_Word p_align;
237};
238
239// Symbol table entry
240struct Elf32_Sym
241{
242 Elf32_Word st_name;
243 Elf32_Addr st_value;
244 Elf32_Word st_size;
245 unsigned char st_info;
246 unsigned char st_other;
247 Elf32_Half st_shndx;
248};
249
250#define ELF32_ST_BIND(i) ((i)>>4)
251#define ELF32_ST_TYPE(i) ((i)&0xf)
252#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
253
254// Relocation entries
255struct Elf32_Rel
256{
257 Elf32_Addr r_offset;
258 Elf32_Word r_info;
259};
260
261struct Elf32_Rela
262{
263 Elf32_Addr r_offset;
264 Elf32_Word r_info;
265 Elf32_Sword r_addend;
266};
267
268#define ELF32_R_SYM(i) ((i)>>8)
269#define ELF32_R_TYPE(i) ((unsigned char)(i))
270#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t))
271
272
273struct Elf32_Dyn
274{
275 Elf32_Sword d_tag;
276 union
277 {
278 Elf32_Word d_val;
279 Elf32_Addr d_ptr;
280 } d_un;
281};
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
new file mode 100644
index 000000000..7e6922e0c
--- /dev/null
+++ b/src/core/loader/loader.cpp
@@ -0,0 +1,205 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "common/common_types.h"
6#include "common/file_util.h"
7
8#include "core/loader/loader.h"
9#include "core/loader/elf_reader.h"
10#include "core/system.h"
11#include "core/core.h"
12#include "core/hle/kernel/kernel.h"
13#include "core/mem_map.h"
14
15////////////////////////////////////////////////////////////////////////////////////////////////////
16
17/// Loads a CTR ELF file
18bool Load_ELF(std::string &filename) {
19 std::string full_path = filename;
20 std::string path, file, extension;
21 SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension);
22#if EMU_PLATFORM == PLATFORM_WINDOWS
23 path = ReplaceAll(path, "/", "\\");
24#endif
25 File::IOFile f(filename, "rb");
26
27 if (f.IsOpen()) {
28 u64 size = f.GetSize();
29 u8* buffer = new u8[size];
30 ElfReader* elf_reader = NULL;
31
32 f.ReadBytes(buffer, size);
33
34 elf_reader = new ElfReader(buffer);
35 elf_reader->LoadInto(0x00100000);
36
37 Kernel::LoadExec(elf_reader->GetEntryPoint());
38
39 delete[] buffer;
40 delete elf_reader;
41 } else {
42 return false;
43 }
44 f.Close();
45
46 return true;
47}
48
49/// Loads a CTR BIN file extracted from an ExeFS
50bool Load_BIN(std::string &filename) {
51 std::string full_path = filename;
52 std::string path, file, extension;
53 SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension);
54#if EMU_PLATFORM == PLATFORM_WINDOWS
55 path = ReplaceAll(path, "/", "\\");
56#endif
57 File::IOFile f(filename, "rb");
58
59 if (f.IsOpen()) {
60 u64 size = f.GetSize();
61 u8* buffer = new u8[size];
62
63 f.ReadBytes(buffer, size);
64
65 u32 entry_point = 0x00100000; // Hardcoded, read from exheader
66
67 const u8 *src = buffer;
68 u8 *dst = Memory::GetPointer(entry_point);
69 u32 srcSize = size;
70 u32 *s = (u32*)src;
71 u32 *d = (u32*)dst;
72 for (int j = 0; j < (int)(srcSize + 3) / 4; j++)
73 {
74 *d++ = (*s++);
75 }
76
77 Kernel::LoadExec(entry_point);
78
79 delete[] buffer;
80 }
81 else {
82 return false;
83 }
84 f.Close();
85
86 return true;
87}
88
89namespace Loader {
90
91bool IsBootableDirectory() {
92 ERROR_LOG(TIME, "Unimplemented function!");
93 return true;
94}
95
96/**
97 * Identifies the type of a bootable file
98 * @param filename String filename of bootable file
99 * @todo (ShizZy) this function sucks... make it actually check file contents etc.
100 * @return FileType of file
101 */
102FileType IdentifyFile(std::string &filename) {
103 if (filename.size() == 0) {
104 ERROR_LOG(LOADER, "invalid filename %s", filename.c_str());
105 return FILETYPE_ERROR;
106 }
107 std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : "";
108
109 if (File::IsDirectory(filename)) {
110 if (IsBootableDirectory()) {
111 return FILETYPE_DIRECTORY_CXI;
112 }
113 else {
114 return FILETYPE_NORMAL_DIRECTORY;
115 }
116 }
117 else if (!strcasecmp(extension.c_str(), ".elf")) {
118 return FILETYPE_CTR_ELF; // TODO(bunnei): Do some filetype checking :p
119 }
120 else if (!strcasecmp(extension.c_str(), ".axf")) {
121 return FILETYPE_CTR_ELF; // TODO(bunnei): Do some filetype checking :p
122 }
123 else if (!strcasecmp(extension.c_str(), ".cxi")) {
124 return FILETYPE_CTR_CXI; // TODO(bunnei): Do some filetype checking :p
125 }
126 else if (!strcasecmp(extension.c_str(), ".cci")) {
127 return FILETYPE_CTR_CCI; // TODO(bunnei): Do some filetype checking :p
128 }
129 else if (!strcasecmp(extension.c_str(), ".bin")) {
130 return FILETYPE_CTR_BIN;
131 }
132 else if (!strcasecmp(extension.c_str(), ".dat")) {
133 return FILETYPE_LAUNCHER_DAT;
134 }
135 else if (!strcasecmp(extension.c_str(), ".zip")) {
136 return FILETYPE_ARCHIVE_ZIP;
137 }
138 else if (!strcasecmp(extension.c_str(), ".rar")) {
139 return FILETYPE_ARCHIVE_RAR;
140 }
141 else if (!strcasecmp(extension.c_str(), ".r00")) {
142 return FILETYPE_ARCHIVE_RAR;
143 }
144 else if (!strcasecmp(extension.c_str(), ".r01")) {
145 return FILETYPE_ARCHIVE_RAR;
146 }
147 return FILETYPE_UNKNOWN;
148}
149
150/**
151 * Identifies and loads a bootable file
152 * @param filename String filename of bootable file
153 * @param error_string Point to string to put error message if an error has occurred
154 * @return True on success, otherwise false
155 */
156bool LoadFile(std::string &filename, std::string *error_string) {
157 INFO_LOG(LOADER, "Identifying file...");
158
159 // Note that this can modify filename!
160 switch (IdentifyFile(filename)) {
161
162 case FILETYPE_CTR_ELF:
163 return Load_ELF(filename);
164
165 case FILETYPE_CTR_BIN:
166 return Load_BIN(filename);
167
168 case FILETYPE_ERROR:
169 ERROR_LOG(LOADER, "Could not read file");
170 *error_string = "Error reading file";
171 break;
172
173 case FILETYPE_ARCHIVE_RAR:
174#ifdef WIN32
175 *error_string = "RAR file detected (Require WINRAR)";
176#else
177 *error_string = "RAR file detected (Require UnRAR)";
178#endif
179 break;
180
181 case FILETYPE_ARCHIVE_ZIP:
182#ifdef WIN32
183 *error_string = "ZIP file detected (Require WINRAR)";
184#else
185 *error_string = "ZIP file detected (Require UnRAR)";
186#endif
187 break;
188
189 case FILETYPE_NORMAL_DIRECTORY:
190 ERROR_LOG(LOADER, "Just a directory.");
191 *error_string = "Just a directory.";
192 break;
193
194 case FILETYPE_UNKNOWN_BIN:
195 case FILETYPE_UNKNOWN_ELF:
196 case FILETYPE_UNKNOWN:
197 default:
198 ERROR_LOG(LOADER, "Failed to identify file");
199 *error_string = " Failed to identify file";
200 break;
201 }
202 return false;
203}
204
205} // namespace \ No newline at end of file
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
new file mode 100644
index 000000000..9d4aaa874
--- /dev/null
+++ b/src/core/loader/loader.h
@@ -0,0 +1,54 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common.h"
8
9////////////////////////////////////////////////////////////////////////////////////////////////////
10
11namespace Loader {
12
13enum FileType {
14 FILETYPE_ERROR,
15
16 FILETYPE_CTR_CCI,
17 FILETYPE_CTR_CIA,
18 FILETYPE_CTR_CXI,
19 FILETYPE_CTR_ELF,
20 FILETYPE_CTR_BIN,
21
22 FILETYPE_LAUNCHER_DAT,
23
24 FILETYPE_DIRECTORY_CXI,
25
26 FILETYPE_UNKNOWN_BIN,
27 FILETYPE_UNKNOWN_ELF,
28
29 FILETYPE_ARCHIVE_RAR,
30 FILETYPE_ARCHIVE_ZIP,
31
32 FILETYPE_NORMAL_DIRECTORY,
33
34 FILETYPE_UNKNOWN
35};
36
37////////////////////////////////////////////////////////////////////////////////////////////////////
38
39/**
40 * Identifies the type of a bootable file
41 * @param filename String filename of bootable file
42 * @return FileType of file
43 */
44FileType IdentifyFile(std::string &filename);
45
46/**
47 * Identifies and loads a bootable file
48 * @param filename String filename of bootable file
49 * @param error_string Point to string to put error message if an error has occurred
50 * @return True on success, otherwise false
51 */
52bool LoadFile(std::string &filename, std::string *error_string);
53
54} // namespace