From: Christoph Egger <Christoph.Egger@fau.de>
Date: Thu, 5 Mar 2015 13:39:52 +0000 (+0100)
Subject: Finish archive loading
X-Git-Tag: v0.1~66
X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=11fd69cdfce58707599bf57c07c5a784905e23f6;p=frida%2Ffrida.git

Finish archive loading

Using the deserializers and adding the necessary gui-foo
---

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 <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);
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 <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;
 };
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<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&);