From 11fd69cdfce58707599bf57c07c5a784905e23f6 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Thu, 5 Mar 2015 14:39:52 +0100 Subject: [PATCH 1/1] Finish archive loading Using the deserializers and adding the necessary gui-foo --- src/core/InformationManager.cxx | 43 +++++++++++++++++++++++++++++++-- src/core/InformationManager.hxx | 6 ++++- src/gui/Mainwindow.cxx | 14 +++++++++-- src/gui/Mainwindow.hxx | 2 ++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index 73ea5ef..fd0715b 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -8,6 +8,8 @@ #include #include +#include + InformationManager::InformationManager() : logger(log4cxx::Logger::getLogger("InformationManager")) {} @@ -27,8 +29,45 @@ void InformationManager::reset(const std::string& filename) { disassembler.get()->start(); } -void InformationManager::save(const QString& filename) { - QuaZip zip(filename); +void InformationManager::load(const std::string& filename) { + QuaZip zip(filename.c_str()); + QuaZipFile file(&zip); + QuaZipFileInfo info; + + zip.open(QuaZip::mdUnzip); + tmpfile.reset(new QTemporaryFile()); + + { + LOG4CXX_INFO(logger, "Loading binary from archive"); + zip.setCurrentFile("binary"); + tmpfile->open(); + file.open(QIODevice::ReadOnly); + QByteArray buffer; + while (!file.atEnd()) { + buffer = file.read(4096); + tmpfile->write(buffer); + } + tmpfile->flush(); + file.close(); + disassembler.reset(createLLVMDisassembler(tmpfile->fileName().toStdString(), this)); + } + + for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { + zip.getCurrentFileInfo(&info); + file.open(QIODevice::ReadOnly); + + if(info.name != "binary") { + QXmlStreamReader reader(&file); + assert(QXmlStreamReader::StartDocument == reader.readNext()); + assert(QXmlStreamReader::StartElement == reader.readNext()); + Function * fun = Function::deserialize(reader, this); + } + file.close(); + } +} + +void InformationManager::save(const std::string& filename) { + QuaZip zip(filename.c_str()); zip.open(QuaZip::mdCreate); zip.setComment("FRIDA 0.0"); QuaZipFile outZipFile(&zip); diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index 2e9358c..5578168 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -8,6 +8,7 @@ #include #include "disassembler/Disassembler.hxx" +#include class Function; class BasicBlock; @@ -19,10 +20,12 @@ class RenameFunctionEvent; class InformationManager { public: + InformationManager(); ~InformationManager(); void reset(const std::string& filename); - void save(const QString& filename); + void load(const std::string& filename); + void save(const std::string& filename); void signal_new_function(Function* f); void signal_new_dyn_symbol(const std::string& f) @@ -92,6 +95,7 @@ private: std::map functions; std::map blocks; std::string filename; + std::unique_ptr tmpfile; log4cxx::LoggerPtr logger; }; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 625e7ac..654dc16 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -24,11 +24,14 @@ Mainwindow::Mainwindow(InformationManager* mgr) : manager(mgr) , logger(log4cxx::Logger::getLogger("Mainwindow")) { openAction = new QAction(tr("&Open"), this); + loadAction = new QAction(tr("&Load"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); connect(openAction, &QAction::triggered, this, &Mainwindow::open); + connect(loadAction, &QAction::triggered, + this, &Mainwindow::load); connect(saveAction, &QAction::triggered, this, &Mainwindow::save); connect(exitAction, &QAction::triggered, @@ -36,6 +39,7 @@ Mainwindow::Mainwindow(InformationManager* mgr) fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(openAction); + fileMenu->addAction(loadAction); fileMenu->addAction(saveAction); fileMenu->addSeparator(); fileMenu->addAction(exitAction); @@ -46,6 +50,7 @@ Mainwindow::Mainwindow(InformationManager* mgr) listWidget = new QTreeWidget(); listWidget->setColumnCount(1); + listWidget->setDragDropMode(QAbstractItemView::InternalMove); listWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(listWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showListContextMenu(const QPoint&))); @@ -101,13 +106,18 @@ void Mainwindow::quit() void Mainwindow::open() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Binaries (*)")); - manager->reset(fileName.toStdString()); } +void Mainwindow::load() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", + tr("Frida Archives (*.frida)")); + manager->load(fileName.toStdString()); +} + void Mainwindow::save() { QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Frida Archives (*.frida)")); - manager->save(filename); + manager->save(filename.toStdString()); } void Mainwindow::switchMainPlaneToAddress(uint64_t address) { diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index 3a2e10d..f89f3ce 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -45,6 +45,7 @@ private: QAction *exitAction; QAction *openAction; + QAction *loadAction; QAction *saveAction; std::map blocks; @@ -59,6 +60,7 @@ private: private Q_SLOTS: void quit(); void open(); + void load(); void save(); void switchMainPlane(QTreeWidgetItem* item); void showListContextMenu(const QPoint&); -- 2.39.2