mirror of
https://github.com/martravi/wiiqt.git
synced 2024-11-22 09:09:18 +01:00
* allow reading of old nand.bin for creating a new one
This commit is contained in:
parent
0e671a6764
commit
c3462a3d24
@ -9,7 +9,7 @@ NewNandBin::NewNandBin( QWidget *parent, QList<quint16> badBlocks ) : QDialog(pa
|
||||
foreach( quint16 block, badBlocks )
|
||||
{
|
||||
QString txt = QString( "%1" ).arg( block );
|
||||
if( !ui->listWidget_badBlocks->findItems( txt, Qt::MatchExactly ).isEmpty() )
|
||||
if( ui->listWidget_badBlocks->findItems( txt, Qt::MatchExactly ).isEmpty() )
|
||||
ui->listWidget_badBlocks->addItem( txt );
|
||||
}
|
||||
}
|
||||
@ -79,27 +79,8 @@ void NewNandBin::on_pushButton_bb_rm_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
//ok clicked
|
||||
void NewNandBin::on_buttonBox_accepted()
|
||||
bool NewNandBin::CreateDefaultEntries()
|
||||
{
|
||||
if( ui->lineEdit_keys->text().isEmpty() || ui->lineEdit_boot->text().isEmpty() || ui->lineEdit_dest->text().isEmpty() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error" ), tr( "Required feilds are empty" ) );
|
||||
return;
|
||||
}
|
||||
QByteArray keys = ReadFile( ui->lineEdit_keys->text() );
|
||||
QByteArray boots = ReadFile( ui->lineEdit_boot->text() );
|
||||
if( keys.size() != 0x400 || boots.size() != 0x108000 )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error" ), tr( "The keys or boot1/2 is not correct" ) );
|
||||
return;
|
||||
}
|
||||
if( !nand.CreateNew( ui->lineEdit_dest->text(), keys, boots, BadBlocks() ) )
|
||||
{
|
||||
qDebug() << "error creating nand.bin";
|
||||
return;
|
||||
}
|
||||
//qDebug() << "created nand, trying to add default entries";
|
||||
if( !nand.CreateEntry( "/sys", 0, 0, NAND_DIR, NAND_RW, NAND_RW, 0 )
|
||||
|| !nand.CreateEntry( "/ticket", 0, 0, NAND_DIR, NAND_RW, NAND_RW, 0 )
|
||||
|| !nand.CreateEntry( "/title", 0, 0, NAND_DIR, NAND_RW, NAND_RW, NAND_READ )
|
||||
@ -111,19 +92,61 @@ void NewNandBin::on_buttonBox_accepted()
|
||||
|| !nand.WriteMetaData() )
|
||||
{
|
||||
qWarning() << "NewNandBin::on_buttonBox_accepted -> error creating directories in the new nand";
|
||||
return;
|
||||
QMessageBox::warning( this, tr( "Error" ), \
|
||||
tr( "Can't create base folders in the new nand." ) );
|
||||
return false;
|
||||
}
|
||||
//add cert.sys
|
||||
quint16 handle = nand.CreateEntry( "/sys/cert.sys", 0, 0, NAND_FILE, NAND_RW, NAND_RW, NAND_READ );
|
||||
if( !handle || !nand.SetData( handle, QByteArray( (const char*)&certs_dat, CERTS_DAT_SIZE ) ) )
|
||||
{
|
||||
qWarning() << "NewNandBin::on_buttonBox_accepted -> error creating cert in the new nand";
|
||||
return;
|
||||
QMessageBox::warning( this, tr( "Error" ), \
|
||||
tr( "Can't create cert.sys folders in the new nand." ) );
|
||||
return false;
|
||||
}
|
||||
//commit changes to metadata
|
||||
if( !nand.WriteMetaData() )
|
||||
{
|
||||
qWarning() << "NewNandBin::on_buttonBox_accepted -> error writing metadata";
|
||||
QMessageBox::warning( this, tr( "Error" ), \
|
||||
tr( "Can't write metadata in the new nand." ) );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//ok clicked
|
||||
void NewNandBin::on_buttonBox_accepted()
|
||||
{
|
||||
if( ui->lineEdit_keys->text().isEmpty() || ui->lineEdit_boot->text().isEmpty() || ui->lineEdit_dest->text().isEmpty() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error" ), tr( "Required feilds are empty" ) );
|
||||
return;
|
||||
}
|
||||
if( keys.isEmpty() )
|
||||
keys = ReadFile( ui->lineEdit_keys->text() );
|
||||
if( boots.isEmpty() )
|
||||
boots = ReadFile( ui->lineEdit_boot->text() );
|
||||
if( keys.size() != 0x400 || boots.size() != 0x108000 )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error" ), tr( "The keys or boot1/2 is not correct" ) );
|
||||
keys.clear();
|
||||
boots.clear();
|
||||
return;
|
||||
}
|
||||
if( !nand.CreateNew( ui->lineEdit_dest->text(), keys, boots, BadBlocks() ) )
|
||||
{
|
||||
qDebug() << "error creating nand.bin";
|
||||
keys.clear();
|
||||
boots.clear();
|
||||
return;
|
||||
}
|
||||
//qDebug() << "created nand, trying to add default entries";
|
||||
if( !CreateDefaultEntries() )
|
||||
{
|
||||
keys.clear();
|
||||
boots.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,3 +194,86 @@ void NewNandBin::on_pushButton_badBlockFile_clicked()
|
||||
ui->listWidget_badBlocks->addItem( line );
|
||||
}
|
||||
}
|
||||
|
||||
//read info from existing nand.bin
|
||||
void NewNandBin::on_pushButton_oldNand_clicked()
|
||||
{
|
||||
QString f = QFileDialog::getOpenFileName( this, tr( "Select Old nand.bin" ), dir );
|
||||
if( f.isEmpty() )
|
||||
return;
|
||||
|
||||
|
||||
QFileInfo fi( f );
|
||||
QFile file( fi.absoluteFilePath() );
|
||||
if( !file.exists() || !file.open( QIODevice::ReadOnly ) )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error" ), \
|
||||
tr( "Can't open %1!" ).arg( fi.absoluteFilePath() ) );
|
||||
return;
|
||||
}
|
||||
ui->listWidget_badBlocks->clear();
|
||||
|
||||
switch( fi.size() )
|
||||
{
|
||||
case 0x21000000:// w/ ecc, keys in different file
|
||||
{
|
||||
boots = file.read( 0x108000 );
|
||||
//file.seek();
|
||||
keys = ReadFile( fi.absoluteDir().absoluteFilePath( "keys.bin" ) );
|
||||
|
||||
}
|
||||
break;
|
||||
case 0x21000400:// w/ ecc, keys at end of nand dump
|
||||
{
|
||||
boots = file.read( 0x108000 );
|
||||
file.seek( 0x21000000 );
|
||||
keys = file.read( 0x400 );
|
||||
//keys = ReadFile( fi.absoluteDir().absoluteFilePath( "keys.bin" ) );
|
||||
|
||||
}
|
||||
break;
|
||||
default://unsupported for this
|
||||
QMessageBox::warning( this, tr( "Error" ), tr( "I need a nand dump with ecc to create a new nand from.<br>Accepted sizes are 0x21000000 and 0x21000400." ) );
|
||||
file.close();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
file.close();
|
||||
|
||||
//create nandBin object to get the list of bad blocks
|
||||
NandBin old( this );
|
||||
if( !old.SetPath( fi.absoluteFilePath() ) || !old.InitNand() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error" ), \
|
||||
tr( "Error reading %1." ).arg( fi.absoluteFilePath() ) );
|
||||
keys.clear();
|
||||
boots.clear();
|
||||
return;
|
||||
}
|
||||
QList<quint16> clusters = old.GetFats();
|
||||
QList<quint16> badBlacks;
|
||||
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 );
|
||||
keys.clear();
|
||||
boots.clear();
|
||||
return;
|
||||
}
|
||||
for( quint16 i = 0; i < 0x8000; i += 8 )//first cluster of each block.
|
||||
{
|
||||
//qDebug() << hex << i << clusters.at( i );
|
||||
if( clusters.at( i ) == 0xFFFD )
|
||||
{
|
||||
quint16 block = ( i / 8 );
|
||||
badBlacks << block;
|
||||
QString txt = QString( "%1" ).arg( block );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
ui->lineEdit_boot->setText( tr( "<From old nand>" ) );
|
||||
ui->lineEdit_keys->setText( tr( "<From old nand>" ) );
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,13 @@ private:
|
||||
QString ret;
|
||||
QString dir;
|
||||
|
||||
QByteArray boots;
|
||||
QByteArray keys;
|
||||
|
||||
bool CreateDefaultEntries();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_oldNand_clicked();
|
||||
void on_pushButton_badBlockFile_clicked();
|
||||
void on_buttonBox_accepted();
|
||||
void on_pushButton_bb_rm_clicked();
|
||||
|
@ -14,7 +14,7 @@
|
||||
<string>New Nand</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton_keys">
|
||||
@ -178,7 +178,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -191,7 +191,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -201,6 +201,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton_oldNand">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>69</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Existing Nand...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
Loading…
Reference in New Issue
Block a user