mirror of
https://github.com/RKX1209/nsemu.git
synced 2024-06-23 14:43:16 -04:00
Add NintendoObject class for NRO/NSO binary format
This commit is contained in:
parent
6de38b8c2f
commit
186bc1ed5f
2
Makefile
2
Makefile
|
@ -2,6 +2,8 @@ CXX := g++
|
|||
SRC_FILES := $(wildcard *.cpp)
|
||||
OBJ_FILES := $(SRC_FILES:.cpp=.o)
|
||||
CXX_FLAGS := -Iinclude
|
||||
LD_FLAGS := -llz4
|
||||
|
||||
all: nsemu
|
||||
nsemu: $(OBJ_FILES)
|
||||
$(CXX) -o nsemu $(LD_FLAGS) $(OBJ_FILES)
|
||||
|
|
27
NintendoObject.cpp
Normal file
27
NintendoObject.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "Nsemu.hpp"
|
||||
#include <lz4.h>
|
||||
|
||||
NintendoObject::NintendoObject(string path) {
|
||||
fp.open(path, ios::in | ios::binary);
|
||||
fp.seekg(0, ios_base::end);
|
||||
length = (uint32_t) fp.tellg();
|
||||
fp.seekg(0);
|
||||
}
|
||||
|
||||
char *decompress(ifstream &fp, uint32_t offset, uint32_t csize, uint32_t usize) {
|
||||
fp.seekg(offset);
|
||||
char *buf = new char[csize];
|
||||
char *obuf = new char[usize];
|
||||
fp.read(buf, csize);
|
||||
assert(LZ4_decompress_safe(buf, obuf, csize, usize) == usize);
|
||||
delete[] buf;
|
||||
return obuf;
|
||||
}
|
||||
|
||||
int Nso::load (Nsemu *nsemu, uint64_t *base) {
|
||||
|
||||
}
|
||||
|
||||
int Nro::load (Nsemu *nsemu, uint64_t *base) {
|
||||
|
||||
}
|
35
include/NintendoObject.hpp
Normal file
35
include/NintendoObject.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef _NINTENDO_OBJECT_HPP
|
||||
#define _NINTENDO_OBJECT_HPP
|
||||
|
||||
class Nsemu;
|
||||
class NintendoObject {
|
||||
public:
|
||||
NintendoObject(std::string path);
|
||||
~NintendoObject() {}
|
||||
virtual int load (Nsemu *nsemu, uint64_t *base) = 0;
|
||||
protected:
|
||||
std::ifstream fp;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
class Nso : NintendoObject {
|
||||
public:
|
||||
Nso(std::string path) : NintendoObject(path) {}
|
||||
int load (Nsemu *nsemu, uint64_t *base);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic, pad0, pad1, pad2;
|
||||
uint32_t textOff, textLoc, textSize, pad3;
|
||||
uint32_t rdataOff, rdataLoc, rdataSize, pad4;
|
||||
uint32_t dataOff, dataLoc, dataSize;
|
||||
uint32_t bssSize;
|
||||
} NsoHeader;
|
||||
|
||||
class Nro : NintendoObject {
|
||||
public:
|
||||
Nro(std::string path) : NintendoObject(path) {}
|
||||
int load (Nsemu *nsemu, uint64_t *base);
|
||||
};
|
||||
|
||||
#endif
|
19
include/Nsemu.hpp
Normal file
19
include/Nsemu.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef _NSEMU_HPP
|
||||
#define _NSEMU_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "NintendoObject.hpp"
|
||||
|
||||
class Nsemu {
|
||||
public:
|
||||
Nsemu();
|
||||
};
|
||||
#endif
|
Loading…
Reference in a new issue