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