summaryrefslogtreecommitdiffstats
path: root/src/core/loader
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/loader/3dsx.cpp40
-rw-r--r--src/core/loader/3dsx.h14
-rw-r--r--src/core/loader/loader.cpp36
-rw-r--r--src/core/loader/loader.h28
4 files changed, 102 insertions, 16 deletions
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp
index 530837d08..111b6a409 100644
--- a/src/core/loader/3dsx.cpp
+++ b/src/core/loader/3dsx.cpp
@@ -62,6 +62,10 @@ struct THREEDSX_Header
// Sizes of the code, rodata and data segments +
// size of the BSS section (uninitialized latter half of the data segment)
u32 code_seg_size, rodata_seg_size, data_seg_size, bss_size;
+ // offset and size of smdh
+ u32 smdh_offset, smdh_size;
+ // offset to filesystem
+ u32 fs_offset;
};
// Relocation header: all fields (even extra unknown fields) are guaranteed to be relocation counts.
@@ -267,4 +271,40 @@ ResultStatus AppLoader_THREEDSX::Load() {
return ResultStatus::Success;
}
+ResultStatus AppLoader_THREEDSX::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) {
+ if (!file.IsOpen())
+ return ResultStatus::Error;
+
+ // Reset read pointer in case this file has been read before.
+ file.Seek(0, SEEK_SET);
+
+ THREEDSX_Header hdr;
+ if (file.ReadBytes(&hdr, sizeof(THREEDSX_Header)) != sizeof(THREEDSX_Header))
+ return ResultStatus::Error;
+
+ if (hdr.header_size != sizeof(THREEDSX_Header))
+ return ResultStatus::Error;
+
+ // Check if the 3DSX has a RomFS...
+ if (hdr.fs_offset != 0) {
+ u32 romfs_offset = hdr.fs_offset;
+ u32 romfs_size = file.GetSize() - hdr.fs_offset;
+
+ LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
+ LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
+
+ // We reopen the file, to allow its position to be independent from file's
+ romfs_file = std::make_shared<FileUtil::IOFile>(filepath, "rb");
+ if (!romfs_file->IsOpen())
+ return ResultStatus::Error;
+
+ offset = romfs_offset;
+ size = romfs_size;
+
+ return ResultStatus::Success;
+ }
+ LOG_DEBUG(Loader, "3DSX has no RomFS");
+ return ResultStatus::ErrorNotUsed;
+}
+
} // namespace Loader
diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h
index a0aa0c533..365ddb7a5 100644
--- a/src/core/loader/3dsx.h
+++ b/src/core/loader/3dsx.h
@@ -17,8 +17,8 @@ namespace Loader {
/// Loads an 3DSX file
class AppLoader_THREEDSX final : public AppLoader {
public:
- AppLoader_THREEDSX(FileUtil::IOFile&& file, std::string filename)
- : AppLoader(std::move(file)), filename(std::move(filename)) {}
+ AppLoader_THREEDSX(FileUtil::IOFile&& file, std::string filename, const std::string& filepath)
+ : AppLoader(std::move(file)), filename(std::move(filename)), filepath(filepath) {}
/**
* Returns the type of the file
@@ -33,8 +33,18 @@ public:
*/
ResultStatus Load() override;
+ /**
+ * Get the RomFS of the application
+ * @param romfs_file Reference to buffer to store data
+ * @param offset Offset in the file to the RomFS
+ * @param size Size of the RomFS in bytes
+ * @return ResultStatus result of function
+ */
+ ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) override;
+
private:
std::string filename;
+ std::string filepath;
};
} // namespace Loader
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 74eb6e871..6b88169e1 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -26,12 +26,7 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = {
{ 0x1F000000, 0x600000, false }, // entire VRAM
};
-/**
- * Identifies the type of a bootable file
- * @param file open file
- * @return FileType of file
- */
-static FileType IdentifyFile(FileUtil::IOFile& file) {
+FileType IdentifyFile(FileUtil::IOFile& file) {
FileType type;
#define CHECK_TYPE(loader) \
@@ -48,12 +43,17 @@ static FileType IdentifyFile(FileUtil::IOFile& file) {
return FileType::Unknown;
}
-/**
- * Guess the type of a bootable file from its extension
- * @param extension_ String extension of bootable file
- * @return FileType of file
- */
-static FileType GuessFromExtension(const std::string& extension_) {
+FileType IdentifyFile(const std::string& file_name) {
+ FileUtil::IOFile file(file_name, "rb");
+ if (!file.IsOpen()) {
+ LOG_ERROR(Loader, "Failed to load file %s", file_name.c_str());
+ return FileType::Unknown;
+ }
+
+ return IdentifyFile(file);
+}
+
+FileType GuessFromExtension(const std::string& extension_) {
std::string extension = Common::ToLower(extension_);
if (extension == ".elf" || extension == ".axf")
@@ -71,7 +71,7 @@ static FileType GuessFromExtension(const std::string& extension_) {
return FileType::Unknown;
}
-static const char* GetFileTypeString(FileType type) {
+const char* GetFileTypeString(FileType type) {
switch (type) {
case FileType::CCI:
return "NCSD";
@@ -116,7 +116,15 @@ ResultStatus LoadFile(const std::string& filename) {
//3DSX file format...
case FileType::THREEDSX:
- return AppLoader_THREEDSX(std::move(file), filename_filename).Load();
+ {
+ AppLoader_THREEDSX app_loader(std::move(file), filename_filename, filename);
+ // Load application and RomFS
+ if (ResultStatus::Success == app_loader.Load()) {
+ Service::FS::RegisterArchiveType(Common::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
+ return ResultStatus::Success;
+ }
+ break;
+ }
// Standard ELF file format...
case FileType::ELF:
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index a37d3348c..8de95dacf 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -33,6 +33,34 @@ enum class FileType {
THREEDSX, //3DSX
};
+/**
+ * Identifies the type of a bootable file based on the magic value in its header.
+ * @param file open file
+ * @return FileType of file
+ */
+FileType IdentifyFile(FileUtil::IOFile& file);
+
+/**
+ * Identifies the type of a bootable file based on the magic value in its header.
+ * @param file_name path to file
+ * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine
+ * a filetype, and will never return FileType::Error.
+ */
+FileType IdentifyFile(const std::string& file_name);
+
+/**
+ * Guess the type of a bootable file from its extension
+ * @param extension String extension of bootable file
+ * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine
+ * a filetype, and will never return FileType::Error.
+ */
+FileType GuessFromExtension(const std::string& extension_);
+
+/**
+ * Convert a FileType into a string which can be displayed to the user.
+ */
+const char* GetFileTypeString(FileType type);
+
/// Return type for functions in Loader namespace
enum class ResultStatus {
Success,