diff --git a/WiiQt/tiktmd.cpp b/WiiQt/tiktmd.cpp index 189be1c..79eb041 100644 --- a/WiiQt/tiktmd.cpp +++ b/WiiQt/tiktmd.cpp @@ -214,6 +214,23 @@ Ticket::Ticket( QByteArray stuff ) return; SetPointer(); + + quint8 iv[ 16 ]; + quint8 keyin[ 16 ]; + quint8 keyout[ 16 ]; + quint8 commonkey[ 16 ] = COMMON_KEY; + + quint8 *enc_key = (quint8 *)&p_tik->cipher_title_key; + memcpy( keyin, enc_key, sizeof keyin ); + memset( keyout, 0, sizeof keyout ); + memset( iv, 0, sizeof iv); + memcpy( iv, &p_tik->titleid, sizeof p_tik->titleid ); + + aes_set_key( commonkey ); + aes_decrypt( iv, keyin, keyout, sizeof( keyin ) ); + + decKey = QByteArray( (const char*)&keyout, 16 ); + if( (quint32)data.size() != SignedSize() ) { data.resize( SignedSize() ); @@ -232,29 +249,17 @@ bool Ticket::SetTid( quint64 tid ) { if( !p_tik ) return false; + //hexdump( data, payLoadOffset, data.size() - payLoadOffset ); - p_tik->titleid = qFromBigEndian( tid ); + quint64 t = qFromBigEndian( tid ); + p_tik->titleid = t; + //hexdump( data, payLoadOffset, data.size() - payLoadOffset ); return true; } QByteArray Ticket::DecryptedKey() { - quint8 iv[ 16 ]; - quint8 keyin[ 16 ]; - quint8 keyout[ 16 ]; - static quint8 commonkey[ 16 ] = COMMON_KEY; - - quint8 *enc_key = (quint8 *)&p_tik->cipher_title_key; - memcpy( keyin, enc_key, sizeof keyin ); - memset( keyout, 0, sizeof keyout ); - memset( iv, 0, sizeof iv); - memcpy( iv, &p_tik->titleid, sizeof p_tik->titleid ); - - aes_set_key( commonkey ); - aes_decrypt( iv, keyin, keyout, sizeof( keyin ) ); - - return QByteArray( (const char*)&keyout, 16 ); - + return decKey; } quint32 Ticket::SignedSize() @@ -274,7 +279,7 @@ void Ticket::SetPointer() else if( data.startsWith( "\x0\x1\x0\x2" ) ) payLoadOffset = sizeof( sig_ecdsa ); - p_tik = (tik*)((quint8*)data.data() + payLoadOffset); + p_tik = (tik*)((quint8*)(data.data()) + payLoadOffset); } bool Ticket::FakeSign() diff --git a/WiiQt/tiktmd.h b/WiiQt/tiktmd.h index f171a6d..0d1e56e 100644 --- a/WiiQt/tiktmd.h +++ b/WiiQt/tiktmd.h @@ -160,6 +160,7 @@ private: //let data hold the entire tik data QByteArray data; + QByteArray decKey; //point the p_tik to the spot in "data" we want void SetPointer(); diff --git a/WiiQt/tools.cpp b/WiiQt/tools.cpp index 5ec0e73..5947c93 100644 --- a/WiiQt/tools.cpp +++ b/WiiQt/tools.cpp @@ -94,7 +94,8 @@ QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo ) QByteArray AesDecrypt( quint16 index, const QByteArray source ) { - static quint8 iv[ 16 ]; + //qDebug() << "AesDecrypt" << hex << index << source.size(); + quint8 iv[ 16 ]; quint16 beidx = qFromBigEndian( index ); memset( iv, 0, 16 ); @@ -118,6 +119,7 @@ QByteArray AesEncrypt( quint16 index, const QByteArray source ) void AesSetKey( const QByteArray key ) { +// qDebug() << "AesSetKey()" << key.toHex(); aes_set_key( (const quint8*)key.data() ); } diff --git a/ohneschwanzenegger/mainwindow.cpp b/ohneschwanzenegger/mainwindow.cpp index d48f287..3090956 100644 --- a/ohneschwanzenegger/mainwindow.cpp +++ b/ohneschwanzenegger/mainwindow.cpp @@ -574,7 +574,7 @@ bool MainWindow::InstallNUSItem( NusJob job ) { //nand.WriteMetaData(); UpdateTree(); - ShowMessage( tr( "Deleted old TMD and private contents for\n%1" ).arg( title ) ); + ShowMessage( tr( "Deleted old TMD and private contents for
%1" ).arg( title ) ); } cnt = t.Count();