Skip to content

Commit 16b195a

Browse files
Yappawhoppa
Yappa
authored and
whoppa
committed
Fix "return" key in disassembler widget (rizinorg#3090)
Fix graph jumps
1 parent e69a007 commit 16b195a

7 files changed

+63
-6
lines changed

rizin

Submodule rizin updated 53 files

src/common/CutterSeekable.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void CutterSeekable::seekToReference(RVA offset)
6666
}
6767

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

7172
if (refs.length()) {

src/common/DisassemblyPreview.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,13 @@ RVA DisassemblyPreview::readDisassemblyOffset(QTextCursor tc)
8989

9090
return userData->line.offset;
9191
}
92+
93+
RVA DisassemblyPreview::readDisassemblyArrow(QTextCursor tc)
94+
{
95+
auto userData = getUserData(tc.block());
96+
if (!userData && userData->line.arrow != RVA_INVALID) {
97+
return RVA_INVALID;
98+
}
99+
100+
return userData->line.arrow;
101+
}

src/common/DisassemblyPreview.h

+6
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ bool showDisasPreview(QWidget *parent, const QPoint &pointOfEvent, const RVA off
4141
* @return The disassembly offset of the hovered asm text
4242
*/
4343
RVA readDisassemblyOffset(QTextCursor tc);
44+
45+
/*!
46+
* @brief Reads the arrow offset for the cursor position
47+
* @return The jump address of the hovered asm text
48+
*/
49+
RVA readDisassemblyArrow(QTextCursor tc);
4450
}
4551
#endif

src/translations

src/widgets/DisassemblerGraphView.cpp

+35-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,41 @@ void DisassemblerGraphView::blockDoubleClicked(GraphView::GraphBlock &block, QMo
914914
QPoint pos)
915915
{
916916
Q_UNUSED(event);
917-
seekable->seekToReference(getAddrForMouseEvent(block, &pos));
917+
RVA arrow = NULL;
918+
RVA offset = getAddrForMouseEvent(block, &pos);
919+
DisassemblyBlock *db = blockForAddress(offset);
920+
921+
Instr lastInstruction = db->instrs.back();
922+
923+
// Handle the blocks without any paths
924+
if (offset == lastInstruction.addr && db->false_path == RVA_INVALID
925+
&& db->true_path == RVA_INVALID) {
926+
return;
927+
}
928+
929+
// Handle the blocks with just one path
930+
if (offset == lastInstruction.addr && db->false_path == RVA_INVALID) {
931+
seekable->seek(db->true_path);
932+
return;
933+
}
934+
935+
// Handle blocks with two paths
936+
if (offset == lastInstruction.addr && db->false_path != RVA_INVALID) {
937+
// gets the offset for the next instruction
938+
RVA nextOffset = lastInstruction.addr + lastInstruction.size;
939+
// sets "arrow" to the path that isn't going to the next offset
940+
if (db->false_path == nextOffset) {
941+
arrow = db->true_path;
942+
} else if (db->true_path == nextOffset) {
943+
arrow = db->false_path;
944+
}
945+
946+
seekable->seek(arrow);
947+
return;
948+
}
949+
950+
// Handle "call" instruction to functions
951+
seekable->seekToReference(offset);
918952
}
919953

920954
void DisassemblerGraphView::blockHelpEvent(GraphView::GraphBlock &block, QHelpEvent *event,

src/widgets/DisassemblyWidget.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ void DisassemblyWidget::moveCursorRelative(bool up, bool page)
613613

614614
void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor)
615615
{
616+
// Handles "jmp" and conditonal jump instructions
617+
RVA arrow = DisassemblyPreview::readDisassemblyArrow(cursor);
618+
if (arrow != RVA_INVALID) {
619+
seekable->seek(arrow);
620+
}
621+
622+
// Handles "call" and "lea" instructions
616623
RVA offset = DisassemblyPreview::readDisassemblyOffset(cursor);
617624
seekable->seekToReference(offset);
618625
}
@@ -627,9 +634,8 @@ bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
627634
jumpToOffsetUnderCursor(cursor);
628635

629636
return true;
630-
} else if (Config()->getPreviewValue()
631-
&& event->type() == QEvent::ToolTip
632-
&& obj == mDisasTextEdit->viewport()) {
637+
} else if (Config()->getPreviewValue() && event->type() == QEvent::ToolTip
638+
&& obj == mDisasTextEdit->viewport()) {
633639
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
634640

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

0 commit comments

Comments
 (0)