From 9f4c23abd8769b189b19eda72358f0eb28581434 Mon Sep 17 00:00:00 2001
From: Clark Coleman <clc@zephyr-software.com>
Date: Sat, 1 May 2021 11:35:20 -0700
Subject: [PATCH] Updates to interface with IDA Pro 7.5.

---
 include/interfaces/STARSIDATypes.h        |  9 +++++++
 include/interfaces/idapro/all.h           |  1 +
 src/drivers/idapro/SMPStaticAnalyzer.cpp  | 30 +++++++++++++++++++----
 src/interfaces/idapro/STARSIDAProgram.cpp |  2 +-
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/include/interfaces/STARSIDATypes.h b/include/interfaces/STARSIDATypes.h
index 94ba7aac..92be9844 100644
--- a/include/interfaces/STARSIDATypes.h
+++ b/include/interfaces/STARSIDATypes.h
@@ -49,6 +49,7 @@
 // #include <fpro.h>  // for qf... functions
 #include <bytes.hpp>   // for getFlags(), isCode(), IsHead(), get_item_end(), next_head(), get_flags_novalue()
 #include <frame.hpp>   // for get_frame()
+#include <ida.hpp>     // for ::inf.is_dll()
 // #include <kernwin.hpp> // for msg()
 // #include <lines.hpp>  // for tag_remove()
 #include <name.hpp>  // for get_true_name()
@@ -108,6 +109,14 @@ typedef range_t STARS_area_t;
 // #define SMP_get_true_name(from, ea, buf, bufsize) get_true_name(from, ea, buf, bufsize)
 #define SMP_next_head(ea, maxea) next_head(ea, maxea)
 
+#if (IDA_SDK_VERSION < 750)
+#define SMP_is_dll()  ::inf.is_dll()
+#define SMP_is_64bit() ::inf.is_64bit()
+#else
+#define SMP_is_dll()  ::inf_is_dll()
+#define SMP_is_64bit() ::inf_is_64bit()
+#endif
+
 #define SMP_add_cref(from, to, type) add_cref(from, to, type)
 
 struct SMP_xref_t {
diff --git a/include/interfaces/idapro/all.h b/include/interfaces/idapro/all.h
index 51199ad6..c1e0e87d 100644
--- a/include/interfaces/idapro/all.h
+++ b/include/interfaces/idapro/all.h
@@ -8,6 +8,7 @@
 #pragma GCC diagnostic ignored "-Wparentheses"
 #pragma GCC diagnostic ignored "-Wsign-compare"
 #pragma GCC diagnostic ignored "-Wclass-memaccess"
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 
 #include <fpro.h>
 #include <pro.h>
diff --git a/src/drivers/idapro/SMPStaticAnalyzer.cpp b/src/drivers/idapro/SMPStaticAnalyzer.cpp
index e1796040..ae6e80af 100644
--- a/src/drivers/idapro/SMPStaticAnalyzer.cpp
+++ b/src/drivers/idapro/SMPStaticAnalyzer.cpp
@@ -49,7 +49,7 @@
 #include <bytes.hpp>
 #include <nalt.hpp>
 #endif
-#include <loader.hpp>
+#include <loader.hpp>  // for plugin_t
 
 #include "interfaces/STARSTypes.h"
 #include "interfaces/STARSIDATypes.h"
@@ -175,7 +175,7 @@ set<string> ZST_SystemCallNumericWhitelist;
 #if (IDA_SDK_VERSION < 700)
 void IDAP_run(int);
 #else
-bool IDAP_run(size_t);
+bool IDAP_run(std::size_t);
 #endif
 
 // Functions for diagnosing and/or fixing problems in the IDA database.
@@ -196,7 +196,7 @@ static unsigned long DebugCounter = 0;
 // Turn LOCK prefix into no-op when detected. Each is one byte in length.
 bool STARS_custom_ana(STARS_ea_t CurrentAddr) {
 	// static_assert(sizeof(STARS_ea_t) == sizeof(uintptr_t), "Sizeof mismatch between STARS_ea_t and uintptr_t");
-	int code = get_byte(CurrentAddr);
+	int code = ::get_byte(CurrentAddr);
 	++CustomAnaCallCount;
 	if (X86_LOCK_PREFIX != code) {
 		return false;
@@ -295,7 +295,19 @@ static ssize_t idaapi idp_callback(void *, int event_id, va_list va) {
 	return 0;  // did not process any event
 } // end of idp_callback()
 
+#if (IDA_SDK_VERSION < 750)
 int IDAP_init(void) {
+#else
+struct STARS_plugmod_t : public plugmod_t {
+	bool run(std::size_t arg) {
+		return IDAP_run(arg);
+	}
+};
+static STARS_plugmod_t PluginModuleStruct;
+
+plugmod_t *IDAP_init(void) {
+#endif
+
 
 	/* init the interface */
 	global_stars_interface = new STARS_IDA_Interface_t;
@@ -314,7 +326,11 @@ int IDAP_init(void) {
 	if (ph.id != PLFM_386 && ph.id != PLFM_ARM && ph.id != PLFM_MIPS) 
 	{
 		error("Processor must be x86, ARM or MIPS.");
+#if (IDA_SDK_VERSION < 750)
 		return PLUGIN_SKIP;
+#else
+		return nullptr;
+#endif
 	}
 
 #if (IDA_SDK_VERSION < 700)
@@ -326,7 +342,11 @@ int IDAP_init(void) {
 #ifdef STARS_IRDB_INTERFACE
 	SMPLogFile = nullptr;
 #endif
+#if (IDA_SDK_VERSION < 750)
 	return PLUGIN_KEEP;
+#else
+	return &PluginModuleStruct;
+#endif
 } // end of IDAP_init
 
 void IDAP_term(void) {
@@ -342,7 +362,7 @@ void IDAP_term(void) {
 #if (IDA_SDK_VERSION < 700)
 void IDAP_run(int arg) {
 #else
-bool IDAP_run(size_t arg) {
+bool IDAP_run(std::size_t arg) {
 #endif
 	FILE *AnnotFile = nullptr;
 	FILE *InfoAnnotFile = nullptr;
@@ -384,7 +404,7 @@ bool IDAP_run(size_t arg) {
 	SMP_msg("INFO: Size of STARS_ea_t: %zu Size of uintptr_t: %zu \n", sizeof(STARS_ea_t), sizeof(uintptr_t));
 	SMP_msg("INFO: Size of SMPInstr: %zu Size of SMPBasicBlock: %zu \n", sizeof(SMPInstr), sizeof(SMPBasicBlock));
 
-	if (inf.is_64bit()) {
+	if (SMP_is_64bit()) {
 		global_STARS_program->Set64BitBinary();
 		const auto pt = (ph.id == PLFM_386) ? ptX86_64 :
 		                (ph.id == PLFM_ARM) ? ptARM64  :
diff --git a/src/interfaces/idapro/STARSIDAProgram.cpp b/src/interfaces/idapro/STARSIDAProgram.cpp
index db2e55cd..32778bbd 100644
--- a/src/interfaces/idapro/STARSIDAProgram.cpp
+++ b/src/interfaces/idapro/STARSIDAProgram.cpp
@@ -158,7 +158,7 @@ void STARS_IDA_Program_t::DetermineRootFileName(void) {
 	string TempRootString(TempRootName);
 	this->SetRootFileName(TempRootString);
 
-	if (::inf.is_dll()) {
+	if (SMP_is_dll()) {
 		this->SetSharedObjectFlag(true);
 		SMP_msg("INFO: Determined shard object from is_dll() in IDA Pro.\n");
 	}
-- 
GitLab