]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/FunctionWidget.cxx
Make signals from geiser work
[frida/frida.git] / src / gui / widgets / FunctionWidget.cxx
1 #include "FunctionWidget.hxx"
2
3 #include "core/Function.hxx"
4 #include "core/BasicBlock.hxx"
5 #include "core/InformationManager.hxx"
6
7 #include "gui/widgets/CFGScene.hxx"
8 #include "gui/Mainwindow.hxx"
9
10 namespace {
11 BasicBlockWidget *
12 local__add_basic_block(BasicBlock * block,
13 Mainwindow * mainwindow, InformationManager * manager,
14 std::map<uint64_t, BasicBlockWidget*>& known_blocks,
15 CFGScene * scene, uint64_t starty, uint64_t startx);
16 }
17
18 FunctionWidget::FunctionWidget(Function* function, Mainwindow* mainwindow)
19 : function(function)
20 , mainwindow(mainwindow)
21 , layouted(false)
22 , logger(log4cxx::Logger::getLogger("gui.Mainwindow")) {
23
24 }
25
26 void FunctionWidget::showEvent(QShowEvent* event) {
27 if (!layouted) {
28 CFGScene * scene = new CFGScene;
29 InformationManager* manager = function->getManager();
30
31 BasicBlock * block = manager->getBasicBlock(function->getStartAddress());
32 LOG4CXX_DEBUG(logger, "Building widget for functionction " << function->getName());
33 for (auto i : function->blocks()) {
34 LOG4CXX_DEBUG(logger, "Functionction contains Block " << i.second->getName());
35 }
36
37 uint64_t start_address(std::numeric_limits<uint64_t>::max());
38 for (auto b : function->blocks()) {
39 if (b.first < start_address)
40 start_address = b.first;
41 }
42
43 std::map<uint64_t, BasicBlockWidget*> _blocks;
44 local__add_basic_block(block, mainwindow,
45 manager, _blocks, scene, 3*start_address, 100);
46
47 QGraphicsView * view = new QGraphicsView(scene);
48 view->setDragMode(QGraphicsView::ScrollHandDrag);
49 addTab(view, "CFG");
50
51 // Listing
52 QTableWidget * t = new QTableWidget();
53 t->setColumnCount(3);
54 t->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
55
56 addTab(t, "Listing");
57 layouted = true;
58 }
59 }
60
61 namespace {
62 BasicBlockWidget *
63 local__add_basic_block(BasicBlock * block,
64 Mainwindow * mainwindow, InformationManager * manager,
65 std::map<uint64_t, BasicBlockWidget*>& known_blocks,
66 CFGScene * scene, uint64_t starty, uint64_t startx) {
67
68 decltype(known_blocks.begin()) old;
69 if (!block) return NULL;
70 if ((old = known_blocks.find(block->getStartAddress())) != known_blocks.end())
71 return old->second;
72
73 std::stringstream s;
74 s << "BLOCK_" << std::hex << block->getStartAddress()
75 << "_" << block->getEndAddress();
76 BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(),
77 block, mainwindow);
78
79 known_blocks.insert(std::make_pair(block->getStartAddress(), widget));
80
81 scene->addItem(widget);
82 widget->setFlag(QGraphicsItem::ItemIsMovable, true);
83 widget->moveBy(100*startx, 3*block->getStartAddress() - starty);
84
85 BasicBlockWidget *tmp, *nextl(NULL), *nextr(NULL);
86 BasicBlock * tmpblock;
87 if (block->getNextBlock(0) != 0) {
88 int xshift = 0;
89 if (block->getNextBlock(1) != 0)
90 xshift = 1;
91 tmpblock = manager->getBasicBlock(block->getNextBlock(0));
92 tmp = local__add_basic_block(tmpblock, mainwindow, manager,
93 known_blocks,
94 scene, starty, startx+xshift);
95 nextl = tmp;
96 tmp->addPrevious(widget);
97 }
98 if (block->getNextBlock(1) != 0) {
99 tmpblock = manager->getBasicBlock(block->getNextBlock(1));
100 tmp = local__add_basic_block(tmpblock, mainwindow, manager,
101 known_blocks,
102 scene, starty, startx-1);
103 nextr = tmp;
104 tmp->addPrevious(widget);
105 }
106 widget->addNext(nextl, nextr);
107 return widget;
108 }
109 }