From 2ccd125bb34d8d8e35bbcf6d4b67c5bf41618672 Mon Sep 17 00:00:00 2001 From: "giantpune@gmail.com" Date: Tue, 18 Jan 2011 03:03:08 +0000 Subject: [PATCH] * account for the other, non-usa regions when creating default UID entries * try to use the least possible ones amount of them while still being accurate --- WiiQt/nusdownloader.h | 4 +- WiiQt/uidmap.cpp | 56 ++++----------- WiiQt/uidmap.h | 5 +- ohneschwanzenegger/mainwindow.cpp | 22 ++++-- ohneschwanzenegger/newnandbin.cpp | 90 +++++++++++++++++++++++- ohneschwanzenegger/newnandbin.h | 2 + ohneschwanzenegger/newnandbin.ui | 109 ++++++++++++++++++++++-------- 7 files changed, 205 insertions(+), 83 deletions(-) diff --git a/WiiQt/nusdownloader.h b/WiiQt/nusdownloader.h index 6f4b77c..8b5c605 100644 --- a/WiiQt/nusdownloader.h +++ b/WiiQt/nusdownloader.h @@ -58,7 +58,7 @@ public: //in the list, ask for it specifically. //lists are created from wiimpersonator logs when available. otherwise they come from examining game update partitions - static QMap< quint64, quint16 > List20u(); + static QMap< quint64, quint16 > List20u();//* there are no games ive seen that contain this update. this is just a guess static QMap< quint64, quint16 > List22u(); static QMap< quint64, quint16 > List30u(); static QMap< quint64, quint16 > List31u(); @@ -70,7 +70,7 @@ public: static QMap< quint64, quint16 > List42u(); static QMap< quint64, quint16 > List43u(); - static QMap< quint64, quint16 > List20e(); + static QMap< quint64, quint16 > List20e();//* there are no games ive seen that contain this update. this is just a guess static QMap< quint64, quint16 > List21e(); static QMap< quint64, quint16 > List22e(); //* there are no games ive seen that contain this update. this is just a guess static QMap< quint64, quint16 > List30e(); diff --git a/WiiQt/uidmap.cpp b/WiiQt/uidmap.cpp index 350776c..a8feaf1 100644 --- a/WiiQt/uidmap.cpp +++ b/WiiQt/uidmap.cpp @@ -106,7 +106,7 @@ quint32 UIDmap::GetUid( quint64 id, bool autoCreate ) return qFromBigEndian( uid ); } -void UIDmap::CreateNew( bool addFactorySetupDiscs ) +void UIDmap::CreateNew( quint8 addFactorySetupDiscs ) { quint64 tid; quint32 uid; @@ -125,9 +125,10 @@ void UIDmap::CreateNew( bool addFactorySetupDiscs ) data = stuff; return; } + quint8 reg = addFactorySetupDiscs; //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++ ) + for( quint32 i = 1; i < 0x14; i++ ) { switch( i ) { @@ -138,45 +139,18 @@ void UIDmap::CreateNew( bool addFactorySetupDiscs ) 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; + case 0x8:tid = qFromBigEndian( 0x10000000full ); break; + case 0x9:tid = qFromBigEndian( 0x0001000030303032ull ); break; + case 0xa:tid = qFromBigEndian( 0x10000000bull ); break; + case 0xb:tid = qFromBigEndian( 0x10000000cull ); break; + case 0xc:tid = qFromBigEndian( 0x10000000dull ); break; + case 0xd:tid = qFromBigEndian( 0x0001000248414341ull ); break; + case 0xe:tid = qFromBigEndian( 0x0001000248414141ull ); break; + case 0xf:tid = qFromBigEndian( 0x0001000248414641ull ); break; + case 0x10:tid = qFromBigEndian( 0x0001000248414241ull ); break; + case 0x11:tid = qFromBigEndian( 0x0001000248414741ull ); break; + case 0x12:tid = qFromBigEndian( (quint64)( 0x0001000848414b00ull | reg ) ); break; + case 0x13:tid = qFromBigEndian( 0x0001000031323200ull ); break; default: qWarning() << "oops" << hex << i; return; diff --git a/WiiQt/uidmap.h b/WiiQt/uidmap.h index 8147409..d153b7c 100644 --- a/WiiQt/uidmap.h +++ b/WiiQt/uidmap.h @@ -20,9 +20,10 @@ public: quint32 GetUid( quint64 tid, bool autoCreate = true ); //creates a new uid.sys with the system menu entry. - //if addFactorySetupDiscs is true, it will add some entries for the setup discs used in the wii factory + //if addFactorySetupDiscs is anything other than 0, it will add some entries for the setup discs used in the wii factory + // addFactorySetupDiscs should be the region code: 0x45=E, 0x50=P... // ( serve no purpose other than to just exist ) - void CreateNew( bool addFactorySetupDiscs = false ); + void CreateNew( quint8 addFactorySetupDiscs = 0 ); //get th entire uid.sys data back in a state ready for writing to a nand const QByteArray Data(){ return data; } diff --git a/ohneschwanzenegger/mainwindow.cpp b/ohneschwanzenegger/mainwindow.cpp index 0677763..74cfd91 100644 --- a/ohneschwanzenegger/mainwindow.cpp +++ b/ohneschwanzenegger/mainwindow.cpp @@ -359,6 +359,18 @@ void MainWindow::on_actionNew_nand_from_keys_triggered() InitNand( path ); ui->lineEdit_nandPath->setText( path ); + //these titles should be in order ( not really functional, but to emulate better how the wii comes from the factory ) + if( !nand.CreateEntry( "/title/00000001", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) + || !nand.CreateEntry( "/title/00000001/00000004", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) + || !nand.CreateEntry( "/title/00000001/00000009", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) + || !nand.CreateEntry( "/title/00000001/00000002", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) + || !nand.CreateEntry( "/title/00000001/00000100", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) + || !nand.CreateEntry( "/title/00000001/00000101", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) ) + { + ShowMessage( "Error creating title subdirs<\b>" ); + return; + } + //add some factory test logs and whatnot quint32 _uid = uid.GetUid( NAND_TEST_OWNER, true ); if( !nand.CreateEntry( "/shared2/test", _uid, NAND_TEST_GROUP, NAND_DIR, NAND_RW, NAND_RW, NAND_RW ) @@ -409,7 +421,7 @@ bool MainWindow::InitNand( const QString &path ) QTreeWidgetItem *it = ItemFromPath( "/sys/uid.sys" ); if( !it ) { - uid.CreateNew( true ); + uid.CreateNew();//dont add any UID besides the system menu since we dont know what region it will be if( !nand.CreateEntry( "/sys/uid.sys", 0, 0, NAND_FILE, NAND_RW, NAND_RW, 0 ) ) { ShowMessage( "Error creating new uid.sys" ); @@ -640,11 +652,11 @@ bool MainWindow::InstallNUSItem( NusJob job ) if( !CreateIfNeeded( "/title/" + upper + "/" + lower, 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ ) ) { qWarning() << "can't create title+upper+lower folder";goto error;} - if( !CreateIfNeeded( "/title/" + upper + "/" + lower + "/content", 0, 0, NAND_DIR, NAND_RW, NAND_RW, 0 ) ) - { qWarning() << "can't create content folder";goto error;} + if( !CreateIfNeeded( "/title/" + upper + "/" + lower + "/data", _uid, _gid, NAND_DIR, NAND_RW, 0, 0 ) ) + { qWarning() << "can't create data folder";goto error;} - if( !CreateIfNeeded( "/title/" + upper + "/" + lower + "/data", _uid, _gid, NAND_DIR, NAND_RW, 0, 0 ) ) - { qWarning() << "can't create data folder";goto error;} + if( !CreateIfNeeded( "/title/" + upper + "/" + lower + "/content", 0, 0, NAND_DIR, NAND_RW, NAND_RW, 0 ) ) + { qWarning() << "can't create content folder";goto error;} //delete old tmd/.apps and whatever else in the content folder content = ItemFromPath( "/title/" + upper + "/" + lower + "/content" ); diff --git a/ohneschwanzenegger/newnandbin.cpp b/ohneschwanzenegger/newnandbin.cpp index 7f58fe9..e71db11 100644 --- a/ohneschwanzenegger/newnandbin.cpp +++ b/ohneschwanzenegger/newnandbin.cpp @@ -1,5 +1,6 @@ #include "newnandbin.h" #include "ui_newnandbin.h" +#include "../WiiQt/uidmap.h" #include "../WiiQt/tools.h" NewNandBin::NewNandBin( QWidget *parent, QList badBlocks ) : QDialog(parent), ui(new Ui::NewNandBin), nand( this ) @@ -102,9 +103,59 @@ bool NewNandBin::CreateDefaultEntries() { qWarning() << "NewNandBin::on_buttonBox_accepted -> error creating cert in the new nand"; QMessageBox::warning( this, tr( "Error" ), \ - tr( "Can't create cert.sys folders in the new nand." ) ); + tr( "Can't create cert.sys in the new nand." ) ); return false; } + //create uid.sys + switch( ui->comboBox_uid->currentIndex() ) + { + case 0: + uidSys.clear(); + break; + case 1://jap + { + UIDmap uid; + uid.CreateNew( 0x4a ); + uidSys = uid.Data(); + } + break; + case 2://usa + { + UIDmap uid; + uid.CreateNew( 0x45 ); + uidSys = uid.Data(); + } + break; + case 3://eur + { + UIDmap uid; + uid.CreateNew( 0x50 ); + uidSys = uid.Data(); + } + break; + case 4://kor + { + UIDmap uid; + uid.CreateNew( 0x4b ); + uidSys = uid.Data(); + } + break; + default: + break; + } + if( !uidSys.isEmpty() ) + { + //hexdump( uidSys ); + quint16 fd = nand.CreateEntry( "/sys/uid.sys", 0, 0, NAND_FILE, NAND_RW, NAND_RW, 0 ); + if( !fd || !nand.SetData( fd, uidSys ) ) + { + qWarning() << "NewNandBin::on_buttonBox_accepted -> error creating cert in the new nand"; + QMessageBox::warning( this, tr( "Error" ), \ + tr( "Can't create uid.sys in the new nand." ) ); + return false; + } + } + //commit changes to metadata if( !nand.WriteMetaData() ) { @@ -268,12 +319,45 @@ void NewNandBin::on_pushButton_oldNand_clicked() quint16 block = ( i / 8 ); badBlacks << block; QString txt = QString( "%1" ).arg( block ); - qDebug() << "bad cluster" << hex << i << block << txt; + //qDebug() << "bad cluster" << hex << i << block << txt; //if( ui->listWidget_badBlocks->findItems( txt, Qt::MatchExactly ).isEmpty() )//just in case, but this should always be true ui->listWidget_badBlocks->addItem( txt ); } } + uidSys = old.GetData( "/sys/uid.sys" ); + if( !uidSys.isEmpty() ) + { + uidSys = GetCleanUid( uidSys ); + ui->comboBox_uid->setCurrentIndex( 5 ); + //hexdump( uidSys ); + } ui->lineEdit_boot->setText( tr( "" ) ); ui->lineEdit_keys->setText( tr( "" ) ); - +} + +//remove all entries of a uid.sys from after the user has started doing stuff +QByteArray NewNandBin::GetCleanUid( QByteArray old ) +{ + QBuffer buf( &old ); + buf.open( QIODevice::ReadWrite ); + + quint64 tid; + quint16 titles = 0; + quint32 cnt = old.size() / 12; + for( quint32 i = 0; i < cnt; i++ ) + { + buf.seek( i * 12 ); + buf.read( (char*)&tid, 8 ); + tid = qFromBigEndian( tid ); + quint32 upper = ( ( tid >> 32 ) & 0xffffffff ); + quint32 lower = ( tid & 0xffffffff ); + //qDebug() << QString( "%1" ).arg( tid, 16, 16, QChar( '0' ) ) << hex << upper << lower << ( ( lower >> 24 ) & 0xff ) << ( lower & 0xffff00 ); + if( ( upper == 0x10001 && ( ( lower >> 24 ) & 0xff ) != 0x48 ) || //a channel, not starting with 'H' + ( upper == 0x10000 && ( ( lower & 0xffff00 ) == 0x555000 ) ) ) //a disc update partition + break; + + titles++; + } + buf.close(); + return old.left( 12 * titles ); } diff --git a/ohneschwanzenegger/newnandbin.h b/ohneschwanzenegger/newnandbin.h index 185b730..48253b9 100644 --- a/ohneschwanzenegger/newnandbin.h +++ b/ohneschwanzenegger/newnandbin.h @@ -29,8 +29,10 @@ private: QByteArray boots; QByteArray keys; + QByteArray uidSys; bool CreateDefaultEntries(); + QByteArray GetCleanUid( QByteArray old ); private slots: void on_pushButton_oldNand_clicked(); diff --git a/ohneschwanzenegger/newnandbin.ui b/ohneschwanzenegger/newnandbin.ui index eef0947..c10d934 100644 --- a/ohneschwanzenegger/newnandbin.ui +++ b/ohneschwanzenegger/newnandbin.ui @@ -6,15 +6,15 @@ 0 0 - 427 - 290 + 446 + 269 New Nand - + @@ -60,7 +60,7 @@ - + Bad Blocks @@ -178,20 +178,82 @@ - - - - Qt::Horizontal - - - - 149 - 20 - - - + + + + + + + 150 + 69 + + + + Existing Nand... + + + + + + + Qt::Horizontal + + + + 149 + 20 + + + + + - + + + + + + uid.sys + + + + + + + + None + + + + + Jap + + + + + Usa + + + + + Eur + + + + + Kor + + + + + From Old Nand + + + + + + + Qt::Horizontal @@ -201,19 +263,6 @@ - - - - - 150 - 69 - - - - Existing Nand... - - -