From e56913e9b81e4874268d539a65e69e560f32486e Mon Sep 17 00:00:00 2001
From: Clark Coleman <clc@zephyr-software.com>
Date: Fri, 2 Oct 2020 00:23:33 -0400
Subject: [PATCH] Fix IsInstIDInFunc() for chunked code layout functions.

---
 src/interfaces/idapro/STARSFunction.cpp | 31 +++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/interfaces/idapro/STARSFunction.cpp b/src/interfaces/idapro/STARSFunction.cpp
index bb30d2f9..85279740 100644
--- a/src/interfaces/idapro/STARSFunction.cpp
+++ b/src/interfaces/idapro/STARSFunction.cpp
@@ -65,8 +65,35 @@ bool STARS_IDA_Function_t::IsChunkUnshared(STARS_ea_t ChunkAddr, STARS_ea_t Func
 
 // Is InstID in this function? For IDA Pro, InstID is a code address.
 bool STARS_IDA_Function_t::IsInstIDInFunc(STARS_ea_t InstID) {
-	return ((InstID >= this->get_startEA()) && (InstID < this->get_endEA()));
-}
+	bool HasChunks = (this->HasSharedChunks() || this->UnsharedChunks);
+	bool Found = false;
+	if (HasChunks) {
+		func_tail_iterator_t FuncTail(this->the_func);
+		for (bool ChunkOK = FuncTail.main(); ChunkOK; ChunkOK = FuncTail.next()) {
+			const STARS_area_t &CurrChunk = FuncTail.chunk();
+			STARS_ea_t CurrChunkStartAddr;
+			STARS_ea_t CurrChunkLastAddr;
+#if (IDA_SDK_VERSION < 700)
+			CurrChunkLastAddr = CurrChunk.endEA;
+#else
+			CurrChunkLastAddr = CurrChunk.end_ea;
+#endif
+#if (IDA_SDK_VERSION < 700)
+			CurrChunkStartAddr = CurrChunk.startEA;
+#else
+			CurrChunkStartAddr = CurrChunk.start_ea;
+#endif
+			if ((InstID >= CurrChunkStartAddr) && (InstID < CurrChunkLastAddr)) {
+				Found = true;
+				break;
+			}
+		} // end for all chunks in function
+	}
+	else {
+		Found = ((InstID >= this->get_startEA()) && (InstID < this->get_endEA()));
+	}
+	return Found;
+} // end of STARS_IDA_Function_t::IsInstIDInFunc()
 
 void STARS_IDA_Function_t::MarkSharedChunks(void) {
 
-- 
GitLab