2017-10-12 19:55:15 +00:00
|
|
|
#include "HexdumpWidget.h"
|
|
|
|
#include "ui_HexdumpWidget.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Helpers.h"
|
|
|
|
#include "common/Configuration.h"
|
|
|
|
#include "common/TempConfig.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include <QTextDocumentFragment>
|
2017-03-29 10:18:37 +00:00
|
|
|
#include <QMenu>
|
2018-01-27 10:08:05 +00:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QScrollBar>
|
2017-11-15 21:42:39 +00:00
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
|
2018-03-21 20:32:32 +00:00
|
|
|
CutterDockWidget(main, action),
|
2018-05-25 14:30:59 +00:00
|
|
|
ui(new Ui::HexdumpWidget),
|
|
|
|
seekable(new CutterSeekableWidget(this))
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-07-11 11:05:42 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
// Setup hex highlight
|
|
|
|
//connect(ui->hexHexText, SIGNAL(cursorPositionChanged()), this, SLOT(highlightHexCurrentLine()));
|
|
|
|
//highlightHexCurrentLine();
|
|
|
|
|
2018-10-21 17:07:02 +00:00
|
|
|
ui->copyMD5->setIcon(QIcon(":/img/icons/copy.svg"));
|
|
|
|
ui->copySHA1->setIcon(QIcon(":/img/icons/copy.svg"));
|
2017-12-03 20:01:11 +00:00
|
|
|
|
2017-11-19 21:21:02 +00:00
|
|
|
int margin = static_cast<int>(ui->hexOffsetText->document()->documentMargin());
|
|
|
|
ui->offsetHeaderLabel->setContentsMargins(margin, 0, margin, 0);
|
|
|
|
|
|
|
|
margin = static_cast<int>(ui->hexHexText->document()->documentMargin());
|
|
|
|
ui->hexHeaderLabel->setContentsMargins(margin, 0, margin, 0);
|
|
|
|
|
|
|
|
margin = static_cast<int>(ui->hexASCIIText->document()->documentMargin());
|
|
|
|
ui->asciiHeaderLabel->setContentsMargins(margin, 0, margin, 0);
|
|
|
|
|
2018-10-18 19:36:46 +00:00
|
|
|
ui->splitter->setChildrenCollapsible(false);
|
|
|
|
|
|
|
|
QToolButton *closeButton = new QToolButton;
|
2018-10-21 17:07:02 +00:00
|
|
|
QIcon closeIcon = QIcon(":/img/icons/delete.svg");
|
2018-10-18 19:36:46 +00:00
|
|
|
closeButton->setIcon(closeIcon);
|
2018-10-21 17:07:02 +00:00
|
|
|
closeButton->setAutoRaise(true);
|
2018-10-18 19:36:46 +00:00
|
|
|
ui->hexSideTab_2->setCornerWidget(closeButton);
|
|
|
|
|
|
|
|
ui->openSideViewB->hide(); // hide button at startup since side view is visible
|
|
|
|
|
|
|
|
connect(closeButton, &QToolButton::clicked, this, [this]{
|
|
|
|
ui->hexSideTab_2->hide();
|
|
|
|
ui->openSideViewB->show();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->openSideViewB, &QToolButton::clicked, this, [this]{
|
|
|
|
ui->hexSideTab_2->show();
|
|
|
|
ui->openSideViewB->hide();
|
|
|
|
});
|
2018-03-05 14:10:17 +00:00
|
|
|
|
2018-10-21 17:07:02 +00:00
|
|
|
ui->bytesMD5->setPlaceholderText("Select bytes to display information");
|
|
|
|
ui->bytesEntropy->setPlaceholderText("Select bytes to display information");
|
|
|
|
ui->bytesSHA1->setPlaceholderText("Select bytes to display information");
|
|
|
|
ui->hexDisasTextEdit->setPlaceholderText("Select bytes to display information");
|
|
|
|
|
2017-11-20 10:10:31 +00:00
|
|
|
setupFonts();
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2018-10-21 17:07:02 +00:00
|
|
|
ui->openSideViewB->setStyleSheet(""
|
|
|
|
"QToolButton {"
|
|
|
|
" border : 0px;"
|
|
|
|
" padding : 0px;"
|
|
|
|
" margin : 0px;"
|
|
|
|
"}"
|
|
|
|
"QToolButton:hover {"
|
|
|
|
" border : 1px solid;"
|
|
|
|
" border-width : 1px;"
|
|
|
|
" border-color : #3daee9"
|
|
|
|
"}");
|
|
|
|
|
2017-11-20 16:38:10 +00:00
|
|
|
colorsUpdatedSlot();
|
2017-11-19 21:21:02 +00:00
|
|
|
updateHeaders();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-05-25 14:30:59 +00:00
|
|
|
this->setWindowTitle(tr("Hexdump"));
|
|
|
|
connect(&syncAction, SIGNAL(triggered(bool)), this, SLOT(toggleSync()));
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
// Set hexdump context menu
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexHexText->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(ui->hexHexText, SIGNAL(customContextMenuRequested(const QPoint &)),
|
2017-03-29 10:18:37 +00:00
|
|
|
this, SLOT(showHexdumpContextMenu(const QPoint &)));
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexASCIIText->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(ui->hexASCIIText, SIGNAL(customContextMenuRequested(const QPoint &)),
|
2017-03-29 10:18:37 +00:00
|
|
|
this, SLOT(showHexASCIIContextMenu(const QPoint &)));
|
|
|
|
|
2017-11-18 14:33:52 +00:00
|
|
|
setupScrollSync();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
// Control Disasm and Hex scroll to add more contents
|
2017-11-17 12:41:30 +00:00
|
|
|
connectScroll(false);
|
2017-04-05 14:03:36 +00:00
|
|
|
|
2017-11-20 10:10:31 +00:00
|
|
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
|
2017-11-20 16:38:10 +00:00
|
|
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
2017-11-20 10:10:31 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this,
|
|
|
|
SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
2017-11-04 11:46:29 +00:00
|
|
|
|
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (visibility) {
|
2017-11-04 11:46:29 +00:00
|
|
|
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Hexdump);
|
|
|
|
}
|
|
|
|
});
|
2017-05-13 18:09:36 +00:00
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
connect(Core(), &CutterCore::refreshAll, this, [this]() {
|
2018-06-27 15:33:21 +00:00
|
|
|
refresh(seekable->getOffset());
|
2017-11-19 12:56:10 +00:00
|
|
|
});
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
connect(ui->hexHexText, &QTextEdit::selectionChanged, this, &HexdumpWidget::selectionChanged);
|
|
|
|
connect(ui->hexASCIIText, &QTextEdit::selectionChanged, this, &HexdumpWidget::selectionChanged);
|
|
|
|
connect(ui->hexHexText, &QTextEdit::cursorPositionChanged, this, &HexdumpWidget::selectionChanged);
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(ui->hexASCIIText, &QTextEdit::cursorPositionChanged, this,
|
|
|
|
&HexdumpWidget::selectionChanged);
|
2018-05-25 14:30:59 +00:00
|
|
|
connect(seekable, &CutterSeekableWidget::seekChanged, this, &HexdumpWidget::on_seekChanged);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
|
|
|
format = Format::Hex;
|
2017-12-03 10:50:14 +00:00
|
|
|
initParsing();
|
2017-12-03 01:44:12 +00:00
|
|
|
selectHexPreview();
|
2017-04-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 14:33:52 +00:00
|
|
|
void HexdumpWidget::setupScrollSync()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For some reason, QScrollBar::valueChanged is not emitted when
|
|
|
|
* the scrolling happened from moving the cursor beyond the visible content,
|
2018-01-27 10:08:05 +00:00
|
|
|
* so QTextEdit::cursorPositionChanged has to be connected as well.
|
2017-11-18 14:33:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
auto offsetHexFunc = [this]() {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = true;
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(ui->hexOffsetText->verticalScrollBar()->value());
|
|
|
|
scroll_disabled = false;
|
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto offsetASCIIFunc = [this]() {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = true;
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(ui->hexOffsetText->verticalScrollBar()->value());
|
|
|
|
scroll_disabled = false;
|
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
};
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(ui->hexOffsetText->verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
ui->hexHexText->verticalScrollBar(), offsetHexFunc);
|
|
|
|
connect(ui->hexOffsetText, &QTextEdit::cursorPositionChanged, ui->hexHexText->verticalScrollBar(),
|
|
|
|
offsetHexFunc);
|
|
|
|
connect(ui->hexOffsetText->verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
ui->hexASCIIText->verticalScrollBar(), offsetASCIIFunc);
|
|
|
|
connect(ui->hexOffsetText, &QTextEdit::cursorPositionChanged, ui->hexASCIIText->verticalScrollBar(),
|
|
|
|
offsetASCIIFunc);
|
2017-11-18 14:33:52 +00:00
|
|
|
|
|
|
|
auto hexOffsetFunc = [this]() {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = true;
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
scroll_disabled = false;
|
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto hexASCIIFunc = [this]() {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = true;
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
scroll_disabled = false;
|
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
};
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(ui->hexHexText->verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
ui->hexOffsetText->verticalScrollBar(), hexOffsetFunc);
|
|
|
|
connect(ui->hexHexText, &QTextEdit::cursorPositionChanged, ui->hexOffsetText->verticalScrollBar(),
|
|
|
|
hexOffsetFunc);
|
|
|
|
connect(ui->hexHexText->verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
ui->hexASCIIText->verticalScrollBar(), hexASCIIFunc);
|
|
|
|
connect(ui->hexHexText, &QTextEdit::cursorPositionChanged, ui->hexASCIIText->verticalScrollBar(),
|
|
|
|
hexASCIIFunc);
|
2017-11-18 14:33:52 +00:00
|
|
|
|
|
|
|
auto asciiOffsetFunc = [this]() {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = true;
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(ui->hexASCIIText->verticalScrollBar()->value());
|
|
|
|
scroll_disabled = false;
|
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto asciiHexFunc = [this]() {
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = true;
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(ui->hexASCIIText->verticalScrollBar()->value());
|
|
|
|
scroll_disabled = false;
|
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
};
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(ui->hexASCIIText->verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
ui->hexOffsetText->verticalScrollBar(), asciiOffsetFunc);
|
|
|
|
connect(ui->hexASCIIText, &QTextEdit::cursorPositionChanged, ui->hexOffsetText->verticalScrollBar(),
|
|
|
|
asciiOffsetFunc);
|
|
|
|
connect(ui->hexASCIIText->verticalScrollBar(), &QScrollBar::valueChanged,
|
|
|
|
ui->hexHexText->verticalScrollBar(), asciiHexFunc);
|
|
|
|
connect(ui->hexASCIIText, &QTextEdit::cursorPositionChanged, ui->hexHexText->verticalScrollBar(),
|
|
|
|
asciiHexFunc);
|
2017-11-18 14:33:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_seekChanged(RVA addr)
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (sent_seek) {
|
2018-01-27 10:08:05 +00:00
|
|
|
sent_seek = false;
|
|
|
|
return;
|
|
|
|
}
|
2017-10-12 19:55:15 +00:00
|
|
|
refresh(addr);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 11:46:29 +00:00
|
|
|
void HexdumpWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (type == CutterCore::MemoryWidgetType::Hexdump) {
|
2017-11-04 11:46:29 +00:00
|
|
|
raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
void HexdumpWidget::connectScroll(bool disconnect_)
|
2017-11-17 12:41:30 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
scroll_disabled = disconnect_;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (disconnect_) {
|
2018-01-27 10:08:05 +00:00
|
|
|
disconnect(ui->hexHexText->verticalScrollBar(), &QScrollBar::valueChanged, this,
|
2018-03-21 20:32:32 +00:00
|
|
|
&HexdumpWidget::scrollChanged);
|
2018-01-27 10:08:05 +00:00
|
|
|
disconnect(ui->hexHexText, &QTextEdit::cursorPositionChanged, this, &HexdumpWidget::scrollChanged);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-01-27 10:08:05 +00:00
|
|
|
connect(ui->hexHexText->verticalScrollBar(), &QScrollBar::valueChanged, this,
|
|
|
|
&HexdumpWidget::scrollChanged);
|
|
|
|
connect(ui->hexHexText, &QTextEdit::cursorPositionChanged, this, &HexdumpWidget::scrollChanged);
|
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
HexdumpWidget::~HexdumpWidget() {}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
/*
|
|
|
|
* Text highlight functions
|
2018-01-27 10:08:05 +00:00
|
|
|
* Currently unused
|
2017-03-29 10:18:37 +00:00
|
|
|
*/
|
2018-01-27 10:08:05 +00:00
|
|
|
/*
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::highlightHexCurrentLine()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
if (!ui->hexHexText->isReadOnly())
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
QTextEdit::ExtraSelection selection;
|
|
|
|
|
|
|
|
QColor lineColor = QColor(190, 144, 212);
|
|
|
|
|
|
|
|
selection.format.setBackground(lineColor);
|
|
|
|
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
2017-11-15 21:42:39 +00:00
|
|
|
selection.cursor = ui->hexHexText->textCursor();
|
2017-03-29 10:18:37 +00:00
|
|
|
selection.cursor.clearSelection();
|
|
|
|
extraSelections.append(selection);
|
|
|
|
}
|
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
QTextCursor cursor = ui->hexHexText->textCursor();
|
2017-03-29 10:18:37 +00:00
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
|
|
|
|
QTextEdit::ExtraSelection currentWord;
|
|
|
|
|
|
|
|
QColor blueColor = QColor(Qt::blue).lighter(160);
|
|
|
|
currentWord.format.setBackground(blueColor);
|
|
|
|
|
|
|
|
currentWord.cursor = cursor;
|
|
|
|
extraSelections.append(currentWord);
|
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexHexText->setExtraSelections(extraSelections);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
highlightHexWords(cursor.selectedText());
|
|
|
|
}
|
|
|
|
|
2017-11-18 14:33:52 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::highlightHexWords(const QString &str)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
QString searchString = str;
|
2017-11-15 21:42:39 +00:00
|
|
|
QTextDocument *document = ui->hexHexText->document();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
document->undo();
|
|
|
|
|
|
|
|
QTextCursor highlightCursor(document);
|
|
|
|
QTextCursor cursor(document);
|
|
|
|
|
|
|
|
cursor.beginEditBlock();
|
|
|
|
|
|
|
|
QColor blueColor = QColor(Qt::blue).lighter(160);
|
|
|
|
|
|
|
|
QTextCharFormat plainFormat(highlightCursor.charFormat());
|
|
|
|
QTextCharFormat colorFormat = plainFormat;
|
|
|
|
colorFormat.setBackground(blueColor);
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
while (!highlightCursor.isNull() && !highlightCursor.atEnd())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords);
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
if (!highlightCursor.isNull())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
highlightCursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
highlightCursor.mergeCharFormat(colorFormat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor.endEditBlock();
|
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
*/
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::refresh(RVA addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
connectScroll(true);
|
|
|
|
|
2017-11-19 21:21:02 +00:00
|
|
|
updateHeaders();
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (addr == RVA_INVALID) {
|
2018-05-25 14:30:59 +00:00
|
|
|
addr = seekable->getOffset();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 20:15:33 +00:00
|
|
|
cols = Core()->getConfigi("hex.cols");
|
|
|
|
// Avoid divison by 0
|
|
|
|
if (cols == 0)
|
|
|
|
cols = 16;
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
// TODO: Figure out how to calculate a sane value for this
|
|
|
|
bufferLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText);
|
2017-11-18 12:56:48 +00:00
|
|
|
|
2018-05-05 13:20:14 +00:00
|
|
|
ut64 loadLines = bufferLines * 3; // total lines to load
|
|
|
|
ut64 curAddrLineOffset = bufferLines; // line number where seek should be
|
2018-04-13 14:48:10 +00:00
|
|
|
|
|
|
|
if (addr < curAddrLineOffset * cols) {
|
|
|
|
curAddrLineOffset = static_cast<int>(addr / cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr > RVA_MAX - curAddrLineOffset * cols) {
|
|
|
|
curAddrLineOffset = static_cast<int>(loadLines - (RVA_MAX - addr) / cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
first_loaded_address = addr - curAddrLineOffset * cols;
|
|
|
|
last_loaded_address = addr + (loadLines - curAddrLineOffset) * cols;
|
|
|
|
|
|
|
|
auto hexdump = fetchHexdump(first_loaded_address, loadLines);
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
ui->hexOffsetText->setText(hexdump[0]);
|
|
|
|
ui->hexHexText->setText(hexdump[1]);
|
2018-07-07 10:01:24 +00:00
|
|
|
ui->hexASCIIText->setPlainText(hexdump[2]);
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2018-04-13 14:48:10 +00:00
|
|
|
QTextCursor cursor(ui->hexHexText->document()->findBlockByLineNumber(curAddrLineOffset));
|
2018-01-27 10:08:05 +00:00
|
|
|
ui->hexHexText->moveCursor(QTextCursor::End);
|
2018-04-13 14:48:10 +00:00
|
|
|
ui->hexHexText->ensureCursorVisible();
|
2018-01-27 10:08:05 +00:00
|
|
|
ui->hexHexText->setTextCursor(cursor);
|
2018-04-13 14:48:10 +00:00
|
|
|
ui->hexHexText->ensureCursorVisible();
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2018-05-13 14:43:38 +00:00
|
|
|
// Set the backgorund color of the current seek
|
|
|
|
QTextCursor offsetCursor(ui->hexOffsetText->document()->findBlockByLineNumber(curAddrLineOffset));
|
|
|
|
QTextBlockFormat formatTmp = offsetCursor.blockFormat();
|
|
|
|
formatTmp.setBackground(QColor(64, 129, 160));
|
|
|
|
offsetCursor.setBlockFormat(formatTmp);
|
2018-05-25 14:30:59 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
updateWidths();
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
// Update other text areas scroll
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
2017-11-17 12:41:30 +00:00
|
|
|
|
|
|
|
connectScroll(false);
|
|
|
|
}
|
2017-11-15 21:56:10 +00:00
|
|
|
|
2017-11-19 21:21:02 +00:00
|
|
|
void HexdumpWidget::updateHeaders()
|
|
|
|
{
|
|
|
|
int cols = Core()->getConfigi("hex.cols");
|
2018-01-27 10:08:05 +00:00
|
|
|
int ascii_cols = cols;
|
2017-11-19 21:21:02 +00:00
|
|
|
bool pairs = Core()->getConfigb("hex.pairs");
|
|
|
|
|
|
|
|
QString hexHeaderString;
|
|
|
|
QString asciiHeaderString;
|
|
|
|
|
|
|
|
QTextStream hexHeader(&hexHeaderString);
|
|
|
|
QTextStream asciiHeader(&asciiHeaderString);
|
|
|
|
|
|
|
|
hexHeader.setIntegerBase(16);
|
|
|
|
hexHeader.setNumberFlags(QTextStream::UppercaseDigits);
|
|
|
|
asciiHeader.setIntegerBase(16);
|
|
|
|
asciiHeader.setNumberFlags(QTextStream::UppercaseDigits);
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
// Custom spacing for the header
|
|
|
|
QString space = " ";
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (format) {
|
2018-01-27 10:08:05 +00:00
|
|
|
case Hex:
|
|
|
|
space = space.repeated(1);
|
|
|
|
break;
|
|
|
|
case Octal:
|
|
|
|
space = space.repeated(2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning() << "Unknown format in hexdump!";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < cols; i++) {
|
|
|
|
if (i > 0 && ((pairs && !(i & 1)) || !pairs)) {
|
2017-11-19 21:21:02 +00:00
|
|
|
hexHeader << " ";
|
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
hexHeader << space << (i & 0xF);
|
|
|
|
}
|
2017-11-19 21:21:02 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < ascii_cols; i++) {
|
2017-11-19 21:21:02 +00:00
|
|
|
asciiHeader << (i & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
hexHeader.flush();
|
|
|
|
asciiHeader.flush();
|
|
|
|
|
|
|
|
ui->hexHeaderLabel->setText(hexHeaderString);
|
|
|
|
ui->asciiHeaderLabel->setText(asciiHeaderString);
|
|
|
|
}
|
|
|
|
|
2017-12-03 10:50:14 +00:00
|
|
|
void HexdumpWidget::initParsing()
|
2017-10-12 19:55:15 +00:00
|
|
|
{
|
|
|
|
// Fill the plugins combo for the hexdump sidebar
|
2017-12-03 10:50:14 +00:00
|
|
|
ui->parseArchComboBox->insertItems(0, Core()->getAsmPluginNames());
|
|
|
|
|
|
|
|
ui->parseEndianComboBox->setCurrentIndex(Core()->getConfigb("cfg.bigendian") ? 1 : 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
std::array<QString, 3> HexdumpWidget::fetchHexdump(RVA addr, int lines)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
// Main bytes to fetch:
|
|
|
|
int bytes = cols * lines;
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
QString command = QString("pxj %1 @%2").arg(
|
2018-03-21 20:32:32 +00:00
|
|
|
QString::number(bytes),
|
|
|
|
RAddressString(addr));
|
2018-01-27 10:08:05 +00:00
|
|
|
QJsonArray byte_array = Core()->cmdj(command).array();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
QString hexText = "";
|
|
|
|
QString offsetText = "";
|
|
|
|
QString asciiText = "";
|
|
|
|
RVA cur_addr = addr;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < lines; i++) {
|
|
|
|
for (int j = 0; j < cols; j++) {
|
2018-01-27 10:08:05 +00:00
|
|
|
int b = byte_array[(i * cols) + j].toInt();
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((j > 0) && (j < cols)) {
|
2018-01-27 10:08:05 +00:00
|
|
|
hexText += " ";
|
|
|
|
}
|
|
|
|
// Non printable
|
2018-03-21 20:32:32 +00:00
|
|
|
if ((b < 0x20) || (b > 0x7E)) {
|
2018-01-27 10:08:05 +00:00
|
|
|
asciiText += ".";
|
|
|
|
} else {
|
|
|
|
asciiText += (char)b;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (format) {
|
2018-01-27 10:08:05 +00:00
|
|
|
case Octal:
|
|
|
|
hexText += QString::number(b, 8).rightJustified(3, '0');
|
|
|
|
break;
|
|
|
|
case Hex:
|
|
|
|
default:
|
|
|
|
hexText += QString::number(b, 16).rightJustified(2, '0');
|
|
|
|
break;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
offsetText += RAddressString(cur_addr) + "\n";
|
|
|
|
hexText += "\n";
|
|
|
|
asciiText += "\n";
|
|
|
|
cur_addr += cols;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 10:29:37 +00:00
|
|
|
return {{offsetText, hexText, asciiText}};
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
void HexdumpWidget::selectionChanged()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (scroll_disabled) {
|
2018-01-27 10:08:05 +00:00
|
|
|
return;
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
connectScroll(true);
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (sender() == ui->hexHexText) {
|
2018-01-27 10:08:05 +00:00
|
|
|
QTextCursor textCursor = ui->hexHexText->textCursor();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!textCursor.hasSelection()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
clearParseWindow();
|
|
|
|
RVA adr = hexPositionToAddress(textCursor.position());
|
|
|
|
int pos = asciiAddressToPosition(adr);
|
|
|
|
setTextEditPosition(ui->hexASCIIText, pos);
|
|
|
|
sent_seek = true;
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(adr);
|
2018-01-27 10:08:05 +00:00
|
|
|
sent_seek = false;
|
|
|
|
connectScroll(false);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
int selectionStart = textCursor.selectionStart();
|
|
|
|
int selectionEnd = textCursor.selectionEnd();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
QChar start = ui->hexHexText->document()->characterAt(selectionStart);
|
|
|
|
QChar end = ui->hexHexText->document()->characterAt(selectionEnd);
|
2017-12-03 10:50:14 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
// This adjusts the selection to make sense with the chosen format
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (format) {
|
2018-01-27 10:08:05 +00:00
|
|
|
case Hex:
|
|
|
|
// Handle the spaces/newlines (if it's at the start, move forward,
|
|
|
|
// if it's at the end, move back)
|
2017-12-03 10:50:14 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!start.isLetterOrNumber()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionStart += 1;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else if (ui->hexHexText->document()->characterAt(selectionStart - 1).isLetterOrNumber()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionStart += 2;
|
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!end.isLetterOrNumber()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionEnd += 1;
|
2017-12-02 17:54:00 +00:00
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
break;
|
|
|
|
case Octal:
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!start.isLetterOrNumber()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionStart += 1;
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!end.isLetterOrNumber()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionEnd += 1;
|
|
|
|
}
|
|
|
|
break;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
// In hextext we have the spaces that we need to somehow handle.
|
|
|
|
RVA startAddress = hexPositionToAddress(selectionStart);
|
|
|
|
RVA endAddress = hexPositionToAddress(selectionEnd);
|
|
|
|
|
|
|
|
updateParseWindow(startAddress, endAddress - startAddress);
|
|
|
|
|
|
|
|
int startPosition = asciiAddressToPosition(startAddress);
|
|
|
|
int endPosition = asciiAddressToPosition(endAddress);
|
|
|
|
QTextCursor targetTextCursor = ui->hexASCIIText->textCursor();
|
|
|
|
targetTextCursor.setPosition(startPosition);
|
|
|
|
targetTextCursor.setPosition(endPosition, QTextCursor::KeepAnchor);
|
|
|
|
ui->hexASCIIText->setTextCursor(targetTextCursor);
|
|
|
|
sent_seek = true;
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(startAddress);
|
2018-01-27 10:08:05 +00:00
|
|
|
sent_seek = false;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-01-27 10:08:05 +00:00
|
|
|
QTextCursor textCursor = ui->hexASCIIText->textCursor();
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!textCursor.hasSelection()) {
|
2018-01-27 10:08:05 +00:00
|
|
|
clearParseWindow();
|
|
|
|
RVA adr = asciiPositionToAddress(textCursor.position());
|
|
|
|
int pos = hexAddressToPosition(adr);
|
|
|
|
setTextEditPosition(ui->hexHexText, pos);
|
|
|
|
connectScroll(false);
|
|
|
|
sent_seek = true;
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(adr);
|
2018-01-27 10:08:05 +00:00
|
|
|
sent_seek = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RVA startAddress = asciiPositionToAddress(textCursor.selectionStart());
|
|
|
|
RVA endAddress = asciiPositionToAddress(textCursor.selectionEnd());
|
|
|
|
|
|
|
|
updateParseWindow(startAddress, endAddress - startAddress);
|
|
|
|
|
|
|
|
int startPosition = hexAddressToPosition(startAddress);
|
|
|
|
int endPosition = hexAddressToPosition(endAddress);
|
|
|
|
|
|
|
|
// End position -1 because the position we get above is for the next
|
|
|
|
// entry, so including the space/newline
|
|
|
|
endPosition -= 1;
|
|
|
|
QTextCursor targetTextCursor = ui->hexHexText->textCursor();
|
|
|
|
targetTextCursor.setPosition(startPosition);
|
|
|
|
targetTextCursor.setPosition(endPosition, QTextCursor::KeepAnchor);
|
|
|
|
ui->hexHexText->setTextCursor(targetTextCursor);
|
|
|
|
sent_seek = true;
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(startAddress);
|
2018-01-27 10:08:05 +00:00
|
|
|
sent_seek = false;
|
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
connectScroll(false);
|
|
|
|
return;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 10:50:14 +00:00
|
|
|
void HexdumpWidget::on_parseArchComboBox_currentTextChanged(const QString &/*arg1*/)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
|
|
|
|
void HexdumpWidget::on_parseBitsComboBox_currentTextChanged(const QString &/*arg1*/)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::showHexdumpContextMenu(const QPoint &pt)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
// Set Hexdump popup menu
|
2017-11-15 21:42:39 +00:00
|
|
|
QMenu *menu = ui->hexHexText->createStandardContextMenu();
|
2017-03-29 10:18:37 +00:00
|
|
|
menu->clear();
|
2017-12-03 20:31:28 +00:00
|
|
|
/*menu->addAction(ui->actionHexCopy_Hexpair);
|
2017-03-29 10:18:37 +00:00
|
|
|
menu->addAction(ui->actionHexCopy_ASCII);
|
|
|
|
menu->addAction(ui->actionHexCopy_Text);
|
2017-12-03 20:31:28 +00:00
|
|
|
menu->addSeparator();*/
|
2018-01-27 10:08:05 +00:00
|
|
|
QMenu *colSubmenu = menu->addMenu(tr("Columns"));
|
2017-03-29 10:18:37 +00:00
|
|
|
colSubmenu->addAction(ui->action4columns);
|
|
|
|
colSubmenu->addAction(ui->action8columns);
|
|
|
|
colSubmenu->addAction(ui->action16columns);
|
|
|
|
colSubmenu->addAction(ui->action32columns);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
|
|
|
QMenu *formatSubmenu = menu->addMenu(tr("Format"));
|
|
|
|
formatSubmenu->addAction(ui->actionFormatHex);
|
|
|
|
formatSubmenu->addAction(ui->actionFormatOctal);
|
2018-05-25 14:30:59 +00:00
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
syncAction.setText(tr("Sync/unsync offset"));
|
|
|
|
menu->addAction(&syncAction);
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
// TODO:
|
|
|
|
// formatSubmenu->addAction(ui->actionFormatHalfWord);
|
|
|
|
// formatSubmenu->addAction(ui->actionFormatWord);
|
|
|
|
// formatSubmenu->addAction(ui->actionFormatQuadWord);
|
|
|
|
// formatSubmenu->addAction(ui->actionFormatEmoji);
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// QMenu *signedIntFormatSubmenu = formatSubmenu->addMenu(tr("Signed integer"));
|
|
|
|
// signedIntFormatSubmenu->addAction(ui->actionFormatSignedInt1);
|
|
|
|
// signedIntFormatSubmenu->addAction(ui->actionFormatSignedInt2);
|
|
|
|
// signedIntFormatSubmenu->addAction(ui->actionFormatSignedInt4);
|
|
|
|
|
2017-12-03 20:31:28 +00:00
|
|
|
/*menu->addSeparator();
|
2017-03-29 10:18:37 +00:00
|
|
|
menu->addAction(ui->actionHexEdit);
|
|
|
|
menu->addAction(ui->actionHexPaste);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui->actionHexInsert_Hex);
|
2017-12-03 20:31:28 +00:00
|
|
|
menu->addAction(ui->actionHexInsert_String);*/
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexHexText->setContextMenuPolicy(Qt::CustomContextMenu);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
menu->exec(ui->hexHexText->mapToGlobal(pt));
|
2017-03-29 10:18:37 +00:00
|
|
|
delete menu;
|
|
|
|
}
|
|
|
|
|
2018-05-25 14:30:59 +00:00
|
|
|
void HexdumpWidget::toggleSync()
|
|
|
|
{
|
|
|
|
QString windowTitle = tr("Hexdump");
|
|
|
|
seekable->toggleSyncWithCore();
|
|
|
|
if (seekable->getSyncWithCore()) {
|
|
|
|
setWindowTitle(windowTitle);
|
|
|
|
} else {
|
|
|
|
setWindowTitle(windowTitle + " (not synced)");
|
|
|
|
seekable->setIndependentOffset(Core()->getOffset());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::showHexASCIIContextMenu(const QPoint &pt)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
// Set Hex ASCII popup menu
|
2017-11-15 21:42:39 +00:00
|
|
|
QMenu *menu = ui->hexASCIIText->createStandardContextMenu();
|
2017-03-29 10:18:37 +00:00
|
|
|
menu->clear();
|
2017-12-03 20:31:28 +00:00
|
|
|
/*menu->addAction(ui->actionHexCopy_Hexpair);
|
2017-03-29 10:18:37 +00:00
|
|
|
menu->addAction(ui->actionHexCopy_ASCII);
|
|
|
|
menu->addAction(ui->actionHexCopy_Text);
|
2017-12-03 20:31:28 +00:00
|
|
|
menu->addSeparator();*/
|
2017-04-09 19:55:06 +00:00
|
|
|
QMenu *colSubmenu = menu->addMenu("Columns");
|
2017-03-29 10:18:37 +00:00
|
|
|
colSubmenu->addAction(ui->action4columns);
|
|
|
|
colSubmenu->addAction(ui->action8columns);
|
|
|
|
colSubmenu->addAction(ui->action16columns);
|
|
|
|
colSubmenu->addAction(ui->action32columns);
|
2017-12-03 20:31:28 +00:00
|
|
|
/*menu->addSeparator();
|
2017-03-29 10:18:37 +00:00
|
|
|
menu->addAction(ui->actionHexEdit);
|
|
|
|
menu->addAction(ui->actionHexPaste);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui->actionHexInsert_Hex);
|
2017-12-03 20:31:28 +00:00
|
|
|
menu->addAction(ui->actionHexInsert_String);*/
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexASCIIText->setContextMenuPolicy(Qt::CustomContextMenu);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
menu->exec(ui->hexASCIIText->mapToGlobal(pt));
|
2017-03-29 10:18:37 +00:00
|
|
|
delete menu;
|
|
|
|
}
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2017-11-20 10:10:31 +00:00
|
|
|
void HexdumpWidget::setupFonts()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-20 10:10:31 +00:00
|
|
|
QFont font = Config()->getFont();
|
2017-11-19 21:21:02 +00:00
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexOffsetText->setFont(font);
|
|
|
|
ui->hexHexText->setFont(font);
|
|
|
|
ui->hexASCIIText->setFont(font);
|
2017-11-19 21:21:02 +00:00
|
|
|
|
|
|
|
ui->offsetHeaderLabel->setFont(font);
|
|
|
|
ui->hexHeaderLabel->setFont(font);
|
|
|
|
ui->asciiHeaderLabel->setFont(font);
|
2017-11-26 21:54:44 +00:00
|
|
|
|
|
|
|
ui->hexDisasTextEdit->setFont(font);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 10:10:31 +00:00
|
|
|
void HexdumpWidget::fontsUpdated()
|
|
|
|
{
|
|
|
|
setupFonts();
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:38:10 +00:00
|
|
|
void HexdumpWidget::colorsUpdatedSlot()
|
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::clearParseWindow()
|
|
|
|
{
|
|
|
|
ui->hexDisasTextEdit->setPlainText("");
|
|
|
|
ui->bytesEntropy->setText("");
|
|
|
|
ui->bytesMD5->setText("");
|
|
|
|
ui->bytesSHA1->setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::updateParseWindow(RVA start_address, int size)
|
|
|
|
{
|
|
|
|
|
|
|
|
QString address = RAddressString(start_address);
|
|
|
|
|
2018-01-27 13:11:30 +00:00
|
|
|
QString argument = QString("%1@" + address).arg(size);
|
2018-01-27 10:08:05 +00:00
|
|
|
// Get selected combos
|
|
|
|
QString arch = ui->parseArchComboBox->currentText();
|
|
|
|
QString bits = ui->parseBitsComboBox->currentText();
|
|
|
|
bool bigEndian = ui->parseEndianComboBox->currentIndex() == 1;
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
{
|
|
|
|
// scope for TempConfig
|
2018-01-27 10:08:05 +00:00
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig
|
2018-03-21 20:32:32 +00:00
|
|
|
.set("asm.arch", arch)
|
|
|
|
.set("asm.bits", bits)
|
|
|
|
.set("cfg.bigendian", bigEndian);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (ui->parseTypeComboBox->currentIndex()) {
|
|
|
|
case 0: // Disassembly
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pda " + argument));
|
|
|
|
break;
|
|
|
|
case 1: // String
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcs " + argument));
|
|
|
|
break;
|
|
|
|
case 2: // Assembler
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pca " + argument));
|
|
|
|
break;
|
|
|
|
case 3: // C byte array
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pc " + argument));
|
|
|
|
break;
|
|
|
|
case 4: // C half-word
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pch " + argument));
|
|
|
|
break;
|
|
|
|
case 5: // C word
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcw " + argument));
|
|
|
|
break;
|
|
|
|
case 6: // C dword
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcd " + argument));
|
|
|
|
break;
|
|
|
|
case 7: // Python
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcp " + argument));
|
|
|
|
break;
|
|
|
|
case 8: // JSON
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcj " + argument));
|
|
|
|
break;
|
|
|
|
case 9: // JavaScript
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcJ " + argument));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ui->hexDisasTextEdit->setPlainText("");
|
2018-01-27 10:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill the information tab hashes and entropy
|
|
|
|
ui->bytesMD5->setText(Core()->cmd("ph md5 " + argument).trimmed());
|
|
|
|
ui->bytesSHA1->setText(Core()->cmd("ph sha1 " + argument).trimmed());
|
|
|
|
ui->bytesEntropy->setText(Core()->cmd("ph entropy " + argument).trimmed());
|
|
|
|
ui->bytesMD5->setCursorPosition(0);
|
|
|
|
ui->bytesSHA1->setCursorPosition(0);
|
2017-11-20 16:38:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
RVA HexdumpWidget::hexPositionToAddress(int position)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (format) {
|
2018-01-27 10:08:05 +00:00
|
|
|
|
|
|
|
case Octal:
|
|
|
|
return first_loaded_address + (position / 4);
|
|
|
|
case Hex:
|
|
|
|
default:
|
|
|
|
return first_loaded_address + (position / 3);
|
|
|
|
}
|
|
|
|
return RVA_INVALID;
|
|
|
|
// In hex each byte takes up 2 characters + 1 spacer (including newline as spacer)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RVA HexdumpWidget::asciiPositionToAddress(int position)
|
|
|
|
{
|
|
|
|
// Each row adds one byte (because of the newline), so cols + 1 gets rid of that offset
|
|
|
|
return first_loaded_address + (position - (position / (cols + 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int HexdumpWidget::hexAddressToPosition(RVA address)
|
|
|
|
{
|
|
|
|
// This strictly assumes that the address is actually loaded.
|
2018-03-21 20:32:32 +00:00
|
|
|
switch (format) {
|
2018-01-27 10:08:05 +00:00
|
|
|
|
|
|
|
case Octal:
|
|
|
|
return (address - first_loaded_address) * 4;
|
|
|
|
case Hex:
|
|
|
|
default:
|
|
|
|
return (address - first_loaded_address) * 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int HexdumpWidget::asciiAddressToPosition(RVA address)
|
|
|
|
{
|
|
|
|
RVA local_address = address - first_loaded_address;
|
|
|
|
int position = local_address + (local_address / cols);
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::setTextEditPosition(QTextEdit *textEdit, int position)
|
|
|
|
{
|
|
|
|
QTextCursor textCursor = textEdit->textCursor();
|
|
|
|
textCursor.setPosition(position);
|
|
|
|
textEdit->setTextCursor(textCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
int HexdumpWidget::getDisplayedLined(QTextEdit *textEdit, bool bottom)
|
|
|
|
{
|
2018-01-27 15:10:41 +00:00
|
|
|
//int start_pos = textEdit->cursorForPosition(QPoint(0, 0)).position();
|
2018-01-27 10:08:05 +00:00
|
|
|
QPoint top_right(textEdit->viewport()->x(), textEdit->viewport()->y());
|
|
|
|
QPoint bottom_right(textEdit->viewport()->width(), textEdit->viewport()->height() - 1);
|
|
|
|
QPoint point = top_right;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (bottom) {
|
2018-01-27 10:08:05 +00:00
|
|
|
point = bottom_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCursor textCursor = textEdit->cursorForPosition(point);
|
2018-01-27 15:10:41 +00:00
|
|
|
//QTextBlock textBlock = textCursor.block();
|
|
|
|
//QTextLayout *textLayout = textBlock.layout();
|
|
|
|
//const int relativePos = textCursor.position() - textBlock.position();
|
|
|
|
//int end_pos = textEdit->cursorForPosition(bottom_right).position();
|
2018-01-27 10:08:05 +00:00
|
|
|
return textCursor.blockNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::removeTopLinesWithoutScroll(QTextEdit *textEdit, int lines)
|
|
|
|
{
|
|
|
|
int scroll_val_before = textEdit->verticalScrollBar()->value();
|
|
|
|
int height_before = textEdit->document()->size().height();
|
|
|
|
|
|
|
|
QTextBlock block = textEdit->document()->firstBlock();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < lines; i++) {
|
2018-01-27 10:08:05 +00:00
|
|
|
QTextCursor cursor(block);
|
|
|
|
block = block.next();
|
2018-04-13 09:36:30 +00:00
|
|
|
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);
|
|
|
|
cursor.removeSelectedText();
|
2018-01-27 10:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int height_after = textEdit->document()->size().height();
|
|
|
|
textEdit->verticalScrollBar()->setValue(scroll_val_before + (height_after - height_before));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::removeBottomLinesWithoutScroll(QTextEdit *textEdit, int lines)
|
|
|
|
{
|
2018-04-13 14:48:10 +00:00
|
|
|
QTextBlock block = textEdit->document()->lastBlock().previous();
|
2018-01-27 10:08:05 +00:00
|
|
|
QTextCursor textCursor = textEdit->textCursor();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int i = 0; i < lines; i++) {
|
2018-01-27 10:08:05 +00:00
|
|
|
QTextCursor cursor(block);
|
|
|
|
block = block.previous();
|
2018-04-13 14:48:10 +00:00
|
|
|
cursor.select(QTextCursor::BlockUnderCursor);
|
2018-04-13 10:13:57 +00:00
|
|
|
cursor.removeSelectedText();
|
2018-01-27 10:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::prependWithoutScroll(QTextEdit *textEdit, QString text)
|
|
|
|
{
|
|
|
|
// TODO: Keep selection (already works for append)
|
|
|
|
QTextCursor textCursor = textEdit->textCursor();
|
|
|
|
int current_positon = textCursor.position();
|
|
|
|
|
2018-01-27 15:10:41 +00:00
|
|
|
//int scroll_max_before = textEdit->verticalScrollBar()->maximum();
|
2018-01-27 10:08:05 +00:00
|
|
|
int scroll_val_before = textEdit->verticalScrollBar()->value();
|
|
|
|
int height_before = textEdit->document()->size().height();
|
|
|
|
textEdit->moveCursor(QTextCursor::Start);
|
|
|
|
textEdit->insertPlainText(text);
|
|
|
|
textCursor.setPosition(text.length() + current_positon);
|
|
|
|
textEdit->setTextCursor(textCursor);
|
|
|
|
int height_after = textEdit->document()->size().height();
|
2018-01-27 15:10:41 +00:00
|
|
|
//int scroll_max_after = textEdit->verticalScrollBar()->maximum();
|
|
|
|
//int scroll_val_after = textEdit->verticalScrollBar()->maximum();
|
2018-01-27 10:08:05 +00:00
|
|
|
textEdit->verticalScrollBar()->setValue(scroll_val_before + (height_after - height_before));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::appendWithoutScroll(QTextEdit *textEdit, QString text)
|
|
|
|
{
|
|
|
|
int scroll_val_before = textEdit->verticalScrollBar()->value();
|
|
|
|
QTextCursor textCursor = textEdit->textCursor();
|
|
|
|
textEdit->moveCursor(QTextCursor::End);
|
|
|
|
textEdit->insertPlainText(text);
|
|
|
|
textEdit->setTextCursor(textCursor);
|
|
|
|
textEdit->verticalScrollBar()->setValue(scroll_val_before);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::scrollChanged()
|
|
|
|
{
|
|
|
|
connectScroll(true);
|
|
|
|
|
|
|
|
int firstLine = getDisplayedLined(ui->hexHexText);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (firstLine < (bufferLines / 2)) {
|
2018-04-13 10:13:57 +00:00
|
|
|
int loadLines = bufferLines;
|
|
|
|
RVA shift = static_cast<RVA>(loadLines * cols);
|
|
|
|
if (shift > first_loaded_address) {
|
|
|
|
loadLines = static_cast<int>(first_loaded_address / cols);
|
|
|
|
shift = first_loaded_address;
|
|
|
|
}
|
|
|
|
first_loaded_address -= shift;
|
|
|
|
last_loaded_address -= shift;
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2018-04-13 10:13:57 +00:00
|
|
|
if (loadLines > 0) {
|
|
|
|
auto hexdump = fetchHexdump(first_loaded_address, loadLines);
|
|
|
|
prependWithoutScroll(ui->hexOffsetText, hexdump[0]);
|
|
|
|
prependWithoutScroll(ui->hexHexText, hexdump[1]);
|
|
|
|
prependWithoutScroll(ui->hexASCIIText, hexdump[2]);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2018-04-13 10:13:57 +00:00
|
|
|
removeBottomLinesWithoutScroll(ui->hexOffsetText, loadLines);
|
|
|
|
removeBottomLinesWithoutScroll(ui->hexHexText, loadLines);
|
|
|
|
removeBottomLinesWithoutScroll(ui->hexASCIIText, loadLines);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2018-04-13 10:13:57 +00:00
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int blocks = ui->hexHexText->document()->blockCount();
|
|
|
|
int lastLine = getDisplayedLined(ui->hexHexText, true);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (blocks - lastLine < (bufferLines / 2)) {
|
2018-04-13 10:13:57 +00:00
|
|
|
int loadLines = bufferLines;
|
|
|
|
RVA shift = static_cast<RVA>(loadLines * cols);
|
|
|
|
if (last_loaded_address > RVA_MAX - shift) {
|
|
|
|
shift = RVA_MAX - last_loaded_address;
|
|
|
|
loadLines = static_cast<int>(shift / cols);
|
|
|
|
}
|
2018-04-13 14:48:10 +00:00
|
|
|
|
|
|
|
if (loadLines > 0) {
|
|
|
|
auto hexdump = fetchHexdump(last_loaded_address, loadLines);
|
|
|
|
last_loaded_address += shift;
|
|
|
|
first_loaded_address += shift;
|
|
|
|
|
|
|
|
removeTopLinesWithoutScroll(ui->hexOffsetText, loadLines);
|
|
|
|
removeTopLinesWithoutScroll(ui->hexHexText, loadLines);
|
|
|
|
removeTopLinesWithoutScroll(ui->hexASCIIText, loadLines);
|
|
|
|
appendWithoutScroll(ui->hexOffsetText, hexdump[0]);
|
|
|
|
appendWithoutScroll(ui->hexHexText, hexdump[1]);
|
|
|
|
appendWithoutScroll(ui->hexASCIIText, hexdump[2]);
|
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
}
|
|
|
|
connectScroll(false);
|
|
|
|
}
|
2017-11-20 10:10:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Actions callback functions
|
|
|
|
*/
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_actionHideHexdump_side_panel_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->hexSideTab_2->isVisible()) {
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideTab_2->hide();
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideTab_2->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action8columns_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 8);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action16columns_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 16);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action4columns_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 4);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action32columns_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 32);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action64columns_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 64);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action2columns_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 2);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_action1column_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
Core()->setConfig("hex.cols", 1);
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
void HexdumpWidget::on_actionFormatHex_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
format = Format::Hex;
|
|
|
|
refresh();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
void HexdumpWidget::on_actionFormatOctal_triggered()
|
2017-12-03 10:50:14 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
format = Format::Octal;
|
|
|
|
refresh();
|
2017-12-03 10:50:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->parseTypeComboBox->currentIndex() == 0) {
|
2018-01-27 10:08:05 +00:00
|
|
|
ui->hexSideFrame_2->show();
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-01-27 10:08:05 +00:00
|
|
|
ui->hexSideFrame_2->hide();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-01-27 10:08:05 +00:00
|
|
|
selectionChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_hexSideTab_2_currentChanged(int /*index*/)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (index == 2) {
|
|
|
|
// Add data to HTML Polar functions graph
|
|
|
|
QFile html(":/html/bar.html");
|
|
|
|
if(!html.open(QIODevice::ReadOnly)) {
|
|
|
|
QMessageBox::information(0,"error",html.errorString());
|
|
|
|
}
|
|
|
|
QString code = html.readAll();
|
|
|
|
html.close();
|
|
|
|
this->histoWebView->setHtml(code);
|
|
|
|
this->histoWebView->show();
|
|
|
|
} else {
|
|
|
|
this->histoWebView->hide();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::resizeEvent(QResizeEvent *event)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-04-10 10:25:33 +00:00
|
|
|
QDockWidget::resizeEvent(event);
|
2018-01-27 10:08:05 +00:00
|
|
|
refresh();
|
2017-04-10 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void HexdumpWidget::wheelEvent(QWheelEvent *event)
|
2017-11-08 13:17:24 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if ( Qt::ControlModifier == event->modifiers() ) {
|
2017-11-08 13:17:24 +00:00
|
|
|
const QPoint numDegrees = event->angleDelta() / 8;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!numDegrees.isNull()) {
|
2017-11-08 13:17:24 +00:00
|
|
|
const QPoint numSteps = numDegrees / 15;
|
2018-03-21 20:32:32 +00:00
|
|
|
if ( 0 != numSteps.y() ) {
|
|
|
|
if (numSteps.y() > 0) {
|
2017-11-08 13:17:24 +00:00
|
|
|
zoomIn(1);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else if ( numSteps.y() < 0 ) {
|
2017-11-08 13:17:24 +00:00
|
|
|
zoomOut(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_copyMD5_clicked()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
QString md5 = ui->bytesMD5->text();
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(md5);
|
2017-10-09 18:08:35 +00:00
|
|
|
// FIXME
|
|
|
|
// this->main->addOutput("MD5 copied to clipboard: " + md5);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_copySHA1_clicked()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
QString sha1 = ui->bytesSHA1->text();
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(sha1);
|
2017-10-09 18:08:35 +00:00
|
|
|
// FIXME
|
|
|
|
// this->main->addOutput("SHA1 copied to clipboard: " + sha1);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:08:05 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::selectHexPreview()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-03-30 09:27:43 +00:00
|
|
|
// Pre-select arch and bits in the hexdump sidebar
|
2018-08-14 15:07:52 +00:00
|
|
|
QString arch = Core()->getConfig("asm.arch");
|
|
|
|
QString bits = Core()->getConfig("asm.bits");
|
2017-03-30 09:27:43 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->parseArchComboBox->findText(arch) != -1) {
|
2017-12-03 10:50:14 +00:00
|
|
|
ui->parseArchComboBox->setCurrentIndex(ui->parseArchComboBox->findText(arch));
|
2017-03-30 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (ui->parseBitsComboBox->findText(bits) != -1) {
|
2017-12-03 10:50:14 +00:00
|
|
|
ui->parseBitsComboBox->setCurrentIndex(ui->parseBitsComboBox->findText(bits));
|
2017-03-30 09:27:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-05 09:35:19 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::showOffsets(bool show)
|
2017-09-27 20:23:18 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (show) {
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexOffsetText->show();
|
|
|
|
Core()->setConfig("asm.offset", 1);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexOffsetText->hide();
|
|
|
|
Core()->setConfig("asm.offset", 0);
|
2017-09-01 13:03:35 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-08 13:17:24 +00:00
|
|
|
|
|
|
|
void HexdumpWidget::zoomIn(int range)
|
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexOffsetText->zoomIn(range);
|
|
|
|
ui->hexASCIIText->zoomIn(range);
|
|
|
|
ui->hexHexText->zoomIn(range);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
|
|
|
updateWidths();
|
2017-11-08 13:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::zoomOut(int range)
|
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexOffsetText->zoomOut(range);
|
|
|
|
ui->hexASCIIText->zoomOut(range);
|
|
|
|
ui->hexHexText->zoomOut(range);
|
2018-01-27 10:08:05 +00:00
|
|
|
|
|
|
|
updateWidths();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::updateWidths()
|
|
|
|
{
|
|
|
|
// Update width
|
|
|
|
ui->hexHexText->document()->adjustSize();
|
|
|
|
ui->hexHexText->setFixedWidth(ui->hexHexText->document()->size().width());
|
|
|
|
|
|
|
|
ui->hexOffsetText->document()->adjustSize();
|
|
|
|
ui->hexOffsetText->setFixedWidth(ui->hexOffsetText->document()->size().width());
|
|
|
|
|
|
|
|
ui->hexASCIIText->document()->adjustSize();
|
2018-03-05 14:10:17 +00:00
|
|
|
ui->hexASCIIText->setMinimumWidth(ui->hexASCIIText->document()->size().width());
|
2017-11-08 13:17:24 +00:00
|
|
|
}
|