execute_process(COMMAND ${LLVM_CONFIG} --libs OUTPUT_VARIABLE LLVM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE LLVM_SYSTEM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
-string(REPLACE -O2 '' LLVM_CFLAGS ${LLVM_CFLAGS})
+string(REPLACE -O2 "" LLVM_CFLAGS ${LLVM_CFLAGS})
+string(REPLACE -fno-exceptions "" LLVM_CFLAGS ${LLVM_CFLAGS})
separate_arguments(LLVM_CFLAGS)
add_definitions(${LLVM_CFLAGS})
SET(frida_SOURCES
src/main.cxx
+ src/core/InformationManager.cxx
src/gui/Mainwindow.cxx
src/gui/widgets/BasicBlockWidget.cxx
src/gui/widgets/CFGScene.cxx
)
SET(frida_HEADERS
src/include_llvm.hxx
+ src/core/InformationManager.hxx
src/gui/qt.hxx
src/gui/Mainwindow.hxx
src/gui/widgets/BasicBlockWidget.hxx
--- /dev/null
+#include "InformationManager.hxx"
+#include "disassembler/llvm/LLVMDisassembler.hxx"
+
+#include <iostream>
+
+void InformationManager::reset(const std::string& filename) {
+ disassembler.reset(new LLVMDisassembler(filename, this));
+ disassembler.get()->start();
+}
--- /dev/null
+#ifndef INCLUDE__InformationManager_hxx
+#define INCLUDE__InformationManager_hxx
+
+#include <boost/signals2.hpp>
+#include <functional>
+
+class Disassembler;
+class Function;
+
+class InformationManager {
+public:
+ boost::signals2::connection
+ connect_new_function_signal(std::function<void(Function*)> f) {
+ return new_function_signal.connect(f);
+ }
+
+ void signal_new_function(Function* f) {
+ new_function_signal(f);
+ }
+
+ boost::signals2::connection
+ connect_reset_signal(std::function<void ()> f) {
+ return reset_signal.connect(f);
+ }
+
+ // boost::signals2::connection
+ // connect_information_added_signal(uint64_t begin, uint64_t end,
+ // std::function<void (uint64_t)>) {
+
+ // }
+
+ Disassembler* getDisassembler() {
+ return disassembler.get();
+ }
+
+ void reset(const std::string& filename);
+private:
+ boost::signals2::signal<void ()> reset_signal;
+ boost::signals2::signal<void (Function*)> new_function_signal;
+ std::unique_ptr<Disassembler> disassembler;
+};
+
+#endif /* INCLUDE__InformationManager_hxx */
-#ifndef INCLUDE__Disassembler_hxx
+ #ifndef INCLUDE__Disassembler_hxx
#define INCLUDE__Disassembler_hxx
#include <string>
#include "disassembler/BasicBlock.hxx"
#include "disassembler/Function.hxx"
-
+#include "core/InformationManager.hxx"
class Disassembler {
public:
- Disassembler(const std::string& filename) {}
+ Disassembler(const std::string& filename, InformationManager* manager) {}
virtual ~Disassembler() {}
- void getSymbols();
- uint64_t entryAddress();
+ virtual void start() = 0;
+ virtual void getSymbols() = 0;
+ virtual uint64_t entryAddress() = 0;
virtual BasicBlock * getBasicBlock(uint64_t address) = 0;
virtual void forEachFunction(std::function<void (uint64_t, Function*)> callback) = 0;
* ist sondern z.B. einfach nur Instruktionen oder ein Bootsektor oder
* foo
*/
-LLVMDisassembler::LLVMDisassembler(const std::string& filename)
- : Disassembler(filename)
+LLVMDisassembler::LLVMDisassembler(const std::string& filename,
+ InformationManager* manager)
+ : Disassembler(filename, manager)
, logger(log4cxx::Logger::getLogger("LLVMDisassembler"))
, triple("unknown-unknown-unknown")
+ , manager(manager)
{
LOG4CXX_DEBUG(logger, "Handling file" << filename);
auto result = createBinary(filename);
std::unique_ptr<MCObjectDisassembler> OD(
new MCObjectDisassembler(*o, *DisAsm, *MIA));
Mod.reset(OD->buildModule(false));
+}
+void LLVMDisassembler::start() {
readSymbols();
readSections();
disassemble();
}
}
LOG4CXX_DEBUG(logger, "Finished function " << function->getName());
+ manager->signal_new_function(function);
}
void LLVMDisassembler::disassemble() {
class LLVMDisassembler
- : public Disassembler {
+ : public Disassembler {
public:
- LLVMDisassembler(const std::string& filename);
- virtual ~LLVMDisassembler();
+ LLVMDisassembler(const std::string& filename, InformationManager* manager);
+ virtual ~LLVMDisassembler();
- void getSymbols();
- uint64_t entryAddress();
+ void start();
+ void getSymbols() {}
+ uint64_t entryAddress() {}
void forEachFunction(std::function<void (uint64_t, Function*)> callback);
void printEachInstruction(uint64_t start, uint64_t end,
return blocks[address];
}
- Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
+ Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
protected:
- bool isFunctionCall(uint64_t address) {return false;}
- bool isJump(uint64_t address) {return false;}
+ bool isFunctionCall(uint64_t address) {return false;}
+ bool isJump(uint64_t address) {return false;}
private:
- // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
- void disassembleFunction(LLVMFunction* function);
- void splitBlocks();
- void disassemble();
+ // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
+ void disassembleFunction(LLVMFunction* function);
+ void splitBlocks();
+ void disassemble();
void readSymbols();
void readSections();
- log4cxx::LoggerPtr logger;
+ log4cxx::LoggerPtr logger;
std::map<uint64_t, LLVMBasicBlock*> blocks;
std::map<uint64_t, LLVMFunction*> functions;
- llvm::Triple triple;
- std::shared_ptr<llvm::object::Binary> binary;
-
-
- const llvm::Target * target;
- llvm::object::ObjectFile * o;
-
- std::unique_ptr<const llvm::MCRegisterInfo> MRI;
- std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
- std::unique_ptr<llvm::MCModule> Mod;
- std::unique_ptr<llvm::MCInstPrinter> IP;
- std::unique_ptr<llvm::MCDisassembler> DisAsm;
- std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
- std::unique_ptr<llvm::MCContext> Ctx;
- std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
- std::unique_ptr<const llvm::MCSubtargetInfo> STI;
- std::unique_ptr<const llvm::MCInstrInfo> MII;
- std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
- std::unique_ptr<llvm::MCSymbolizer> Symzer;
-
- std::map<std::string, llvm::object::SectionRef> sections;
- std::map<std::string, llvm::object::SymbolRef> symbols;
+ llvm::Triple triple;
+ std::shared_ptr<llvm::object::Binary> binary;
+
+ const llvm::Target * target;
+ llvm::object::ObjectFile * o;
+
+ std::unique_ptr<const llvm::MCRegisterInfo> MRI;
+ std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
+ std::unique_ptr<llvm::MCModule> Mod;
+ std::unique_ptr<llvm::MCInstPrinter> IP;
+ std::unique_ptr<llvm::MCDisassembler> DisAsm;
+ std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
+ std::unique_ptr<llvm::MCContext> Ctx;
+ std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
+ std::unique_ptr<const llvm::MCSubtargetInfo> STI;
+ std::unique_ptr<const llvm::MCInstrInfo> MII;
+ std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
+ std::unique_ptr<llvm::MCSymbolizer> Symzer;
+
+ std::map<std::string, llvm::object::SectionRef> sections;
+ std::map<std::string, llvm::object::SymbolRef> symbols;
+ InformationManager * manager;
};
#endif
#include "Mainwindow.hxx"
#include "qt.hxx"
#include "disassembler/llvm/LLVMDisassembler.hxx"
+
#include "widgets/CFGScene.hxx"
#include <iostream>
#include <QtGui>
-Mainwindow::Mainwindow(const std::string& filename)
-{
- openAction = new QAction(tr("&Open"), this);
- // saveAction = new QAction(tr("&Save"), this);
- exitAction = new QAction(tr("E&xit"), this);
-
- connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
- // connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
- connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
-
- fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(openAction);
- // fileMenu->addAction(saveAction);
- fileMenu->addSeparator();
- fileMenu->addAction(exitAction);
-
- scripting = new ScriptingDock(tr("Scripting"), this);
- scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
- addDockWidget(Qt::BottomDockWidgetArea, scripting);
-
- listWidget = new QListWidget();
- stackedWidget = new QStackedWidget();
- dockWidget = new QDockWidget(tr("Functions"), this);
- dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
- Qt::RightDockWidgetArea);
- dockWidget->setWidget(listWidget);
- addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
- setCentralWidget(stackedWidget);
-
- connect(listWidget, SIGNAL(currentRowChanged(int)),
- stackedWidget, SLOT(setCurrentIndex(int)));
-
- setWindowTitle(tr("FRIDA"));
-
- openBinary(filename);
+namespace {
+ BasicBlockWidget *
+ local__add_basic_block(BasicBlock * block, Disassembler * dis,
+ std::map<uint64_t, BasicBlockWidget*>& known_blocks,
+ CFGScene * scene, uint64_t starty, uint64_t startx);
+}
+
+Mainwindow::Mainwindow(InformationManager* mgr)
+ : manager(mgr) {
+ openAction = new QAction(tr("&Open"), this);
+ // saveAction = new QAction(tr("&Save"), this);
+ exitAction = new QAction(tr("E&xit"), this);
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
+ // connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAction);
+ // fileMenu->addAction(saveAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAction);
+
+ scripting = new ScriptingDock(tr("Scripting"), this);
+ scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
+ addDockWidget(Qt::BottomDockWidgetArea, scripting);
+
+ listWidget = new QListWidget();
+ stackedWidget = new QStackedWidget();
+ dockWidget = new QDockWidget(tr("Functions"), this);
+ dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
+ Qt::RightDockWidgetArea);
+ dockWidget->setWidget(listWidget);
+ addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
+ setCentralWidget(stackedWidget);
+
+ connect(listWidget, SIGNAL(currentRowChanged(int)),
+ stackedWidget, SLOT(setCurrentIndex(int)));
+
+ setWindowTitle(tr("FRIDA"));
+
+ mgr->connect_new_function_signal([&] (Function* fun) {addFunction(fun);});
}
void Mainwindow::quit()
{
- QMessageBox messageBox;
- messageBox.setWindowTitle(tr("Notepad"));
- messageBox.setText(tr("Do you really want to quit?"));
- messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- messageBox.setDefaultButton(QMessageBox::No);
- if (messageBox.exec() == QMessageBox::Yes)
- qApp->quit();
+ QMessageBox messageBox;
+ messageBox.setWindowTitle(tr("Notepad"));
+ messageBox.setText(tr("Do you really want to quit?"));
+ messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ messageBox.setDefaultButton(QMessageBox::No);
+ if (messageBox.exec() == QMessageBox::Yes)
+ qApp->quit();
}
void Mainwindow::open() {
- QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
- tr("Binaries (*)"));
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
+ tr("Binaries (*)"));
- openBinary(fileName.toStdString());
+ manager->reset(fileName.toStdString());
}
-void Mainwindow::openBinary(const std::string& filename) {
- if (filename != "") {
- disassembler.reset(new LLVMDisassembler(filename));
- disassembler->forEachFunction([&](uint64_t address, Function* fun) {
- populateSymbolInformation(fun);
- });
- }
+void Mainwindow::addFunction(Function* fun) {
+ if (functions.find(fun) != functions.end())
+ return;
+
+ functions.insert(fun);
+
+ QTabWidget * w = new QTabWidget();
+
+ // CFG
+ CFGScene * scene = new CFGScene;
+
+ Disassembler * dis = manager->getDisassembler();
+ std::cerr << dis << std::endl;
+
+ BasicBlock * block = dis->getBasicBlock(fun->getStartAddress());
+
+ local__add_basic_block(block, manager->getDisassembler(), blocks, scene, block->getStartAddress(), 100);
+
+ QGraphicsView * view = new QGraphicsView(scene);
+ w->addTab(view, "CFG");
+
+ // Listing
+ QTableWidget * t = new QTableWidget();
+ t->setColumnCount(3);
+ t->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
+
+ w->addTab(t, "Listing");
+
+ listWidget->addItem(fun->getName().c_str());
+ stackedWidget->addWidget(w);
}
namespace {
BasicBlockWidget *
local__add_basic_block(BasicBlock * block, Disassembler * dis,
- std::map<uint64_t, BasicBlockWidget*>& known_blocks,
- CFGScene * scene, uint64_t starty, uint64_t startx) {
+ std::map<uint64_t, BasicBlockWidget*>& known_blocks,
+ CFGScene * scene, uint64_t starty, uint64_t startx) {
decltype(known_blocks.begin()) old;
if ((old = known_blocks.find(block->getStartAddress())) != known_blocks.end())
return widget;
}
}
-
-void Mainwindow::populateSymbolInformation(Function* fun) {
- QTabWidget * w = new QTabWidget();
-
- // CFG
- CFGScene * scene = new CFGScene;
-
- BasicBlock * block = disassembler->getBasicBlock(fun->getStartAddress());
-
- local__add_basic_block(block, disassembler.get(), blocks, scene, block->getStartAddress(), 100);
-
- QGraphicsView * view = new QGraphicsView(scene);
- w->addTab(view, "CFG");
-
- // Listing
- QTableWidget * t = new QTableWidget();
- t->setColumnCount(3);
- t->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
-
- w->addTab(t, "Listing");
-
- listWidget->addItem(fun->getName().c_str());
- stackedWidget->addWidget(w);
-}
#include <memory>
#include <map>
+#include <set>
#include <QTextEdit>
#include <QPushButton>
#include <QMainWindow>
#include "disassembler/Disassembler.hxx"
#include "widgets/BasicBlockWidget.hxx"
#include "widgets/ScriptingDock.hxx"
+#include "core/InformationManager.hxx"
class Mainwindow : public QMainWindow {
- Q_OBJECT
+ Q_OBJECT
public:
- Mainwindow(const std::string& filename = "");
+ Mainwindow(InformationManager* mgr);
private:
- void openBinary(const std::string& filename);
+ void addFunction(Function* fun);
- void populateSymbolInformation(Function * fun);
+ QTextEdit *textEdit;
+ QPushButton *quitButton;
+ QMenu *fileMenu;
- QTextEdit *textEdit;
- QPushButton *quitButton;
- QMenu *fileMenu;
+ QTabWidget * tabwidget;
+ QListWidget * listWidget;
+ QStackedWidget * stackedWidget;
+ QDockWidget * dockWidget;
+ ScriptingDock * scripting;
- QTabWidget * tabwidget;
- QListWidget * listWidget;
- QStackedWidget * stackedWidget;
- QDockWidget * dockWidget;
- ScriptingDock * scripting;
+ QAction *exitAction;
+ QAction *openAction;
- QAction *exitAction;
- QAction *openAction;
-
- std::shared_ptr<Disassembler> disassembler;
std::map<uint64_t, BasicBlockWidget*> blocks;
+ std::set<Function*> functions;
+ InformationManager* manager;
private Q_SLOTS:
- void quit();
- void open();
+ void quit();
+ void open();
};
#endif /* INCLUDE__Mainwindow_hxx_ */
#include "log4cxx/basicconfigurator.h"
#include "gui/Mainwindow.hxx"
+#include "core/InformationManager.hxx"
+#include "disassembler/llvm/LLVMDisassembler.hxx"
using std::cout;
using std::cin;
parser.addVersionOption();
parser.addPositionalArgument("filename", QCoreApplication::translate("main", "File to disassemble."));
-
parser.process(app);
#endif
+ InformationManager iman;
+
LOG4CXX_DEBUG(_logger, "Initializing LLVM");
llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargetMCs();
}
#endif
- Mainwindow m(filename);
+ Mainwindow m(&iman);
m.show();
+ iman.reset(filename);
return app.exec();
}