Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "return" key in disassembler widget (#3090) and graph jumps #3146

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/CutterSeekable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void CutterSeekable::seekToReference(RVA offset)
}

RVA target;
// finds the xrefs for calls, lea, and jmp
QList<XrefDescription> refs = Core()->getXRefs(offset, false, false);

if (refs.length()) {
Expand Down
10 changes: 10 additions & 0 deletions src/common/DisassemblyPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@ RVA DisassemblyPreview::readDisassemblyOffset(QTextCursor tc)

return userData->line.offset;
}

RVA DisassemblyPreview::readDisassemblyArrow(QTextCursor tc)
{
auto userData = getUserData(tc.block());
if (!userData && userData->line.arrow != RVA_INVALID) {
return RVA_INVALID;
}

return userData->line.arrow;
}
6 changes: 6 additions & 0 deletions src/common/DisassemblyPreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ bool showDisasPreview(QWidget *parent, const QPoint &pointOfEvent, const RVA off
* @return The disassembly offset of the hovered asm text
*/
RVA readDisassemblyOffset(QTextCursor tc);

/*!
* @brief Reads the arrow offset for the cursor position
* @return The jump address of the hovered asm text
*/
RVA readDisassemblyArrow(QTextCursor tc);
}
#endif
36 changes: 35 additions & 1 deletion src/widgets/DisassemblerGraphView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,41 @@ void DisassemblerGraphView::blockDoubleClicked(GraphView::GraphBlock &block, QMo
QPoint pos)
{
Q_UNUSED(event);
seekable->seekToReference(getAddrForMouseEvent(block, &pos));
RVA arrow = NULL;
RVA offset = getAddrForMouseEvent(block, &pos);
DisassemblyBlock *db = blockForAddress(offset);

Instr lastInstruction = db->instrs.back();

// Handle the blocks without any paths
if (offset == lastInstruction.addr && db->false_path == RVA_INVALID
&& db->true_path == RVA_INVALID) {
return;
}

// Handle the blocks with just one path
if (offset == lastInstruction.addr && db->false_path == RVA_INVALID) {
seekable->seek(db->true_path);
return;
}

// Handle blocks with two paths
if (offset == lastInstruction.addr && db->false_path != RVA_INVALID) {
// gets the offset for the next instruction
RVA nextOffset = lastInstruction.addr + lastInstruction.size;
// sets "arrow" to the path that isn't going to the next offset
if (db->false_path == nextOffset) {
arrow = db->true_path;
} else if (db->true_path == nextOffset) {
arrow = db->false_path;
}

seekable->seek(arrow);
return;
}

// Handle "call" instruction to functions
seekable->seekToReference(offset);
}

void DisassemblerGraphView::blockHelpEvent(GraphView::GraphBlock &block, QHelpEvent *event,
Expand Down
12 changes: 9 additions & 3 deletions src/widgets/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,13 @@ void DisassemblyWidget::moveCursorRelative(bool up, bool page)

void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor)
{
// Handles "jmp" and conditonal jump instructions
RVA arrow = DisassemblyPreview::readDisassemblyArrow(cursor);
if (arrow != RVA_INVALID) {
seekable->seek(arrow);
}

// Handles "call" and "lea" instructions
RVA offset = DisassemblyPreview::readDisassemblyOffset(cursor);
seekable->seekToReference(offset);
}
Expand All @@ -627,9 +634,8 @@ bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
jumpToOffsetUnderCursor(cursor);

return true;
} else if (Config()->getPreviewValue()
&& event->type() == QEvent::ToolTip
&& obj == mDisasTextEdit->viewport()) {
} else if (Config()->getPreviewValue() && event->type() == QEvent::ToolTip
&& obj == mDisasTextEdit->viewport()) {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);

auto cursorForWord = mDisasTextEdit->cursorForPosition(helpEvent->pos());
Expand Down