]>
git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/FunctionWidget.cxx
1 #include "FunctionWidget.hxx"
3 #include "core/Function.hxx"
4 #include "core/BasicBlock.hxx"
5 #include "core/InformationManager.hxx"
7 #include "gui/widgets/CFGScene.hxx"
8 #include "gui/Mainwindow.hxx"
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
);
18 FunctionWidget::FunctionWidget(Function
* function
, Mainwindow
* mainwindow
)
20 , mainwindow(mainwindow
)
21 , logger(log4cxx::Logger::getLogger("gui.Mainwindow")) {
24 CFGScene
* scene
= new CFGScene
;
25 InformationManager
* manager
= function
->getManager();
27 BasicBlock
* block
= manager
->getBasicBlock(function
->getStartAddress());
28 LOG4CXX_DEBUG(logger
, "Building widget for functionction " << function
->getName());
29 for (auto i
: function
->blocks()) {
30 LOG4CXX_DEBUG(logger
, "Functionction contains Block " << i
.second
->getName());
33 uint64_t start_address(std::numeric_limits
<uint64_t>::max());
34 for (auto b
: function
->blocks()) {
35 if (b
.first
< start_address
)
36 start_address
= b
.first
;
39 std::map
<uint64_t, BasicBlockWidget
*> _blocks
;
40 local__add_basic_block(block
, mainwindow
,
41 manager
, _blocks
, scene
, start_address
, 100);
43 QGraphicsView
* view
= new QGraphicsView(scene
);
44 view
->setDragMode(QGraphicsView::ScrollHandDrag
);
48 QTableWidget
* t
= new QTableWidget();
50 t
->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents
);
60 local__add_basic_block(BasicBlock
* block
,
61 Mainwindow
* mainwindow
, InformationManager
* manager
,
62 std::map
<uint64_t, BasicBlockWidget
*>& known_blocks
,
63 CFGScene
* scene
, uint64_t starty
, uint64_t startx
) {
65 decltype(known_blocks
.begin()) old
;
66 if (!block
) return NULL
;
67 if ((old
= known_blocks
.find(block
->getStartAddress())) != known_blocks
.end())
71 s
<< "BLOCK_" << std::hex
<< block
->getStartAddress()
72 << "_" << block
->getEndAddress();
73 BasicBlockWidget
* widget
= new BasicBlockWidget(s
.str().c_str(),
76 known_blocks
.insert(std::make_pair(block
->getStartAddress(), widget
));
78 scene
->addItem(widget
);
79 widget
->setFlag(QGraphicsItem::ItemIsMovable
, true);
80 widget
->moveBy(100*startx
, block
->getStartAddress() - starty
);
82 BasicBlockWidget
*tmp
, *nextl(NULL
), *nextr(NULL
);
83 BasicBlock
* tmpblock
;
84 if (block
->getNextBlock(0) != 0) {
86 if (block
->getNextBlock(1) != 0)
88 tmpblock
= manager
->getBasicBlock(block
->getNextBlock(0));
89 tmp
= local__add_basic_block(tmpblock
, mainwindow
, manager
,
91 scene
, starty
, startx
+xshift
);
93 tmp
->addPrevious(widget
);
95 if (block
->getNextBlock(1) != 0) {
96 tmpblock
= manager
->getBasicBlock(block
->getNextBlock(1));
97 tmp
= local__add_basic_block(tmpblock
, mainwindow
, manager
,
99 scene
, starty
, startx
-1);
101 tmp
->addPrevious(widget
);
103 widget
->addNext(nextl
, nextr
);