mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-22 06:33:46 +00:00
Fix Hexdump bounds
This commit is contained in:
parent
e62d731783
commit
1bdb9ae80f
@ -129,7 +129,9 @@ void DisassemblyWidget::refreshDisasm(RVA offset)
|
|||||||
|
|
||||||
if (maxLines <= 0)
|
if (maxLines <= 0)
|
||||||
{
|
{
|
||||||
|
connectCursorPositionChanged(true);
|
||||||
mDisasTextEdit->clear();
|
mDisasTextEdit->clear();
|
||||||
|
connectCursorPositionChanged(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ void HexdumpWidget::refresh(RVA addr)
|
|||||||
addr = Core()->getOffset();
|
addr = Core()->getOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVisibleLines(); // TODO: only on resize
|
int visibleLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText);
|
||||||
|
|
||||||
RCoreLocked lcore = Core()->core();
|
RCoreLocked lcore = Core()->core();
|
||||||
|
|
||||||
@ -216,14 +216,36 @@ void HexdumpWidget::refresh(RVA addr)
|
|||||||
|
|
||||||
|
|
||||||
int cols = lcore->print->cols;
|
int cols = lcore->print->cols;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
topOffset = addr - linesMarginDefault * cols;
|
|
||||||
topOffset = (topOffset / cols) * cols; // align
|
|
||||||
|
|
||||||
int fetchLines = visibleLines + linesMarginDefault * 2;
|
int fetchLines = visibleLines + linesMarginDefault * 2;
|
||||||
RVA bytes = static_cast<RVA>(fetchLines) * cols;
|
RVA bytes = static_cast<RVA>(fetchLines) * cols;
|
||||||
|
|
||||||
bottomOffset = topOffset + bytes;
|
|
||||||
|
// upper bound of UT64_MAX
|
||||||
|
RVA bytesLeft = UT64_MAX - topOffset;
|
||||||
|
if (bytes > bytesLeft)
|
||||||
|
{
|
||||||
|
bottomOffset = UT64_MAX;
|
||||||
|
topOffset = bottomOffset - bytes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bottomOffset = topOffset + bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto hexdump = fetchHexdump(topOffset, bytes);
|
auto hexdump = fetchHexdump(topOffset, bytes);
|
||||||
|
|
||||||
@ -238,9 +260,12 @@ void HexdumpWidget::refresh(RVA addr)
|
|||||||
cur.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, linesMarginDefault);
|
cur.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, linesMarginDefault);
|
||||||
ui->hexOffsetText->setTextCursor(cur);
|
ui->hexOffsetText->setTextCursor(cur);
|
||||||
|
|
||||||
connectScroll(false);
|
int scroll = static_cast<int>((addr - topOffset) / cols);
|
||||||
|
ui->hexOffsetText->verticalScrollBar()->setValue(scroll);
|
||||||
|
ui->hexHexText->verticalScrollBar()->setValue(scroll);
|
||||||
|
ui->hexASCIIText->verticalScrollBar()->setValue(scroll);
|
||||||
|
|
||||||
ui->hexASCIIText->verticalScrollBar()->setValue(linesMarginDefault);
|
connectScroll(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HexdumpWidget::appendHexdumpLines(int lines, bool top)
|
void HexdumpWidget::appendHexdumpLines(int lines, bool top)
|
||||||
@ -250,10 +275,18 @@ void HexdumpWidget::appendHexdumpLines(int lines, bool top)
|
|||||||
int cols = Core()->getConfigi("hex.cols");
|
int cols = Core()->getConfigi("hex.cols");
|
||||||
RVA bytes = static_cast<RVA>(lines) * cols;
|
RVA bytes = static_cast<RVA>(lines) * cols;
|
||||||
|
|
||||||
// TODO: check bounds
|
|
||||||
|
|
||||||
if (top)
|
if (top)
|
||||||
{
|
{
|
||||||
|
if (bytes > topOffset)
|
||||||
|
{
|
||||||
|
bytes = topOffset;
|
||||||
|
if (bytes == 0)
|
||||||
|
{
|
||||||
|
connectScroll(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
topOffset -= bytes;
|
topOffset -= bytes;
|
||||||
auto hexdump = fetchHexdump(topOffset, bytes);
|
auto hexdump = fetchHexdump(topOffset, bytes);
|
||||||
|
|
||||||
@ -272,10 +305,23 @@ void HexdumpWidget::appendHexdumpLines(int lines, bool top)
|
|||||||
cur.insertText(hexdump[2]);
|
cur.insertText(hexdump[2]);
|
||||||
|
|
||||||
int actualLines = static_cast<int>(bytes / cols);
|
int actualLines = static_cast<int>(bytes / cols);
|
||||||
|
ui->hexOffsetText->verticalScrollBar()->setValue(actualLines + scroll);
|
||||||
|
ui->hexHexText->verticalScrollBar()->setValue(actualLines + scroll);
|
||||||
ui->hexASCIIText->verticalScrollBar()->setValue(actualLines + scroll);
|
ui->hexASCIIText->verticalScrollBar()->setValue(actualLines + scroll);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (bytes > UT64_MAX - bottomOffset)
|
||||||
|
{
|
||||||
|
bytes = UT64_MAX - bottomOffset;
|
||||||
|
|
||||||
|
if (bytes == 0)
|
||||||
|
{
|
||||||
|
connectScroll(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto hexdump = fetchHexdump(bottomOffset, bytes);
|
auto hexdump = fetchHexdump(bottomOffset, bytes);
|
||||||
bottomOffset += bytes;
|
bottomOffset += bytes;
|
||||||
|
|
||||||
@ -305,43 +351,39 @@ void HexdumpWidget::removeHexdumpLines(int lines, bool top)
|
|||||||
|
|
||||||
int scroll = ui->hexASCIIText->verticalScrollBar()->value();
|
int scroll = ui->hexASCIIText->verticalScrollBar()->value();
|
||||||
|
|
||||||
for (QPlainTextEdit *edit : edits)
|
if (top)
|
||||||
{
|
{
|
||||||
QTextCursor cur = edit->textCursor();
|
for (QPlainTextEdit *edit : edits)
|
||||||
|
|
||||||
if (top)
|
|
||||||
{
|
{
|
||||||
|
QTextCursor cur = edit->textCursor();
|
||||||
cur.movePosition(QTextCursor::Start);
|
cur.movePosition(QTextCursor::Start);
|
||||||
cur.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, lines + 1);
|
cur.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, lines + 1);
|
||||||
|
cur.removeSelectedText();
|
||||||
topOffset += lines * cols;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
|
QTextCursor cur = edit->textCursor();
|
||||||
cur.movePosition(QTextCursor::End);
|
cur.movePosition(QTextCursor::End);
|
||||||
cur.movePosition(QTextCursor::Up, QTextCursor::KeepAnchor, lines);
|
cur.movePosition(QTextCursor::Up, QTextCursor::KeepAnchor, lines);
|
||||||
cur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
|
cur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
|
||||||
cur.removeSelectedText();
|
cur.removeSelectedText();
|
||||||
|
|
||||||
bottomOffset -= lines * cols;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cur.removeSelectedText();
|
bottomOffset -= lines * cols;
|
||||||
}
|
|
||||||
|
|
||||||
if (top)
|
|
||||||
{
|
|
||||||
ui->hexASCIIText->verticalScrollBar()->setValue(scroll - lines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectScroll(false);
|
connectScroll(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HexdumpWidget::updateVisibleLines()
|
|
||||||
{
|
|
||||||
visibleLines = qhelpers::getMaxFullyDisplayedLines(ui->hexHexText);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Content management functions
|
* Content management functions
|
||||||
*/
|
*/
|
||||||
@ -399,11 +441,9 @@ void HexdumpWidget::resizeHexdump()
|
|||||||
|
|
||||||
void HexdumpWidget::hexScrolled()
|
void HexdumpWidget::hexScrolled()
|
||||||
{
|
{
|
||||||
RCoreLocked lcore = Core()->core();
|
|
||||||
QScrollBar *sb = ui->hexASCIIText->verticalScrollBar();
|
QScrollBar *sb = ui->hexASCIIText->verticalScrollBar();
|
||||||
|
int topMargin = sb->value() - sb->minimum();
|
||||||
int topMargin = sb->value();
|
int bottomMargin = sb->maximum() - sb->value();
|
||||||
int bottomMargin = sb->maximum() - sb->value();
|
|
||||||
|
|
||||||
if (topMargin < linesMarginMin)
|
if (topMargin < linesMarginMin)
|
||||||
{
|
{
|
||||||
|
@ -63,8 +63,6 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<Ui::HexdumpWidget> ui;
|
std::unique_ptr<Ui::HexdumpWidget> ui;
|
||||||
|
|
||||||
int visibleLines;
|
|
||||||
|
|
||||||
RVA topOffset;
|
RVA topOffset;
|
||||||
RVA bottomOffset;
|
RVA bottomOffset;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user