* adding stuff to convert to/from data.bin for saves

git-svn-id: http://wiiqt.googlecode.com/svn/trunk@34 389f4c8b-5dfe-645f-db0e-df882bc27289
This commit is contained in:
giantpune@gmail.com 2011-01-02 06:15:26 +00:00
parent 7570278999
commit 1994e8bdda
50 changed files with 6457 additions and 3002 deletions

View File

@ -9,7 +9,7 @@
*/
//#include <stdio.h>
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
@ -343,7 +343,8 @@ void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len) {
u8 block[16];
unsigned int blockno = 0, i;
// debug_printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
//fprintf( stderr,"aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len );
//printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
for (blockno = 0; blockno <= (len / sizeof(block)); blockno++) {
unsigned int fraction;
@ -373,7 +374,8 @@ void aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len) {
u8 block[16];
unsigned int blockno = 0, i;
// debug_printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
//printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
//fprintf( stderr,"aes_encrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
for (blockno = 0; blockno <= (len / sizeof(block)); blockno++) {
unsigned int fraction;

View File

@ -6,7 +6,7 @@ Blocks0to7::Blocks0to7( QList<QByteArray>blocks )
{
_ok = false;
if( !blocks.isEmpty() )
SetBlocks( blocks );
SetBlocks( blocks );
}
bool Blocks0to7::SetBlocks( QList<QByteArray>blocks )
@ -17,14 +17,14 @@ bool Blocks0to7::SetBlocks( QList<QByteArray>blocks )
boot2Infos.clear();
quint16 cnt = blocks.size();
if( cnt != 8 )
return false;
return false;
for( quint16 i = 0; i < cnt; i++ )
{
if( blocks.at( i ).size() != 0x20000 )
{
qWarning() << "Blocks0to7::SetBlocks -> block" << i << "is" << hex << blocks.at( i ).size() << "bytes";
return false;
}
if( blocks.at( i ).size() != 0x20000 )
{
qWarning() << "Blocks0to7::SetBlocks -> block" << i << "is" << hex << blocks.at( i ).size() << "bytes";
return false;
}
}
this->blocks = blocks;
_ok = true;
@ -35,19 +35,19 @@ quint8 Blocks0to7::Boot1Version()
{
if( blocks.size() != 8 )
{
qWarning() << "Blocks0to7::Boot1Version -> not enough blocks" << blocks.size();
return BOOT_1_UNK;
qWarning() << "Blocks0to7::Boot1Version -> not enough blocks" << blocks.size();
return BOOT_1_UNK;
}
QByteArray hash = GetSha1( blocks.at( 0 ) );
if( hash == QByteArray( "\x4a\x7c\x6f\x30\x38\xde\xea\x7a\x07\xd3\x32\x32\x02\x4b\xe9\x5a\xfb\x56\xbf\x65" ) )
return BOOT_1_A;
return BOOT_1_A;
if( hash == QByteArray( "\x2c\xdd\x5a\xff\xd2\xe7\x8c\x53\x76\x16\xa1\x19\xa7\xa2\xe1\xc5\x68\xe9\x1f\x22" ) )
return BOOT_1_B;
return BOOT_1_B;
if( hash == QByteArray( "\xf0\x1e\x8a\xca\x02\x9e\xe0\xcb\x52\x87\xf5\x05\x5d\xa1\xa0\xbe\xd2\xa5\x33\xfa" ) )
return BOOT_1_C;
return BOOT_1_C;
if( hash == QByteArray( "\x8d\x9e\xcf\x2f\x8f\x98\xa3\xc1\x07\xf1\xe5\xe3\x6f\xf2\x4d\x57\x7e\xac\x36\x08" ) )
return BOOT_1_D; //displayed as "boot1?" in ceilingcat
return BOOT_1_D; //displayed as "boot1?" in ceilingcat
qWarning() << "Blocks0to7::Boot1Version -> unknown boot1 hash:" << hash.toHex();
@ -62,83 +62,83 @@ QList<Boot2Info> Blocks0to7::Boot2Infos()
{
if( !boot2Infos.isEmpty() )
{
//qDebug() << "Blocks0to7::Boot2Infos() returning data from last time";
return boot2Infos;
//qDebug() << "Blocks0to7::Boot2Infos() returning data from last time";
return boot2Infos;
}
QList< Boot2Info > ret;
if( blocks.size() != 8 )
return ret;
return ret;
quint16 cnt = blocks.size();
if( cnt != 8 )
return ret;
return ret;
//get all the blockmaps
quint16 newest = 0;
quint8 lbm[ 8 ];
for( quint8 i = 1; i < 8; i++ )
{
Boot2Info info = GetBlockMap( blocks.at( i ) );
if( info.state == BOOT_2_ERROR )//this block doesnt contain a decent blockmap
continue;
Boot2Info info = GetBlockMap( blocks.at( i ) );
if( info.state == BOOT_2_ERROR )//this block doesnt contain a decent blockmap
continue;
info.secondBlock = i; //this one is easy enough
//find the first block that belongs to this second one
if( i > 4 )//blocks are backwards
{
bool found = false;
for( quint8 j = 7; j > i; j++ )
{
if( info.blockMap[ j ] )//marked bad
continue;
info.secondBlock = i; //this one is easy enough
//find the first block that belongs to this second one
if( i > 4 )//blocks are backwards
{
bool found = false;
for( quint8 j = 7; j > i; j++ )
{
if( info.blockMap[ j ] )//marked bad
continue;
if( ( ( j > i + 1 ) && !info.blockMap[ i + 1 ] )//probably a much cleaner way to write this
|| ( j == 6 && !info.blockMap[ 7 ] ) ) //but basically check for a couple stupid shit in the layout that really shouldnt ever happen
break;
if( ( ( j > i + 1 ) && !info.blockMap[ i + 1 ] )//probably a much cleaner way to write this
|| ( j == 6 && !info.blockMap[ 7 ] ) ) //but basically check for a couple stupid shit in the layout that really shouldnt ever happen
break;
info.firstBlock = j;
found = true;
break;
}
if( !found )
continue;
}
else//blocks are forwards
{
bool found = false;
for( quint8 j = 0; j < i; j++ )
{
if( info.blockMap[ j ] )//marked bad
continue;
info.firstBlock = j;
found = true;
break;
}
if( !found )
continue;
}
else//blocks are forwards
{
bool found = false;
for( quint8 j = 0; j < i; j++ )
{
if( info.blockMap[ j ] )//marked bad
continue;
info.firstBlock = j;
found = true;
break;
}
if( !found )
continue;
found = false;
//probably a much cleaner way to write this
//but basically check for a couple stupid shit in the layout that really shouldnt ever happen
for( quint8 j = info.firstBlock + 1; j < info.secondBlock && !found; j++ )
{
if( info.blockMap[ j ] )//marked bad
continue;
found = true;
}
if( found )//this means there is some other good block between the first block and this one that has the block map
continue;
}
//we made it this far, it means that so far we have a correct looking blockmap that points to this copy of boot2
if( info.generation > newest )
{
newest = info.generation;
for( quint8 j = 0; j < 8; j++ )
lbm[ j ] = info.blockMap[ j ];
}
info.firstBlock = j;
found = true;
break;
}
if( !found )
continue;
found = false;
//probably a much cleaner way to write this
//but basically check for a couple stupid shit in the layout that really shouldnt ever happen
for( quint8 j = info.firstBlock + 1; j < info.secondBlock && !found; j++ )
{
if( info.blockMap[ j ] )//marked bad
continue;
found = true;
}
if( found )//this means there is some other good block between the first block and this one that has the block map
continue;
}
//we made it this far, it means that so far we have a correct looking blockmap that points to this copy of boot2
if( info.generation > newest )
{
newest = info.generation;
for( quint8 j = 0; j < 8; j++ )
lbm[ j ] = info.blockMap[ j ];
}
ret << info;
ret << info;
}
//qDebug() << "newest blockmap" << QByteArray( (const char*)&lbm, 8 ).toHex();
@ -147,29 +147,29 @@ QList<Boot2Info> Blocks0to7::Boot2Infos()
bool foundBackup = false;
for( quint8 i = 0; i < cnt; i++ )
{
ret[ i ] = CheckHashes( ret[ i ] );//check all the hashes and stuff
if( !foundBoot && !lbm[ ret.at( i ).firstBlock ] && !lbm[ ret.at( i ).secondBlock ] )
{
//qDebug() << "copy" << i << "is used when booting";
ret[ i ].state |= BOOT_2_USED_TO_BOOT;
//ret[ i ].usedToBoot = true;
foundBoot = true;
}
else if( lbm[ ret.at( i ).firstBlock ] || lbm[ ret.at( i ).secondBlock ] )
{
ret[ i ].state |= BOOT_2_MARKED_BAD;
}
ret[ i ] = CheckHashes( ret[ i ] );//check all the hashes and stuff
if( !foundBoot && !lbm[ ret.at( i ).firstBlock ] && !lbm[ ret.at( i ).secondBlock ] )
{
//qDebug() << "copy" << i << "is used when booting";
ret[ i ].state |= BOOT_2_USED_TO_BOOT;
//ret[ i ].usedToBoot = true;
foundBoot = true;
}
else if( lbm[ ret.at( i ).firstBlock ] || lbm[ ret.at( i ).secondBlock ] )
{
ret[ i ].state |= BOOT_2_MARKED_BAD;
}
}
for( quint8 i = ret.size(); !foundBackup && i > 0; i-- )
{
if( !lbm[ ret.at( i - 1 ).firstBlock ] && !lbm[ ret.at( i - 1 ).secondBlock ] && ret.at( i - 1 ).firstBlock > ret.at( i - 1 ).secondBlock )
{
//qDebug() << "copy" << i << "is used when booting from backup";
ret[ i - 1 ].state |= BOOT_2_BACKUP_COPY;
foundBackup = true;
if( !foundBoot )
ret[ i - 1 ].state |= BOOT_2_USED_TO_BOOT;
}
if( !lbm[ ret.at( i - 1 ).firstBlock ] && !lbm[ ret.at( i - 1 ).secondBlock ] && ret.at( i - 1 ).firstBlock > ret.at( i - 1 ).secondBlock )
{
//qDebug() << "copy" << i << "is used when booting from backup";
ret[ i - 1 ].state |= BOOT_2_BACKUP_COPY;
foundBackup = true;
if( !foundBoot )
ret[ i - 1 ].state |= BOOT_2_USED_TO_BOOT;
}
}
boot2Infos = ret;
return ret;
@ -180,22 +180,22 @@ Boot2Info Blocks0to7::GetBlockMap( QByteArray block )
Boot2Info ret;
ret.state = BOOT_2_ERROR;
if( block.size() != 0x20000 )
return ret;
return ret;
QByteArray first = block.mid( 0x1f800, 0x4c );
QByteArray second = block.mid( 0x1f84c, 0x4c );
QByteArray third = block.mid( 0x1f898, 0x4c );
QByteArray goodOne = QByteArray( "\x26\xF2\x9A\x40\x1E\xE6\x84\xCF" );
if( first.startsWith( goodOne ) && ( first == second || first == third ) )
goodOne = first;
goodOne = first;
else if( second.startsWith( goodOne ) && ( second == third ) )
goodOne = second;
goodOne = second;
else
return ret;
return ret;
ret.generation = goodOne.mid( 8, 4 ).toHex().toInt( NULL, 16 );
for( quint8 i = 0; i < 8; i++ )
ret.blockMap[ i ] = goodOne.at( i + 12 );
ret.blockMap[ i ] = goodOne.at( i + 12 );
ret.state = BOOT_2_TIK_SIG_OK; //just assign this for now. it will be corrected before this data leaves the class
return ret;
@ -219,7 +219,7 @@ Boot2Info Blocks0to7::CheckHashes( Boot2Info info )
b.read( (char*)&tmp, 4 );
headerSize = qFromBigEndian( tmp );
if( headerSize != 0x20 )
return ret;
return ret;
b.read( (char*)&tmp, 4 );
dataOff = qFromBigEndian( tmp );
@ -237,8 +237,8 @@ Boot2Info Blocks0to7::CheckHashes( Boot2Info info )
Ticket ticket( tikD );
if( t.Tid() != 0x100000001ull || ticket.Tid() != 0x100000001ull )
{
qWarning() << "Blocks0to7::CheckHashes -> bad TID";
return ret;
qWarning() << "Blocks0to7::CheckHashes -> bad TID";
return ret;
}
ret.state = 0;
int res = check_cert_chain( tikD );
@ -249,22 +249,22 @@ Boot2Info Blocks0to7::CheckHashes( Boot2Info info )
case ERROR_SUB_TYPE:
case ERROR_RSA_TYPE_UNKNOWN:
case ERROR_CERT_NOT_FOUND:
ret.state = BOOT_2_ERROR;
qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
ret.state = BOOT_2_ERROR;
qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
case ERROR_RSA_TYPE_MISMATCH:
case ERROR_RSA_HASH:
ret.state = BOOT_2_BAD_SIGNATURE;
//qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
ret.state = BOOT_2_BAD_SIGNATURE;
//qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
case ERROR_RSA_FAKESIGNED:
ret.state |= BOOT_2_TIK_FAKESIGNED;
break;
ret.state |= BOOT_2_TIK_FAKESIGNED;
break;
case ERROR_SUCCESS:
ret.state |= BOOT_2_TIK_SIG_OK;
break;
ret.state |= BOOT_2_TIK_SIG_OK;
break;
}
res = check_cert_chain( tmdD );
switch( res )
@ -274,33 +274,33 @@ Boot2Info Blocks0to7::CheckHashes( Boot2Info info )
case ERROR_SUB_TYPE:
case ERROR_RSA_TYPE_UNKNOWN:
case ERROR_CERT_NOT_FOUND:
ret.state = BOOT_2_ERROR;
//qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
ret.state = BOOT_2_ERROR;
//qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
case ERROR_RSA_TYPE_MISMATCH:
case ERROR_RSA_HASH:
ret.state = BOOT_2_BAD_SIGNATURE;
//qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
ret.state = BOOT_2_BAD_SIGNATURE;
//qWarning() << "check_cert_chain( tikD ):" << res;
return ret;
break;
case ERROR_RSA_FAKESIGNED:
{
ret.state |= BOOT_2_TMD_FAKESIGNED;
if( tmdD.contains( "BM1.1" ) )
ret.version = BOOTMII_11;
else if( tmdD.contains( "BM1.3" ) )
ret.version = BOOTMII_13;
else
ret.version = BOOTMII_UNK;
}
break;
{
ret.state |= BOOT_2_TMD_FAKESIGNED;
if( tmdD.contains( "BM1.1" ) )
ret.version = BOOTMII_11;
else if( tmdD.contains( "BM1.3" ) )
ret.version = BOOTMII_13;
else
ret.version = BOOTMII_UNK;
}
break;
case ERROR_SUCCESS:
{
ret.state |= BOOT_2_TMD_SIG_OK;
ret.version = t.Version();
}
break;
{
ret.state |= BOOT_2_TMD_SIG_OK;
ret.version = t.Version();
}
break;
}
//now decrypt boot2 and check the hash ( only checking 1 content because thats all there is )
@ -311,7 +311,7 @@ Boot2Info Blocks0to7::CheckHashes( Boot2Info info )
decD.resize( t.Size( 0 ) );
QByteArray realHash = GetSha1( decD );
if( realHash != t.Hash( 0 ) )
ret.state |= BOOT_2_BAD_CONTENT_HASH;
ret.state |= BOOT_2_BAD_CONTENT_HASH;
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,6 @@
#include "blocks0to7.h"
#include "nandspare.h"
#define NAND_FILE 1
#define NAND_DIR 2
#define NAND_READ 1
#define NAND_WRITE 2
#define NAND_RW ( NAND_READ | NAND_WRITE )
struct fst_t
{
quint8 filename[ 0xc ];

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,16 @@
#ifndef NANDDUMP_H
#define NANDDUMP_H
#include "nusdownloader.h"
#include "includes.h"
#include "sharedcontentmap.h"
#include "uidmap.h"
#include "wad.h"
#include "tools.h"
struct SaveGame//struct to hold save data
{
quint64 tid; //tid this data belongs to
QStringList entries; //paths of all the files & folders
QList<bool>isFile; //type of each entry. false = folder, true = file
QList<QByteArray> data; //data for each file. size of this list should equal the number of files in the above list
};
//there is no way to know what attributes the save items were meant to have when reading from an extracted dump
//these are just generic attributes that should work for all save data when writing back to a real nand
#define DEFAULT_SAVE_ATTR_FILE NAND_ATTR( NAND_FILE, NAND_RW, NAND_RW, 0 )
#define DEFAULT_SAVE_ATTR_DIR NAND_ATTR( NAND_DIR, NAND_RW, NAND_RW, 0 )
//class for handeling an extracted wii nand filesystem
//! nothing can be done unless basePath is set. do this either by setting it in the constructor, or by calling SetPath()
@ -70,6 +67,10 @@ public:
// returns a map of < tid, version >
QMap< quint64, quint16 > GetInstalledTitles();
//get a list of all available saves in this nand
// returns <tid, size>
QMap< quint64, quint32 > GetSaveList();
//write the current uid & content.map to the PC
//failure to make sure this is done can end up with a broken nand
bool Flush();
@ -91,6 +92,9 @@ public:
// if no save is found, it will return a SaveData object with an empty list of entries
SaveGame GetSaveData( quint64 tid );
//deletes everything in the "data" folder for a title
bool DeleteSave( quint64 tid );
//installs a save to the nand
bool InstallSave( const SaveGame &save );
@ -109,8 +113,8 @@ public:
const QString ToNandPath( const QString &path );
const QString FromNandPath( const QString &path );
//sanity check a save object
static bool IsValidSave( const SaveGame &save );
//get the current basepath
const QString BasePath();

View File

@ -14,8 +14,8 @@ quint8 NandSpare::Parity( quint8 x )
quint8 y = 0;
while( x )
{
y ^= ( x & 1 );
x >>= 1;
y ^= ( x & 1 );
x >>= 1;
}
return y;
}
@ -23,7 +23,7 @@ quint8 NandSpare::Parity( quint8 x )
QByteArray NandSpare::CalcEcc( QByteArray in )
{
if( in.size() != 0x800 )
return QByteArray();
return QByteArray();
quint8 a[ 12 ][ 2 ];
quint32 a0, a1;
@ -35,41 +35,41 @@ QByteArray NandSpare::CalcEcc( QByteArray in )
for( int k = 0; k < 4; k++ )
{
memset( a, 0, sizeof a );
for( int i = 0; i < 512; i++ )
{
x = data[ i ];
for( int j = 0; j < 9; j++ )
a[ 3 + j ][ ( i >> j ) & 1 ] ^= x;
}
memset( a, 0, sizeof a );
for( int i = 0; i < 512; i++ )
{
x = data[ i ];
for( int j = 0; j < 9; j++ )
a[ 3 + j ][ ( i >> j ) & 1 ] ^= x;
}
x = a[ 3 ][ 0 ] ^ a[ 3 ][ 1 ];
a[ 0 ][ 0 ] = x & 0x55;
a[ 0 ][ 1 ] = x & 0xaa;
a[ 1 ][ 0 ] = x & 0x33;
a[ 1 ][ 1 ] = x & 0xcc;
a[ 2 ][ 0 ] = x & 0x0f;
a[ 2 ][ 1 ] = x & 0xf0;
x = a[ 3 ][ 0 ] ^ a[ 3 ][ 1 ];
a[ 0 ][ 0 ] = x & 0x55;
a[ 0 ][ 1 ] = x & 0xaa;
a[ 1 ][ 0 ] = x & 0x33;
a[ 1 ][ 1 ] = x & 0xcc;
a[ 2 ][ 0 ] = x & 0x0f;
a[ 2 ][ 1 ] = x & 0xf0;
for( int j = 0; j < 12; j++ )
{
a[ j ][ 0 ] = Parity( a[ j ][ 0 ]);
a[ j ][ 1 ] = Parity( a[ j ][ 1 ]);
}
a0 = a1 = 0;
for( int j = 0; j < 12; j++ )
{
a[ j ][ 0 ] = Parity( a[ j ][ 0 ]);
a[ j ][ 1 ] = Parity( a[ j ][ 1 ]);
}
a0 = a1 = 0;
for( int j = 0; j < 12; j++ )
{
a0 |= a[ j ][ 0 ] << j;
a1 |= a[ j ][ 1 ] << j;
}
ecc[ 0 ] = a0;
ecc[ 1 ] = a0 >> 8;
ecc[ 2 ] = a1;
ecc[ 3 ] = a1 >> 8;
for( int j = 0; j < 12; j++ )
{
a0 |= a[ j ][ 0 ] << j;
a1 |= a[ j ][ 1 ] << j;
}
ecc[ 0 ] = a0;
ecc[ 1 ] = a0 >> 8;
ecc[ 2 ] = a1;
ecc[ 3 ] = a1 >> 8;
data += 512;
ecc += 4;
data += 512;
ecc += 4;
}
return ret;
}
@ -93,7 +93,7 @@ void hmac_init(hmac_ctx *ctx, const char *key, int key_size)
memcpy( ctx->key,key,key_size );
for( int i = 0; i < 0x40; ++i )
ctx->key[ i ] ^= 0x36; // ipad
ctx->key[ i ] ^= 0x36; // ipad
SHA1Reset( &ctx->hash_ctx );
SHA1Input( &ctx->hash_ctx, ctx->key, 0x40 );
@ -115,10 +115,10 @@ void hmac_final( hmac_ctx *ctx, unsigned char *hmac )
// this sha1 implementation is buggy, needs to switch endian
for( int i = 0;i < 5;++i )
{
wbe32( hash + 4 * i, ctx->hash_ctx.Message_Digest[ i ] );
wbe32( hash + 4 * i, ctx->hash_ctx.Message_Digest[ i ] );
}
for( int i = 0; i < 0x40; ++i )
ctx->key[i] ^= 0x36^0x5c; // opad
ctx->key[i] ^= 0x36^0x5c; // opad
SHA1Reset(&ctx->hash_ctx);
SHA1Input(&ctx->hash_ctx,ctx->key,0x40);
@ -128,7 +128,7 @@ void hmac_final( hmac_ctx *ctx, unsigned char *hmac )
//hexdump(ctx->hash_ctx.Message_Digest, 0x14);
for( int i = 0; i < 5; ++i )
{
wbe32( hash + 4 * i, ctx->hash_ctx.Message_Digest[ i ] );
wbe32( hash + 4 * i, ctx->hash_ctx.Message_Digest[ i ] );
}
memcpy( hmac, hash, 0x14 );
}
@ -175,11 +175,11 @@ void fs_hmac_data( const unsigned char *data, quint32 uid, const unsigned char *
wbe32( extra + 0x14, entry_n );
wbe32( extra + 0x18, x3 );
// fprintf(stderr,"extra (%s): \nX ",name);
// for(i=0;i<0x20;++i){
// fprintf(stderr,"%02X ",extra[i]);
// if(!((i+1)&0xf)) fprintf(stderr,"\nX ");
// }
// fprintf(stderr,"extra (%s): \nX ",name);
// for(i=0;i<0x20;++i){
// fprintf(stderr,"%02X ",extra[i]);
// if(!((i+1)&0xf)) fprintf(stderr,"\nX ");
// }
fs_hmac_generic( data, 0x4000, extra, 0x40, hmac );
}
@ -187,7 +187,7 @@ QByteArray NandSpare::Get_hmac_data( const QByteArray cluster, quint32 uid, cons
{
//qDebug() << "NandSpare::Get_hmac_data" << hex << cluster.size() << uid << QString( QByteArray( (const char*)name, 12 ) ) << entry_n << x3 << blk;
if( hmacKey.size() != 0x14 || cluster.size() != 0x4000 )
return QByteArray();
return QByteArray();
fs_hmac_set_key( hmacKey.data(), 0x14 );
@ -202,8 +202,8 @@ QByteArray NandSpare::Get_hmac_meta( const QByteArray cluster, quint16 super_blk
//qDebug() << "NandSpare::Get_hmac_meta" << hex << super_blk;
if( hmacKey.size() != 0x14 || cluster.size() != 0x40000 )
{
//qDebug() << "NandSpare::Get_hmac_meta" << hex << hmacKey.size() << cluster.size();
return QByteArray();
//qDebug() << "NandSpare::Get_hmac_meta" << hex << hmacKey.size() << cluster.size();
return QByteArray();
}
fs_hmac_set_key( hmacKey.data(), 0x14 );

View File

@ -25,8 +25,8 @@ void NusDownloader::GetTitle( const NusJob &job )
if( !running )
{
//qDebug() << "no job is running, starting this one";
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );
//qDebug() << "no job is running, starting this one";
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );
}
running = true;
}
@ -39,7 +39,7 @@ void NusDownloader::GetTitles( const QList<NusJob> &jobs )
totalJobs += jobs.size();
if( !running )
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );
running = true;
}
@ -60,7 +60,7 @@ quint32 NusDownloader::TitleSizeDownloaded()
{
quint32 ret = 0;
for( int i = 0; i < currentJob.data.size(); i++ )
ret += currentJob.data.at( i ).size();
ret += currentJob.data.at( i ).size();
return ret;
}
@ -70,14 +70,14 @@ void NusDownloader::StartNextJob()
//qDebug() << "NusDownloader::StartNextJob";
if( jobList.isEmpty() )//nothing else to do
{
currentJob.tid = 0;
totalJobs = 0;
emit SendTitleProgress( 100 );
emit SendTotalProgress( 100 );
running = false;
//qDebug() << "done";
emit SendDone();
return;
currentJob.tid = 0;
totalJobs = 0;
emit SendTitleProgress( 100 );
emit SendTotalProgress( 100 );
running = false;
//qDebug() << "done";
emit SendDone();
return;
}
//pull the first title from the list
currentJob = jobList.takeFirst();
@ -87,26 +87,26 @@ void NusDownloader::StartNextJob()
tmdJob.index = IDX_TMD;
if( currentJob.version != TITLE_LATEST_VERSION )
{
tmdJob.name = QString( "tmd.%1" ).arg( currentJob.version );
QByteArray stuff = GetDataFromCache( tmdJob );
//DbgJoB( currentJob );
if( !stuff.isEmpty() )
{
//qDebug() << "tmdJob.data size:" << hex << stuff.size();
//DbgJoB( currentJob );
ReadTmdAndGetTicket( stuff );
}
else
{
dlJob = tmdJob;
QTimer::singleShot( 500, this, SLOT( StartDownload() ) );
}
tmdJob.name = QString( "tmd.%1" ).arg( currentJob.version );
QByteArray stuff = GetDataFromCache( tmdJob );
//DbgJoB( currentJob );
if( !stuff.isEmpty() )
{
//qDebug() << "tmdJob.data size:" << hex << stuff.size();
//DbgJoB( currentJob );
ReadTmdAndGetTicket( stuff );
}
else
{
dlJob = tmdJob;
QTimer::singleShot( 500, this, SLOT( StartDownload() ) );
}
}
else//download the latest tmd to get the version
{
tmdJob.name = "tmd";
dlJob = tmdJob;
QTimer::singleShot( 500, this, SLOT( StartDownload() ) );
tmdJob.name = "tmd";
dlJob = tmdJob;
QTimer::singleShot( 500, this, SLOT( StartDownload() ) );
}
}
@ -116,20 +116,20 @@ QByteArray NusDownloader::GetDataFromCache( downloadJob job )
{
//qDebug() << "NusDownloader::GetDataFromCache";
if( cachePath.isEmpty() || currentJob.version == TITLE_LATEST_VERSION )
return QByteArray();
return QByteArray();
QFileInfo fi( cachePath );
if( !fi.exists() || !fi.isDir() )
{
//qWarning() << "NusDownloader::GetDataFromCache -> cachePath is not a directory";
return QByteArray();
//qWarning() << "NusDownloader::GetDataFromCache -> cachePath is not a directory";
return QByteArray();
}
QFile f( GetCachePath( job.index ) );
if( !f.exists() || !f.open( QIODevice::ReadOnly ) )
{
//qWarning() << "NusDownloader::GetDataFromCache -> file cant be opened for reading" << QFileInfo( f ).absoluteFilePath();
return QByteArray();
//qWarning() << "NusDownloader::GetDataFromCache -> file cant be opened for reading" << QFileInfo( f ).absoluteFilePath();
return QByteArray();
}
//qDebug() << "reading data from PC";
@ -146,18 +146,18 @@ void NusDownloader::ReadTmdAndGetTicket( const QByteArray &ba )
curTmd = Tmd( ba );
if( curTmd.Tid() != currentJob.tid )
{
qDebug() << curTmd.Tid() << currentJob.tid;
CurrentJobErrored( tr( "TID in TMD doesn't match expected." ) );
return;
qDebug() << curTmd.Tid() << currentJob.tid;
CurrentJobErrored( tr( "TID in TMD doesn't match expected." ) );
return;
}
if( currentJob.version == TITLE_LATEST_VERSION )
{
currentJob.version = qFromBigEndian( curTmd.payload()->title_version );
currentJob.version = qFromBigEndian( curTmd.payload()->title_version );
}
else if( currentJob.version != qFromBigEndian( curTmd.payload()->title_version ) )
{
CurrentJobErrored( tr( "Version in TMD doesn't match expected." ) );
return;
CurrentJobErrored( tr( "Version in TMD doesn't match expected." ) );
return;
}
//add the tmd data to the current job return
currentJob.data << ba;
@ -166,7 +166,7 @@ void NusDownloader::ReadTmdAndGetTicket( const QByteArray &ba )
totalTitleSize = 0;
for( quint32 i = 0; i < qFromBigEndian( curTmd.payload()->num_contents ); i++ )
{
totalTitleSize += curTmd.Size( i );
totalTitleSize += curTmd.Size( i );
}
totalTitleSize += ba.size() + 0x9a4;//ticket size for ios 9. should be good enough for everything else
@ -177,18 +177,18 @@ void NusDownloader::ReadTmdAndGetTicket( const QByteArray &ba )
QByteArray stuff = GetDataFromCache( tikJob );
if( stuff.isEmpty() )
{
dlJob = tikJob;
QTimer::singleShot( 0, this, SLOT( StartDownload() ) );
dlJob = tikJob;
QTimer::singleShot( 0, this, SLOT( StartDownload() ) );
}
else
{
Ticket t( stuff );
//set this key to decrypt contents
decKey = t.DecryptedKey();
//AesSetKey( t.DecryptedKey() );
//add the ticket data to the return
currentJob.data << stuff;
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );
Ticket t( stuff );
//set this key to decrypt contents
decKey = t.DecryptedKey();
//AesSetKey( t.DecryptedKey() );
//add the ticket data to the return
currentJob.data << stuff;
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );
}
}
@ -198,8 +198,8 @@ bool NusDownloader::SaveDataToCache( const QString &path, const QByteArray &stuf
//make sure there is all the parent folders needed to hold this folder
if( path.count( "/" ) < 4 || !path.startsWith( cachePath + "/" ))
{
qWarning() << "NusDownloader::SaveDataToCache -> bad path" << path << cachePath;
return false;
qWarning() << "NusDownloader::SaveDataToCache -> bad path" << path << cachePath;
return false;
}
QString parent = path;//really ugly, but somehow still prettier than a recursing mkdir function
parent.resize( parent.lastIndexOf( "/" ) );
@ -207,19 +207,19 @@ bool NusDownloader::SaveDataToCache( const QString &path, const QByteArray &stuf
QDir d( cachePath );
if( !d.exists() || !d.mkpath( parent ) )
{
qWarning() << "NusDownloader::SaveDataToCache -> cant create directory" << QString( d.absolutePath() + "/" + path );
return false;
qWarning() << "NusDownloader::SaveDataToCache -> cant create directory" << QString( d.absolutePath() + "/" + path );
return false;
}
QFile f( path );
if( f.exists() )
{
qWarning() << "NusDownloader::SaveDataToCache -> file already exists" << path;
return false;
qWarning() << "NusDownloader::SaveDataToCache -> file already exists" << path;
return false;
}
if( !f.open( QIODevice::WriteOnly ) )
{
qWarning() << "NusDownloader::SaveDataToCache -> can't create file" << path;
return false;
qWarning() << "NusDownloader::SaveDataToCache -> can't create file" << path;
return false;
}
f.write( stuff );//probably should check the return values on these. but if they dont go right, then the person has bigger things to worry about
f.close();
@ -252,18 +252,18 @@ void NusDownloader::GetNextItemForCurrentTitle()
//DbgJoB( currentJob );
if( currentJob.data.size() < 2 )
{
qDebug() << "currentJob.data.size() < 2 )" << currentJob.data.size();
CurrentJobErrored( tr( "Tried to download contents without having the TMD & Ticket") );
return;
qDebug() << "currentJob.data.size() < 2 )" << currentJob.data.size();
CurrentJobErrored( tr( "Tried to download contents without having the TMD & Ticket") );
return;
}
quint32 alreadyHave = currentJob.data.size() - 2;//number of contest from this title already gotten
if( alreadyHave >= qFromBigEndian( curTmd.payload()->num_contents ) )//WTF
{
qDebug() << "alreadyHave >= qFromBigEndian( curTmd.payload()->num_contents )" << alreadyHave << qFromBigEndian( curTmd.payload()->num_contents );
CurrentJobErrored( tr( "Tried to download more contents then this title has." ) );
return;
qDebug() << "alreadyHave >= qFromBigEndian( curTmd.payload()->num_contents )" << alreadyHave << qFromBigEndian( curTmd.payload()->num_contents );
CurrentJobErrored( tr( "Tried to download more contents then this title has." ) );
return;
}
//send progress about how much of this title we already have
int prog = (int)( (float)( (float)TitleSizeDownloaded() / (float)totalTitleSize ) * 100.0f );
@ -274,30 +274,30 @@ void NusDownloader::GetNextItemForCurrentTitle()
QByteArray stuff = GetDataFromCache( appJob );
if( stuff.isEmpty() )
{
dlJob = appJob;
QTimer::singleShot( 0, this, SLOT( StartDownload() ) );
//StartDownload( appJob );
dlJob = appJob;
QTimer::singleShot( 0, this, SLOT( StartDownload() ) );
//StartDownload( appJob );
}
else
{
//hexdump( stuff );
if( !DecryptCheckHashAndAppendData( stuff, appJob.index ) )
{
CurrentJobErrored( tr( "Cached data has a different hash than expected." ) );
return;
}
//qDebug() << "hash matched for index" << alreadyHave;
if( alreadyHave + 1 < qFromBigEndian( curTmd.payload()->num_contents ) )
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
//hexdump( stuff );
if( !DecryptCheckHashAndAppendData( stuff, appJob.index ) )
{
CurrentJobErrored( tr( "Cached data has a different hash than expected." ) );
return;
}
//qDebug() << "hash matched for index" << alreadyHave;
if( alreadyHave + 1 < qFromBigEndian( curTmd.payload()->num_contents ) )
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
else
{
int progress = (int)( ( (float)( totalJobs - jobList.size() ) / (float)totalJobs ) * 100.0f );
emit SendTotalProgress( progress );
emit SendTitleProgress( 100 );
emit SendData( currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );//start next job
}
else
{
int progress = (int)( ( (float)( totalJobs - jobList.size() ) / (float)totalJobs ) * 100.0f );
emit SendTotalProgress( progress );
emit SendTitleProgress( 100 );
emit SendData( currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );//start next job
}
}
}
@ -306,11 +306,11 @@ QString NusDownloader::GetCachePath( quint32 idx )
{
//qDebug() << "NusDownloader::GetCachePath" << currentJob.version << currentJob.tid;
if( currentJob.version == TITLE_LATEST_VERSION || !currentJob.tid )//c'mon guy
return QString();
return QString();
QString path = cachePath;
if( path.endsWith( "/" ) )
path.resize( path.size() - 1 );
path.resize( path.size() - 1 );
QString idPath = QString( "/%1" ).arg( currentJob.tid, 16, 16, QChar( '0' ) );
idPath.insert( 9, "/" );
QString verPath = QString( "/v%1/" ).arg( currentJob.version );
@ -318,14 +318,14 @@ QString NusDownloader::GetCachePath( quint32 idx )
switch( idx )
{
case IDX_CETK:
path += "cetk";
break;
path += "cetk";
break;
case IDX_TMD:
path += QString( "tmd.%1" ).arg( currentJob.version );
break;
path += QString( "tmd.%1" ).arg( currentJob.version );
break;
default:
path += curTmd.Cid( idx );
break;
path += curTmd.Cid( idx );
break;
}
return path;
}
@ -335,12 +335,12 @@ void NusDownloader::DbgJoB( NusJob job )
{
QString dataStuff = QString( "%1 items:" ).arg( job.data.size() );
for( int i = 0; i < job.data.size(); i++ )
dataStuff += QString( " %1" ).arg( job.data.at( i ).size(), 0, 16, QChar( ' ' ) );
dataStuff += QString( " %1" ).arg( job.data.at( i ).size(), 0, 16, QChar( ' ' ) );
qDebug() << QString( "NusJob( %1, %2, %3, %4 )" )
.arg( job.tid, 16, 16, QChar( '0' ) )
.arg( job.version ).arg( job.decrypt ? "decrypted" : "encrypted" )
.arg( dataStuff );
.arg( job.tid, 16, 16, QChar( '0' ) )
.arg( job.version ).arg( job.decrypt ? "decrypted" : "encrypted" )
.arg( dataStuff );
}
//check a hash and add the data to the return item
@ -357,17 +357,17 @@ bool NusDownloader::DecryptCheckHashAndAppendData( const QByteArray &encData, qu
QByteArray realHash = GetSha1( decData );
if( realHash != curTmd.Hash( idx ) )
{
qWarning() << "NusDownloader::DecryptCheckHashAndAppendData -> hash doesnt match for content" << hex << idx;
//CurrentJobErrored( tr( "Downloaded data has a different hash than expected." ) );
hexdump( realHash );
hexdump( curTmd.Hash( idx ) );
return false;
qWarning() << "NusDownloader::DecryptCheckHashAndAppendData -> hash doesnt match for content" << hex << idx;
//CurrentJobErrored( tr( "Downloaded data has a different hash than expected." ) );
hexdump( realHash );
hexdump( curTmd.Hash( idx ) );
return false;
}
//add whatever data is requested to the return
if( currentJob.decrypt )
currentJob.data << decData;
currentJob.data << decData;
else
currentJob.data << encData;
currentJob.data << encData;
return true;
}
@ -378,9 +378,9 @@ void NusDownloader::FileIsFinishedDownloading( downloadJob job )
//qDebug() << "NusDownloader::FileIsFinishedDownloading" << job.index;
if( job.data.isEmpty() )
{
qWarning() << "NusDownloader::FileIsFinishedDownloading -> got empty data in return";
CurrentJobErrored( tr( "Error downloading, returned empty data" ) );
return;
qWarning() << "NusDownloader::FileIsFinishedDownloading -> got empty data in return";
CurrentJobErrored( tr( "Error downloading, returned empty data" ) );
return;
}
//this is kinda ugly, but we need to get the path to save the data in the cache
@ -389,66 +389,66 @@ void NusDownloader::FileIsFinishedDownloading( downloadJob job )
switch( job.index )
{
case IDX_TMD:
{
ReadTmdAndGetTicket( job.data );
cPath = GetCachePath( job.index );
}
break;
{
ReadTmdAndGetTicket( job.data );
cPath = GetCachePath( job.index );
}
break;
case IDX_CETK:
{
Ticket t( job.data );
decKey = t.DecryptedKey();
//set this key to decrypt contents
//AesSetKey( t.DecryptedKey() );
//add the ticket data to the return
currentJob.data << job.data;
//start downloading the contents
GetNextItemForCurrentTitle();
{
Ticket t( job.data );
decKey = t.DecryptedKey();
//set this key to decrypt contents
//AesSetKey( t.DecryptedKey() );
//add the ticket data to the return
currentJob.data << job.data;
//start downloading the contents
GetNextItemForCurrentTitle();
cPath = GetCachePath( job.index );
}
break;
cPath = GetCachePath( job.index );
}
break;
default:
{
if( job.index > qFromBigEndian( curTmd.payload()->num_contents ) )
{
qWarning() << "NusDownloader::FileIsFinishedDownloading -> received data that doesnt fit anywhere";
CurrentJobErrored( tr( "I have confused myself and cannot find where some downloaded data goes." ) );
return;
}
if( job.index != currentJob.data.size() - 2 )
{
qWarning() << "NusDownloader::FileIsFinishedDownloading -> index doesnt match what it should";
CurrentJobErrored( tr( "I have confused myself and cannot find where some downloaded data goes." ) );
return;
}
if( !DecryptCheckHashAndAppendData( job.data, job.index ) )
{
CurrentJobErrored( tr( "Downloaded data has a different hash than expected." ) );
return;
}
{
if( job.index > qFromBigEndian( curTmd.payload()->num_contents ) )
{
qWarning() << "NusDownloader::FileIsFinishedDownloading -> received data that doesnt fit anywhere";
CurrentJobErrored( tr( "I have confused myself and cannot find where some downloaded data goes." ) );
return;
}
if( job.index != currentJob.data.size() - 2 )
{
qWarning() << "NusDownloader::FileIsFinishedDownloading -> index doesnt match what it should";
CurrentJobErrored( tr( "I have confused myself and cannot find where some downloaded data goes." ) );
return;
}
if( !DecryptCheckHashAndAppendData( job.data, job.index ) )
{
CurrentJobErrored( tr( "Downloaded data has a different hash than expected." ) );
return;
}
if( job.index == qFromBigEndian( curTmd.payload()->num_contents ) - 1 )//this is the last content for this title
{
int progress = (int)( ( (float)( totalJobs - jobList.size() ) / (float)totalJobs ) * 100.0f );
emit SendTotalProgress( progress );
emit SendTitleProgress( 100 );
emit SendData( currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );//move on to next job
}
if( job.index == qFromBigEndian( curTmd.payload()->num_contents ) - 1 )//this is the last content for this title
{
int progress = (int)( ( (float)( totalJobs - jobList.size() ) / (float)totalJobs ) * 100.0f );
emit SendTotalProgress( progress );
emit SendTitleProgress( 100 );
emit SendData( currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );//move on to next job
}
else
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
else
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
cPath = GetCachePath( job.index );
}
break;
cPath = GetCachePath( job.index );
}
break;
}
//try to save this data to the cache
if( cPath.isEmpty() )
return;
return;
SaveDataToCache( cPath, job.data );
}
@ -485,17 +485,17 @@ void NusDownloader::downloadProgress( qint64 bytesReceived, qint64 bytesTotal )
QString unit;
if( speed < 1024 )
{
unit = "bytes/sec";
unit = "bytes/sec";
}
else if( speed < 1024 * 1024 )
{
speed /= 1024;
unit = "kB/s";
speed /= 1024;
unit = "kB/s";
}
else
{
speed /= 1024*1024;
unit = "MB/s";
speed /= 1024*1024;
unit = "MB/s";
}
emit SendText( currentJobText + " " + QString::fromLatin1( "%1 %2" ).arg( speed, 3, 'f', 1 ).arg( unit ) );
int progress = (int)( ( (float)bytesReceived / (float)bytesTotal ) * 100.0f );
@ -508,13 +508,13 @@ void NusDownloader::downloadFinished()
//qDebug() << "NusDownloader::downloadFinished";
if( currentDownload->error() )
{
qDebug() << "currentDownload->error()";
CurrentJobErrored( tr( "Error downloading part of the title." ) );
qDebug() << "currentDownload->error()";
CurrentJobErrored( tr( "Error downloading part of the title." ) );
}
else
{
emit SendDownloadProgress( 100 );
FileIsFinishedDownloading( dlJob );
emit SendDownloadProgress( 100 );
FileIsFinishedDownloading( dlJob );
}
currentDownload->deleteLater();
@ -576,8 +576,8 @@ bool NusDownloader::GetUpdate( const QString & upd, bool decrypt )
QMap< quint64, quint16 >::ConstIterator i = titles.begin();
while( i != titles.end() )
{
Get( i.key(), decrypt, i.value() );
i++;
Get( i.key(), decrypt, i.value() );
i++;
}
return true;
}
@ -1101,7 +1101,7 @@ QMap< quint64, quint16 > NusDownloader::List30u()
titles.insert( 0x1000248414341ull, 0x4 );//nigaoeNRv4 - MII
titles.insert( 0x1000248414241ull, 0x7 );//shoppingv7
return titles;
}
}
QMap< quint64, quint16 > NusDownloader::List31u()
{

View File

@ -6,6 +6,7 @@
#include "includes.h"
#include "tiktmd.h"
#include "tools.h"
#define SHOPPING_USER_AGENT "Opera/9.00 (Nintendo Wii; U; ; 1038-58; Wii Shop Channel/1.0; en)"
#define UPDATING_USER_AGENT "wii libnup/1.0"
@ -13,7 +14,7 @@
#define WIICONNECT24_USER_AGENT "WiiConnect24/1.0FC4plus1 (build 061114161108)"
#define NUS_BASE_URL "http://ccs.shop.wii.com/ccs/download/"
#define TITLE_LATEST_VERSION 0xffff
enum
{
@ -21,16 +22,6 @@ enum
IDX_TMD
};
//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 downloadJob
{
QString tid;
@ -63,7 +54,7 @@ public:
//get a list of titles for a given update
//if a title is not available on NUS, a substitute is given instead ( a later version of the same title )
//to keep people from bulk DLing and installing and messing something up, any boot2 upudate will NOT be included
//to keep people from bulk DLing and installing and messing something up, any boot2 update will NOT be included
//in the list, ask for it specifically. IOS35 is added in all updates for use in sneek
//lists are created from wiimpersonator logs when available. otherwise they come from examining game update partitions

View File

@ -16,26 +16,26 @@ SaveBanner::SaveBanner( QByteArray stuff )
quint32 size = f.size();
if( size < 0x72a0 || ( ( size - 0x60a0 ) % 0x1200 ) )//sanity check the size. must have enough data for the header, names, banner, and 1 icon image
{
qDebug() << "SaveBanner::SaveBanner -> bad filesize" << hex << size;
f.close();
return;
qDebug() << "SaveBanner::SaveBanner -> bad filesize" << hex << size;
f.close();
return;
}
quint32 magic;
f.read( (char*)&magic, 4 );
if( qFromBigEndian( magic ) != 0x5749424e )//WIBN
{
hexdump( stuff, 0, 0x30 );
f.close();
qWarning() << "SaveBanner::SaveBanner -> bad file magic" << hex << qFromBigEndian( magic );
return;
hexdump( stuff, 0, 0x30 );
f.close();
qWarning() << "SaveBanner::SaveBanner -> bad file magic" << hex << qFromBigEndian( magic );
return;
}
//no clue what this stuff is, dont really need it though
//i suspect instructions for animation ? ( VC icons display forwards and backwards in the system menu )
//also speed is not always the same
//quint32 tmp;
//f.read( (char*)&tmp, 4 );
//quint32 tmp2;
//f.read( (char*)&tmp2, 4 );
quint32 tmp;
f.read( (char*)&tmp, 4 );
quint32 tmp2;
f.read( (char*)&tmp2, 4 );
f.seek( 0x20 );
quint16 name[ 0x20 ];
@ -46,7 +46,7 @@ SaveBanner::SaveBanner( QByteArray stuff )
//QString title;
for( int i = 0; i < 0x20 && name[ i ] != 0; i++ )
saveTitle += QChar( qFromBigEndian( name[ i ] ) );
saveTitle += QChar( qFromBigEndian( name[ i ] ) );
saveTitle = saveTitle.trimmed();
@ -54,7 +54,7 @@ SaveBanner::SaveBanner( QByteArray stuff )
//QString title2;
for( int i = 0; i < 0x20 && name2[ i ] != 0; i++ )
saveTitle2 += QChar( qFromBigEndian( name2[ i ] ) );
saveTitle2 += QChar( qFromBigEndian( name2[ i ] ) );
saveTitle2 = saveTitle2.trimmed();
@ -66,44 +66,44 @@ SaveBanner::SaveBanner( QByteArray stuff )
bannerImg = ConvertTextureToImage( ban, 0xc0, 0x40 );
if( bannerImg.isNull() )
{
f.close();
qWarning() << "SaveBanner::SaveBanner -> error converting banner image";
return;
f.close();
qWarning() << "SaveBanner::SaveBanner -> error converting banner image";
return;
}
//get the images that make up the icon
while( f.pos() != size )
{
QByteArray icn = f.read( 0x1200 );
//check that there is actually data. some banners use all 0x00 for some images
bool null = true;
for( int i = 0; i < 0x1200; i++ )
{
if( icn.at( i ) )//this buffer contains at least 1 byte of data, try to turn it into an image
{
null = false;
break;
}
}
if( null )
{
//qDebug() << "skipping empty image";
break;
}
QByteArray icn = f.read( 0x1200 );
//check that there is actually data. some banners use all 0x00 for some images
bool null = true;
for( int i = 0; i < 0x1200; i++ )
{
if( icn.at( i ) )//this buffer contains at least 1 byte of data, try to turn it into an image
{
null = false;
break;
}
}
if( null )
{
//qDebug() << "skipping empty image";
break;
}
//make this texture int an image
QImage iconImg = ConvertTextureToImage( icn, 0x30, 0x30 );
if( iconImg.isNull() )
break;
//make this texture int an image
QImage iconImg = ConvertTextureToImage( icn, 0x30, 0x30 );
if( iconImg.isNull() )
break;
//add the image to the list
iconImgs << iconImg;
//add the image to the list
iconImgs << iconImg;
}
f.close();
ok = true;
//qDebug() << hex << QString( "%1 %2").arg( qFromBigEndian( tmp ), 9, 16).arg( qFromBigEndian( tmp2 ), 9, 16)
//<< saveTitle.leftJustified( 0x20 ) << QString( "icons: %1").arg( iconImgs.size(), 1, 16 ) << QString( "banner size: %1" ).arg( size, 4, 16 );
//<< saveTitle.leftJustified( 0x20 ) << QString( "icons: %1").arg( iconImgs.size(), 1, 16 ) << QString( "banner size: %1" ).arg( size, 4, 16 );
}
@ -113,23 +113,23 @@ SaveBanner::SaveBanner( const QString &bannerPath )
QFile f( bannerPath );
if( !f.exists() || !f.open( QIODevice::ReadOnly ) )
{
qWarning() << "SaveBanner::SaveBanner -> error opening" << bannerPath;
return;
qWarning() << "SaveBanner::SaveBanner -> error opening" << bannerPath;
return;
}
quint32 size = f.size();
if( size < 0x72a0 || ( ( size - 0x60a0 ) % 0x1200 ) )//sanity check the size. must have enough data for the header, names, banner, and 1 icon image
{
qDebug() << "SaveBanner::SaveBanner -> bad filesize" << hex << size;
f.close();
return;
qDebug() << "SaveBanner::SaveBanner -> bad filesize" << hex << size;
f.close();
return;
}
quint32 magic;
f.read( (char*)&magic, 4 );
if( qFromBigEndian( magic ) != 0x5749424e )//WIBN
{
f.close();
qWarning() << "SaveBanner::SaveBanner -> bad file magic" << qFromBigEndian( magic );
return;
f.close();
qWarning() << "SaveBanner::SaveBanner -> bad file magic" << qFromBigEndian( magic );
return;
}
//get the title of the save
f.seek( 0x20 );
@ -142,13 +142,13 @@ SaveBanner::SaveBanner( const QString &bannerPath )
//QString title;
for( int i = 0; i < 0x20 && name[ i ] != 0; i++ )
saveTitle += QChar( qFromBigEndian( name[ i ] ) );
saveTitle += QChar( qFromBigEndian( name[ i ] ) );
saveTitle = saveTitle.trimmed();
//QString title2;
for( int i = 0; i < 0x20 && name2[ i ] != 0; i++ )
saveTitle2 += QChar( qFromBigEndian( name2[ i ] ) );
saveTitle2 += QChar( qFromBigEndian( name2[ i ] ) );
saveTitle2 = saveTitle2.trimmed();
@ -160,38 +160,38 @@ SaveBanner::SaveBanner( const QString &bannerPath )
bannerImg = ConvertTextureToImage( ban, 0xc0, 0x40 );
if( bannerImg.isNull() )
{
f.close();
qWarning() << "SaveBanner::SaveBanner -> error converting banner image";
return;
f.close();
qWarning() << "SaveBanner::SaveBanner -> error converting banner image";
return;
}
//get the images that make up the icon
while( f.pos() != size )
{
QByteArray icn = f.read( 0x1200 );
//check that there is actually data. some banners use all 0x00 for some images
bool null = true;
for( int i = 0; i < 0x1200; i++ )
{
if( icn.at( i ) )//this buffer contains at least 1 byte of data, try to turn it into an image
{
null = false;
break;
}
}
if( null )
{
//qDebug() << "skipping empty image";
break;
}
QByteArray icn = f.read( 0x1200 );
//check that there is actually data. some banners use all 0x00 for some images
bool null = true;
for( int i = 0; i < 0x1200; i++ )
{
if( icn.at( i ) )//this buffer contains at least 1 byte of data, try to turn it into an image
{
null = false;
break;
}
}
if( null )
{
//qDebug() << "skipping empty image";
break;
}
//make this texture int an image
QImage iconImg = ConvertTextureToImage( icn, 0x30, 0x30 );
if( iconImg.isNull() )
break;
//make this texture int an image
QImage iconImg = ConvertTextureToImage( icn, 0x30, 0x30 );
if( iconImg.isNull() )
break;
//add the image to the list
iconImgs << iconImg;
//add the image to the list
iconImgs << iconImg;
}
f.close();
ok = true;
@ -204,8 +204,8 @@ QImage SaveBanner::ConvertTextureToImage( const QByteArray &ba, quint32 w, quint
int ret = ConvertRGB5A3ToBitMap( (quint8*)ba.constData(), &bitmapdata, w, h );
if( !ret )
{
qWarning() << "SaveBanner::ConvertTextureToImage -> error converting image";
return QImage();
qWarning() << "SaveBanner::ConvertTextureToImage -> error converting image";
return QImage();
}
QImage im = QImage( (const uchar*)bitmapdata, w, h, QImage::Format_ARGB32 );
QImage im2 = im.copy( im.rect() );//make a copy of the image so the "free" wont delete any data we still want
@ -255,3 +255,78 @@ static int ConvertRGB5A3ToBitMap(quint8* tplbuf, quint8** bitmapdata, quint32 wi
}
return outsz;
}
/*
" 0 20000" "Data East Arcade Classics " "icons: 4" "banner size: a8a0"
" 10 20000" "Paintball 2009 " "icons: 1" "banner size: 72a0"
" 0 55570000" "Let's TAP " "icons: 8" "banner size: f0a0" //too slow
" 0 57ff0000" "Metroid: Other M " "icons: 8" "banner size: f0a0" //too fast
" 0 2aaa0000" "Championship foosball " "icons: 7" "banner size: dea0" //little too slow
" 1 aaaa0000" "Blue World " "icons: 8" "banner size: f0a0" //perfect?
" 0 55520000" "零-月蝕の仮面- " "icons: 1" "banner size: 72a0"
" 0 2e0000" "Punch-Out!! " "icons: 4" "banner size: a8a0" //just a little bit too slow
" 0 15550000" "Balls of Fury " "icons: 7" "banner size: dea0" //mine plays to slow
" 0 aaaa0000" "The Umbrella Chronicles " "icons: 8" "banner size: f0a0"
" 0 20000" "DU SUPER MARIO BROS. Wii " "icons: 1" "banner size: 72a0"
" 0 55550000" "Excite Truck " "icons: 8" "banner size: f0a0" //plays too slow
" 0 2aa0000" "Guitar Hero III " "icons: 5" "banner size: baa0" //to slow
" 0 2aa0000" "Guitar Hero III " "icons: 5" "banner size: baa0"
" 0 aa0000" "HOD 2&3 RETURN " "icons: 4" "banner size: a8a0" //static
" 10 0" "The House of the Dead " "icons: 1" "banner size: 72a0"
" 1 aaaa0000" "Quantum of Solace™ " "icons: 8" "banner size: f0a0" //close to original speed
" 10 0" "Trauma Center: Second Opinion " "icons: 1" "banner size: 72a0"
" 0 0" "Indiana Pwns, by Team Twiizers " "icons: 1" "banner size: 72a0"
" 10 55550000" "Alien Syndrome " "icons: 8" "banner size: f0a0" //should be playing forwards and then reverse 1 or 2 frames and start over?
" 10 0" "Prince of Persia " "icons: 1" "banner size: 72a0"
" 0 ffff0000" "Mad Dog McCree " "icons: 8" "banner size: f0a0" //plays too fast
" 10 30000" "Rubik's World " "icons: 1" "banner size: 72a0"
" 1 2000000" "Smash Bros. Brawl " "icons: 1" "banner size: 72a0"
" 1 2000000" "大乱闘スマッシュブラザーズX " "icons: 1" "banner size: 72a0"
" 1 2000000" "Smash Bros. Brawl " "icons: 1" "banner size: 72a0"
" 0 20000" "Wii Sports " "icons: 1" "banner size: 72a0"
" 10 aaaa0000" "Downhill Jam " "icons: 8" "banner size: f0a0"//correctish
" 1 ffff0000" "Call of Duty: WaW " "icons: 8" "banner size: f0a0" //plays too fast
" 10 ff0000" "Tony Hawk: RIDE " "icons: 4" "banner size: a8a0" //appears static
" 0 20000" "Link's Training " "icons: 1" "banner size: 72a0"
" 0 20000" "Wii Sports Resort " "icons: 1" "banner size: 72a0"
" 0 ff0000" "Iron Man™ 2 " "icons: 4" "banner size: a8a0"//too slow
" 10 55550000" "Attack of the Movies 3-D " "icons: 8" "banner size: f0a0" //appears static
" 0 30000" "SUPER MARIO GALAXY 2 " "icons: 1" "banner size: 72a0"
" 1 ffff0000" "Call of Duty: Black Ops " "icons: 8" "banner size: f0a0" //appears static
" 0 aaaa0000" "DKC Returns " "icons: 8" "banner size: f0a0"//correct
" 0 aaaa0000" "Wheel of Fortune " "icons: 8" "banner size: f0a0"//correct
" 0 0" "Scooby-Doo! " "icons: 1" "banner size: 72a0"
" 11 aaaa0000" "GoldenEye 007 " "icons: 8" "banner size: f0a0"//correctish
" 0 aaaa0000" "Jeopardy! " "icons: 8" "banner size: f0a0"//correctish
" 10 0" "All Star Karate " "icons: 1" "banner size: 72a0"
" 0 20000" "NewSuperMarioBrosWii " "icons: 1" "banner size: 72a0"
" 0 20000" "New SUPER MARIO BROS. Wii " "icons: 1" "banner size: 72a0"
" 10 20000" "Cabela's NAA " "icons: 1" "banner size: 72a0"
" 10 0" "NBA JAM " "icons: 1" "banner size: 72a0"
" 0 30000" "Spider-Man™: SD " "icons: 1" "banner size: 72a0"
" 1 ffff0000" "Tetris® Party Deluxe " "icons: 8" "banner size: f0a0"//plays too fast
" 0 2aaa0000" "GH World Tour " "icons: 7" "banner size: dea0"
" 0 aaa0000" "GH Metallica " "icons: 6" "banner size: cca0"
" 0 aaa0000" "GH Smash Hits " "icons: 6" "banner size: cca0"
" 0 2aaa0000" "GH™:Warriors of Rock " "icons: 7" "banner size: dea0"
" 1 3ff0000" "Rock Band™ 2 " "icons: 5" "banner size: baa0"
" 1 3ff0000" "Rock Band™ 3 " "icons: 5" "banner size: baa0"
" 1 20000" "Check Mii Out Ch. " "icons: 1" "banner size: 72a0"
" 10 ffff0000" "Super Smash Bros. " "icons: 8" "banner size: f0a0" //plays forward, pause, backwards, pause
" 0 20000" "Wii Fit " "icons: 1" "banner size: 72a0"
" 0 20000" "Wii Fit™ Plus " "icons: 1" "banner size: 72a0"
skipping empty image
skipping empty image
skipping empty image
skipping empty image
skipping empty image
skipping empty image
skipping empty image
" 1 20000" "Rabbids Go Home " "icons: 8" "banner size: f0a0"
" 1 20000" "Mario Kart Wii " "icons: 1" "banner size: 72a0"
" 1 20000" "Mario Kart Wii " "icons: 1" "banner size: 72a0"
0x20000 = static even if theres multiple images ( data east arcade )
*/

View File

@ -7,90 +7,90 @@ SettingTxtDialog::SettingTxtDialog( QWidget *parent, const QByteArray &old, qint
ui->setupUi( this );
if( !old.isEmpty() )
{
QByteArray copy = old;
copy = LolCrypt( copy );
QByteArray copy = old;
copy = LolCrypt( copy );
QString str( copy );
str.replace( "\r\n", "\n" );//maybe not needed to do this in 2 steps, but there may be some reason the file only uses "\n", so do it this way to be safe
QStringList parts = str.split( "\n", QString::SkipEmptyParts );
foreach( QString part, parts )
{
QString p = part;
if( part.startsWith( "AREA=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_area->setText( p );
}
else if( part.startsWith( "MODEL=" ) )
{
p.remove( 0, 6 );
ui->lineEdit_model->setText( p );
}
else if( part.startsWith( "DVD=" ) )
{
p.remove( 0, 4 );
ui->lineEdit_dvd->setText( p );
}
else if( part.startsWith( "MPCH=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_mpch->setText( p );
}
else if( part.startsWith( "CODE=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_code->setText( p );
}
else if( part.startsWith( "SERNO=" ) )
{
p.remove( 0, 6 );
ui->lineEdit_serno->setText( p );
}
else if( part.startsWith( "VIDEO=" ) )
{
p.remove( 0, 6 );
ui->lineEdit_video->setText( p );
}
else if( part.startsWith( "GAME=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_game->setText( p );
}
else
{
qDebug() << "SettingTxtDialog::SettingTxtDialog -> unhandled shit" << p;
}
}
QString str( copy );
str.replace( "\r\n", "\n" );//maybe not needed to do this in 2 steps, but there may be some reason the file only uses "\n", so do it this way to be safe
QStringList parts = str.split( "\n", QString::SkipEmptyParts );
foreach( QString part, parts )
{
QString p = part;
if( part.startsWith( "AREA=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_area->setText( p );
}
else if( part.startsWith( "MODEL=" ) )
{
p.remove( 0, 6 );
ui->lineEdit_model->setText( p );
}
else if( part.startsWith( "DVD=" ) )
{
p.remove( 0, 4 );
ui->lineEdit_dvd->setText( p );
}
else if( part.startsWith( "MPCH=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_mpch->setText( p );
}
else if( part.startsWith( "CODE=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_code->setText( p );
}
else if( part.startsWith( "SERNO=" ) )
{
p.remove( 0, 6 );
ui->lineEdit_serno->setText( p );
}
else if( part.startsWith( "VIDEO=" ) )
{
p.remove( 0, 6 );
ui->lineEdit_video->setText( p );
}
else if( part.startsWith( "GAME=" ) )
{
p.remove( 0, 5 );
ui->lineEdit_game->setText( p );
}
else
{
qDebug() << "SettingTxtDialog::SettingTxtDialog -> unhandled shit" << p;
}
}
}
else
{
switch( region )
{
case SETTING_TXT_PAL:
ui->lineEdit_area->setText( "EUR" );
ui->lineEdit_model->setText( "RVL-001(EUR)" );
ui->lineEdit_code->setText( "LEH" );
ui->lineEdit_video->setText( "PAL" );
ui->lineEdit_game->setText( "EU" );
break;
case SETTING_TXT_JAP:
ui->lineEdit_area->setText( "JPN" );
ui->lineEdit_model->setText( "RVL-001(JPN)" );
ui->lineEdit_code->setText( "LJF" );
ui->lineEdit_video->setText( "NTSC" );
ui->lineEdit_game->setText( "JP" );
break;
case SETTING_TXT_KOR:
ui->lineEdit_area->setText( "KOR" );
ui->lineEdit_model->setText( "RVL-001(KOR)" );
ui->lineEdit_code->setText( "LKM" );
ui->lineEdit_video->setText( "NTSC" );
ui->lineEdit_game->setText( "KR" );
break;
case SETTING_TXT_USA://these are already the default values
default:
break;
}
switch( region )
{
case SETTING_TXT_PAL:
ui->lineEdit_area->setText( "EUR" );
ui->lineEdit_model->setText( "RVL-001(EUR)" );
ui->lineEdit_code->setText( "LEH" );
ui->lineEdit_video->setText( "PAL" );
ui->lineEdit_game->setText( "EU" );
break;
case SETTING_TXT_JAP:
ui->lineEdit_area->setText( "JPN" );
ui->lineEdit_model->setText( "RVL-001(JPN)" );
ui->lineEdit_code->setText( "LJF" );
ui->lineEdit_video->setText( "NTSC" );
ui->lineEdit_game->setText( "JP" );
break;
case SETTING_TXT_KOR:
ui->lineEdit_area->setText( "KOR" );
ui->lineEdit_model->setText( "RVL-001(KOR)" );
ui->lineEdit_code->setText( "LKM" );
ui->lineEdit_video->setText( "NTSC" );
ui->lineEdit_game->setText( "KR" );
break;
case SETTING_TXT_USA://these are already the default values
default:
break;
}
}
}
@ -103,13 +103,13 @@ SettingTxtDialog::~SettingTxtDialog()
void SettingTxtDialog::on_buttonBox_accepted()
{
QString s = "AREA=" + ui->lineEdit_area->text() + "\r\n" +
"MODEL=" + ui->lineEdit_model->text() + "\r\n" +
"DVD=" + ui->lineEdit_dvd->text() + "\r\n" +
"MPCH=" + ui->lineEdit_mpch->text() + "\r\n" +
"CODE=" + ui->lineEdit_code->text() + "\r\n" +
"SERNO=" + ui->lineEdit_serno->text() + "\r\n" +
"VIDEO=" + ui->lineEdit_video->text() + "\r\n" +
"GAME=" + ui->lineEdit_game->text();
"MODEL=" + ui->lineEdit_model->text() + "\r\n" +
"DVD=" + ui->lineEdit_dvd->text() + "\r\n" +
"MPCH=" + ui->lineEdit_mpch->text() + "\r\n" +
"CODE=" + ui->lineEdit_code->text() + "\r\n" +
"SERNO=" + ui->lineEdit_serno->text() + "\r\n" +
"VIDEO=" + ui->lineEdit_video->text() + "\r\n" +
"GAME=" + ui->lineEdit_game->text();
ret = s.toAscii();
ret = PaddedByteArray( ret, 0x100 );
@ -122,17 +122,17 @@ QByteArray SettingTxtDialog::LolCrypt( QByteArray ba )
{
int s;
for( s = ba.size() - 1; s > 0; s-- )
if( ba.at( s ) != '\0' )
break;
if( ba.at( s ) != '\0' )
break;
QByteArray ret = ba;
quint32 key = 0x73b5dbfa;
quint8 * stuff = (quint8 *)ret.data();
for( int i = 0; i < s + 1; i++ )
{
*stuff ^= ( key & 0xff );
stuff++;
key = ( ( key << 1 ) | ( key >> 31 ) );
*stuff ^= ( key & 0xff );
stuff++;
key = ( ( key << 1 ) | ( key >> 31 ) );
}
return ret;
}
@ -141,7 +141,7 @@ QByteArray SettingTxtDialog::Edit( QWidget *parent, const QByteArray &old, qint8
{
SettingTxtDialog d( parent, old, region );
if( d.exec() )
return d.ret;
return d.ret;
return QByteArray();
}

View File

@ -5,15 +5,15 @@ SharedContentMap::SharedContentMap( const QByteArray &old )
{
data = old;
if( data.size() )
Check();
Check();
}
bool SharedContentMap::Check( const QString &path )
{
if( !data.size() || data.size() % 28 )
{
qWarning() << "SharedContentMap::Check -> bad size" << hex << data.size();
return false;
qWarning() << "SharedContentMap::Check -> bad size" << hex << data.size();
return false;
}
QByteArray cid;
@ -21,60 +21,60 @@ bool SharedContentMap::Check( const QString &path )
//check that all the cid's can be converted to numbers, and make sure that ther are in numerical order
for( quint32 i = 0; i < cnt; i++ )
{
bool ok;
cid = data.mid( ( i * 28 ), 8 );
quint32 num = cid.toInt( &ok, 16 );
if( !ok )
{
qWarning() << "SharedContentMap::Check -> error converting" << cid << "to a number";
return false;
}
if( i != num )
{
qWarning() << "SharedContentMap::Check -> something is a miss" << num << i;
return false;
}
bool ok;
cid = data.mid( ( i * 28 ), 8 );
quint32 num = cid.toInt( &ok, 16 );
if( !ok )
{
qWarning() << "SharedContentMap::Check -> error converting" << cid << "to a number";
return false;
}
if( i != num )
{
qWarning() << "SharedContentMap::Check -> something is a miss" << num << i;
return false;
}
}
//this is all there is to check right now
if( path.isEmpty() )
return true;
return true;
QDir dir( path );
if( !dir.exists() )
{
qWarning() << "SharedContentMap::Check ->" << path << "doesnt exist";
return false;
qWarning() << "SharedContentMap::Check ->" << path << "doesnt exist";
return false;
}
//check hashes for all the contents in the map
for( quint32 i = 0; i < cnt; i++ )
{
cid = data.mid( ( i * 28 ), 8 );
QString appName( cid );
QFileInfo fi = dir.absoluteFilePath( appName + ".app" );
if( !fi.exists() )
{
qWarning() << "SharedContentMap::Check -> content in the map isnt found in" << path;
return false;
}
QFile f( fi.absoluteFilePath() );
if( !f.open( QIODevice::ReadOnly ) )
{
qWarning() << "SharedContentMap::Check -> cant open" << fi.absoluteFilePath();
return false;
}
cid = data.mid( ( i * 28 ), 8 );
QString appName( cid );
QFileInfo fi = dir.absoluteFilePath( appName + ".app" );
if( !fi.exists() )
{
qWarning() << "SharedContentMap::Check -> content in the map isnt found in" << path;
return false;
}
QFile f( fi.absoluteFilePath() );
if( !f.open( QIODevice::ReadOnly ) )
{
qWarning() << "SharedContentMap::Check -> cant open" << fi.absoluteFilePath();
return false;
}
QByteArray goods = f.readAll();
f.close();
QByteArray goods = f.readAll();
f.close();
QByteArray expectedHash = data.mid( ( i * 28 ) + 8, 20 );
QByteArray actualHash = GetSha1( goods );
if( expectedHash != actualHash )
{
qWarning() << "SharedContentMap::Check -> hash mismatch in" << fi.absoluteFilePath() << "\n"
<< expectedHash << actualHash;
return false;
}
QByteArray expectedHash = data.mid( ( i * 28 ) + 8, 20 );
QByteArray actualHash = GetSha1( goods );
if( expectedHash != actualHash )
{
qWarning() << "SharedContentMap::Check -> hash mismatch in" << fi.absoluteFilePath() << "\n"
<< expectedHash << actualHash;
return false;
}
}
return true;
}
@ -84,13 +84,13 @@ QString SharedContentMap::GetAppFromHash( const QByteArray &hash )
quint32 cnt = data.size() / 28;
for( quint32 i = 0; i < cnt; i++ )
{
QString appName( data.mid( ( i * 28 ), 8 ) );
QByteArray mapHash = data.mid( ( i * 28 ) + 8, 20 );
//qDebug() << QString( mapHash ) << hash;
if( mapHash == hash )
{
return appName;
}
QString appName( data.mid( ( i * 28 ), 8 ) );
QByteArray mapHash = data.mid( ( i * 28 ) + 8, 20 );
//qDebug() << QString( mapHash ) << hash;
if( mapHash == hash )
{
return appName;
}
}
//hash not found
return QString();
@ -103,33 +103,38 @@ QString SharedContentMap::GetNextEmptyCid()
QList<quint32>cids;
for( quint32 i = 0; i < cnt; i++ )
{
QByteArray cid = data.mid( ( i * 28 ), 8 );
quint32 num = cid.toInt( NULL, 16 );
cids << num;
QByteArray cid = data.mid( ( i * 28 ), 8 );
quint32 num = cid.toInt( NULL, 16 );
cids << num;
}
//find the lowest number cid that isnt used
while( cids.contains( ret ) )
ret++;
ret++;
//qDebug() << hex << ret;
return QString( "%1" ).arg( ret, 8, 16, QChar( '0' ) );
}
void SharedContentMap::AddEntry( const QString &app, const QByteArray &hash )
{
if( app.size() != 8 || hash.size() != 20 )
{
qWarning() << "SharedContentMap::AddEntry -> bas size" << hex << app.size() << hash.size();
return;
}
data += app.toAscii() + hash;
}
const QByteArray SharedContentMap::Hash( quint16 i )
{
if( Count() < i )
return QByteArray();
return QByteArray();
return data.mid( ( i * 28 ) + 8, 20 );
}
const QString SharedContentMap::Cid( quint16 i )
{
if( Count() < i )
return QByteArray();
return QByteArray();
return QString( data.mid( ( i * 28 ), 8 ) );
}

View File

@ -9,13 +9,13 @@ Tmd::Tmd( const QByteArray &stuff )
data = stuff;
p_tmd = NULL;
if( data.isEmpty() || data.size() < 4 )//maybe 4 is still too low?
return;
return;
SetPointer();
if( (quint32)data.size() != SignedSize() )
{
data.resize( SignedSize() );
SetPointer();
data.resize( SignedSize() );
SetPointer();
}
//hexdump( stuff );
}
@ -23,14 +23,14 @@ Tmd::Tmd( const QByteArray &stuff )
quint64 Tmd::Tid()
{
if( !p_tmd )
return 0;
return 0;
return qFromBigEndian( p_tmd->title_id );
}
bool Tmd::SetTid( quint64 tid )
{
if( !p_tmd )
return false;
return false;
p_tmd->title_id = qFromBigEndian( tid );
return true;
@ -39,14 +39,14 @@ bool Tmd::SetTid( quint64 tid )
quint64 Tmd::IOS()
{
if( !p_tmd )
return 0;
return 0;
return qFromBigEndian( p_tmd->sys_version );
}
bool Tmd::SetIOS( quint64 ios )
{
if( !p_tmd )
return false;
return false;
p_tmd->sys_version = qFromBigEndian( ios );
return true;
@ -55,7 +55,7 @@ bool Tmd::SetIOS( quint64 ios )
bool Tmd::SetAhb( bool remove )
{
if( !p_tmd )
return false;
return false;
quint32 access = qFromBigEndian( p_tmd->access_rights );
if( remove )
@ -69,7 +69,7 @@ bool Tmd::SetAhb( bool remove )
bool Tmd::SetDiskAccess( bool allow )
{
if( !p_tmd )
return false;
return false;
quint32 access = qFromBigEndian( p_tmd->access_rights );
if( allow )
@ -83,21 +83,21 @@ bool Tmd::SetDiskAccess( bool allow )
quint16 Tmd::Gid()
{
if( !p_tmd )
return 0;
return 0;
return qFromBigEndian( p_tmd->group_id );
}
QString Tmd::Cid( quint16 i )
{
if( !p_tmd || i > qFromBigEndian( p_tmd->num_contents ) )
return QString();
return QString();
return QString( "%1" ).arg( qFromBigEndian( p_tmd->contents[ i ].cid ), 8, 16, QChar( '0' ) );
}
QByteArray Tmd::Hash( quint16 i )
{
if( !p_tmd || i > qFromBigEndian( p_tmd->num_contents ) )
return QByteArray();
return QByteArray();
return QByteArray( (const char*)&p_tmd->contents[ i ].hash, 20 );
}
@ -105,18 +105,18 @@ QByteArray Tmd::Hash( quint16 i )
bool Tmd::SetHash( quint16 cid, const QByteArray &hash )
{
if( !p_tmd || cid >= qFromBigEndian( p_tmd->num_contents ) || hash.size() != 20 )
return false;
return false;
const char* h = hash.data();
for( quint8 i = 0; i < 20; i++ )
p_tmd->contents[ cid ].hash[ i ] = h[ i ];
p_tmd->contents[ cid ].hash[ i ] = h[ i ];
return true;
}
quint16 Tmd::Count()
{
if( !p_tmd )
return 0;
return 0;
return qFromBigEndian( p_tmd->num_contents );
}
@ -124,7 +124,7 @@ quint16 Tmd::Count()
quint16 Tmd::Version()
{
if( !p_tmd )
return 0;
return 0;
return qFromBigEndian( p_tmd->title_version );
}
@ -132,7 +132,7 @@ quint16 Tmd::Version()
bool Tmd::SetVersion( quint16 v )
{
if( !p_tmd )
return false;
return false;
p_tmd->title_version = qFromBigEndian( v );
return true;
@ -141,14 +141,14 @@ bool Tmd::SetVersion( quint16 v )
quint64 Tmd::Size( quint16 i )
{
if( !p_tmd || i > qFromBigEndian( p_tmd->num_contents ) )
return 0;
return 0;
return qFromBigEndian( p_tmd->contents[ i ].size );
}
bool Tmd::SetSize( quint16 cid, quint32 size )
{
if( !p_tmd || cid >= qFromBigEndian( p_tmd->num_contents ) )
return false;
return false;
p_tmd->contents[ cid ].size = qFromBigEndian( (quint64)size );
return true;
@ -157,14 +157,14 @@ bool Tmd::SetSize( quint16 cid, quint32 size )
quint16 Tmd::Type( quint16 i )
{
if( !p_tmd || i > qFromBigEndian( p_tmd->num_contents ) )
return 0;
return 0;
return qFromBigEndian( p_tmd->contents[ i ].type );
}
bool Tmd::SetType( quint16 cid, quint16 type )
{
if( !p_tmd || cid >= qFromBigEndian( p_tmd->num_contents ) )
return false;
return false;
p_tmd->contents[ cid ].type = qFromBigEndian( type );
return true;
@ -173,7 +173,7 @@ bool Tmd::SetType( quint16 cid, quint16 type )
quint32 Tmd::SignedSize()
{
if( !p_tmd )
return 0;
return 0;
return payLoadOffset + sizeof( tmd ) + ( sizeof( tmd_content ) * qFromBigEndian( p_tmd->num_contents ) );
}
@ -181,13 +181,13 @@ void Tmd::SetPointer()
{
payLoadOffset = 0;
if( data.startsWith( "\x0\x1\x0\x0" ) )
payLoadOffset = sizeof( sig_rsa2048 );
payLoadOffset = sizeof( sig_rsa2048 );
else if( data.startsWith( "\x0\x1\x0\x1" ) )
payLoadOffset = sizeof( sig_rsa4096 );
payLoadOffset = sizeof( sig_rsa4096 );
else if( data.startsWith( "\x0\x1\x0\x2" ) )
payLoadOffset = sizeof( sig_ecdsa );
payLoadOffset = sizeof( sig_ecdsa );
p_tmd = (tmd*)((quint8*)data.data() + payLoadOffset);
}
@ -195,26 +195,26 @@ void Tmd::SetPointer()
void Tmd::Dbg()
{
if( !p_tmd )
return;
return;
QString contents;
quint16 cnt = Count();
for( quint16 i = 0; i < cnt; i++ )
{
contents += QString( "%1 %2 %3 %4 " ).arg( i, 2, 16 ).arg( Type( i ), 4, 16 ).arg( Cid( i ) ).arg( Size( i ), 8, 16 )
+ Hash( i ).toHex() + "\n";
contents += QString( "%1 %2 %3 %4 " ).arg( i, 2, 16 ).arg( Type( i ), 4, 16 ).arg( Cid( i ) ).arg( Size( i ), 8, 16 )
+ Hash( i ).toHex() + "\n";
}
QString s = QString( "TMD Dbg:\ntid:: %1\ncnt:: %2\n" )
.arg( Tid(), 16, 16, QChar( '0' ) )
.arg( cnt ) + contents;
.arg( Tid(), 16, 16, QChar( '0' ) )
.arg( cnt ) + contents;
qDebug() << s;
}
bool Tmd::FakeSign()
{
if( !p_tmd || payLoadOffset < 5 )
return false;
return false;
quint32 size = SignedSize();
memset( (void*)( data.data() + 4 ), 0, payLoadOffset - 4 );//zero the RSA
@ -223,12 +223,12 @@ bool Tmd::FakeSign()
bool ret = false;//brute force the sha1
do
{
p_tmd->zero = i;//no need to worry about endian here
if( GetSha1( data.mid( payLoadOffset, size ) ).startsWith( '\0' ) )
{
ret = true;
break;
}
p_tmd->zero = i;//no need to worry about endian here
if( GetSha1( data.mid( payLoadOffset, size ) ).startsWith( '\0' ) )
{
ret = true;
break;
}
}
while( ++i );
return ret;
@ -239,7 +239,7 @@ Ticket::Ticket( const QByteArray &stuff )
data = stuff;
p_tik = NULL;
if( data.isEmpty() || data.size() < 4 )//maybe 4 is still too low?
return;
return;
SetPointer();
@ -261,22 +261,22 @@ Ticket::Ticket( const QByteArray &stuff )
if( (quint32)data.size() != SignedSize() )
{
data.resize( SignedSize() );
SetPointer();
data.resize( SignedSize() );
SetPointer();
}
}
quint64 Ticket::Tid()
{
if( !p_tik )
return 0;
return 0;
return qFromBigEndian( p_tik->titleid );
}
bool Ticket::SetTid( quint64 tid )
{
if( !p_tik )
return false;
return false;
p_tik->titleid = qFromBigEndian( tid );
@ -292,7 +292,7 @@ bool Ticket::SetTid( quint64 tid )
aes_set_key( (quint8 *)&commonkey );
aes_encrypt( (quint8 *)&iv, (quint8 *)&keyin,
(quint8 *)&p_tik->cipher_title_key, 16 );
(quint8 *)&p_tik->cipher_title_key, 16 );
return true;
}
@ -311,13 +311,13 @@ void Ticket::SetPointer()
{
payLoadOffset = 0;
if( data.startsWith( "\x0\x1\x0\x0" ) )
payLoadOffset = sizeof( sig_rsa2048 );
payLoadOffset = sizeof( sig_rsa2048 );
else if( data.startsWith( "\x0\x1\x0\x1" ) )
payLoadOffset = sizeof( sig_rsa4096 );
payLoadOffset = sizeof( sig_rsa4096 );
else if( data.startsWith( "\x0\x1\x0\x2" ) )
payLoadOffset = sizeof( sig_ecdsa );
payLoadOffset = sizeof( sig_ecdsa );
p_tik = (tik*)((quint8*)(data.data()) + payLoadOffset);
}
@ -325,7 +325,7 @@ void Ticket::SetPointer()
bool Ticket::FakeSign()
{
if( !p_tik || payLoadOffset < 5 )
return false;
return false;
quint32 size = SignedSize();
memset( (void*)( data.data() + 4 ), 0, payLoadOffset - 4 );//zero the RSA
@ -334,12 +334,12 @@ bool Ticket::FakeSign()
bool ret = false;//brute force the sha1
do
{
p_tik->padding = i;//no need to worry about endian here
if( GetSha1( data.mid( payLoadOffset, size ) ).startsWith( '\0' ) )
{
ret = true;
break;
}
p_tik->padding = i;//no need to worry about endian here
if( GetSha1( data.mid( payLoadOffset, size ) ).startsWith( '\0' ) )
{
ret = true;
break;
}
}
while( ++i );
return ret;
@ -362,9 +362,9 @@ static void bn_sub_modulus( quint8 *a, const quint8 *N, const quint32 n )
for( quint32 i = n - 1; i < n; i-- )
{
dig = N[ i ] + c;
c = ( a [ i ] < dig );
a[ i ] -= dig;
dig = N[ i ] + c;
c = ( a [ i ] < dig );
a[ i ] -= dig;
}
}
@ -377,15 +377,15 @@ static void bn_add( quint8 *d, const quint8 *a, const quint8 *b, const quint8 *N
for( i = n - 1; i < n; i--)
{
dig = a[ i ] + b[ i ] + c;
c = ( dig >= 0x100 );
d[ i ] = dig;
dig = a[ i ] + b[ i ] + c;
c = ( dig >= 0x100 );
d[ i ] = dig;
}
if( c )
bn_sub_modulus( d, N, n );
bn_sub_modulus( d, N, n );
if( bn_compare( d, N, n ) >= 0 )
bn_sub_modulus( d, N, n );
bn_sub_modulus( d, N, n );
}
// calc d = (a * b) mod N, given n = size of d,a,b,N in bytes
@ -395,11 +395,11 @@ static void bn_mul( quint8 *d, const quint8 *a, const quint8 *b, const quint8 *N
bn_zero( d, n );
for( quint32 i = 0; i < n; i++ )
for( mask = 0x80; mask != 0; mask >>= 1 )
{
for( mask = 0x80; mask != 0; mask >>= 1 )
{
bn_add( d, d, d, N, n );
if( ( a[ i ] & mask ) != 0 )
bn_add( d, d, b, N, n );
bn_add( d, d, b, N, n );
}
}
@ -412,13 +412,13 @@ static void bn_exp( quint8 *d, const quint8 *a, const quint8 *N, const quint32 n
bn_zero( d, n );
d[ n-1 ] = 1;
for( quint32 i = 0; i < en; i++ )
for( mask = 0x80; mask != 0; mask >>= 1 )
{
for( mask = 0x80; mask != 0; mask >>= 1 )
{
bn_mul( t, d, d, N, n );
if( ( e [ i ] & mask ) != 0 )
bn_mul( d, t, a, N, n );
bn_mul( d, t, a, N, n );
else
bn_copy( d, t, n );
bn_copy( d, t, n );
}
}
@ -429,11 +429,11 @@ static int get_sig_len( const quint8 *sig )
switch( type - 0x10000 )
{
case 0:
return 0x240;
return 0x240;
case 1:
return 0x140;
return 0x140;
case 2:
return 0x80;
return 0x80;
}
return -ERROR_SIG_TYPE;
}
@ -455,7 +455,7 @@ static int check_rsa( const QByteArray &h, const quint8 *sig, const quint8 *key,
{
quint8 correct[ 0x200 ], x[ 0x200 ];
static const quint8 ber[ 16 ] = { 0x00,0x30,0x21,0x30,0x09,0x06,0x05,0x2b,
0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14 };
0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14 };
correct[ 0 ] = 0;
correct[ 1 ] = 1;
memset( correct + 2, 0xff, n - 38 );
@ -468,10 +468,10 @@ static int check_rsa( const QByteArray &h, const quint8 *sig, const quint8 *key,
//qDebug() << " SHA1 hash:" << h.toHex();
if( memcmp( correct, x, n ) == 0 )
return 0;
return 0;
if( strncmp( (char*)h.constData(), (char*) x + n - 20, 20 ) == 0 )
return ERROR_RSA_FAKESIGNED;
return ERROR_RSA_FAKESIGNED;
return ERROR_RSA_HASH;
}
@ -481,10 +481,10 @@ static int check_hash( const QByteArray &h, const quint8 *sig, const quint8 *key
quint32 type;
type = BE32( sig ) - 0x10000;
if( (qint32)type != BE32( key + 0x40 ) )
return ERROR_RSA_TYPE_MISMATCH;
return ERROR_RSA_TYPE_MISMATCH;
if( type == 1 )
return check_rsa( h, sig + 4, key + 0x88, 0x100 );
return check_rsa( h, sig + 4, key + 0x88, 0x100 );
return ERROR_RSA_TYPE_UNKNOWN;
}
@ -498,32 +498,32 @@ static const quint8* find_cert_in_chain( const quint8 *sub, const quint8 *cert,
parent[ sizeof parent - 1 ] = 0;
child = strrchr( parent, '-' );
if( child )
*child++ = 0;
*child++ = 0;
else
{
*parent = 0;
child = (char*)sub;
*parent = 0;
child = (char*)sub;
}
*err = -ERROR_CERT_NOT_FOUND;
for( p = cert; p < cert + cert_len; p += sig_len + sub_len )
{
sig_len = get_sig_len( p );
if( sig_len < 0 )
{
*err = sig_len;
break;
}
issuer = p + sig_len;
sub_len = get_sub_len( issuer );
if( sub_len < 0 )
{
*err = sub_len;
break;
}
if( strcmp( parent, (char*)issuer ) == 0 && strcmp( child, (char*)issuer + 0x44 ) == 0 )
return p;
sig_len = get_sig_len( p );
if( sig_len < 0 )
{
*err = sig_len;
break;
}
issuer = p + sig_len;
sub_len = get_sub_len( issuer );
if( sub_len < 0 )
{
*err = sub_len;
break;
}
if( strcmp( parent, (char*)issuer ) == 0 && strcmp( child, (char*)issuer + 0x44 ) == 0 )
return p;
}
return NULL;
}
@ -541,45 +541,45 @@ int check_cert_chain( const QByteArray &data )
sig = (const quint8*)data.constData();
sig_len = get_sig_len( sig );
if( sig_len < 0 )
return -sig_len;
return -sig_len;
sub = (const quint8*)( data.data() + sig_len );
sub_len = data.size() - sig_len;
if( sub_len <= 0 )
return ERROR_SUB_TYPE;
return ERROR_SUB_TYPE;
for( ; ; )
{
//qDebug() << "Verifying using" << QString( (const char*) sub );
if( strcmp((char*)sub, "Root" ) == 0 )
{
key = root_dat;
h = GetSha1( QByteArray( (const char*)sub, sub_len ) );
if( BE32( sig ) != 0x10000 )
return ERROR_SIG_TYPE;
return check_rsa( h, sig + 4, key, 0x200 );
}
//qDebug() << "Verifying using" << QString( (const char*) sub );
if( strcmp((char*)sub, "Root" ) == 0 )
{
key = root_dat;
h = GetSha1( QByteArray( (const char*)sub, sub_len ) );
if( BE32( sig ) != 0x10000 )
return ERROR_SIG_TYPE;
return check_rsa( h, sig + 4, key, 0x200 );
}
key_cert = find_cert_in_chain( sub, certificates, CERTS_DAT_SIZE, &cert_err );
if( key_cert )
cert_err = get_sig_len( key_cert );
key_cert = find_cert_in_chain( sub, certificates, CERTS_DAT_SIZE, &cert_err );
if( key_cert )
cert_err = get_sig_len( key_cert );
if( cert_err < 0 )
return -cert_err;
key = key_cert + cert_err;
if( cert_err < 0 )
return -cert_err;
key = key_cert + cert_err;
h = GetSha1( QByteArray( (const char*)sub, sub_len ) );
ret = check_hash( h, sig, key );
// remove this if statement if you don't want to check the whole chain
if( ret != ERROR_SUCCESS )
return ret;
sig = key_cert;
sig_len = get_sig_len( sig );
if( sig_len < 0 )
return -sig_len;
sub = sig + sig_len;
sub_len = get_sub_len( sub );
if( sub_len < 0 )
return -sub_len;
h = GetSha1( QByteArray( (const char*)sub, sub_len ) );
ret = check_hash( h, sig, key );
// remove this if statement if you don't want to check the whole chain
if( ret != ERROR_SUCCESS )
return ret;
sig = key_cert;
sig_len = get_sig_len( sig );
if( sig_len < 0 )
return -sig_len;
sub = sig + sig_len;
sub_len = get_sub_len( sub );
if( sub_len < 0 )
return -sub_len;
}
}

View File

@ -87,13 +87,13 @@ typedef struct _tmd {
// C99 flexible array
tmd_content contents[];
} __attribute__((packed)) tmd;
/*
typedef struct _tmd_view_content
{
quint32 cid;
quint16 index;
quint16 type;
quint64 size;
quint32 cid;
quint16 index;
quint16 type;
quint64 size;
} __attribute__((packed)) tmd_view_content;
typedef struct _cert_header {
@ -132,9 +132,7 @@ typedef struct _cert_ecdsa {
quint8 s[30];
quint8 pad[0x3c];
} __attribute__((packed)) cert_ecdsa;
#define COMMON_KEY {0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, 0x48, 0xd9, 0xc5, 0x45, 0x73, 0x81, 0xaa, 0xf7}
*/
//just a quick class to try to keep the rest of the code from getting full of the same shit over and over
class Ticket
{
@ -236,15 +234,15 @@ private:
enum
{
ERROR_SUCCESS = 0,
ERROR_SIG_TYPE,
ERROR_SUB_TYPE,
ERROR_RSA_FAKESIGNED,
ERROR_RSA_HASH,
ERROR_RSA_TYPE_UNKNOWN,
ERROR_RSA_TYPE_MISMATCH,
ERROR_CERT_NOT_FOUND,
ERROR_COUNT
ERROR_SUCCESS = 0,
ERROR_SIG_TYPE,
ERROR_SUB_TYPE,
ERROR_RSA_FAKESIGNED,
ERROR_RSA_HASH,
ERROR_RSA_TYPE_UNKNOWN,
ERROR_RSA_TYPE_MISMATCH,
ERROR_CERT_NOT_FOUND,
ERROR_COUNT
};
//checks the signatures in a tmd/ticket

View File

@ -17,26 +17,26 @@ void hexdump( const void *d, int len ) {
data = (unsigned char*)d;
fprintf( stderr, "\n");
for ( off = 0; off < len; off += 16 ) {
fprintf( stderr, "%08x ", off );
for ( i=0; i<16; i++ )
{
if( ( i + 1 ) % 4 )
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x",data[ off + i ]);
}
else
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x ",data[ off + i ]);
}
}
fprintf( stderr, "%08x ", off );
for ( i=0; i<16; i++ )
{
if( ( i + 1 ) % 4 )
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x",data[ off + i ]);
}
else
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x ",data[ off + i ]);
}
}
fprintf( stderr, " " );
for ( i = 0; i < 16; i++ )
if ( ( i + off) >= len ) fprintf( stderr," ");
fprintf( stderr, " " );
for ( i = 0; i < 16; i++ )
if ( ( i + off) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%c", ascii( data[ off + i ]));
fprintf( stderr,"\n");
fprintf( stderr,"\n");
}
fflush( stderr );
}
@ -52,26 +52,26 @@ void hexdump12( const void *d, int len ) {
data = (unsigned char*)d;
fprintf( stderr, "\n");
for ( off = 0; off < len; off += 12 ) {
fprintf( stderr, "%08x ", off );
for ( i=0; i<12; i++ )
{
if( ( i + 1 ) % 4 )
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x",data[ off + i ]);
}
else
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x ",data[ off + i ]);
}
}
fprintf( stderr, "%08x ", off );
for ( i=0; i<12; i++ )
{
if( ( i + 1 ) % 4 )
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x",data[ off + i ]);
}
else
{
if ( ( i + off ) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%02x ",data[ off + i ]);
}
}
fprintf( stderr, " " );
for ( i = 0; i < 12; i++ )
if ( ( i + off) >= len ) fprintf( stderr," ");
fprintf( stderr, " " );
for ( i = 0; i < 12; i++ )
if ( ( i + off) >= len ) fprintf( stderr," ");
else fprintf( stderr,"%c", ascii( data[ off + i ]));
fprintf( stderr,"\n");
fprintf( stderr,"\n");
}
fflush( stderr );
}
@ -83,7 +83,7 @@ void hexdump12( const QByteArray &d, int from, int len )
QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo )
{
QByteArray padding( RU( padTo, orig.size() ) - orig.size(), '\0' );
QByteArray padding( RU( orig.size(), padTo ) - orig.size(), '\0' );
//qDebug() << "padding with" << hex << RU( padTo, orig.size() ) << "bytes" <<
return orig + padding;
}
@ -115,7 +115,7 @@ QByteArray AesEncrypt( quint16 index, const QByteArray &source )
void AesSetKey( const QByteArray &key )
{
// qDebug() << "AesSetKey()" << key.toHex();
// qDebug() << "AesSetKey()" << key.toHex();
aes_set_key( (const quint8*)key.data() );
}
@ -126,15 +126,15 @@ QByteArray GetSha1( const QByteArray &stuff )
SHA1Input( &sha, (const unsigned char*)stuff.data(), stuff.size() );
if( !SHA1Result( &sha ) )
{
qWarning() << "GetSha1 -> sha error";
return QByteArray();
qWarning() << "GetSha1 -> sha error";
return QByteArray();
}
QByteArray ret( 20, '\0' );
quint8 *p = (quint8 *)ret.data();
for( int i = 0; i < 5 ; i++ )
{
quint32 part = qFromBigEndian( sha.Message_Digest[ i ] );
memcpy( p + ( i * 4 ), &part, 4 );
quint32 part = qFromBigEndian( sha.Message_Digest[ i ] );
memcpy( p + ( i * 4 ), &part, 4 );
}
//hexdump( ret );
return ret;
@ -145,8 +145,8 @@ QByteArray ReadFile( const QString &path )
QFile file( path );
if( !file.exists() || !file.open( QIODevice::ReadOnly ) )
{
qWarning() << "ReadFile -> can't open" << path;
return QByteArray();
qWarning() << "ReadFile -> can't open" << path;
return QByteArray();
}
QByteArray ret = file.readAll();
file.close();
@ -158,216 +158,297 @@ bool WriteFile( const QString &path, const QByteArray &ba )
QFile file( path );
if( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
qWarning() << "WriteFile -> can't open" << path;
return false;
qWarning() << "WriteFile -> can't open" << path;
return false;
}
if( file.write( ba ) != ba.size() )
{
file.close();
qWarning() << "WriteFile -> can't write all the data to" << path;
return false;
file.close();
qWarning() << "WriteFile -> can't write all the data to" << path;
return false;
}
file.close();
return true;
}
bool IsValidSave( const SaveGame &save )
{
if( !save.tid || save.entries.size() != save.attr.size() )
{
qWarning() << "IsValidSave :bad sizes";
return false;
}
if( !save.entries.contains( "/banner.bin" ) )
{
qWarning() << "IsValidSave :save doesnt contain a banner.bin" << save.entries;
return false;
}
quint16 files = 0;
quint16 cnt = save.entries.size();
for( quint16 i = 0; i < cnt; i++ )
{
if( save.entries.at( i ).size() > 52 )
{
qWarning() << "IsValidSave :name is too long" << i << save.entries.at( i );
return false;
}
quint8 attr = save.attr.at( i );
if( NAND_ATTR_TYPE( attr ) == NAND_FILE )
{
files++;
}
else if( NAND_ATTR_TYPE( attr ) == NAND_DIR )
{
}
else //unknown attribute
{
qWarning() << "IsValidSave :unknown attribute" << i << hex << attr << NAND_ATTR_TYPE( attr );
return false;
}
}
if( files != save.data.size() )
{
qWarning() << "IsValidSave :files != data.size()";
return false;
}
return true;
}
const QByteArray DataFromSave( const SaveGame &save, const QString &name )
{
if( !save.tid || save.entries.size() != save.attr.size() )
return QByteArray();
quint16 idx = 0;
quint16 cnt = save.entries.size();
for( quint16 i = 0; i < cnt; i++ )
{
quint8 attr = save.attr.at( i );
if( NAND_ATTR_TYPE( attr ) == NAND_FILE )
{
if( save.entries.at( i ) == name )
return save.data.at( idx );
idx++;
}
}
return QByteArray();
}
quint8 AttrFromSave( const SaveGame &save, const QString &name )
{
if( !save.tid || save.entries.size() != save.attr.size() )
return 0;
quint16 cnt = save.entries.size();
for( quint16 i = 0; i < cnt; i++ )
{
if( save.entries.at( i ) == name )
return save.attr.at( i );
}
return 0;
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99, 0x93, 0x0A, 0xEE,
0x08, 0xB0, 0xB0, 0xE5, 0x1A, 0x3E, 0x9F, 0xAF, 0xCD, 0xC2, 0xD7, 0xE3, 0xCB, 0xA1, 0x2F, 0x3A,
0xC0, 0x07, 0x90, 0xDE, 0x44, 0x7A, 0xC3, 0xC5, 0x38, 0xA8, 0x67, 0x92, 0x38, 0x07, 0x8B, 0xD4,
0xC4, 0xB2, 0x45, 0xAC, 0x29, 0x16, 0x88, 0x6D, 0x2A, 0x0E, 0x59, 0x4E, 0xED, 0x5C, 0xC8, 0x35,
0x69, 0x8B, 0x4D, 0x62, 0x38, 0xDF, 0x05, 0x72, 0x4D, 0xCC, 0xF6, 0x81, 0x80, 0x8A, 0x70, 0x74,
0x06, 0x59, 0x30, 0xBF, 0xF8, 0x51, 0x41, 0x37, 0xE8, 0x15, 0xFA, 0xBA, 0xA1, 0x72, 0xB8, 0xE0,
0x69, 0x6C, 0x61, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x52, 0x6F, 0x6F, 0x74, 0x2D, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x58, 0x53, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xF1, 0xB8, 0x9F, 0xD1, 0xAD, 0x07, 0xA9, 0x37, 0x8A, 0x7B, 0x10, 0x0C,
0x7D, 0xC7, 0x39, 0xBE, 0x9E, 0xDD, 0xB7, 0x32, 0x00, 0x89, 0xAB, 0x25, 0xB1, 0xF8, 0x71, 0xAF,
0x5A, 0xA9, 0xF4, 0x58, 0x9E, 0xD1, 0x83, 0x02, 0x32, 0x8E, 0x81, 0x1A, 0x1F, 0xEF, 0xD0, 0x09,
0xC8, 0x06, 0x36, 0x43, 0xF8, 0x54, 0xB9, 0xE1, 0x3B, 0xBB, 0x61, 0x3A, 0x7A, 0xCF, 0x87, 0x14,
0x85, 0x6B, 0xA4, 0x5B, 0xAA, 0xE7, 0xBB, 0xC6, 0x4E, 0xB2, 0xF7, 0x5D, 0x87, 0xEB, 0xF2, 0x67,
0xED, 0x0F, 0xA4, 0x41, 0xA9, 0x33, 0x66, 0x5E, 0x57, 0x7D, 0x5A, 0xDE, 0xAB, 0xFB, 0x46, 0x2E,
0x76, 0x00, 0xCA, 0x9C, 0xE9, 0x4D, 0xC4, 0xCB, 0x98, 0x39, 0x92, 0xAB, 0x7A, 0x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, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x52, 0x6F, 0x6F, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5B, 0xFA, 0x7D, 0x5C, 0xB2, 0x79, 0xC9, 0xE2, 0xEE, 0xE1, 0x21, 0xC6,
0xEA, 0xF4, 0x4F, 0xF6, 0x39, 0xF8, 0x8F,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, 0x41,
0xDB, 0x8D, 0xE9, 0xC7, 0x20, 0x15, 0x4C, 0xA4, 0x83, 0x2B, 0x69, 0xC0, 0x8C, 0x69, 0xCD, 0x3B,
0x07, 0x3A, 0x00, 0x63, 0x60, 0x2F, 0x46, 0x2D, 0x33, 0x80, 0x61, 0xA5, 0xEA, 0x6C, 0x91, 0x5C,
0xD5, 0x62, 0x35, 0x79, 0xC3, 0xEB, 0x64, 0xCE, 0x44, 0xEF, 0x58, 0x6D, 0x14, 0xBA, 0xAA, 0x88,
0x34, 0x01, 0x9B, 0x3E, 0xEB, 0xEE, 0xD3, 0x79, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x4E, 0x00, 0x5F, 0xF1, 0x3F, 0x86, 0x75, 0x8D, 0xB6, 0x9C, 0x45, 0x63,
0x0F, 0xD4, 0x9B, 0xF4, 0xCC, 0x5D, 0x54, 0xCF, 0xCC, 0x22, 0x34, 0x72, 0x57, 0xAB, 0xA4, 0xBA,
0x53, 0xD2, 0xB3, 0x3D, 0xE6, 0xEC, 0x9E, 0xA1, 0x57, 0x54, 0x53, 0xAE, 0x5F, 0x93, 0x3D, 0x96,
0xBF, 0xF7, 0xCC, 0x7A, 0x79, 0x56, 0x6E, 0x84, 0x7B, 0x1B, 0x60, 0x77, 0xC2, 0xA9, 0x38, 0x71,
0x30, 0x1A, 0x8C, 0xD3, 0xC9, 0x3D, 0x4D, 0xB3, 0x26, 0xE9, 0x87, 0x92, 0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x88, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x52, 0x6F, 0x6F, 0x74, 0x2D, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x43, 0x50, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xF1, 0xB8, 0xA0, 0x64, 0xC1, 0x6D, 0xF3, 0x83, 0x29, 0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0x91, 0xF6, 0xDE, 0x18, 0x61, 0x83, 0xBC, 0x4B, 0x32, 0x67, 0x93,
0xC7, 0x2E, 0x50, 0xD9, 0x1E, 0x36, 0xA0, 0xDC, 0xE2, 0xB9, 0x7D, 0xA0, 0x21, 0x3E, 0x46, 0x96,
0x02, 0x1F, 0x33, 0x1C, 0xBE, 0xAE, 0x8D, 0xFC, 0x92, 0x87, 0x32, 0xAA, 0x44, 0xDC, 0x78, 0xE7,
0x19, 0x9A, 0x3D, 0xDD, 0x57, 0x22, 0x7E, 0x9E, 0x77, 0xDE, 0x32, 0x63, 0x86, 0x93, 0x6C, 0x11,
0xAC, 0xA7, 0x0F, 0x81, 0x19, 0xD3, 0x3A, 0x99, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x7D, 0x9D, 0x5E, 0xBA, 0x52, 0x81, 0xDC, 0xA7, 0x06, 0x5D, 0x2F, 0x08,
0x68, 0xDB, 0x8A, 0xC7, 0x3A, 0xCE, 0x7E, 0xA9, 0x91, 0xF1, 0x96, 0x9F, 0xE1, 0xD0, 0xF2, 0xC1,
0x1F, 0xAE, 0xC0, 0xC3, 0xF0, 0x1A, 0xDC, 0xB4, 0x46, 0xAD, 0xE5, 0xCA, 0x03, 0xB6, 0x25, 0x21,
0x94, 0x62, 0xC6, 0xE1, 0x41, 0x0D, 0xB9, 0xE6, 0x3F, 0xDE, 0x98, 0xD1, 0xAF, 0x26, 0x3B, 0x4C,
0xB2, 0x87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8, 0x15, 0xFA, 0xBA, 0xA1, 0x72, 0xB8, 0xE0,
0x69, 0x6C, 0x61, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x52, 0x6F, 0x6F, 0x74, 0x2D, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x58, 0x53, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0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 0x4A, 0x6E, 0x9C, 0x9B, 0xFE, 0x45, 0x80, 0x34, 0xA9,
0x42, 0x18, 0x2D, 0xDE, 0xB7, 0x5F, 0xE0, 0xD1, 0xB3, 0xDF, 0x0E, 0x97, 0xE3, 0x99, 0x80, 0x87,
0x70, 0x18, 0xC2, 0xB2, 0x83, 0xF1, 0x35, 0x75, 0x7C, 0x5A, 0x30, 0xFC, 0x3F, 0x30, 0x84, 0xA4,
0x9A, 0xAA, 0xC0, 0x1E, 0xE7, 0x06, 0x69, 0x4F, 0x8E, 0x14, 0x48, 0xDA, 0x12, 0x3A, 0xCC, 0x4F,
0xFA, 0x26, 0xAA, 0x38, 0xF7, 0xEF, 0xBF, 0x27, 0x8F, 0x36, 0x97, 0x79, 0x77, 0x5D, 0xB7, 0xC5,
0xAD, 0xC7, 0x89, 0x91, 0xDC, 0xF8, 0x43, 0x8D, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0xB3, 0xAD, 0xB3, 0x22, 0x6B, 0x3C, 0x3D, 0xFF, 0x1B, 0x4B, 0x40, 0x77,
0x16, 0xFF, 0x4F, 0x7A, 0xD7, 0x64, 0x86, 0xC8, 0x95, 0xAC, 0x56, 0x2D, 0x21, 0xF1, 0x06, 0x01,
0xD4, 0xF6, 0x64, 0x28, 0x19, 0x1C, 0x07, 0x76, 0x8F, 0xDF, 0x1A, 0xE2, 0xCE, 0x7B, 0x27, 0xC9,
0x0F, 0xBC, 0x0A, 0xD0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5, 0x83, 0xA1, 0xF9, 0x86, 0x0F, 0x87, 0xAF, 0x52, 0x44, 0x54, 0xBB, 0x47, 0xC3,
0x06, 0x0C, 0x94, 0xE9, 0x9B, 0xF7, 0xD6, 0x32, 0xA7, 0xC8, 0xAB, 0x4B, 0x4F, 0xF5, 0x35, 0x21,
0x1F, 0xC1, 0x80, 0x47, 0xBB, 0x7A, 0xFA, 0x5A, 0x2B, 0xD7, 0xB8, 0x84, 0xAD, 0x8E, 0x56, 0x4F,
0x5B, 0x89, 0xFF, 0x37, 0x97, 0x37, 0xF1, 0xF5, 0x01, 0x3B, 0x1F, 0x9E, 0xC4, 0x18, 0x6F, 0x92,
0x2A, 0xD5, 0xC4, 0xB3, 0xC0, 0xD5, 0x87, 0x0B, 0x9C, 0x04, 0xAF, 0x1A, 0xB5, 0xF3, 0xBC, 0x6D,
0x0A, 0xF1, 0x7D, 0x47, 0x08, 0xE4, 0x43, 0xE9, 0x73, 0xF7, 0xB7, 0x70, 0x77, 0x54, 0xBA, 0xF3,
0xEC, 0xD2, 0xAC, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x52, 0x6F, 0x6F, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5B, 0xFA, 0x7D, 0x5C, 0xB2, 0x79, 0xC9, 0xE2, 0xEE, 0xE1, 0x21, 0xC6,
0xEA, 0xF4, 0x4F, 0xF6, 0x39, 0xF8, 0x8F, 0x07, 0x8B, 0x4B, 0x77, 0xED, 0x9F, 0x95, 0x60, 0xB0,
0x35, 0x82, 0x81, 0xB5, 0x0E, 0x55, 0xAB, 0x72, 0x11, 0x15, 0xA1, 0x77, 0x70, 0x3C, 0x7A, 0x30,
0xFE, 0x3A, 0xE9, 0xEF, 0x1C, 0x60, 0xBC, 0x1D, 0x97, 0x46, 0x76, 0xB2, 0x3A, 0x68, 0xCC, 0x04,
0xB1, 0x98, 0x52, 0x5B, 0xC9, 0x68, 0xF1, 0x1D, 0xE2, 0xDB, 0x50, 0xE4, 0xD9, 0xE7, 0xF0, 0x71,
0xE5, 0x62, 0xDA, 0xE2, 0x09, 0x22, 0x33, 0xE9, 0xD3, 0x63, 0xF6, 0x1D, 0xD7, 0xC1, 0x9F, 0xF3,
0xA4, 0xA9, 0x1E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 0xD0, 0xFC, 0x8D, 0xD4, 0x80, 0x9E, 0xD7, 0x61,
0xBD, 0x11, 0xB7, 0x85, 0x94, 0x8C, 0xD6, 0xD0, 0x7A, 0xDB, 0xA4, 0x08, 0xD0, 0xF0, 0x86, 0xF6,
0x5A, 0xAE, 0x19, 0x14, 0xB2, 0x88, 0x9A, 0xA8, 0xAE, 0x4A, 0xA2, 0xAA, 0xC7, 0x61, 0xA9, 0x0D,
0x41, 0x2C, 0xB1, 0x50, 0x09, 0xAB, 0x3E, 0x93, 0xFC, 0xA9, 0x24, 0xDE, 0xCE, 0x4F, 0x7C, 0x06,
0xAB, 0xDC, 0x2E, 0x60, 0x9D, 0x68, 0xBE, 0x00, 0x73, 0xFA, 0x80, 0x57, 0x6A, 0x14, 0x5E, 0xED,
0xC4, 0x8B, 0x74, 0x32, 0x87, 0x07, 0x93, 0xC8, 0xFC, 0xA6, 0xD8, 0x3E, 0x09, 0x6E, 0xC5, 0xF2,
0xA9, 0xC4, 0x21, 0xE7, 0x48, 0xB3, 0x73, 0x40, 0x5B, 0xE2, 0xFA, 0x8A, 0xE1, 0x58, 0x78, 0xE9,
0xD5, 0x23, 0x88, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x52, 0x6F, 0x6F, 0x74, 0x2D, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x43, 0x50, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xF1, 0xB8, 0xA0, 0x64, 0xC1, 0x6D, 0xF3, 0x83, 0x29, 0x55, 0xC3, 0x29,
0x5B, 0x72, 0xF0, 0x33, 0x2E, 0x97, 0xEF, 0x14, 0x84, 0x8A, 0x68, 0x04, 0x9C, 0xA6, 0x8E, 0xAC,
0xDE, 0x14, 0x50, 0x33, 0xB8, 0x6C, 0x10, 0x8D, 0x48, 0x33, 0x5C, 0x5D, 0x0C, 0xAB, 0x77, 0x04,
0x62, 0x54, 0x47, 0x55, 0x45, 0x2A, 0x90, 0x00, 0x70, 0xB1, 0x56, 0x92, 0x5C, 0x17, 0x86, 0xE2,
0xCD, 0x20, 0x6D, 0xCC, 0xDC, 0x2C, 0x2E, 0x37, 0x6E, 0x27, 0xFC, 0xB4, 0x20, 0x66, 0xCC, 0x0A,
0x8C, 0xE9, 0xFE, 0xE8, 0x57, 0x04, 0xE6, 0xCA, 0x63, 0x1A, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
// public root cert
const quint8 root_dat[] = {
0xF8, 0x24, 0x6C, 0x58, 0xBA, 0xE7, 0x50, 0x03, 0x01, 0xFB, 0xB7, 0xC2, 0xEB, 0xE0, 0x01, 0x05,
0x71, 0xDA, 0x92, 0x23, 0x78, 0xF0, 0x51, 0x4E, 0xC0, 0x03, 0x1D, 0xD0, 0xD2, 0x1E, 0xD3, 0xD0,
0x7E, 0xFC, 0x85, 0x20, 0x69, 0xB5, 0xDE, 0x9B, 0xB9, 0x51, 0xA8, 0xBC, 0x90, 0xA2, 0x44, 0x92,
0x6D, 0x37, 0x92, 0x95, 0xAE, 0x94, 0x36, 0xAA, 0xA6, 0xA3, 0x02, 0x51, 0x0C, 0x7B, 0x1D, 0xED,
0xD5, 0xFB, 0x20, 0x86, 0x9D, 0x7F, 0x30, 0x16, 0xF6, 0xBE, 0x65, 0xD3, 0x83, 0xA1, 0x6D, 0xB3,
0x32, 0x1B, 0x95, 0x35, 0x18, 0x90, 0xB1, 0x70, 0x02, 0x93, 0x7E, 0xE1, 0x93, 0xF5, 0x7E, 0x99,
0xA2, 0x47, 0x4E, 0x9D, 0x38, 0x24, 0xC7, 0xAE, 0xE3, 0x85, 0x41, 0xF5, 0x67, 0xE7, 0x51, 0x8C,
0x7A, 0x0E, 0x38, 0xE7, 0xEB, 0xAF, 0x41, 0x19, 0x1B, 0xCF, 0xF1, 0x7B, 0x42, 0xA6, 0xB4, 0xED,
0xE6, 0xCE, 0x8D, 0xE7, 0x31, 0x8F, 0x7F, 0x52, 0x04, 0xB3, 0x99, 0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) : ( y ) )
#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 }
#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 };
#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
};
char ascii( char s );
void hexdump( const void *d, int len );
void hexdump( const QByteArray &d, int from = 0, int len = -1 );
@ -22,6 +60,10 @@ QByteArray AesEncrypt( quint16 index, const QByteArray &source );
QByteArray GetSha1( const QByteArray &stuff );
bool IsValidSave( const SaveGame &save );
const QByteArray DataFromSave( const SaveGame &save, const QString &name );
quint8 AttrFromSave( const SaveGame &save, const QString &name );
//get a padded version of the given buffer
QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo );

View File

@ -5,7 +5,7 @@ UIDmap::UIDmap( const QByteArray &old )
{
data = old;
if( data.isEmpty() )
CreateNew();//no need to add all the factory uids if the nand in never going to be sent back to the big N
CreateNew();//no need to add all the factory uids if the nand in never going to be sent back to the big N
}
UIDmap::~UIDmap()
{
@ -16,8 +16,8 @@ bool UIDmap::Check()
{
if( !data.size() || data.size() % 12 )
{
qWarning() << "UIDmap::Check() bad size:" << hex << data.size();
return false;
qWarning() << "UIDmap::Check() bad size:" << hex << data.size();
return false;
}
quint64 tid;
@ -32,9 +32,9 @@ bool UIDmap::Check()
uid = qFromBigEndian( uid );
if( tid != 0x100000002ull || uid != 0x1000 )//system menu should be the first entry
{
qWarning() << "UIDmap::Check() system menu entry is messed up:" << hex << tid << uid;
buf.close();
return false;
qWarning() << "UIDmap::Check() system menu entry is messed up:" << hex << tid << uid;
buf.close();
return false;
}
QList<quint64> tids;
@ -43,25 +43,25 @@ bool UIDmap::Check()
quint32 cnt = data.size() / 12;
for( quint32 i = 1; i < cnt; i++ )
{
buf.read( (char*)&tid, 8 );
buf.read( (char*)&uid, 4 );
tid = qFromBigEndian( tid );
uid = qFromBigEndian( uid );
if( tids.contains( tid ) )
{
qWarning() << "UIDmap::Check() tid is present more than once:" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
buf.close();
return false;
}
if( ( uid != 0x1000 + i ) || uids.contains( uid ) )
{
qWarning() << "UIDmap::Check() uid error:" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) ) << hex << uid;
buf.close();
return false;
}
buf.read( (char*)&tid, 8 );
buf.read( (char*)&uid, 4 );
tid = qFromBigEndian( tid );
uid = qFromBigEndian( uid );
if( tids.contains( tid ) )
{
qWarning() << "UIDmap::Check() tid is present more than once:" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
buf.close();
return false;
}
if( ( uid != 0x1000 + i ) || uids.contains( uid ) )
{
qWarning() << "UIDmap::Check() uid error:" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) ) << hex << uid;
buf.close();
return false;
}
tids << tid;
uids << uid;
tids << tid;
uids << uid;
}
return true;
@ -79,19 +79,19 @@ quint32 UIDmap::GetUid( quint64 id, bool autoCreate )
quint32 cnt = data.size() / 12;
for( quint32 i = 0; i < cnt; i++ )
{
buf.read( (char*)&tid, 8 );
buf.read( (char*)&uid, 4 );
tid = qFromBigEndian( tid );
if( tid == id )
{
buf.close();
return qFromBigEndian( uid );
}
buf.read( (char*)&tid, 8 );
buf.read( (char*)&uid, 4 );
tid = qFromBigEndian( tid );
if( tid == id )
{
buf.close();
return qFromBigEndian( uid );
}
}
//not found
if( !autoCreate )
return 0;
return 0;
//add the new entry
tid = qFromBigEndian( id );
@ -121,75 +121,75 @@ void UIDmap::CreateNew( bool addFactorySetupDiscs )
buf.write( (const char*)&uid, 4 );
if( !addFactorySetupDiscs )
{
buf.close();
data = stuff;
return;
buf.close();
data = stuff;
return;
}
//add some entries for the factory setup discs, as seen on my nand up until the first retail game
for( quint32 i = 1; i < 0x2f; i++ )
{
switch( i )
{
case 0x1:tid = qFromBigEndian( 0x100000004ull ); break;
case 0x2:tid = qFromBigEndian( 0x100000009ull ); break;
case 0x3:tid = qFromBigEndian( 0x100003132334aull ); break;
case 0x4:tid = qFromBigEndian( 0x000100000000deadull ); break;
case 0x5:tid = qFromBigEndian( 0x100000100ull ); break;
case 0x6:tid = qFromBigEndian( 0x100000101ull ); break;
case 0x7:tid = qFromBigEndian( 0x000100003132314aull ); break;
case 0x8:tid = qFromBigEndian( 0x100000015ull ); break;
case 0x9:tid = qFromBigEndian( 0x0001000030303032ull ); break;
case 0xa:tid = qFromBigEndian( 0x100000003ull ); break;
case 0xb:tid = qFromBigEndian( 0x10000000aull ); break;
case 0xc:tid = qFromBigEndian( 0x10000000bull ); break;
case 0xd:tid = qFromBigEndian( 0x10000000cull ); break;
case 0xe:tid = qFromBigEndian( 0x10000000dull ); break;
case 0xf:tid = qFromBigEndian( 0x10000000eull ); break;
case 0x10:tid = qFromBigEndian( 0x10000000full ); break;
case 0x11:tid = qFromBigEndian( 0x100000011ull ); break;
case 0x12:tid = qFromBigEndian( 0x100000014ull ); break;
case 0x13:tid = qFromBigEndian( 0x100000016ull ); break;
case 0x14:tid = qFromBigEndian( 0x10000001cull ); break;
case 0x15:tid = qFromBigEndian( 0x10000001eull ); break;
case 0x16:tid = qFromBigEndian( 0x10000001full ); break;
case 0x17:tid = qFromBigEndian( 0x100000021ull ); break;
case 0x18:tid = qFromBigEndian( 0x100000022ull ); break;
case 0x19:tid = qFromBigEndian( 0x100000023ull ); break;
case 0x1a:tid = qFromBigEndian( 0x100000024ull ); break;
case 0x1b:tid = qFromBigEndian( 0x100000025ull ); break;
case 0x1c:tid = qFromBigEndian( 0x100000026ull ); break;
case 0x1d:tid = qFromBigEndian( 0x100000032ull ); break;
case 0x1e:tid = qFromBigEndian( 0x100000033ull ); break;
case 0x1f:tid = qFromBigEndian( 0x100000035ull ); break;
case 0x20:tid = qFromBigEndian( 0x100000037ull ); break;
case 0x21:tid = qFromBigEndian( 0x1000000feull ); break;
case 0x22:tid = qFromBigEndian( 0x0001000248414341ull ); break;
case 0x23:tid = qFromBigEndian( 0x0001000248414141ull ); break;
case 0x24:tid = qFromBigEndian( 0x0001000248415941ull ); break;
case 0x25:tid = qFromBigEndian( 0x0001000248414641ull ); break;
case 0x26:tid = qFromBigEndian( 0x0001000248414645ull ); break;
case 0x27:tid = qFromBigEndian( 0x0001000248414241ull ); break;
case 0x28:tid = qFromBigEndian( 0x0001000248414741ull ); break;
case 0x29:tid = qFromBigEndian( 0x0001000248414745ull ); break;
case 0x2a:tid = qFromBigEndian( 0x0001000848414b45ull ); break;
case 0x2b:tid = qFromBigEndian( 0x0001000848414c45ull ); break;
case 0x2c:tid = qFromBigEndian( 0x0001000148434745ull ); break;
case 0x2d:tid = qFromBigEndian( 0x0001000031323245ull ); break;
case 0x2e:tid = qFromBigEndian( 0x0001000030303033ull ); break;
default:
qWarning() << "oops" << hex << i;
return;
break;
}
switch( i )
{
case 0x1:tid = qFromBigEndian( 0x100000004ull ); break;
case 0x2:tid = qFromBigEndian( 0x100000009ull ); break;
case 0x3:tid = qFromBigEndian( 0x100003132334aull ); break;
case 0x4:tid = qFromBigEndian( 0x000100000000deadull ); break;
case 0x5:tid = qFromBigEndian( 0x100000100ull ); break;
case 0x6:tid = qFromBigEndian( 0x100000101ull ); break;
case 0x7:tid = qFromBigEndian( 0x000100003132314aull ); break;
case 0x8:tid = qFromBigEndian( 0x100000015ull ); break;
case 0x9:tid = qFromBigEndian( 0x0001000030303032ull ); break;
case 0xa:tid = qFromBigEndian( 0x100000003ull ); break;
case 0xb:tid = qFromBigEndian( 0x10000000aull ); break;
case 0xc:tid = qFromBigEndian( 0x10000000bull ); break;
case 0xd:tid = qFromBigEndian( 0x10000000cull ); break;
case 0xe:tid = qFromBigEndian( 0x10000000dull ); break;
case 0xf:tid = qFromBigEndian( 0x10000000eull ); break;
case 0x10:tid = qFromBigEndian( 0x10000000full ); break;
case 0x11:tid = qFromBigEndian( 0x100000011ull ); break;
case 0x12:tid = qFromBigEndian( 0x100000014ull ); break;
case 0x13:tid = qFromBigEndian( 0x100000016ull ); break;
case 0x14:tid = qFromBigEndian( 0x10000001cull ); break;
case 0x15:tid = qFromBigEndian( 0x10000001eull ); break;
case 0x16:tid = qFromBigEndian( 0x10000001full ); break;
case 0x17:tid = qFromBigEndian( 0x100000021ull ); break;
case 0x18:tid = qFromBigEndian( 0x100000022ull ); break;
case 0x19:tid = qFromBigEndian( 0x100000023ull ); break;
case 0x1a:tid = qFromBigEndian( 0x100000024ull ); break;
case 0x1b:tid = qFromBigEndian( 0x100000025ull ); break;
case 0x1c:tid = qFromBigEndian( 0x100000026ull ); break;
case 0x1d:tid = qFromBigEndian( 0x100000032ull ); break;
case 0x1e:tid = qFromBigEndian( 0x100000033ull ); break;
case 0x1f:tid = qFromBigEndian( 0x100000035ull ); break;
case 0x20:tid = qFromBigEndian( 0x100000037ull ); break;
case 0x21:tid = qFromBigEndian( 0x1000000feull ); break;
case 0x22:tid = qFromBigEndian( 0x0001000248414341ull ); break;
case 0x23:tid = qFromBigEndian( 0x0001000248414141ull ); break;
case 0x24:tid = qFromBigEndian( 0x0001000248415941ull ); break;
case 0x25:tid = qFromBigEndian( 0x0001000248414641ull ); break;
case 0x26:tid = qFromBigEndian( 0x0001000248414645ull ); break;
case 0x27:tid = qFromBigEndian( 0x0001000248414241ull ); break;
case 0x28:tid = qFromBigEndian( 0x0001000248414741ull ); break;
case 0x29:tid = qFromBigEndian( 0x0001000248414745ull ); break;
case 0x2a:tid = qFromBigEndian( 0x0001000848414b45ull ); break;
case 0x2b:tid = qFromBigEndian( 0x0001000848414c45ull ); break;
case 0x2c:tid = qFromBigEndian( 0x0001000148434745ull ); break;
case 0x2d:tid = qFromBigEndian( 0x0001000031323245ull ); break;
case 0x2e:tid = qFromBigEndian( 0x0001000030303033ull ); break;
default:
qWarning() << "oops" << hex << i;
return;
break;
}
uid = qFromBigEndian( 0x1000 + i );
buf.write( (const char*)&tid, 8 );
buf.write( (const char*)&uid, 4 );
uid = qFromBigEndian( 0x1000 + i );
buf.write( (const char*)&tid, 8 );
buf.write( (const char*)&uid, 4 );
}
buf.close();
data = stuff;
// hexdump12( data );
// hexdump12( data );
}

View File

@ -108,7 +108,7 @@ Wad::Wad( const QByteArray &stuff )
quint32 s = RU( 0x40, t.Size( i ) );
qDebug() << "content" << i << "is at" << hex << pos
<< "with size" << s;
<< "with size" << s;
QByteArray encData = stuff.mid( pos, s );
pos += s;
@ -136,8 +136,8 @@ Wad::Wad( const QList< QByteArray > &stuff, bool encrypted )
{
if( stuff.size() < 3 )
{
Err( "Cant treate a wad with < 3 items" );
return;
Err( "Cant treate a wad with < 3 items" );
return;
}
tmdData = stuff.at( 0 );
@ -149,25 +149,25 @@ Wad::Wad( const QList< QByteArray > &stuff, bool encrypted )
quint16 cnt = stuff.size() - 2;
if( cnt != t.Count() )
{
Err( "The number of items given doesnt match the number in the tmd" );
return;
Err( "The number of items given doesnt match the number in the tmd" );
return;
}
for( quint16 i = 0; i < cnt; i++ )
{
QByteArray encData;
QByteArray encData;
if( encrypted )
{
encData = stuff.at( i + 2 );
}
else
{
QByteArray decDataPadded = PaddedByteArray( stuff.at( i + 2 ), 0x40 );
//doing this here in case there is some other object that is using the AES that would change the key on us
AesSetKey( ticket.DecryptedKey() );
encData = AesEncrypt( i, decDataPadded );
}
partsEnc << encData;
if( encrypted )
{
encData = stuff.at( i + 2 );
}
else
{
QByteArray decDataPadded = PaddedByteArray( stuff.at( i + 2 ), 0x40 );
//doing this here in case there is some other object that is using the AES that would change the key on us
AesSetKey( ticket.DecryptedKey() );
encData = AesEncrypt( i, decDataPadded );
}
partsEnc << encData;
}
ok = true;
@ -182,8 +182,8 @@ quint64 Wad::Tid()
{
if( !tmdData.size() )
{
Err( "There is no data in the TMD" );
return 0;
Err( "There is no data in the TMD" );
return 0;
}
Tmd t( tmdData );
return t.Tid();
@ -208,15 +208,15 @@ const QByteArray Wad::Content( quint16 i )
{
if( tmdData.isEmpty() || tikData.isEmpty() )
{
Err( "Can't decryte data without a TMD and ticket" );
return QByteArray();
Err( "Can't decryte data without a TMD and ticket" );
return QByteArray();
}
Ticket ticket( tikData );
Tmd t( tmdData );
if( partsEnc.size() != t.Count() || i >= partsEnc.size() )
{
Err( "I dont know whats going on some number is out of range and i dont like it" );
return QByteArray();
Err( "I dont know whats going on some number is out of range and i dont like it" );
return QByteArray();
}
QByteArray encData = partsEnc.at( i );
@ -227,8 +227,8 @@ const QByteArray Wad::Content( quint16 i )
QByteArray realHash = GetSha1( decData );
if( realHash != t.Hash( i ) )
{
Err( QString( "hash doesnt match for content %1" ).arg( i ) );
return QByteArray();
Err( QString( "hash doesnt match for content %1" ).arg( i ) );
return QByteArray();
}
return decData;
}
@ -284,10 +284,10 @@ const QByteArray Wad::Data( quint32 magicWord, const QByteArray &footer )
if( RU( 0x40, t.Size( i ) ) != s )
{
Err( QString( "Size of content %1 is bad ( %2, %3, %4 )" )
.arg( i )
.arg( t.Size( i ), 0, 16 )
.arg( RU( 0x40, t.Size( i ) ), 0, 16 )
.arg( s, 0, 16 ) );
.arg( i )
.arg( t.Size( i ), 0, 16 )
.arg( RU( 0x40, t.Size( i ) ), 0, 16 )
.arg( s, 0, 16 ) );
return QByteArray();
}
appSize += s;
@ -341,8 +341,8 @@ QString Wad::WadName( const QString &path )
{
if( !tmdData.size() )
{
Err( "There is no data in the TMD" );
return QString();
Err( "There is no data in the TMD" );
return QString();
}
Tmd t( tmdData );
return WadName( t.Tid(), t.Version(), path );
@ -358,109 +358,109 @@ QString Wad::WadName( quint64 tid, quint16 version, const QString &path )
switch( reg )
{
case 0x45:
region = "US";
break;
region = "US";
break;
case 0x50:
region = "EU";
break;
region = "EU";
break;
case 0x4A:
region = "JP";
break;
region = "JP";
break;
case 0x4B:
region = "KO";//is this correct?? i have no korean games
break;
region = "KO";//is this correct?? i have no korean games
break;
default:
break;
break;
}
QString name;
switch( type )
{
case 1:
switch( base )
{
case 1:
name = QString( "BOOT2-v%1-64" ).arg( version );
break;
case 2:
name = QString( "RVL-WiiSystemmenu-v%1" ).arg( version );
break;
case 0x100:
name = QString( "RVL-bc-v%1" ).arg( version );
break;
case 0x101:
name = QString( "RVL-mios-v%1" ).arg( version );
break;
default:
if( base > 0xff )
break;
name = QString( "IOS%1-64-v%2" ).arg( base ).arg( version );
break;
}
break;
switch( base )
{
case 1:
name = QString( "BOOT2-v%1-64" ).arg( version );
break;
case 2:
name = QString( "RVL-WiiSystemmenu-v%1" ).arg( version );
break;
case 0x100:
name = QString( "RVL-bc-v%1" ).arg( version );
break;
case 0x101:
name = QString( "RVL-mios-v%1" ).arg( version );
break;
default:
if( base > 0xff )
break;
name = QString( "IOS%1-64-v%2" ).arg( base ).arg( version );
break;
}
break;
case 0x10002:
switch( base )
{
case 0x48414141://HAAA
name = QString( "RVL-photo-v%1" ).arg( version );
break;
case 0x48415941://HAYA
name = QString( "RVL-photo2-v%1" ).arg( version );
break;
case 0x48414241://HABA
name = QString( "RVL-Shopping-v%1" ).arg( version );
break;
case 0x48414341://HACA
name = QString( "RVL-NigaoeNR-v%1" ).arg( version );//mii channel
break;
case 0x48414741://HAGA
name = QString( "RVL-News-v%1" ).arg( version );
break;
case 0x48414641://HAFA
name = QString( "RVL-Weather-v%1" ).arg( version );
break;
default:
switch( regionFree )
{
case 0x48414600://HAF?
name = QString( "RVL-Forecast_%1-v%2" ).arg( region ).arg( version );
break;
case 0x48414700://HAG?
name = QString( "RVL-News_%1-v%2" ).arg( region ).arg( version );
break;
default:
break;
}
break;
}
break;
switch( base )
{
case 0x48414141://HAAA
name = QString( "RVL-photo-v%1" ).arg( version );
break;
case 0x48415941://HAYA
name = QString( "RVL-photo2-v%1" ).arg( version );
break;
case 0x48414241://HABA
name = QString( "RVL-Shopping-v%1" ).arg( version );
break;
case 0x48414341://HACA
name = QString( "RVL-NigaoeNR-v%1" ).arg( version );//mii channel
break;
case 0x48414741://HAGA
name = QString( "RVL-News-v%1" ).arg( version );
break;
case 0x48414641://HAFA
name = QString( "RVL-Weather-v%1" ).arg( version );
break;
default:
switch( regionFree )
{
case 0x48414600://HAF?
name = QString( "RVL-Forecast_%1-v%2" ).arg( region ).arg( version );
break;
case 0x48414700://HAG?
name = QString( "RVL-News_%1-v%2" ).arg( region ).arg( version );
break;
default:
break;
}
break;
}
break;
case 0x10008:
switch( regionFree )
{
case 0x48414b00://HAK?
name = QString( "RVL-Eulav_%1-v%2" ).arg( region ).arg( version );
break;
case 0x48414c00://HAL?
name = QString( "RVL-Rgnsel_%1-v%2" ).arg( region ).arg( version );
break;
default:
break;
}
break;
switch( regionFree )
{
case 0x48414b00://HAK?
name = QString( "RVL-Eulav_%1-v%2" ).arg( region ).arg( version );
break;
case 0x48414c00://HAL?
name = QString( "RVL-Rgnsel_%1-v%2" ).arg( region ).arg( version );
break;
default:
break;
}
break;
default:
break;
break;
}
if( name.isEmpty() )
return QString();
return QString();
if( path.isEmpty() )
return name + ".wad.out.wad";
return name + ".wad.out.wad";
QString ret = name + ".wad.out.wad";
int i = 1;
while( QFile::exists( path + "/" + ret ) )
{
ret = name + QString( "(copy %1)" ).arg( i ) + ".wad.out.wad";
i++;
ret = name + QString( "(copy %1)" ).arg( i ) + ".wad.out.wad";
i++;
}
return ret;
}
@ -470,21 +470,21 @@ QByteArray Wad::FromDirectory( QDir dir )
QFileInfoList tmds = dir.entryInfoList( QStringList() << "*.tmd" << "tmd.*", QDir::Files );
if( tmds.isEmpty() )
{
qWarning() << "Wad::FromDirectory -> no tmd found in" << dir.absolutePath();
return QByteArray();
qWarning() << "Wad::FromDirectory -> no tmd found in" << dir.absolutePath();
return QByteArray();
}
QByteArray tmdD = ReadFile( tmds.at( 0 ).absoluteFilePath() );
if( tmdD.isEmpty() )
return QByteArray();
return QByteArray();
QFileInfoList tiks = dir.entryInfoList( QStringList() << "*.tik" << "cetk", QDir::Files );
if( tiks.isEmpty() )
{
qWarning() << "Wad::FromDirectory -> no tik found in" << dir.absolutePath();
return QByteArray();
qWarning() << "Wad::FromDirectory -> no tik found in" << dir.absolutePath();
return QByteArray();
}
QByteArray tikD = ReadFile( tiks.at( 0 ).absoluteFilePath() );
if( tikD.isEmpty() )
return QByteArray();
return QByteArray();
Tmd t( tmdD );
Ticket ticket( tikD );
@ -502,45 +502,45 @@ QByteArray Wad::FromDirectory( QDir dir )
bool tmdChanged = false;
for( quint16 i = 0; i < cnt; i++ )
{
QByteArray appD = ReadFile( dir.absoluteFilePath( t.Cid( i ) + ".app" ) );
if( appD.isEmpty() )
return QByteArray();
QByteArray appD = ReadFile( dir.absoluteFilePath( t.Cid( i ) + ".app" ) );
if( appD.isEmpty() )
return QByteArray();
if( (quint32)appD.size() != t.Size( i ) )
{
t.SetSize( i, appD.size() );
tmdChanged = true;
}
QByteArray realHash = GetSha1( appD );
if( t.Hash( i ) != realHash )
{
t.SetHash( i, realHash );
tmdChanged = true;
}
datas << appD;
if( (quint32)appD.size() != t.Size( i ) )
{
t.SetSize( i, appD.size() );
tmdChanged = true;
}
QByteArray realHash = GetSha1( appD );
if( t.Hash( i ) != realHash )
{
t.SetHash( i, realHash );
tmdChanged = true;
}
datas << appD;
}
//if something in the tmd changed, fakesign it and replace the data in our list with the new data
if( tmdChanged )
{
if( !t.FakeSign() )
{
qWarning() << "Error signing the wad";
}
else
{
datas.replace( 0, t.Data() );
}
if( !t.FakeSign() )
{
qWarning() << "Error signing the wad";
}
else
{
datas.replace( 0, t.Data() );
}
}
Wad wad( datas, false );
if( !wad.IsOk() )
return QByteArray();
return QByteArray();
QFileInfoList certs = dir.entryInfoList( QStringList() << "*.cert", QDir::Files );
if( !certs.isEmpty() )
{
QByteArray certD = ReadFile( certs.at( 0 ).absoluteFilePath() );
if( !certD.isEmpty() )
wad.SetCert( certD );
QByteArray certD = ReadFile( certs.at( 0 ).absoluteFilePath() );
if( !certD.isEmpty() )
wad.SetCert( certD );
}
QByteArray ret = wad.Data();
@ -679,6 +679,6 @@ QByteArray FromPartList( const QList< QByteArray > &stuff, bool isEncrypted = tr
{
Wad wad( stuff, isEncrypted );
if( !wad.IsOk() )
return QByteArray();
return QByteArray();
return wad.Data();
}

View File

@ -50,88 +50,88 @@ void ShowBootInfo( quint8 boot1, QList<Boot2Info> boot2stuff )
switch( boot1 )
{
case BOOT_1_A:
qDebug() << "Boot1 A (vulnerable)";
break;
qDebug() << "Boot1 A (vulnerable)";
break;
case BOOT_1_B:
qDebug() << "Boot1 B (vulnerable)";
break;
qDebug() << "Boot1 B (vulnerable)";
break;
case BOOT_1_C:
qDebug() << "Boot1 C (fixed)";
break;
qDebug() << "Boot1 C (fixed)";
break;
case BOOT_1_D:
qDebug() << "Boot1 D (fixed)";
break;
qDebug() << "Boot1 D (fixed)";
break;
default:
qDebug() << "unrecognized boot1 version";
break;
qDebug() << "unrecognized boot1 version";
break;
}
quint16 cnt = boot2stuff.size();
if( !cnt )
Fail( "didnt find any boot2. this nand wont work" );
Fail( "didnt find any boot2. this nand wont work" );
qDebug() << "found" << cnt << "copies of boot2";
for( quint16 i = 0; i < cnt; i++ )
{
Boot2Info bi = boot2stuff.at( i );
QString str = QString( "blocks %1 & %2: " ).arg( bi.firstBlock ).arg( bi.secondBlock );
if( bi.state == BOOT_2_ERROR_PARSING || bi.state == BOOT_2_ERROR )
str += "parsing error";
Boot2Info bi = boot2stuff.at( i );
QString str = QString( "blocks %1 & %2: " ).arg( bi.firstBlock ).arg( bi.secondBlock );
if( bi.state == BOOT_2_ERROR_PARSING || bi.state == BOOT_2_ERROR )
str += "parsing error";
else if( bi.state == BOOT_2_BAD_SIGNATURE )
str += "Bad RSA Signature";
str += "Bad RSA Signature";
else if( bi.state == BOOT_2_BAD_CONTENT_HASH )
str += "Content hash doesn't match TMD";
str += "Content hash doesn't match TMD";
else if( bi.state == BOOT_2_ERROR_PARSING )
str += "Error parsing boot2";
str += "Error parsing boot2";
else
{
if( bi.state & BOOT_2_MARKED_BAD )
str += "Marked as bad blocks; ";
else if( bi.state & BOOT_2_USED_TO_BOOT )
{
str += "Used for booting; ";
if( boot1 != BOOT_1_A && boot1 != BOOT_1_B
&& (( bi.state & BOOT_2_TIK_FAKESIGNED) ||
( bi.state & BOOT_2_TMD_FAKESIGNED ) ) )
Fail( "The version of boot1 installed doesn't have the strncmp bug and the copy of boot2 used for booting is fakesigned" );
}
else if( bi.state & BOOT_2_BACKUP_COPY )
str += "Backup copy; ";
if( bi.state & BOOT_2_MARKED_BAD )
str += "Marked as bad blocks; ";
else if( bi.state & BOOT_2_USED_TO_BOOT )
{
str += "Used for booting; ";
if( boot1 != BOOT_1_A && boot1 != BOOT_1_B
&& (( bi.state & BOOT_2_TIK_FAKESIGNED) ||
( bi.state & BOOT_2_TMD_FAKESIGNED ) ) )
Fail( "The version of boot1 installed doesn't have the strncmp bug and the copy of boot2 used for booting is fakesigned" );
}
else if( bi.state & BOOT_2_BACKUP_COPY )
str += "Backup copy; ";
str += "Content Sha1 matches TMD; ";
str += "Content Sha1 matches TMD; ";
if( bi.state & BOOT_2_TMD_FAKESIGNED )
str += "TMD is fakesigned; ";
else if( bi.state & BOOT_2_TMD_SIG_OK )
str += "TMD officially signed; ";
else
str += "Error checking TMD; " ;
if( bi.state & BOOT_2_TMD_FAKESIGNED )
str += "TMD is fakesigned; ";
else if( bi.state & BOOT_2_TMD_SIG_OK )
str += "TMD officially signed; ";
else
str += "Error checking TMD; " ;
if( bi.state & BOOT_2_TIK_FAKESIGNED )
str += "Ticket is fakesigned; ";
else if( bi.state & BOOT_2_TIK_SIG_OK )
str += "Ticket officially signed; ";
else
str += "Error checking ticket; ";
if( bi.state & BOOT_2_TIK_FAKESIGNED )
str += "Ticket is fakesigned; ";
else if( bi.state & BOOT_2_TIK_SIG_OK )
str += "Ticket officially signed; ";
else
str += "Error checking ticket; ";
QString ver;
switch( bi.version )
{
case BOOTMII_11:
ver = "BootMii 1.1";
break;
case BOOTMII_13:
ver = "BootMii 1.3";
break;
case BOOTMII_UNK:
ver = "BootMii (Unk)";
break;
default:
ver = QString( "Version %1" ).arg( bi.version );
break;
}
str += ver;
QString ver;
switch( bi.version )
{
case BOOTMII_11:
ver = "BootMii 1.1";
break;
case BOOTMII_13:
ver = "BootMii 1.3";
break;
case BOOTMII_UNK:
ver = "BootMii (Unk)";
break;
default:
ver = QString( "Version %1" ).arg( bi.version );
break;
}
str += ver;
}
qDebug() << str;
}
@ -142,11 +142,11 @@ QTreeWidgetItem *FindItem( const QString &s, QTreeWidgetItem *parent )
int cnt = parent->childCount();
for( int i = 0; i <cnt; i++ )
{
QTreeWidgetItem *r = parent->child( i );
if( r->text( 0 ) == s )
{
return r;
}
QTreeWidgetItem *r = parent->child( i );
if( r->text( 0 ) == s )
{
return r;
}
}
return NULL;
}
@ -156,20 +156,20 @@ QTreeWidgetItem *ItemFromPath( const QString &path )
QTreeWidgetItem *item = root;
if( !path.startsWith( "/" ) || path.contains( "//" ))
{
return NULL;
return NULL;
}
int slash = 1;
while( slash )
{
int nextSlash = path.indexOf( "/", slash + 1 );
QString lookingFor = path.mid( slash, nextSlash - slash );
item = FindItem( lookingFor, item );
if( !item )
{
qWarning() << "ItemFromPath ->item not found" << path;
return NULL;
}
slash = nextSlash + 1;
int nextSlash = path.indexOf( "/", slash + 1 );
QString lookingFor = path.mid( slash, nextSlash - slash );
item = FindItem( lookingFor, item );
if( !item )
{
qWarning() << "ItemFromPath ->item not found" << path;
return NULL;
}
slash = nextSlash + 1;
}
return item;
}
@ -179,10 +179,10 @@ QString PathFromItem( QTreeWidgetItem *item )
QString ret;
while( item )
{
ret.prepend( "/" + item->text( 0 ) );
item = item->parent();
if( item->text( 0 ) == "/" )// dont add the root
break;
ret.prepend( "/" + item->text( 0 ) );
item = item->parent();
if( item->text( 0 ) == "/" )// dont add the root
break;
}
return ret;
@ -194,50 +194,50 @@ QList< quint64 > InstalledTitles()
QList< quint64 > ret;
QTreeWidgetItem *tikFolder = ItemFromPath( "/ticket" );
if( !tikFolder )
Fail( "Couldnt find a ticket folder in this nand" );
Fail( "Couldnt find a ticket folder in this nand" );
quint16 subfc = tikFolder->childCount();
for( quint16 i = 0; i < subfc; i++ )//check all subfolders of "/ticket"
{
QTreeWidgetItem *subF = tikFolder->child( i );
//qDebug() << "checking folder" << subF->text( 0 );
bool ok = false;
quint32 upper = subF->text( 0 ).toInt( &ok, 16 );//make sure it can be converted to int
if ( !ok )
continue;
QTreeWidgetItem *subF = tikFolder->child( i );
//qDebug() << "checking folder" << subF->text( 0 );
bool ok = false;
quint32 upper = subF->text( 0 ).toInt( &ok, 16 );//make sure it can be converted to int
if ( !ok )
continue;
quint16 subfc2 = subF->childCount();//get all entries in this subfolder
for( quint16 j = 0; j < subfc2; j++ )
{
QTreeWidgetItem *tikI = subF->child( j );
QString name = tikI->text( 0 );
//qDebug() << "checking item" << subF->text( 0 ) + "/" + name;
if( !name.endsWith( ".tik" ) )
{
//qDebug() << "!tik";
continue;
}
quint16 subfc2 = subF->childCount();//get all entries in this subfolder
for( quint16 j = 0; j < subfc2; j++ )
{
QTreeWidgetItem *tikI = subF->child( j );
QString name = tikI->text( 0 );
//qDebug() << "checking item" << subF->text( 0 ) + "/" + name;
if( !name.endsWith( ".tik" ) )
{
//qDebug() << "!tik";
continue;
}
name.resize( 8 );
quint32 lower = name.toInt( &ok, 16 );
if( !ok )
{
//qDebug() << "!ok";
continue;
}
name.resize( 8 );
quint32 lower = name.toInt( &ok, 16 );
if( !ok )
{
//qDebug() << "!ok";
continue;
}
//now see if there is a tmd
QTreeWidgetItem *tmdI = ItemFromPath( "/title/" + subF->text( 0 ) + "/" + name + "/content/title.tmd" );
if( !tmdI )
{
//qDebug() << "no tmd";
continue;
}
//now see if there is a tmd
QTreeWidgetItem *tmdI = ItemFromPath( "/title/" + subF->text( 0 ) + "/" + name + "/content/title.tmd" );
if( !tmdI )
{
//qDebug() << "no tmd";
continue;
}
quint64 tid = (( (quint64)upper << 32) | lower );
//qDebug() << "adding item to list" << TidTxt( tid );
ret << tid;
}
quint64 tid = (( (quint64)upper << 32) | lower );
//qDebug() << "adding item to list" << TidTxt( tid );
ret << tid;
}
}
return ret;
}
@ -246,21 +246,21 @@ void CheckShared()
{
QByteArray ba = nand.GetData( "/shared1/content.map" );
if( ba.isEmpty() )
Fail( "No content map found in the nand" );
Fail( "No content map found in the nand" );
sharedM = SharedContentMap( ba );
quint16 cnt = sharedM.Count();
for( quint16 i = 0; i < cnt; i++ )
{
QString path = "/shared1/" + sharedM.Cid( i ) + ".app";
qDebug() << "checking" << path << "...";
QByteArray stuff = nand.GetData( path );
if( stuff.isEmpty() )
Fail( "One of the shared contents in this nand is missing" );
QString path = "/shared1/" + sharedM.Cid( i ) + ".app";
qDebug() << "checking" << path << "...";
QByteArray stuff = nand.GetData( path );
if( stuff.isEmpty() )
Fail( "One of the shared contents in this nand is missing" );
QByteArray realHash = GetSha1( stuff );
if( realHash != sharedM.Hash( i ) )
Fail( "The hash for at least 1 content is bad" );
QByteArray realHash = GetSha1( stuff );
if( realHash != sharedM.Hash( i ) )
Fail( "The hash for at least 1 content is bad" );
}
}
@ -268,43 +268,43 @@ void BuildGoodIosList()
{
foreach( quint64 tid, tids )
{
quint32 upper = ( tid >> 32 ) & 0xffffffff;
if( upper != 1 )
continue;
quint32 upper = ( tid >> 32 ) & 0xffffffff;
if( upper != 1 )
continue;
quint32 lower = tid & 0xffffffff;
quint32 lower = tid & 0xffffffff;
if( lower < 3 || lower > 255 )
continue;
if( lower < 3 || lower > 255 )
continue;
QString tmdp = TidTxt( tid );
tmdp.insert( 8, "/" );
tmdp.prepend( "/title/" );
tmdp += "/content/title.tmd";
QByteArray ba = nand.GetData( tmdp );
if( ba.isEmpty() )
continue;
QString tmdp = TidTxt( tid );
tmdp.insert( 8, "/" );
tmdp.prepend( "/title/" );
tmdp += "/content/title.tmd";
QByteArray ba = nand.GetData( tmdp );
if( ba.isEmpty() )
continue;
Tmd t( ba ); //skip stubbzzzzz
if( !( t.Version() % 0x100 ) && //version is a nice pretty round number
t.Count() == 3 && //3 contents, 1 private and 2 shared
t.Type( 0 ) == 1 &&
t.Type( 1 ) == 0x8001 &&
t.Type( 2 ) == 0x8001 )
{
continue;
}
if( !CheckTitleIntegrity( tid ) )
continue;
Tmd t( ba ); //skip stubbzzzzz
if( !( t.Version() % 0x100 ) && //version is a nice pretty round number
t.Count() == 3 && //3 contents, 1 private and 2 shared
t.Type( 0 ) == 1 &&
t.Type( 1 ) == 0x8001 &&
t.Type( 2 ) == 0x8001 )
{
continue;
}
if( !CheckTitleIntegrity( tid ) )
continue;
validIoses << tid;//seems good enough. add it to the list
validIoses << tid;//seems good enough. add it to the list
}
}
bool CheckTitleIntegrity( quint64 tid )
{
if( validIoses.contains( tid ) )//this one has already been checked
return true;
return true;
qDebug() << "Checking" << TidTxt( tid ).insert( 8, "-" ) << "...";
QString p = TidTxt( tid );
@ -322,101 +322,101 @@ bool CheckTitleIntegrity( quint64 tid )
//remember the tmd for checking the actual contents
for( quint8 i = 0; i < 2; i++ )
{
QString it = ( i ? "tmd" : "ticket" );
QByteArray ba = nand.GetData( i ? tmdp : tikp );
if( ba.isEmpty() )
{
qDebug() << "error getting" << it << "data";
return false;
}
switch( check_cert_chain( ba ) )
{
case ERROR_SIG_TYPE:
case ERROR_SUB_TYPE:
case ERROR_RSA_HASH:
case ERROR_RSA_TYPE_UNKNOWN:
case ERROR_RSA_TYPE_MISMATCH:
case ERROR_CERT_NOT_FOUND:
qDebug() << "\t" << it << "RSA signature isn't even close";
//return false; //maye in the future this will be true, but for now, this doesnt mean it wont boot
break;
case ERROR_RSA_FAKESIGNED:
qDebug() << "\t" << it << "fakesigned";
break;
default:
break;
}
if( i )
{
t = Tmd( ba );
if( t.Tid() != tid )
{
qDebug() << "the TMD contains the wrong TID";
return false;
}
}
else
{
Ticket ticket( ba );
if( ticket.Tid() != tid )
{
qDebug() << "the ticket contains the wrong TID";
return false;
}
}
QString it = ( i ? "tmd" : "ticket" );
QByteArray ba = nand.GetData( i ? tmdp : tikp );
if( ba.isEmpty() )
{
qDebug() << "error getting" << it << "data";
return false;
}
switch( check_cert_chain( ba ) )
{
case ERROR_SIG_TYPE:
case ERROR_SUB_TYPE:
case ERROR_RSA_HASH:
case ERROR_RSA_TYPE_UNKNOWN:
case ERROR_RSA_TYPE_MISMATCH:
case ERROR_CERT_NOT_FOUND:
qDebug() << "\t" << it << "RSA signature isn't even close";
//return false; //maye in the future this will be true, but for now, this doesnt mean it wont boot
break;
case ERROR_RSA_FAKESIGNED:
qDebug() << "\t" << it << "fakesigned";
break;
default:
break;
}
if( i )
{
t = Tmd( ba );
if( t.Tid() != tid )
{
qDebug() << "the TMD contains the wrong TID";
return false;
}
}
else
{
Ticket ticket( ba );
if( ticket.Tid() != tid )
{
qDebug() << "the ticket contains the wrong TID";
return false;
}
}
}
quint32 upper = ((tid >>32 ) & 0xffffffff);
if( upper == 0x10005 || upper == 0x10007 ) //dont try to verify all the contents of DLC, it will just find a bunch of missing contents and bitch about them
return true;
return true;
quint16 cnt = t.Count();
for( quint16 i = 0; i < cnt; i++ )
{
if( t.Type( i ) == 0x8001 )//shared
{
if( sharedM.GetAppFromHash( t.Hash( i ) ).isEmpty() )
{
qDebug() << "one of the shared contents is missing";
return false;
}
}
else//private
{
QString cid = t.Cid( i );
QString pA = tmdp;
pA.resize( 33 );
pA += cid + ".app";
QByteArray ba = nand.GetData( pA );
if( ba.isEmpty() )
{
qDebug() << "one of the private contents is missing" << pA;
return false;
}
QByteArray realH = GetSha1( ba );
if( realH != t.Hash( i ) )
{
qDebug() << "\tone of the private contents' hash doesnt check out" << i << pA <<
"\n\texpected" << t.Hash( i ).toHex() <<
"\n\tactual " << realH.toHex();
//return false; //dont return false, as this this title may still boot
}
}
if( t.Type( i ) == 0x8001 )//shared
{
if( sharedM.GetAppFromHash( t.Hash( i ) ).isEmpty() )
{
qDebug() << "one of the shared contents is missing";
return false;
}
}
else//private
{
QString cid = t.Cid( i );
QString pA = tmdp;
pA.resize( 33 );
pA += cid + ".app";
QByteArray ba = nand.GetData( pA );
if( ba.isEmpty() )
{
qDebug() << "one of the private contents is missing" << pA;
return false;
}
QByteArray realH = GetSha1( ba );
if( realH != t.Hash( i ) )
{
qDebug() << "\tone of the private contents' hash doesnt check out" << i << pA <<
"\n\texpected" << t.Hash( i ).toHex() <<
"\n\tactual " << realH.toHex();
//return false; //dont return false, as this this title may still boot
}
}
}
quint64 ios = t.IOS();
if( ios && !validIoses.contains( ios ) )
{
qDebug() << "\tthe IOS for this title is not bootable\n\t" << TidTxt( ios ).insert( 8, "-" ) ;
return false;
qDebug() << "\tthe IOS for this title is not bootable\n\t" << TidTxt( ios ).insert( 8, "-" ) ;
return false;
}
quint32 uid = uidM.GetUid( tid, false );
if( !uid )
{
qDebug() << "\tthis title has no UID entry";
return false;
qDebug() << "\tthis title has no UID entry";
return false;
}
//make sure all the stuff in this title's data directory belongs to it, and all the contents belong to nobody
@ -427,31 +427,31 @@ bool CheckTitleIntegrity( quint64 tid )
QTreeWidgetItem *dataI = ItemFromPath( dataP );
if( dataI )
{
quint16 gid = t.Gid();
QString uidS = QString( "%1" ).arg( uid, 8, 16, QChar( '0' ) );
QString gidS = QString( "%1" ).arg( gid, 4, 16, QChar( '0' ) );
if( dataI->text( 3 ) != uidS || !dataI->text( 4 ).startsWith( gidS ) )//dont necessarily fail for this. the title will still be bootable without its data
qDebug() << "\tincorrect uid/gid for data folder";
quint16 cnt = dataI->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
QTreeWidgetItem *item = dataI->child( i );
if( item->text( 3 ) != uidS || !item->text( 4 ).startsWith( gidS ) )
qDebug() << "\tincorrect uid/gid for" << QString( "data/" + item->text( 0 ) );
}
quint16 gid = t.Gid();
QString uidS = QString( "%1" ).arg( uid, 8, 16, QChar( '0' ) );
QString gidS = QString( "%1" ).arg( gid, 4, 16, QChar( '0' ) );
if( dataI->text( 3 ) != uidS || !dataI->text( 4 ).startsWith( gidS ) )//dont necessarily fail for this. the title will still be bootable without its data
qDebug() << "\tincorrect uid/gid for data folder";
quint16 cnt = dataI->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
QTreeWidgetItem *item = dataI->child( i );
if( item->text( 3 ) != uidS || !item->text( 4 ).startsWith( gidS ) )
qDebug() << "\tincorrect uid/gid for" << QString( "data/" + item->text( 0 ) );
}
}
dataP.resize( 25 );
dataP += "content";
dataI = ItemFromPath( dataP );
if( dataI )
{
quint16 cnt = dataI->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
QTreeWidgetItem *item = dataI->child( i );
if( item->text( 3 ) != "00000000" || !item->text( 4 ).startsWith( "0000" ) )
qDebug() << "\tincorrect uid/gid for" << QString( "content/" + item->text( 0 ) );
}
quint16 cnt = dataI->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
QTreeWidgetItem *item = dataI->child( i );
if( item->text( 3 ) != "00000000" || !item->text( 4 ).startsWith( "0000" ) )
qDebug() << "\tincorrect uid/gid for" << QString( "content/" + item->text( 0 ) );
}
}
return true;
}
@ -466,28 +466,28 @@ void CheckLostClusters()
fats = nand.GetFats();
for( quint16 i = 0; i < 0x8000; i++ )
{
if( u.contains( fats.at( i ) ) )//this cluster is really used
continue;
switch( fats.at( i ) )
{
case 0xFFFB:
case 0xFFFC:
case 0xFFFD:
break;
case 0xFFFE:
frs << i;
break;
case 0xFFFF:
ffs << i;
break;
default:
lost++;
//qDebug() << hex << i << fats.at( i );
break;
}
if( u.contains( fats.at( i ) ) )//this cluster is really used
continue;
switch( fats.at( i ) )
{
case 0xFFFB:
case 0xFFFC:
case 0xFFFD:
break;
case 0xFFFE:
frs << i;
break;
case 0xFFFF:
ffs << i;
break;
default:
lost++;
//qDebug() << hex << i << fats.at( i );
break;
}
}
qDebug() << "found" << lost << "lost clusters\nUNK ( 0xffff )" << hex << ffs.size() << ffs <<
"\nfree " << frs.size();
"\nfree " << frs.size();
}
void CheckEcc()
@ -499,33 +499,33 @@ void CheckEcc()
quint16 badClustersNotSpecial = 0;
for( quint16 i = 0; i < 0x8000; i++ )
{
if( fats.at( i ) == 0xfffd || fats.at( i ) == 0xfffe )
continue;
//qDebug() << hex << i;
if( fats.at( i ) == 0xfffd || fats.at( i ) == 0xfffe )
continue;
//qDebug() << hex << i;
for( quint8 j = 0; j < 8; j++, checked += 8 )
{
quint32 page = ( i * 8 ) + j;
if( !nand.CheckEcc( page ) )
{
bad << page;
if( !clusters.contains( i ) )
clusters << i;
}
}
for( quint8 j = 0; j < 8; j++, checked += 8 )
{
quint32 page = ( i * 8 ) + j;
if( !nand.CheckEcc( page ) )
{
bad << page;
if( !clusters.contains( i ) )
clusters << i;
}
}
}
QList< quint16 > blocks;
QList< quint16 > clustersCpy = clusters;
while( clustersCpy.size() )
{
quint16 p = clustersCpy.takeFirst();
if( fats.at( p ) < 0xfff0 )
badClustersNotSpecial ++;
//qDebug() << p << hex << fats.at( p );
quint16 block = p/8;
if( !blocks.contains( block ) )
blocks << block;
quint16 p = clustersCpy.takeFirst();
if( fats.at( p ) < 0xfff0 )
badClustersNotSpecial ++;
//qDebug() << p << hex << fats.at( p );
quint16 block = p/8;
if( !blocks.contains( block ) )
blocks << block;
}
/*QList< quint32 > badCpy = bad;
while( badCpy.size() )
@ -536,7 +536,7 @@ void CheckEcc()
blocks << block;
}*/
qDebug() << bad.size() << "out of" << checked << "pages had incorrect ecc.\nthey were spread through"
<< clusters.size() << "clusters in" << blocks.size() << "blocks:\n" << blocks;
<< clusters.size() << "clusters in" << blocks.size() << "blocks:\n" << blocks;
qDebug() << badClustersNotSpecial << "of those clusters are non-special (they belong to the fs)";
//qDebug() << bad;
}
@ -544,10 +544,10 @@ void CheckEcc()
void SetUpTree()
{
if( root )
return;
return;
QTreeWidgetItem *r = nand.GetTree();
if( r->childCount() != 1 || r->child( 0 )->text( 0 ) != "/" )
Fail( "The nand FS is seriously broken. I Couldn't even find a correct root" );
Fail( "The nand FS is seriously broken. I Couldn't even find a correct root" );
root = r->takeChild( 0 );
delete r;
@ -559,13 +559,13 @@ int RecurseCountFiles( QTreeWidgetItem *dir )
quint16 cnt = dir->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
QTreeWidgetItem *item = dir->child( i );
if( item->text( 7 ).startsWith( "02" ) )
ret += RecurseCountFiles( item );
else
{
ret++;
}
QTreeWidgetItem *item = dir->child( i );
if( item->text( 7 ).startsWith( "02" ) )
ret += RecurseCountFiles( item );
else
{
ret++;
}
}
return ret;
}
@ -576,22 +576,22 @@ int RecurseCheckHmac( QTreeWidgetItem *dir )
quint16 cnt = dir->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
QTreeWidgetItem *item = dir->child( i );
if( item->text( 7 ).startsWith( "02" ) )
ret += RecurseCheckHmac( item );
else
{
bool ok = false;
quint16 entry = item->text( 1 ).toInt( &ok );
if( !ok )
continue;
QTreeWidgetItem *item = dir->child( i );
if( item->text( 7 ).startsWith( "02" ) )
ret += RecurseCheckHmac( item );
else
{
bool ok = false;
quint16 entry = item->text( 1 ).toInt( &ok );
if( !ok )
continue;
if( !nand.CheckHmacData( entry ) )
{
qDebug() << "bad HMAC for" << PathFromItem( item );
ret++;
}
}
if( !nand.CheckHmacData( entry ) )
{
qDebug() << "bad HMAC for" << PathFromItem( item );
ret++;
}
}
}
return ret;
}
@ -606,12 +606,12 @@ void CheckHmac()
QList<quint16> sclBad;
for( quint16 i = 0x7f00; i < 0x8000; i += 0x10 )
{
if( !nand.CheckHmacMeta( i ) )
sclBad << i;
if( !nand.CheckHmacMeta( i ) )
sclBad << i;
}
qDebug() << sclBad.size() << "superClusters had bad HMAC data";
if( sclBad.size() )
qDebug() << sclBad;
qDebug() << sclBad;
}
int main( int argc, char *argv[] )
@ -619,64 +619,64 @@ int main( int argc, char *argv[] )
QCoreApplication a( argc, argv );
QStringList args = QCoreApplication::arguments();
if( args.size() < 2 )
Usage();
Usage();
if( !QFile( args.at( 1 ) ).exists() )
Usage();
Usage();
if( !nand.SetPath( args.at( 1 ) ) || !nand.InitNand() )
Fail( "Error setting path to nand object" );
Fail( "Error setting path to nand object" );
root = NULL;
//these only serve to show info. no action is taken
if( args.contains( "-boot", Qt::CaseInsensitive ) || args.contains( "-all", Qt::CaseInsensitive ) )
{
qDebug() << "checking boot1 & 2...";
ShowBootInfo( nand.Boot1Version(), nand.Boot2Infos() );
qDebug() << "checking boot1 & 2...";
ShowBootInfo( nand.Boot1Version(), nand.Boot2Infos() );
}
if( args.contains( "-fs", Qt::CaseInsensitive ) || args.contains( "-all", Qt::CaseInsensitive ) )
{
qDebug() << "checking uid.sys...";
QByteArray ba = nand.GetData( "/sys/uid.sys" );
if( ba.isEmpty() )
Fail( "No uid map found in the nand" );
uidM = UIDmap( ba );
uidM.Check(); //dont really take action, the check should spit out info if there is an error. not all errors are fatal
qDebug() << "checking uid.sys...";
QByteArray ba = nand.GetData( "/sys/uid.sys" );
if( ba.isEmpty() )
Fail( "No uid map found in the nand" );
uidM = UIDmap( ba );
uidM.Check(); //dont really take action, the check should spit out info if there is an error. not all errors are fatal
qDebug() << "checking content.map...";
CheckShared(); //check for the presence of the content.map as well as verify all the hashes
qDebug() << "checking content.map...";
CheckShared(); //check for the presence of the content.map as well as verify all the hashes
SetUpTree();
SetUpTree();
tids = InstalledTitles();
tids = InstalledTitles();
qDebug() << "found" << tids.size() << "titles installed";
BuildGoodIosList();
qDebug() << "found" << validIoses.size() << "bootable IOS";
foreach( quint64 tid, tids )
{
CheckTitleIntegrity( tid );
//if( !CheckTitleIntegrity( tid ) && tid == 0x100000002ull ) //well, this SHOULD be the case. but nintendo doesnt care so much about
//Fail( "The System menu isnt valid" ); //checking signatures & hashes as the rest of us.
}
qDebug() << "found" << tids.size() << "titles installed";
BuildGoodIosList();
qDebug() << "found" << validIoses.size() << "bootable IOS";
foreach( quint64 tid, tids )
{
CheckTitleIntegrity( tid );
//if( !CheckTitleIntegrity( tid ) && tid == 0x100000002ull ) //well, this SHOULD be the case. but nintendo doesnt care so much about
//Fail( "The System menu isnt valid" ); //checking signatures & hashes as the rest of us.
}
}
if( args.contains( "-clInfo", Qt::CaseInsensitive ) || args.contains( "-all", Qt::CaseInsensitive ) )
{
qDebug() << "checking for lost clusters...";
CheckLostClusters();
qDebug() << "checking for lost clusters...";
CheckLostClusters();
}
if( args.contains( "-spare", Qt::CaseInsensitive ) || args.contains( "-all", Qt::CaseInsensitive ) )
{
qDebug() << "verifying ecc...";
CheckEcc();
qDebug() << "verifying ecc...";
CheckEcc();
SetUpTree();
qDebug() << "verifying hmac...";
CheckHmac();
SetUpTree();
qDebug() << "verifying hmac...";
CheckHmac();
}

