NDSFactory/ndsfactory/ndsfactory.h
NyuBlara ec81e2bfbe
Feat/fat decoding (#14)
* First step in implementing FAT file decoding : brute-force extraction without FNT lookup.

The FAT alone contains enough information to extract every file in a
folder chosen by the user. However, reference to the file name table
(FNT) is needed to restore the files' names and the directory structure
(and avoid dumping useless data that may be left over in the data
section).

This commit only implements the dumping of all data by incrementing
through the FAT and writing every section marked by a FAT range into a
separate file, giving them incremental names.

The next commit will use the FNT to name them properly.

* Proper FAT decoding : FNT lookup and directory structure

Code comments explain the algorithm (which was understood thanks to the 
wonderfully simple "FNT-Tool" script at : 
https://github.com/RoadrunnerWMC/FNT-Tool) ; the implementation is more 
or less a C++ port of the Python code.

Everything may still be a little dirty, but it works !

* Updated README!

* Updated README!

* MINOR compliance modifications 

- Removed extra entry in .gitignore
- Removed superfluous debug inclusions 
- Replaced magic values by preprocessor macros

Co-authored-by: rblard <rblard@enseirb-matmeca.fr>
2022-11-16 18:46:13 +01:00

33 lines
1.3 KiB
C++

#ifndef NDSFACTORY_H
#define NDSFACTORY_H
#include <string>
#include <vector>
#include <cstdint>
#include "ndsheader.h"
#include "fatstruct.h"
class NDSFactory
{
public:
NDSFactory();
bool loadRomHeader(const std::string& romPath, std::vector<char>& header);
bool dumpDataFromFile(const std::string& romPath, const std::string& savePath, uint32_t startAddr, uint32_t size);
bool readBytesFromFile(std::vector<char>& byteBuffer, const std::string& romPath, uint32_t startAddr, uint32_t size);
bool writeSectionToFile(const std::string& sectionPath, const std::string& savePath, uint32_t startAddr, uint32_t size);
bool writeFatSectionToFile(const std::string& romPath, FatRange* pfatrange, const std::string& savePath);
bool writeBytesToFile(std::vector<char>& byteBuffer, const std::string& savePath, uint32_t startAddr, uint32_t size);
bool writePaddingToFile(char paddingChar, const std::string& savePath, uint32_t startAddr, uint32_t size);
int getCardSizeInBytes(int cardType);
bool checkArm9FooterPresence(const std::string& sectionPath, uint32_t size);
bool patchFat(const std::string& sectionPath, uint32_t shiftSize, const std::string& savePath);
uint16_t calcHeaderCrc16(const std::vector<char>& romHeader);
private:
};
#endif // NDSFACTORY_H