diff --git a/include/resourceexplorer.h b/include/resourceexplorer.h index ef6df9e..aed06c2 100644 --- a/include/resourceexplorer.h +++ b/include/resourceexplorer.h @@ -19,6 +19,10 @@ public: explicit ResourceExplorer(QWidget *parent = nullptr); ~ResourceExplorer(); +private slots: + void extractButtonPressed(); + void itemSelected(QTreeWidgetItem*); + private: struct MemoryMap { const unsigned char* begin; @@ -46,6 +50,7 @@ private: std::vector children; bool isDir() const; + bool isCompressed() const; }; using data = const unsigned char*; diff --git a/qtdebugger.pro b/qtdebugger.pro index 1874dc0..b8122ad 100644 --- a/qtdebugger.pro +++ b/qtdebugger.pro @@ -33,7 +33,7 @@ SOURCES += \ src/resourceexplorer.cpp HEADERS += \ - include/injector.cpp \ + include/injector.h \ include/qtdebugger.h \ include/resourceexplorer.h diff --git a/src/main.c b/src/main.c index de3b96f..ed0d21e 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ int main(int argc, char** argv) { setenv("LD_PRELOAD", "/usr/local/lib/libqtdebugger.so", 1); // should never return - execv(argv[1], argv+1); + execvp(argv[1], argv+1); fprintf(stderr, "exec failed: %s\n", strerror(errno)); return 2; diff --git a/src/resourceexplorer.cpp b/src/resourceexplorer.cpp index 4dd5d87..1aec571 100644 --- a/src/resourceexplorer.cpp +++ b/src/resourceexplorer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,38 @@ ResourceExplorer::~ResourceExplorer() { delete this->ui; } +void ResourceExplorer::extractButtonPressed() { + QTreeWidgetItem* item = this->ui->treeWidget->currentItem(); + if ( !item ) return; + + ResourceNode* node = (ResourceNode*) item->data(0, Qt::UserRole).toULongLong(); + if ( !node ) return; + + QString saveFile = QFileDialog::getSaveFileName(this, "Extract File"); + + if ( saveFile.isEmpty() ) return; + + QFile fileOut( saveFile ); + if( !fileOut.open( QIODevice::WriteOnly | QIODevice::Truncate )) return; + + QByteArray data = QByteArray::fromRawData( (const char*) node->start, node->size ); + fileOut.write(data); +} + +void ResourceExplorer::itemSelected(QTreeWidgetItem* newItem) { + if ( !newItem ) return; + + ResourceNode* node = (ResourceNode*) newItem->data(0, Qt::UserRole).toULongLong(); + + if ( node ) { + if ( !node->isDir() && !node->isCompressed() ) { + this->ui->extractButton->setEnabled( true ); + return; + } + } + this->ui->extractButton->setEnabled( false ); +} + ResourceExplorer::ResourceNode::~ResourceNode() { for ( ResourceNode* rn : this->children ) { delete rn; @@ -69,8 +102,13 @@ bool ResourceExplorer::ResourceNode::isDir() const { return this->flags & ResourceFlags::Directory; } +bool ResourceExplorer::ResourceNode::isCompressed() const { + return this->flags & ResourceFlags::Compressed; +} + void ResourceExplorer::rebuild() { this->ui->treeWidget->clear(); + this->ui->extractButton->setEnabled(false); if ( !registeredResources || registeredResources->empty() ) { QTreeWidgetItem* resItem = new QTreeWidgetItem(); @@ -253,6 +291,9 @@ QTreeWidgetItem* ResourceExplorer::resourceNodeToItem( ResourceNode* node, const item->addChild( sub ); } + QVariant ptrVariant( (qulonglong) node ); + item->setData(0, Qt::UserRole, ptrVariant); + return item; } diff --git a/ui/resourceexplorer.ui b/ui/resourceexplorer.ui index e651b8e..f09aa48 100644 --- a/ui/resourceexplorer.ui +++ b/ui/resourceexplorer.ui @@ -43,6 +43,16 @@ + + + + false + + + Extract + + + @@ -58,5 +68,42 @@ - + + + extractButton + clicked() + ResourceExplorer + extractButtonPressed() + + + 421 + 550 + + + 450 + 646 + + + + + treeWidget + currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + ResourceExplorer + itemSelected(QTreeWidgetItem*) + + + 641 + 387 + + + 842 + 410 + + + + + + extractButtonPressed() + itemSelected(QTreeWidgetItem*) +