#include <quazip/quazip.h>
#include <quazip/quazipfile.h>
+#include <QTemporaryFile>
+
InformationManager::InformationManager()
: logger(log4cxx::Logger::getLogger("InformationManager"))
{}
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);
#include <map>
#include "disassembler/Disassembler.hxx"
+#include <QTemporaryFile>
class Function;
class BasicBlock;
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)
std::map<uint64_t, Function*> functions;
std::map<uint64_t, BasicBlock*> blocks;
std::string filename;
+ std::unique_ptr<QTemporaryFile> tmpfile;
log4cxx::LoggerPtr logger;
};
: 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,
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
+ fileMenu->addAction(loadAction);
fileMenu->addAction(saveAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
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&)));
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) {