]>
git.siccegge.de Git - frida/frida.git/blob - src/gui/Mainwindow.cxx
1 #include "Mainwindow.hxx"
3 #include "disassembler/llvm/LLVMDisassembler.hxx"
11 Mainwindow::Mainwindow(const std::string
& filename
)
13 openAction
= new QAction(tr("&Open"), this);
14 // saveAction = new QAction(tr("&Save"), this);
15 exitAction
= new QAction(tr("E&xit"), this);
17 connect(openAction
, SIGNAL(triggered()), this, SLOT(open()));
18 // connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
19 connect(exitAction
, SIGNAL(triggered()), qApp
, SLOT(quit()));
21 fileMenu
= menuBar()->addMenu(tr("&File"));
22 fileMenu
->addAction(openAction
);
23 // fileMenu->addAction(saveAction);
24 fileMenu
->addSeparator();
25 fileMenu
->addAction(exitAction
);
27 listWidget
= new QListWidget();
28 stackedWidget
= new QStackedWidget();
29 dockWidget
= new QDockWidget(tr("Functions"), this);
30 dockWidget
->setAllowedAreas(Qt::LeftDockWidgetArea
|
31 Qt::RightDockWidgetArea
);
32 dockWidget
->setWidget(listWidget
);
33 addDockWidget(Qt::LeftDockWidgetArea
, dockWidget
);
34 setCentralWidget(stackedWidget
);
36 connect(listWidget
, SIGNAL(currentRowChanged(int)),
37 stackedWidget
, SLOT(setCurrentIndex(int)));
39 setWindowTitle(tr("FRIDA"));
44 void Mainwindow::quit()
46 QMessageBox messageBox
;
47 messageBox
.setWindowTitle(tr("Notepad"));
48 messageBox
.setText(tr("Do you really want to quit?"));
49 messageBox
.setStandardButtons(QMessageBox::Yes
| QMessageBox::No
);
50 messageBox
.setDefaultButton(QMessageBox::No
);
51 if (messageBox
.exec() == QMessageBox::Yes
)
55 void Mainwindow::open() {
56 QString fileName
= QFileDialog::getOpenFileName(this, tr("Open File"), "",
59 openBinary(fileName
.toStdString());
62 void Mainwindow::openBinary(const std::string
& filename
) {
64 disassembler
.reset(new LLVMDisassembler(filename
));
65 disassembler
->forEachFunction([&](uint64_t address
, Function
* fun
) {
66 populateSymbolInformation(fun
);
73 local__add_basic_block(BasicBlock
* block
, Disassembler
* dis
,
74 std::map
<uint64_t, BasicBlockWidget
*>& known_blocks
,
75 QGraphicsScene
* scene
, uint64_t starty
, uint64_t startx
) {
77 decltype(known_blocks
.begin()) old
;
78 if ((old
= known_blocks
.find(block
->getStartAddress())) != known_blocks
.end())
82 s
<< "BLOCK_" << std::hex
<< block
->getStartAddress()
83 << "_" << block
->getEndAddress();
84 BasicBlockWidget
* widget
= new BasicBlockWidget(s
.str().c_str(), block
);
86 known_blocks
.insert(std::make_pair(block
->getStartAddress(), widget
));
88 scene
->addItem(widget
);
89 widget
->setFlag(QGraphicsItem::ItemIsMovable
, true);
90 widget
->moveBy(100*startx
, 10*(block
->getStartAddress() - starty
));
92 dis
->printEachInstruction(block
->getStartAddress(), block
->getEndAddress(),
93 [&](uint8_t* bytes
, size_t byte_count
, const std::string
& line
) {
94 widget
->addItem(bytes
, byte_count
, line
.c_str() + 1);
97 BasicBlockWidget
*tmp
, *nextl(NULL
), *nextr(NULL
);
98 BasicBlock
* tmpblock
;
99 if (block
->getNextBlock(0) != 0) {
100 tmpblock
= dis
->getBasicBlock(block
->getNextBlock(0));
101 tmp
= local__add_basic_block(tmpblock
, dis
,
103 scene
, starty
, startx
+1);
105 tmp
->addPrevious(widget
);
107 if (block
->getNextBlock(1) != 0) {
108 tmpblock
= dis
->getBasicBlock(block
->getNextBlock(1));
109 tmp
= local__add_basic_block(tmpblock
, dis
,
111 scene
, starty
, startx
-1);
113 tmp
->addPrevious(widget
);
115 widget
->addNext(nextl
, nextr
);
120 void Mainwindow::populateSymbolInformation(Function
* fun
) {
121 QTabWidget
* w
= new QTabWidget();
124 QGraphicsScene
* scene
= new QGraphicsScene
;
126 BasicBlock
* block
= disassembler
->getBasicBlock(fun
->getStartAddress());
128 local__add_basic_block(block
, disassembler
.get(), blocks
, scene
, block
->getStartAddress(), 100);
130 QGraphicsView
* view
= new QGraphicsView(scene
);
131 w
->addTab(view
, "CFG");
134 QTableWidget
* t
= new QTableWidget();
135 t
->setColumnCount(3);
136 t
->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents
);
138 w
->addTab(t
, "Listing");
140 listWidget
->addItem(fun
->getName().c_str());
141 stackedWidget
->addWidget(w
);