Prepare HexdumpWidget

This commit is contained in:
Florian Märkl 2017-11-15 22:42:39 +01:00
parent 225e089469
commit bde54511a9
3 changed files with 155 additions and 238 deletions

View File

@ -18,17 +18,16 @@
#include <cassert> #include <cassert>
static const int blockSize = 16;
static const int blocksMarginMin = 2;
static const int blocksMarginDefault = 3;
static const int blocksMarginMax = 4;
HexdumpWidget::HexdumpWidget(QWidget *parent, Qt::WindowFlags flags) : HexdumpWidget::HexdumpWidget(QWidget *parent, Qt::WindowFlags flags) :
QDockWidget(parent, flags), QDockWidget(parent, flags),
ui(new Ui::HexdumpWidget), ui(new Ui::HexdumpWidget)
core(CutterCore::getInstance())
{ {
ui->setupUi(this); ui->setupUi(this);
this->hexOffsetText = ui->hexOffsetText_2;
this->hexHexText = ui->hexHexText_2;
this->hexASCIIText = ui->hexASCIIText_2;
this->hexDisasTextEdit = ui->hexDisasTextEdit_2;
//this->on_actionSettings_menu_1_triggered(); //this->on_actionSettings_menu_1_triggered();
@ -37,9 +36,9 @@ HexdumpWidget::HexdumpWidget(QWidget *parent, Qt::WindowFlags flags) :
//highlightHexCurrentLine(); //highlightHexCurrentLine();
// Normalize fonts for other OS // Normalize fonts for other OS
qhelpers::normalizeEditFont(this->hexOffsetText); qhelpers::normalizeFont(ui->hexOffsetText);
qhelpers::normalizeEditFont(this->hexHexText); qhelpers::normalizeFont(ui->hexHexText);
qhelpers::normalizeEditFont(this->hexASCIIText); qhelpers::normalizeFont(ui->hexASCIIText);
// Popup menu on Settings toolbutton // Popup menu on Settings toolbutton
QMenu *memMenu = new QMenu(); QMenu *memMenu = new QMenu();
@ -48,33 +47,33 @@ HexdumpWidget::HexdumpWidget(QWidget *parent, Qt::WindowFlags flags) :
ui->memSettingsButton_2->setMenu(memMenu); ui->memSettingsButton_2->setMenu(memMenu);
// Set hexdump context menu // Set hexdump context menu
ui->hexHexText_2->setContextMenuPolicy(Qt::CustomContextMenu); ui->hexHexText->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->hexHexText_2, SIGNAL(customContextMenuRequested(const QPoint &)), connect(ui->hexHexText, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showHexdumpContextMenu(const QPoint &))); this, SLOT(showHexdumpContextMenu(const QPoint &)));
ui->hexASCIIText_2->setContextMenuPolicy(Qt::CustomContextMenu); ui->hexASCIIText->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->hexASCIIText_2, SIGNAL(customContextMenuRequested(const QPoint &)), connect(ui->hexASCIIText, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showHexASCIIContextMenu(const QPoint &))); this, SLOT(showHexASCIIContextMenu(const QPoint &)));
// Syncronize hexdump scrolling // Synchronize hexdump scrolling
connect(ui->hexOffsetText_2->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(ui->hexOffsetText->verticalScrollBar(), SIGNAL(valueChanged(int)),
ui->hexHexText_2->verticalScrollBar(), SLOT(setValue(int))); ui->hexHexText->verticalScrollBar(), SLOT(setValue(int)));
connect(ui->hexOffsetText_2->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(ui->hexOffsetText->verticalScrollBar(), SIGNAL(valueChanged(int)),
ui->hexASCIIText_2->verticalScrollBar(), SLOT(setValue(int))); ui->hexASCIIText->verticalScrollBar(), SLOT(setValue(int)));
connect(ui->hexHexText_2->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(ui->hexHexText->verticalScrollBar(), SIGNAL(valueChanged(int)),
ui->hexOffsetText_2->verticalScrollBar(), SLOT(setValue(int))); ui->hexOffsetText->verticalScrollBar(), SLOT(setValue(int)));
connect(ui->hexHexText_2->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(ui->hexHexText->verticalScrollBar(), SIGNAL(valueChanged(int)),
ui->hexASCIIText_2->verticalScrollBar(), SLOT(setValue(int))); ui->hexASCIIText->verticalScrollBar(), SLOT(setValue(int)));
connect(ui->hexASCIIText_2->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)),
ui->hexOffsetText_2->verticalScrollBar(), SLOT(setValue(int))); ui->hexOffsetText->verticalScrollBar(), SLOT(setValue(int)));
connect(ui->hexASCIIText_2->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)),
ui->hexHexText_2->verticalScrollBar(), SLOT(setValue(int))); ui->hexHexText->verticalScrollBar(), SLOT(setValue(int)));
// Control Disasm and Hex scroll to add more contents // Control Disasm and Hex scroll to add more contents
connect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
connect(core, SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType))); connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) { connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
@ -118,7 +117,7 @@ void HexdumpWidget::highlightHexCurrentLine()
{ {
QList<QTextEdit::ExtraSelection> extraSelections; QList<QTextEdit::ExtraSelection> extraSelections;
if (!ui->hexHexText_2->isReadOnly()) if (!ui->hexHexText->isReadOnly())
{ {
QTextEdit::ExtraSelection selection; QTextEdit::ExtraSelection selection;
@ -126,12 +125,12 @@ void HexdumpWidget::highlightHexCurrentLine()
selection.format.setBackground(lineColor); selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true); selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = ui->hexHexText_2->textCursor(); selection.cursor = ui->hexHexText->textCursor();
selection.cursor.clearSelection(); selection.cursor.clearSelection();
extraSelections.append(selection); extraSelections.append(selection);
} }
QTextCursor cursor = ui->hexHexText_2->textCursor(); QTextCursor cursor = ui->hexHexText->textCursor();
cursor.select(QTextCursor::WordUnderCursor); cursor.select(QTextCursor::WordUnderCursor);
QTextEdit::ExtraSelection currentWord; QTextEdit::ExtraSelection currentWord;
@ -142,7 +141,7 @@ void HexdumpWidget::highlightHexCurrentLine()
currentWord.cursor = cursor; currentWord.cursor = cursor;
extraSelections.append(currentWord); extraSelections.append(currentWord);
ui->hexHexText_2->setExtraSelections(extraSelections); ui->hexHexText->setExtraSelections(extraSelections);
highlightHexWords(cursor.selectedText()); highlightHexWords(cursor.selectedText());
} }
@ -150,7 +149,7 @@ void HexdumpWidget::highlightHexCurrentLine()
void HexdumpWidget::highlightHexWords(const QString &str) void HexdumpWidget::highlightHexWords(const QString &str)
{ {
QString searchString = str; QString searchString = str;
QTextDocument *document = ui->hexHexText_2->document(); QTextDocument *document = ui->hexHexText->document();
document->undo(); document->undo();
@ -182,24 +181,24 @@ void HexdumpWidget::refresh(RVA addr)
{ {
if (addr == RVA_INVALID) if (addr == RVA_INVALID)
{ {
addr = core->getOffset(); addr = Core()->getOffset();
} }
RCoreLocked lcore = this->core->core(); RCoreLocked lcore = Core()->core();
// Prevent further scroll // Prevent further scroll
disconnect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); disconnect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
// Clear previous content to add new // Clear previous content to add new
this->hexOffsetText->clear(); ui->hexOffsetText->clear();
this->hexHexText->clear(); ui->hexHexText->clear();
this->hexASCIIText->clear(); ui->hexASCIIText->clear();
int hexdumpLength; int hexdumpLength;
int cols = lcore->print->cols; int cols = lcore->print->cols;
ut64 bsize = 128 * cols; ut64 bsize = 128 * cols;
if (hexdumpBottomOffset < bsize) if (bottomOffset < bsize)
{ {
hexdumpBottomOffset = 0; bottomOffset = 0;
hexdumpLength = bsize;//-hexdumpBottomOffset; hexdumpLength = bsize;//-hexdumpBottomOffset;
} }
else else
@ -215,32 +214,32 @@ void HexdumpWidget::refresh(RVA addr)
// Add first the hexdump at block size -- // Add first the hexdump at block size --
QList<QString> ret = this->get_hexdump(RAddressString(addr - hexdumpLength)); QList<QString> ret = this->get_hexdump(RAddressString(addr - hexdumpLength));
hexdumpBottomOffset = lcore->offset; bottomOffset = lcore->offset;
this->hexOffsetText->setPlainText(ret[0]); ui->hexOffsetText->setPlainText(ret[0]);
this->hexHexText->setPlainText(ret[1]); ui->hexHexText->setPlainText(ret[1]);
this->hexASCIIText->setPlainText(ret[2]); ui->hexASCIIText->setPlainText(ret[2]);
this->resizeHexdump(); resizeHexdump();
// Get address to move cursor to later // Get address to move cursor to later
s = this->normalize_addr(this->core->cmd("s")); s = this->normalize_addr(Core()->cmd("s"));
ret = this->get_hexdump(RAddressString(addr)); ret = this->get_hexdump(RAddressString(addr));
hexdumpBottomOffset = lcore->offset; bottomOffset = lcore->offset;
this->hexOffsetText->append(ret[0]); ui->hexOffsetText->appendPlainText(ret[0]);
this->hexHexText->append(ret[1]); ui->hexHexText->appendPlainText(ret[1]);
this->hexASCIIText->append(ret[2]); ui->hexASCIIText->appendPlainText(ret[2]);
this->resizeHexdump(); resizeHexdump();
// Move cursor to desired address // Move cursor to desired address
QTextCursor cur = this->hexOffsetText->textCursor(); QTextCursor cur = ui->hexOffsetText->textCursor();
this->hexOffsetText->ensureCursorVisible(); ui->hexOffsetText->ensureCursorVisible();
this->hexHexText->ensureCursorVisible(); ui->hexHexText->ensureCursorVisible();
this->hexASCIIText->ensureCursorVisible(); ui->hexASCIIText->ensureCursorVisible();
this->hexOffsetText->moveCursor(QTextCursor::End); ui->hexOffsetText->moveCursor(QTextCursor::End);
this->hexOffsetText->find(s, QTextDocument::FindBackward); ui->hexOffsetText->find(s, QTextDocument::FindBackward);
this->hexOffsetText->moveCursor(QTextCursor::EndOfLine, QTextCursor::MoveAnchor); ui->hexOffsetText->moveCursor(QTextCursor::EndOfLine, QTextCursor::MoveAnchor);
connect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
} }
@ -251,21 +250,21 @@ void HexdumpWidget::refresh(RVA addr)
void HexdumpWidget::fillPlugins() void HexdumpWidget::fillPlugins()
{ {
// Fill the plugins combo for the hexdump sidebar // Fill the plugins combo for the hexdump sidebar
ui->hexArchComboBox_2->insertItems(0, core->getAsmPluginNames()); ui->hexArchComboBox_2->insertItems(0, Core()->getAsmPluginNames());
} }
QList<QString> HexdumpWidget::get_hexdump(const QString &offset) QList<QString> HexdumpWidget::get_hexdump(const QString &offset)
{ {
RCoreLocked lcore = this->core->core(); RCoreLocked lcore = Core()->core();
QList<QString> ret; QList<QString> ret;
QString hexdump; QString hexdump;
int hexdumpLength; int hexdumpLength;
int cols = lcore->print->cols; int cols = lcore->print->cols;
ut64 bsize = 128 * cols; ut64 bsize = 128 * cols;
if (hexdumpBottomOffset < bsize) if (bottomOffset < bsize)
{ {
hexdumpBottomOffset = 0; bottomOffset = 0;
hexdumpLength = bsize; hexdumpLength = bsize;
//-hexdumpBottomOffset; //-hexdumpBottomOffset;
} }
@ -274,17 +273,17 @@ QList<QString> HexdumpWidget::get_hexdump(const QString &offset)
hexdumpLength = bsize; hexdumpLength = bsize;
} }
//this->main->add_debug_output("BSize: " + this->core->itoa(hexdumpLength, 10)); //this->main->add_debug_output("BSize: " + Core()->itoa(hexdumpLength, 10));
if (offset.isEmpty()) if (offset.isEmpty())
{ {
hexdump = this->core->cmd("px " + this->core->itoa(hexdumpLength, 10)); hexdump = Core()->cmd("px " + Core()->itoa(hexdumpLength, 10));
} }
else else
{ {
hexdump = this->core->cmd("px " + this->core->itoa(hexdumpLength, 10) + " @ " + offset); hexdump = Core()->cmd("px " + Core()->itoa(hexdumpLength, 10) + " @ " + offset);
} }
//QString hexdump = this->core->cmd ("px 0x" + this->core->itoa(size) + " @ 0x0"); //QString hexdump = Core()->cmd ("px 0x" + Core()->itoa(size) + " @ 0x0");
// TODO: use pxl to simplify // TODO: use pxl to simplify
QString offsets; QString offsets;
QString hex; QString hex;
@ -325,21 +324,21 @@ QList<QString> HexdumpWidget::get_hexdump(const QString &offset)
void HexdumpWidget::resizeHexdump() void HexdumpWidget::resizeHexdump()
{ {
this->hexOffsetText->setMinimumWidth(this->hexOffsetText->document()->size().width()); ui->hexOffsetText->setMinimumWidth(static_cast<int>(ui->hexOffsetText->document()->size().width()));
this->hexHexText->setMinimumWidth(this->hexHexText->document()->size().width()); ui->hexHexText->setMinimumWidth(static_cast<int>(ui->hexHexText->document()->size().width()));
//this->hexASCIIText->setMinimumWidth(this->hexASCIIText->document()->size().width()); //this->hexASCIIText->setMinimumWidth(this->hexASCIIText->document()->size().width());
} }
void HexdumpWidget::hexScrolled() void HexdumpWidget::hexScrolled()
{ {
RCoreLocked lcore = this->core->core(); RCoreLocked lcore = Core()->core();
QScrollBar *sb = this->hexASCIIText->verticalScrollBar(); QScrollBar *sb = ui->hexASCIIText->verticalScrollBar();
if (sb->value() > sb->maximum() - 10) if (sb->value() > sb->maximum() - 10)
{ {
//this->main->addDebugOutput("End is coming"); //this->main->addDebugOutput("End is coming");
QTextCursor tc = this->hexOffsetText->textCursor(); QTextCursor tc = ui->hexOffsetText->textCursor();
tc.movePosition(QTextCursor::End); tc.movePosition(QTextCursor::End);
tc.select(QTextCursor::LineUnderCursor); tc.select(QTextCursor::LineUnderCursor);
QString lastline = tc.selectedText(); QString lastline = tc.selectedText();
@ -350,17 +349,17 @@ void HexdumpWidget::hexScrolled()
// To prevent recursive calls to hexScrolled (this function) blocks the // To prevent recursive calls to hexScrolled (this function) blocks the
// scroll bar signals // scroll bar signals
auto appendTextWithoutSignals = [](QTextEdit * edit, const QString & text) auto appendTextWithoutSignals = [](QPlainTextEdit *edit, const QString & text)
{ {
edit->verticalScrollBar()->blockSignals(true); edit->verticalScrollBar()->blockSignals(true);
edit->append(text); edit->appendPlainText(text);
edit->verticalScrollBar()->blockSignals(false); edit->verticalScrollBar()->blockSignals(false);
}; };
appendTextWithoutSignals(hexOffsetText, ret[0]); appendTextWithoutSignals(ui->hexOffsetText, ret[0]);
appendTextWithoutSignals(hexHexText, ret[1]); appendTextWithoutSignals(ui->hexHexText, ret[1]);
appendTextWithoutSignals(hexASCIIText, ret[2]); appendTextWithoutSignals(ui->hexASCIIText, ret[2]);
this->resizeHexdump(); resizeHexdump();
// Append more hex text here // Append more hex text here
// ui->disasTextEdit->moveCursor(QTextCursor::Start); // ui->disasTextEdit->moveCursor(QTextCursor::Start);
@ -371,7 +370,7 @@ void HexdumpWidget::hexScrolled()
{ {
//this->main->add_debug_output("Begining is coming"); //this->main->add_debug_output("Begining is coming");
QTextCursor tc = this->hexOffsetText->textCursor(); QTextCursor tc = ui->hexOffsetText->textCursor();
tc.movePosition(QTextCursor::Start); tc.movePosition(QTextCursor::Start);
tc.select(QTextCursor::LineUnderCursor); tc.select(QTextCursor::LineUnderCursor);
QString firstline = tc.selectedText(); QString firstline = tc.selectedText();
@ -384,45 +383,45 @@ void HexdumpWidget::hexScrolled()
int bsize = 800; int bsize = 800;
QString s = QString::number(bsize); QString s = QString::number(bsize);
// s = 2048.. sigh... // s = 2048.. sigh...
QString kk = this->core->cmd("? " + firstline + " - " + s); QString kk = Core()->cmd("? " + firstline + " - " + s);
QString k = kk.split(" ")[1]; QString k = kk.split(" ")[1];
QList<QString> ret = this->get_hexdump(k); QList<QString> ret = this->get_hexdump(k);
// Prevent further scroll // Prevent further scroll
disconnect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); disconnect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
// Get actual maximum scrolling value // Get actual maximum scrolling value
int b = this->hexASCIIText->verticalScrollBar()->maximum(); int b = ui->hexASCIIText->verticalScrollBar()->maximum();
// Add new offset content // Add new offset content
QTextDocument *offset_document = this->hexOffsetText->document(); QTextDocument *offset_document = ui->hexOffsetText->document();
QTextCursor offset_cursor(offset_document); QTextCursor offset_cursor(offset_document);
offset_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); offset_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
offset_cursor.insertText(ret[0] + "\n"); offset_cursor.insertText(ret[0] + "\n");
// Add new hex content // Add new hex content
QTextDocument *hex_document = this->hexHexText->document(); QTextDocument *hex_document = ui->hexHexText->document();
QTextCursor hex_cursor(hex_document); QTextCursor hex_cursor(hex_document);
hex_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); hex_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
hex_cursor.insertText(ret[1] + "\n"); hex_cursor.insertText(ret[1] + "\n");
// Add new ASCII content // Add new ASCII content
QTextDocument *ascii_document = this->hexASCIIText->document(); QTextDocument *ascii_document = ui->hexASCIIText->document();
QTextCursor ascii_cursor(ascii_document); QTextCursor ascii_cursor(ascii_document);
ascii_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); ascii_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
ascii_cursor.insertText(ret[2] + "\n"); ascii_cursor.insertText(ret[2] + "\n");
// Get new maximum scroll value // Get new maximum scroll value
int c = this->hexASCIIText->verticalScrollBar()->maximum(); int c = ui->hexASCIIText->verticalScrollBar()->maximum();
// Get size of new added content // Get size of new added content
int z = c - b; int z = c - b;
// Get new slider position // Get new slider position
int a = this->hexASCIIText->verticalScrollBar()->sliderPosition(); int a = ui->hexASCIIText->verticalScrollBar()->sliderPosition();
// move to previous position // move to previous position
this->hexASCIIText->verticalScrollBar()->setValue(a + z); ui->hexASCIIText->verticalScrollBar()->setValue(a + z);
this->resizeHexdump(); this->resizeHexdump();
connect(this->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
} }
} }
@ -431,7 +430,7 @@ void HexdumpWidget::on_hexHexText_2_selectionChanged()
// Get selected partsing type // Get selected partsing type
QString parsing = ui->codeCombo_2->currentText(); QString parsing = ui->codeCombo_2->currentText();
// Get selected text // Get selected text
QTextCursor cursor(this->hexHexText->textCursor()); QTextCursor cursor(ui->hexHexText->textCursor());
QString sel_text = cursor.selectedText(); QString sel_text = cursor.selectedText();
sel_text = sel_text.simplified().remove(" "); sel_text = sel_text.simplified().remove(" ");
@ -439,7 +438,7 @@ void HexdumpWidget::on_hexHexText_2_selectionChanged()
if (sel_text == "") if (sel_text == "")
{ {
this->hexDisasTextEdit->setPlainText(""); ui->hexDisasTextEdit->setPlainText("");
ui->bytesEntropy->setText(""); ui->bytesEntropy->setText("");
ui->bytesMD5->setText(""); ui->bytesMD5->setText("");
ui->bytesSHA1->setText(""); ui->bytesSHA1->setText("");
@ -452,15 +451,15 @@ void HexdumpWidget::on_hexHexText_2_selectionChanged()
QString arch = ui->hexArchComboBox_2->currentText(); QString arch = ui->hexArchComboBox_2->currentText();
QString bits = ui->hexBitsComboBox_2->currentText(); QString bits = ui->hexBitsComboBox_2->currentText();
QString oarch = this->core->getConfig("asm.arch"); QString oarch = Core()->getConfig("asm.arch");
QString obits = this->core->getConfig("asm.bits"); QString obits = Core()->getConfig("asm.bits");
this->core->setConfig("asm.arch", arch); Core()->setConfig("asm.arch", arch);
this->core->setConfig("asm.bits", bits); Core()->setConfig("asm.bits", bits);
QString str = this->core->cmd("pad " + sel_text); QString str = Core()->cmd("pad " + sel_text);
this->hexDisasTextEdit->setPlainText(str); ui->hexDisasTextEdit->setPlainText(str);
this->core->setConfig("asm.arch", oarch); Core()->setConfig("asm.arch", oarch);
this->core->setConfig("asm.bits", obits); Core()->setConfig("asm.bits", obits);
//qDebug() << "Selected Arch: " << arch; //qDebug() << "Selected Arch: " << arch;
//qDebug() << "Selected Bits: " << bits; //qDebug() << "Selected Bits: " << bits;
//qDebug() << "Selected Text: " << sel_text; //qDebug() << "Selected Text: " << sel_text;
@ -468,41 +467,41 @@ void HexdumpWidget::on_hexHexText_2_selectionChanged()
// TODO: update on selection changes.. use cmd("pc "+len+"@"+off) // TODO: update on selection changes.. use cmd("pc "+len+"@"+off)
else if (parsing == "C byte array") else if (parsing == "C byte array")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pc@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pc@x:" + sel_text));
} }
else if (parsing == "C dword array") else if (parsing == "C dword array")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pcw@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcw@x:" + sel_text));
} }
else if (parsing == "C qword array") else if (parsing == "C qword array")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pcq@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcq@x:" + sel_text));
} }
else if (parsing == "Assembler") else if (parsing == "Assembler")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pca@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pca@x:" + sel_text));
} }
else if (parsing == "String") else if (parsing == "String")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pcs@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcs@x:" + sel_text));
} }
else if (parsing == "JSON") else if (parsing == "JSON")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pcj@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcj@x:" + sel_text));
} }
else if (parsing == "Javascript") else if (parsing == "Javascript")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pcJ@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcJ@x:" + sel_text));
} }
else if (parsing == "Python") else if (parsing == "Python")
{ {
this->hexDisasTextEdit->setPlainText(this->core->cmd("pcp@x:" + sel_text)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcp@x:" + sel_text));
} }
// Fill the information tab hashes and entropy // Fill the information tab hashes and entropy
ui->bytesMD5->setText(this->core->cmd("ph md5@x:" + sel_text).trimmed()); ui->bytesMD5->setText(Core()->cmd("ph md5@x:" + sel_text).trimmed());
ui->bytesSHA1->setText(this->core->cmd("ph sha1@x:" + sel_text).trimmed()); ui->bytesSHA1->setText(Core()->cmd("ph sha1@x:" + sel_text).trimmed());
ui->bytesEntropy->setText(this->core->cmd("ph entropy@x:" + sel_text).trimmed()); ui->bytesEntropy->setText(Core()->cmd("ph entropy@x:" + sel_text).trimmed());
ui->bytesMD5->setCursorPosition(0); ui->bytesMD5->setCursorPosition(0);
ui->bytesSHA1->setCursorPosition(0); ui->bytesSHA1->setCursorPosition(0);
} }
@ -525,7 +524,7 @@ void HexdumpWidget::on_hexBitsComboBox_2_currentTextChanged(const QString &/*arg
void HexdumpWidget::showHexdumpContextMenu(const QPoint &pt) void HexdumpWidget::showHexdumpContextMenu(const QPoint &pt)
{ {
// Set Hexdump popup menu // Set Hexdump popup menu
QMenu *menu = ui->hexHexText_2->createStandardContextMenu(); QMenu *menu = ui->hexHexText->createStandardContextMenu();
menu->clear(); menu->clear();
menu->addAction(ui->actionHexCopy_Hexpair); menu->addAction(ui->actionHexCopy_Hexpair);
menu->addAction(ui->actionHexCopy_ASCII); menu->addAction(ui->actionHexCopy_ASCII);
@ -543,16 +542,16 @@ void HexdumpWidget::showHexdumpContextMenu(const QPoint &pt)
menu->addAction(ui->actionHexInsert_Hex); menu->addAction(ui->actionHexInsert_Hex);
menu->addAction(ui->actionHexInsert_String); menu->addAction(ui->actionHexInsert_String);
ui->hexHexText_2->setContextMenuPolicy(Qt::CustomContextMenu); ui->hexHexText->setContextMenuPolicy(Qt::CustomContextMenu);
menu->exec(ui->hexHexText_2->mapToGlobal(pt)); menu->exec(ui->hexHexText->mapToGlobal(pt));
delete menu; delete menu;
} }
void HexdumpWidget::showHexASCIIContextMenu(const QPoint &pt) void HexdumpWidget::showHexASCIIContextMenu(const QPoint &pt)
{ {
// Set Hex ASCII popup menu // Set Hex ASCII popup menu
QMenu *menu = ui->hexASCIIText_2->createStandardContextMenu(); QMenu *menu = ui->hexASCIIText->createStandardContextMenu();
menu->clear(); menu->clear();
menu->addAction(ui->actionHexCopy_Hexpair); menu->addAction(ui->actionHexCopy_Hexpair);
menu->addAction(ui->actionHexCopy_ASCII); menu->addAction(ui->actionHexCopy_ASCII);
@ -570,9 +569,9 @@ void HexdumpWidget::showHexASCIIContextMenu(const QPoint &pt)
menu->addAction(ui->actionHexInsert_Hex); menu->addAction(ui->actionHexInsert_Hex);
menu->addAction(ui->actionHexInsert_String); menu->addAction(ui->actionHexInsert_String);
ui->hexASCIIText_2->setContextMenuPolicy(Qt::CustomContextMenu); ui->hexASCIIText->setContextMenuPolicy(Qt::CustomContextMenu);
menu->exec(ui->hexASCIIText_2->mapToGlobal(pt)); menu->exec(ui->hexASCIIText->mapToGlobal(pt));
delete menu; delete menu;
} }
/* /*
@ -600,9 +599,9 @@ void HexdumpWidget::setFonts(QFont font)
//ui->disasTextEdit_2->setFont(font); //ui->disasTextEdit_2->setFont(font);
// the user clicked OK and font is set to the font the user selected // the user clicked OK and font is set to the font the user selected
//ui->disasTextEdit_2->setFont(font); //ui->disasTextEdit_2->setFont(font);
ui->hexOffsetText_2->setFont(font); ui->hexOffsetText->setFont(font);
ui->hexHexText_2->setFont(font); ui->hexHexText->setFont(font);
ui->hexASCIIText_2->setFont(font); ui->hexASCIIText->setFont(font);
} }
void HexdumpWidget::on_actionHideHexdump_side_panel_triggered() void HexdumpWidget::on_actionHideHexdump_side_panel_triggered()
@ -628,44 +627,44 @@ void HexdumpWidget::on_actionHideHexdump_side_panel_triggered()
void HexdumpWidget::on_action8columns_triggered() void HexdumpWidget::on_action8columns_triggered()
{ {
this->core->setConfig("hex.cols", 8); Core()->setConfig("hex.cols", 8);
this->refresh(); refresh();
} }
void HexdumpWidget::on_action16columns_triggered() void HexdumpWidget::on_action16columns_triggered()
{ {
this->core->setConfig("hex.cols", 16); Core()->setConfig("hex.cols", 16);
this->refresh(); refresh();
} }
void HexdumpWidget::on_action4columns_triggered() void HexdumpWidget::on_action4columns_triggered()
{ {
this->core->setConfig("hex.cols", 4); Core()->setConfig("hex.cols", 4);
this->refresh(); refresh();
} }
void HexdumpWidget::on_action32columns_triggered() void HexdumpWidget::on_action32columns_triggered()
{ {
this->core->setConfig("hex.cols", 32); Core()->setConfig("hex.cols", 32);
this->refresh(); refresh();
} }
void HexdumpWidget::on_action64columns_triggered() void HexdumpWidget::on_action64columns_triggered()
{ {
this->core->setConfig("hex.cols", 64); Core()->setConfig("hex.cols", 64);
this->refresh(); refresh();
} }
void HexdumpWidget::on_action2columns_triggered() void HexdumpWidget::on_action2columns_triggered()
{ {
this->core->setConfig("hex.cols", 2); Core()->setConfig("hex.cols", 2);
this->refresh(); refresh();
} }
void HexdumpWidget::on_action1column_triggered() void HexdumpWidget::on_action1column_triggered()
{ {
this->core->setConfig("hex.cols", 1); Core()->setConfig("hex.cols", 1);
this->refresh(); refresh();
} }
void HexdumpWidget::on_codeCombo_2_currentTextChanged(const QString &arg1) void HexdumpWidget::on_codeCombo_2_currentTextChanged(const QString &arg1)
@ -673,18 +672,18 @@ void HexdumpWidget::on_codeCombo_2_currentTextChanged(const QString &arg1)
if (arg1 == "Dissasembly") if (arg1 == "Dissasembly")
{ {
ui->hexSideFrame_2->show(); ui->hexSideFrame_2->show();
ui->hexDisasTextEdit_2->setPlainText(";; Select some bytes on the left\n;; to see them disassembled"); ui->hexDisasTextEdit->setPlainText(";; Select some bytes on the left\n;; to see them disassembled");
} }
else else
{ {
ui->hexSideFrame_2->hide(); ui->hexSideFrame_2->hide();
ui->hexDisasTextEdit_2->setPlainText(";; Select some bytes on the left\n;; to see them parsed here"); ui->hexDisasTextEdit->setPlainText(";; Select some bytes on the left\n;; to see them parsed here");
} }
} }
QString HexdumpWidget::normalize_addr(QString addr) QString HexdumpWidget::normalize_addr(QString addr)
{ {
QString base = this->core->cmd("s").split("0x")[1].trimmed(); QString base = Core()->cmd("s").split("0x")[1].trimmed();
int len = base.length(); int len = base.length();
if (len < 8) if (len < 8)
{ {
@ -834,8 +833,8 @@ void HexdumpWidget::on_copySHA1_clicked()
void HexdumpWidget::selectHexPreview() void HexdumpWidget::selectHexPreview()
{ {
// Pre-select arch and bits in the hexdump sidebar // Pre-select arch and bits in the hexdump sidebar
QString arch = this->core->cmd("e asm.arch").trimmed(); QString arch = Core()->cmd("e asm.arch").trimmed();
QString bits = this->core->cmd("e asm.bits").trimmed(); QString bits = Core()->cmd("e asm.bits").trimmed();
//int arch_index = ui->hexArchComboBox_2->findText(arch); //int arch_index = ui->hexArchComboBox_2->findText(arch);
if (ui->hexArchComboBox_2->findText(arch) != -1) if (ui->hexArchComboBox_2->findText(arch) != -1)
@ -854,28 +853,28 @@ void HexdumpWidget::showOffsets(bool show)
{ {
if (show) if (show)
{ {
this->hexOffsetText->show(); ui->hexOffsetText->show();
core->setConfig("asm.offset", 1); Core()->setConfig("asm.offset", 1);
} }
else else
{ {
this->hexOffsetText->hide(); ui->hexOffsetText->hide();
core->setConfig("asm.offset", 0); Core()->setConfig("asm.offset", 0);
} }
} }
void HexdumpWidget::zoomIn(int range) void HexdumpWidget::zoomIn(int range)
{ {
hexOffsetText->zoomIn(range); ui->hexOffsetText->zoomIn(range);
hexASCIIText->zoomIn(range); ui->hexASCIIText->zoomIn(range);
hexHexText->zoomIn(range); ui->hexHexText->zoomIn(range);
resizeHexdump(); resizeHexdump();
} }
void HexdumpWidget::zoomOut(int range) void HexdumpWidget::zoomOut(int range)
{ {
hexOffsetText->zoomOut(range); ui->hexOffsetText->zoomOut(range);
hexASCIIText->zoomOut(range); ui->hexASCIIText->zoomOut(range);
hexHexText->zoomOut(range); ui->hexHexText->zoomOut(range);
resizeHexdump(); resizeHexdump();
} }

View File

@ -33,12 +33,6 @@ public:
explicit HexdumpWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = 0); explicit HexdumpWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
~HexdumpWidget(); ~HexdumpWidget();
QTextEdit *hexOffsetText;
QTextEdit *hexASCIIText;
QTextEdit *hexHexText;
QPlainTextEdit *hexDisasTextEdit;
Highlighter *highlighter; Highlighter *highlighter;
signals: signals:
@ -64,9 +58,9 @@ protected:
private: private:
std::unique_ptr<Ui::HexdumpWidget> ui; std::unique_ptr<Ui::HexdumpWidget> ui;
CutterCore *core;
ut64 hexdumpBottomOffset; RVA topOffset;
RVA bottomOffset;
void refresh(RVA addr = RVA_INVALID); void refresh(RVA addr = RVA_INVALID);

View File

@ -210,7 +210,7 @@ QToolTip {
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QTextEdit" name="hexOffsetText_2"> <widget class="QPlainTextEdit" name="hexOffsetText">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -244,41 +244,10 @@ QToolTip {
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum> <enum>QAbstractScrollArea::AdjustToContents</enum>
</property> </property>
<property name="documentTitle">
<string notr="true"/>
</property>
<property name="undoRedoEnabled">
<bool>true</bool>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Anonymous Pro'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Monaco'; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="overwriteMode">
<bool>false</bool>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="placeholderText">
<string notr="true"/>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTextEdit" name="hexHexText_2"> <widget class="QPlainTextEdit" name="hexHexText">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -321,32 +290,10 @@ p, li { white-space: pre-wrap; }
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum> <enum>QAbstractScrollArea::AdjustToContents</enum>
</property> </property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Anonymous Pro'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Monaco'; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="overwriteMode">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="placeholderText">
<string notr="true"/>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTextEdit" name="hexASCIIText_2"> <widget class="QPlainTextEdit" name="hexASCIIText">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -389,25 +336,6 @@ p, li { white-space: pre-wrap; }
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum> <enum>QAbstractScrollArea::AdjustToContents</enum>
</property> </property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Anonymous Pro'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Monaco'; font-size:12pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="overwriteMode">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -656,7 +584,7 @@ p, li { white-space: pre-wrap; }
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPlainTextEdit" name="hexDisasTextEdit_2"> <widget class="QPlainTextEdit" name="hexDisasTextEdit">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -1147,8 +1075,4 @@ QToolTip {
<include location="../resources.qrc"/> <include location="../resources.qrc"/>
</resources> </resources>
<connections/> <connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_3"/>
</buttongroups>
</ui> </ui>