]> git.siccegge.de Git - frida/frida.git/commitdiff
Finish archive loading
authorChristoph Egger <Christoph.Egger@fau.de>
Thu, 5 Mar 2015 13:39:52 +0000 (14:39 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Thu, 5 Mar 2015 13:39:52 +0000 (14:39 +0100)
Using the deserializers and adding the necessary gui-foo

src/core/InformationManager.cxx
src/core/InformationManager.hxx
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx

index 73ea5ef1cda9bfdb61fda0fe59e807ed7d11d524..fd0715b851adfe927601fe50aa0bc5ef9e552485 100644 (file)
@@ -8,6 +8,8 @@
 #include <quazip/quazip.h>
 #include <quazip/quazipfile.h>
 
+#include <QTemporaryFile>
+
 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);
index 2e9358c9afdd05301d901241828b797e0877acc8..557816877ec9ded8804bd0f88118191818573062 100644 (file)
@@ -8,6 +8,7 @@
 #include <map>
 
 #include "disassembler/Disassembler.hxx"
+#include <QTemporaryFile>
 
 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<uint64_t, Function*> functions;
        std::map<uint64_t, BasicBlock*> blocks;
        std::string filename;
+       std::unique_ptr<QTemporaryFile> tmpfile;
 
        log4cxx::LoggerPtr logger;
 };
index 625e7acad7d99ae890ee650615b4600f86032b51..654dc16aafd6f7ad386b7840a15f155ba0b84531 100644 (file)
@@ -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) {
index 3a2e10d3587de8980c0db8a843f3eaf5f7fc9be4..f89f3ce140dfb02cba3269eccf47f82954f89ce2 100644 (file)
@@ -45,6 +45,7 @@ private:
 
        QAction *exitAction;
        QAction *openAction;
+       QAction *loadAction;
        QAction *saveAction;
 
        std::map<uint64_t, BasicBlockWidget*> 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&);