]> git.siccegge.de Git - frida/frida.git/blob - src/gui/Mainwindow.cxx
Separate out several parts of llvm-using code ; Add logger
[frida/frida.git] / src / gui / Mainwindow.cxx
1 #include "Mainwindow.hxx"
2 #include "widgets/BasicBlockWidget.hxx"
3 #include "qt.hxx"
4
5 #include <iostream>
6 #include <sstream>
7
8 #include <QtGui>
9
10 Mainwindow::Mainwindow()
11 {
12 openAction = new QAction(tr("&Open"), this);
13 // saveAction = new QAction(tr("&Save"), this);
14 exitAction = new QAction(tr("E&xit"), this);
15
16 connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
17 // connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
18 connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
19
20 fileMenu = menuBar()->addMenu(tr("&File"));
21 fileMenu->addAction(openAction);
22 // fileMenu->addAction(saveAction);
23 fileMenu->addSeparator();
24 fileMenu->addAction(exitAction);
25
26 listWidget = new QListWidget();
27 stackedWidget = new QStackedWidget();
28 dockWidget = new QDockWidget(tr("Functions"), this);
29 dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
30 Qt::RightDockWidgetArea);
31 dockWidget->setWidget(listWidget);
32 addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
33 setCentralWidget(stackedWidget);
34
35 connect(listWidget, SIGNAL(currentRowChanged(int)),
36 stackedWidget, SLOT(setCurrentIndex(int)));
37
38 setWindowTitle(tr("Notepad"));
39 }
40
41 void Mainwindow::quit()
42 {
43 QMessageBox messageBox;
44 messageBox.setWindowTitle(tr("Notepad"));
45 messageBox.setText(tr("Do you really want to quit?"));
46 messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
47 messageBox.setDefaultButton(QMessageBox::No);
48 if (messageBox.exec() == QMessageBox::Yes)
49 qApp->quit();
50 }
51
52 void Mainwindow::open() {
53 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
54 tr("Binaries (*)"));
55
56 if (fileName != "") {
57 curBin = new qtlldb::Binary(fileName.toStdString());
58
59 std::vector<std::string> symbols = curBin->getSymbols();
60 if (0 == symbols.size())
61 populateSymbolInformation(".text");
62 for (std::vector<std::string>::iterator it = symbols.begin();
63 it != symbols.end();
64 ++it) {
65 populateSymbolInformation(*it);
66 }
67 }
68 }
69
70 void Mainwindow::populateSymbolInformation(const std::string& sym) {
71 QTabWidget * w = new QTabWidget();
72
73 // Listing
74 QTableWidget * t = new QTableWidget();
75 t->setColumnCount(3);
76 t->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
77 curBin->for_each_instruction(sym, [&t](long add, std::string bytes, std::string mnemonic) {
78 int row = t->rowCount();
79 std::stringstream s;
80 t->setRowCount(t->rowCount() + 1);
81 s << std::hex << add;
82 t->setItem(row,0,new QTableWidgetItem(s.str().c_str()));
83 s.str("");
84 s << std::hex;
85 for_each(bytes.begin(), bytes.end(), [&s](char c){s << (unsigned int)((unsigned char)c) << ' ';});
86 t->setItem(row,1,new QTableWidgetItem(s.str().c_str()));
87 t->setItem(row,2,new QTableWidgetItem(mnemonic.c_str() + 1));
88 });
89 w->addTab(t, "Listing");
90
91 // CFG
92 QGraphicsScene * scene = new QGraphicsScene;
93
94 BasicBlockWidget * s1 = new BasicBlockWidget;
95 scene->addItem(s1);
96 s1->setFlag(QGraphicsItem::ItemIsMovable, true);
97
98 BasicBlockWidget * s2 = new BasicBlockWidget;
99 scene->addItem(s2);
100 s2->setFlag(QGraphicsItem::ItemIsMovable, true);
101 s2->moveBy(-200, 350);
102
103 BasicBlockWidget * s3 = new BasicBlockWidget;
104 scene->addItem(s3);
105 s3->setFlag(QGraphicsItem::ItemIsMovable, true);
106 s3->moveBy(100, 350);
107
108 BasicBlockWidget * s4 = new BasicBlockWidget;
109 scene->addItem(s4);
110 s4->setFlag(QGraphicsItem::ItemIsMovable, true);
111 s4->moveBy(400, 350);
112
113
114 QGraphicsView * view = new QGraphicsView(scene);
115 w->addTab(view, "CFG");
116
117 listWidget->addItem(sym.c_str());
118 stackedWidget->addWidget(w);
119 }