View File

@ -9,34 +9,34 @@ Boot2InfoDialog::Boot2InfoDialog( QWidget *parent, QList<Boot2Info> boot, quint8
switch( boot1version )
{
case BOOT_1_A:
ui->label_boot1->setText( "Boot1 A (vulnerable)");
break;
ui->label_boot1->setText( "Boot1 A (vulnerable)");
break;
case BOOT_1_B:
ui->label_boot1->setText( "Boot1 B (vulnerable)");
break;
ui->label_boot1->setText( "Boot1 B (vulnerable)");
break;
case BOOT_1_C:
ui->label_boot1->setText( "Boot1 C (fixed)");
break;
ui->label_boot1->setText( "Boot1 C (fixed)");
break;
case BOOT_1_D:
ui->label_boot1->setText( "Boot1 D (fixed)");
break;
ui->label_boot1->setText( "Boot1 D (fixed)");
break;
}
quint8 c = boot.size();
if( !c )
return;
return;
ui->label_foundTxt->setText( QString( "Found %1 copies of boot2" ).arg( c ) );
boot2s = boot;
for( quint8 i = 0; i < c; i++ )
{
QString entry = QString( "%1 - %2" ).arg( boot.at( i ).firstBlock ).arg( boot.at( i ).secondBlock );
ui->comboBox_boot2->addItem( entry );
if( boot.at( i ).state & BOOT_2_USED_TO_BOOT )
{
ui->comboBox_boot2->setCurrentIndex( i );
}
QString entry = QString( "%1 - %2" ).arg( boot.at( i ).firstBlock ).arg( boot.at( i ).secondBlock );
ui->comboBox_boot2->addItem( entry );
if( boot.at( i ).state & BOOT_2_USED_TO_BOOT )
{
ui->comboBox_boot2->setCurrentIndex( i );
}
}
}
@ -48,7 +48,7 @@ Boot2InfoDialog::~Boot2InfoDialog()
void Boot2InfoDialog::on_comboBox_boot2_currentIndexChanged( int index )
{
if( index > boot2s.size() )
return;
return;
Boot2Info bi = boot2s.at( index );
ui->label_boot2Version->clear();
@ -60,57 +60,57 @@ void Boot2InfoDialog::on_comboBox_boot2_currentIndexChanged( int index )
if( bi.state == BOOT_2_ERROR_PARSING || bi.state == BOOT_2_ERROR )
ui->lineEdit_contentStatus->setText( tr( "Error parsing boot2" ) );
ui->lineEdit_contentStatus->setText( tr( "Error parsing boot2" ) );
else if( bi.state == BOOT_2_BAD_SIGNATURE )
ui->lineEdit_contentStatus->setText( tr( "Bad RSA Signature" ) );
ui->lineEdit_contentStatus->setText( tr( "Bad RSA Signature" ) );
else if( bi.state == BOOT_2_BAD_CONTENT_HASH )
ui->lineEdit_contentStatus->setText( tr( "Content hash doesn't match TMD" ) );
ui->lineEdit_contentStatus->setText( tr( "Content hash doesn't match TMD" ) );
else if( bi.state == BOOT_2_ERROR_PARSING )
ui->lineEdit_contentStatus->setText( tr( "Error parsing boot2" ) );
ui->lineEdit_contentStatus->setText( tr( "Error parsing boot2" ) );
else
{
if( bi.state & BOOT_2_MARKED_BAD )
ui->lineEdit_bootStatus->setText( tr( "Marked as bad blocks" ) );
else if( bi.state & BOOT_2_USED_TO_BOOT )
ui->lineEdit_bootStatus->setText( tr( "Used for booting" ) + " " );//in case the backup copy is used for booting
else if( bi.state & BOOT_2_BACKUP_COPY )
ui->lineEdit_bootStatus->setText( ui->lineEdit_bootStatus->text() + tr( "Backup copy" ) );
if( bi.state & BOOT_2_MARKED_BAD )
ui->lineEdit_bootStatus->setText( tr( "Marked as bad blocks" ) );
else if( bi.state & BOOT_2_USED_TO_BOOT )
ui->lineEdit_bootStatus->setText( tr( "Used for booting" ) + " " );//in case the backup copy is used for booting
else if( bi.state & BOOT_2_BACKUP_COPY )
ui->lineEdit_bootStatus->setText( ui->lineEdit_bootStatus->text() + tr( "Backup copy" ) );
ui->lineEdit_contentStatus->setText( tr( "Content Sha1 matches TMD" ) );
ui->lineEdit_contentStatus->setText( tr( "Content Sha1 matches TMD" ) );
if( bi.state & BOOT_2_TMD_FAKESIGNED )
ui->lineEdit_tmdSig->setText( tr( "TMD is fakesigned" ) );
else if( bi.state & BOOT_2_TMD_SIG_OK )
ui->lineEdit_tmdSig->setText( tr( "TMD officially signed" ) );
else
ui->lineEdit_tmdSig->setText( tr( "Error checking TMD" ) );
if( bi.state & BOOT_2_TMD_FAKESIGNED )
ui->lineEdit_tmdSig->setText( tr( "TMD is fakesigned" ) );
else if( bi.state & BOOT_2_TMD_SIG_OK )
ui->lineEdit_tmdSig->setText( tr( "TMD officially signed" ) );
else
ui->lineEdit_tmdSig->setText( tr( "Error checking TMD" ) );
if( bi.state & BOOT_2_TIK_FAKESIGNED )
ui->lineEdit_tikSig->setText( tr( "Ticket is fakesigned" ) );
else if( bi.state & BOOT_2_TIK_SIG_OK )
ui->lineEdit_tikSig->setText( tr( "Ticket officially signed" ) );
else
ui->lineEdit_tikSig->setText( tr( "Error checking ticket" ) );
if( bi.state & BOOT_2_TIK_FAKESIGNED )
ui->lineEdit_tikSig->setText( tr( "Ticket is fakesigned" ) );
else if( bi.state & BOOT_2_TIK_SIG_OK )
ui->lineEdit_tikSig->setText( tr( "Ticket officially signed" ) );
else
ui->lineEdit_tikSig->setText( tr( "Error checking ticket" ) );
QString ver;
switch( bi.version )
{
case BOOTMII_11:
ver = "BootMii 1.1";
break;
case BOOTMII_13:
ver = "BootMii 1.3";
break;
case BOOTMII_UNK:
ver = "BootMii (Unk)";
break;
default:
ver = QString( tr( "Version %1" ).arg( bi.version ) );
break;
}
ui->label_boot2Version->setText( ver );
QString ver;
switch( bi.version )
{
case BOOTMII_11:
ver = "BootMii 1.1";
break;
case BOOTMII_13:
ver = "BootMii 1.3";
break;
case BOOTMII_UNK:
ver = "BootMii (Unk)";
break;
default:
ver = QString( tr( "Version %1" ).arg( bi.version ) );
break;
}
ui->label_boot2Version->setText( ver );
}

View File

@ -25,7 +25,7 @@ NandThread::~NandThread()
wait();
if( itemToExtract )
delete itemToExtract;
delete itemToExtract;
}
bool NandThread::IsRunning()
@ -37,8 +37,8 @@ bool NandThread::SetPath( const QString &path )
{
if( isRunning() )
{
emit SendError( tr( "Wait till the current job is done" ) );
return false;
emit SendError( tr( "Wait till the current job is done" ) );
return false;
}
return nandBin.SetPath( path );
}
@ -47,8 +47,8 @@ const Blocks0to7 NandThread::BootBlocks()
{
if( isRunning() )
{
emit SendError( tr( "Wait till the current job is done" ) );
return Blocks0to7();
emit SendError( tr( "Wait till the current job is done" ) );
return Blocks0to7();
}
return nandBin.BootBlocks();
}
@ -57,8 +57,8 @@ const QList<Boot2Info> NandThread::Boot2Infos()
{
if( isRunning() )
{
emit SendError( tr( "Wait till the current job is done" ) );
return QList<Boot2Info>();
emit SendError( tr( "Wait till the current job is done" ) );
return QList<Boot2Info>();
}
return nandBin.Boot2Infos();
}
@ -67,8 +67,8 @@ quint8 NandThread::Boot1Version()
{
if( isRunning() )
{
emit SendError( tr( "Wait till the current job is done" ) );
return 0;
emit SendError( tr( "Wait till the current job is done" ) );
return 0;
}
return nandBin.Boot1Version();
}
@ -77,8 +77,8 @@ QTreeWidgetItem *NandThread::GetTree()
{
if( isRunning() )
{
emit SendError( tr( "Wait till the current job is done" ) );
return NULL;
emit SendError( tr( "Wait till the current job is done" ) );
return NULL;
}
return nandBin.GetTree();
}
@ -87,8 +87,8 @@ bool NandThread::InitNand( QIcon dirs, QIcon files )
{
if( isRunning() )
{
emit SendError( tr( "Wait till the current job is done" ) );
return false;
emit SendError( tr( "Wait till the current job is done" ) );
return false;
}
return nandBin.InitNand( dirs, files );
}
@ -107,13 +107,13 @@ void NandThread::Extract( QTreeWidgetItem *item, const QString &path )
{
if( isRunning() )
{
emit SendError( tr( "This thread is already doing something. Please wait." ) );
return;
emit SendError( tr( "This thread is already doing something. Please wait." ) );
return;
}
if( !item )
{
emit SendError( tr( "Oh Noez!! I was told to extract with a pointer to NULL :( ." ) );
return;
emit SendError( tr( "Oh Noez!! I was told to extract with a pointer to NULL :( ." ) );
return;
}
abort = false;
extractPath = path;
@ -128,14 +128,14 @@ void NandThread::run()
{
if( abort )
{
qDebug( "NandThread::run -> Thread abort" );
return;
qDebug( "NandThread::run -> Thread abort" );
return;
}
mutex.lock();
if( extractPath.isEmpty() )
{
qDebug() << "NandThread::run -> its empty";
return;
qDebug() << "NandThread::run -> its empty";
return;
}
fileCnt = FileCount( itemToExtract );
idx = 0;
@ -154,13 +154,13 @@ quint32 NandThread::FileCount( QTreeWidgetItem *item )
{
if( item->text( 7 ).startsWith( "02" ) )//its a folder, recurse through it and count all the files
{
quint32 ret = 0;
quint16 cnt = item->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
ret += FileCount( item->child( i ) ) ;
}
return ret;
quint32 ret = 0;
quint16 cnt = item->childCount();
for( quint16 i = 0; i < cnt; i++ )
{
ret += FileCount( item->child( i ) ) ;
}
return ret;
}
//not a folder, must be a file. just return 1
return 1;

View File

@ -10,60 +10,60 @@ class NandThread : public QThread
{
Q_OBJECT
public:
NandThread( QObject *parent = 0 );
~NandThread();
public:
NandThread( QObject *parent = 0 );
~NandThread();
bool IsRunning();
bool IsRunning();
//these just call the same function of the nand.bin object
// dont use them if the thread is running ( it is busy extracting )
// wait till after SendExtractDone() is emitted
bool SetPath( const QString &path );
QTreeWidgetItem *GetTree();
bool InitNand( QIcon dirs = QIcon(), QIcon files = QIcon() );
const QList<quint16> GetFats();
const QList<quint16> GetFatsForFile( quint16 i );
//these just call the same function of the nand.bin object
// dont use them if the thread is running ( it is busy extracting )
// wait till after SendExtractDone() is emitted
bool SetPath( const QString &path );
QTreeWidgetItem *GetTree();
bool InitNand( QIcon dirs = QIcon(), QIcon files = QIcon() );
const QList<quint16> GetFats();
const QList<quint16> GetFatsForFile( quint16 i );
//extract some stuff from a nand.bin in a thread so the gui doesn't freeze up
void Extract( QTreeWidgetItem *item, const QString &path );
void ForceQuit();
//extract some stuff from a nand.bin in a thread so the gui doesn't freeze up
void Extract( QTreeWidgetItem *item, const QString &path );
void ForceQuit();
const Blocks0to7 BootBlocks();
const QList<Boot2Info> Boot2Infos();
quint8 Boot1Version();
const Blocks0to7 BootBlocks();
const QList<Boot2Info> Boot2Infos();
quint8 Boot1Version();
protected:
void run();
protected:
void run();
signals:
void SendProgress( int );
void SendExtractDone();
void SendText( QString );
void SendError( QString );
signals:
void SendProgress( int );
void SendExtractDone();
void SendText( QString );
void SendError( QString );
private:
QMutex mutex;
QWaitCondition condition;
private:
QMutex mutex;
QWaitCondition condition;
QString extractPath;
QTreeWidgetItem *itemToExtract;
NandBin nandBin;
QString extractPath;
QTreeWidgetItem *itemToExtract;
NandBin nandBin;
quint32 fileCnt;
quint32 idx;
quint32 fileCnt;
quint32 idx;
bool abort;
bool abort;
//count the number of files in a given folder
quint32 FileCount( QTreeWidgetItem *item );
//count the number of files in a given folder
quint32 FileCount( QTreeWidgetItem *item );
public slots:
void GetError( QString );
void GetStatusUpdate( QString );
};
public slots:
void GetError( QString );
void GetStatusUpdate( QString );
};
#endif // NANDTHREAD_H

View File

@ -45,14 +45,14 @@ void NandWindow::SetUpBlockMap()
quint16 i = 0;
for( quint16 y = 0; y < 288; y += 9 ) //create all the blocks and make them grey
{
for( quint16 x = 0; x < 1152; x += 9 )
{
pmi[ i ] = new QGraphicsPixmapItem( grey );
pmi[ i ]->setPos( x, y );
gv.addItem( pmi[ i ] );//items belong to this now. no need to delete them
for( quint16 x = 0; x < 1152; x += 9 )
{
pmi[ i ] = new QGraphicsPixmapItem( grey );
pmi[ i ]->setPos( x, y );
gv.addItem( pmi[ i ] );//items belong to this now. no need to delete them
i++;
}
i++;
}
}
QFontMetrics fm( fontMetrics() );
@ -147,8 +147,8 @@ void NandWindow::on_treeWidget_customContextMenuRequested( QPoint pos )
QTreeWidgetItem* item = ui->treeWidget->itemAt( pos );
if( !item )//right-clicked in the partition window, but not on an item
{
qDebug() << "no item selected";
return;
qDebug() << "no item selected";
return;
}
QMenu myMenu( this );
@ -159,16 +159,16 @@ void NandWindow::on_treeWidget_customContextMenuRequested( QPoint pos )
//respond to what was selected
if( s )
{
// something was chosen, do stuff
if( s == &extractA )//extract a file
{
QString path = QFileDialog::getExistingDirectory( this, tr("Select a destination") );
if( path.isEmpty() )
return;
// something was chosen, do stuff
if( s == &extractA )//extract a file
{
QString path = QFileDialog::getExistingDirectory( this, tr("Select a destination") );
if( path.isEmpty() )
return;
ui->progressBar->setVisible( true );
nThread.Extract( item, path );
}
ui->progressBar->setVisible( true );
nThread.Extract( item, path );
}
}
}
@ -177,14 +177,14 @@ void NandWindow::on_actionOpen_Nand_triggered()
{
QString path = QFileDialog::getOpenFileName( this, tr( "Select a Nand to open" ) );
if( path.isEmpty() )
return;
return;
blocks.clear();
if( !nThread.SetPath( path ) )
{
qDebug() << " error in nandBin.SetPath";
ui->statusBar->showMessage( "Error setting path to " + path );
return;
qDebug() << " error in nandBin.SetPath";
ui->statusBar->showMessage( "Error setting path to " + path );
return;
}
ui->statusBar->showMessage( "Loading " + path );
QIcon groupIcon;
@ -195,9 +195,9 @@ void NandWindow::on_actionOpen_Nand_triggered()
if( !nThread.InitNand( groupIcon, keyIcon ) )
{
qDebug() << " error in nandBin.InitNand()";
ui->statusBar->showMessage( "Error reading " + path );
return;
qDebug() << " error in nandBin.InitNand()";
ui->statusBar->showMessage( "Error reading " + path );
return;
}
ui->treeWidget->clear();
@ -216,7 +216,7 @@ void NandWindow::on_actionOpen_Nand_triggered()
//expand the root item
if( ui->treeWidget->topLevelItemCount() )
ui->treeWidget->topLevelItem( 0 )->setExpanded( true );
ui->treeWidget->topLevelItem( 0 )->setExpanded( true );
ui->statusBar->showMessage( "Loaded " + path, 5000 );
}
@ -229,29 +229,29 @@ void NandWindow::GetBlocksfromNand()
QList<quint16> clusters = nThread.GetFats();
if( !clusters.size() == 0x8000 )
{
QMessageBox::warning( this, tr( "Error" ), tr( "Expected 0x8000 clusters from the nand, but got %1 instead!" ).arg( clusters.size(), 0, 16 ), QMessageBox::Ok );
return;
QMessageBox::warning( this, tr( "Error" ), tr( "Expected 0x8000 clusters from the nand, but got %1 instead!" ).arg( clusters.size(), 0, 16 ), QMessageBox::Ok );
return;
}
for( quint16 i = 0; i < 0x8000; i += 8 )//first cluster of each block.
{
quint16 thisBlock = clusters.at( i );
quint16 thisBlock = clusters.at( i );
if( thisBlock == 0xFFFC
|| thisBlock == 0xFFFD )
{
blocks << thisBlock;
continue;
}
bool used = false;
for( quint16 j = i; j < i + 8; j++ )//each individual cluster
{
if( clusters.at( j ) == 0xFFFE )
freeSpace += 0x4000;
if( thisBlock == 0xFFFC
|| thisBlock == 0xFFFD )
{
blocks << thisBlock;
continue;
}
bool used = false;
for( quint16 j = i; j < i + 8; j++ )//each individual cluster
{
if( clusters.at( j ) == 0xFFFE )
freeSpace += 0x4000;
else used = true;
}
blocks << ( used ? 1 : 0xfffe ); // just put 1 for used blocks
else used = true;
}
blocks << ( used ? 1 : 0xfffe ); // just put 1 for used blocks
}
quint32 used = 0x20000000 - freeSpace;
float per = (float)((float)used/(float)0x20000000) * 100.0f;
@ -269,9 +269,9 @@ QList<quint16> NandWindow::ToBlocks( QList<quint16> clusters )
quint16 size = clusters.size();
for( quint16 i = 0; i < size; i++ )
{
quint16 block = ( clusters.at( i ) / 8 );
if( !ret.contains( block ) )
ret << block;
quint16 block = ( clusters.at( i ) / 8 );
if( !ret.contains( block ) )
ret << block;
}
return ret;
}
@ -281,8 +281,8 @@ void NandWindow::DrawBlockMap( QList<quint16> newFile )
{
if( blocks.size() != 0x1000 )
{
qWarning() << "NandWindow::DrawBlockMap -> current blocks are fucked up, son" << hex << blocks.size();
return;
qWarning() << "NandWindow::DrawBlockMap -> current blocks are fucked up, son" << hex << blocks.size();
return;
}
QPixmap blue( ":/blue.png" );
QPixmap green( ":/green.png" );
@ -292,34 +292,34 @@ void NandWindow::DrawBlockMap( QList<quint16> newFile )
for( quint16 i = 0; i < 0x1000; i++ )
{
quint16 thisBlock;
if( !newFile.contains( i ) )
{
thisBlock = blocks.at( i );
}
else
{
thisBlock = 2;
}
switch( thisBlock )
{
default:
case 1://used, but not in this file
pmi[ i ]->setPixmap( green );
break;
case 2://used in this file
pmi[ i ]->setPixmap( pink );
break;
case 0xFFFE://free block
pmi[ i ]->setPixmap( grey );
break;
case 0xFFFC://reserved
pmi[ i ]->setPixmap( blue );
break;
case 0xFFFD: // bad block
pmi[ i ]->setPixmap( black );
break;
}
quint16 thisBlock;
if( !newFile.contains( i ) )
{
thisBlock = blocks.at( i );
}
else
{
thisBlock = 2;
}
switch( thisBlock )
{
default:
case 1://used, but not in this file
pmi[ i ]->setPixmap( green );
break;
case 2://used in this file
pmi[ i ]->setPixmap( pink );
break;
case 0xFFFE://free block
pmi[ i ]->setPixmap( grey );
break;
case 0xFFFC://reserved
pmi[ i ]->setPixmap( blue );
break;
case 0xFFFD: // bad block
pmi[ i ]->setPixmap( black );
break;
}
}
@ -366,13 +366,13 @@ void NandWindow::on_treeWidget_currentItemChanged( QTreeWidgetItem* current, QTr
Q_UNUSED( previous );
if( !current || current->text( 7 ).startsWith( "02" ) )
return;
return;
bool ok = false;
quint16 entry = current->text( 1 ).toInt( &ok );
if( !ok )
{
qDebug() << "NandWindow::on_treeWidget_currentItemChanged ->" << current->text( 1 ) << "isnt a decimal number";
return;
qDebug() << "NandWindow::on_treeWidget_currentItemChanged ->" << current->text( 1 ) << "isnt a decimal number";
return;
}
QList<quint16> clusters = nThread.GetFatsForFile( entry );
@ -382,19 +382,19 @@ void NandWindow::on_treeWidget_currentItemChanged( QTreeWidgetItem* current, QTr
float size = current->text( 2 ).toInt( &ok, 16 );
if( !ok )
{
qDebug() << "error converting" << current->text( 2 ) << "to int";
return;
qDebug() << "error converting" << current->text( 2 ) << "to int";
return;
}
QString unit = "bytes";
if( size > 1024 )
{
unit = "KiB";
size /= 1024.0f;
unit = "KiB";
size /= 1024.0f;
}
if( size > 1024 )
{
unit = "MiB";
size /= 1024.0f;
unit = "MiB";
size /= 1024.0f;
}
QString clusterStr = clusters.size() == 1 ? tr( "%1 cluster" ).arg( 1 ) : tr( "%1 clusters" ).arg( clusters.size() );
QString blockStr = blocks.size() == 1 ? tr( "%1 block" ).arg( 1 ) : tr( "%1 blocks" ).arg( blocks.size() );
@ -412,8 +412,8 @@ void NandWindow::on_actionBoot2_triggered()
QList<Boot2Info> b = nThread.Boot2Infos();
if( b.isEmpty() )
{
qDebug() << "!ok";
return;
qDebug() << "!ok";
return;
}
quint8 boot1 = nThread.Boot1Version();

View File

@ -2,8 +2,6 @@
#define NANDWINDOW_H
#include "../WiiQt/includes.h"
//#include "../WiiQt/nandbin.h"
#include "nandthread.h"
namespace Ui {
@ -33,10 +31,6 @@ private:
QGraphicsTextItem *nandSize; //pointers to the items to show info under the blockmap
QGraphicsTextItem *fileSize;
/*QGraphicsTextItem *badText;
QGraphicsTextItem *freeText;
QGraphicsTextItem *usedText;
QGraphicsTextItem *resText;*/
QList<quint16> blocks; //hold a list of what the blocks in the nand are used for
void GetBlocksfromNand();
@ -59,7 +53,7 @@ private slots:
//void ScaleBlockMap();
protected:
//void resizeEvent( QResizeEvent* event );
//void resizeEvent( QResizeEvent* event );
};
#endif // NANDWINDOW_H

View File

@ -49,13 +49,13 @@ void MainWindow::GetError( const QString &message, NusJob job )
{
QString dataStuff = QString( "%1 items:" ).arg( job.data.size() );
for( int i = 0; i < job.data.size(); i++ )
dataStuff += QString( " %1" ).arg( job.data.at( i ).size(), 0, 16, QChar( ' ' ) );
dataStuff += QString( " %1" ).arg( job.data.at( i ).size(), 0, 16, QChar( ' ' ) );
QString str = tr( "<b>Error getting title from NUS: %1</b>" ).arg( message );
QString j = QString( "NusJob( %1, %2, %3, %4 )<br>" )
.arg( job.tid, 16, 16, QChar( '0' ) )
.arg( job.version ).arg( job.decrypt ? "decrypted" : "encrypted" )
.arg( dataStuff );
.arg( job.tid, 16, 16, QChar( '0' ) )
.arg( job.version ).arg( job.decrypt ? "decrypted" : "encrypted" )
.arg( dataStuff );
ui->plainTextEdit_log->appendHtml( str );
@ -75,34 +75,34 @@ void MainWindow::NusIsDone()
ui->statusBar->showMessage( tr( "Done" ), 5000 );
if( ui->radioButton_folder->isChecked() )
{
ui->lineEdit_extractPath->setEnabled( true );
ui->pushButton_decFolder->setEnabled( true );
ui->lineEdit_extractPath->setEnabled( true );
ui->pushButton_decFolder->setEnabled( true );
}
else if( ui->radioButton_nand->isChecked() )
{
ui->lineEdit_nandPath->setEnabled( true );
ui->pushButton_nandPath->setEnabled( true );
ui->lineEdit_nandPath->setEnabled( true );
ui->pushButton_nandPath->setEnabled( true );
//write the uid.sys and content.map to disc
ShowMessage( tr( "Flushing nand..." ) );
nand.Flush();
//write the uid.sys and content.map to disc
ShowMessage( tr( "Flushing nand..." ) );
nand.Flush();
//make sure there is a setting.txt
QByteArray set = nand.GetSettingTxt();
if( set.isEmpty() )
{
quint8 reg = SETTING_TXT_UNK;
if( ui->lineEdit_tid->text().endsWith( "e", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_PAL;
if( ui->lineEdit_tid->text().endsWith( "j", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_JAP;
if( ui->lineEdit_tid->text().endsWith( "k", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_KOR;
set = SettingTxtDialog::Edit( this, QByteArray(), reg );
if( !set.isEmpty() )
nand.SetSettingTxt( set );
}
/*QMap< quint64, quint16 > t = nand.GetInstalledTitles();
//make sure there is a setting.txt
QByteArray set = nand.GetSettingTxt();
if( set.isEmpty() )
{
quint8 reg = SETTING_TXT_UNK;
if( ui->lineEdit_tid->text().endsWith( "e", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_PAL;
if( ui->lineEdit_tid->text().endsWith( "j", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_JAP;
if( ui->lineEdit_tid->text().endsWith( "k", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_KOR;
set = SettingTxtDialog::Edit( this, QByteArray(), reg );
if( !set.isEmpty() )
nand.SetSettingTxt( set );
}
/*QMap< quint64, quint16 > t = nand.GetInstalledTitles();
QMap< quint64, quint16 >::iterator i = t.begin();
while( i != t.end() )
{
@ -113,8 +113,8 @@ void MainWindow::NusIsDone()
}
else if( ui->radioButton_wad->isChecked() )
{
ui->lineEdit_wad->setEnabled( true );
ui->pushButton_wad->setEnabled( true );
ui->lineEdit_wad->setEnabled( true );
ui->pushButton_wad->setEnabled( true );
}
ui->radioButton_folder->setEnabled( true );
@ -132,19 +132,19 @@ void MainWindow::ReceiveTitleFromNus( NusJob job )
//do something with the data we got
if( ui->radioButton_folder->isChecked() )//copy its decrypted contents to a folder
{
SaveJobToFolder( job );
SaveJobToFolder( job );
}
else if( ui->radioButton_nand->isChecked() )//install this title to a decrypted nand dump for sneek/dolphin
{
bool ok = nand.InstallNusItem( job );
if( ok )
ShowMessage( tr( "Installed %1 title to nand" ).arg( title ) );
else
ShowMessage( tr( "<b>Error %1 title to nand</b>" ).arg( title ) );
bool ok = nand.InstallNusItem( job );
if( ok )
ShowMessage( tr( "Installed %1 title to nand" ).arg( title ) );
else
ShowMessage( tr( "<b>Error %1 title to nand</b>" ).arg( title ) );
}
else if( ui->radioButton_wad->isChecked() )
{
SaveJobToWad( job );
SaveJobToWad( job );
}
}
@ -157,70 +157,70 @@ void MainWindow::on_pushButton_GetTitle_clicked()
quint32 ver = 0;
if( ui->lineEdit_tid->text().size() == 4 )
{
wholeUpdate = true;
wholeUpdate = true;
}
else
{
tid = ui->lineEdit_tid->text().toLongLong( &ok, 16 );
if( !ok )
{
ShowMessage( "<b>Error converting \"" + ui->lineEdit_tid->text() + "\" to a hex number.</b>" );
return;
}
ver = TITLE_LATEST_VERSION;
if( !ui->lineEdit_version->text().isEmpty() )
{
ver = ui->lineEdit_version->text().toInt( &ok, 10 );
if( !ok )
{
ShowMessage( "<b>Error converting \"" + ui->lineEdit_version->text() + "\" to a decimal number.</b>" );
return;
}
if( ver > 0xffff )
{
ShowMessage( tr( "<b>Version %1 is too high. Max is 65535</b>" ).arg( ver ) );
return;
}
}
tid = ui->lineEdit_tid->text().toLongLong( &ok, 16 );
if( !ok )
{
ShowMessage( "<b>Error converting \"" + ui->lineEdit_tid->text() + "\" to a hex number.</b>" );
return;
}
ver = TITLE_LATEST_VERSION;
if( !ui->lineEdit_version->text().isEmpty() )
{
ver = ui->lineEdit_version->text().toInt( &ok, 10 );
if( !ok )
{
ShowMessage( "<b>Error converting \"" + ui->lineEdit_version->text() + "\" to a decimal number.</b>" );
return;
}
if( ver > 0xffff )
{
ShowMessage( tr( "<b>Version %1 is too high. Max is 65535</b>" ).arg( ver ) );
return;
}
}
}
//decide how we want nus to give us the title
bool decrypt = true;
if( ui->radioButton_folder->isChecked() )
{
if( ui->lineEdit_extractPath->text().isEmpty() )
{
ShowMessage( tr( "<b>No path given to save downloads in.</b>" ) );
return;
}
ui->lineEdit_extractPath->setEnabled( false );
ui->pushButton_decFolder->setEnabled( false );
if( ui->lineEdit_extractPath->text().isEmpty() )
{
ShowMessage( tr( "<b>No path given to save downloads in.</b>" ) );
return;
}
ui->lineEdit_extractPath->setEnabled( false );
ui->pushButton_decFolder->setEnabled( false );
}
else if( ui->radioButton_nand->isChecked() )
{
if( nand.GetPath() != ui->lineEdit_nandPath->text() && !nand.SetPath( ui->lineEdit_nandPath->text() ) )
{
ShowMessage( tr( "<b>Error setting the basepath of the nand to %1</b>" )
.arg( QFileInfo( ui->lineEdit_nandPath->text() ).absoluteFilePath() ) );
return;
}
if( ui->lineEdit_nandPath->text().isEmpty() )
{
ShowMessage( tr( "<b>No path given for nand dump base.</b>" ) );
return;
}
ui->lineEdit_nandPath->setEnabled( false );
ui->pushButton_nandPath->setEnabled( false );
if( nand.GetPath() != ui->lineEdit_nandPath->text() && !nand.SetPath( ui->lineEdit_nandPath->text() ) )
{
ShowMessage( tr( "<b>Error setting the basepath of the nand to %1</b>" )
.arg( QFileInfo( ui->lineEdit_nandPath->text() ).absoluteFilePath() ) );
return;
}
if( ui->lineEdit_nandPath->text().isEmpty() )
{
ShowMessage( tr( "<b>No path given for nand dump base.</b>" ) );
return;
}
ui->lineEdit_nandPath->setEnabled( false );
ui->pushButton_nandPath->setEnabled( false );
}
else if( ui->radioButton_wad->isChecked() )
{
if( ui->lineEdit_wad->text().isEmpty() )
{
ShowMessage( tr( "<b>No path given to save wads in.</b>" ) );
return;
}
decrypt = false;
ui->lineEdit_wad->setEnabled( false );
ui->pushButton_wad->setEnabled( false );
if( ui->lineEdit_wad->text().isEmpty() )
{
ShowMessage( tr( "<b>No path given to save wads in.</b>" ) );
return;
}
decrypt = false;
ui->lineEdit_wad->setEnabled( false );
ui->pushButton_wad->setEnabled( false );
}
@ -234,15 +234,15 @@ void MainWindow::on_pushButton_GetTitle_clicked()
nus.SetCachePath( ui->lineEdit_cachePath->text() );
if( wholeUpdate )
{
if( !nus.GetUpdate( ui->lineEdit_tid->text(), decrypt ) )
{
ShowMessage( tr( "<b>I dont know the titles that were in the %1 update</b>" ).arg( ui->lineEdit_tid->text() ) );
return;
}
if( !nus.GetUpdate( ui->lineEdit_tid->text(), decrypt ) )
{
ShowMessage( tr( "<b>I dont know the titles that were in the %1 update</b>" ).arg( ui->lineEdit_tid->text() ) );
return;
}
}
else
{
nus.Get( tid, decrypt, ver );
nus.Get( tid, decrypt, ver );
}
}
@ -271,7 +271,7 @@ void MainWindow::on_pushButton_nandPath_clicked()
QString path = ui->lineEdit_nandPath->text().isEmpty() ? "/media" : ui->lineEdit_nandPath->text();
QString f = QFileDialog::getExistingDirectory( this, tr( "Select Nand Base Folder" ), path );
if( f.isEmpty() )
return;
return;
ui->lineEdit_nandPath->setText( f );
nus.SetCachePath( ui->lineEdit_cachePath->text() );
@ -282,7 +282,7 @@ void MainWindow::on_pushButton_decFolder_clicked()
QString path = ui->lineEdit_extractPath->text().isEmpty() ? QDir::currentPath() : ui->lineEdit_extractPath->text();
QString f = QFileDialog::getExistingDirectory( this, tr( "Select folder to save decrypted titles" ), path );
if( f.isEmpty() )
return;
return;
ui->lineEdit_extractPath->setText( f );
}
@ -292,7 +292,7 @@ void MainWindow::on_pushButton_wad_clicked()
QString path = ui->lineEdit_wad->text().isEmpty() ? QDir::currentPath() : ui->lineEdit_wad->text();
QString f = QFileDialog::getExistingDirectory( this, tr( "Select folder to save wads to" ), path );
if( f.isEmpty() )
return;
return;
ui->lineEdit_wad->setText( f );
}
@ -302,36 +302,38 @@ void MainWindow::on_actionSetting_txt_triggered()
{
if( nand.GetPath() != ui->lineEdit_nandPath->text() && !nand.SetPath( ui->lineEdit_nandPath->text() ) )
{
ShowMessage( tr( "<b>Error setting the basepath of the nand to %1</b>" )
.arg( QFileInfo( ui->lineEdit_nandPath->text() ).absoluteFilePath() ) );
return;
ShowMessage( tr( "<b>Error setting the basepath of the nand to %1</b>" )
.arg( QFileInfo( ui->lineEdit_nandPath->text() ).absoluteFilePath() ) );
return;
}
QByteArray ba = nand.GetSettingTxt(); //read the current setting.txt
ba = SettingTxtDialog::Edit( this, ba ); //call a dialog to edit that existing file and store the result in the same bytearray
if( !ba.isEmpty() ) //if the dialog returned anything ( cancel wasnt pressed ) write that new setting.txt to the nand dump
nand.SetSettingTxt( ba );
nand.SetSettingTxt( ba );
}
//nand-dump -> flush
void MainWindow::on_actionFlush_triggered()
{
if( !nand.GetPath().isEmpty() )
nand.Flush();
nand.Flush();
}
//nand-dump -> ImportWad
void MainWindow::on_actionImportWad_triggered()
{
if( nand.GetPath() != ui->lineEdit_nandPath->text() &&
!nand.SetPath( ui->lineEdit_nandPath->text() ) )
!nand.SetPath( ui->lineEdit_nandPath->text() ) )
{
ShowMessage( tr( "<b>Error setting the basepath of the nand to %1</b>" ).arg( QFileInfo( ui->lineEdit_nandPath->text() ).absoluteFilePath() ) );
return;
}
QString path = ui->lineEdit_wad->text().isEmpty() ?
QCoreApplication::applicationDirPath() : ui->lineEdit_wad->text();
QString fn = QFileDialog::getOpenFileName( this,
tr("Wad files(*.wad)"),
QCoreApplication::applicationDirPath(),
tr("WadFiles (*.wad)"));
tr("Wad files(*.wad)"),
path,
tr("WadFiles (*.wad)"));
if(fn == "") return;
QByteArray data = ReadFile( fn );
@ -357,59 +359,59 @@ void MainWindow::SaveJobToFolder( NusJob job )
QFileInfo fi( ui->lineEdit_extractPath->text() );
if( fi.isFile() )
{
ShowMessage( "<b>" + ui->lineEdit_extractPath->text() + " is a file. I need a folder<\b>" );
return;
ShowMessage( "<b>" + ui->lineEdit_extractPath->text() + " is a file. I need a folder<\b>" );
return;
}
if( !fi.exists() )
{
ShowMessage( "<b>" + fi.absoluteFilePath() + " is not a folder!\nTrying to create it...<\b>" );
if( !QDir().mkpath( fi.absoluteFilePath() ) )
{
ShowMessage( "<b>Failed to make the directory!<\b>" );
return;
}
ShowMessage( "<b>" + fi.absoluteFilePath() + " is not a folder!\nTrying to create it...<\b>" );
if( !QDir().mkpath( fi.absoluteFilePath() ) )
{
ShowMessage( "<b>Failed to make the directory!<\b>" );
return;
}
}
QString newFName = title;
int i = 1;
while( QFileInfo( fi.absoluteFilePath() + "/" + newFName ).exists() )//find a folder that doesnt exist and try to create it
{
newFName = QString( "%1 (copy%2)" ).arg( title ).arg( i++ );
newFName = QString( "%1 (copy%2)" ).arg( title ).arg( i++ );
}
if( !QDir().mkpath( fi.absoluteFilePath() + "/" + newFName ) )
{
ShowMessage( "<b>Can't create" + fi.absoluteFilePath() + "/" + newFName + " to save this title into!<\b>" );
return;
ShowMessage( "<b>Can't create" + fi.absoluteFilePath() + "/" + newFName + " to save this title into!<\b>" );
return;
}
//start writing all this stuff to the HDD
QDir d( fi.absoluteFilePath() + "/" + newFName );
QByteArray tmdDat = job.data.takeFirst(); //remember the tmd and use it for getting the names of the .app files
if( !WriteFile( d.absoluteFilePath( "title.tmd" ), tmdDat ) )
{
ShowMessage( "<b>Error writing " + d.absoluteFilePath( "title.tmd" ) + "!<\b>" );
return;
ShowMessage( "<b>Error writing " + d.absoluteFilePath( "title.tmd" ) + "!<\b>" );
return;
}
if( !WriteFile( d.absoluteFilePath( "cetk" ), job.data.takeFirst() ) )
{
ShowMessage( "<b>Error writing " + d.absoluteFilePath( "cetk" ) + "!<\b>" );
return;
ShowMessage( "<b>Error writing " + d.absoluteFilePath( "cetk" ) + "!<\b>" );
return;
}
Tmd t( tmdDat );
quint16 cnt = t.Count();
if( job.data.size() != cnt )
{
ShowMessage( "<b>Error! Number of contents in the TMD dont match the number received from NUS!<\b>" );
return;
ShowMessage( "<b>Error! Number of contents in the TMD dont match the number received from NUS!<\b>" );
return;
}
for( quint16 i = 0; i < cnt; i++ )//write all the contents in the new folder. if the job is decrypted, append ".app" to the end of their names
{
QString appName = t.Cid( i );
if( job.decrypt )
appName += ".app";
if( !WriteFile( d.absoluteFilePath( appName ), job.data.takeFirst() ) )
{
ShowMessage( "<b>Error writing " + d.absoluteFilePath( appName ) + "!<\b>" );
return;
}
QString appName = t.Cid( i );
if( job.decrypt )
appName += ".app";
if( !WriteFile( d.absoluteFilePath( appName ), job.data.takeFirst() ) )
{
ShowMessage( "<b>Error writing " + d.absoluteFilePath( appName ) + "!<\b>" );
return;
}
}
ShowMessage( tr( "Wrote title to %1" ).arg( fi.absoluteFilePath() + "/" + newFName ) );
}
@ -421,46 +423,46 @@ void MainWindow::SaveJobToWad( NusJob job )
Wad wad( job.data );
if( !wad.IsOk() )
{
ShowMessage( "<b>Error making a wad from " + title + "<\b>" );
return;
ShowMessage( "<b>Error making a wad from " + title + "<\b>" );
return;
}
QFileInfo fi( ui->lineEdit_wad->text() );
if( fi.isFile() )
{
ShowMessage( "<b>" + ui->lineEdit_wad->text() + " is a file. I need a folder<\b>" );
return;
ShowMessage( "<b>" + ui->lineEdit_wad->text() + " is a file. I need a folder<\b>" );
return;
}
if( !fi.exists() )
{
ShowMessage( "<b>" + fi.absoluteFilePath() + " is not a folder!\nTrying to create it...<\b>" );
if( !QDir().mkpath( ui->lineEdit_wad->text() ) )
{
ShowMessage( "<b>Failed to make the directory!<\b>" );
return;
}
ShowMessage( "<b>" + fi.absoluteFilePath() + " is not a folder!\nTrying to create it...<\b>" );
if( !QDir().mkpath( ui->lineEdit_wad->text() ) )
{
ShowMessage( "<b>Failed to make the directory!<\b>" );
return;
}
}
QByteArray w = wad.Data();
if( w.isEmpty() )
{
ShowMessage( "<b>Error creating wad<br>" + wad.LastError() + "<\b>" );
return;
ShowMessage( "<b>Error creating wad<br>" + wad.LastError() + "<\b>" );
return;
}
QString name = wad.WadName( fi.absoluteFilePath() );
if( name.isEmpty() )
{
name = QFileDialog::getSaveFileName( this, tr( "Filename for %1" ).arg( title ), fi.absoluteFilePath() );
if( name.isEmpty() )
{
ShowMessage( "<b>No save name given, aborting<\b>" );
return;
}
name = QFileDialog::getSaveFileName( this, tr( "Filename for %1" ).arg( title ), fi.absoluteFilePath() );
if( name.isEmpty() )
{
ShowMessage( "<b>No save name given, aborting<\b>" );
return;
}
}
QFile file( fi.absoluteFilePath() + "/" + name );
if( !file.open( QIODevice::WriteOnly ) )
{
ShowMessage( "<b>Cant open " + fi.absoluteFilePath() + "/" + name + " for writing<\b>" );
return;
ShowMessage( "<b>Cant open " + fi.absoluteFilePath() + "/" + name + " for writing<\b>" );
return;
}
file.write( w );
file.close();
@ -473,7 +475,7 @@ void MainWindow::on_pushButton_CachePathBrowse_clicked()
{
QString f = QFileDialog::getExistingDirectory( this, tr( "Select NUS Cache base folder" ) );
if( f.isEmpty() )
return;
return;
ui->lineEdit_cachePath->setText( f );
nus.SetCachePath( ui->lineEdit_cachePath->text() );

View File

@ -1,30 +1,53 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "tools.h"
#include "savebanner.h"
#include "ngdialog.h"
#include "textdialog.h"
#include "../WiiQt/tools.h"
#include "../WiiQt/savebanner.h"
#include "../WiiQt/savedatabin.h"
#include "quazip.h"
#include "quazipfile.h"
//TODO... get these from settings and dont use global variables
static QString pcPath = "./saveBackups";
static QString sneekPath = "/media/SDHC_4GB";
//static QString sneekPath = "/media/SDHC_4GB";
static QString sneekPath = "/home/j/c/QtWii/test";
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), bannerthread( this )
{
ui->setupUi(this);
progressBar.setVisible( false );
ui->statusBar->addPermanentWidget( &progressBar, 0 );
ngID = 0;
ngKeyID = 0;
//sneekIconTimer.setInterval( 150 );//delay of icon image animation
connect( &bannerthread, SIGNAL( SendProgress( int ) ), this, SLOT( GetProgressUpdate( int ) ) );
connect( &bannerthread, SIGNAL( SendDone( int ) ), this, SLOT( LoadThreadIsDone( int ) ) );
connect( &bannerthread, SIGNAL( SendItem( QByteArray, const QString&, int, int ) ), this, SLOT( ReceiveSaveItem( QByteArray, const QString&, int, int ) ) );
connect( &sneekIconTimer, SIGNAL(timeout() ), this, SLOT( ShowNextSneekIcon() ) );
connect( &bannerthread, SIGNAL( SendDone( int ) ), this, SLOT( LoadThreadIsDone( int ) ) );
connect( &bannerthread, SIGNAL( SendSneekItem( QByteArray, const QString&, int ) ), this, SLOT( ReceiveSneekBanner( QByteArray, const QString&, int ) ) );
connect( &bannerthread, SIGNAL( SendPcItem( PcSaveInfo ) ), this, SLOT( ReceivePcItem( PcSaveInfo ) ) );
connect( &sneekIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextSneekIcon() ) );
connect( &pcIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextPcIcon() ) );
pcPath = "./saveBackups";
//GetSavesFromSneek( "/media/WiiFat500" );
GetSavesFromSneek( sneekPath );
GetSavesFromSneek( sneekPath );
GetSavesFromPC( pcPath );
ngID = 0x4324c84;
ngKeyID = 0x6aedb6ed;
ngMac = QByteArray::fromHex( "0017abd2f253" );
ngPriv = QByteArray::fromHex( "00633682060dc10f5e8ec41907745f6380b67f8ad11019caf21a3ea242d2" );
ngSig = QByteArray::fromHex( "0015097c4e17ad791aa971221e07a0a2d9c97c6e2885fc7bf624e564c34100dd18568f683aa6f4f5a984842ddb002ef87724594975d0d43a0ecff81d" );
//QMessageBox::aboutQt( this, "bla" );
//QString bla = GetSaveName( 0x1000112345678ull );
//qDebug() << "bla" << bla;
}
MainWindow::~MainWindow()
@ -35,12 +58,56 @@ MainWindow::~MainWindow()
//get the saves from a nand directory
void MainWindow::GetSavesFromSneek( const QString &path )
{
if( !QFileInfo( path ).exists() )
return;
if( bannerthread.isRunning() )
{
ui->statusBar->showMessage( tr( "Wait for the current job to finish" ) );
return;
}
sneekPath = path;
ui->listWidget_sneekSaves->clear();
progressBar.setValue( 0 );
progressBar.setVisible( true );
bannerthread.GetBanners( path, LOAD_SNEEK );
if( !bannerthread.SetNandPath( path ) )
{
qWarning() << "MainWindow::GetSavesFromSneek -> error sotteng path" << path;
return;
}
bannerthread.GetBanners();
}
void MainWindow::GetSavesFromPC( const QString &path )
{
pcPath = path;
if( !QFileInfo( path ).exists() )
return;
if( bannerthread.isRunning() )
{
ui->statusBar->showMessage( tr( "Wait for the current job to finish" ) );
return;
}
//remove all currently loaded saves
ui->listWidget_pcSaves->clear();
pcInfos.clear();
progressBar.setValue( 0 );
progressBar.setVisible( true );
bannerthread.GetBanners( pcPath );
}
void MainWindow::ReceivePcItem( PcSaveInfo info )
{
//qDebug() << "received a pc save";
if( !info.sizes.size() || info.sizes.size() != info.descriptions.size() || info.sizes.size() != info.paths.size() )//invalid
return;
SaveBanner sb( info.banner );
new SaveListItem( sb, info.tid, 0, ui->listWidget_pcSaves );
//ui->listWidget_sneekSaves->addItem( item );
//descMap.insert( tid, descriptions );
pcInfos << info;
}
/*
//sneek save clicked
void MainWindow::on_listWidget_sneekSaves_itemClicked(QListWidgetItem* item)
@ -66,7 +133,7 @@ void MainWindow::on_listWidget_sneekSaves_currentItemChanged(QListWidgetItem* cu
{
Q_UNUSED( previous );
if( !current )
return;
return;
SaveListItem *i = static_cast< SaveListItem * >( current );
@ -74,23 +141,12 @@ void MainWindow::on_listWidget_sneekSaves_currentItemChanged(QListWidgetItem* cu
}
//get an item from the thread loading all the data and turn it into a banner
void MainWindow::ReceiveSaveItem( QByteArray stuff, const QString& tid, int type, int size )
void MainWindow::ReceiveSneekBanner( QByteArray stuff, const QString& tid, int size )
{
switch( type )
{
case LOAD_SNEEK:
{
QByteArray copy = stuff;
SaveBanner sb( copy );
SaveListItem *item = new SaveListItem( sb, tid, size, ui->listWidget_sneekSaves );
ui->listWidget_sneekSaves->addItem( item );
}
break;
default:
break;
}
QByteArray copy = stuff;
SaveBanner sb( copy );
new SaveListItem( sb, tid, size, ui->listWidget_sneekSaves );
//ui->listWidget_sneekSaves->addItem( item );
}
//get a pregress update from something that is doing work
@ -111,7 +167,7 @@ void MainWindow::on_actionSet_Sneek_Path_triggered()
{
QString p = QFileDialog::getExistingDirectory( this, tr( "Select SNEEK root" ), "/media" );
if( p.isEmpty() )
return;
return;
ui->listWidget_sneekSaves->clear();
GetSavesFromSneek( p );
@ -129,9 +185,9 @@ void MainWindow::ShowSneekSaveDetails( SaveListItem *item )
ui->label_sneek_title->setText( sb->Title() );
if( !sb->SubTitle().isEmpty() && sb->Title() != sb->SubTitle() )
ui->label_sneek_title2->setText( sb->SubTitle() );
ui->label_sneek_title2->setText( sb->SubTitle() );
else
ui->label_sneek_title2->clear();
ui->label_sneek_title2->clear();
QString tid = item->Tid();
tid.insert( 8, "/" );
@ -142,22 +198,22 @@ void MainWindow::ShowSneekSaveDetails( SaveListItem *item )
tid = item->Tid().right( 8 );
quint32 num = qFromBigEndian( (quint32) tid.toInt( NULL, 16 ) );
for( int i = 0; i < 4; i++ )
id += ascii( (char)( num >> ( 8 * i ) ) & 0xff );
id += ascii( (char)( num >> ( 8 * i ) ) & 0xff );
ui->label_sneek_id->setText( id );
int size = item->Size();
QString sizeStr;
if( size < 0x400 )
sizeStr = tr( "%1 B" ).arg( size, 3 );
sizeStr = tr( "%1 B" ).arg( size, 3 );
else if( size < 0x100000 )
{
float kib = (float)size / 1024.00f;
sizeStr = tr( "%1 KiB" ).arg( kib, 3, 'f', 2 );
float kib = (float)size / 1024.00f;
sizeStr = tr( "%1 KiB" ).arg( kib, 3, 'f', 2 );
}
else//assume there wont be any 1GB saves
{
float mib = (float)size / 1048576.00f;
sizeStr = tr( "%1 MiB" ).arg( mib, 3, 'f', 2 );
float mib = (float)size / 1048576.00f;
sizeStr = tr( "%1 MiB" ).arg( mib, 3, 'f', 2 );
}
int blocks = RU( 0x20000, size) / 0x20000;
QString si = QString( "%1 %2 (%3)").arg( blocks ).arg( blocks == 1 ? tr( "Block" ) : tr( "Blocks" ) ).arg( sizeStr );
@ -165,21 +221,456 @@ void MainWindow::ShowSneekSaveDetails( SaveListItem *item )
ui->label_sneek_size->setText( si );
foreach( QImage im, sb->IconImgs() )
sneekIcon << QPixmap::fromImage( im );
sneekIcon << QPixmap::fromImage( im );
currentSneekIcon = 0;
ui->label_sneek_icon->setPixmap( sneekIcon.at( 0 ) );
if( sneekIcon.size() > 1 )
{
sneekIconTimer.setInterval( 1000 / sneekIcon.size() );//delay of icon image animation
sneekIconTimer.start();
sneekIconTimer.setInterval( 1000 / sneekIcon.size() );//delay of icon image animation
sneekIconTimer.start();
}
}
void MainWindow::ShowNextSneekIcon()
{
if( ++currentSneekIcon >= sneekIcon.size() )
currentSneekIcon = 0;
if( ++currentSneekIcon >= sneekIcon.size() )
currentSneekIcon = 0;
ui->label_sneek_icon->setPixmap( sneekIcon.at( currentSneekIcon ) );
ui->label_sneek_icon->setPixmap( sneekIcon.at( currentSneekIcon ) );
}
void MainWindow::ShowNextPcIcon()
{
if( ++currentPcIcon >= pcIcon.size() )
currentPcIcon = 0;
ui->label_PC_icon->setPixmap( pcIcon.at( currentPcIcon ) );
}
//clicked button to delete save from sneek
void MainWindow::on_pushButton_sneekDelete_clicked()
{
QList<QListWidgetItem*>selected = ui->listWidget_sneekSaves->selectedItems();
quint16 cnt = selected.size();
if( !cnt )
return;
if( QMessageBox::question( this, tr( "Are you sure?" ), \
tr( "You are about to delete %1 %2 from the SNEEK nand" ).arg( cnt )\
.arg( cnt == 1 ? tr( "save" ) : tr( "saves" ) ),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) != QMessageBox::Ok )
return;
quint16 del = 0;
for( quint16 i = 0; i < cnt; i++ )
{
QListWidgetItem* item = selected.takeFirst();
SaveListItem *si = static_cast< SaveListItem * >( item );
if( !si )
{
qDebug() << "MainWindow::on_pushButton_sneekDelete_clicked() -> error casting" << item->text();
delete item;
continue;
}
bool ok = false;
quint64 tid = si->Tid().toLongLong( &ok, 16 );
if( !ok )
{
qDebug() << "MainWindow::on_pushButton_sneekDelete_clicked() -> error converting" << si->Tid() << "to int";
delete item;
continue;
}
delete item;
if( !bannerthread.DeleteSaveFromSneekNand( tid ) )
qDebug() << "MainWindow::on_pushButton_sneekDelete_clicked() -> error deleting" << tid;
else
del++;
}
ui->statusBar->showMessage( tr( "Deleted %1 of %2 saves" ).arg( del ).arg( cnt ), 5000 );
}
QString MainWindow::GetSaveName( quint64 tid )
{
if( pcPath.isEmpty() )
return QString();
QString tidStr = QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
tidStr.insert( 8, "/" );
QString parent = pcPath + "/" + tidStr;
QFileInfo fi( parent );
if( fi.exists() && fi.isFile() )
{
qWarning() << "MainWindow::GetSaveName ->" << fi.absoluteFilePath() << "is a file";
return QString();
}
if( !fi.exists() && !QDir().mkpath( fi.absoluteFilePath() ) )
{
qWarning() << "MainWindow::GetSaveName -> error creating" << fi.absoluteFilePath();
return QString();
}
quint32 i = 1;
QString name = QString( "1.zip" );
QDir dir( fi.absoluteFilePath() );
while( dir.exists( name ) )
{
name = QString( "%1.zip" ).arg( ++i );
}
return fi.absoluteFilePath() + "/" + name;
}
//quick sanity checks on the NG stuff
bool MainWindow::NG_Ok()
{
return ( ngID && ngKeyID && ngSig.size() == 60 && ngMac.size() == 6 && ngPriv.size() == 30 );
}
//button to extract a save from sneek clicked
void MainWindow::on_pushButton_sneekExtract_clicked()
{
QList<QListWidgetItem*>selected = ui->listWidget_sneekSaves->selectedItems();
quint16 cnt = selected.size();
if( !cnt )
{
ui->statusBar->showMessage( tr( "No saves are selected to extract" ) );
return;
}
if( !NG_Ok() )
{
on_actionSet_NG_Keys_triggered();
if( !NG_Ok() )
{
qDebug() << "invalid keys. can't create data.bins";
ui->statusBar->showMessage( tr( "I Need valid keys to extract saves" ) );
return;
}
}
bool promptForDetails = true;
//keep from prompting for details for multiple saves
if( cnt > 1 && QMessageBox::question( this, tr( "Enter Details?" ), \
tr( "You are about to extract %1 saves from the SNEEK nand.<br>Do you want to enter details for each of them?" )
.arg( cnt ), QMessageBox::No | QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
promptForDetails = false;
quint16 done = 0;
for( quint16 i = 0; i < cnt; i++ )
{
QListWidgetItem* item = selected.at( i );
SaveListItem *si = static_cast< SaveListItem * >( item );
if( !si )
{
qDebug() << "MainWindow::on_pushButton_sneekExtract_clicked() -> error casting" << item->text();
delete item;
continue;
}
bool ok = false;
quint64 tid = si->Tid().toLongLong( &ok, 16 );
if( !ok )
{
qDebug() << "MainWindow::on_pushButton_sneekExtract_clicked() -> error converting" << si->Tid() << "to int";
continue;
}
//get a save destination
QString fn = GetSaveName( tid );
if( fn.isEmpty() )
continue;
//extract the save
SaveGame sg = bannerthread.GetSave( tid );
if( !IsValidSave( sg ) )
{
ui->statusBar->showMessage( tr( "Error extracting save for %1").arg( tid, 16, 16, QChar( '0' ) ) );
qDebug() << "MainWindow::on_pushButton_sneekExtract_clicked() -> invalid save" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
continue;
}
//convert to data.bin
QByteArray ba = SaveDataBin::DataBinFromSaveStruct( sg, ngPriv, ngSig, ngMac, ngID, ngKeyID );
if( ba.isEmpty() )
{
ui->statusBar->showMessage( tr( "Error encoding save for %1").arg( tid, 16, 16, QChar( '0' ) ) );
qDebug() << "MainWindow::on_pushButton_sneekExtract_clicked() -> error converting" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
continue;
}
QString fullDesc = QString( "SaveInfo\nversion=%1\ntid=%2\n" ).arg( DESC_VERSION ).arg( tid, 16, 16, QChar( '0' ) );
QDate date = QDate::currentDate();
QTime time = QTime::currentTime();
QString desc = QString( "title=%1\ndate=%2\ntime=%3\n" ).arg( si->Banner()->Title() ).arg( date.toString() ).arg( time.toString() );
if( promptForDetails )
{
fullDesc += "desc=\n" + TextDialog::GetText( this, desc ) + "\nend_desc\n";
}
else
{
fullDesc += "desc=\n" + desc + "\nend_desc\n";
}
//qDebug() << "description:\n" << fullDesc;
//write to file
if( !WriteZipFile( ba, fullDesc.toLatin1(), fn ) )
{
ui->statusBar->showMessage( tr( "Error writing save for %1").arg( tid, 16, 16, QChar( '0' ) ) );
qDebug() << "MainWindow::on_pushButton_sneekExtract_clicked() -> error writing" << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
continue;
}
//item extracted ok, now add the info to the tab displaying the PC
SaveBanner banner = *si->Banner();
AddNewPCSave( fullDesc, si->Tid(), si->Size(), fn, banner );
done++;
}
ui->statusBar->showMessage( tr( "Extracted %1 of %2 saves" ).arg( done ).arg( cnt ), 5000 );
}
void MainWindow::AddNewPCSave( const QString &desc, const QString &tid, quint32 size, const QString &path, SaveBanner banner )
{
//look to see if there is already some pc saves from the same game
quint32 cnt = pcInfos.size();
for( quint32 i = 0; i < cnt; i++ )
{
if( tid == pcInfos.at( i ).tid )
{
PcSaveInfo info = pcInfos.at( i );
info.sizes << size;
info.descriptions << desc;
info.paths << path;
pcInfos.replace( i, info );
return;
}
}
//not found, create a new one
PcSaveInfo info;
info.tid = tid;
info.sizes << size;
info.descriptions << desc;
info.paths << path;
pcInfos << info;
new SaveListItem( banner, tid, 0, ui->listWidget_pcSaves );
}
//try to write a zip file with a data.bin and a descriptive text file
bool MainWindow::WriteZipFile( const QByteArray &dataBin, const QByteArray &desc, const QString &path )
{
qDebug() << "MainWindow::WriteZipFile" << path;
QuaZip zip( path );
if( !zip.open(QuaZip::mdCreate ) )
{
qWarning( "error creating zip file: %d", zip.getZipError() );
return false;
}
zip.setComment( "Created with giantpune's saveToy" );
QuaZipFile outFile( &zip );
for( quint8 i = 0; i < 2; i++ )
{
QString fn;
QByteArray stuff;
if( i == 0 )
{
stuff = dataBin;
fn = "data.bin";
}
else
{
stuff = desc;
fn = "info.txt";
}
if( !outFile.open( QIODevice::WriteOnly, QuaZipNewInfo( fn, fn ) ) )
{
qWarning("MainWindow::WriteZipFile: outFile.open(): %d", outFile.getZipError() );
goto error;
}
if( outFile.write( stuff ) != stuff.size() )
{
qWarning() << "MainWindow::WriteZipFile: wrong size written to zip file";
goto error;
}
outFile.close();
if( outFile.getZipError() !=UNZ_OK )
{
qWarning("MainWindow::WriteZipFile: outFile.close(): %d", outFile.getZipError() );
goto error;
}
}
zip.close();
if( zip.getZipError() != 0 )
{
qWarning("MainWindow::WriteZipFile: zip.close(): %d", zip.getZipError());
goto error;
}
return true;
error:
zip.close();
if( QFile::exists( path ) )
QFile::remove( path );
return false;
}
//tools -> set ng keys
void MainWindow::on_actionSet_NG_Keys_triggered()
{
qDebug() << hex << ngID;
NgDialog d( this );
d.ngID = ngID;
d.ngKeyID = ngKeyID;
d.ngMac = ngMac;
d.ngPriv = ngPriv;
d.ngSig = ngSig;
if( !d.exec() )
{
//qDebug() << "not accepted";
return;
}
ngID = d.ngID;
ngKeyID = d.ngKeyID;
ngMac = d.ngMac;
ngPriv = d.ngPriv;
ngSig = d.ngSig;
/*qDebug() << "accepted";
qDebug() << hex << d.ngID
<< "\n" << d.ngKeyID
<< "\n" << d.ngMac.toHex()
<< "\n" << d.ngPriv.toHex()
<< "\n" << d.ngSig.toHex();*/
}
//PC list item changed
void MainWindow::on_listWidget_pcSaves_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
{
Q_UNUSED( previous );
if( !current )
return;
SaveListItem *i = static_cast< SaveListItem * >( current );
ShowPCSaveDetails( i );
}
//show detials for a save backed up on the PC
void MainWindow::ShowPCSaveDetails( SaveListItem *item )
{
qDebug() << "MainWindow::ShowPCSaveDetails";
pcIconTimer.stop();
currentPcIcon = 0;
pcIcon.clear();
ui->comboBox_pcSelect->clear();
//find the item in the list of infos that matches this item
currentPcSave = 0xffffffff;
quint32 cnt = pcInfos.size();
for( quint32 i = 0; i < cnt; i++ )
{
if( item->Tid() == pcInfos.at( i ).tid )
{
currentPcSave = i;
break;
}
}
if( currentPcSave == 0xffffffff )
{
qWarning() << "MainWindow::ShowPCSaveDetails -> tid not found";
return;
}
SaveBanner *sb = item->Banner();
ui->label_pc_title->setText( sb->Title() );
if( !sb->SubTitle().isEmpty() && sb->Title() != sb->SubTitle() )
ui->label_pc_title2->setText( sb->SubTitle() );
else
ui->label_pc_title2->clear();
QString tid = item->Tid();
tid.insert( 8, "/" );
tid.prepend( "/" );
//ui->label_sneek_path->setText( tid );
QString id;
tid = item->Tid().right( 8 );
quint32 num = qFromBigEndian( (quint32) tid.toInt( NULL, 16 ) );
for( int i = 0; i < 4; i++ )
id += ascii( (char)( num >> ( 8 * i ) ) & 0xff );
ui->label_pc_id->setText( id );
foreach( QImage im, sb->IconImgs() )
pcIcon << QPixmap::fromImage( im );
currentPcIcon = 0;
ui->label_PC_icon->setPixmap( pcIcon.at( 0 ) );
if( pcIcon.size() > 1 )
{
pcIconTimer.setInterval( 1000 / pcIcon.size() );//delay of icon image animation
pcIconTimer.start();
}
//add combobox entries for each of the different saves for this game
cnt = pcInfos.at( currentPcSave ).sizes.size();
for( quint32 i = 0; i < cnt; i++ )
{
QString version = pcInfos.at( currentPcSave ).paths.at( i );
version.remove( 0, version.lastIndexOf( "/" ) + 1 );
ui->comboBox_pcSelect->addItem( version );
}
}
//pc combobox index changed
void MainWindow::on_comboBox_pcSelect_currentIndexChanged( int index )
{
qDebug() << "MainWindow::on_comboBox_pcSelect_currentIndexChanged" << index;
if( index < 0 )
return;
ui->plainTextEdit_pcDesc->clear();
if( currentPcSave >= (quint32)pcInfos.size() || index >= pcInfos.at( currentPcSave ).sizes.size() )
{
qWarning() << "MainWindow::on_comboBox_pc_date_currentIndexChanged -> index is out of range";
return;
}
int size = pcInfos.at( currentPcSave ).sizes.at( index );
QString sizeStr;
if( size < 0x400 )
sizeStr = tr( "%1 B" ).arg( size, 3 );
else if( size < 0x100000 )
{
float kib = (float)size / 1024.00f;
sizeStr = tr( "%1 KiB" ).arg( kib, 3, 'f', 2 );
}
else//assume there wont be any 1GB saves
{
float mib = (float)size / 1048576.00f;
sizeStr = tr( "%1 MiB" ).arg( mib, 3, 'f', 2 );
}
int blocks = RU( 0x20000, size) / 0x20000;
QString si = QString( "%1 %2 (%3)").arg( blocks ).arg( blocks == 1 ? tr( "Block" ) : tr( "Blocks" ) ).arg( sizeStr );
ui->label_pc_size->setText( si );
QString path = pcInfos.at( currentPcSave ).paths.at( index );
if( path.size() >= 30 )
{
path = path.right( 27 );
path.prepend( "..." );
}
ui->label_pc_path->setText( path );
ui->plainTextEdit_pcDesc->clear();
ui->plainTextEdit_pcDesc->insertPlainText( pcInfos.at( currentPcSave ).descriptions.at( index ) );
}

View File

@ -3,8 +3,8 @@
#include "saveloadthread.h"
#include "savelistitem.h"
#include "savebanner.h"
#include "includes.h"
#include "../WiiQt/savebanner.h"
#include "../WiiQt/includes.h"
namespace Ui {
class MainWindow;
@ -22,27 +22,59 @@ private:
Ui::MainWindow *ui;
QProgressBar progressBar;
void GetSavesFromSneek( const QString &path );
void GetSavesFromPC( const QString &path );
SaveLoadThread bannerthread;
//void ShowSneekSaveDetails( SaveListItem *item );
int currentSneekIcon;
QTimer sneekIconTimer;
QList<QPixmap>sneekIcon;
int currentSneekIcon;
QTimer sneekIconTimer;
QList<QPixmap>sneekIcon;
int currentPcIcon;
QTimer pcIconTimer;
QList<QPixmap>pcIcon;
quint32 currentPcSave;
//basepath used for local save backups
QString pcPath;
//get available filename for backup save inside pcPath
QString GetSaveName( quint64 tid );
//variables used for creating the data.bins on extraction
quint32 ngID;
quint32 ngKeyID;
QByteArray ngSig;
QByteArray ngMac;
QByteArray ngPriv;
//for remembering PC saves' TID and the descriptions of each save
QList< PcSaveInfo > pcInfos;
bool NG_Ok();
bool WriteZipFile( const QByteArray &dataBin, const QByteArray &desc, const QString &path );
void AddNewPCSave( const QString &desc, const QString &tid, quint32 size, const QString &path, SaveBanner banner );
private slots:
void on_comboBox_pcSelect_currentIndexChanged(int index);
void on_listWidget_pcSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);
void on_actionSet_NG_Keys_triggered();
void on_pushButton_sneekExtract_clicked();
void on_pushButton_sneekDelete_clicked();
void on_actionSet_Sneek_Path_triggered();
void on_listWidget_sneekSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);
//void on_listWidget_sneekSaves_itemClicked(QListWidgetItem* item);
//void on_listWidget_sneekSaves_itemActivated( QListWidgetItem* item );
void on_listWidget_sneekSaves_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
void ReceiveSaveItem( QByteArray, const QString&, int, int );
void ReceiveSneekBanner( QByteArray, const QString&, int );
void ReceivePcItem( PcSaveInfo );
void GetProgressUpdate( int );
void LoadThreadIsDone( int );
void ShowSneekSaveDetails( SaveListItem *item );
void ShowNextSneekIcon();
void ShowSneekSaveDetails( SaveListItem *item );
void ShowPCSaveDetails( SaveListItem *item );
void ShowNextSneekIcon();
void ShowNextPcIcon();
};

View File

@ -175,13 +175,13 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<widget class="QWidget" name="PCtab">
<attribute name="title">
<string>Tab 2</string>
<string>PC Backups</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QListWidget" name="listWidget_sneekSaves_2">
<widget class="QListWidget" name="listWidget_pcSaves">
<property name="minimumSize">
<size>
<width>620</width>
@ -297,10 +297,14 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_pc_date"/>
<widget class="QComboBox" name="comboBox_pcSelect"/>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit"/>
<widget class="QPlainTextEdit" name="plainTextEdit_pcDesc">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3">
@ -313,6 +317,9 @@
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_pc_saveDesc">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save Desc.</string>
</property>
@ -349,6 +356,8 @@
<string>Tools</string>
</property>
<addaction name="actionSet_Sneek_Path"/>
<addaction name="actionSet_Local_Path"/>
<addaction name="actionSet_NG_Keys"/>
</widget>
<addaction name="menuTools"/>
</widget>
@ -369,6 +378,22 @@
<string>Ctrl+L</string>
</property>
</action>
<action name="actionSet_Local_Path">
<property name="text">
<string>Set Local Path...</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionSet_NG_Keys">
<property name="text">
<string>Set NG Keys...</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

200
saveToy/ngdialog.cpp Normal file
View File

@ -0,0 +1,200 @@
#include "ngdialog.h"
#include "ui_ngdialog.h"
#include "../WiiQt/keysbin.h"
#include "../WiiQt/savedatabin.h"
NgDialog::NgDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NgDialog)
{
ui->setupUi(this);
hex.setPattern( "^[A-Fa-f0-9]+$" );
ngID = 0;
ngKeyID = 0;
QFontMetrics fm( fontMetrics() );
int max = fm.width( ui->label_ngid->text() );
max = MAX( max, fm.width( ui->label_ngKeyId->text() ) );
max = MAX( max, fm.width( ui->label_ngMac->text() ) );
max = MAX( max, fm.width( ui->label_ngPriv->text() ) );
max = MAX( max, fm.width( ui->label_ngSig->text() ) );
max += 5;
ui->label_ngid->setMinimumWidth( max );
ui->label_ngKeyId->setMinimumWidth( max );
ui->label_ngMac->setMinimumWidth( max );
ui->label_ngPriv->setMinimumWidth( max );
ui->label_ngSig->setMinimumWidth( max );
}
NgDialog::~NgDialog()
{
delete ui;
}
int NgDialog::exec()
{
ui->lineEdit_ngID->setText( QString( "%1" ).arg( ngID, 8, 16, QChar( '0' ) ) );
ui->lineEdit_ngKeyId->setText( QString( "%1" ).arg( ngKeyID, 8, 16, QChar( '0' ) ) );
ui->lineEdit_ngSig->setText( ngSig.toHex() );
ui->lineEdit_ngMac->setText( ngMac.toHex() );
ui->lineEdit_ngPriv->setText( ngPriv.toHex() );
return QDialog::exec();
}
bool NgDialog::ValidNGID()
{
bool ok = false;
ngID = ui->lineEdit_ngID->text().toInt( &ok, 16 );
return ok;
}
bool NgDialog::ValidNGKeyID()
{
bool ok = false;
ngKeyID = ui->lineEdit_ngKeyId->text().toInt( &ok, 16 );
return ok;
}
bool NgDialog::ValidNGSig()
{
if( ui->lineEdit_ngSig->text().size() != 120 )
return false;
return hex.exactMatch( ui->lineEdit_ngSig->text() );
}
bool NgDialog::ValidNGMac()
{
if( ui->lineEdit_ngMac->text().size() != 12 )
return false;
return hex.exactMatch( ui->lineEdit_ngMac->text() );
}
bool NgDialog::ValidNGPriv()
{
if( ui->lineEdit_ngPriv->text().size() != 60 )
return false;
return hex.exactMatch( ui->lineEdit_ngPriv->text() );
}
void NgDialog::on_lineEdit_ngID_textChanged( QString str )
{
if( str.contains( " " ) )//remove spaces ( useful for copy/pasting out of a hexeditor )
{
str.remove( " " );
ui->lineEdit_ngID->setText( str );
return;
}
QString color = ValidNGID() ? "green" : "red";
ui->lineEdit_ngID->setStyleSheet( "QLineEdit { background-color: " + color + "; }" );
}
void NgDialog::on_lineEdit_ngSig_textChanged( QString str )
{
if( str.contains( " " ) )//remove spaces ( useful for copy/pasting out of a hexeditor )
{
str.remove( " " );
ui->lineEdit_ngSig->setText( str );
return;
}
QString color = ValidNGSig() ? "green" : "red";
ui->lineEdit_ngSig->setStyleSheet( "QLineEdit { background-color: " + color + "; }" );
}
void NgDialog::on_lineEdit_ngKeyId_textChanged( QString str )
{
if( str.contains( " " ) )//remove spaces ( useful for copy/pasting out of a hexeditor )
{
str.remove( " " );
ui->lineEdit_ngKeyId->setText( str );
return;
}
QString color = ValidNGKeyID() ? "green" : "red";
ui->lineEdit_ngKeyId->setStyleSheet( "QLineEdit { background-color: " + color + "; }" );
}
void NgDialog::on_lineEdit_ngMac_textChanged( QString str )
{
if( str.contains( " " ) )//remove spaces ( useful for copy/pasting out of a hexeditor )
{
str.remove( " " );
ui->lineEdit_ngMac->setText( str );
return;
}
QString color = ValidNGMac() ? "green" : "red";
ui->lineEdit_ngMac->setStyleSheet( "QLineEdit { background-color: " + color + "; }" );
}
void NgDialog::on_lineEdit_ngPriv_textChanged( QString str )
{
if( str.contains( " " ) )//remove spaces ( useful for copy/pasting out of a hexeditor )
{
str.remove( " " );
ui->lineEdit_ngPriv->setText( str );
return;
}
QString color = ValidNGPriv() ? "green" : "red";
ui->lineEdit_ngPriv->setStyleSheet( "QLineEdit { background-color: " + color + "; }" );
}
//open keys.bin to get stuff from it
void NgDialog::on_pushButton_keys_clicked()
{
QString fn = QFileDialog::getOpenFileName( this, tr( "Select keys.bin" ) );
if( fn.isEmpty() )
return;
QByteArray ba = ReadFile( fn );
if( ba.size() != 0x400 )
{
ui->label_message->setText( tr( "keys.bin should be 0x400 bytes" ) );
return;
}
KeysBin keys( ba );
ui->lineEdit_ngID->setText( keys.NG_ID().toHex() );
ui->lineEdit_ngKeyId->setText( keys.NG_key_ID().toHex() );
ui->lineEdit_ngPriv->setText( keys.NG_Priv().toHex() );
ui->lineEdit_ngSig->setText( keys.NG_Sig().toHex() );
}
//read a data.bin and get some keys from it
void NgDialog::on_pushButton_existingSave_clicked()
{
QString fn = QFileDialog::getOpenFileName( this, tr( "Select data.bin" ) );
if( fn.isEmpty() )
return;
QByteArray ba = ReadFile( fn );
SaveDataBin sb( ba );
if( !sb.IsOk() )
{
ui->label_message->setText( tr( "error reading the data.bin" ) );
return;
}
ui->lineEdit_ngID->setText( QString( "%1" ).arg( sb.NgID(), 8, 16, QChar( '0' ) ) );
ui->lineEdit_ngKeyId->setText( QString( "%1" ).arg( sb.NgKeyID(), 8, 16, QChar( '0' ) ) );
ui->lineEdit_ngSig->setText( sb.NgSig().toHex() );
ui->lineEdit_ngMac->setText( sb.NgMac().toHex() );
}
void NgDialog::on_pushButton_ok_clicked()
{
if( !ValidNGID() || !ValidNGKeyID() || !ValidNGSig() || !ValidNGMac() || !ValidNGPriv() )
{
ui->label_message->setText( tr( "Please correct mistakes before clicking ok" ) );
qWarning() << "NgDialog::on_buttonBox_accepted() -> invalid shit";
return;
}
ngSig = QByteArray::fromHex( ui->lineEdit_ngSig->text().toLatin1() );
ngMac = QByteArray::fromHex( ui->lineEdit_ngMac->text().toLatin1() );;
ngPriv = QByteArray::fromHex( ui->lineEdit_ngPriv->text().toLatin1() );
QDialog::accept();
}
void NgDialog::on_pushButton_cancel_clicked()
{
QDialog::reject();
}

51
saveToy/ngdialog.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef NGDIALOG_H
#define NGDIALOG_H
#include "../WiiQt/includes.h"
#include "../WiiQt/tools.h"
namespace Ui {
class NgDialog;
}
class NgDialog : public QDialog
{
Q_OBJECT
public:
explicit NgDialog( QWidget *parent = 0 );
~NgDialog();
quint32 ngID;
quint32 ngKeyID;
QByteArray ngSig;
QByteArray ngMac;
QByteArray ngPriv;
private:
Ui::NgDialog *ui;
QRegExp hex;
bool ValidNGID();
bool ValidNGKeyID();
bool ValidNGSig();
bool ValidNGMac();
bool ValidNGPriv();
private slots:
void on_pushButton_cancel_clicked();
void on_pushButton_ok_clicked();
void on_pushButton_existingSave_clicked();
void on_pushButton_keys_clicked();
void on_lineEdit_ngPriv_textChanged(QString );
void on_lineEdit_ngMac_textChanged(QString );
void on_lineEdit_ngKeyId_textChanged(QString );
void on_lineEdit_ngSig_textChanged(QString );
void on_lineEdit_ngID_textChanged(QString );
public slots:
int exec();
};
#endif // NGDIALOG_H

180
saveToy/ngdialog.ui Normal file
View File

@ -0,0 +1,180 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NgDialog</class>
<widget class="QDialog" name="NgDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
<string>NG Stuff</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_ngid">
<property name="text">
<string>NG ID</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_ngID">
<property name="maxLength">
<number>16</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_ngKeyId">
<property name="text">
<string>NG Key ID</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_ngKeyId">
<property name="maxLength">
<number>16</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_ngMac">
<property name="maxLength">
<number>24</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_ngMac">
<property name="text">
<string>NG Mac</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton_keys">
<property name="text">
<string>Read keys.bin</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_existingSave">
<property name="text">
<string>Read data.bin</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_ngPriv">
<property name="text">
<string>NG Priv</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_ngPriv">
<property name="maxLength">
<number>120</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_ngSig">
<property name="text">
<string>NG SIG</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_ngSig">
<property name="maxLength">
<number>200</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_message">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_ok">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,32 @@
#ifndef JLCOMPRESSFOLDER_H_
#define JLCOMPRESSFOLDER_H_
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
#include <QString>
#include <QDir>
#include <QFileInfo>
#include <QFile>
class JlCompress {
private:
static bool compressFile(QuaZip* zip, QString fileName, QString fileDest);
static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive = true);
static bool extractFile(QuaZip* zip, QString fileName, QString fileDest);
static bool removeFile(QStringList listFile);
public:
static bool compressFile(QString fileCompressed, QString file);
static bool compressFiles(QString fileCompressed, QStringList files);
static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true);
public:
static QString extractFile(QString fileCompressed, QString file, QString fileDest = QString());
static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString());
static QStringList extractDir(QString fileCompressed, QString dir = QString());
static QStringList getFileList(QString fileCompressed);
};
#endif /* JLCOMPRESSFOLDER_H_ */

View File

@ -0,0 +1,133 @@
/* crypt.h -- base code for crypt/uncrypt ZIPfile
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
This code is a modified version of crypting code in Infozip distribution
The encryption/decryption parts of this source code (as opposed to the
non-echoing password parts) were originally written in Europe. The
whole source package can be freely distributed, including from the USA.
(Prior to January 2000, re-export from the US was a violation of US law.)
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
If you don't need crypting in your application, just define symbols
NOCRYPT and NOUNCRYPT.
This code support the "Traditional PKWARE Encryption".
The new AES encryption added on Zip format by Winzip (see the page
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
Encryption is not supported.
*/
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
{
(void) pcrc_32_tab; /* avoid "unused parameter" warning */
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
{
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
{
register int keyshift = (int)((*(pkeys+1)) >> 24);
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
}
return c;
}
/***********************************************************************
* Initialize the encryption keys and the random header according to
* the given password.
*/
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
*(pkeys+2) = 878082192L;
while (*passwd != '\0') {
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
passwd++;
}
}
#define zdecode(pkeys,pcrc_32_tab,c) \
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
#define zencode(pkeys,pcrc_32_tab,c,t) \
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
#define RAND_HEAD_LEN 12
/* "last resort" source for second part of crypt seed pattern */
# ifndef ZCR_SEED2
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
const char *passwd; /* password string */
unsigned char *buf; /* where to write header */
int bufSize;
unsigned long* pkeys;
const unsigned long* pcrc_32_tab;
unsigned long crcForCrypting;
{
int n; /* index in random header */
int t; /* temporary */
int c; /* random byte */
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
static unsigned calls = 0; /* ensure different random header each time */
if (bufSize<RAND_HEAD_LEN)
return 0;
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
* output of rand() to get less predictability, since rand() is
* often poorly implemented.
*/
if (++calls == 1)
{
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
}
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
c = (rand() >> 7) & 0xff;
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
}
/* Encrypt random header (last two bytes is high word of crc) */
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
}
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
return n;
}
#endif

View File

@ -0,0 +1,75 @@
/* ioapi.h -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
*/
#ifndef _ZLIBIOAPI_H
#define _ZLIBIOAPI_H
#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)
#define ZLIB_FILEFUNC_SEEK_SET (0)
#define ZLIB_FILEFUNC_MODE_READ (1)
#define ZLIB_FILEFUNC_MODE_WRITE (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE (8)
#ifndef ZCALLBACK
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
#define ZCALLBACK CALLBACK
#else
#define ZCALLBACK
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
typedef struct zlib_filefunc_def_s
{
open_file_func zopen_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell_file_func ztell_file;
seek_file_func zseek_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
voidpf opaque;
} zlib_filefunc_def;
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,29 @@
#ifndef QUAADLER32_H
#define QUAADLER32_H
#include <QByteArray>
#include "quachecksum32.h"
/// Adler32 checksum
/** \class QuaAdler32 quaadler32.h <quazip/quaadler32.h>
* This class wrappers the adler32 function with the QuaChecksum32 interface.
* See QuaChecksum32 for more info.
*/
class QuaAdler32 : public QuaChecksum32
{
public:
QuaAdler32();
quint32 calculate(const QByteArray &data);
void reset();
void update(const QByteArray &buf);
quint32 value();
private:
quint32 checksum;
};
#endif //QUAADLER32_H

View File

@ -0,0 +1,53 @@
#ifndef QUACHECKSUM32_H
#define QUACHECKSUM32_H
#include <QByteArray>
/// Checksum interface.
/** \class QuaChecksum32 quachecksum32.h <quazip/quachecksum32.h>
* This is an interface for 32 bit checksums.
* Classes implementing this interface can calcunate a certin
* checksum in a single step:
* \code
* QChecksum32 *crc32 = new QuaCrc32();
* rasoult = crc32->calculate(data);
* \endcode
* or by streaming the data:
* \code
* QChecksum32 *crc32 = new QuaCrc32();
* while(!fileA.atEnd())
* crc32->update(fileA.read(bufSize));
* resoultA = crc32->value();
* crc32->reset();
* while(!fileB.atEnd())
* crc32->update(fileB.read(bufSize));
* resoultB = crc32->value();
* \endcode
*/
class QuaChecksum32
{
public:
///Calculates the checksum for data.
/** \a data source data
* \return data checksum
*
* This function has no efect on the value returned by value().
*/
virtual quint32 calculate(const QByteArray &data) = 0;
///Resets the calculation on a checksun for a stream.
virtual void reset() = 0;
///Updates the calculated checksum for the stream
/** \a buf next portion of data from the stream
*/
virtual void update(const QByteArray &buf) = 0;
///Value of the checksum calculated for the stream passed throw update().
/** \return checksum
*/
virtual quint32 value() = 0;
};
#endif //QUACHECKSUM32_H

View File

@ -0,0 +1,26 @@
#ifndef QUACRC32_H
#define QUACRC32_H
#include "quachecksum32.h"
///CRC32 checksum
/** \class QuaCrc32 quacrc32.h <quazip/quacrc32.h>
* This class wrappers the crc32 function with the QuaChecksum32 interface.
* See QuaChecksum32 for more info.
*/
class QuaCrc32 : public QuaChecksum32 {
public:
QuaCrc32();
quint32 calculate(const QByteArray &data);
void reset();
void update(const QByteArray &buf);
quint32 value();
private:
quint32 checksum;
};
#endif //QUACRC32_H

View File

@ -0,0 +1,346 @@
#ifndef QUA_ZIP_H
#define QUA_ZIP_H
/*
-- A kind of "standard" GPL license statement --
QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
Copyright (C) 2005-2007 Sergey A. Tachenov
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-- A kind of "standard" GPL license statement ends here --
See COPYING file for GPL.
You are also permitted to use QuaZIP under the terms of LGPL (see
COPYING.LGPL). You are free to choose either license, but please note
that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
you are using Open Source edition of Qt, you therefore MUST use GPL for
your code based on QuaZIP, since it would be also based on Qt in this
case. If you are Qt commercial license owner, then you are free to use
QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
**/
#include <QString>
#include <QTextCodec>
#include "zip.h"
#include "unzip.h"
#include "quazipfileinfo.h"
// just in case it will be defined in the later versions of the ZIP/UNZIP
#ifndef UNZ_OPENERROR
// define additional error code
#define UNZ_OPENERROR -1000
#endif
/// ZIP archive.
/** \class QuaZip quazip.h <quazip/quazip.h>
* This class implements basic interface to the ZIP archive. It can be
* used to read table contents of the ZIP archive and retreiving
* information about the files inside it.
*
* You can also use this class to open files inside archive by passing
* pointer to the instance of this class to the constructor of the
* QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*)
* for the possible pitfalls.
*
* This class is indended to provide interface to the ZIP subpackage of
* the ZIP/UNZIP package as well as to the UNZIP subpackage. But
* currently it supports only UNZIP.
*
* The use of this class is simple - just create instance using
* constructor, then set ZIP archive file name using setFile() function
* (if you did not passed the name to the constructor), then open() and
* then use different functions to work with it! Well, if you are
* paranoid, you may also wish to call close before destructing the
* instance, to check for errors on close.
*
* You may also use getUnzFile() and getZipFile() functions to get the
* ZIP archive handle and use it with ZIP/UNZIP package API directly.
*
* This class supports localized file names inside ZIP archive, but you
* have to set up proper codec with setCodec() function. By default,
* locale codec will be used, which is probably ok for UNIX systems, but
* will almost certainly fail with ZIP archives created in Windows. This
* is because Windows ZIP programs have strange habit of using DOS
* encoding for file names in ZIP archives. For example, ZIP archive
* with cyrillic names created in Windows will have file names in \c
* IBM866 encoding instead of \c WINDOWS-1251. I think that calling one
* function is not much trouble, but for true platform independency it
* would be nice to have some mechanism for file name encoding auto
* detection using locale information. Does anyone know a good way to do
* it?
**/
class QuaZip {
public:
/// Useful constants.
enum Constants {
MAX_FILE_NAME_LENGTH=256 /**< Maximum file name length. Taken from
\c UNZ_MAXFILENAMEINZIP constant in
unzip.c. */
};
/// Open mode of the ZIP file.
enum Mode {
mdNotOpen, ///< ZIP file is not open. This is the initial mode.
mdUnzip, ///< ZIP file is open for reading files inside it.
mdCreate, ///< ZIP file was created with open() call.
mdAppend, /**< ZIP file was opened in append mode. This refers to
* \c APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package
* and means that zip is appended to some existing file
* what is useful when that file contains
* self-extractor code. This is obviously \em not what
* you whant to use to add files to the existing ZIP
* archive.
**/
mdAdd ///< ZIP file was opened for adding files in the archive.
};
/// Case sensitivity for the file names.
/** This is what you specify when accessing files in the archive.
* Works perfectly fine with any characters thanks to Qt's great
* unicode support. This is different from ZIP/UNZIP API, where
* only US-ASCII characters was supported.
**/
enum CaseSensitivity {
csDefault=0, ///< Default for platform. Case sensitive for UNIX, not for Windows.
csSensitive=1, ///< Case sensitive.
csInsensitive=2 ///< Case insensitive.
};
private:
QTextCodec *fileNameCodec, *commentCodec;
QString zipName;
QString comment;
Mode mode;
union {
unzFile unzFile_f;
zipFile zipFile_f;
};
bool hasCurrentFile_f;
int zipError;
// not (and will not be) implemented
QuaZip(const QuaZip& that);
// not (and will not be) implemented
QuaZip& operator=(const QuaZip& that);
public:
/// Constructs QuaZip object.
/** Call setName() before opening constructed object. */
QuaZip();
/// Constructs QuaZip object associated with ZIP file \a zipName.
QuaZip(const QString& zipName);
/// Destroys QuaZip object.
/** Calls close() if necessary. */
~QuaZip();
/// Opens ZIP file.
/** Argument \a ioApi specifies IO function set for ZIP/UNZIP
* package to use. See unzip.h, zip.h and ioapi.h for details. By
* passing NULL (the default) you just tell package to use the
* default API which works just fine on UNIX platforms. I have tried
* it on win32-g++ platform too and it seems it works fine there
* too, so I see no reason to use win32 IO API included in original
* ZIP/UNZIP package.
*
* ZIP archive file name will be converted to 8-bit encoding using
* Qt's QFile::encodeName() function before passing it to the
* ZIP/UNZIP package API.
*
* Returns \c true if successful, \c false otherwise.
*
* Argument \a mode specifies open mode of the ZIP archive. See Mode
* for details. Note that there is zipOpen2() function in the
* ZIP/UNZIP API which accepts \a globalcomment argument, but it
* does not use it anywhere, so this open() function does not have this
* argument. See setComment() if you need to set global comment.
*
* \note ZIP/UNZIP API open calls do not return error code - they
* just return \c NULL indicating an error. But to make things
* easier, quazip.h header defines additional error code \c
* UNZ_ERROROPEN and getZipError() will return it if the open call
* of the ZIP/UNZIP API returns \c NULL.
**/
bool open(Mode mode, zlib_filefunc_def *ioApi =NULL);
/// Closes ZIP file.
/** Call getZipError() to determine if the close was successful. */
void close();
/// Sets the codec used to encode/decode file names inside archive.
/** This is necessary to access files in the ZIP archive created
* under Windows with non-latin characters in file names. For
* example, file names with cyrillic letters will be in \c IBM866
* encoding.
**/
void setFileNameCodec(QTextCodec *fileNameCodec)
{this->fileNameCodec=fileNameCodec;}
/// Sets the codec used to encode/decode file names inside archive.
/** \overload
* Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
**/
void setFileNameCodec(const char *fileNameCodecName)
{fileNameCodec=QTextCodec::codecForName(fileNameCodecName);}
/// Returns the codec used to encode/decode comments inside archive.
QTextCodec* getFileNameCodec()const {return fileNameCodec;}
/// Sets the codec used to encode/decode comments inside archive.
/** This codec defaults to locale codec, which is probably ok.
**/
void setCommentCodec(QTextCodec *commentCodec)
{this->commentCodec=commentCodec;}
/// Sets the codec used to encode/decode comments inside archive.
/** \overload
* Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
**/
void setCommentCodec(const char *commentCodecName)
{commentCodec=QTextCodec::codecForName(commentCodecName);}
/// Returns the codec used to encode/decode comments inside archive.
QTextCodec* getCommentCodec()const {return commentCodec;}
/// Returns the name of the ZIP file.
/** Returns null string if no ZIP file name has been set.
* \sa setZipName()
**/
QString getZipName()const {return zipName;}
/// Sets the name of the ZIP file.
/** Does nothing if the ZIP file is open.
*
* Does not reset error code returned by getZipError().
**/
void setZipName(const QString& zipName);
/// Returns the mode in which ZIP file was opened.
Mode getMode()const {return mode;}
/// Returns \c true if ZIP file is open, \c false otherwise.
bool isOpen()const {return mode!=mdNotOpen;}
/// Returns the error code of the last operation.
/** Returns \c UNZ_OK if the last operation was successful.
*
* Error code resets to \c UNZ_OK every time you call any function
* that accesses something inside ZIP archive, even if it is \c
* const (like getEntriesCount()). open() and close() calls reset
* error code too. See documentation for the specific functions for
* details on error detection.
**/
int getZipError()const {return zipError;}
/// Returns number of the entries in the ZIP central directory.
/** Returns negative error code in the case of error. The same error
* code will be returned by subsequent getZipError() call.
**/
int getEntriesCount()const;
/// Returns global comment in the ZIP file.
QString getComment()const;
/// Sets global comment in the ZIP file.
/** Comment will be written to the archive on close operation.
*
* \sa open()
**/
void setComment(const QString& comment) {this->comment=comment;}
/// Sets the current file to the first file in the archive.
/** Returns \c true on success, \c false otherwise. Call
* getZipError() to get the error code.
**/
bool goToFirstFile();
/// Sets the current file to the next file in the archive.
/** Returns \c true on success, \c false otherwise. Call
* getZipError() to determine if there was an error.
*
* Should be used only in QuaZip::mdUnzip mode.
*
* \note If the end of file was reached, getZipError() will return
* \c UNZ_OK instead of \c UNZ_END_OF_LIST_OF_FILE. This is to make
* things like this easier:
* \code
* for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
* // do something
* }
* if(zip.getZipError()==UNZ_OK) {
* // ok, there was no error
* }
* \endcode
**/
bool goToNextFile();
/// Sets current file by its name.
/** Returns \c true if successful, \c false otherwise. Argument \a
* cs specifies case sensitivity of the file name. Call
* getZipError() in the case of a failure to get error code.
*
* This is not a wrapper to unzLocateFile() function. That is
* because I had to implement locale-specific case-insensitive
* comparison.
*
* Here are the differences from the original implementation:
*
* - If the file was not found, error code is \c UNZ_OK, not \c
* UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()).
* - If this function fails, it unsets the current file rather than
* resetting it back to what it was before the call.
*
* If \a fileName is null string then this function unsets the
* current file and return \c true. Note that you should close the
* file first if it is open! See
* QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.
*
* Should be used only in QuaZip::mdUnzip mode.
*
* \sa setFileNameCodec(), CaseSensitivity
**/
bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
/// Returns \c true if the current file has been set.
bool hasCurrentFile()const {return hasCurrentFile_f;}
/// Retrieves information about the current file.
/** Fills the structure pointed by \a info. Returns \c true on
* success, \c false otherwise. In the latter case structure pointed
* by \a info remains untouched. If there was an error,
* getZipError() returns error code.
*
* Should be used only in QuaZip::mdUnzip mode.
*
* Does nothing and returns \c false in any of the following cases.
* - ZIP is not open;
* - ZIP does not have current file;
* - \a info is \c NULL;
*
* In all these cases getZipError() returns \c UNZ_OK since there
* is no ZIP/UNZIP API call.
**/
bool getCurrentFileInfo(QuaZipFileInfo* info)const;
/// Returns the current file name.
/** Equivalent to calling getCurrentFileInfo() and then getting \c
* name field of the QuaZipFileInfo structure, but faster and more
* convenient.
*
* Should be used only in QuaZip::mdUnzip mode.
**/
QString getCurrentFileName()const;
/// Returns \c unzFile handle.
/** You can use this handle to directly call UNZIP part of the
* ZIP/UNZIP package functions (see unzip.h).
*
* \warning When using the handle returned by this function, please
* keep in mind that QuaZip class is unable to detect any changes
* you make in the ZIP file state (e. g. changing current file, or
* closing the handle). So please do not do anything with this
* handle that is possible to do with the functions of this class.
* Or at least return the handle in the original state before
* calling some another function of this class (including implicit
* destructor calls and calls from the QuaZipFile objects that refer
* to this QuaZip instance!). So if you have changed the current
* file in the ZIP archive - then change it back or you may
* experience some strange behavior or even crashes.
**/
unzFile getUnzFile() {return unzFile_f;}
/// Returns \c zipFile handle.
/** You can use this handle to directly call ZIP part of the
* ZIP/UNZIP package functions (see zip.h). Warnings about the
* getUnzFile() function also apply to this function.
**/
zipFile getZipFile() {return zipFile_f;}
};
#endif

View File

@ -0,0 +1,442 @@
#ifndef QUA_ZIPFILE_H
#define QUA_ZIPFILE_H
/*
-- A kind of "standard" GPL license statement --
QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
Copyright (C) 2005-2008 Sergey A. Tachenov
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-- A kind of "standard" GPL license statement ends here --
See COPYING file for GPL.
You are also permitted to use QuaZIP under the terms of LGPL (see
COPYING.LGPL). You are free to choose either license, but please note
that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
you are using Open Source edition of Qt, you therefore MUST use GPL for
your code based on QuaZIP, since it would be also based on Qt in this
case. If you are Qt commercial license owner, then you are free to use
QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
**/
#include <QIODevice>
#include "quazip.h"
#include "quazipnewinfo.h"
/// A file inside ZIP archive.
/** \class QuaZipFile quazipfile.h <quazip/quazipfile.h>
* This is the most interesting class. Not only it provides C++
* interface to the ZIP/UNZIP package, but also integrates it with Qt by
* subclassing QIODevice. This makes possible to access files inside ZIP
* archive using QTextStream or QDataStream, for example. Actually, this
* is the main purpose of the whole QuaZIP library.
*
* You can either use existing QuaZip instance to create instance of
* this class or pass ZIP archive file name to this class, in which case
* it will create internal QuaZip object. See constructors' descriptions
* for details. Writing is only possible with the existing instance.
*
* \section quazipfile-sequential Sequential or random-access?
*
* At the first thought, QuaZipFile has fixed size, the start and the
* end and should be therefore considered random-access device. But
* there is one major obstacle to making it random-access: ZIP/UNZIP API
* does not support seek() operation and the only way to implement it is
* through reopening the file and re-reading to the required position,
* but this is prohibitely slow.
*
* Therefore, QuaZipFile is considered to be a sequential device. This
* has advantage of availability of the ungetChar() operation (QIODevice
* does not implement it properly for non-sequential devices unless they
* support seek()). Disadvantage is a somewhat strange behaviour of the
* size() and pos() functions. This should be kept in mind while using
* this class.
*
**/
class QuaZipFile: public QIODevice {
Q_OBJECT
private:
QuaZip *zip;
QString fileName;
QuaZip::CaseSensitivity caseSensitivity;
bool raw;
qint64 writePos;
// these two are for writing raw files
ulong uncompressedSize;
quint32 crc;
bool internal;
int zipError;
// these are not supported nor implemented
QuaZipFile(const QuaZipFile& that);
QuaZipFile& operator=(const QuaZipFile& that);
void resetZipError()const {setZipError(UNZ_OK);}
// const, but sets zipError!
void setZipError(int zipError)const;
protected:
/// Implementation of the QIODevice::readData().
qint64 readData(char *data, qint64 maxSize);
/// Implementation of the QIODevice::writeData().
qint64 writeData(const char *data, qint64 maxSize);
public:
/// Constructs a QuaZipFile instance.
/** You should use setZipName() and setFileName() or setZip() before
* trying to call open() on the constructed object.
**/
QuaZipFile();
/// Constructs a QuaZipFile instance.
/** \a parent argument specifies this object's parent object.
*
* You should use setZipName() and setFileName() or setZip() before
* trying to call open() on the constructed object.
**/
QuaZipFile(QObject *parent);
/// Constructs a QuaZipFile instance.
/** \a parent argument specifies this object's parent object and \a
* zipName specifies ZIP archive file name.
*
* You should use setFileName() before trying to call open() on the
* constructed object.
*
* QuaZipFile constructed by this constructor can be used for read
* only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
**/
QuaZipFile(const QString& zipName, QObject *parent =NULL);
/// Constructs a QuaZipFile instance.
/** \a parent argument specifies this object's parent object, \a
* zipName specifies ZIP archive file name and \a fileName and \a cs
* specify a name of the file to open inside archive.
*
* QuaZipFile constructed by this constructor can be used for read
* only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
*
* \sa QuaZip::setCurrentFile()
**/
QuaZipFile(const QString& zipName, const QString& fileName,
QuaZip::CaseSensitivity cs =QuaZip::csDefault, QObject *parent =NULL);
/// Constructs a QuaZipFile instance.
/** \a parent argument specifies this object's parent object.
*
* \a zip is the pointer to the existing QuaZip object. This
* QuaZipFile object then can be used to read current file in the
* \a zip or to write to the file inside it.
*
* \warning Using this constructor for reading current file can be
* tricky. Let's take the following example:
* \code
* QuaZip zip("archive.zip");
* zip.open(QuaZip::mdUnzip);
* zip.setCurrentFile("file-in-archive");
* QuaZipFile file(&zip);
* file.open(QIODevice::ReadOnly);
* // ok, now we can read from the file
* file.read(somewhere, some);
* zip.setCurrentFile("another-file-in-archive"); // oops...
* QuaZipFile anotherFile(&zip);
* anotherFile.open(QIODevice::ReadOnly);
* anotherFile.read(somewhere, some); // this is still ok...
* file.read(somewhere, some); // and this is NOT
* \endcode
* So, what exactly happens here? When we change current file in the
* \c zip archive, \c file that references it becomes invalid
* (actually, as far as I understand ZIP/UNZIP sources, it becomes
* closed, but QuaZipFile has no means to detect it).
*
* Summary: do not close \c zip object or change its current file as
* long as QuaZipFile is open. Even better - use another constructors
* which create internal QuaZip instances, one per object, and
* therefore do not cause unnecessary trouble. This constructor may
* be useful, though, if you already have a QuaZip instance and do
* not want to access several files at once. Good example:
* \code
* QuaZip zip("archive.zip");
* zip.open(QuaZip::mdUnzip);
* // first, we need some information about archive itself
* QByteArray comment=zip.getComment();
* // and now we are going to access files inside it
* QuaZipFile file(&zip);
* for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
* file.open(QIODevice::ReadOnly);
* // do something cool with file here
* file.close(); // do not forget to close!
* }
* zip.close();
* \endcode
**/
QuaZipFile(QuaZip *zip, QObject *parent =NULL);
/// Destroys a QuaZipFile instance.
/** Closes file if open, destructs internal QuaZip object (if it
* exists and \em is internal, of course).
**/
virtual ~QuaZipFile();
/// Returns the ZIP archive file name.
/** If this object was created by passing QuaZip pointer to the
* constructor, this function will return that QuaZip's file name
* (or null string if that object does not have file name yet).
*
* Otherwise, returns associated ZIP archive file name or null
* string if there are no name set yet.
*
* \sa setZipName() getFileName()
**/
QString getZipName()const;
/// Returns a pointer to the associated QuaZip object.
/** Returns \c NULL if there is no associated QuaZip or it is
* internal (so you will not mess with it).
**/
QuaZip* getZip()const;
/// Returns file name.
/** This function returns file name you passed to this object either
* by using
* QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*)
* or by calling setFileName(). Real name of the file may differ in
* case if you used case-insensitivity.
*
* Returns null string if there is no file name set yet. This is the
* case when this QuaZipFile operates on the existing QuaZip object
* (constructor QuaZipFile(QuaZip*,QObject*) or setZip() was used).
*
* \sa getActualFileName
**/
QString getFileName()const {return fileName;}
/// Returns case sensitivity of the file name.
/** This function returns case sensitivity argument you passed to
* this object either by using
* QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*)
* or by calling setFileName().
*
* Returns unpredictable value if getFileName() returns null string
* (this is the case when you did not used setFileName() or
* constructor above).
*
* \sa getFileName
**/
QuaZip::CaseSensitivity getCaseSensitivity()const {return caseSensitivity;}
/// Returns the actual file name in the archive.
/** This is \em not a ZIP archive file name, but a name of file inside
* archive. It is not necessary the same name that you have passed
* to the
* QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*),
* setFileName() or QuaZip::setCurrentFile() - this is the real file
* name inside archive, so it may differ in case if the file name
* search was case-insensitive.
*
* Equivalent to calling getCurrentFileName() on the associated
* QuaZip object. Returns null string if there is no associated
* QuaZip object or if it does not have a current file yet. And this
* is the case if you called setFileName() but did not open the
* file yet. So this is perfectly fine:
* \code
* QuaZipFile file("somezip.zip");
* file.setFileName("somefile");
* QString name=file.getName(); // name=="somefile"
* QString actual=file.getActualFileName(); // actual is null string
* file.open(QIODevice::ReadOnly);
* QString actual=file.getActualFileName(); // actual can be "SoMeFiLe" on Windows
* \endcode
*
* \sa getZipName(), getFileName(), QuaZip::CaseSensitivity
**/
QString getActualFileName()const;
/// Sets the ZIP archive file name.
/** Automatically creates internal QuaZip object and destroys
* previously created internal QuaZip object, if any.
*
* Will do nothing if this file is already open. You must close() it
* first.
**/
void setZipName(const QString& zipName);
/// Returns \c true if the file was opened in raw mode.
/** If the file is not open, the returned value is undefined.
*
* \sa open(OpenMode,int*,int*,bool,const char*)
**/
bool isRaw()const {return raw;}
/// Binds to the existing QuaZip instance.
/** This function destroys internal QuaZip object, if any, and makes
* this QuaZipFile to use current file in the \a zip object for any
* further operations. See QuaZipFile(QuaZip*,QObject*) for the
* possible pitfalls.
*
* Will do nothing if the file is currently open. You must close()
* it first.
**/
void setZip(QuaZip *zip);
/// Sets the file name.
/** Will do nothing if at least one of the following conditions is
* met:
* - ZIP name has not been set yet (getZipName() returns null
* string).
* - This QuaZipFile is associated with external QuaZip. In this
* case you should call that QuaZip's setCurrentFile() function
* instead!
* - File is already open so setting the name is meaningless.
*
* \sa QuaZip::setCurrentFile
**/
void setFileName(const QString& fileName, QuaZip::CaseSensitivity cs =QuaZip::csDefault);
/// Opens a file for reading.
/** Returns \c true on success, \c false otherwise.
* Call getZipError() to get error code.
*
* \note Since ZIP/UNZIP API provides buffered reading only,
* QuaZipFile does not support unbuffered reading. So do not pass
* QIODevice::Unbuffered flag in \a mode, or open will fail.
**/
virtual bool open(OpenMode mode);
/// Opens a file for reading.
/** \overload
* Argument \a password specifies a password to decrypt the file. If
* it is NULL then this function behaves just like open(OpenMode).
**/
bool open(OpenMode mode, const char *password)
{return open(mode, NULL, NULL, false, password);}
/// Opens a file for reading.
/** \overload
* Argument \a password specifies a password to decrypt the file.
*
* An integers pointed by \a method and \a level will receive codes
* of the compression method and level used. See unzip.h.
*
* If raw is \c true then no decompression is performed.
*
* \a method should not be \c NULL. \a level can be \c NULL if you
* don't want to know the compression level.
**/
bool open(OpenMode mode, int *method, int *level, bool raw, const char *password =NULL);
/// Opens a file for writing.
/** \a info argument specifies information about file. It should at
* least specify a correct file name. Also, it is a good idea to
* specify correct timestamp (by default, current time will be
* used). See QuaZipNewInfo.
*
* Arguments \a password and \a crc provide necessary information
* for crypting. Note that you should specify both of them if you
* need crypting. If you do not, pass \c NULL as password, but you
* still need to specify \a crc if you are going to use raw mode
* (see below).
*
* Arguments \a method and \a level specify compression method and
* level.
*
* If \a raw is \c true, no compression is performed. In this case,
* \a crc and uncompressedSize field of the \a info are required.
*
* Arguments \a windowBits, \a memLevel, \a strategy provide zlib
* algorithms tuning. See deflateInit2() in zlib.
**/
bool open(OpenMode mode, const QuaZipNewInfo& info,
const char *password =NULL, quint32 crc =0,
int method =Z_DEFLATED, int level =Z_DEFAULT_COMPRESSION, bool raw =false,
int windowBits =-MAX_WBITS, int memLevel =DEF_MEM_LEVEL, int strategy =Z_DEFAULT_STRATEGY);
/// Returns \c true, but \ref quazipfile-sequential "beware"!
virtual bool isSequential()const;
/// Returns current position in the file.
/** Implementation of the QIODevice::pos(). When reading, this
* function is a wrapper to the ZIP/UNZIP unztell(), therefore it is
* unable to keep track of the ungetChar() calls (which is
* non-virtual and therefore is dangerous to reimplement). So if you
* are using ungetChar() feature of the QIODevice, this function
* reports incorrect value until you get back characters which you
* ungot.
*
* When writing, pos() returns number of bytes already written
* (uncompressed unless you use raw mode).
*
* \note Although
* \ref quazipfile-sequential "QuaZipFile is a sequential device"
* and therefore pos() should always return zero, it does not,
* because it would be misguiding. Keep this in mind.
*
* This function returns -1 if the file or archive is not open.
*
* Error code returned by getZipError() is not affected by this
* function call.
**/
virtual qint64 pos()const;
/// Returns \c true if the end of file was reached.
/** This function returns \c false in the case of error. This means
* that you called this function on either not open file, or a file
* in the not open archive or even on a QuaZipFile instance that
* does not even have QuaZip instance associated. Do not do that
* because there is no means to determine whether \c false is
* returned because of error or because end of file was reached.
* Well, on the other side you may interpret \c false return value
* as "there is no file open to check for end of file and there is
* no end of file therefore".
*
* When writing, this function always returns \c true (because you
* are always writing to the end of file).
*
* Error code returned by getZipError() is not affected by this
* function call.
**/
virtual bool atEnd()const;
/// Returns file size.
/** This function returns csize() if the file is open for reading in
* raw mode, usize() if it is open for reading in normal mode and
* pos() if it is open for writing.
*
* Returns -1 on error, call getZipError() to get error code.
*
* \note This function returns file size despite that
* \ref quazipfile-sequential "QuaZipFile is considered to be sequential device",
* for which size() should return bytesAvailable() instead. But its
* name would be very misguiding otherwise, so just keep in mind
* this inconsistence.
**/
virtual qint64 size()const;
/// Returns compressed file size.
/** Equivalent to calling getFileInfo() and then getting
* compressedSize field, but more convenient and faster.
*
* File must be open for reading before calling this function.
*
* Returns -1 on error, call getZipError() to get error code.
**/
qint64 csize()const;
/// Returns uncompressed file size.
/** Equivalent to calling getFileInfo() and then getting
* uncompressedSize field, but more convenient and faster. See
* getFileInfo() for a warning.
*
* File must be open for reading before calling this function.
*
* Returns -1 on error, call getZipError() to get error code.
**/
qint64 usize()const;
/// Gets information about current file.
/** This function does the same thing as calling
* QuaZip::getCurrentFileInfo() on the associated QuaZip object,
* but you can not call getCurrentFileInfo() if the associated
* QuaZip is internal (because you do not have access to it), while
* you still can call this function in that case.
*
* File must be open for reading before calling this function.
*
* Returns \c false in the case of an error.
**/
bool getFileInfo(QuaZipFileInfo *info);
/// Closes the file.
/** Call getZipError() to determine if the close was successful.
**/
virtual void close();
/// Returns the error code returned by the last ZIP/UNZIP API call.
int getZipError()const {return zipError;}
};
#endif

View File

@ -0,0 +1,73 @@
#ifndef QUA_ZIPFILEINFO_H
#define QUA_ZIPFILEINFO_H
/*
-- A kind of "standard" GPL license statement --
QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
Copyright (C) 2005-2007 Sergey A. Tachenov
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-- A kind of "standard" GPL license statement ends here --
See COPYING file for GPL.
You are also permitted to use QuaZIP under the terms of LGPL (see
COPYING.LGPL). You are free to choose either license, but please note
that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
you are using Open Source edition of Qt, you therefore MUST use GPL for
your code based on QuaZIP, since it would be also based on Qt in this
case. If you are Qt commercial license owner, then you are free to use
QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
**/
#include <QByteArray>
#include <QDateTime>
/// Information about a file inside archive.
/** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to
* fill this structure. */
struct QuaZipFileInfo {
/// File name.
QString name;
/// Version created by.
quint16 versionCreated;
/// Version needed to extract.
quint16 versionNeeded;
/// General purpose flags.
quint16 flags;
/// Compression method.
quint16 method;
/// Last modification date and time.
QDateTime dateTime;
/// CRC.
quint32 crc;
/// Compressed file size.
quint32 compressedSize;
/// Uncompressed file size.
quint32 uncompressedSize;
/// Disk number start.
quint16 diskNumberStart;
/// Internal file attributes.
quint16 internalAttr;
/// External file attributes.
quint32 externalAttr;
/// Comment.
QString comment;
/// Extra field.
QByteArray extra;
};
#endif

View File

@ -0,0 +1,109 @@
#ifndef QUA_ZIPNEWINFO_H
#define QUA_ZIPNEWINFO_H
/*
-- A kind of "standard" GPL license statement --
QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
Copyright (C) 2005-2007 Sergey A. Tachenov
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-- A kind of "standard" GPL license statement ends here --
See COPYING file for GPL.
You are also permitted to use QuaZIP under the terms of LGPL (see
COPYING.LGPL). You are free to choose either license, but please note
that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
you are using Open Source edition of Qt, you therefore MUST use GPL for
your code based on QuaZIP, since it would be also based on Qt in this
case. If you are Qt commercial license owner, then you are free to use
QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
**/
#include <QDateTime>
#include <QString>
/// Information about a file to be created.
/** This structure holds information about a file to be created inside
* ZIP archive. At least name should be set to something correct before
* passing this structure to
* QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool).
**/
struct QuaZipNewInfo {
/// File name.
/** This field holds file name inside archive, including path relative
* to archive root.
**/
QString name;
/// File timestamp.
/** This is the last file modification date and time. Will be stored
* in the archive central directory. It is a good practice to set it
* to the source file timestamp instead of archive creating time. Use
* setFileDateTime() or QuaZipNewInfo(const QString&, const QString&).
**/
QDateTime dateTime;
/// File internal attributes.
quint16 internalAttr;
/// File external attributes.
quint32 externalAttr;
/// File comment.
/** Will be encoded using QuaZip::getCommentCodec().
**/
QString comment;
/// File local extra field.
QByteArray extraLocal;
/// File global extra field.
QByteArray extraGlobal;
/// Uncompressed file size.
/** This is only needed if you are using raw file zipping mode, i. e.
* adding precompressed file in the zip archive.
**/
ulong uncompressedSize;
/// Constructs QuaZipNewInfo instance.
/** Initializes name with \a name, dateTime with current date and
* time. Attributes are initialized with zeros, comment and extra
* field with null values.
**/
QuaZipNewInfo(const QString& name);
/// Constructs QuaZipNewInfo instance.
/** Initializes name with \a name and dateTime with timestamp of the
* file named \a file. If the \a file does not exists or its timestamp
* is inaccessible (e. g. you do not have read permission for the
* directory file in), uses current date and time. Attributes are
* initialized with zeros, comment and extra field with null values.
*
* \sa setFileDateTime()
**/
QuaZipNewInfo(const QString& name, const QString& file);
/// Sets the file timestamp from the existing file.
/** Use this function to set the file timestamp from the existing
* file. Use it like this:
* \code
* QuaZipFile zipFile(&zip);
* QFile file("file-to-add");
* file.open(QIODevice::ReadOnly);
* QuaZipNewInfo info("file-name-in-archive");
* info.setFileDateTime("file-to-add"); // take the timestamp from file
* zipFile.open(QIODevice::WriteOnly, info);
* \endcode
*
* This function does not change dateTime if some error occured (e. g.
* file is inaccessible).
**/
void setFileDateTime(const QString& file);
};
#endif

View File

@ -0,0 +1,354 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Multi volume ZipFile (span) are not supported.
Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
http://www.info-zip.org/pub/infozip/doc/
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _unz_H
#define _unz_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
} unz_file_info;
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
const char* fileName2,
int iCaseSensitivity));
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
or strcasecmp)
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
(like 1 on Unix, 2 on Windows)
*/
extern unzFile ZEXPORT unzOpen OF((const char *path));
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
"zlib/zlib113.zip".
If the zipfile cannot be opened (file don't exist or in not valid), the
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
zlib_filefunc_def* pzlib_filefunc_def));
/*
Open a Zip file, like unzOpen, but provide a set of file low level API
for read/write the zip file (see ioapi.h)
*/
extern int ZEXPORT unzClose OF((unzFile file));
/*
Close a ZipFile opened with unzipOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
unz_global_info *pglobal_info));
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
char *szComment,
uLong uSizeBuf));
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
/*
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
/*
Set the current file of the zipfile to the next file.
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
extern int ZEXPORT unzLocateFile OF((unzFile file,
const char *szFileName,
int iCaseSensitivity));
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
/* ****************************************** */
/* Ryan supplied functions */
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_pos_s
{
uLong pos_in_zip_directory; /* offset in zip file directory */
uLong num_of_file; /* # of file */
} unz_file_pos;
extern int ZEXPORT unzGetFilePos(
unzFile file,
unz_file_pos* file_pos);
extern int ZEXPORT unzGoToFilePos(
unzFile file,
unz_file_pos* file_pos);
/* ****************************************** */
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
unz_file_info *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize));
/*
Get Info about the current file
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
*/
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
/*
Open for reading data the current file in the zipfile.
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
const char* password));
/*
Open for reading data the current file in the zipfile.
password is a crypting password
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
int* method,
int* level,
int raw));
/*
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1
*method will receive method of compression, *level will receive level of
compression
note : you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL
*/
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
int* method,
int* level,
int raw,
const char* password));
/*
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1
*method will receive method of compression, *level will receive level of
compression
note : you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL
*/
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
/*
Close the file in zip opened with unzOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
voidp buf,
unsigned len));
/*
Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
extern z_off_t ZEXPORT unztell OF((unzFile file));
/*
Give the current position in uncompressed data
*/
extern int ZEXPORT unzeof OF((unzFile file));
/*
return 1 if the end of file was reached, 0 elsewhere
*/
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
voidp buf,
unsigned len));
/*
Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
/***************************************************************************/
/* Get the current file offset */
extern uLong ZEXPORT unzGetOffset (unzFile file);
/* Set the current file offset */
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
#ifdef __cplusplus
}
#endif
#endif /* _unz_H */

