Skip to content

Commit 41213e0

Browse files
committed
Expose analysis' system call type and name retrieval
Previously we only really had a way to access the platform system call information, this was missing the system call information found in type libraries Fixes #7089
1 parent bd1b6b8 commit 41213e0

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

binaryninjaapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6425,6 +6425,8 @@ namespace BinaryNinja {
64256425
void UndefineType(const std::string& id);
64266426
void UndefineUserType(const QualifiedName& name);
64276427
void RenameType(const QualifiedName& oldName, const QualifiedName& newName);
6428+
Ref<Type> GetSystemCallType(Platform* platform, uint32_t id);
6429+
std::string GetSystemCallName(Platform* platform, uint32_t id);
64286430

64296431
void RegisterPlatformTypes(Platform* platform);
64306432

binaryninjacore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5424,6 +5424,8 @@ extern "C"
54245424
BINARYNINJACOREAPI void BNUndefineUserAnalysisType(BNBinaryView* view, BNQualifiedName* name);
54255425
BINARYNINJACOREAPI void BNRenameAnalysisType(
54265426
BNBinaryView* view, BNQualifiedName* oldName, BNQualifiedName* newName);
5427+
BINARYNINJACOREAPI BNType* BNGetAnalysisSystemCallType(BNBinaryView* view, BNPlatform* platform, uint32_t id);
5428+
BINARYNINJACOREAPI char* BNGetAnalysisSystemCallName(BNBinaryView* view, BNPlatform* platform, uint32_t id);
54275429
BINARYNINJACOREAPI char* BNGenerateAutoTypeId(const char* source, BNQualifiedName* name);
54285430
BINARYNINJACOREAPI char* BNGenerateAutoPlatformTypeId(BNPlatform* platform, BNQualifiedName* name);
54295431
BINARYNINJACOREAPI char* BNGenerateAutoDemangledTypeId(BNQualifiedName* name);

binaryview.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,6 +4392,24 @@ void BinaryView::RenameType(const QualifiedName& oldName, const QualifiedName& n
43924392
}
43934393

43944394

4395+
Ref<Type> BinaryView::GetSystemCallType(Platform *platform, uint32_t id)
4396+
{
4397+
BNType* type = BNGetAnalysisSystemCallType(m_object, platform->m_object, id);
4398+
if (!type)
4399+
return nullptr;
4400+
return new Type(type);
4401+
}
4402+
4403+
4404+
std::string BinaryView::GetSystemCallName(Platform *platform, uint32_t id)
4405+
{
4406+
char* name = BNGetAnalysisSystemCallName(m_object, platform->m_object, id);
4407+
string result = name;
4408+
BNFreeString(name);
4409+
return result;
4410+
}
4411+
4412+
43954413
void BinaryView::RegisterPlatformTypes(Platform* platform)
43964414
{
43974415
BNRegisterPlatformTypes(m_object, platform->GetObject());

lang/c/pseudoc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,13 +2705,14 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
27052705
if (GetFunction() && (operandList.size() > 0) && (operandList[0].operation == HLIL_CONST))
27062706
{
27072707
const auto platform = GetFunction()->GetPlatform();
2708+
const auto view = GetFunction()->GetView();
27082709
if (platform)
27092710
{
27102711
const auto syscall = (uint32_t)operandList[0].GetConstant<HLIL_CONST>();
2711-
const auto syscallName = platform->GetSystemCallName(syscall);
2712+
const auto syscallName = view->GetSystemCallName(platform, syscall);
27122713
if (settings && settings->GetCallParameterHints() != NeverShowParameterHints)
27132714
{
2714-
const auto functionType = platform->GetSystemCallType(syscall);
2715+
const auto functionType = view->GetSystemCallType(platform, syscall);
27152716
if (functionType && (functionType->GetClass() == FunctionTypeClass))
27162717
namedParams = functionType->GetParameters();
27172718
}

lang/rust/pseudorust.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,13 +2723,14 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
27232723
if (GetFunction() && (operandList.size() > 0) && (operandList[0].operation == HLIL_CONST))
27242724
{
27252725
const auto platform = GetFunction()->GetPlatform();
2726+
const auto view = GetFunction()->GetView();
27262727
if (platform)
27272728
{
27282729
const auto syscall = (uint32_t)operandList[0].GetConstant<HLIL_CONST>();
2729-
const auto syscallName = platform->GetSystemCallName(syscall);
2730+
const auto syscallName = view->GetSystemCallName(platform, syscall);
27302731
if (settings && settings->GetCallParameterHints() != NeverShowParameterHints)
27312732
{
2732-
const auto functionType = platform->GetSystemCallType(syscall);
2733+
const auto functionType = view->GetSystemCallType(platform, syscall);
27332734
if (functionType && (functionType->GetClass() == FunctionTypeClass))
27342735
namedParams = functionType->GetParameters();
27352736
}

python/binaryview.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8293,6 +8293,26 @@ def rename_type(self, old_name: '_types.QualifiedNameType', new_name: '_types.Qu
82938293
_new_name = _types.QualifiedName(new_name)._to_core_struct()
82948294
core.BNRenameAnalysisType(self.handle, _old_name, _new_name)
82958295

8296+
def get_system_call_type(self, id: int, platform: Optional['_platform.Platform'] = None) -> Optional['_types.Type']:
8297+
if platform is None:
8298+
platform = self.platform
8299+
if platform is None:
8300+
raise Exception("Unable to retrieve system call type without a platform")
8301+
handle = core.BNGetAnalysisSystemCallType(self.handle, platform.handle, id)
8302+
if handle is None:
8303+
return None
8304+
return _types.Type.create(handle, platform=platform)
8305+
8306+
def get_system_call_name(self, id: int, platform: Optional['_platform.Platform'] = None) -> Optional[str]:
8307+
if platform is None:
8308+
platform = self.platform
8309+
if platform is None:
8310+
raise Exception("Unable to retrieve system call type without a platform")
8311+
result = core.BNGetAnalysisSystemCallName(self.handle, platform.handle, id)
8312+
if result is None:
8313+
return None
8314+
return result
8315+
82968316
def import_library_type(self, name: str, lib: Optional[typelibrary.TypeLibrary] = None) -> Optional['_types.Type']:
82978317
"""
82988318
``import_library_type`` recursively imports a type from the specified type library, or, if

0 commit comments

Comments
 (0)