]>
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
)
22 , logger(log4cxx::Logger::getLogger("gui.Mainwindow")) {
26 void FunctionWidget::showEvent(QShowEvent
* event
) {
28 CFGScene
* scene
= new CFGScene
;
29 InformationManager
* manager
= function
->getManager();
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());
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
;
43 std::map
<uint64_t, BasicBlockWidget
*> _blocks
;
44 local__add_basic_block(block
, mainwindow
,
45 manager
, _blocks
, scene
, 3*start_address
, 100);
47 QGraphicsView
* view
= new QGraphicsView(scene
);
48 view
->setDragMode(QGraphicsView::ScrollHandDrag
);
52 QTableWidget
* t
= new QTableWidget();
54 t
->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents
);
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
) {
68 decltype(known_blocks
.begin()) old
;
69 if (!block
) return NULL
;
70 if ((old
= known_blocks
.find(block
->getStartAddress())) != known_blocks
.end())
74 s
<< "BLOCK_" << std::hex
<< block
->getStartAddress()
75 << "_" << block
->getEndAddress();
76 BasicBlockWidget
* widget
= new BasicBlockWidget(s
.str().c_str(),
79 known_blocks
.insert(std::make_pair(block
->getStartAddress(), widget
));
81 scene
->addItem(widget
);
82 widget
->setFlag(QGraphicsItem::ItemIsMovable
, true);
83 widget
->moveBy(100*startx
, 3*block
->getStartAddress() - starty
);
85 BasicBlockWidget
*tmp
, *nextl(NULL
), *nextr(NULL
);
86 BasicBlock
* tmpblock
;
87 if (block
->getNextBlock(0) != 0) {
89 if (block
->getNextBlock(1) != 0)
91 tmpblock
= manager
->getBasicBlock(block
->getNextBlock(0));
92 tmp
= local__add_basic_block(tmpblock
, mainwindow
, manager
,
94 scene
, starty
, startx
+xshift
);
96 tmp
->addPrevious(widget
);
98 if (block
->getNextBlock(1) != 0) {
99 tmpblock
= manager
->getBasicBlock(block
->getNextBlock(1));
100 tmp
= local__add_basic_block(tmpblock
, mainwindow
, manager
,
102 scene
, starty
, startx
-1);
104 tmp
->addPrevious(widget
);
106 widget
->addNext(nextl
, nextr
);