2017-10-12 19:55:15 +00:00
|
|
|
|
|
|
|
#include "HexdumpWidget.h"
|
|
|
|
#include "ui_HexdumpWidget.h"
|
2017-09-28 21:53:59 +00:00
|
|
|
#include "DisassemblerGraphView.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-11-20 20:11:56 +00:00
|
|
|
#include "utils/TempConfig.h"
|
2017-12-03 20:01:11 +00:00
|
|
|
#include "utils/SvgIconEngine.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QFontDialog>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QUrl>
|
2017-04-13 15:14:02 +00:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
#include <cassert>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
const int HexdumpWidget::linesMarginMin = 32;
|
|
|
|
const int HexdumpWidget::linesMarginDefault = 48;
|
|
|
|
const int HexdumpWidget::linesMarginMax = 64;
|
2017-11-15 21:42:39 +00:00
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
HexdumpWidget::HexdumpWidget(QWidget *parent, Qt::WindowFlags flags) :
|
|
|
|
QDockWidget(parent, flags),
|
2017-11-15 21:42:39 +00:00
|
|
|
ui(new Ui::HexdumpWidget)
|
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
|
|
|
//this->on_actionSettings_menu_1_triggered();
|
|
|
|
|
|
|
|
// Setup hex highlight
|
|
|
|
//connect(ui->hexHexText, SIGNAL(cursorPositionChanged()), this, SLOT(highlightHexCurrentLine()));
|
|
|
|
//highlightHexCurrentLine();
|
|
|
|
|
2017-12-03 20:01:11 +00:00
|
|
|
ui->copyMD5->setIcon(QIcon(new SvgIconEngine(QString(":/img/icons/transfer.svg"), palette().buttonText().color())));
|
|
|
|
ui->copySHA1->setIcon(QIcon(new SvgIconEngine(QString(":/img/icons/transfer.svg"), palette().buttonText().color())));
|
|
|
|
|
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);
|
|
|
|
|
2017-11-20 10:10:31 +00:00
|
|
|
setupFonts();
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
2017-11-04 11:46:29 +00:00
|
|
|
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
|
|
|
|
|
|
|
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
|
|
|
if (visibility)
|
|
|
|
{
|
|
|
|
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]() {
|
|
|
|
refresh(Core()->getOffset());
|
|
|
|
});
|
|
|
|
|
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-10-12 19:55:15 +00:00
|
|
|
HexdumpWidget::HexdumpWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: HexdumpWidget(parent, flags)
|
2017-07-11 11:05:42 +00:00
|
|
|
{
|
2017-10-12 19:55:15 +00:00
|
|
|
setWindowTitle(title);
|
2017-07-11 11:05:42 +00:00
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2017-10-12 19:55:15 +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,
|
|
|
|
* so QPlainTextEdit::cursorPositionChanged has to be connected as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
auto offsetHexFunc = [this]() {
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(ui->hexOffsetText->verticalScrollBar()->value());
|
|
|
|
};
|
|
|
|
|
|
|
|
auto offsetASCIIFunc = [this]() {
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(ui->hexOffsetText->verticalScrollBar()->value());
|
|
|
|
};
|
|
|
|
|
|
|
|
connect(ui->hexOffsetText->verticalScrollBar(), &QScrollBar::valueChanged, ui->hexHexText->verticalScrollBar(), offsetHexFunc);
|
|
|
|
connect(ui->hexOffsetText, &QPlainTextEdit::cursorPositionChanged, ui->hexHexText->verticalScrollBar(), offsetHexFunc);
|
|
|
|
connect(ui->hexOffsetText->verticalScrollBar(), &QScrollBar::valueChanged, ui->hexASCIIText->verticalScrollBar(), offsetASCIIFunc);
|
|
|
|
connect(ui->hexOffsetText, &QPlainTextEdit::cursorPositionChanged, ui->hexASCIIText->verticalScrollBar(), offsetASCIIFunc);
|
|
|
|
|
|
|
|
|
|
|
|
auto hexOffsetFunc = [this]() {
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
};
|
|
|
|
|
|
|
|
auto hexASCIIFunc = [this]() {
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(ui->hexHexText->verticalScrollBar()->value());
|
|
|
|
};
|
|
|
|
|
|
|
|
connect(ui->hexHexText->verticalScrollBar(), &QScrollBar::valueChanged, ui->hexOffsetText->verticalScrollBar(), hexOffsetFunc);
|
|
|
|
connect(ui->hexHexText, &QPlainTextEdit::cursorPositionChanged, ui->hexOffsetText->verticalScrollBar(), hexOffsetFunc);
|
|
|
|
connect(ui->hexHexText->verticalScrollBar(), &QScrollBar::valueChanged, ui->hexASCIIText->verticalScrollBar(), hexASCIIFunc);
|
|
|
|
connect(ui->hexHexText, &QPlainTextEdit::cursorPositionChanged, ui->hexASCIIText->verticalScrollBar(), hexASCIIFunc);
|
|
|
|
|
|
|
|
|
|
|
|
auto asciiOffsetFunc = [this]() {
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(ui->hexASCIIText->verticalScrollBar()->value());
|
|
|
|
};
|
|
|
|
|
|
|
|
auto asciiHexFunc = [this]() {
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(ui->hexASCIIText->verticalScrollBar()->value());
|
|
|
|
};
|
|
|
|
|
|
|
|
connect(ui->hexASCIIText->verticalScrollBar(), &QScrollBar::valueChanged, ui->hexOffsetText->verticalScrollBar(), asciiOffsetFunc);
|
|
|
|
connect(ui->hexASCIIText, &QPlainTextEdit::cursorPositionChanged, ui->hexOffsetText->verticalScrollBar(), asciiOffsetFunc);
|
|
|
|
connect(ui->hexASCIIText->verticalScrollBar(), &QScrollBar::valueChanged, ui->hexHexText->verticalScrollBar(), asciiHexFunc);
|
|
|
|
connect(ui->hexASCIIText, &QPlainTextEdit::cursorPositionChanged, ui->hexHexText->verticalScrollBar(), asciiHexFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_seekChanged(RVA addr)
|
2017-04-28 13:09:40 +00:00
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
if (type == CutterCore::MemoryWidgetType::Hexdump)
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
void HexdumpWidget::connectScroll(bool disconnect)
|
|
|
|
{
|
|
|
|
if (disconnect)
|
|
|
|
{
|
2017-11-19 14:09:48 +00:00
|
|
|
this->disconnect(ui->hexASCIIText->verticalScrollBar(), &QScrollBar::valueChanged, this,
|
|
|
|
&HexdumpWidget::adjustHexdumpLines);
|
|
|
|
this->disconnect(ui->hexASCIIText, &QPlainTextEdit::cursorPositionChanged, this,
|
|
|
|
&HexdumpWidget::adjustHexdumpLines);
|
2017-11-17 12:41:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-19 14:09:48 +00:00
|
|
|
connect(ui->hexASCIIText->verticalScrollBar(), &QScrollBar::valueChanged, this,
|
|
|
|
&HexdumpWidget::adjustHexdumpLines);
|
|
|
|
connect(ui->hexASCIIText, &QPlainTextEdit::cursorPositionChanged, this, &HexdumpWidget::adjustHexdumpLines);
|
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
|
|
|
|
*/
|
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();
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::refresh(RVA addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-19 21:21:02 +00:00
|
|
|
updateHeaders();
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
if (addr == RVA_INVALID)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
addr = Core()->getOffset();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 12:56:48 +00:00
|
|
|
int visibleLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText);
|
2017-11-15 21:56:10 +00:00
|
|
|
|
2017-11-15 21:42:39 +00:00
|
|
|
RCoreLocked lcore = Core()->core();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
connectScroll(true);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
|
2017-04-09 17:12:36 +00:00
|
|
|
int cols = lcore->print->cols;
|
2017-11-18 12:56:48 +00:00
|
|
|
RVA marginBytes = static_cast<RVA>(linesMarginDefault) * cols;
|
|
|
|
|
|
|
|
// lower bound of 0
|
|
|
|
if (addr > marginBytes)
|
|
|
|
{
|
|
|
|
topOffset = addr - marginBytes;
|
|
|
|
topOffset = (topOffset / cols) * cols; // align
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
topOffset = 0;
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
int fetchLines = visibleLines + linesMarginDefault * 2;
|
2017-11-16 21:12:44 +00:00
|
|
|
RVA bytes = static_cast<RVA>(fetchLines) * cols;
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-18 12:56:48 +00:00
|
|
|
|
|
|
|
// upper bound of UT64_MAX
|
|
|
|
RVA bytesLeft = UT64_MAX - topOffset;
|
|
|
|
if (bytes > bytesLeft)
|
|
|
|
{
|
|
|
|
bottomOffset = UT64_MAX;
|
|
|
|
topOffset = bottomOffset - bytes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bottomOffset = topOffset + bytes;
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
|
|
|
|
auto hexdump = fetchHexdump(topOffset, bytes);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
ui->hexOffsetText->setPlainText(hexdump[0]);
|
|
|
|
ui->hexHexText->setPlainText(hexdump[1]);
|
|
|
|
ui->hexASCIIText->setPlainText(hexdump[2]);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-19 14:05:47 +00:00
|
|
|
|
|
|
|
int seekLine = static_cast<int>((addr - topOffset) / cols);
|
|
|
|
|
|
|
|
// Move cursors to desired address
|
2017-11-15 21:42:39 +00:00
|
|
|
QTextCursor cur = ui->hexOffsetText->textCursor();
|
2017-11-16 21:12:44 +00:00
|
|
|
cur.movePosition(QTextCursor::Start);
|
2017-11-19 14:05:47 +00:00
|
|
|
cur.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, seekLine);
|
2017-11-16 21:12:44 +00:00
|
|
|
ui->hexOffsetText->setTextCursor(cur);
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-19 14:05:47 +00:00
|
|
|
cur = ui->hexHexText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::Start);
|
|
|
|
cur.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, seekLine);
|
|
|
|
ui->hexHexText->setTextCursor(cur);
|
|
|
|
|
|
|
|
cur = ui->hexASCIIText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::Start);
|
|
|
|
cur.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, seekLine);
|
|
|
|
ui->hexASCIIText->setTextCursor(cur);
|
|
|
|
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(seekLine);
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(seekLine);
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(seekLine);
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2017-11-18 12:56:48 +00:00
|
|
|
connectScroll(false);
|
2017-11-17 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HexdumpWidget::appendHexdumpLines(int lines, bool top)
|
|
|
|
{
|
|
|
|
connectScroll(true);
|
|
|
|
|
|
|
|
int cols = Core()->getConfigi("hex.cols");
|
|
|
|
RVA bytes = static_cast<RVA>(lines) * cols;
|
|
|
|
|
|
|
|
if (top)
|
|
|
|
{
|
2017-11-18 12:56:48 +00:00
|
|
|
if (bytes > topOffset)
|
|
|
|
{
|
|
|
|
bytes = topOffset;
|
|
|
|
if (bytes == 0)
|
|
|
|
{
|
|
|
|
connectScroll(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
topOffset -= bytes;
|
|
|
|
auto hexdump = fetchHexdump(topOffset, bytes);
|
|
|
|
|
|
|
|
int scroll = ui->hexASCIIText->verticalScrollBar()->value();
|
|
|
|
|
|
|
|
QTextCursor cur = ui->hexOffsetText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::Start);
|
|
|
|
cur.insertText(hexdump[0]);
|
|
|
|
|
|
|
|
cur = ui->hexHexText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::Start);
|
|
|
|
cur.insertText(hexdump[1]);
|
|
|
|
|
|
|
|
cur = ui->hexASCIIText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::Start);
|
|
|
|
cur.insertText(hexdump[2]);
|
|
|
|
|
|
|
|
int actualLines = static_cast<int>(bytes / cols);
|
2017-11-18 12:56:48 +00:00
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(actualLines + scroll);
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(actualLines + scroll);
|
2017-11-17 12:41:30 +00:00
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(actualLines + scroll);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-18 12:56:48 +00:00
|
|
|
if (bytes > UT64_MAX - bottomOffset)
|
|
|
|
{
|
|
|
|
bytes = UT64_MAX - bottomOffset;
|
|
|
|
|
|
|
|
if (bytes == 0)
|
|
|
|
{
|
|
|
|
connectScroll(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
auto hexdump = fetchHexdump(bottomOffset, bytes);
|
|
|
|
bottomOffset += bytes;
|
|
|
|
|
|
|
|
QTextCursor cur = ui->hexOffsetText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::End);
|
|
|
|
cur.insertText(hexdump[0]);
|
|
|
|
|
|
|
|
cur = ui->hexHexText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::End);
|
|
|
|
cur.insertText(hexdump[1]);
|
|
|
|
|
|
|
|
cur = ui->hexASCIIText->textCursor();
|
|
|
|
cur.movePosition(QTextCursor::End);
|
|
|
|
cur.insertText(hexdump[2]);
|
|
|
|
}
|
2017-10-12 19:55:15 +00:00
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
connectScroll(false);
|
2017-10-12 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
void HexdumpWidget::removeHexdumpLines(int lines, bool top)
|
|
|
|
{
|
|
|
|
connectScroll(true);
|
|
|
|
|
|
|
|
int cols = Core()->getConfigi("hex.cols");
|
|
|
|
|
|
|
|
std::array<QPlainTextEdit *, 3> edits = { ui->hexOffsetText, ui->hexHexText, ui->hexASCIIText };
|
|
|
|
|
|
|
|
int scroll = ui->hexASCIIText->verticalScrollBar()->value();
|
|
|
|
|
2017-11-18 12:56:48 +00:00
|
|
|
if (top)
|
2017-11-17 12:41:30 +00:00
|
|
|
{
|
2017-11-18 12:56:48 +00:00
|
|
|
for (QPlainTextEdit *edit : edits)
|
2017-11-17 12:41:30 +00:00
|
|
|
{
|
2017-11-18 12:56:48 +00:00
|
|
|
QTextCursor cur = edit->textCursor();
|
2017-11-17 12:41:30 +00:00
|
|
|
cur.movePosition(QTextCursor::Start);
|
|
|
|
cur.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, lines + 1);
|
2017-11-18 12:56:48 +00:00
|
|
|
cur.removeSelectedText();
|
2017-11-17 12:41:30 +00:00
|
|
|
}
|
2017-11-18 12:56:48 +00:00
|
|
|
|
|
|
|
topOffset += lines * cols;
|
|
|
|
|
|
|
|
ui->hexOffsetText->verticalScrollBar()->setValue(scroll - lines);
|
|
|
|
ui->hexHexText->verticalScrollBar()->setValue(scroll - lines);
|
|
|
|
ui->hexASCIIText->verticalScrollBar()->setValue(scroll - lines);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (QPlainTextEdit *edit : edits)
|
2017-11-17 12:41:30 +00:00
|
|
|
{
|
2017-11-18 12:56:48 +00:00
|
|
|
QTextCursor cur = edit->textCursor();
|
2017-11-17 12:41:30 +00:00
|
|
|
cur.movePosition(QTextCursor::End);
|
|
|
|
cur.movePosition(QTextCursor::Up, QTextCursor::KeepAnchor, lines);
|
|
|
|
cur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
|
|
|
|
cur.removeSelectedText();
|
|
|
|
}
|
|
|
|
|
2017-11-18 12:56:48 +00:00
|
|
|
bottomOffset -= lines * cols;
|
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");
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (int i=0; i<cols; i++)
|
|
|
|
{
|
|
|
|
if (i > 0 && ((pairs && !(i&1)) || !pairs))
|
|
|
|
{
|
|
|
|
hexHeader << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
hexHeader << " " << (i & 0xF);
|
|
|
|
|
|
|
|
asciiHeader << (i & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
hexHeader.flush();
|
|
|
|
asciiHeader.flush();
|
|
|
|
|
|
|
|
ui->hexHeaderLabel->setText(hexHeaderString);
|
|
|
|
ui->asciiHeaderLabel->setText(asciiHeaderString);
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
/*
|
|
|
|
* Content management functions
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
std::array<QString, 3> HexdumpWidget::fetchHexdump(RVA offset, RVA bytes)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-20 20:11:56 +00:00
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("scr.color", false);
|
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
QString hexdump = Core()->cmd(QString("px %1 @ %2").arg(QString::number(bytes), QString::number(offset)));
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-12 20:44:05 +00:00
|
|
|
QString offsets;
|
|
|
|
QString hex;
|
|
|
|
QString ascii;
|
2017-03-29 10:18:37 +00:00
|
|
|
int ln = 0;
|
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
for (const QString &line : hexdump.split("\n"))
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-17 12:41:30 +00:00
|
|
|
if (ln++ == 0 || line.trimmed().isEmpty())
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-17 12:41:30 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
int wc = 0;
|
|
|
|
for (const QString a : line.split(" "))
|
|
|
|
{
|
|
|
|
switch (wc++)
|
|
|
|
{
|
2017-10-12 19:55:15 +00:00
|
|
|
case 0:
|
|
|
|
offsets += a + "\n";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
hex += a.trimmed() + "\n";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ascii += a + "\n";
|
|
|
|
break;
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
return { offsets, hex, ascii };
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 14:09:48 +00:00
|
|
|
void HexdumpWidget::adjustHexdumpLines()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
QScrollBar *sb = ui->hexASCIIText->verticalScrollBar();
|
2017-11-18 12:56:48 +00:00
|
|
|
int topMargin = sb->value() - sb->minimum();
|
|
|
|
int bottomMargin = sb->maximum() - sb->value();
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
if (topMargin < linesMarginMin)
|
|
|
|
{
|
|
|
|
int loadLines = linesMarginDefault - topMargin;
|
|
|
|
appendHexdumpLines(loadLines, true);
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
if(bottomMargin < linesMarginMin)
|
|
|
|
{
|
|
|
|
int loadLines = linesMarginDefault - bottomMargin;
|
|
|
|
appendHexdumpLines(loadLines, false);
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-11-17 12:41:30 +00:00
|
|
|
if(topMargin > linesMarginMax)
|
|
|
|
{
|
|
|
|
int removeLines = topMargin - linesMarginDefault;
|
|
|
|
removeHexdumpLines(removeLines, true);
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
2017-11-17 12:41:30 +00:00
|
|
|
|
|
|
|
if(bottomMargin > linesMarginMax)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-17 12:41:30 +00:00
|
|
|
int removeLines = bottomMargin - linesMarginDefault;
|
|
|
|
removeHexdumpLines(removeLines, false);
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 21:12:44 +00:00
|
|
|
void HexdumpWidget::on_hexHexText_selectionChanged()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
// Get selected text
|
2017-11-15 21:42:39 +00:00
|
|
|
QTextCursor cursor(ui->hexHexText->textCursor());
|
2017-03-29 10:18:37 +00:00
|
|
|
QString sel_text = cursor.selectedText();
|
|
|
|
|
2017-12-03 10:50:14 +00:00
|
|
|
sel_text = sel_text.simplified().remove(' ');
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
if (sel_text == "")
|
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexDisasTextEdit->setPlainText("");
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->bytesEntropy->setText("");
|
|
|
|
ui->bytesMD5->setText("");
|
|
|
|
ui->bytesSHA1->setText("");
|
2017-12-03 10:50:14 +00:00
|
|
|
return;
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
|
|
|
|
// Get selected combos
|
|
|
|
QString arch = ui->parseArchComboBox->currentText();
|
|
|
|
QString bits = ui->parseBitsComboBox->currentText();
|
|
|
|
bool bigEndian = ui->parseEndianComboBox->currentIndex() == 1;
|
|
|
|
|
|
|
|
{ // scope for TempConfig
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig
|
|
|
|
.set("asm.arch", arch)
|
|
|
|
.set("asm.bits", bits)
|
|
|
|
.set("cfg.bigendian", bigEndian);
|
|
|
|
|
|
|
|
switch(ui->parseTypeComboBox->currentIndex())
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-12-03 10:50:14 +00:00
|
|
|
case 0: // Disassembly
|
|
|
|
{
|
|
|
|
QStringRef disasBytes = sel_text.leftRef((sel_text.length() / 2) * 2);
|
|
|
|
QString str = "";
|
|
|
|
if (disasBytes.length() > 0)
|
|
|
|
{
|
|
|
|
QString cmd = "pad ";
|
|
|
|
str = Core()->cmd(cmd.append(disasBytes));
|
|
|
|
}
|
|
|
|
ui->hexDisasTextEdit->setPlainText(str);
|
2017-12-02 17:54:00 +00:00
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case 1: // String
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcs@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 2: // Assembler
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pca@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 3: // C byte array
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pc@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 4: // C half-word
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pch@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 5: // C word
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcw@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 6: // C dword
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcd@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 7: // Python
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcp@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 8: // JSON
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcj@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
case 9: // JavaScript
|
|
|
|
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcJ@x:" + sel_text));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ui->hexDisasTextEdit->setPlainText("");
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-03 10:50:14 +00:00
|
|
|
|
|
|
|
// Fill the information tab hashes and entropy
|
|
|
|
ui->bytesMD5->setText(Core()->cmd("ph md5@x:" + sel_text).trimmed());
|
|
|
|
ui->bytesSHA1->setText(Core()->cmd("ph sha1@x:" + sel_text).trimmed());
|
|
|
|
ui->bytesEntropy->setText(Core()->cmd("ph entropy@x:" + sel_text).trimmed());
|
|
|
|
ui->bytesMD5->setCursorPosition(0);
|
|
|
|
ui->bytesSHA1->setCursorPosition(0);
|
|
|
|
|
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
|
|
|
{
|
2017-11-16 21:12:44 +00:00
|
|
|
on_hexHexText_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
|
|
|
{
|
2017-11-16 21:12:44 +00:00
|
|
|
on_hexHexText_selectionChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-11-18 14:33:52 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
/*
|
|
|
|
* Context menu functions
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
menu->addAction(ui->actionHexCopy_Hexpair);
|
|
|
|
menu->addAction(ui->actionHexCopy_ASCII);
|
|
|
|
menu->addAction(ui->actionHexCopy_Text);
|
|
|
|
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);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui->actionHexEdit);
|
|
|
|
menu->addAction(ui->actionHexPaste);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui->actionHexInsert_Hex);
|
|
|
|
menu->addAction(ui->actionHexInsert_String);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
menu->addAction(ui->actionHexCopy_Hexpair);
|
|
|
|
menu->addAction(ui->actionHexCopy_ASCII);
|
|
|
|
menu->addAction(ui->actionHexCopy_Text);
|
|
|
|
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);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui->actionHexEdit);
|
|
|
|
menu->addAction(ui->actionHexPaste);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(ui->actionHexInsert_Hex);
|
|
|
|
menu->addAction(ui->actionHexInsert_String);
|
|
|
|
|
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-18 14:33:52 +00:00
|
|
|
|
2017-10-11 21:07:32 +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();
|
|
|
|
adjustHexdumpLines();
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:38:10 +00:00
|
|
|
void HexdumpWidget::colorsUpdatedSlot()
|
|
|
|
{
|
|
|
|
QString styleSheet = QString("QPlainTextEdit { background-color: %1; color: %2; }")
|
|
|
|
.arg(ConfigColor("gui.background").name())
|
|
|
|
.arg(ConfigColor("btext").name());
|
|
|
|
|
|
|
|
ui->hexOffsetText->setStyleSheet(styleSheet);
|
|
|
|
ui->hexHexText->setStyleSheet(styleSheet);
|
|
|
|
ui->hexASCIIText->setStyleSheet(styleSheet);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
if (ui->hexSideTab_2->isVisible())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideTab_2->hide();
|
2017-04-09 19:55:06 +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_actionSend_to_Notepad_triggered()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
QTextCursor cursor = ui->disasTextEdit_2->textCursor();
|
|
|
|
QString text = cursor.selectedText();
|
2017-10-09 18:08:35 +00:00
|
|
|
// TODO
|
|
|
|
// this->main->sendToNotepad(text);
|
2017-10-11 21:07:32 +00:00
|
|
|
}*/
|
2017-03-29 10:18:37 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-12-03 11:47:26 +00:00
|
|
|
void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-12-03 10:50:14 +00:00
|
|
|
if (ui->parseTypeComboBox->currentIndex() == 0)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideFrame_2->show();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideFrame_2->hide();
|
|
|
|
}
|
2017-12-03 01:44:12 +00:00
|
|
|
on_hexHexText_selectionChanged();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 11:47:26 +00:00
|
|
|
void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &)
|
2017-12-03 10:50:14 +00:00
|
|
|
{
|
|
|
|
on_hexHexText_selectionChanged();
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
QString HexdumpWidget::normalize_addr(QString addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
QString base = Core()->cmd("s").split("0x")[1].trimmed();
|
2017-03-29 10:18:37 +00:00
|
|
|
int len = base.length();
|
2017-04-09 19:55:06 +00:00
|
|
|
if (len < 8)
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
int padding = 8 - len;
|
|
|
|
QString zero = "0";
|
|
|
|
QString zeroes = zero.repeated(padding);
|
|
|
|
QString s = "0x" + zeroes + base;
|
|
|
|
return s;
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-24 06:49:35 +00:00
|
|
|
return addr.trimmed();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
QString HexdumpWidget::normalizeAddr(QString addr)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
QString base = addr.split("0x")[1].trimmed();
|
|
|
|
int len = base.length();
|
2017-04-09 19:55:06 +00:00
|
|
|
if (len < 8)
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
int padding = 8 - len;
|
|
|
|
QString zero = "0";
|
|
|
|
QString zeroes = zero.repeated(padding);
|
|
|
|
QString s = "0x" + zeroes + base;
|
|
|
|
return s;
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:55:15 +00:00
|
|
|
void HexdumpWidget::on_memSideToolButton_clicked()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
if (ui->memSideToolButton->isChecked())
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideTab_2->hide();
|
2017-06-15 09:53:10 +00:00
|
|
|
ui->memSideToolButton->setIcon(QIcon(":/img/icons/left_light.svg"));
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
ui->hexSideTab_2->show();
|
2017-06-15 09:53:10 +00:00
|
|
|
ui->memSideToolButton->setIcon(QIcon(":/img/icons/right_light.svg"));
|
2017-03-29 10:18:37 +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);
|
2017-11-19 14:09:48 +00:00
|
|
|
|
|
|
|
adjustHexdumpLines();
|
2017-04-10 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 13:17:24 +00:00
|
|
|
void HexdumpWidget::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
|
|
|
if( Qt::ControlModifier == event->modifiers() )
|
|
|
|
{
|
|
|
|
const QPoint numDegrees = event->angleDelta() / 8;
|
|
|
|
if(!numDegrees.isNull())
|
|
|
|
{
|
|
|
|
const QPoint numSteps = numDegrees / 15;
|
|
|
|
if( 0 != numSteps.y() )
|
|
|
|
{
|
|
|
|
if(numSteps.y() > 0)
|
|
|
|
{
|
|
|
|
zoomIn(1);
|
|
|
|
}
|
|
|
|
else if( numSteps.y() < 0 )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
2017-11-15 21:42:39 +00:00
|
|
|
QString arch = Core()->cmd("e asm.arch").trimmed();
|
|
|
|
QString bits = Core()->cmd("e asm.bits").trimmed();
|
2017-03-30 09:27:43 +00:00
|
|
|
|
|
|
|
//int arch_index = ui->hexArchComboBox_2->findText(arch);
|
2017-12-03 10:50:14 +00:00
|
|
|
if (ui->parseArchComboBox->findText(arch) != -1)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-12-03 10:50:14 +00:00
|
|
|
ui->parseArchComboBox->setCurrentIndex(ui->parseArchComboBox->findText(arch));
|
2017-03-30 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//int bits_index = ui->hexBitsComboBox_2->findText(bits);
|
2017-12-03 10:50:14 +00:00
|
|
|
if (ui->parseBitsComboBox->findText(bits) != -1)
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
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
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
{
|
2017-11-15 21:42:39 +00:00
|
|
|
ui->hexOffsetText->show();
|
|
|
|
Core()->setConfig("asm.offset", 1);
|
2017-09-27 20:23:18 +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);
|
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);
|
2017-11-08 13:17:24 +00:00
|
|
|
}
|