mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Limit Disassembly scrolling from 0 and RVA_MAX
This commit is contained in:
parent
b8594e3bf5
commit
6934d785f4
@ -205,31 +205,34 @@ void DisassemblyWidget::refreshDisasm(RVA offset)
|
|||||||
mDisasTextEdit->document()->clear();
|
mDisasTextEdit->document()->clear();
|
||||||
QTextCursor cursor(mDisasTextEdit->document());
|
QTextCursor cursor(mDisasTextEdit->document());
|
||||||
for (DisassemblyLine line : disassemblyLines) {
|
for (DisassemblyLine line : disassemblyLines) {
|
||||||
|
if (line.offset < topOffset) { // overflow
|
||||||
|
break;
|
||||||
|
}
|
||||||
cursor.insertHtml(line.text);
|
cursor.insertHtml(line.text);
|
||||||
auto a = new DisassemblyTextBlockUserData(line);
|
auto a = new DisassemblyTextBlockUserData(line);
|
||||||
cursor.block().setUserData(a);
|
cursor.block().setUserData(a);
|
||||||
cursor.insertBlock();
|
cursor.insertBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get bottomOffset from last visible line.
|
if (!disassemblyLines.isEmpty()) {
|
||||||
// because pd N may return more than N lines, move maxLines lines down from the top
|
bottomOffset = disassemblyLines[qMin(disassemblyLines.size(), maxLines) - 1].offset;
|
||||||
mDisasTextEdit->moveCursor(QTextCursor::Start);
|
if (bottomOffset < topOffset) {
|
||||||
QTextCursor tc = mDisasTextEdit->textCursor();
|
bottomOffset = RVA_MAX;
|
||||||
tc.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, maxLines - 1);
|
}
|
||||||
mDisasTextEdit->setTextCursor(tc);
|
} else {
|
||||||
|
|
||||||
connectCursorPositionChanged(false);
|
|
||||||
|
|
||||||
bottomOffset = readCurrentDisassemblyOffset();
|
|
||||||
if (bottomOffset == RVA_INVALID) {
|
|
||||||
bottomOffset = topOffset;
|
bottomOffset = topOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove additional lines
|
// remove additional lines
|
||||||
|
QTextCursor tc = mDisasTextEdit->textCursor();
|
||||||
|
tc.movePosition(QTextCursor::Start);
|
||||||
|
tc.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, maxLines - 1);
|
||||||
tc.movePosition(QTextCursor::EndOfLine);
|
tc.movePosition(QTextCursor::EndOfLine);
|
||||||
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||||
tc.removeSelectedText();
|
tc.removeSelectedText();
|
||||||
|
|
||||||
|
connectCursorPositionChanged(false);
|
||||||
|
|
||||||
updateCursorPosition();
|
updateCursorPosition();
|
||||||
|
|
||||||
mDisasTextEdit->setLockScroll(false);
|
mDisasTextEdit->setLockScroll(false);
|
||||||
@ -246,8 +249,14 @@ void DisassemblyWidget::scrollInstructions(int count)
|
|||||||
RVA offset;
|
RVA offset;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
offset = Core()->nextOpAddr(topOffset, count);
|
offset = Core()->nextOpAddr(topOffset, count);
|
||||||
|
if (offset < topOffset) {
|
||||||
|
offset = RVA_MAX;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
offset = Core()->prevOpAddr(topOffset, -count);
|
offset = Core()->prevOpAddr(topOffset, -count);
|
||||||
|
if (offset > topOffset) {
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDisasm(offset);
|
refreshDisasm(offset);
|
||||||
@ -435,9 +444,14 @@ void DisassemblyWidget::moveCursorRelative(bool up, bool page)
|
|||||||
RVA offset;
|
RVA offset;
|
||||||
if (!up) {
|
if (!up) {
|
||||||
offset = Core()->nextOpAddr(bottomOffset, 1);
|
offset = Core()->nextOpAddr(bottomOffset, 1);
|
||||||
|
if (offset < bottomOffset) {
|
||||||
|
offset = RVA_MAX;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
offset = Core()->prevOpAddr(topOffset, maxLines);
|
offset = Core()->prevOpAddr(topOffset, maxLines);
|
||||||
|
if (offset > topOffset) {
|
||||||
|
offset = 0;
|
||||||
|
} else {
|
||||||
// disassembly from calculated offset may have more than maxLines lines
|
// disassembly from calculated offset may have more than maxLines lines
|
||||||
// move some instructions down if necessary.
|
// move some instructions down if necessary.
|
||||||
|
|
||||||
@ -458,6 +472,7 @@ void DisassemblyWidget::moveCursorRelative(bool up, bool page)
|
|||||||
offset = lines[overflowLines].offset;
|
offset = lines[overflowLines].offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
refreshDisasm(offset);
|
refreshDisasm(offset);
|
||||||
} else { // normal arrow keys
|
} else { // normal arrow keys
|
||||||
int blockCount = mDisasTextEdit->blockCount();
|
int blockCount = mDisasTextEdit->blockCount();
|
||||||
@ -519,7 +534,7 @@ void DisassemblyWidget::on_seekChanged(RVA offset)
|
|||||||
cursorLineOffset = 0;
|
cursorLineOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topOffset != RVA_INVALID && bottomOffset != RVA_INVALID
|
if (topOffset != RVA_INVALID
|
||||||
&& offset >= topOffset && offset <= bottomOffset) {
|
&& offset >= topOffset && offset <= bottomOffset) {
|
||||||
// if the line with the seek offset is currently visible, just move the cursor there
|
// if the line with the seek offset is currently visible, just move the cursor there
|
||||||
updateCursorPosition();
|
updateCursorPosition();
|
||||||
|
Loading…
Reference in New Issue
Block a user