View File

@ -0,0 +1,235 @@
/* zip.h -- IO for compress .zip files using zlib
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Multi volume ZipFile (span) are not supported.
Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
For uncompress .zip file, look at unzip.h
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
http://www.info-zip.org/pub/infozip/doc/
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _zip_H
#define _zip_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagzipFile__ { int unused; } zipFile__;
typedef zipFile__ *zipFile;
#else
typedef voidp zipFile;
#endif
#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_PARAMERROR (-102)
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
# else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
# endif
#endif
/* default memLevel */
/* tm_zip contain date/time info */
typedef struct tm_zip_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_zip;
typedef struct
{
tm_zip tmz_date; /* date in understandable format */
uLong dosDate; /* if dos_date == 0, tmu_date is used */
/* uLong flag; */ /* general purpose bit flag 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
typedef const char* zipcharpc;
#define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2)
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
/*
Create a zipfile.
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
an Unix computer "zlib/zlib113.zip".
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
will be created at the end of the file.
(useful if the file contain a self extractor code)
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
add files in existing zip (be sure you don't add file that doesn't exist)
If the zipfile cannot be opened, the return value is NULL.
Else, the return value is a zipFile Handle, usable with other function
of this zip package.
*/
/* Note : there is no delete function into a zipfile.
If you want delete file into a zipfile, you must open a zipfile, and create another
Of couse, you can use RAW reading and writing to copy the file you did not want delte
*/
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
int append,
zipcharpc* globalcomment,
zlib_filefunc_def* pzlib_filefunc_def));
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level));
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
*/
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw));
/*
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
*/
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char* password,
uLong crcForCtypting));
/*
Same than zipOpenNewFileInZip2, except
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
password : crypting password (NULL for no crypting)
crcForCtypting : crc of file to compress (needed for crypting)
*/
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
const void* buf,
unsigned len));
/*
Write data in the zipfile
*/
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
/*
Close the current file in the zipfile
*/
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
uLong uncompressed_size,
uLong crc32));
/*
Close the current file in the zipfile, for fiel opened with
parameter raw=1 in zipOpenNewFileInZip2
uncompressed_size and crc32 are value for the uncompressed size
*/
extern int ZEXPORT zipClose OF((zipFile file,
const char* global_comment));
/*
Close the zipfile
*/
#ifdef __cplusplus
}
#endif
#endif /* _zip_H */

