From f3a965524eae344fbd25ba486e9fa32e1262fcc4 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Fri, 23 May 2014 18:20:38 +0200 Subject: [PATCH] Allow opening of binary via comman argument --- src/gui/Mainwindow.cxx | 12 +++++++++--- src/gui/Mainwindow.hxx | 4 +++- src/main.cxx | 18 +++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 061734a..fd0c245 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -8,7 +8,7 @@ #include -Mainwindow::Mainwindow() +Mainwindow::Mainwindow(const std::string& filename) { openAction = new QAction(tr("&Open"), this); // saveAction = new QAction(tr("&Save"), this); @@ -37,6 +37,8 @@ Mainwindow::Mainwindow() stackedWidget, SLOT(setCurrentIndex(int))); setWindowTitle(tr("Notepad")); + + openBinary(filename); } void Mainwindow::quit() @@ -54,8 +56,12 @@ void Mainwindow::open() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Binaries (*)")); - if (fileName != "") { - disassembler.reset(new LLVMDisassembler(fileName.toStdString())); + openBinary(fileName.toStdString()); +} + +void Mainwindow::openBinary(const std::string& filename) { + if (filename != "") { + disassembler.reset(new LLVMDisassembler(filename)); // curBin = new Binary(fileName.toStdString()); // std::vector symbols = curBin->getSymbols(); diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index adfe71e..3892ebd 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -10,8 +10,10 @@ class Mainwindow : public QMainWindow { Q_OBJECT public: - Mainwindow(); + Mainwindow(const std::string& filename = ""); private: + void openBinary(const std::string& filename); + void populateSymbolInformation(const std::string& sym); QTextEdit *textEdit; diff --git a/src/main.cxx b/src/main.cxx index 0ce89ab..74d1325 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -21,6 +21,16 @@ int main(int argc, char** argv) log4cxx::BasicConfigurator::configure(); log4cxx::LoggerPtr _logger(log4cxx::Logger::getLogger("main")); + QCommandLineParser parser; + + QApplication::setApplicationName("frida"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("filename", QCoreApplication::translate("main", "File to disassemble.")); + + QApplication app(argc, argv); + parser.process(app); + LOG4CXX_DEBUG(_logger, "Initializing LLVM"); llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetMCs(); @@ -28,14 +38,8 @@ int main(int argc, char** argv) llvm::InitializeAllDisassemblers(); LOG4CXX_DEBUG(_logger, "Initializing Qt"); - QApplication app(argc, argv); - QCommandLineParser parser; - - QApplication::setApplicationName("frida"); - parser.addHelpOption(); - parser.process(app); - Mainwindow m; + Mainwindow m(parser.positionalArguments().at(0).toStdString()); m.show(); return app.exec(); -- 2.39.5