From 2730244ec1d6a983cec2d3be6be53f0c144dcf3e Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Mon, 4 Sep 2023 10:52:07 -0400 Subject: [PATCH] Seek to first call if multiple references (#3240) --- src/common/CutterSeekable.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/common/CutterSeekable.cpp b/src/common/CutterSeekable.cpp index 12ef7b7b..bba7c317 100644 --- a/src/common/CutterSeekable.cpp +++ b/src/common/CutterSeekable.cpp @@ -65,7 +65,6 @@ void CutterSeekable::seekToReference(RVA offset) return; } - RVA target; QList refs = Core()->getXRefs(offset, false, false); if (refs.length()) { @@ -73,10 +72,19 @@ void CutterSeekable::seekToReference(RVA offset) qWarning() << tr("More than one (%1) references here. Weird behaviour expected.") .arg(refs.length()); } - - target = refs.at(0).to; - if (target != RVA_INVALID) { - seek(target); + // Try first call + for (auto &ref : refs) { + if (ref.to != RVA_INVALID && ref.type == "CALL") { + seek(ref.to); + return; + } + } + // Fallback to first valid, if any + for (auto &ref : refs) { + if (ref.to != RVA_INVALID) { + seek(ref.to); + return; + } } } }