namespace {
BasicBlockWidget *
local__add_basic_block(BasicBlock * block, Disassembler * dis,
+ Mainwindow * mainwindow,
std::map<uint64_t, BasicBlockWidget*>& known_blocks,
CFGScene * scene, uint64_t starty, uint64_t startx);
}
manager->reset(fileName.toStdString());
}
+void Mainwindow::switchMainPlaneToAddress(uint64_t address) {
+ if (objects_list_by_address.find(address) != objects_list_by_address.end()) {
+ LOG4CXX_DEBUG(logger, "Switching to function " << std::hex << address);
+ QListWidgetItem * item = objects_list_by_address[address];
+ listWidget->setCurrentItem(item);
+ stackedWidget->setCurrentWidget(objects_list[item]);
+ } else {
+ LOG4CXX_DEBUG(logger, "No function at " << std::hex << address
+ << " -- it's probably an imported Symbol");
+ }
+}
+
void Mainwindow::switchMainPlane(int index) {
stackedWidget->setCurrentWidget(objects_list[listWidget->currentItem()]);
}
start_address = b.first;
}
- local__add_basic_block(block, manager->getDisassembler(), blocks, scene,
- start_address, 100);
+ local__add_basic_block(block, manager->getDisassembler(), this,
+ blocks, scene, start_address, 100);
QGraphicsView * view = new QGraphicsView(scene);
w->addTab(view, "CFG");
QListWidgetItem * item = new QListWidgetItem(fun->getName().c_str(), listWidget);
stackedWidget->addWidget(w);
objects_list.insert(std::make_pair(item, w));
+ LOG4CXX_DEBUG(logger, "Adding function widget at " << std::hex
+ << fun->getStartAddress());
+ objects_list_by_address.insert(std::make_pair(fun->getStartAddress(), item));
}
namespace {
BasicBlockWidget *
local__add_basic_block(BasicBlock * block, Disassembler * dis,
+ Mainwindow * mainwindow,
std::map<uint64_t, BasicBlockWidget*>& known_blocks,
CFGScene * scene, uint64_t starty, uint64_t startx) {
std::stringstream s;
s << "BLOCK_" << std::hex << block->getStartAddress()
<< "_" << block->getEndAddress();
- BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(), block);
+ BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(),
+ block, mainwindow);
known_blocks.insert(std::make_pair(block->getStartAddress(), widget));
xshift = 1;
tmpblock = dis->getBasicBlock(block->getNextBlock(0));
tmp = local__add_basic_block(tmpblock, dis,
+ mainwindow,
known_blocks,
scene, starty, startx+xshift);
nextl = tmp;
if (block->getNextBlock(1) != 0) {
tmpblock = dis->getBasicBlock(block->getNextBlock(1));
tmp = local__add_basic_block(tmpblock, dis,
+ mainwindow,
known_blocks,
scene, starty, startx-1);
nextr = tmp;
std::map<uint64_t, BasicBlockWidget*> blocks;
std::map<QListWidgetItem*, QWidget*> objects_list;
+ std::map<uint64_t, QListWidgetItem*> objects_list_by_address;
std::set<Function*> functions;
InformationManager* manager;
log4cxx::LoggerPtr logger;
+public Q_SLOTS:
+ void switchMainPlaneToAddress(uint64_t);
private Q_SLOTS:
void quit();
void open();
#include "BasicBlockWidget.hxx"
+#include "gui/Mainwindow.hxx"
-BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block)
+BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block,
+ Mainwindow * mainwindow)
: width(270), height(45)
- , name(name), block(block)
- , _proxy(this) {
+ , _proxy(this), name(name)
+ , block(block), mainwindow(mainwindow) {
next[0] = NULL; next[1] = NULL;
- _widget.setStyleSheet("QTableWidget { background-color : #ddddff; }");
- _widget.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
- _widget.verticalHeader()->setDefaultSectionSize(18);
- _widget.setColumnCount(3);
- _widget.verticalHeader()->hide();
- _widget.horizontalHeader()->hide();
- _widget.setShowGrid(false);
- _widget.setWordWrap(false);
- _widget.setMinimumSize(210, 20);
-
+ _widget.setStyleSheet("QWidget { background-color : #ddddff; }");
+ _widget.setLayout(&_layout);
+ _layout.setContentsMargins(0, 0, 0, 0);
_proxy.setWidget(&_widget);
_proxy.setPos(5, 20);
bytestring += ' ';
}
- int current_row = _widget.rowCount();
- _widget.setRowCount(1 + current_row);
- _widget.setItem(current_row, 0, new QTableWidgetItem(bytestring));
- _widget.setItem(current_row, 1, new QTableWidgetItem(line.replace('\t', ' ')));
-// _widget.setItem(current_row, 2, new QTableWidgetItem(href));
+ int current_row = _layout.rowCount();
+ QLabel * bytestring_label = new QLabel(bytestring);
+ bytestring_label->setTextInteractionFlags(Qt::TextSelectableByMouse|
+ Qt::LinksAccessibleByMouse);
+ bytestring_label->setWordWrap(false);
+ _layout.addWidget(bytestring_label, current_row, 0);
+ bytestring_label->setVisible(true);
- _widget.resizeColumnToContents(0);
- _widget.resizeColumnToContents(1);
- _widget.resizeColumnToContents(2);
+ line = line.replace('\t', ' ').toHtmlEscaped();
+ if (href != "") {
+ line = "<a href=\"" + href + "\">" + line + "</a>";
+ }
+ QLabel * instruction_label = new QLabel(line);
+ instruction_label->setTextInteractionFlags(Qt::TextSelectableByMouse|
+ Qt::LinksAccessibleByMouse);
+ instruction_label->setWordWrap(false);
+ instruction_label->setFocusPolicy(Qt::StrongFocus);
+ if (href != "") {
+ QObject::connect(instruction_label, &QLabel::linkActivated,
+ [=](QString str) {
+ if (str.startsWith("function:")) {
+ QString address = str.remove("function:");
+ mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
+ }
+ });
+ }
+ _layout.addWidget(instruction_label, current_row, 1);
+ instruction_label->setVisible(true);
width = 12 + _widget.sizeHint().width();
- height = 25 + _widget.sizeHint().height();
+ height = 25 + _widget.childrenRect().height();
if (width < 250) width = 250;
_widget.resize(width - 12, height - 25);
#include <tuple>
#include <array>
+class Mainwindow;
+
class BasicBlockWidget : public QGraphicsItem
{
public:
- BasicBlockWidget(const QString& name, BasicBlock * block);
+ BasicBlockWidget(const QString& name, BasicBlock * block, Mainwindow * mainwindow);
void addItem(uint8_t* bytes, size_t num_bytes, QString line, const QString& href);
private:
uint32_t width, height;
QGraphicsProxyWidget _proxy;
- QTableWidget _widget;
+ QGridLayout _layout;
+ QLabel _widget;
QString name;
BasicBlock * block;
+ Mainwindow * mainwindow;
std::vector<BasicBlockWidget*> previous;
BasicBlockWidget* next[2];
};