2010-12-08 08:26:18 +01:00
|
|
|
#ifndef NANDBIN_H
|
|
|
|
#define NANDBIN_H
|
|
|
|
|
|
|
|
#include "includes.h"
|
2010-12-14 06:58:44 +01:00
|
|
|
#include "blocks0to7.h"
|
2010-12-15 09:11:56 +01:00
|
|
|
#include "nandspare.h"
|
2010-12-08 08:26:18 +01:00
|
|
|
struct fst_t
|
|
|
|
{
|
2010-12-10 04:50:08 +01:00
|
|
|
quint8 filename[ 0xc ];
|
2010-12-08 08:26:18 +01:00
|
|
|
quint8 mode;
|
|
|
|
quint8 attr;
|
|
|
|
quint16 sub;
|
|
|
|
quint16 sib;
|
|
|
|
quint32 size;
|
|
|
|
quint32 uid;
|
|
|
|
quint16 gid;
|
|
|
|
quint32 x3;
|
2010-12-15 09:11:56 +01:00
|
|
|
quint16 fst_pos;//not really part of the nand structure, but needed when calculating hmac data
|
2010-12-08 08:26:18 +01:00
|
|
|
};
|
|
|
|
// class to deal with an encrypted wii nand dump
|
|
|
|
// basic usage... create an object, set a path, call InitNand. then you can get the detailed list of entries with GetTree()
|
|
|
|
// extract files with GetFile()
|
2010-12-10 04:50:08 +01:00
|
|
|
|
|
|
|
//once InitNand() is called, you can get the contents of the nand in a nice QTreeWidgetItem* with GetTree()
|
2010-12-08 08:26:18 +01:00
|
|
|
class NandBin : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-12-10 04:50:08 +01:00
|
|
|
//creates a NandBin object. if a path is given, it will call SetPath() on that path. though you cant check the return value
|
2010-12-08 08:26:18 +01:00
|
|
|
NandBin( QObject * parent = 0, const QString &path = QString() );
|
2010-12-10 04:50:08 +01:00
|
|
|
|
|
|
|
//destroys this object, and all its used resources ( closes the nand.bin file and deletes the filetree )
|
2010-12-08 08:26:18 +01:00
|
|
|
~NandBin();
|
2010-12-10 04:50:08 +01:00
|
|
|
|
|
|
|
//sets the path of this object to path. returns false if it cannot open an already existing file
|
|
|
|
//keys.bin should be in this same path if they are to be used
|
2010-12-08 08:26:18 +01:00
|
|
|
bool SetPath( const QString &path );
|
2010-12-08 09:05:23 +01:00
|
|
|
|
|
|
|
//try to read the filesystem and create a tree from its contents
|
2010-12-10 04:50:08 +01:00
|
|
|
//this takes care of the stuff like reading the keys, finding teh superblock, and creating the QTreeWidgetItem* tree
|
2010-12-08 09:05:23 +01:00
|
|
|
//icons given here will be the ones used when asking for that tree
|
|
|
|
bool InitNand( QIcon dirs = QIcon(), QIcon files = QIcon() );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//get a root item containing children that are actually entries in the nand dump
|
|
|
|
//the root itself is just a container to hold them all and can be deleted once its children are taken
|
2010-12-10 04:50:08 +01:00
|
|
|
//! all returned items are cloned and it is up to you to delete them !
|
|
|
|
//text is assigned to the items as follows...
|
|
|
|
// 0 name
|
|
|
|
// 1 entry #
|
|
|
|
// 2 size
|
|
|
|
// 3 uid
|
|
|
|
// 4 gid
|
|
|
|
// 5 x3
|
|
|
|
// 6 mode
|
|
|
|
// 7 attr
|
2010-12-08 08:26:18 +01:00
|
|
|
QTreeWidgetItem *GetTree();
|
|
|
|
|
|
|
|
|
|
|
|
//extracts an item( and all its children ) to a directory
|
|
|
|
//this function is BLOCKING and will block the current thread, so if done in the gui thread, it will freeze your GUI till it returns
|
|
|
|
bool ExtractToDir( QTreeWidgetItem *item, const QString &path );
|
|
|
|
|
|
|
|
//print a little info about the free space
|
|
|
|
void ShowInfo();
|
|
|
|
|
|
|
|
//set this to change ":" in names to "-" on etracting.
|
|
|
|
//theres more illegal characters in FAT, but thes seems to be the only one that happens on the nand FS
|
|
|
|
void SetFixNamesForFAT( bool fix = true );
|
|
|
|
|
2010-12-10 04:50:08 +01:00
|
|
|
//returns the data that makes up the file of a given entry#
|
|
|
|
QByteArray GetFile( quint16 entry );
|
|
|
|
|
|
|
|
|
|
|
|
//get data for a given path
|
|
|
|
//! this function is slower than the above one, as it first iterates through the QTreeWidgetItems till it finds the right ono
|
|
|
|
//! and then end up calling the above one anyways.
|
|
|
|
//the path should be a file, not folder
|
|
|
|
//returns an empty array on failure
|
|
|
|
//path should start with "/" and items should be delimited by "/"
|
|
|
|
//ie... /title/00000001/00000002/data/setting.txt
|
|
|
|
const QByteArray GetData( const QString &path );
|
|
|
|
|
2010-12-11 11:12:50 +01:00
|
|
|
//returns the fats for this nand.
|
|
|
|
const QList<quint16> GetFats() { return fats; }
|
|
|
|
|
|
|
|
//get the fats for a given file
|
|
|
|
const QList<quint16> GetFatsForFile( quint16 i );
|
|
|
|
|
2010-12-14 06:58:44 +01:00
|
|
|
const Blocks0to7 BootBlocks(){ return bootBlocks; }
|
|
|
|
const QList<Boot2Info> Boot2Infos();
|
|
|
|
quint8 Boot1Version();
|
|
|
|
|
2010-12-15 09:11:56 +01:00
|
|
|
QByteArray GetPage( quint32 pageNo, bool withEcc = false );
|
|
|
|
|
2010-12-10 04:50:08 +01:00
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
private:
|
|
|
|
QByteArray key;
|
|
|
|
qint32 loc_super;
|
|
|
|
qint32 loc_fat;
|
|
|
|
qint32 loc_fst;
|
|
|
|
QString extractPath;
|
2010-12-10 04:50:08 +01:00
|
|
|
QString nandPath;
|
2010-12-08 08:26:18 +01:00
|
|
|
QFile f;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
bool fatNames;
|
2010-12-08 09:05:23 +01:00
|
|
|
QIcon groupIcon;
|
|
|
|
QIcon keyIcon;
|
2010-12-08 08:26:18 +01:00
|
|
|
|
2010-12-15 09:11:56 +01:00
|
|
|
NandSpare spare;//used to handle the hmac mumbojumbo
|
|
|
|
|
2010-12-11 11:12:50 +01:00
|
|
|
//read all the fst and remember them rather than seeking back and forth in the file all the time
|
|
|
|
// uses ~120KiB RAM
|
|
|
|
bool fstInited;
|
|
|
|
fst_t fsts[ 0x17ff ];
|
|
|
|
|
|
|
|
//cache the fat to keep from having to look them up repeatedly
|
|
|
|
// uses ~64KiB
|
|
|
|
QList<quint16>fats;
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
int GetDumpType( quint64 fileSize );
|
|
|
|
bool GetKey( int type );
|
2010-12-15 09:11:56 +01:00
|
|
|
QByteArray ReadKeyfile( QString path, quint8 type );//type 0 for nand key, type 1 for hmac
|
2010-12-08 08:26:18 +01:00
|
|
|
qint32 FindSuperblock();
|
|
|
|
quint16 GetFAT( quint16 fat_entry );
|
|
|
|
fst_t GetFST( quint16 entry );
|
|
|
|
QByteArray GetCluster( quint16 cluster_entry, bool decrypt = true );
|
|
|
|
QByteArray GetFile( fst_t fst );
|
|
|
|
|
|
|
|
QString FstName( fst_t fst );
|
2010-12-08 09:05:23 +01:00
|
|
|
bool ExtractFST( quint16 entry, const QString &path, bool singleFile = false );
|
2010-12-08 08:26:18 +01:00
|
|
|
bool ExtractDir( fst_t fst, QString parent );
|
|
|
|
bool ExtractFile( fst_t fst, QString parent );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *root;
|
|
|
|
bool AddChildren( QTreeWidgetItem *parent, quint16 entry );
|
2010-12-10 04:50:08 +01:00
|
|
|
QTreeWidgetItem *ItemFromPath( const QString &path );
|
|
|
|
QTreeWidgetItem *FindItem( const QString &s, QTreeWidgetItem *parent );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
2010-12-14 06:58:44 +01:00
|
|
|
//holds info about boot1 & 2
|
|
|
|
Blocks0to7 bootBlocks;
|
|
|
|
|
2010-12-15 09:11:56 +01:00
|
|
|
bool WriteCluster( quint32 pageNo, const QByteArray data, const QByteArray hmac );
|
|
|
|
bool WriteDecryptedCluster( quint32 pageNo, const QByteArray data, fst_t fst, quint16 idx );
|
|
|
|
bool WritePage( quint32 pageNo, const QByteArray data );
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
signals:
|
2010-12-10 04:50:08 +01:00
|
|
|
//connect to these to receive messages from this object
|
2010-12-08 08:26:18 +01:00
|
|
|
void SendError( QString );
|
|
|
|
void SendText( QString );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NANDBIN_H
|