cutter/src/widgets/HexdumpWidget.cpp

1216 lines
39 KiB
C++
Raw Normal View History

#include "HexdumpWidget.h"
#include "ui_HexdumpWidget.h"
2018-10-17 07:55:53 +00:00
#include "common/Helpers.h"
#include "common/Configuration.h"
#include "common/TempConfig.h"
2018-01-27 10:08:05 +00:00
#include <QJsonObject>
#include <QJsonArray>
#include <QElapsedTimer>
#include <QTextDocumentFragment>
#include <QMenu>
2018-01-27 10:08:05 +00:00
#include <QClipboard>
#include <QScrollBar>
#include <QInputDialog>
2017-11-15 21:42:39 +00:00
HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
2018-03-21 20:32:32 +00:00
CutterDockWidget(main, action),
ui(new Ui::HexdumpWidget),
seekable(new CutterSeekable(this))
{
ui->setupUi(this);
// Setup hex highlight
//connect(ui->hexHexText, SIGNAL(cursorPositionChanged()), this, SLOT(highlightHexCurrentLine()));
//highlightHexCurrentLine();
ui->copyMD5->setIcon(QIcon(":/img/icons/copy.svg"));
ui->copySHA1->setIcon(QIcon(":/img/icons/copy.svg"));
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);
ui->splitter->setChildrenCollapsible(false);
QToolButton *closeButton = new QToolButton;
QIcon closeIcon = QIcon(":/img/icons/delete.svg");
closeButton->setIcon(closeIcon);
closeButton->setAutoRaise(true);
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
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");
setupFonts();
2018-01-27 10:08:05 +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();
this->setWindowTitle(tr("Hexdump"));
connect(&syncAction, SIGNAL(triggered(bool)), this, SLOT(toggleSync()));
2018-01-27 10:08:05 +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 &)),
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 &)),
this, SLOT(showHexASCIIContextMenu(const QPoint &)));
setupScrollSync();
// Control Disasm and Hex scroll to add more contents
2017-11-17 12:41:30 +00:00
connectScroll(false);
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
2017-11-20 16:38:10 +00:00
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
2018-03-21 20:32:32 +00:00
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this,
SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
2018-03-21 20:32:32 +00:00
if (visibility) {
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Hexdump);
}
});
connect(Core(), &CutterCore::refreshAll, this, [this]() {
refresh(seekable->getOffset());
});
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);
connect(seekable, &CutterSeekable::seekableSeekChanged, this, &HexdumpWidget::onSeekChanged);
connect(&rangeDialog, &QDialog::accepted, this, &HexdumpWidget::on_rangeDialogAccepted);
2018-01-27 10:08:05 +00:00
format = Format::Hex;
initParsing();
2017-12-03 01:44:12 +00:00
selectHexPreview();
}
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.
*/
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;
}
};
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;
}
};
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);
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;
}
};
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;
}
};
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);
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;
}
};
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;
}
};
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);
}
void HexdumpWidget::onSeekChanged(RVA addr)
{
2018-03-21 20:32:32 +00:00
if (sent_seek) {
2018-01-27 10:08:05 +00:00
sent_seek = false;
return;
}
if (isVisibleToUser()) {
refreshContent();
}
}
void HexdumpWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type)
{
2018-03-21 20:32:32 +00:00
if (type == CutterCore::MemoryWidgetType::Hexdump) {
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
}
}
HexdumpWidget::~HexdumpWidget() {}
/*
* Text highlight functions
2018-01-27 10:08:05 +00:00
* Currently unused
*/
2018-01-27 10:08:05 +00:00
/*
void HexdumpWidget::highlightHexCurrentLine()
{
QList<QTextEdit::ExtraSelection> extraSelections;
2017-11-15 21:42:39 +00:00
if (!ui->hexHexText->isReadOnly())
2017-04-09 19:55:06 +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();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
2017-11-15 21:42:39 +00:00
QTextCursor cursor = ui->hexHexText->textCursor();
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);
highlightHexWords(cursor.selectedText());
}
void HexdumpWidget::highlightHexWords(const QString &str)
{
QString searchString = str;
2017-11-15 21:42:39 +00:00
QTextDocument *document = ui->hexHexText->document();
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())
{
highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords);
2017-04-09 19:55:06 +00:00
if (!highlightCursor.isNull())
{
highlightCursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
highlightCursor.mergeCharFormat(colorFormat);
}
}
cursor.endEditBlock();
}
2018-01-27 10:08:05 +00:00
*/
void HexdumpWidget::refresh(RVA addr)
2017-04-09 19:55:06 +00:00
{
ut64 loadLines = 0;
ut64 curAddrLineOffset = 0;
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) {
addr = seekable->getOffset();
}
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) * 10;
2017-11-18 12:56:48 +00:00
if (requestedSelectionEndAddress != 0 && requestedSelectionStartAddress != 0
&& requestedSelectionEndAddress > requestedSelectionStartAddress) {
loadLines = ((requestedSelectionEndAddress - requestedSelectionStartAddress) / cols) +
(bufferLines * 2);
curAddrLineOffset = bufferLines;
} else {
loadLines = bufferLines * 3; // total lines to load
curAddrLineOffset = bufferLines; // line number where seek should be
}
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
QTextCursor cursor(ui->hexHexText->document()->findBlockByLineNumber(curAddrLineOffset));
2018-01-27 10:08:05 +00:00
ui->hexHexText->moveCursor(QTextCursor::End);
ui->hexHexText->ensureCursorVisible();
2018-01-27 10:08:05 +00:00
ui->hexHexText->setTextCursor(cursor);
ui->hexHexText->ensureCursorVisible();
2017-11-17 12:41:30 +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-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-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);
}
void HexdumpWidget::initParsing()
{
// Fill the plugins combo for the hexdump sidebar
ui->parseArchComboBox->insertItems(0, Core()->getAsmPluginNames());
ui->parseEndianComboBox->setCurrentIndex(Core()->getConfigb("cfg.bigendian") ? 1 : 0);
}
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;
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();
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;
}
}
2018-01-27 10:08:05 +00:00
offsetText += RAddressString(cur_addr) + "\n";
hexText += "\n";
asciiText += "\n";
cur_addr += cols;
}
return {{offsetText, hexText, asciiText}};
}
2018-01-27 10:08:05 +00:00
void HexdumpWidget::selectionChanged()
{
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;
seekable->seek(adr);
2018-01-27 10:08:05 +00:00
sent_seek = false;
connectScroll(false);
return;
}
2018-01-27 10:08:05 +00:00
int selectionStart = textCursor.selectionStart();
int selectionEnd = textCursor.selectionEnd();
2018-01-27 10:08:05 +00:00
QChar start = ui->hexHexText->document()->characterAt(selectionStart);
QChar end = ui->hexHexText->document()->characterAt(selectionEnd);
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)
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;
}
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;
}
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;
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;
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;
seekable->seek(startAddress);
2018-01-27 10:08:05 +00:00
sent_seek = false;
}
2018-01-27 10:08:05 +00:00
connectScroll(false);
return;
}
void HexdumpWidget::on_parseArchComboBox_currentTextChanged(const QString &/*arg1*/)
{
2018-01-27 10:08:05 +00:00
selectionChanged();
}
void HexdumpWidget::on_parseBitsComboBox_currentTextChanged(const QString &/*arg1*/)
{
2018-01-27 10:08:05 +00:00
selectionChanged();
}
void HexdumpWidget::showHexdumpContextMenu(const QPoint &pt)
{
// Set Hexdump popup menu
2017-11-15 21:42:39 +00:00
QMenu *menu = ui->hexHexText->createStandardContextMenu();
menu->clear();
/*menu->addAction(ui->actionHexCopy_Hexpair);
menu->addAction(ui->actionHexCopy_ASCII);
menu->addAction(ui->actionHexCopy_Text);
menu->addSeparator();*/
2018-01-27 10:08:05 +00:00
QMenu *colSubmenu = menu->addMenu(tr("Columns"));
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);
menu->addAction(ui->actionSelect_Block);
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);
/*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-11-15 21:42:39 +00:00
menu->exec(ui->hexHexText->mapToGlobal(pt));
delete menu;
}
void HexdumpWidget::toggleSync()
{
QString windowTitle = tr("Hexdump");
seekable->toggleSynchronization();
if (seekable->isSynchronized()) {
setWindowTitle(windowTitle);
} else {
setWindowTitle(windowTitle + CutterSeekable::tr(" (unsynced)"));
}
}
void HexdumpWidget::showHexASCIIContextMenu(const QPoint &pt)
{
// Set Hex ASCII popup menu
2017-11-15 21:42:39 +00:00
QMenu *menu = ui->hexASCIIText->createStandardContextMenu();
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");
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-11-15 21:42:39 +00:00
menu->exec(ui->hexASCIIText->mapToGlobal(pt));
delete menu;
}
2017-11-17 12:41:30 +00:00
void HexdumpWidget::setupFonts()
2017-04-09 19:55:06 +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);
ui->hexDisasTextEdit->setFont(font);
}
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();
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)
{
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();
cursor.select(QTextCursor::BlockUnderCursor);
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)) {
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
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
removeBottomLinesWithoutScroll(ui->hexOffsetText, loadLines);
removeBottomLinesWithoutScroll(ui->hexHexText, loadLines);
removeBottomLinesWithoutScroll(ui->hexASCIIText, loadLines);
2018-01-27 10:08:05 +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)) {
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);
}
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);
}
/*
* Actions callback functions
*/
void HexdumpWidget::on_actionHideHexdump_side_panel_triggered()
{
2018-03-21 20:32:32 +00:00
if (ui->hexSideTab_2->isVisible()) {
ui->hexSideTab_2->hide();
2018-03-21 20:32:32 +00:00
} else {
ui->hexSideTab_2->show();
}
}
void HexdumpWidget::on_action8columns_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 8);
refresh();
}
void HexdumpWidget::on_action16columns_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 16);
refresh();
}
void HexdumpWidget::on_action4columns_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 4);
refresh();
}
void HexdumpWidget::on_action32columns_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 32);
refresh();
}
void HexdumpWidget::on_action64columns_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 64);
refresh();
}
void HexdumpWidget::on_action2columns_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 2);
refresh();
}
void HexdumpWidget::on_action1column_triggered()
{
2017-11-15 21:42:39 +00:00
Core()->setConfig("hex.cols", 1);
refresh();
}
2018-01-27 10:08:05 +00:00
void HexdumpWidget::on_actionFormatHex_triggered()
{
2018-01-27 10:08:05 +00:00
format = Format::Hex;
refresh();
}
2018-01-27 10:08:05 +00:00
void HexdumpWidget::on_actionFormatOctal_triggered()
{
2018-01-27 10:08:05 +00:00
format = Format::Octal;
refresh();
}
void HexdumpWidget::on_actionSelect_Block_triggered()
{
//get the current hex address from current cursor location
rangeDialog.setStartAddress(
hexPositionToAddress(ui->hexHexText->textCursor().position()));
rangeDialog.setModal(false);
rangeDialog.show();
rangeDialog.activateWindow();
rangeDialog.raise();
}
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();
}
2018-01-27 10:08:05 +00:00
selectionChanged();
}
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();
}
void HexdumpWidget::on_hexSideTab_2_currentChanged(int /*index*/)
{
/*
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
void HexdumpWidget::resizeEvent(QResizeEvent *event)
2017-04-09 19:55:06 +00:00
{
QDockWidget::resizeEvent(event);
2018-01-27 10:08:05 +00:00
refresh();
}
2018-03-21 20:32:32 +00:00
void HexdumpWidget::wheelEvent(QWheelEvent *event)
{
2018-03-21 20:32:32 +00:00
if ( Qt::ControlModifier == event->modifiers() ) {
const QPoint numDegrees = event->angleDelta() / 8;
2018-03-21 20:32:32 +00:00
if (!numDegrees.isNull()) {
const QPoint numSteps = numDegrees / 15;
2018-03-21 20:32:32 +00:00
if ( 0 != numSteps.y() ) {
if (numSteps.y() > 0) {
zoomIn(1);
2018-03-21 20:32:32 +00:00
} else if ( numSteps.y() < 0 ) {
zoomOut(1);
}
}
}
event->accept();
return;
}
event->ignore();
}
void HexdumpWidget::on_copyMD5_clicked()
{
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);
}
void HexdumpWidget::on_copySHA1_clicked()
{
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);
}
2018-01-27 10:08:05 +00:00
void HexdumpWidget::selectHexPreview()
2017-04-09 19:55:06 +00:00
{
// Pre-select arch and bits in the hexdump sidebar
QString arch = Core()->getConfig("asm.arch");
QString bits = Core()->getConfig("asm.bits");
2018-03-21 20:32:32 +00:00
if (ui->parseArchComboBox->findText(arch) != -1) {
ui->parseArchComboBox->setCurrentIndex(ui->parseArchComboBox->findText(arch));
}
2018-03-21 20:32:32 +00:00
if (ui->parseBitsComboBox->findText(bits) != -1) {
ui->parseBitsComboBox->setCurrentIndex(ui->parseBitsComboBox->findText(bits));
}
}
2017-04-05 09:35:19 +00:00
void HexdumpWidget::on_rangeDialogAccepted()
{
int startPosition;
int endPosition;
QTextCursor targetTextCursor;
requestedSelectionStartAddress = Core()->math(rangeDialog.getStartAddress());
requestedSelectionEndAddress = rangeDialog.getEndAddressRadioButtonChecked() ?
Core()->math(rangeDialog.getEndAddress()) :
requestedSelectionStartAddress + Core()->math(rangeDialog.getLength());
//not sure what the accepted user feedback mechanism is, output to console or a QMessageBox alert
if (requestedSelectionEndAddress <= requestedSelectionStartAddress) {
Core()->message(tr("Error: Could not select range, end address is less then start address"));
return;
}
//seek to the start address and create a text cursor to highlight the desired range
refresh(requestedSelectionStartAddress);
//for large selections, won't be able to calculate the endPosition because hexAddressToPosition assumes the address is loaded?
startPosition = hexAddressToPosition(requestedSelectionStartAddress);
endPosition = hexAddressToPosition(requestedSelectionEndAddress) - 1;
targetTextCursor = ui->hexHexText->textCursor();
targetTextCursor.setPosition(startPosition);
targetTextCursor.setPosition(endPosition, QTextCursor::KeepAnchor);
ui->hexHexText->setTextCursor(targetTextCursor);
}
void HexdumpWidget::showOffsets(bool show)
{
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);
}
}
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();
}
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());
}