From 3f1f5654ad30ee90dbf9d9f70f7fc46e0dce8fd6 Mon Sep 17 00:00:00 2001 From: "giantpune@gmail.com" Date: Mon, 3 Jan 2011 10:21:34 +0000 Subject: [PATCH] * add a few more things to get from keys.bin * remove some junk left over from testing git-svn-id: http://wiiqt.googlecode.com/svn/trunk@44 389f4c8b-5dfe-645f-db0e-df882bc27289 --- WiiQt/ec.cpp | 23 +++------- WiiQt/keysbin.cpp | 35 +++++++++++++++ WiiQt/keysbin.h | 7 ++- WiiQt/nandbin.cpp | 101 ++++++-------------------------------------- saveToy/saveToy.pro | 6 ++- 5 files changed, 66 insertions(+), 106 deletions(-) diff --git a/WiiQt/ec.cpp b/WiiQt/ec.cpp index 62c720f..ed56457 100755 --- a/WiiQt/ec.cpp +++ b/WiiQt/ec.cpp @@ -428,24 +428,15 @@ int check_ec(quint8 *ng, quint8 *ap, quint8 *sig, quint8 *sig_hash) void make_ec_cert( quint8 *cert, quint8 *sig, char *signer, char *name, quint8 *priv, quint32 key_id ) { //qDebug() << "make_ec_cert"; - memset( cert, 0, 0x180 ); - //qDebug() << "1"; + memset( cert, 0, 0x180 ); quint32 tmp = qFromBigEndian( (quint32)0x10002 ); - memcpy( (char*)cert, (const void*)&tmp, 4 ); - //qDebug() << "2"; - memcpy( cert + 4, sig, 60 ); - //qDebug() << "3"; - strcpy( (char*)cert + 0x80, signer ); - //qDebug() << "4"; + memcpy( (char*)cert, (const void*)&tmp, 4 ); + memcpy( cert + 4, sig, 60 ); + strcpy( (char*)cert + 0x80, signer ); tmp = qFromBigEndian( (quint32)2 ); - memcpy( (char*)cert + 0xc0, (const void*)&tmp, 4 ); - //qDebug() << "5"; - //wbe32( cert + 0xc0, 2 ); - strcpy( (char*)cert + 0xc4, name ); - //qDebug() << "6"; + memcpy( (char*)cert + 0xc0, (const void*)&tmp, 4 ); + strcpy( (char*)cert + 0xc4, name ); tmp = qFromBigEndian( key_id ); - memcpy( (char*)cert + 0x104, (const void*)&tmp, 4 ); - //qDebug() << "7"; - //wbe32( cert + 0x104, key_id ); + memcpy( (char*)cert + 0x104, (const void*)&tmp, 4 ); ec_priv_to_pub( priv, cert + 0x108 ); } diff --git a/WiiQt/keysbin.cpp b/WiiQt/keysbin.cpp index 631d92c..8120fae 100644 --- a/WiiQt/keysbin.cpp +++ b/WiiQt/keysbin.cpp @@ -50,3 +50,38 @@ const QByteArray KeysBin::HMac() return QByteArray(); return data.mid( 0x144, 0x14 ); } + +const QByteArray KeysBin::Boot1Hash() +{ + if( data.size() != 0x400 ) + return QByteArray(); + return data.mid( 0x100, 0x14 ); +} + +const QByteArray KeysBin::CommonKey() +{ + if( data.size() != 0x400 ) + return QByteArray(); + return data.mid( 0x114, 0x10 ); +} + +const QByteArray KeysBin::RngKey() +{ + if( data.size() != 0x400 ) + return QByteArray(); + return data.mid( 0x168, 0x10 ); +} + +const QByteArray KeysBin::Otp() +{ + if( data.size() != 0x400 ) + return QByteArray(); + return data.mid( 0x100, 0x80 ); +} + +const QByteArray KeysBin::Seeprom() +{ + if( data.size() != 0x400 ) + return QByteArray(); + return data.mid( 0x200, 0x100 ); +} diff --git a/WiiQt/keysbin.h b/WiiQt/keysbin.h index b07e701..04a3d9a 100644 --- a/WiiQt/keysbin.h +++ b/WiiQt/keysbin.h @@ -4,12 +4,17 @@ #include "includes.h" //quick class for grabbing some stuff from a keys.bin from bootmii ( should be 0x400 bytes ) -// TODO - this isnt complete at all class KeysBin { public: KeysBin( QByteArray stuff = QByteArray() ); + const QByteArray Otp(); + const QByteArray Seeprom(); + + const QByteArray Boot1Hash(); + const QByteArray CommonKey(); + const QByteArray RngKey(); const QByteArray NG_ID(); const QByteArray NG_key_ID(); const QByteArray NG_Sig(); diff --git a/WiiQt/nandbin.cpp b/WiiQt/nandbin.cpp index 4939733..491f064 100755 --- a/WiiQt/nandbin.cpp +++ b/WiiQt/nandbin.cpp @@ -16,7 +16,9 @@ NandBin::~NandBin() { if( f.isOpen() ) { +#ifdef NAND_BIN_CAN_WRITE f.flush(); +#endif f.close(); } @@ -381,18 +383,7 @@ bool NandBin::InitNand( const QIcon &dirs, const QIcon &files ) keyIcon = files; root = new QTreeWidgetItem( QStringList() << nandPath ); - AddChildren( root, 0 ); - /*#ifdef NAND_BIN_CAN_WRITE - CreateEntry( "/testDir", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_RW ); - quint16 pp = CreateEntry( "/testDir/testFile", 0, 0, NAND_FILE, NAND_RW, NAND_RW, NAND_RW ); - qDebug() << "created entry" << pp; - Delete( "/testDir/testFile" ); - pp = CreateEntry( "/testDir/testFile", 0, 0, NAND_FILE, NAND_RW, NAND_RW, NAND_RW ); - qDebug() << "created entry" << pp; - SetData( pp, QByteArray( 0x10000, '\x0' ) ); - - WriteMetaData(); -#endif*/ + AddChildren( root, 0 ); //checkout the blocks for boot1&2 QListblocks; @@ -1069,13 +1060,11 @@ bool NandBin::WriteDecryptedCluster( quint32 pageNo, const QByteArray &data, fst bool NandBin::WritePage( quint32 pageNo, const QByteArray &data ) { - //return true; #ifndef NAND_BIN_CAN_WRITE qWarning() << __FILE__ << "was built without write support"; return false; #endif - //qDebug() << "NandBin::WritePage(" << hex << pageNo << ")"; - //return true; + //qDebug() << "NandBin::WritePage(" << hex << pageNo << ")"; quint32 n_pagelen[] = { 0x800, 0x840, 0x840 }; if( (quint32)data.size() != n_pagelen[ type ] ) { @@ -1091,7 +1080,7 @@ bool NandBin::WritePage( quint32 pageNo, const QByteArray &data ) f.seek( (quint64)pageNo * (quint64)n_pagelen[ type ] ); //seek to the beginning of the page to write //qDebug() << "writing page at:" << f.pos() << hex << (quint32)f.pos(); //hexdump( data, 0, 0x20 ); - return f.write( data ); + return ( f.write( data ) == data.size() ); } quint16 NandBin::CreateNode( const QString &name, quint32 uid, quint16 gid, quint8 attr, quint8 user_perm, quint8 group_perm, quint8 other_perm ) @@ -1411,12 +1400,8 @@ bool NandBin::SetData( quint16 idx, const QByteArray &data ) //grab a random cluster from the list quint16 idx = qrand() % freeClusters.size(); - quint16 cl = freeClusters.takeAt( idx ); //remove this number from the list - /*if( freeClusters.contains( cl ) ) - { - qDebug() << "wtf4"; - return false; - }*/ + quint16 cl = freeClusters.takeAt( idx ); //remove this number from the list + fts << cl; //add this one to the clusters that will be used to hold the data quint16 block = cl / 8; //try to find other clusters in the same block for( quint16 i = block * 8; i < ( ( block + 1 ) * 8 ) && fts.size() < clCnt; i++ ) @@ -1427,12 +1412,7 @@ bool NandBin::SetData( quint16 idx, const QByteArray &data ) if( fats.at( i ) == 0xfffe ) //theres more free clusters in this same block, grab them { fts << i; - freeClusters.removeAt( freeClusters.indexOf( i, 0 ) ); - /*if( freeClusters.contains( i ) ) - { - qDebug() << "wtf5"; - return false; - }*/ + freeClusters.removeAt( freeClusters.indexOf( i, 0 ) ); } } //read the spare data to see that the cluster is good - removed for now. but its probably not a bad idea to do this @@ -1462,76 +1442,24 @@ bool NandBin::SetData( quint16 idx, const QByteArray &data ) } //qDebug() << "done writing shit, fix the fats now" << clCnt << fts.size(); //all the data has been written, now make sure the fats are correct - fsts[ idx ].sub = fts.at( 0 ); - - /*QListbugFix = fts; - for( quint16 i = 0; i < fts.size(); i++ ) - { - if( bugFix.at( i ) != fts.at( i ) ) - { - qDebug() << "wwwwtttf?" << i << hex << bugFix.at( i ) << fts.at( i ); - return false; - } - } - quint16 te = fsts[ idx ].sub;*/ + fsts[ idx ].sub = fts.at( 0 ); for( quint16 i = 0; i < clCnt - 1; i++ ) { - fats.replace( fts.at( 0 ), fts.at( 1 ) ); - /*qDebug() << "replacing fat" << hex << fts.at( 0 ) << "to point to" << fts.at( 1 ) << "actual:" << fats.at( fts.at( 0 ) ); - if( te != fts.at( 0 ) || te != bugFix.at( i ) ) - { - qDebug() << "failed" << i << hex << te << fts.at( 0 ) << bugFix.at( i ); - return false; - }*/ - fts.takeFirst(); - //te = GetFAT( te ); - } - //follow the fat chain and make sure it is as expected - /*quint16 num = 0; - te = fsts[ idx ].sub; - while( te < 0xfff0 ) - { - if( te != bugFix.at( num ) ) - { - qDebug() << "mismatch" << num << hex << te << bugFix.at( num ); - break; + fats.replace( fts.at( 0 ), fts.at( 1 ) ); + fts.takeFirst(); } - te = GetFAT( te ); - num++; - }*/ - //qDebug() << "1 followed the chain to" << num << "items. expected" << clCnt; - //qDebug() << "loop is done"; + //qDebug() << "1 followed the chain to" << num << "items. expected" << clCnt; fats.replace( fts.at( 0 ), 0xfffb );//last cluster in chain fts.takeFirst(); //qDebug() << "fixed the last one" << hex << fts; - // if the new data uses less clusters than the previous data, mark the extra ones as free - //if( !fts.isEmpty() ) - //qDebug() << "need to mark" << fts.size() << "clusters free"; - + // if the new data uses less clusters than the previous data, mark the extra ones as free while( !fts.isEmpty() ) { fats.replace( fts.at( 0 ), 0xfffe ); fts.takeFirst(); - } - //qDebug() << "2nd loop is done"; - - //follow the fat chain and make sure it is as expected - /*num = 0; - te = fsts[ idx ].sub; - while( te < 0xfff0 ) - { - if( te != bugFix.at( num ) ) - { - qDebug() << "mismatch" << num << hex << te << bugFix.at( num ); - break; } - te = GetFAT( te ); - num++; - } - - qDebug() << "2 followed the chain to" << num << "items. expected" << clCnt;*/ fsts[ idx ].size = data.size(); @@ -1542,8 +1470,7 @@ bool NandBin::SetData( quint16 idx, const QByteArray &data ) return false; } - i->setText( 2, QString( "%1" ).arg( data.size(), 0, 16 ) ); - //f.flush(); + i->setText( 2, QString( "%1" ).arg( data.size(), 0, 16 ) ); return true; } diff --git a/saveToy/saveToy.pro b/saveToy/saveToy.pro index 585b871..51a77c4 100644 --- a/saveToy/saveToy.pro +++ b/saveToy/saveToy.pro @@ -76,13 +76,15 @@ macx{ message("mac build") LIBS += -L./quazip/lib/mac -lquazip } -else unix { - !contains(QMAKE_HOST.arch, x86_64) { +else { + 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 } + } }