Implement HexdumpWidget::refresh()

This commit is contained in:
Florian Märkl 2017-11-16 22:12:44 +01:00
parent c0248c8bf6
commit c74c743f79
2 changed files with 32 additions and 79 deletions

View File

@ -195,54 +195,36 @@ void HexdumpWidget::refresh(RVA addr)
ui->hexHexText->clear(); ui->hexHexText->clear();
ui->hexASCIIText->clear(); ui->hexASCIIText->clear();
int hexdumpLength;
int cols = lcore->print->cols;
ut64 bsize = 128 * cols;
if (bottomOffset < bsize)
{
bottomOffset = 0;
hexdumpLength = bsize;//-hexdumpBottomOffset;
}
else
{
hexdumpLength = bsize;
}
//int size; int cols = lcore->print->cols;
//size = core->get_size();
topOffset = addr - blocksMarginDefault * blockSize * cols;
topOffset = (topOffset / cols) * cols; // align
int fetchLines = visibleLines + blocksMarginDefault * 2 * blockSize;
RVA bytes = static_cast<RVA>(fetchLines) * cols;
bottomOffset = topOffset + bytes;
auto hexdump = fetchHexdump(topOffset, bytes);
QString s = ""; QString s = "";
// Add first the hexdump at block size -- ui->hexOffsetText->setPlainText(hexdump[0]);
QList<QString> ret = this->get_hexdump(RAddressString(addr - hexdumpLength)); ui->hexHexText->setPlainText(hexdump[1]);
ui->hexASCIIText->setPlainText(hexdump[2]);
bottomOffset = lcore->offset;
ui->hexOffsetText->setPlainText(ret[0]);
ui->hexHexText->setPlainText(ret[1]);
ui->hexASCIIText->setPlainText(ret[2]);
resizeHexdump();
// Get address to move cursor to later
s = this->normalize_addr(Core()->cmd("s"));
ret = this->get_hexdump(RAddressString(addr));
bottomOffset = lcore->offset;
ui->hexOffsetText->appendPlainText(ret[0]);
ui->hexHexText->appendPlainText(ret[1]);
ui->hexASCIIText->appendPlainText(ret[2]);
resizeHexdump(); resizeHexdump();
// Move cursor to desired address // Move cursor to desired address
QTextCursor cur = ui->hexOffsetText->textCursor(); QTextCursor cur = ui->hexOffsetText->textCursor();
ui->hexOffsetText->ensureCursorVisible(); cur.movePosition(QTextCursor::Start);
ui->hexHexText->ensureCursorVisible(); cur.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, blocksMarginDefault * blockSize);
ui->hexASCIIText->ensureCursorVisible(); ui->hexOffsetText->setTextCursor(cur);
ui->hexOffsetText->moveCursor(QTextCursor::End);
ui->hexOffsetText->find(s, QTextDocument::FindBackward);
ui->hexOffsetText->moveCursor(QTextCursor::EndOfLine, QTextCursor::MoveAnchor);
connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
ui->hexASCIIText->verticalScrollBar()->setValue(blocksMarginDefault * blockSize);
} }
@ -261,44 +243,16 @@ void HexdumpWidget::fillPlugins()
ui->hexArchComboBox_2->insertItems(0, Core()->getAsmPluginNames()); ui->hexArchComboBox_2->insertItems(0, Core()->getAsmPluginNames());
} }
QList<QString> HexdumpWidget::get_hexdump(const QString &offset) std::array<QString, 3> HexdumpWidget::fetchHexdump(RVA offset, RVA bytes)
{ {
RCoreLocked lcore = Core()->core(); QString hexdump = Core()->cmd(QString("px %1 @ %2").arg(QString::number(bytes), QString::number(offset)));
QList<QString> ret;
QString hexdump;
int hexdumpLength;
int cols = lcore->print->cols;
ut64 bsize = 128 * cols;
if (bottomOffset < bsize)
{
bottomOffset = 0;
hexdumpLength = bsize;
//-hexdumpBottomOffset;
}
else
{
hexdumpLength = bsize;
}
//this->main->add_debug_output("BSize: " + Core()->itoa(hexdumpLength, 10));
if (offset.isEmpty())
{
hexdump = Core()->cmd("px " + Core()->itoa(hexdumpLength, 10));
}
else
{
hexdump = Core()->cmd("px " + Core()->itoa(hexdumpLength, 10) + " @ " + offset);
}
//QString hexdump = Core()->cmd ("px 0x" + Core()->itoa(size) + " @ 0x0");
// TODO: use pxl to simplify
QString offsets; QString offsets;
QString hex; QString hex;
QString ascii; QString ascii;
int ln = 0; int ln = 0;
for (const QString line : hexdump.split("\n")) for (const QString &line : hexdump.split("\n"))
{ {
if (ln++ == 0) if (ln++ == 0)
{ {
@ -323,11 +277,8 @@ QList<QString> HexdumpWidget::get_hexdump(const QString &offset)
} }
} }
} }
ret << offsets.trimmed();
ret << hex.trimmed();
ret << ascii.trimmed();
return ret; return { offsets, hex, ascii };
} }
void HexdumpWidget::resizeHexdump() void HexdumpWidget::resizeHexdump()
@ -339,6 +290,8 @@ void HexdumpWidget::resizeHexdump()
void HexdumpWidget::hexScrolled() void HexdumpWidget::hexScrolled()
{ {
/*
RCoreLocked lcore = Core()->core(); RCoreLocked lcore = Core()->core();
QScrollBar *sb = ui->hexASCIIText->verticalScrollBar(); QScrollBar *sb = ui->hexASCIIText->verticalScrollBar();
@ -430,10 +383,10 @@ void HexdumpWidget::hexScrolled()
this->resizeHexdump(); this->resizeHexdump();
connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled())); connect(ui->hexASCIIText->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hexScrolled()));
} }*/
} }
void HexdumpWidget::on_hexHexText_2_selectionChanged() void HexdumpWidget::on_hexHexText_selectionChanged()
{ {
// Get selected partsing type // Get selected partsing type
QString parsing = ui->codeCombo_2->currentText(); QString parsing = ui->codeCombo_2->currentText();
@ -517,12 +470,12 @@ void HexdumpWidget::on_hexHexText_2_selectionChanged()
void HexdumpWidget::on_hexArchComboBox_2_currentTextChanged(const QString &/*arg1*/) void HexdumpWidget::on_hexArchComboBox_2_currentTextChanged(const QString &/*arg1*/)
{ {
on_hexHexText_2_selectionChanged(); on_hexHexText_selectionChanged();
} }
void HexdumpWidget::on_hexBitsComboBox_2_currentTextChanged(const QString &/*arg1*/) void HexdumpWidget::on_hexBitsComboBox_2_currentTextChanged(const QString &/*arg1*/)
{ {
on_hexHexText_2_selectionChanged(); on_hexHexText_selectionChanged();
} }
/* /*

View File

@ -2,7 +2,7 @@
#ifndef HEXDUMPWIDGET_H #ifndef HEXDUMPWIDGET_H
#define HEXDUMPWIDGET_H #define HEXDUMPWIDGET_H
#include <array>
#include <QDebug> #include <QDebug>
#include <QTextEdit> #include <QTextEdit>
#include <QDockWidget> #include <QDockWidget>
@ -67,6 +67,7 @@ private:
void refresh(RVA addr = RVA_INVALID); void refresh(RVA addr = RVA_INVALID);
void updateVisibleLines(); void updateVisibleLines();
std::array<QString, 3> fetchHexdump(RVA offset, RVA bytes);
private slots: private slots:
void on_seekChanged(RVA addr); void on_seekChanged(RVA addr);
@ -82,7 +83,7 @@ private slots:
void showHexdumpContextMenu(const QPoint &pt); void showHexdumpContextMenu(const QPoint &pt);
void showHexASCIIContextMenu(const QPoint &pt); void showHexASCIIContextMenu(const QPoint &pt);
void on_hexHexText_2_selectionChanged(); void on_hexHexText_selectionChanged();
void on_hexArchComboBox_2_currentTextChanged(const QString &arg1); void on_hexArchComboBox_2_currentTextChanged(const QString &arg1);
void on_hexBitsComboBox_2_currentTextChanged(const QString &arg1); void on_hexBitsComboBox_2_currentTextChanged(const QString &arg1);
@ -96,7 +97,6 @@ private slots:
void resizeHexdump(); void resizeHexdump();
void hexScrolled(); void hexScrolled();
QList<QString> get_hexdump(const QString &offset);
void on_codeCombo_2_currentTextChanged(const QString &arg1); void on_codeCombo_2_currentTextChanged(const QString &arg1);
void on_hexSideTab_2_currentChanged(int index); void on_hexSideTab_2_currentChanged(int index);