* fix bug in nand extractor that kept on going even if you tried to extract a single file

* add pretty icons to the nand extractor
This commit is contained in:
giantpune@gmail.com 2010-12-08 08:05:23 +00:00
parent f22a0cf4c1
commit 50b8b666d4
4 changed files with 54 additions and 20 deletions

View File

@ -6,6 +6,7 @@ NandBin::NandBin( QObject * parent, const QString &path ) : QObject( parent )
type = -1; type = -1;
fatNames = false; fatNames = false;
root = NULL; root = NULL;
if( !path.isEmpty() ) if( !path.isEmpty() )
SetPath( path ); SetPath( path );
} }
@ -51,7 +52,7 @@ bool NandBin::ExtractToDir( QTreeWidgetItem *item, const QString &path )
emit SendError( tr( "Error converting entry(%1) to a number" ).arg( item->text( 1 ) ) ); emit SendError( tr( "Error converting entry(%1) to a number" ).arg( item->text( 1 ) ) );
return false; return false;
} }
return ExtractFST( entry, path ); return ExtractFST( entry, path, true );//dont bother extracting this item's siblings
return true; return true;
} }
@ -89,10 +90,26 @@ bool NandBin::AddChildren( QTreeWidgetItem *parent, quint16 entry )
text << name << en << size << uid << gid << x3 << mode << attr; text << name << en << size << uid << gid << x3 << mode << attr;
QTreeWidgetItem *child = new QTreeWidgetItem( parent, text ); QTreeWidgetItem *child = new QTreeWidgetItem( parent, text );
child->setTextAlignment( 1, Qt::AlignRight | Qt::AlignVCenter );//align to the right
child->setTextAlignment( 2, Qt::AlignRight | Qt::AlignVCenter );
child->setTextAlignment( 3, Qt::AlignRight | Qt::AlignVCenter );
child->setTextAlignment( 4, Qt::AlignRight | Qt::AlignVCenter );
child->setTextAlignment( 5, Qt::AlignRight | Qt::AlignVCenter );
child->setTextAlignment( 6, Qt::AlignRight | Qt::AlignVCenter );
child->setTextAlignment( 7, Qt::AlignRight | Qt::AlignVCenter );
//try to add subfolder contents to the tree //set some icons
if( !fst.mode && fst.sub != 0xffff && !AddChildren( child, fst.sub ) ) if( fst.mode )
return false; {
child->setIcon( 0, keyIcon );
}
else
{
child->setIcon( 0, groupIcon );
//try to add subfolder contents to the tree
if( fst.sub != 0xffff && !AddChildren( child, fst.sub ) )
return false;
}
return true; return true;
} }
@ -106,7 +123,7 @@ QString NandBin::FstName( fst_t fst )
return ret; return ret;
} }
bool NandBin::ExtractFST( quint16 entry, const QString &path ) bool NandBin::ExtractFST( quint16 entry, const QString &path, bool singleFile )
{ {
//qDebug() << "NandBin::ExtractFST(" << hex << entry << "," << path << ")"; //qDebug() << "NandBin::ExtractFST(" << hex << entry << "," << path << ")";
fst_t fst = GetFST( entry ); fst_t fst = GetFST( entry );
@ -114,7 +131,7 @@ bool NandBin::ExtractFST( quint16 entry, const QString &path )
if( !fst.filename[ 0 ] )//something is amiss, better quit now if( !fst.filename[ 0 ] )//something is amiss, better quit now
return false; return false;
if( fst.sib != 0xffff && !ExtractFST( fst.sib, path ) ) if( !singleFile && fst.sib != 0xffff && !ExtractFST( fst.sib, path ) )
return false; return false;
switch( fst.mode ) switch( fst.mode )
@ -176,7 +193,7 @@ bool NandBin::ExtractFile( fst_t fst, QString parent )
return true; return true;
} }
bool NandBin::InitNand() bool NandBin::InitNand( QIcon dirs, QIcon files )
{ {
type = GetDumpType( f.size() ); type = GetDumpType( f.size() );
if( type < 0 || type > 3 ) if( type < 0 || type > 3 )
@ -197,6 +214,9 @@ bool NandBin::InitNand()
if( root ) if( root )
delete root; delete root;
groupIcon = dirs;
keyIcon = files;
root = new QTreeWidgetItem( QStringList() << nandPath ); root = new QTreeWidgetItem( QStringList() << nandPath );
AddChildren( root, 0 ); AddChildren( root, 0 );
@ -493,12 +513,6 @@ void NandBin::SetFixNamesForFAT( bool fix )
fatNames = fix; fatNames = fix;
} }
/*
* 0xFFFB - last cluster within a chain
* 0xFFFC - reserved cluster
* 0xFFFD - bad block (marked at factory) -- you should always see these in groups of 8 (8 clusters per NAND block)
* 0xFFFE - empty (unused / available) space
*/
void NandBin::ShowInfo() void NandBin::ShowInfo()
{ {
quint16 badBlocks = 0; quint16 badBlocks = 0;

View File

@ -25,7 +25,10 @@ public:
NandBin( QObject * parent = 0, const QString &path = QString() ); NandBin( QObject * parent = 0, const QString &path = QString() );
~NandBin(); ~NandBin();
bool SetPath( const QString &path ); bool SetPath( const QString &path );
bool InitNand();
//try to read the filesystem and create a tree from its contents
//icons given here will be the ones used when asking for that tree
bool InitNand( QIcon dirs = QIcon(), QIcon files = QIcon() );
//get a root item containing children that are actually entries in the nand dump //get a root item containing children that are actually entries in the nand dump
//the root itself is just a container to hold them all and can be deleted once its children are taken //the root itself is just a container to hold them all and can be deleted once its children are taken
@ -56,6 +59,8 @@ private:
int type; int type;
bool fatNames; bool fatNames;
QIcon groupIcon;
QIcon keyIcon;
int GetDumpType( quint64 fileSize ); int GetDumpType( quint64 fileSize );
bool GetKey( int type ); bool GetKey( int type );
@ -68,7 +73,7 @@ private:
QByteArray GetFile( fst_t fst ); QByteArray GetFile( fst_t fst );
QString FstName( fst_t fst ); QString FstName( fst_t fst );
bool ExtractFST( quint16 entry, const QString &path ); bool ExtractFST( quint16 entry, const QString &path, bool singleFile = false );
bool ExtractDir( fst_t fst, QString parent ); bool ExtractDir( fst_t fst, QString parent );
bool ExtractFile( fst_t fst, QString parent ); bool ExtractFile( fst_t fst, QString parent );

View File

@ -8,7 +8,16 @@ NandWindow::NandWindow(QWidget *parent) :
nandBin( this ) nandBin( this )
{ {
ui->setupUi(this); ui->setupUi(this);
ui->treeWidget->header()->resizeSection( 0, 300 );//name //ui->treeWidget->header()->resizeSection( 0, 300 );//name
QFontMetrics fm( fontMetrics() );
ui->treeWidget->header()->resizeSection( 0, fm.width( QString( 22, 'W' ) ) );//name
ui->treeWidget->header()->resizeSection( 1, fm.width( "WWWWW" ) );//entry #
ui->treeWidget->header()->resizeSection( 2, fm.width( "WWWWW" ) );//size
ui->treeWidget->header()->resizeSection( 3, fm.width( "WWWWWWWWWW" ) );//uid
ui->treeWidget->header()->resizeSection( 4, fm.width( "WWWWWWWWWW" ) );//gid
ui->treeWidget->header()->resizeSection( 5, fm.width( "WWWWWWWWWW" ) );//x3
ui->treeWidget->header()->resizeSection( 6, fm.width( "WWWWW" ) );//mode
ui->treeWidget->header()->resizeSection( 7, fm.width( "WWWWW" ) );//attr
connect( &nandBin, SIGNAL( SendError( QString ) ), this, SLOT( GetError( QString ) ) ); connect( &nandBin, SIGNAL( SendError( QString ) ), this, SLOT( GetError( QString ) ) );
@ -85,6 +94,7 @@ void NandWindow::on_treeWidget_customContextMenuRequested( QPoint pos )
} }
} }
//file->open
void NandWindow::on_actionOpen_Nand_triggered() void NandWindow::on_actionOpen_Nand_triggered()
{ {
QString path = QFileDialog::getOpenFileName( this, tr( "Select a Nand to open" ) ); QString path = QFileDialog::getOpenFileName( this, tr( "Select a Nand to open" ) );
@ -98,7 +108,12 @@ void NandWindow::on_actionOpen_Nand_triggered()
return; return;
} }
ui->statusBar->showMessage( "Loading " + path ); ui->statusBar->showMessage( "Loading " + path );
if( !nandBin.InitNand() ) QIcon groupIcon;
QIcon keyIcon;
groupIcon.addPixmap( style()->standardPixmap( QStyle::SP_DirClosedIcon ), QIcon::Normal, QIcon::Off );
groupIcon.addPixmap( style()->standardPixmap( QStyle::SP_DirOpenIcon ), QIcon::Normal, QIcon::On );
keyIcon.addPixmap( style()->standardPixmap( QStyle::SP_FileIcon ) );
if( !nandBin.InitNand( groupIcon, keyIcon ) )
{ {
qDebug() << " error in nandBin.InitNand()"; qDebug() << " error in nandBin.InitNand()";
ui->statusBar->showMessage( "Error reading " + path ); ui->statusBar->showMessage( "Error reading " + path );

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>657</width> <width>901</width>
<height>499</height> <height>472</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -69,7 +69,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>657</width> <width>901</width>
<height>27</height> <height>27</height>
</rect> </rect>
</property> </property>