Skip to content

Commit eddefff

Browse files
committed
Add new calling convention callbacks to Python API
1 parent d4a5ad8 commit eddefff

8 files changed

Lines changed: 753 additions & 141 deletions

File tree

binaryninjaapi.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17903,17 +17903,19 @@ namespace BinaryNinja {
1790317903
void* ctxt, const BNVariable* var, BNFunction* func, BNVariable* result);
1790417904

1790517905
static bool IsReturnTypeRegisterCompatibleCallback(void* ctxt, BNType* type);
17906-
static BNVariable GetIndirectReturnValueLocationCallback(void* ctxt);
17906+
static void GetIndirectReturnValueLocationCallback(void* ctxt, BNVariable* outVar);
1790717907
static bool GetReturnedIndirectReturnValuePointerCallback(void* ctxt, BNVariable* outVar);
1790817908

1790917909
static bool IsArgumentTypeRegisterCompatibleCallback(void* ctxt, BNType* type);
1791017910
static bool AreNonRegisterArgumentsIndirectCallback(void* ctxt);
1791117911
static bool AreStackArgumentsNaturallyAlignedCallback(void* ctxt);
1791217912

17913-
static BNCallLayout GetCallLayoutCallback(void* ctxt, BNReturnValue* returnValue, BNFunctionParameter* params,
17914-
size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs, size_t permittedRegCount);
17913+
static void GetCallLayoutCallback(void* ctxt, BNReturnValue* returnValue, BNFunctionParameter* params,
17914+
size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs, size_t permittedRegCount,
17915+
BNCallLayout* result);
1791517916
static void FreeCallLayoutCallback(void* ctxt, BNCallLayout* layout);
17916-
static BNValueLocation GetReturnValueLocationCallback(void* ctxt, BNReturnValue* returnValue);
17917+
static void GetReturnValueLocationCallback(
17918+
void* ctxt, BNReturnValue* returnValue, BNValueLocation* outLocation);
1791717919
static void FreeValueLocationCallback(void* ctxt, BNValueLocation* location);
1791817920
static BNValueLocation* GetParameterLocationsCallback(void* ctxt, BNValueLocation* returnValue,
1791917921
BNFunctionParameter* params, size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs,

binaryninjacore.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ extern "C"
29182918
void (*getIncomingFlagValue)(void* ctxt, uint32_t flag, BNFunction* func, BNRegisterValue* result);
29192919

29202920
bool (*isReturnTypeRegisterCompatible)(void* ctxt, BNType* type);
2921-
BNVariable (*getIndirectReturnValueLocation)(void* ctxt);
2921+
void (*getIndirectReturnValueLocation)(void* ctxt, BNVariable* outVar);
29222922
bool (*getReturnedIndirectReturnValuePointer)(void* ctxt, BNVariable* outVar);
29232923

29242924
bool (*isArgumentTypeRegisterCompatible)(void* ctxt, BNType* type);
@@ -2932,10 +2932,11 @@ extern "C"
29322932

29332933
bool (*areArgumentRegistersUsedForVarArgs)(void* ctxt);
29342934

2935-
BNCallLayout (*getCallLayout)(void* ctxt, BNReturnValue* returnValue, BNFunctionParameter* params,
2936-
size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs, size_t permittedRegCount);
2935+
void (*getCallLayout)(void* ctxt, BNReturnValue* returnValue, BNFunctionParameter* params,
2936+
size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs, size_t permittedRegCount,
2937+
BNCallLayout* result);
29372938
void (*freeCallLayout)(void* ctxt, BNCallLayout* layout);
2938-
BNValueLocation (*getReturnValueLocation)(void* ctxt, BNReturnValue* returnValue);
2939+
void (*getReturnValueLocation)(void* ctxt, BNReturnValue* returnValue, BNValueLocation* outLocation);
29392940
void (*freeValueLocation)(void* ctxt, BNValueLocation* location);
29402941
BNValueLocation* (*getParameterLocations)(void* ctxt, BNValueLocation* returnValue, BNFunctionParameter* params,
29412942
size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs, size_t permittedRegCount,

callingconvention.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ bool CallingConvention::IsReturnTypeRegisterCompatibleCallback(void* ctxt, BNTyp
353353
}
354354

355355

356-
BNVariable CallingConvention::GetIndirectReturnValueLocationCallback(void* ctxt)
356+
void CallingConvention::GetIndirectReturnValueLocationCallback(void* ctxt, BNVariable* outVar)
357357
{
358358
CallbackRef<CallingConvention> cc(ctxt);
359-
return cc->GetIndirectReturnValueLocation();
359+
*outVar = cc->GetIndirectReturnValueLocation();
360360
}
361361

362362

@@ -394,9 +394,9 @@ bool CallingConvention::AreStackArgumentsNaturallyAlignedCallback(void* ctxt)
394394
}
395395

396396

397-
BNCallLayout CallingConvention::GetCallLayoutCallback(void* ctxt, BNReturnValue* returnValue,
397+
void CallingConvention::GetCallLayoutCallback(void* ctxt, BNReturnValue* returnValue,
398398
BNFunctionParameter* params, size_t paramCount, bool hasPermittedRegs, uint32_t* permittedRegs,
399-
size_t permittedRegCount)
399+
size_t permittedRegCount, BNCallLayout* result)
400400
{
401401
CallbackRef<CallingConvention> cc(ctxt);
402402
auto ret = ReturnValue::FromAPIObject(returnValue);
@@ -414,7 +414,7 @@ BNCallLayout CallingConvention::GetCallLayoutCallback(void* ctxt, BNReturnValue*
414414
}
415415

416416
auto layout = cc->GetCallLayout(ret, paramObjs, regOpt);
417-
return layout.ToAPIObject();
417+
*result = layout.ToAPIObject();
418418
}
419419

420420

@@ -424,12 +424,13 @@ void CallingConvention::FreeCallLayoutCallback(void*, BNCallLayout* layout)
424424
}
425425

