Attempt to add RomFS dumping

This commit is contained in:
wheremyfoodat 2023-10-07 21:23:05 +03:00
parent f9dc9ac94d
commit abe4675477
10 changed files with 180 additions and 8 deletions

View file

@ -12,6 +12,7 @@
#include "cpu.hpp"
#include "crypto/aes_engine.hpp"
#include "discord_rpc.hpp"
#include "fs/romfs.hpp"
#include "io_file.hpp"
#include "lua_manager.hpp"
#include "memory.hpp"
@ -120,6 +121,7 @@ class Emulator {
void initGraphicsContext() { gpu.initGraphicsContext(window); }
#endif
RomFS::DumpingResult dumpRomFS(const std::filesystem::path& path);
void setOutputSize(u32 width, u32 height) { gpu.setOutputSize(width, height); }
EmulatorConfig& getConfig() { return config; }

View file

@ -18,5 +18,12 @@ namespace RomFS {
std::vector<std::unique_ptr<RomFSNode>> files;
};
// Result codes when dumping RomFS. These are used by the frontend to print appropriate error messages if RomFS dumping fails
enum class DumpingResult {
Success = 0,
InvalidFormat = 1, // ROM is a format that doesn't support RomFS, such as ELF
NoRomFS = 2
};
std::unique_ptr<RomFSNode> parseRomFSTree(uintptr_t romFS, u64 romFSSize);
} // namespace RomFS

View file

@ -57,6 +57,7 @@ struct NCCH {
FSInfo exeFS;
FSInfo romFS;
CodeSetInfo text, data, rodata;
FSInfo partitionInfo;
// Contents of the .code file in the ExeFS
std::vector<u8> codeFile;

View file

@ -0,0 +1,42 @@
#pragma once
#include <filesystem>
#include <system_error>
#include "helpers.hpp"
#include "mio/mio.hpp"
// Minimal RAII wrapper over memory mapped files
class MemoryMappedFile {
std::filesystem::path filePath = ""; // path of our file
mio::mmap_sink map; // mmap sink for our file
u8* pointer = nullptr; // Pointer to the contents of the memory mapped file
bool opened = false;
public:
bool exists() const { return opened; }
u8* data() const { return pointer; }
std::error_code flush();
MemoryMappedFile();
MemoryMappedFile(const std::filesystem::path& path);
~MemoryMappedFile();
// Returns true on success
bool open(const std::filesystem::path& path);
void close();
// TODO: For memory-mapped output files we'll need some more stuff such as a constructor that takes path/size/shouldCreate as parameters
u8& operator[](size_t index) { return pointer[index]; }
const u8& operator[](size_t index) const { return pointer[index]; }
auto begin() { return map.begin(); }
auto end() { return map.end(); }
auto cbegin() { return map.cbegin(); }
auto cend() { return map.cend(); }
mio::mmap_sink& getSink() { return map; }
};

View file

@ -39,6 +39,7 @@ class MainWindow : public QMainWindow {
void swapEmuBuffer();
void emuThreadMainLoop();
void selectROM();
void dumpRomFS();
// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
bool usingGL = false;