View File

@ -17,16 +17,69 @@ SOURCES += main.cpp\
../WiiQt/tools.cpp \
../WiiQt/savebanner.cpp \
../WiiQt/aes.c \
../WiiQt/sha1.c
../WiiQt/sha1.c \
../WiiQt/md5.cpp \
../WiiQt/sharedcontentmap.cpp \
../WiiQt/tiktmd.cpp \
../WiiQt/uidmap.cpp \
../WiiQt/nanddump.cpp \
../WiiQt/wad.cpp \
../WiiQt/bn.cpp \
../WiiQt/ec.cpp \
../WiiQt/savedatabin.cpp \
../WiiQt/keysbin.cpp \
ngdialog.cpp \
textdialog.cpp
HEADERS += mainwindow.h \
savelistitem.h \
saveloadthread.h\
../WiiQt/tools.h
../WiiQt/tools.h \
../WiiQt/savebanner.h \
../WiiQt/sharedcontentmap.h \
../WiiQt/tiktmd.h \
../WiiQt/uidmap.h \
../WiiQt/nanddump.h \
../WiiQt/wad.h \
../WiiQt/savedatabin.h \
../WiiQt/ec.h \
../WiiQt/keysbin.h \
quazip/include/zip.h \
quazip/include/unzip.h \
quazip/include/quazipnewinfo.h \
quazip/include/quazipfileinfo.h \
quazip/include/quazipfile.h \
quazip/include/quazip.h \
quazip/include/quacrc32.h \
quazip/include/quachecksum32.h \
quazip/include/quaadler32.h \
quazip/include/JlCompress.h \
quazip/include/ioapi.h \
quazip/include/crypt.h \
ngdialog.h \
textdialog.h
FORMS += mainwindow.ui
FORMS += mainwindow.ui \
ngdialog.ui \
textdialog.ui
RESOURCES += \
rc.qrc
INCPATH += "../WiiQt"
INCLUDEPATH += . ./quazip/include
#different paths for different zip libraries
win32 {
message("still need to build quazlib for windows")
}
unix {
!contains(QMAKE_HOST.arch, x86_64) {
message("x86 build")
LIBS += -L./quazip/lib/linux_x86 -lquazip
} else {
message("x86_64 build")
LIBS += -L./quazip/lib/linux_x64 -lquazip
}
}
macx{
message("still need to build quazlib for mac")
}

