From 7c8ad0eeb34ca1e5a0f41dec71956d55a96e9bb2 Mon Sep 17 00:00:00 2001 From: Clark Coleman <clc@zephyr-software.com> Date: Tue, 17 Dec 2019 13:33:08 -0500 Subject: [PATCH] Use IDA Pro is_dll() method as preferred way to detect shared objects. --- src/interfaces/idapro/STARSIDAProgram.cpp | 95 ++++++++++++----------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/src/interfaces/idapro/STARSIDAProgram.cpp b/src/interfaces/idapro/STARSIDAProgram.cpp index 7a65485d..db2e55cd 100644 --- a/src/interfaces/idapro/STARSIDAProgram.cpp +++ b/src/interfaces/idapro/STARSIDAProgram.cpp @@ -22,6 +22,7 @@ // IDA Pro headers #include <bytes.hpp> // for get_flags(), is_code(), is_data(), is_unknown() +#include <ida.hpp> // for is_dll() #if 0 #include <pro.h> @@ -157,59 +158,65 @@ void STARS_IDA_Program_t::DetermineRootFileName(void) { string TempRootString(TempRootName); this->SetRootFileName(TempRootString); - // Try to find ".so" or ".dll" or ".a" in file name, indicating shared object. - // This code below only works for non-renamed file, e.g. STARS/IDA Pro operation, - // and not files renamed with new extensions, e.g. a.ncexe. Replace with info from - // file header soon. - bool sharedObjectFlag = false; - char token[210]; - std::size_t tokencount = 0; - istringstream FileNameStr(TempRootString); - this->SetSharedObjectFlag(false); - char delim = '.'; - FileNameStr.getline(token, 200, delim); - while (FileNameStr.rdstate() == std::istringstream::goodbit) { - ++tokencount; - if (1 < tokencount) { // Not looking for file extension before first "." - sharedObjectFlag = ((0 == strcmp(token, "so")) || (0 == strcmp(token, "dll")) - || (0 == strcmp(token, "a"))); - if (sharedObjectFlag) { - this->SetSharedObjectFlag(sharedObjectFlag); - SMP_msg("INFO: Determined shared object from file extension %s\n", token); - break; + if (::inf.is_dll()) { + this->SetSharedObjectFlag(true); + SMP_msg("INFO: Determined shard object from is_dll() in IDA Pro.\n"); + } + else { + // Try to find ".so" or ".dll" or ".a" in file name, indicating shared object. + // This code below only works for non-renamed file, e.g. STARS/IDA Pro operation, + // and not files renamed with new extensions, e.g. a.ncexe. Replace with info from + // file header soon. + bool sharedObjectFlag = false; + char token[210]; + std::size_t tokencount = 0; + istringstream FileNameStr(TempRootString); + this->SetSharedObjectFlag(false); + char delim = '.'; + FileNameStr.getline(token, 200, delim); + while (FileNameStr.rdstate() == std::istringstream::goodbit) { + ++tokencount; + if (1 < tokencount) { // Not looking for file extension before first "." + sharedObjectFlag = ((0 == strcmp(token, "so")) || (0 == strcmp(token, "dll")) + || (0 == strcmp(token, "a"))); + if (sharedObjectFlag) { + this->SetSharedObjectFlag(sharedObjectFlag); + SMP_msg("INFO: Determined shared object from file extension %s\n", token); + break; + } } + FileNameStr.getline(token, 200, delim); } - FileNameStr.getline(token, 200, delim); - } #if 1 - // See if shared object extension is at the very end, with no more "." delimiter after. - // Find file name extension. - if (!sharedObjectFlag) { - string delimiter("."); - std::size_t found = TempRootString.rfind(delimiter, TempRootString.length()); - if (found != std::string::npos) { // found last instance of delimiter - string extension = TempRootString.substr(found, std::string::npos); - if (!extension.empty()) { - // This code below only works for non-renamed files, e.g. STARS/IDA Pro operation, - // and not files renamed with new extensions, e.g. a.ncexe. Replace with info from - // file header soon. - SMP_msg("INFO: Found extension %s\n", extension.c_str()); - sharedObjectFlag = ((0 == extension.compare(".so")) || (0 == extension.compare(".dll")) - || (0 == extension.compare(".a"))); - this->SetSharedObjectFlag(sharedObjectFlag); - if (sharedObjectFlag) - SMP_msg("INFO: Determined shared object from file extension %s\n", extension.c_str()); + // See if shared object extension is at the very end, with no more "." delimiter after. + // Find file name extension. + if (!sharedObjectFlag) { + string delimiter("."); + std::size_t found = TempRootString.rfind(delimiter, TempRootString.length()); + if (found != std::string::npos) { // found last instance of delimiter + string extension = TempRootString.substr(found, std::string::npos); + if (!extension.empty()) { + // This code below only works for non-renamed files, e.g. STARS/IDA Pro operation, + // and not files renamed with new extensions, e.g. a.ncexe. Replace with info from + // file header soon. + SMP_msg("INFO: Found extension %s\n", extension.c_str()); + sharedObjectFlag = ((0 == extension.compare(".so")) || (0 == extension.compare(".dll")) + || (0 == extension.compare(".a"))); + this->SetSharedObjectFlag(sharedObjectFlag); + if (sharedObjectFlag) + SMP_msg("INFO: Determined shared object from file extension %s\n", extension.c_str()); + } + else { + SMP_msg("ERROR: Empty file name extension.\n"); + } } else { - SMP_msg("ERROR: Empty file name extension.\n"); + SMP_msg("ERROR: Could not reverse-find the dot delimiter in file name.\n"); } } - else { - SMP_msg("ERROR: Could not reverse-find the dot delimiter in file name.\n"); - } - } #endif + } return; } -- GitLab