Skip to content

Commit 9f5bb02

Browse files
committed
Add GetAddressSize method to Platform
1 parent 331f2ad commit 9f5bb02

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
@@ -15451,6 +15451,7 @@ namespace BinaryNinja {
1545115451
static void InitViewCallback(void* ctxt, BNBinaryView* view);
1545215452
static uint32_t* GetGlobalRegistersCallback(void* ctxt, size_t* count);
1545315453
static void FreeRegisterListCallback(void* ctxt, uint32_t* regs, size_t count);
15454+
static size_t GetAddressSizeCallback(void* ctxt);
1545415455
static BNType* GetGlobalRegisterTypeCallback(void* ctxt, uint32_t reg);
1545515456
static void AdjustTypeParserInputCallback(
1545615457
void* ctxt,
@@ -15635,6 +15636,12 @@ namespace BinaryNinja {
1563515636
*/
1563615637
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg);
1563715638

15639+
/*! Get the address size for this platform
15640+
15641+
\return The address size for this platform
15642+
*/
15643+
virtual size_t GetAddressSize() const;
15644+
1563815645
/*! Modify the input passed to the Type Parser with Platform-specific features.
1563915646

1564015647
\param[in] parser Type Parser instance
@@ -15762,6 +15769,7 @@ namespace BinaryNinja {
1576215769
std::vector<std::string>& arguments,
1576315770
std::vector<std::pair<std::string, std::string>>& sourceFiles
1576415771
) override;
15772+
virtual size_t GetAddressSize() const override;
1576515773
};
1576615774

1576715775
/*!

binaryninjacore.h

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

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

1929+
size_t (*getAddressSize)(void* ctxt);
1930+
19291931
void (*adjustTypeParserInput)(
19301932
void* ctxt,
19311933
BNTypeParser* parser,
@@ -6940,6 +6942,7 @@ extern "C"
69406942

69416943
BINARYNINJACOREAPI uint32_t* BNGetPlatformGlobalRegisters(BNPlatform* platform, size_t* count);
69426944
BINARYNINJACOREAPI BNType* BNGetPlatformGlobalRegisterType(BNPlatform* platform, uint32_t reg);
6945+
BINARYNINJACOREAPI size_t BNGetPlatformAddressSize(BNPlatform* platform);
69436946
BINARYNINJACOREAPI void BNPlatformAdjustTypeParserInput(
69446947
BNPlatform* platform,
69456948
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)