View File

@ -6,11 +6,11 @@ SaveListItem::SaveListItem( SaveBanner banner, const QString &tid, quint32 s, QL
QImage im = banner.BannerImg();
if( !im.isNull() )
{
im.load( ";/noBanner.png" );
im.load( ";/noBanner.png" );
}
QString tex = banner.Title();
if( tex.isEmpty() )
tex = "???";
tex = "???";
this->setText( tex );
this->setIcon( QIcon( QPixmap::fromImage( im ) ) );

View File

@ -2,8 +2,8 @@
#define SAVELISTITEM_H
#include "savebanner.h"
#include "includes.h"
#include "../WiiQt/savebanner.h"
#include "../WiiQt/includes.h"
class SaveListItem : public QListWidgetItem
@ -15,8 +15,6 @@ public:
SaveBanner *Banner(){ return &sb; }
QString Tid(){ return id; }
quint32 Size(){ return size; }
//quint32 Blocks(){ return size / 0x20000; }
//quint32 MiB(){ return size / 0x100000; }
private:
SaveBanner sb;

View File

@ -1,9 +1,13 @@
#include "saveloadthread.h"
#include "quazip.h"
#include "quazipfile.h"
#include "../WiiQt/savedatabin.h"
Q_DECLARE_METATYPE( PcSaveInfo )
SaveLoadThread::SaveLoadThread( QObject *parent ) : QThread( parent )
{
abort = false;
//qRegisterMetaType< SaveListItem* >();
qRegisterMetaType< PcSaveInfo >();
}
void SaveLoadThread::ForceQuit()
@ -22,124 +26,74 @@ SaveLoadThread::~SaveLoadThread()
wait();
}
void SaveLoadThread::GetBanners( const QString &bPath, int mode )
void SaveLoadThread::GetBanners( const QString &bPath )
{
if( isRunning() )
{
qWarning() << "SaveLoadThread::GetBanners -> already running";
return;
}
basePath = bPath;
type = mode;
if( basePath.isEmpty() )
type = LOAD_SNEEK;
else
type = LOAD_PC;
start( NormalPriority );
}
bool SaveLoadThread::SetNandPath( const QString &bPath )
{
if( isRunning() )
return false;
if( nand.BasePath() == bPath )
return true;
return nand.SetPath( bPath );
}
SaveGame SaveLoadThread::GetSave( quint64 tid )
{
SaveGame ret;
ret.tid = 0;
if( isRunning() )
return ret;
return nand.GetSaveData( tid );
}
void SaveLoadThread::run()
{
if ( abort )
{
qDebug( "SaveLoadThread::run -> Thread abort" );
return;
qDebug( "SaveLoadThread::run -> Thread abort" );
return;
}
mutex.lock();
if( basePath.isEmpty() )
/*if( basePath.isEmpty() )
{
qDebug() << "SaveLoadThread::run -> its empty";
return;
}
qDebug() << "SaveLoadThread::run -> its empty";
return;
}*/
mutex.unlock();
QFileInfo fi( basePath );
if( !fi.exists() || !fi.isDir() )
switch( type )
{
qWarning() << "SaveLoadThread::run ->" << basePath << "is not a directory";
return;
case LOAD_SNEEK:
GetSavesFromNandDump();
break;
case LOAD_PC:
if( basePath.isEmpty() )
return;
GetPCSaves();
break;
default:
break;
}
fi.setFile(basePath + "/title/00010000" );
if( !fi.exists() || !fi.isDir() )
{
qWarning() << "SaveLoadThread::run ->" << QString( basePath + "/title/00010000" ) << "is not a directory";
return;
}
QDir subDir( basePath + "/title/00010000" );
subDir.setFilter( QDir::Dirs | QDir::NoDotAndDotDot );
QFileInfoList fiL = subDir.entryInfoList();
quint32 cnt = fiL.size();
int i = 0;
subDir.setPath( basePath + "/title/00010001" );
QFileInfoList fiL2 = subDir.entryInfoList();
cnt += fiL2.size();
subDir.setPath( basePath + "/title/00010002" );
QFileInfoList fiL3 = subDir.entryInfoList();
cnt += fiL3.size();
subDir.setPath( basePath + "/title/00010004" );
QFileInfoList fiL4 = subDir.entryInfoList();
cnt += fiL4.size();
foreach( QFileInfo f, fiL )
{
i++;
emit SendProgress( (int)( ( (float)( i ) / (float)cnt ) * (float)100 ) );
QFile ff( f.absoluteFilePath() + "/data/banner.bin" );
if( !ff.exists() || !ff.open( QIODevice::ReadOnly ) )
continue;
QByteArray stuff = ff.readAll();
ff.close();
quint32 size = GetFolderSize( f.absoluteFilePath() + "/data" );
emit SendItem( stuff, QString( "00010000" + f.fileName() ), type, size );
}
foreach( QFileInfo f, fiL2 )
{
i++;
emit SendProgress( (int)( ( (float)( i ) / (float)cnt ) * (float)100 ) );
QFile ff( f.absoluteFilePath() + "/data/banner.bin" );
if( !ff.exists() || !ff.open( QIODevice::ReadOnly ) )
continue;
QByteArray stuff = ff.readAll();
ff.close();
quint32 size = GetFolderSize( f.absoluteFilePath() + "/data" );
emit SendItem( stuff, QString( "00010001" + f.fileName() ), type, size );
}
foreach( QFileInfo f, fiL3 )
{
i++;
emit SendProgress( (int)( ( (float)( i ) / (float)cnt ) * (float)100 ) );
QFile ff( f.absoluteFilePath() + "/data/banner.bin" );
if( !ff.exists() || !ff.open( QIODevice::ReadOnly ) )
continue;
QByteArray stuff = ff.readAll();
ff.close();
quint32 size = GetFolderSize( f.absoluteFilePath() + "/data" );
emit SendItem( stuff, QString( "00010002" + f.fileName() ), type, size );
}
foreach( QFileInfo f, fiL4 )
{
i++;
emit SendProgress( (int)( ( (float)( i ) / (float)cnt ) * (float)100 ) );
QFile ff( f.absoluteFilePath() + "/data/banner.bin" );
if( !ff.exists() || !ff.open( QIODevice::ReadOnly ) )
continue;
QByteArray stuff = ff.readAll();
ff.close();
quint32 size = GetFolderSize( f.absoluteFilePath() + "/data" );
emit SendItem( stuff, QString( "00010004" + f.fileName() ), type, size );
}
emit SendProgress( 100 );
emit SendDone( type );
}
@ -148,15 +102,203 @@ int SaveLoadThread::GetFolderSize( const QString& path )
//qDebug() << "SaveLoadThread::GetFolderSize" << path;
quint32 ret = 0;
QDir dir( path );
dir.setFilter( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot );
dir.setFilter( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot );
QFileInfoList fiL = dir.entryInfoList();
foreach( QFileInfo fi, fiL )
{
if( fi.isDir() )
ret += GetFolderSize( fi.absoluteFilePath() );
if( fi.isDir() )
ret += GetFolderSize( fi.absoluteFilePath() );
else
ret += fi.size();
else
ret += fi.size();
}
return ret;
}
void SaveLoadThread::GetSavesFromPC()
{
emit SendProgress( 0 );
emit SendProgress( 100 );
}
void SaveLoadThread::GetPCSaves()
{
emit SendProgress( 0 );
if( basePath.isEmpty() )
return;
int total = 0;
int done = 0;
//first count all the saves
//list all subdirs of the base ( TID upper )
QDir base( basePath );
QFileInfoList fi1 = base.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
foreach( QFileInfo upper, fi1 )
{
//qDebug() << "looking in" << upper.absoluteFilePath();
//get all subdirectories of the subfolder ( TID lower )
QDir uDir( upper.absoluteFilePath() );
QFileInfoList fi2 = uDir.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
foreach( QFileInfo lower, fi2 )
{
//qDebug() << "looking in" << lower.absoluteFilePath();
//list all .zip files in the game's folder
QDir lDir( lower.absoluteFilePath() );
QFileInfoList fi3 = lDir.entryInfoList( QStringList() << "*.zip", QDir::Files );
//qDebug() << "found" << fi3.size() << "zip files in here";
total += fi3.size();
}
}
//qDebug() << "SaveLoadThread::GetPCSaves(): will open" << total << "zip archives";
//now actually read/send the saves
foreach( QFileInfo upper, fi1 )
{
//get all subdirectories of the subfolder ( TID lower )
QDir uDir( upper.absoluteFilePath() );
QFileInfoList fi2 = uDir.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
foreach( QFileInfo lower, fi2 )
{
//list all .zip files in the game's folder
QDir lDir( lower.absoluteFilePath() );
QFileInfoList fi3 = lDir.entryInfoList( QStringList() << "*.zip", QDir::Files );
quint32 cnt = fi3.size();
//QStringList descriptions;
//QByteArray banner;
//quint32 size = 0;
PcSaveInfo info;
info.tid = upper.fileName() + lower.fileName();
for( quint32 i = 0; i < cnt; i++ )
{
//qDebug() << "opening archive" << fi3.at( i ).absoluteFilePath();
bool bnrOk = false;
bool txtOk = false;
quint32 sSize = 0;
QString desc;
QuaZip zip( fi3.at( i ).absoluteFilePath() );
if( !zip.open( QuaZip::mdUnzip ) )
{
qWarning("SaveLoadThread::GetPCSaves(): zip.open(): %d", zip.getZipError() );
continue;
}
zip.setFileNameCodec("IBM866");
if( zip.getEntriesCount() != 2 )
{
qWarning() << "SaveLoadThread::GetPCSaves() -> save contains more than 2 entries" << fi3.at( i ).absoluteFilePath();
zip.close();
continue;
}
QuaZipFile file(&zip);
QString name;
for( bool more = zip.goToFirstFile(); more; more = zip.goToNextFile() )
{
if( !file.open( QIODevice::ReadOnly ) )
{
qWarning("SaveLoadThread::GetPCSaves(): file.open(): %d", file.getZipError() );
zip.close();
continue;
}
name = file.getActualFileName();
//qDebug() << "extracting" << name << "from the archive";
if( file.getZipError() != UNZ_OK )
{
qWarning("SaveLoadThread::GetPCSaves(): file.getFileName(): %d", file.getZipError());
file.close();
zip.close();
continue;
}
if( name != "data.bin" && name != "info.txt" )
{
qWarning() << "SaveLoadThread::GetPCSaves() -> zip contians bad filename" << fi3.at( i ).absoluteFilePath() << name;
file.close();
zip.close();
continue;
}
/*if( name == "data.bin" && banner.size() )//theres already a banner been extracted, no need to get another one
{
file.close();
continue;
}*/
QByteArray unc = file.readAll();
//qDebug() << "read" << hex << unc.size();
if( file.getZipError() != UNZ_OK )
{
qWarning("SaveLoadThread::GetPCSaves(): file.getFileName(): %d", file.getZipError());
file.close();
zip.close();
continue;
}
file.close();
//read the data.bin to get the banner
if( name == "data.bin" )
{
if( info.banner.isEmpty() )
info.banner = SaveDataBin::GetBanner( unc );
sSize = SaveDataBin::GetSize( unc );
bnrOk = true;
}
else if( name == "info.txt" )
{
desc = QString( unc );
txtOk = true;
}
}
if( txtOk && bnrOk )
{
info.descriptions << desc;
info.sizes << sSize;
info.paths << fi3.at( i ).absoluteFilePath();
}
zip.close();
emit SendProgress( (int)( ( (float)( ++done) / (float)total ) * (float)100 ) );
}
//QString tidStr = upper.fileName() + lower.fileName();
//emit SendPcItem( banner, tidStr, descriptions, size );
if( info.sizes.size() )
emit SendPcItem( info );
}
}
emit SendProgress( 100 );
}
void SaveLoadThread::GetSavesFromNandDump()
{
emit SendProgress( 0 );
QString base = nand.BasePath();
if( base.isEmpty() )
return;
QMap< quint64, quint32 > list = nand.GetSaveList();
QMap< quint64, quint32 >::Iterator it = list.begin();
int i = 0;
int s = list.size();
while( it != list.end() && !abort )
{
quint64 tid = it.key();
quint32 size = it.value();
it++;
QString tidStr = QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) );
QString bnrPath = tidStr;
bnrPath.insert( 8, "/" );
bnrPath.prepend( "/title/" );
bnrPath.append( "/data/banner.bin" );
QByteArray bnr = nand.GetFile( bnrPath );
emit SendProgress( (int)( ( (float)( ++i ) / (float)s ) * (float)100 ) );
if( bnr.isEmpty() )
continue;
emit SendSneekItem( bnr, tidStr, size );
}
emit SendProgress( 100 );
}
bool SaveLoadThread::DeleteSaveFromSneekNand( quint64 tid )
{
if( isRunning() )
return false;
return nand.DeleteSave( tid );
}

