From fc5b443d86d10c5ce308630f8b41c8f64f5f40f1 Mon Sep 17 00:00:00 2001 From: Zichuan Li <34680029+river-li@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:20:56 -0400 Subject: Implement callback function for fallback type library --- binaryninjaapi.h | 8 ++++++++ binaryninjacore.h | 2 ++ platform.cpp | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 96bb4b8c..c37a1a3d 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -14556,6 +14556,7 @@ namespace BinaryNinja { char** sourceFileValues, size_t sourceFilesLen ); + static bool GetFallbackEnabledCallback(void* ctxt); public: Platform(BNPlatform* platform); @@ -14728,6 +14729,13 @@ namespace BinaryNinja { std::vector>& sourceFiles ); + /*! Provide an option for platforms to decide whether to use + * the fallback type library. + * + * Allows the Platform to override it to false. + */ + virtual bool GetFallbackEnabled(); + Ref GetRelatedPlatform(Architecture* arch); void AddRelatedPlatform(Architecture* arch, Platform* platform); Ref GetAssociatedPlatformByAddress(uint64_t& addr); diff --git a/binaryninjacore.h b/binaryninjacore.h index 96ea6f5e..9d217902 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1906,6 +1906,8 @@ extern "C" char** sourceFileValues, size_t sourceFilesLen ); + + bool (*getFallbackEnabled)(void* ctxt); } BNCustomPlatform; typedef struct BNBasicBlockEdge diff --git a/platform.cpp b/platform.cpp index ec27b710..55044595 100644 --- a/platform.cpp +++ b/platform.cpp @@ -44,6 +44,7 @@ Platform::Platform(Architecture* arch, const string& name) plat.getGlobalRegisterType = GetGlobalRegisterTypeCallback; plat.adjustTypeParserInput = AdjustTypeParserInputCallback; plat.freeTypeParserInput = FreeTypeParserInputCallback; + plat.getFallbackEnabled = GetFallbackEnabledCallback; m_object = BNCreateCustomPlatform(arch->GetObject(), name.c_str(), &plat); AddRefForRegistration(); } @@ -60,6 +61,7 @@ Platform::Platform(Architecture* arch, const string& name, const string& typeFil plat.getGlobalRegisterType = GetGlobalRegisterTypeCallback; plat.adjustTypeParserInput = AdjustTypeParserInputCallback; plat.freeTypeParserInput = FreeTypeParserInputCallback; + plat.getFallbackEnabled = GetFallbackEnabledCallback; const char** includeDirList = new const char*[includeDirs.size()]; for (size_t i = 0; i < includeDirs.size(); i++) includeDirList[i] = includeDirs[i].c_str(); @@ -191,6 +193,12 @@ BNType* Platform::GetGlobalRegisterTypeCallback(void* ctxt, uint32_t reg) return BNNewTypeReference(result->GetObject()); } +bool Platform::GetFallbackEnabledCallback(void* ctxt) +{ + CallbackRef plat(ctxt); + return plat->GetFallbackEnabled(); +} + Ref Platform::GetArchitecture() const { @@ -410,6 +418,12 @@ Ref Platform::GetGlobalRegisterType(uint32_t reg) } +bool Platform::GetFallbackEnabled() +{ + return true; +} + + std::vector CorePlatform::GetGlobalRegisters() { size_t count; -- cgit v1.3.1