diff --git a/ida/digest.cc b/ida/digest.cc index 819a76f8..d837f243 100644 --- a/ida/digest.cc +++ b/ida/digest.cc @@ -17,6 +17,7 @@ // clang-format off #include "third_party/zynamics/binexport/ida/begin_idasdk.inc" // NOLINT #include // NOLINT +#include // NOLINT #include "third_party/zynamics/binexport/ida/end_idasdk.inc" // NOLINT // clang-format on @@ -27,16 +28,25 @@ namespace security::binexport { absl::StatusOr GetInputFileSha256() { - std::string hash(32, '\0'); - if (!retrieve_input_file_sha256(reinterpret_cast(&hash[0]))) { + constexpr int kNumSha256Bytes = 32; + std::string hash(kNumSha256Bytes, '\0'); + auto* hash_uchar = reinterpret_cast(&hash[0]); + if (!retrieve_input_file_sha256(hash_uchar) && + // b/186782665: IDA 7.5 and lower use the root_node instead. + (root_node.supval(RIDX_SHA256, hash_uchar, kNumSha256Bytes) != + kNumSha256Bytes)) { return absl::InternalError("Failed to load SHA256 hash of input file"); } return absl::AsciiStrToLower(absl::BytesToHexString(hash)); } absl::StatusOr GetInputFileMd5() { - std::string hash(32, '\0'); - if (!retrieve_input_file_md5(reinterpret_cast(&hash[0]))) { + constexpr int kNumMd5Bytes = 16; + std::string hash(kNumMd5Bytes, '\0'); + auto* hash_uchar = reinterpret_cast(&hash[0]); + if (!retrieve_input_file_md5(hash_uchar) && + // b/186782665: IDA 7.5 and lower use the root_node instead. + (root_node.supval(RIDX_MD5, hash_uchar, kNumMd5Bytes) != kNumMd5Bytes)) { return absl::InternalError("Failed to load MD5 hash of input file"); } return absl::AsciiStrToLower(absl::BytesToHexString(hash)); diff --git a/ida/names.cc b/ida/names.cc index f1ee0684..616c3557 100644 --- a/ida/names.cc +++ b/ida/names.cc @@ -29,6 +29,8 @@ #include // NOLINT #include // NOLINT #include // NOLINT +#include // NOLINT +#include // NOLINT #include // NOLINT #include // NOLINT #include // NOLINT @@ -116,9 +118,13 @@ absl::optional GetArchitectureName() { int GetArchitectureBitness() { return inf_is_64bit() ? 64 : 32; } std::string GetModuleName() { - char path_buffer[QMAXPATH] = {0}; - get_input_file_path(path_buffer, QMAXPATH); - return Basename(path_buffer); + std::string path(QMAXPATH, '\0'); + if (get_input_file_path(&path[0], QMAXPATH) == 0) { + // b/186782665: IDA 7.5 and lower use the root_node instead. + root_node.valstr(&path[0], QMAXPATH); + } + path.resize(std::strlen(path.data())); + return Basename(path); } int GetOriginalIdaLine(const Address address, std::string* line) {