]>
git.siccegge.de Git - frida/frida.git/blob - src/gui/Mainwindow.cxx
1 #include "Mainwindow.hxx"
3 #include "disassembler/llvm/LLVMDisassembler.hxx"
5 #include "widgets/CFGScene.hxx"
6 #include "dialogs/NewFunctionDialog.hxx"
15 local__add_basic_block(BasicBlock
* block
, Disassembler
* dis
,
16 std::map
<uint64_t, BasicBlockWidget
*>& known_blocks
,
17 CFGScene
* scene
, uint64_t starty
, uint64_t startx
);
20 Mainwindow::Mainwindow(InformationManager
* mgr
)
22 , logger(log4cxx::Logger::getLogger("Mainwindow")) {
23 openAction
= new QAction(tr("&Open"), this);
24 // saveAction = new QAction(tr("&Save"), this);
25 exitAction
= new QAction(tr("E&xit"), this);
27 connect(openAction
, SIGNAL(triggered()),
29 // connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
30 connect(exitAction
, SIGNAL(triggered()),
33 fileMenu
= menuBar()->addMenu(tr("&File"));
34 fileMenu
->addAction(openAction
);
35 // fileMenu->addAction(saveAction);
36 fileMenu
->addSeparator();
37 fileMenu
->addAction(exitAction
);
39 scripting
= new ScriptingDock(tr("Scripting"), this);
40 scripting
->setAllowedAreas(Qt::BottomDockWidgetArea
);
41 addDockWidget(Qt::BottomDockWidgetArea
, scripting
);
43 listWidget
= new QListWidget();
44 listWidget
->setContextMenuPolicy(Qt::CustomContextMenu
);
45 connect(listWidget
, SIGNAL(customContextMenuRequested(const QPoint
&)),
46 this, SLOT(showListContextMenu(const QPoint
&)));
48 stackedWidget
= new QStackedWidget();
49 dockWidget
= new QDockWidget(tr("Functions"), this);
50 dockWidget
->setAllowedAreas(Qt::LeftDockWidgetArea
|
51 Qt::RightDockWidgetArea
);
52 dockWidget
->setWidget(listWidget
);
53 addDockWidget(Qt::LeftDockWidgetArea
, dockWidget
);
54 setCentralWidget(stackedWidget
);
56 connect(listWidget
, SIGNAL(currentRowChanged(int)),
57 stackedWidget
, SLOT(setCurrentIndex(int)));
59 setWindowTitle(tr("FRIDA"));
61 mgr
->connect_new_function_signal([&] (Function
* fun
) {addFunction(fun
);});
62 mgr
->connect_new_dyn_symbol_signal([&] (const std::string
& name
) {
63 auto item
= new QListWidgetItem(name
.c_str(), listWidget
);
64 item
->setBackground(QBrush(QColor(0xff, 0xdd, 0xdd)));
68 void Mainwindow::quit()
70 QMessageBox messageBox
;
71 messageBox
.setWindowTitle(tr("Frida"));
72 messageBox
.setText(tr("Do you really want to quit?"));
73 messageBox
.setStandardButtons(QMessageBox::Yes
| QMessageBox::No
);
74 messageBox
.setDefaultButton(QMessageBox::No
);
75 if (messageBox
.exec() == QMessageBox::Yes
)
79 void Mainwindow::open() {
80 QString fileName
= QFileDialog::getOpenFileName(this, tr("Open File"), "",
83 manager
->reset(fileName
.toStdString());
86 void Mainwindow::showListContextMenu(const QPoint
& point
) {
87 QListWidgetItem
* item
= listWidget
->itemAt(point
);
89 LOG4CXX_DEBUG(logger
, "WOHO " << item
->text().toStdString());
92 QAction
* act
= menu
.addAction("AddFunction");
93 connect(act
, SIGNAL(triggered()), this, SLOT(requestNewFunction()));
95 menu
.exec(listWidget
->mapToGlobal(point
));
99 void Mainwindow::requestNewFunction() {
100 NewFunctionDialog dialog
;
101 int result
= dialog
.exec();
102 if (QDialog::Accepted
== result
) {
103 LOG4CXX_DEBUG(logger
, "requesting Function at " << std::hex
<< dialog
.result());
104 manager
->getDisassembler()->disassembleFunctionAt(dialog
.result());
106 LOG4CXX_DEBUG(logger
, "requestNewFunction aborted");
110 void Mainwindow::addFunction(Function
* fun
) {
111 if (functions
.find(fun
) != functions
.end())
114 functions
.insert(fun
);
116 QTabWidget
* w
= new QTabWidget();
119 CFGScene
* scene
= new CFGScene
;
121 Disassembler
* dis
= manager
->getDisassembler();
122 BasicBlock
* block
= dis
->getBasicBlock(fun
->getStartAddress());
124 uint64_t start_address(std::numeric_limits
<uint64_t>::max());
125 for (auto b
: fun
->blocks()) {
126 if (b
.first
< start_address
)
127 start_address
= b
.first
;
130 local__add_basic_block(block
, manager
->getDisassembler(), blocks
, scene
,
133 QGraphicsView
* view
= new QGraphicsView(scene
);
134 w
->addTab(view
, "CFG");
137 QTableWidget
* t
= new QTableWidget();
138 t
->setColumnCount(3);
139 t
->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents
);
141 w
->addTab(t
, "Listing");
143 listWidget
->addItem(fun
->getName().c_str());
144 stackedWidget
->addWidget(w
);
149 local__add_basic_block(BasicBlock
* block
, Disassembler
* dis
,
150 std::map
<uint64_t, BasicBlockWidget
*>& known_blocks
,
151 CFGScene
* scene
, uint64_t starty
, uint64_t startx
) {
153 decltype(known_blocks
.begin()) old
;
154 if ((old
= known_blocks
.find(block
->getStartAddress())) != known_blocks
.end())
158 s
<< "BLOCK_" << std::hex
<< block
->getStartAddress()
159 << "_" << block
->getEndAddress();
160 BasicBlockWidget
* widget
= new BasicBlockWidget(s
.str().c_str(), block
);
162 known_blocks
.insert(std::make_pair(block
->getStartAddress(), widget
));
164 scene
->addItem(widget
);
165 widget
->setFlag(QGraphicsItem::ItemIsMovable
, true);
166 widget
->moveBy(100*startx
, block
->getStartAddress() - starty
);
168 dis
->printEachInstruction(block
->getStartAddress(),
169 block
->getEndAddress(),
172 const std::string
& line
,
173 const std::string
& ref
) {
174 widget
->addItem(bytes
, byte_count
,
175 line
.c_str() + 1, // remove \t
179 BasicBlockWidget
*tmp
, *nextl(NULL
), *nextr(NULL
);
180 BasicBlock
* tmpblock
;
181 if (block
->getNextBlock(0) != 0) {
183 if (block
->getNextBlock(1) != 0)
185 tmpblock
= dis
->getBasicBlock(block
->getNextBlock(0));
186 tmp
= local__add_basic_block(tmpblock
, dis
,
188 scene
, starty
, startx
+xshift
);
190 tmp
->addPrevious(widget
);
192 if (block
->getNextBlock(1) != 0) {
193 tmpblock
= dis
->getBasicBlock(block
->getNextBlock(1));
194 tmp
= local__add_basic_block(tmpblock
, dis
,
196 scene
, starty
, startx
-1);
198 tmp
->addPrevious(widget
);
200 widget
->addNext(nextl
, nextr
);