Skip to content

Commit 05bdadd

Browse files
author
Yappa
committed
Fix "return" key in disassembler widget (rizinorg#3090)
Fix graph jumps
1 parent 68ec5a3 commit 05bdadd

6 files changed

+55
-1
lines changed

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/widgets/DisassemblerGraphView.cpp

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

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

src/widgets/DisassemblyWidget.cpp

+7
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
}

src/widgets/DisassemblyWidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected slots:
9999
void moveCursorRelative(bool up, bool page);
100100

101101
void jumpToOffsetUnderCursor(const QTextCursor &);
102+
void jumpToArrowOffsetUnderCursor(const QTextCursor &);
102103
};
103104

104105
class DisassemblyScrollArea : public QAbstractScrollArea

0 commit comments

Comments
 (0)