View File

@ -1,44 +1,71 @@
#ifndef SAVELOADTHREAD_H
#define SAVELOADTHREAD_H
#include "savelistitem.h"
#include "includes.h"
//#include "savelistitem.h"
#include "../WiiQt/includes.h"
#include "../WiiQt/nanddump.h"
#define DESC_VERSION 1
enum
{
LOAD_SNEEK = 0x111,
LOAD_PC
};
//little struct to hold the info about all the saves for 1 game backed up on the PC
struct PcSaveInfo
{
QString tid;
QByteArray banner;
QList<quint32> sizes;
QStringList descriptions;
QStringList paths;
};
class SaveLoadThread : public QThread
{
Q_OBJECT
public:
SaveLoadThread( QObject *parent = 0 );
~SaveLoadThread();
public:
SaveLoadThread( QObject *parent = 0 );
~SaveLoadThread();
void GetBanners( const QString &bPath, int mode );
void ForceQuit();
//get banners
//if no path is given, it will try to get them from NandDump, otherwise it will use the path on the PC ( not implemented yet )
void GetBanners( const QString &bPath = QString() );
protected:
void run();
//set this object's extracted nand path
bool SetNandPath( const QString &bPath );
signals:
void SendProgress( int );
void SendDone( int );
void SendItem( QByteArray, const QString&, int, int );
//TODO: these arent done on the work thread, but instead in the calling thread
bool DeleteSaveFromSneekNand( quint64 tid );
SaveGame GetSave( quint64 tid );
private:
QMutex mutex;
QWaitCondition condition;
QString basePath;
int type;
bool abort;
void ForceQuit();
int GetFolderSize( const QString& path );
};
protected:
void run();
NandDump nand;
void GetSavesFromNandDump();
void GetSavesFromPC();
void GetPCSaves();
//Q_DECLARE_METATYPE( SaveListItem* )
signals:
void SendProgress( int );
void SendDone( int );
void SendSneekItem( QByteArray, const QString&, int );
//void SendPcItem( QByteArray, const QString&, const QStringList&, int );
void SendPcItem( PcSaveInfo );
private:
QMutex mutex;
QWaitCondition condition;
QString basePath;
int type;
bool abort;
int GetFolderSize( const QString& path );
};
#endif // SAVELOADTHREAD_H

