Skip to content

Commit

Permalink
IDA Pro: Implement GetArchitectureBitness() directly using `inf_get…
Browse files Browse the repository at this point in the history
…_app_bitness()`

PiperOrigin-RevId: 633177650
Change-Id: I6810a5fb2eb8cf667dd8894e68123b6da3269ac9
  • Loading branch information
cblichmann authored and copybara-github committed May 13, 2024
1 parent 29ba7f4 commit d37b404
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 5 additions & 1 deletion ida/main_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

#include "third_party/zynamics/binexport/ida/main_plugin.h"

#include <cstddef>
#include <fstream>
#include <string>

// clang-format off
#include "third_party/zynamics/binexport/ida/begin_idasdk.inc" // NOLINT
#include <auto.hpp> // NOLINT
Expand Down Expand Up @@ -294,7 +298,7 @@ bool Plugin::Init() {
alsologtostderr_ =
absl::AsciiStrToUpper(GetArgument("AlsoLogToStdErr")) == "TRUE";
log_filename_ = GetArgument("LogFile");
if (auto status = InitLogging(LoggingOptions{}
if (auto status = InitLogging(LoggingOptions()
.set_alsologtostderr(alsologtostderr_)
.set_log_filename(log_filename_),
absl::make_unique<IdaLogSink>());
Expand Down
18 changes: 10 additions & 8 deletions ida/names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#include "third_party/zynamics/binexport/ida/names.h"

#include <cinttypes>
#include <cstddef>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

// clang-format off
#include "third_party/zynamics/binexport/ida/begin_idasdk.inc" // NOLINT
Expand Down Expand Up @@ -82,6 +84,8 @@ Architecture GetArchitecture() {
return kGeneric;
}

int GetArchitectureBitness() { return inf_get_app_bitness(); }

absl::optional<std::string> GetArchitectureName() {
std::string architecture;
switch (GetArchitecture()) {
Expand All @@ -107,7 +111,7 @@ absl::optional<std::string> GetArchitectureName() {
return {};
}

switch (size_t address_size = inf_get_app_bitness(); address_size) {
switch (size_t address_size = GetArchitectureBitness(); address_size) {
case 64:
absl::StrAppend(&architecture, "-64");
break;
Expand All @@ -118,19 +122,17 @@ absl::optional<std::string> GetArchitectureName() {
absl::StrAppend(&architecture, "-16");
break;
default:
LOG(WARNING) << "Unexpected address size " << address_size
<< " for architecture \"" << architecture
<< "\", export may be incorrect";
LOG_IF(WARNING, architecture != "GENERIC")
LOG_FIRST_N(WARNING, 1) << "Unexpected address size " << address_size
<< " for architecture \"" << architecture
<< "\", export may be incorrect";
LOG_IF_FIRST_N(WARNING, architecture != "GENERIC", 1)
<< "If you're not using a custom processor module, you may want to "
"file a bug";
break;
}
return architecture;
}

int GetArchitectureBitness() { return inf_is_64bit() ? 64 : 32; }

std::string GetModuleName() {
std::string path(QMAXPATH, '\0');
if (get_input_file_path(&path[0], QMAXPATH) == 0) {
Expand Down
3 changes: 1 addition & 2 deletions ida/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ enum Architecture {
kDalvik,
};

int GetArchitectureBitness();
Architecture GetArchitecture();
absl::optional<std::string> GetArchitectureName();

int GetArchitectureBitness();

std::string GetSizePrefix(size_t size_in_bytes);

// Returns the size of an instruction's operand in bytes. Returns 0 for invalid
Expand Down

0 comments on commit d37b404

Please sign in to comment.