mirror of
https://github.com/martravi/wiiqt6.git
synced 2024-11-21 21:19:15 +01:00
* use Qt stuff for general sha1 & md5.
* replace apparently buggy round-up macro git-svn-id: http://wiiqt.googlecode.com/svn/trunk@45 389f4c8b-5dfe-645f-db0e-df882bc27289
This commit is contained in:
parent
3f1f5654ad
commit
930e92ca3c
@ -307,7 +307,7 @@ Boot2Info Blocks0to7::CheckHashes( Boot2Info info )
|
||||
stuff += blocks.at( ret.secondBlock );
|
||||
|
||||
AesSetKey( ticket.DecryptedKey() );
|
||||
QByteArray decD = AesDecrypt( 0, stuff.mid( dataOff, RU( 0x40, t.Size( 0 ) ) ) );
|
||||
QByteArray decD = AesDecrypt( 0, stuff.mid( dataOff, RU( t.Size( 0 ), 0x40 ) ) );
|
||||
decD.resize( t.Size( 0 ) );
|
||||
QByteArray realHash = GetSha1( decD );
|
||||
if( realHash != t.Hash( 0 ) )
|
||||
|
@ -1602,7 +1602,7 @@ bool NandBin::CheckHmacData( quint16 entry )
|
||||
if( !fst.size )
|
||||
return true;
|
||||
|
||||
quint16 clCnt = ( RU( 0x4000, fst.size ) / 0x4000 );
|
||||
quint16 clCnt = ( RU( fst.size, 0x4000 ) / 0x4000 );
|
||||
//qDebug() << FstName( fst ) << "is" << hex << fst.size << "bytes (" << clCnt << ") clusters";
|
||||
|
||||
quint16 fat = fst.sub;
|
||||
|
@ -377,8 +377,9 @@ bool NandDump::InstallNusItem( const NusJob &job )
|
||||
}
|
||||
|
||||
quint32 cnt = qFromBigEndian( t.payload()->num_contents );
|
||||
if( cnt != (quint32)job.data.size() )
|
||||
if( cnt != (quint32)job.data.size() - 2 )
|
||||
{
|
||||
qWarning() << "cnt != (quint32)job.data.size()";
|
||||
AbortInstalling( job.tid );
|
||||
return false;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "savedatabin.h"
|
||||
#include "aes.h"
|
||||
#include "md5.h"
|
||||
#include "ec.h"
|
||||
|
||||
SaveDataBin::SaveDataBin( QByteArray stuff )
|
||||
@ -26,13 +25,8 @@ SaveDataBin::SaveDataBin( QByteArray stuff )
|
||||
//check MD5
|
||||
quint8 md5blanker[ 16 ] = MD5_BLANKER;
|
||||
QByteArray expected = header.mid( 0xe, 16 );
|
||||
QByteArray headerWithBlanker = header.left( 0xe ) + QByteArray( (const char*)&md5blanker, 16 ) + header.right( 0xf0a2 );
|
||||
//hexdump( headerWithBlanker.left( 0x50 ) );
|
||||
MD5 hash;
|
||||
hash.update( headerWithBlanker.data(), size );
|
||||
hash.finalize();
|
||||
|
||||
QByteArray actual = QByteArray( (const char*)hash.hexdigestChar(), 16 );
|
||||
QByteArray headerWithBlanker = header.left( 0xe ) + QByteArray( (const char*)&md5blanker, 16 ) + header.right( 0xf0a2 );
|
||||
QByteArray actual = GetMd5( headerWithBlanker );
|
||||
if( actual != expected )
|
||||
{
|
||||
qWarning() << "SaveDataBin::SaveDataBin -> md5 mismatch";
|
||||
@ -260,19 +254,15 @@ const QByteArray SaveDataBin::Data( const QByteArray &ngPriv, const QByteArray &
|
||||
b.write( (const char*)&tmp8, 1 );
|
||||
tmp8 = 0; //nocopy or some shit like that?
|
||||
b.write( (const char*)&tmp8, 1 );
|
||||
b.close();
|
||||
b.close();
|
||||
QByteArray header2 = header +
|
||||
QByteArray( (const char*)&md5blanker, 16 ) +
|
||||
QByteArray( 2, '\0' ); //md5 blanker + padding to 0x20
|
||||
header2 += bnr; //add the banner.bin
|
||||
header2 = PaddedByteArray( header2, 0xf0c0 ); //pad to 0xf0c0
|
||||
header2 += bnr; //add the banner.bin
|
||||
header2 = PaddedByteArray( header2, 0xf0c0 ); //pad to 0xf0c0
|
||||
|
||||
MD5 hash;
|
||||
hash.update( header2.data(), 0xf0c0 );
|
||||
hash.finalize();
|
||||
|
||||
QByteArray actual = QByteArray( (const char*)hash.hexdigestChar(), 16 );
|
||||
header += actual + QByteArray( 2, '\0' ) + bnr;
|
||||
QByteArray actual = GetMd5( header2 );
|
||||
header += actual + QByteArray( 2, '\0' ) + bnr;
|
||||
header = PaddedByteArray( header, 0xf0c0 );
|
||||
|
||||
quint8 iv[ 16 ] = SD_IV;
|
||||
@ -510,11 +500,7 @@ quint32 SaveDataBin::GetSize( QByteArray dataBin )
|
||||
quint8 md5blanker[ 16 ] = MD5_BLANKER;
|
||||
QByteArray expected = header.mid( 0xe, 16 );
|
||||
QByteArray headerWithBlanker = header.left( 0xe ) + QByteArray( (const char*)&md5blanker, 16 ) + header.right( 0xf0a2 );
|
||||
MD5 hash;
|
||||
hash.update( headerWithBlanker.data(), size );
|
||||
hash.finalize();
|
||||
|
||||
QByteArray actual = QByteArray( (const char*)hash.hexdigestChar(), 16 );
|
||||
QByteArray actual = GetMd5( headerWithBlanker );
|
||||
if( actual != expected )
|
||||
{
|
||||
qWarning() << "SaveDataBin::GetSize -> md5 mismatch";
|
||||
|
@ -83,8 +83,8 @@ void hexdump12( const QByteArray &d, int from, int len )
|
||||
|
||||
QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo )
|
||||
{
|
||||
QByteArray padding( RU( orig.size(), padTo ) - orig.size(), '\0' );
|
||||
//qDebug() << "padding with" << hex << RU( padTo, orig.size() ) << "bytes" <<
|
||||
//qDebug() << "need to pad from" << hex << orig.size() << "to nearest" << padTo;
|
||||
QByteArray padding( RU( orig.size(), padTo ) - orig.size(), '\0' );
|
||||
return orig + padding;
|
||||
}
|
||||
|
||||
@ -121,7 +121,8 @@ void AesSetKey( const QByteArray &key )
|
||||
|
||||
QByteArray GetSha1( const QByteArray &stuff )
|
||||
{
|
||||
SHA1Context sha;
|
||||
return QCryptographicHash::hash( stuff, QCryptographicHash::Sha1 );
|
||||
/*SHA1Context sha;
|
||||
SHA1Reset( &sha );
|
||||
SHA1Input( &sha, (const unsigned char*)stuff.data(), stuff.size() );
|
||||
if( !SHA1Result( &sha ) )
|
||||
@ -135,9 +136,15 @@ QByteArray GetSha1( const QByteArray &stuff )
|
||||
{
|
||||
quint32 part = qFromBigEndian( sha.Message_Digest[ i ] );
|
||||
memcpy( p + ( i * 4 ), &part, 4 );
|
||||
}
|
||||
//hexdump( ret );
|
||||
return ret;
|
||||
}
|
||||
return ret;*/
|
||||
}
|
||||
|
||||
|
||||
QByteArray GetMd5( const QByteArray &stuff )
|
||||
{
|
||||
//qDebug() << "GetMd5" << hex << stuff.size();
|
||||
return QCryptographicHash::hash( stuff, QCryptographicHash::Md5 );
|
||||
}
|
||||
|
||||
QByteArray ReadFile( const QString &path )
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include "includes.h"
|
||||
//#include "
|
||||
|
||||
#define RU(x,n) (-(-(x) & -(n))) //round up
|
||||
//#define RU(x,n) (-(-(x) & -(n))) //round up
|
||||
#define RU(N, S) ((((N) + (S) - 1) / (S)) * (S))
|
||||
|
||||
#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )
|
||||
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
|
||||
@ -59,6 +60,7 @@ QByteArray AesDecrypt( quint16 index, const QByteArray &source );
|
||||
QByteArray AesEncrypt( quint16 index, const QByteArray &source );
|
||||
|
||||
QByteArray GetSha1( const QByteArray &stuff );
|
||||
QByteArray GetMd5( const QByteArray &stuff );
|
||||
|
||||
bool IsValidSave( const SaveGame &save );
|
||||
const QByteArray DataFromSave( const SaveGame &save, const QString &name );
|
||||
|
@ -66,7 +66,7 @@ Wad::Wad( const QByteArray &stuff )
|
||||
|
||||
//sanity check this thing
|
||||
quint32 s = stuff.size();
|
||||
if( s < ( RU( 0x40, certSize ) + RU( 0x40, tikSize ) + RU( 0x40, tmdSize ) + RU( 0x40, appSize ) + RU( 0x40, footerSize ) ) )
|
||||
if( s < ( RU( certSize, 0x40 ) + RU( tikSize, 0x40 ) + RU( tmdSize, 0x40 ) + RU( appSize, 0x40 ) + RU( footerSize, 0x40 ) ) )
|
||||
{
|
||||
Err( "Total size is less than the combined sizes of all the parts that it is supposed to contain" );
|
||||
return;
|
||||
@ -74,11 +74,11 @@ Wad::Wad( const QByteArray &stuff )
|
||||
|
||||
quint32 pos = 0x40;
|
||||
certData = stuff.mid( pos, certSize );
|
||||
pos += RU( 0x40, certSize );
|
||||
pos += RU( certSize, 0x4 );
|
||||
tikData = stuff.mid( pos, tikSize );
|
||||
pos += RU( 0x40, tikSize );
|
||||
pos += RU( tikSize, 0x40 );
|
||||
tmdData = stuff.mid( pos, tmdSize );
|
||||
pos += RU( 0x40, tmdSize );
|
||||
pos += RU( tmdSize, 0x40 );
|
||||
|
||||
Ticket ticket( tikData );
|
||||
Tmd t( tmdData );
|
||||
@ -106,7 +106,7 @@ Wad::Wad( const QByteArray &stuff )
|
||||
for( quint32 i = 0; i < cnt; i++ )
|
||||
{
|
||||
|
||||
quint32 s = RU( 0x40, t.Size( i ) );
|
||||
quint32 s = RU( t.Size( i ), 0x40 );
|
||||
qDebug() << "content" << i << "is at" << hex << pos
|
||||
<< "with size" << s;
|
||||
QByteArray encData = stuff.mid( pos, s );
|
||||
@ -280,13 +280,13 @@ const QByteArray Wad::Data( quint32 magicWord, const QByteArray &footer )
|
||||
quint16 cnt = t.Count();
|
||||
for( quint16 i = 0; i < cnt; i++ )
|
||||
{
|
||||
quint32 s = RU( 0x40, partsEnc.at( i ).size() );
|
||||
if( RU( 0x40, t.Size( i ) ) != s )
|
||||
quint32 s = RU( partsEnc.at( i ).size(), 0x40 );
|
||||
if( RU( t.Size( i ), 0x40 ) != 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( RU( t.Size( i ), 0x40 ), 0, 16 )
|
||||
.arg( s, 0, 16 ) );
|
||||
return QByteArray();
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ void MainWindow::ReceiveTitleFromNus( NusJob job )
|
||||
if( ok )
|
||||
ShowMessage( tr( "Installed %1 title to nand" ).arg( title ) );
|
||||
else
|
||||
ShowMessage( tr( "<b>Error %1 title to nand</b>" ).arg( title ) );
|
||||
ShowMessage( tr( "<b>Error installing %1 title to nand</b>" ).arg( title ) );
|
||||
}
|
||||
else if( ui->radioButton_wad->isChecked() )
|
||||
{
|
||||
|
@ -194,7 +194,7 @@ void MainWindow::ShowSneekSaveDetails( SaveListItem *item )
|
||||
float mib = (float)size / 1048576.00f;
|
||||
sizeStr = tr( "%1 MiB" ).arg( mib, 3, 'f', 2 );
|
||||
}
|
||||
int blocks = RU( 0x20000, size) / 0x20000;
|
||||
int blocks = RU( size, 0x20000 ) / 0x20000;
|
||||
QString si = QString( "%1 %2 (%3)").arg( blocks ).arg( blocks == 1 ? tr( "Block" ) : tr( "Blocks" ) ).arg( sizeStr );
|
||||
|
||||
ui->label_sneek_size->setText( si );
|
||||
@ -652,7 +652,7 @@ void MainWindow::on_comboBox_pcSelect_currentIndexChanged( int index )
|
||||
float mib = (float)size / 1048576.00f;
|
||||
sizeStr = tr( "%1 MiB" ).arg( mib, 3, 'f', 2 );
|
||||
}
|
||||
int blocks = RU( 0x20000, size) / 0x20000;
|
||||
int blocks = RU( size, 0x20000 ) / 0x20000;
|
||||
QString si = QString( "%1 %2 (%3)").arg( blocks ).arg( blocks == 1 ? tr( "Block" ) : tr( "Blocks" ) ).arg( sizeStr );
|
||||
|
||||
ui->label_pc_size->setText( si );
|
||||
|
@ -17,8 +17,7 @@ SOURCES += main.cpp\
|
||||
../WiiQt/tools.cpp \
|
||||
../WiiQt/savebanner.cpp \
|
||||
../WiiQt/aes.c \
|
||||
../WiiQt/sha1.c \
|
||||
../WiiQt/md5.cpp \
|
||||
../WiiQt/sha1.c \
|
||||
../WiiQt/sharedcontentmap.cpp \
|
||||
../WiiQt/tiktmd.cpp \
|
||||
../WiiQt/uidmap.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user