Skip to content

Commit 324b0db

Browse files
committed
Add GetAddressSize method to Platform
1 parent 8360abd commit 324b0db

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

binaryninjaapi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15423,6 +15423,7 @@ namespace BinaryNinja {
1542315423
static void InitViewCallback(void* ctxt, BNBinaryView* view);
1542415424
static uint32_t* GetGlobalRegistersCallback(void* ctxt, size_t* count);
1542515425
static void FreeRegisterListCallback(void* ctxt, uint32_t* regs, size_t count);
15426+
static size_t GetAddressSizeCallback(void* ctxt);
1542615427
static BNType* GetGlobalRegisterTypeCallback(void* ctxt, uint32_t reg);
1542715428
static void AdjustTypeParserInputCallback(
1542815429
void* ctxt,
@@ -15607,6 +15608,12 @@ namespace BinaryNinja {
1560715608
*/
1560815609
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg);
1560915610

15611+
/*! Get the address size for this platform
15612+
15613+
\return The address size for this platform
15614+
*/
15615+
virtual size_t GetAddressSize() const;
15616+
1561015617
/*! Modify the input passed to the Type Parser with Platform-specific features.
1561115618

1561215619
\param[in] parser Type Parser instance
@@ -15734,6 +15741,7 @@ namespace BinaryNinja {
1573415741
std::vector<std::string>& arguments,
1573515742
std::vector<std::pair<std::string, std::string>>& sourceFiles
1573615743
) override;
15744+
virtual size_t GetAddressSize() const override;
1573715745
};
1573815746

1573915747
/*!

binaryninjacore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,8 @@ extern "C"
19251925

19261926
BNType* (*getGlobalRegisterType)(void* ctxt, uint32_t reg);
19271927

1928+
size_t (*getAddressSize)(void* ctxt);
1929+
19281930
void (*adjustTypeParserInput)(
19291931
void* ctxt,
19301932
BNTypeParser* parser,
@@ -6916,6 +6918,7 @@ extern "C"
69166918

69176919
BINARYNINJACOREAPI uint32_t* BNGetPlatformGlobalRegisters(BNPlatform* platform, size_t* count);
69186920
BINARYNINJACOREAPI BNType* BNGetPlatformGlobalRegisterType(BNPlatform* platform, uint32_t reg);
6921+
BINARYNINJACOREAPI size_t BNGetPlatformAddressSize(BNPlatform* platform);
69196922
BINARYNINJACOREAPI void BNPlatformAdjustTypeParserInput(
69206923
BNPlatform* platform,
69216924
BNTypeParser* parser,

platform.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Platform::Platform(Architecture* arch, const string& name)
4141
plat.viewInit = InitViewCallback;
4242
plat.getGlobalRegisters = GetGlobalRegistersCallback;
4343
plat.freeRegisterList = FreeRegisterListCallback;
44+
plat.getAddressSize = GetAddressSizeCallback;
4445
plat.getGlobalRegisterType = GetGlobalRegisterTypeCallback;
4546
plat.adjustTypeParserInput = AdjustTypeParserInputCallback;
4647
plat.freeTypeParserInput = FreeTypeParserInputCallback;
@@ -59,6 +60,7 @@ Platform::Platform(Architecture* arch, const string& name, const string& typeFil
5960
plat.getGlobalRegisters = GetGlobalRegistersCallback;
6061
plat.freeRegisterList = FreeRegisterListCallback;
6162
plat.getGlobalRegisterType = GetGlobalRegisterTypeCallback;
63+
plat.getAddressSize = GetAddressSizeCallback;
6264
plat.adjustTypeParserInput = AdjustTypeParserInputCallback;
6365
plat.freeTypeParserInput = FreeTypeParserInputCallback;
6466
plat.getFallbackEnabled = GetFallbackEnabledCallback;
@@ -193,6 +195,14 @@ BNType* Platform::GetGlobalRegisterTypeCallback(void* ctxt, uint32_t reg)
193195
return BNNewTypeReference(result->GetObject());
194196
}
195197

198+
199+
size_t Platform::GetAddressSizeCallback(void* ctxt)
200+
{
201+
CallbackRef<Platform> plat(ctxt);
202+
return plat->GetAddressSize();
203+
}
204+
205+
196206
bool Platform::GetFallbackEnabledCallback(void* ctxt)
197207
{
198208
CallbackRef<Platform> plat(ctxt);
@@ -424,6 +434,12 @@ bool Platform::GetFallbackEnabled()
424434
}
425435

426436

437+
size_t Platform::GetAddressSize() const
438+
{
439+
return GetArchitecture()->GetAddressSize();
440+
}
441+
442+
427443
std::vector<uint32_t> CorePlatform::GetGlobalRegisters()
428444
{
429445
size_t count;
@@ -448,6 +464,12 @@ Ref<Type> CorePlatform::GetGlobalRegisterType(uint32_t reg)
448464
}
449465

450466

467+
size_t CorePlatform::GetAddressSize() const
468+
{
469+
return BNGetPlatformAddressSize(m_object);
470+
}
471+
472+
451473
void Platform::AdjustTypeParserInput(
452474
Ref<TypeParser> parser,
453475
vector<string>& arguments,

python/platform.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, arch: Optional['architecture.Architecture'] = None, handle=No
8585
self._cb.getGlobalRegisters = self._cb.getGlobalRegisters.__class__(self._get_global_regs)
8686
self._cb.freeRegisterList = self._cb.freeRegisterList.__class__(self._free_register_list)
8787
self._cb.getGlobalRegisterType = self._cb.getGlobalRegisterType.__class__(self._get_global_reg_type)
88+
self._cb.getAddressSize = self._cb.getAddressSize.__class__(lambda ctxt: self._get_address_size)
8889
self._cb.adjustTypeParserInput = self._cb.adjustTypeParserInput.__class__(self._adjust_type_parser_input)
8990
self._cb.freeTypeParserInput = self._cb.freeTypeParserInput.__class__(self._free_type_parser_input)
9091
self._pending_reg_lists = {}
@@ -168,6 +169,13 @@ def _get_global_reg_type(self, ctxt, reg):
168169
log_error(traceback.format_exc())
169170
return None
170171

172+
def _get_address_size(self, ctxt):
173+
try:
174+
return core.BNGetPlatformAddressSize(self.handle)
175+
except:
176+
log_error(traceback.format_exc())
177+
return None
178+
171179
def _adjust_type_parser_input(
172180
self,
173181
ctxt,

0 commit comments

Comments
 (0)