426426

427-
BNValueLocation CallingConvention::GetReturnValueLocationCallback(void* ctxt, BNReturnValue* returnValue)
427+
void CallingConvention::GetReturnValueLocationCallback(
428+
void* ctxt, BNReturnValue* returnValue, BNValueLocation* outLocation)
428429
{
429430
CallbackRef<CallingConvention> cc(ctxt);
430431
ReturnValue ret = ReturnValue::FromAPIObject(returnValue);
431432
ValueLocation location = cc->GetReturnValueLocation(ret);
432-
return location.ToAPIObject();
433+
*outLocation = location.ToAPIObject();
433434
}
434435

435436

python/architecture.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ def calling_conventions(self) -> Mapping[str, 'callingconvention.CallingConventi
10511051
result = {}
10521052
try:
10531053
for i in range(0, count.value):
1054-
obj = callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i]))
1054+
obj = callingconvention.CoreCallingConvention(handle=core.BNNewCallingConventionReference(cc[i]))
10551055
result[obj.name] = obj
10561056
finally:
10571057
core.BNFreeCallingConventionList(cc, count.value)
@@ -2613,7 +2613,7 @@ def default_calling_convention(self):
26132613
cc_handle = core.BNGetArchitectureDefaultCallingConvention(self.handle)
26142614
if cc_handle is None:
26152615
return None
2616-
return callingconvention.CallingConvention(handle=cc_handle)
2616+
return callingconvention.CoreCallingConvention(handle=cc_handle)
26172617

26182618
@default_calling_convention.setter
26192619
def default_calling_convention(self, cc: 'callingconvention.CallingConvention'):
@@ -2633,7 +2633,7 @@ def cdecl_calling_convention(self):
26332633
cc_handle = core.BNGetArchitectureCdeclCallingConvention(self.handle)
26342634
if cc_handle is None:
26352635
return None
2636-
return callingconvention.CallingConvention(handle=cc_handle)
2636+
return callingconvention.CoreCallingConvention(handle=cc_handle)
26372637

26382638
@cdecl_calling_convention.setter
26392639
def cdecl_calling_convention(self, cc: 'callingconvention.CallingConvention'):
@@ -2653,7 +2653,7 @@ def stdcall_calling_convention(self):
26532653
cc_handle = core.BNGetArchitectureStdcallCallingConvention(self.handle)
26542654
if cc_handle is None:
26552655
return None
2656-
return callingconvention.CallingConvention(handle=cc_handle)
2656+
return callingconvention.CoreCallingConvention(handle=cc_handle)
26572657

26582658
@stdcall_calling_convention.setter
26592659
def stdcall_calling_convention(self, cc: 'callingconvention.CallingConvention'):
@@ -2673,7 +2673,7 @@ def fastcall_calling_convention(self):
26732673
cc_handle = core.BNGetArchitectureFastcallCallingConvention(self.handle)
26742674
if cc_handle is None:
26752675
return None
2676-
return callingconvention.CallingConvention(handle=cc_handle)
2676+
return callingconvention.CoreCallingConvention(handle=cc_handle)
26772677

26782678
@fastcall_calling_convention.setter
26792679
def fastcall_calling_convention(self, cc: 'callingconvention.CallingConvention'):

0 commit comments

Comments
 (0)