28
saveToy/textdialog.cpp Normal file
View File

@ -0,0 +1,28 @@
#include "textdialog.h"
#include "ui_textdialog.h"
TextDialog::TextDialog(QWidget *parent, const QString &txt ) :
QDialog(parent),
ui(new Ui::TextDialog)
{
ui->setupUi(this);
ui->textEdit->append( txt );
}
TextDialog::~TextDialog()
{
delete ui;
}
void TextDialog::on_buttonBox_accepted()
{
ret = ui->textEdit->document()->toPlainText();
}
QString TextDialog::GetText( QWidget *parent, const QString &txt )
{
TextDialog d( parent, txt );
if( !d.exec() )
return QString();
return d.ret;
}

29
saveToy/textdialog.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef TEXTDIALOG_H
#define TEXTDIALOG_H
#include <QDialog>
namespace Ui {
class TextDialog;
}
//generic dialog to get text
class TextDialog : public QDialog
{
Q_OBJECT
public:
explicit TextDialog(QWidget *parent = 0, const QString &txt = QString() );
~TextDialog();
static QString GetText( QWidget *parent = 0, const QString &txt = QString() );
private:
Ui::TextDialog *ui;
QString ret;
private slots:
void on_buttonBox_accepted();
};
#endif // TEXTDIALOG_H