Limit Disassembly scrolling from 0 and RVA_MAX

This commit is contained in:
Florian Märkl 2018-04-15 19:06:05 +02:00
parent b8594e3bf5
commit 6934d785f4

View File

@ -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,27 +444,33 @@ 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
// move some instructions down if necessary.
// disassembly from calculated offset may have more than maxLines lines auto lines = Core()->disassembleLines(offset, maxLines).toVector();
// move some instructions down if necessary. int oldTopLine;
for (oldTopLine = lines.length(); oldTopLine > 0; oldTopLine--) {
auto lines = Core()->disassembleLines(offset, maxLines).toVector(); if (lines[oldTopLine - 1].offset < topOffset) {
int oldTopLine; break;
for (oldTopLine = lines.length(); oldTopLine > 0; oldTopLine--) { }
if (lines[oldTopLine - 1].offset < topOffset) {
break;
} }
}
int overflowLines = oldTopLine - maxLines; int overflowLines = oldTopLine - maxLines;
if (overflowLines > 0) { if (overflowLines > 0) {
while (lines[overflowLines - 1].offset == lines[overflowLines].offset while (lines[overflowLines - 1].offset == lines[overflowLines].offset
&& overflowLines < lines.length() - 1) { && overflowLines < lines.length() - 1) {
overflowLines++; overflowLines++;
}
offset = lines[overflowLines].offset;
} }
offset = lines[overflowLines].offset;
} }
} }
refreshDisasm(offset); refreshDisasm(offset);
@ -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();