2010-12-08 08:26:18 +01:00
|
|
|
#ifndef WAD_H
|
|
|
|
#define WAD_H
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
class Wad
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//create a wad instance from a bytearray containing a wad
|
|
|
|
Wad( const QByteArray stuff = QByteArray() );
|
|
|
|
|
|
|
|
//create a wad object from a list of byteArrays.
|
|
|
|
//the first one should be the tmd, the second one the ticket, and the rest are the contents, in order
|
|
|
|
//it will use the global cert unless one is given with SetCert
|
|
|
|
Wad( QList< QByteArray > stuff, bool isEncrypted = true );
|
|
|
|
|
|
|
|
//check if this wad is valid
|
|
|
|
bool IsOk(){ return ok; }
|
|
|
|
|
|
|
|
//set the cert for this wad
|
|
|
|
void SetCert( const QByteArray stuff );
|
|
|
|
|
|
|
|
//returns the tid of the tmd of this wad( which may be different than the one in the ticket if somebody did something stupid )
|
|
|
|
quint64 Tid();
|
|
|
|
|
|
|
|
//set the tid in the ticket&tmd and fakesign the wad
|
2010-12-09 12:30:25 +01:00
|
|
|
bool SetTid( quint64 tid );
|
|
|
|
|
|
|
|
//replace a content of this wad, update the size & hash in the tmd and sign it
|
|
|
|
//ba should be decrypted
|
|
|
|
bool ReplaceContent( quint16 idx, const QByteArray ba );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//add a new content to this wad and fakesign
|
|
|
|
//if the data is encrypted, set that arguement to true
|
|
|
|
//index is the index used for the new entry, default is after all the others
|
2010-12-09 12:30:25 +01:00
|
|
|
//void AddContent( const QByteArray &stuff, quint16 type, bool isEncrypted = false, quint16 index = 0xffff );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//remove a content from this wad
|
2010-12-09 12:30:25 +01:00
|
|
|
//void RemoveContent( quint16 index );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//set the global cert that will be used for all created
|
|
|
|
static void SetGlobalCert( const QByteArray &stuff );
|
|
|
|
|
|
|
|
//pack a wad from the given directory
|
2010-12-08 19:07:57 +01:00
|
|
|
static QByteArray FromDirectory( QDir dir );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//get a assembled wad from the list of parts
|
|
|
|
//the first one should be the tmd, the second one the ticket, and the rest are the contents, in order
|
|
|
|
//it will use the global cert
|
|
|
|
static QByteArray FromPartList( QList< QByteArray > stuff, bool isEncrypted = true );
|
|
|
|
|
|
|
|
//get all the parts of this wad put together in a wad ready for writing to disc or whatever
|
2010-12-08 19:07:57 +01:00
|
|
|
const QByteArray Data( quint32 magicWord = 0x49730000, const QByteArray footer = QByteArray() );
|
2010-12-16 21:07:38 +01:00
|
|
|
|
2010-12-21 21:01:39 +01:00
|
|
|
//get the tmd for the wad
|
|
|
|
const QByteArray getTmd();
|
2010-12-16 21:07:38 +01:00
|
|
|
|
2010-12-21 21:01:39 +01:00
|
|
|
//get the tik for the wad
|
|
|
|
const QByteArray getTik();
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//get the decrypted data from a content
|
|
|
|
const QByteArray Content( quint16 i );
|
|
|
|
|
2010-12-21 21:01:39 +01:00
|
|
|
//get the number of contents
|
|
|
|
quint32 content_count();
|
2010-12-16 21:07:38 +01:00
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
//get the last error encountered while trying to do something
|
|
|
|
const QString LastError(){ return errStr; }
|
|
|
|
|
2010-12-08 19:07:57 +01:00
|
|
|
//get a name for a wad as it would be seen in a wii disc update partition
|
|
|
|
//if a path is given, it will check that path for existing wads with the name and append a number to the end "(1)" to avoid duplicate files
|
|
|
|
//returns an empty string if it cant guess the title based on TID
|
|
|
|
static QString WadName( quint64 tid, quint16 version, QString path = QString() );
|
|
|
|
|
2010-12-09 12:30:25 +01:00
|
|
|
//get this Wad's name as it would appear on a disc update partition
|
2010-12-08 19:07:57 +01:00
|
|
|
QString WadName( QString path = QString() );
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
private:
|
|
|
|
bool ok;
|
|
|
|
QString errStr;
|
|
|
|
|
|
|
|
//keep encrypted parts here
|
|
|
|
QList< QByteArray > partsEnc;
|
|
|
|
QByteArray tmdData;
|
|
|
|
QByteArray tikData;
|
|
|
|
QByteArray certData;
|
|
|
|
|
|
|
|
void Err( QString str );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WAD_H
|