2010-12-08 08:26:18 +01:00
|
|
|
#ifndef TOOLS_H
|
|
|
|
#define TOOLS_H
|
|
|
|
#include "includes.h"
|
2010-12-10 04:50:08 +01:00
|
|
|
//#include "
|
2010-12-08 08:26:18 +01:00
|
|
|
|
2011-01-04 01:07:21 +01:00
|
|
|
//#define RU(x,n) (-(-(x) & -(n))) //round up
|
|
|
|
#define RU(N, S) ((((N) + (S) - 1) / (S)) * (S))
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
|
|
|
|
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
|
|
|
|
|
2011-01-02 07:15:26 +01:00
|
|
|
#define NAND_FILE 1
|
|
|
|
#define NAND_DIR 2
|
|
|
|
#define NAND_READ 1
|
|
|
|
#define NAND_WRITE 2
|
|
|
|
#define NAND_RW ( NAND_READ | NAND_WRITE )
|
|
|
|
|
|
|
|
#define NAND_ATTR( type, user, group, other ) ( ( quint8 )( ( type & 3 ) | ( ( user & 3 ) << 6 ) | ( ( group & 3 ) << 4 ) | ( ( other & 3 ) << 2 ) ) )
|
|
|
|
#define NAND_ATTR_TYPE( attr ) ( attr & 3 )
|
|
|
|
#define NAND_ATTR_USER( attr ) ( ( attr >> 6 ) & 3 )
|
|
|
|
#define NAND_ATTR_GROUP( attr ) ( ( attr >> 4 ) & 3 )
|
|
|
|
#define NAND_ATTR_OTHER( attr ) ( ( attr >> 2 ) & 3 )
|
|
|
|
|
|
|
|
#define COMMON_KEY { 0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, 0x48, 0xd9, 0xc5, 0x45, 0x73, 0x81, 0xaa, 0xf7 }
|
2011-01-21 07:21:28 +01:00
|
|
|
#define KOREAN_KEY { 0x63, 0xb8, 0x2b, 0xb4, 0xf4, 0x61, 0x4e, 0x2e, 0x13, 0xf2, 0xfe, 0xfb, 0xba, 0x4c, 0x9b, 0x7e }
|
|
|
|
|
2011-01-02 07:15:26 +01:00
|
|
|
|
|
|
|
#define SD_KEY { 0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d };
|
|
|
|
#define SD_IV { 0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98 };
|
|
|
|
#define MD5_BLANKER { 0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93 };
|
|
|
|
|
2012-01-11 06:29:59 +01:00
|
|
|
// debug helpers
|
|
|
|
#define DBG qDebug() << __PRETTY_FUNCTION__
|
|
|
|
#define WRN qWarning() << __PRETTY_FUNCTION__
|
|
|
|
|
2011-01-02 07:15:26 +01:00
|
|
|
|
|
|
|
#define TITLE_LATEST_VERSION 0xffff
|
|
|
|
//struct used to keep all the data about a NUS request together
|
|
|
|
//when a finished job is returned, the data list will be the TMD, then the ticket, then all the contents
|
|
|
|
struct NusJob
|
|
|
|
{
|
|
|
|
quint64 tid;
|
|
|
|
quint16 version;
|
|
|
|
bool decrypt;
|
|
|
|
QList<QByteArray> data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SaveGame//struct to hold save data
|
|
|
|
{
|
|
|
|
quint64 tid; //tid this data belongs to
|
|
|
|
QStringList entries; //paths of all the files & folders
|
|
|
|
QList<quint8>attr; //attributes for each file & folder in the save
|
|
|
|
QList<QByteArray> data; //data for each file. size of this list should equal the number of files in the above list
|
|
|
|
};
|
|
|
|
|
2010-12-10 04:50:08 +01:00
|
|
|
char ascii( char s );
|
2010-12-08 08:26:18 +01:00
|
|
|
void hexdump( const void *d, int len );
|
|
|
|
void hexdump( const QByteArray &d, int from = 0, int len = -1 );
|
|
|
|
|
|
|
|
void hexdump12( const void *d, int len );
|
|
|
|
void hexdump12( const QByteArray &d, int from = 0, int len = -1 );
|
|
|
|
|
|
|
|
//simplified functions for crypto shit
|
2010-12-23 17:17:46 +01:00
|
|
|
void AesSetKey( const QByteArray &key );
|
|
|
|
QByteArray AesDecrypt( quint16 index, const QByteArray &source );
|
|
|
|
QByteArray AesEncrypt( quint16 index, const QByteArray &source );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
2010-12-23 17:17:46 +01:00
|
|
|
QByteArray GetSha1( const QByteArray &stuff );
|
2011-01-04 01:07:21 +01:00
|
|
|
QByteArray GetMd5( const QByteArray &stuff );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
2011-01-02 07:15:26 +01:00
|
|
|
bool IsValidSave( const SaveGame &save );
|
|
|
|
const QByteArray DataFromSave( const SaveGame &save, const QString &name );
|
2011-01-04 06:37:50 +01:00
|
|
|
quint32 SaveItemSize( const SaveGame &save );
|
2011-01-02 07:15:26 +01:00
|
|
|
quint8 AttrFromSave( const SaveGame &save, const QString &name );
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
//get a padded version of the given buffer
|
|
|
|
QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo );
|
|
|
|
|
2010-12-08 19:07:57 +01:00
|
|
|
//read a file into a bytearray
|
|
|
|
QByteArray ReadFile( const QString &path );
|
|
|
|
|
2010-12-09 12:30:25 +01:00
|
|
|
//save a file to disc
|
2010-12-23 17:17:46 +01:00
|
|
|
bool WriteFile( const QString &path, const QByteArray &ba );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
2011-05-28 08:50:16 +02:00
|
|
|
//cleanup an svn revision string
|
|
|
|
QString CleanSvnStr( const QString &orig );
|
|
|
|
|
2010-12-08 19:07:57 +01:00
|
|
|
#define CERTS_DAT_SIZE 2560
|
|
|
|
extern const quint8 certs_dat[ CERTS_DAT_SIZE ];
|
|
|
|
extern const quint8 root_dat[];
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
#endif // TOOLS_H
|