Skip to content

Commit fc5b443

Browse files
committed
Implement callback function for fallback type library
1 parent 7518e76 commit fc5b443

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

binaryninjaapi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14556,6 +14556,7 @@ namespace BinaryNinja {
1455614556
char** sourceFileValues,
1455714557
size_t sourceFilesLen
1455814558
);
14559+
static bool GetFallbackEnabledCallback(void* ctxt);
1455914560

1456014561
public:
1456114562
Platform(BNPlatform* platform);
@@ -14728,6 +14729,13 @@ namespace BinaryNinja {
1472814729
std::vector<std::pair<std::string, std::string>>& sourceFiles
1472914730
);
1473014731

14732+
/*! Provide an option for platforms to decide whether to use
14733+
* the fallback type library.
14734+
*
14735+
* Allows the Platform to override it to false.
14736+
*/
14737+
virtual bool GetFallbackEnabled();
14738+
1473114739
Ref<Platform> GetRelatedPlatform(Architecture* arch);
1473214740
void AddRelatedPlatform(Architecture* arch, Platform* platform);
1473314741
Ref<Platform> GetAssociatedPlatformByAddress(uint64_t& addr);

binaryninjacore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,8 @@ extern "C"
19061906
char** sourceFileValues,
19071907
size_t sourceFilesLen
19081908
);
1909+
1910+
bool (*getFallbackEnabled)(void* ctxt);
19091911
} BNCustomPlatform;
19101912

19111913
typedef struct BNBasicBlockEdge

platform.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Platform::Platform(Architecture* arch, const string& name)
4444
plat.getGlobalRegisterType = GetGlobalRegisterTypeCallback;
4545
plat.adjustTypeParserInput = AdjustTypeParserInputCallback;
4646
plat.freeTypeParserInput = FreeTypeParserInputCallback;
47+
plat.getFallbackEnabled = GetFallbackEnabledCallback;
4748
m_object = BNCreateCustomPlatform(arch->GetObject(), name.c_str(), &plat);
4849
AddRefForRegistration();
4950
}
@@ -60,6 +61,7 @@ Platform::Platform(Architecture* arch, const string& name, const string& typeFil
6061
plat.getGlobalRegisterType = GetGlobalRegisterTypeCallback;
6162
plat.adjustTypeParserInput = AdjustTypeParserInputCallback;
6263
plat.freeTypeParserInput = FreeTypeParserInputCallback;
64+
plat.getFallbackEnabled = GetFallbackEnabledCallback;
6365
const char** includeDirList = new const char*[includeDirs.size()];
6466
for (size_t i = 0; i < includeDirs.size(); i++)
6567
includeDirList[i] = includeDirs[i].c_str();
@@ -191,6 +193,12 @@ BNType* Platform::GetGlobalRegisterTypeCallback(void* ctxt, uint32_t reg)
191193
return BNNewTypeReference(result->GetObject());
192194
}
193195

196+
bool Platform::GetFallbackEnabledCallback(void* ctxt)
197+
{
198+
CallbackRef<Platform> plat(ctxt);
199+
return plat->GetFallbackEnabled();
200+
}
201+
194202

195203
Ref<Architecture> Platform::GetArchitecture() const
196204
{
@@ -410,6 +418,12 @@ Ref<Type> Platform::GetGlobalRegisterType(uint32_t reg)
410418
}
411419

412420

421+
bool Platform::GetFallbackEnabled()
422+
{
423+
return true;
424+
}
425+
426+
413427
std::vector<uint32_t> CorePlatform::GetGlobalRegisters()
414428
{
415429
size_t count;

0 commit comments

Comments
 (0)