2017-12-08 15:00:52 +00:00
|
|
|
#include "VisualNavbar.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
2017-12-07 23:41:15 +00:00
|
|
|
#include "utils/TempConfig.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-09 22:00:29 +00:00
|
|
|
#include <cmath>
|
2017-04-13 15:14:02 +00:00
|
|
|
#include <QGraphicsView>
|
2017-03-29 10:18:37 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsRectItem>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonParseError>
|
2017-12-09 23:22:16 +00:00
|
|
|
#include <QToolTip>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) :
|
2017-10-01 18:08:12 +00:00
|
|
|
QToolBar(main),
|
2017-12-08 15:00:52 +00:00
|
|
|
graphicsView(new QGraphicsView),
|
2018-01-27 11:15:58 +00:00
|
|
|
cursorGraphicsItem(nullptr),
|
2017-10-01 18:08:12 +00:00
|
|
|
main(main)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(parent);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
setObjectName("visualNavbar");
|
|
|
|
setWindowTitle(tr("Visual navigation bar"));
|
2017-04-09 19:55:06 +00:00
|
|
|
// setMovable(false);
|
2017-03-29 10:18:37 +00:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2017-04-07 15:34:24 +00:00
|
|
|
// If line below is used, with the dark theme the paintEvent is not called
|
|
|
|
// and the result is wrong. Something to do with overwriting the style sheet :/
|
|
|
|
//setStyleSheet("QToolBar { border: 0px; border-bottom: 0px; border-top: 0px; border-width: 0px;}");
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
QComboBox *addsCombo = new QComboBox();
|
|
|
|
addsCombo->addItem("");
|
|
|
|
addsCombo->addItem("Entry points");
|
|
|
|
addsCombo->addItem("Marks");
|
|
|
|
*/
|
2017-12-08 15:00:52 +00:00
|
|
|
addWidget(this->graphicsView);
|
2017-03-29 10:18:37 +00:00
|
|
|
//addWidget(addsCombo);
|
2017-11-19 12:56:10 +00:00
|
|
|
|
2017-12-07 23:41:15 +00:00
|
|
|
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(fetchAndPaintData()));
|
2017-12-11 13:07:12 +00:00
|
|
|
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(updateMetadataAndPaint()));
|
|
|
|
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(updateMetadataAndPaint()));
|
2017-12-08 09:55:47 +00:00
|
|
|
|
|
|
|
graphicsScene = new QGraphicsScene(this);
|
2017-12-08 15:00:52 +00:00
|
|
|
|
|
|
|
const QBrush bg = QBrush(QColor(74, 74, 74));
|
|
|
|
|
|
|
|
graphicsScene->setBackgroundBrush(bg);
|
|
|
|
|
|
|
|
this->graphicsView->setAlignment(Qt::AlignLeft);
|
|
|
|
this->graphicsView->setMinimumHeight(20);
|
|
|
|
this->graphicsView->setMaximumHeight(20);
|
|
|
|
this->graphicsView->setFrameShape(QFrame::NoFrame);
|
|
|
|
this->graphicsView->setRenderHints(0);
|
|
|
|
this->graphicsView->setScene(graphicsScene);
|
|
|
|
this->graphicsView->setRenderHints(QPainter::Antialiasing);
|
2017-12-09 23:22:16 +00:00
|
|
|
this->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
this->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
// So the graphicsView doesn't intercept mouse events.
|
|
|
|
this->graphicsView->setEnabled(false);
|
|
|
|
this->graphicsView->setMouseTracking(true);
|
|
|
|
setMouseTracking(true);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
void VisualNavbar::paintEvent(QPaintEvent *event)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(event);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
|
|
|
QPainter painter(this);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (previousWidth != this->width()) {
|
2017-12-08 09:55:47 +00:00
|
|
|
this->fillData();
|
2017-12-08 15:00:52 +00:00
|
|
|
previousWidth = this->width();
|
2017-12-08 09:55:47 +00:00
|
|
|
}
|
2017-04-09 17:09:35 +00:00
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
void VisualNavbar::fetchAndPaintData()
|
2017-12-07 23:41:15 +00:00
|
|
|
{
|
|
|
|
fetchData();
|
|
|
|
fillData();
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
bool VisualNavbar::sortSectionLessThan(const SectionDescription §ion1,
|
|
|
|
const SectionDescription §ion2)
|
2017-12-07 23:41:15 +00:00
|
|
|
{
|
2017-12-09 23:22:16 +00:00
|
|
|
return section1.vaddr < section2.vaddr;
|
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
VisualNavbar::MappedSegment *VisualNavbar::mappedSegmentForAddress(RVA addr)
|
2017-12-09 23:22:16 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < mappedSegments.length(); i++) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegment *mappedSegment = &mappedSegments[i];
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((mappedSegment->address_from <= addr) && (addr <= mappedSegment->address_to)) {
|
2017-12-09 23:22:16 +00:00
|
|
|
return mappedSegment;
|
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
return nullptr;
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
void VisualNavbar::fetchData()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-12-09 23:22:16 +00:00
|
|
|
// TODO: This code is quite verbose but very readable. The goal is to
|
|
|
|
// experiment until we know what we want and then start to optimize.
|
|
|
|
sections = Core()->getAllSections();
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
// Sort sections so we don't have to filter for overlaps afterwards
|
|
|
|
qSort(sections.begin(), sections.end(), sortSectionLessThan);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
mappedSegments.clear();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (SectionDescription section : sections) {
|
2017-12-09 23:22:16 +00:00
|
|
|
bool segment_found = false;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < mappedSegments.count(); i++) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegment &mappedSegment = mappedSegments[i];
|
|
|
|
// Check if the segment contains the section
|
|
|
|
bool segment_contains_section_start = false;
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((mappedSegment.address_from <= section.vaddr) &&
|
2017-12-09 23:22:16 +00:00
|
|
|
(section.vaddr <= mappedSegment.address_to)) {
|
|
|
|
segment_contains_section_start = true;
|
|
|
|
}
|
|
|
|
bool segment_contains_section_end = false;
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((mappedSegment.address_from <= section.vaddr + section.vsize) &&
|
|
|
|
(section.vaddr + section.vsize <= mappedSegment.address_to)) {
|
2017-12-09 23:22:16 +00:00
|
|
|
segment_contains_section_end = true;
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
// Check if the section contains the segment
|
|
|
|
bool section_contains_segment_start = false;
|
|
|
|
bool section_contains_segment_end = false;
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((section.vaddr <= mappedSegment.address_from) &&
|
|
|
|
(mappedSegment.address_from <= section.vaddr + section.vsize)) {
|
2017-12-09 23:22:16 +00:00
|
|
|
section_contains_segment_start = true;
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((section.vaddr <= mappedSegment.address_to) &&
|
|
|
|
(mappedSegment.address_to <= section.vaddr + section.vsize)) {
|
2017-12-09 23:22:16 +00:00
|
|
|
section_contains_segment_end = true;
|
|
|
|
}
|
2017-11-19 12:56:10 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (segment_contains_section_start | segment_contains_section_end |
|
|
|
|
section_contains_segment_start | section_contains_segment_end) {
|
|
|
|
if (section.vaddr < mappedSegment.address_from) {
|
2017-12-09 23:22:16 +00:00
|
|
|
mappedSegment.address_from = section.vaddr;
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if (mappedSegment.address_to < section.vaddr + section.vsize) {
|
2017-12-09 23:22:16 +00:00
|
|
|
mappedSegment.address_to = section.vaddr + section.vsize;
|
|
|
|
}
|
|
|
|
segment_found = true;
|
|
|
|
mappedSegment.sectionDescriptions.append(section);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!segment_found) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegment mappedSegment;
|
|
|
|
mappedSegment.address_from = section.vaddr;
|
|
|
|
mappedSegment.address_to = section.vaddr + section.vsize;
|
|
|
|
mappedSegment.sectionDescriptions.append(section);
|
|
|
|
mappedSegments.append(mappedSegment);
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-12-10 18:12:22 +00:00
|
|
|
// If the file does not contain any sections we get the segments
|
|
|
|
// from the memory maps instead.
|
|
|
|
// It treats each map on its own, so overlapping maps will be shown
|
|
|
|
// seperated.
|
2018-03-21 20:32:32 +00:00
|
|
|
if (sections.count() == 0) {
|
2017-12-10 18:12:22 +00:00
|
|
|
QJsonArray maps = Core()->cmdj("omj").array();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QJsonValue mapValue : maps) {
|
2017-12-10 18:12:22 +00:00
|
|
|
QJsonObject map = mapValue.toObject();
|
|
|
|
MappedSegment mappedSegment;
|
|
|
|
mappedSegment.address_from = map["from"].toVariant().toULongLong();
|
|
|
|
mappedSegment.address_to = map["to"].toVariant().toULongLong();
|
|
|
|
mappedSegments.append(mappedSegment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
totalMappedSize = 0;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &mappedSegment : mappedSegments) {
|
2017-12-09 23:22:16 +00:00
|
|
|
totalMappedSize += mappedSegment.address_to - mappedSegment.address_from;
|
|
|
|
}
|
2017-11-19 12:56:10 +00:00
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
updateMetadata();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualNavbar::updateMetadataAndPaint()
|
|
|
|
{
|
|
|
|
qWarning() << "Update metadata & paint";
|
|
|
|
updateMetadata();
|
|
|
|
fillData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualNavbar::updateMetadata()
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < mappedSegments.length(); i++) {
|
2017-12-11 13:07:12 +00:00
|
|
|
mappedSegments[i].functions.clear();
|
|
|
|
mappedSegments[i].symbols.clear();
|
|
|
|
mappedSegments[i].strings.clear();
|
|
|
|
}
|
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
QList<FunctionDescription> functions = Core()->getAllFunctions();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto function : functions) {
|
2017-12-09 23:22:16 +00:00
|
|
|
auto mappedSegment = mappedSegmentForAddress(function.offset);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (mappedSegment) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegmentMetadata metadata;
|
|
|
|
metadata.address = function.offset;
|
|
|
|
metadata.size = function.size;
|
|
|
|
mappedSegment->functions.append(metadata);
|
2017-04-03 08:23:21 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
QList<SymbolDescription> symbols = Core()->getAllSymbols();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto symbol : symbols) {
|
2017-12-09 23:22:16 +00:00
|
|
|
auto mappedSegment = mappedSegmentForAddress(symbol.vaddr);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (mappedSegment) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegmentMetadata metadata;
|
|
|
|
metadata.address = symbol.vaddr;
|
|
|
|
metadata.size = 1;
|
|
|
|
mappedSegment->symbols.append(metadata);
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
QList<StringDescription> strings = Core()->getAllStrings();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto string : strings) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegment *mappedSegment = mappedSegmentForAddress(string.vaddr);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (mappedSegment) {
|
2017-12-09 23:22:16 +00:00
|
|
|
MappedSegmentMetadata metadata;
|
|
|
|
metadata.address = string.vaddr;
|
|
|
|
metadata.size = string.string.length();
|
|
|
|
mappedSegment->strings.append(metadata);
|
2017-12-08 09:55:47 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
void VisualNavbar::drawMetadata(QList<MappedSegmentMetadata> metadata,
|
|
|
|
RVA offset,
|
|
|
|
double x,
|
|
|
|
double width_per_byte,
|
|
|
|
double h, QColor color)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto s : metadata) {
|
2017-12-09 23:22:16 +00:00
|
|
|
double block_x = x + ((double)(s.address - offset) * width_per_byte);
|
|
|
|
double block_width = (double)s.size * width_per_byte;
|
|
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(block_x, 0, block_width, h);
|
|
|
|
rect->setPen(Qt::NoPen);
|
|
|
|
rect->setBrush(QBrush(color));
|
|
|
|
graphicsScene->addItem(rect);
|
|
|
|
}
|
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
void VisualNavbar::fillData()
|
|
|
|
{
|
|
|
|
graphicsScene->clear();
|
|
|
|
cursorGraphicsItem = nullptr;
|
|
|
|
// Do not try to draw if no sections are available.
|
2018-03-21 20:32:32 +00:00
|
|
|
if (mappedSegments.length() == 0) {
|
2017-12-09 23:22:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-09 23:22:16 +00:00
|
|
|
int w = this->graphicsView->width();
|
|
|
|
int h = this->graphicsView->height();
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
double width_per_byte = (double)w / (double)totalMappedSize;
|
2017-12-09 23:22:16 +00:00
|
|
|
xToAddress.clear();
|
|
|
|
double current_x = 0;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto mappedSegment : mappedSegments) {
|
2017-12-09 23:22:16 +00:00
|
|
|
RVA segment_size = mappedSegment.address_to - mappedSegment.address_from;
|
|
|
|
double segment_width = (double)segment_size * width_per_byte;
|
|
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(current_x, 0, segment_width, h);
|
2018-02-01 16:06:30 +00:00
|
|
|
rect->setBrush(QBrush(Config()->getColor("gui.navbar.empty")));
|
2017-12-09 23:22:16 +00:00
|
|
|
graphicsScene->addItem(rect);
|
|
|
|
drawMetadata(mappedSegment.strings,
|
|
|
|
mappedSegment.address_from,
|
|
|
|
current_x,
|
|
|
|
width_per_byte,
|
2018-02-01 16:06:30 +00:00
|
|
|
h, Config()->getColor("gui.navbar.str"));
|
2017-12-09 23:22:16 +00:00
|
|
|
drawMetadata(mappedSegment.symbols,
|
|
|
|
mappedSegment.address_from,
|
|
|
|
current_x,
|
|
|
|
width_per_byte,
|
2018-02-01 16:06:30 +00:00
|
|
|
h, Config()->getColor("gui.navbar.sym"));
|
2017-12-09 23:22:16 +00:00
|
|
|
drawMetadata(mappedSegment.functions,
|
|
|
|
mappedSegment.address_from,
|
|
|
|
current_x,
|
|
|
|
width_per_byte,
|
2018-02-01 16:06:30 +00:00
|
|
|
h, Config()->getColor("gui.navbar.code"));
|
2017-12-09 23:22:16 +00:00
|
|
|
|
|
|
|
// Keep track of where which memory segment is mapped so we are able to convert from
|
|
|
|
// address to X coordinate and vice versa.
|
|
|
|
struct xToAddress x2a;
|
|
|
|
x2a.x_start = current_x;
|
|
|
|
x2a.x_end = current_x + segment_width;
|
|
|
|
x2a.address_from = mappedSegment.address_from;
|
|
|
|
x2a.address_to = mappedSegment.address_to;
|
|
|
|
xToAddress.append(x2a);
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
current_x += segment_width;
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
// Update scene width
|
|
|
|
graphicsScene->setSceneRect(graphicsScene->itemsBoundingRect());
|
2017-12-07 23:41:15 +00:00
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
// Draw cursor
|
2017-12-08 12:21:24 +00:00
|
|
|
drawCursor();
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
void VisualNavbar::drawCursor()
|
2017-12-08 12:21:24 +00:00
|
|
|
{
|
|
|
|
RVA offset = Core()->getOffset();
|
|
|
|
double cursor_x = addressToLocalX(offset);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (cursorGraphicsItem != nullptr) {
|
2017-12-08 12:21:24 +00:00
|
|
|
graphicsScene->removeItem(cursorGraphicsItem);
|
|
|
|
delete cursorGraphicsItem;
|
2017-12-08 15:00:52 +00:00
|
|
|
cursorGraphicsItem = nullptr;
|
2017-12-08 12:21:24 +00:00
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if (std::isnan(cursor_x)) {
|
2017-12-08 12:21:24 +00:00
|
|
|
return;
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
2017-12-08 15:00:52 +00:00
|
|
|
int h = this->graphicsView->height();
|
2017-12-08 12:21:24 +00:00
|
|
|
cursorGraphicsItem = new QGraphicsRectItem(cursor_x, 0, 2, h);
|
|
|
|
cursorGraphicsItem->setPen(Qt::NoPen);
|
2018-02-01 16:06:30 +00:00
|
|
|
cursorGraphicsItem->setBrush(QBrush(Config()->getColor("gui.navbar.err")));
|
2017-12-08 12:21:24 +00:00
|
|
|
graphicsScene->addItem(cursorGraphicsItem);
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
void VisualNavbar::on_seekChanged(RVA addr)
|
2017-12-07 23:41:15 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(addr);
|
2018-02-01 16:06:30 +00:00
|
|
|
// Update cursor
|
2017-12-08 12:21:24 +00:00
|
|
|
this->drawCursor();
|
2017-12-07 23:41:15 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
void VisualNavbar::mousePressEvent(QMouseEvent *event)
|
2017-12-07 23:41:15 +00:00
|
|
|
{
|
|
|
|
qreal x = event->localPos().x();
|
2017-12-08 12:21:24 +00:00
|
|
|
RVA address = localXToAddress(x);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (address != RVA_INVALID) {
|
2017-12-09 23:22:16 +00:00
|
|
|
QToolTip::showText(event->globalPos(), toolTipForAddress(address), this);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (event->buttons() & Qt::LeftButton) {
|
2017-12-09 23:22:16 +00:00
|
|
|
event->accept();
|
|
|
|
Core()->seek(address);
|
|
|
|
}
|
2017-12-08 12:21:24 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualNavbar::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
mousePressEvent(event);
|
2017-12-08 12:21:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
RVA VisualNavbar::localXToAddress(double x)
|
2017-12-08 12:21:24 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto x2a : xToAddress) {
|
|
|
|
if ((x2a.x_start <= x) && (x <= x2a.x_end)) {
|
2017-12-07 23:41:15 +00:00
|
|
|
double offset = (x - x2a.x_start) / (x2a.x_end - x2a.x_start);
|
|
|
|
double size = x2a.address_to - x2a.address_from;
|
2017-12-08 12:21:24 +00:00
|
|
|
return x2a.address_from + (offset * size);
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 15:00:52 +00:00
|
|
|
return RVA_INVALID;
|
2017-12-08 12:21:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 15:00:52 +00:00
|
|
|
double VisualNavbar::addressToLocalX(RVA address)
|
2017-12-08 12:21:24 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto x2a : xToAddress) {
|
|
|
|
if ((x2a.address_from <= address) && (address < x2a.address_to)) {
|
2017-12-08 12:21:24 +00:00
|
|
|
double offset = (double)(address - x2a.address_from) / (double)(x2a.address_to - x2a.address_from);
|
|
|
|
double size = x2a.x_end - x2a.x_start;
|
|
|
|
return x2a.x_start + (offset * size);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 12:21:24 +00:00
|
|
|
return nan("");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
|
|
|
|
QList<QString> VisualNavbar::sectionsForAddress(RVA address)
|
|
|
|
{
|
|
|
|
QList<QString> ret;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto mappedSegment : mappedSegments) {
|
|
|
|
for (auto section : mappedSegment.sectionDescriptions) {
|
|
|
|
if ((section.vaddr <= address) && (address <= section.vaddr + section.vsize)) {
|
2017-12-09 23:22:16 +00:00
|
|
|
ret.append(section.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VisualNavbar::toolTipForAddress(RVA address)
|
|
|
|
{
|
2017-12-10 18:12:22 +00:00
|
|
|
QString ret = "Address: " + RAddressString(address);
|
2017-12-09 23:22:16 +00:00
|
|
|
auto sections = sectionsForAddress(address);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (sections.count()) {
|
2017-12-10 18:12:22 +00:00
|
|
|
ret += "\nSections: \n";
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto section : sections) {
|
2017-12-10 18:12:22 +00:00
|
|
|
ret += " " + section + "\n";
|
|
|
|
}
|
2017-12-09 23:22:16 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|