summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-07-13 19:09:58 -0400
committerMason Reed <mason@vector35.com>2025-07-15 12:34:43 -0400
commit41213e0c959b4b11e3059b60ec5248b31024d236 (patch)
treed47fd4caee967233f2f9ae3b5403aba333de29a6
parentbd1b6b8a1a75df296da5c7afa8107ba301c9cd8e (diff)
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 https://github.com/Vector35/binaryninja-api/issues/7089
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp18
-rw-r--r--lang/c/pseudoc.cpp5
-rw-r--r--lang/rust/pseudorust.cpp5
-rw-r--r--python/binaryview.py20
6 files changed, 48 insertions, 4 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index cb2d3632..85dedca7 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -6425,6 +6425,8 @@ namespace BinaryNinja {
void UndefineType(const std::string& id);
void UndefineUserType(const QualifiedName& name);
void RenameType(const QualifiedName& oldName, const QualifiedName& newName);
+ Ref<Type> GetSystemCallType(Platform* platform, uint32_t id);
+ std::string GetSystemCallName(Platform* platform, uint32_t id);
void RegisterPlatformTypes(Platform* platform);
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 61d7a381..b4c29816 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -5424,6 +5424,8 @@ extern "C"
BINARYNINJACOREAPI void BNUndefineUserAnalysisType(BNBinaryView* view, BNQualifiedName* name);
BINARYNINJACOREAPI void BNRenameAnalysisType(
BNBinaryView* view, BNQualifiedName* oldName, BNQualifiedName* newName);
+ BINARYNINJACOREAPI BNType* BNGetAnalysisSystemCallType(BNBinaryView* view, BNPlatform* platform, uint32_t id);
+ BINARYNINJACOREAPI char* BNGetAnalysisSystemCallName(BNBinaryView* view, BNPlatform* platform, uint32_t id);
BINARYNINJACOREAPI char* BNGenerateAutoTypeId(const char* source, BNQualifiedName* name);
BINARYNINJACOREAPI char* BNGenerateAutoPlatformTypeId(BNPlatform* platform, BNQualifiedName* name);
BINARYNINJACOREAPI char* BNGenerateAutoDemangledTypeId(BNQualifiedName* name);
diff --git a/binaryview.cpp b/binaryview.cpp
index 433767c0..f2e72930 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -4392,6 +4392,24 @@ void BinaryView::RenameType(const QualifiedName& oldName, const QualifiedName& n
}
+Ref<Type> BinaryView::GetSystemCallType(Platform *platform, uint32_t id)
+{
+ BNType* type = BNGetAnalysisSystemCallType(m_object, platform->m_object, id);
+ if (!type)
+ return nullptr;
+ return new Type(type);
+}
+
+
+std::string BinaryView::GetSystemCallName(Platform *platform, uint32_t id)
+{
+ char* name = BNGetAnalysisSystemCallName(m_object, platform->m_object, id);
+ string result = name;
+ BNFreeString(name);
+ return result;
+}
+
+
void BinaryView::RegisterPlatformTypes(Platform* platform)
{
BNRegisterPlatformTypes(m_object, platform->GetObject());
diff --git a/lang/c/pseudoc.cpp b/lang/c/pseudoc.cpp
index 4d585966..74fcedcc 100644
--- a/lang/c/pseudoc.cpp
+++ b/lang/c/pseudoc.cpp
@@ -2705,13 +2705,14 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
if (GetFunction() && (operandList.size() > 0) && (operandList[0].operation == HLIL_CONST))
{
const auto platform = GetFunction()->GetPlatform();
+ const auto view = GetFunction()->GetView();
if (platform)
{
const auto syscall = (uint32_t)operandList[0].GetConstant<HLIL_CONST>();
- const auto syscallName = platform->GetSystemCallName(syscall);
+ const auto syscallName = view->GetSystemCallName(platform, syscall);
if (settings && settings->GetCallParameterHints() != NeverShowParameterHints)
{
- const auto functionType = platform->GetSystemCallType(syscall);
+ const auto functionType = view->GetSystemCallType(platform, syscall);
if (functionType && (functionType->GetClass() == FunctionTypeClass))
namedParams = functionType->GetParameters();
}
diff --git a/lang/rust/pseudorust.cpp b/lang/rust/pseudorust.cpp
index 429def51..0acb10cd 100644
--- a/lang/rust/pseudorust.cpp
+++ b/lang/rust/pseudorust.cpp
@@ -2723,13 +2723,14 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
if (GetFunction() && (operandList.size() > 0) && (operandList[0].operation == HLIL_CONST))
{
const auto platform = GetFunction()->GetPlatform();
+ const auto view = GetFunction()->GetView();
if (platform)
{
const auto syscall = (uint32_t)operandList[0].GetConstant<HLIL_CONST>();
- const auto syscallName = platform->GetSystemCallName(syscall);
+ const auto syscallName = view->GetSystemCallName(platform, syscall);
if (settings && settings->GetCallParameterHints() != NeverShowParameterHints)
{
- const auto functionType = platform->GetSystemCallType(syscall);
+ const auto functionType = view->GetSystemCallType(platform, syscall);
if (functionType && (functionType->GetClass() == FunctionTypeClass))
namedParams = functionType->GetParameters();
}
diff --git a/python/binaryview.py b/python/binaryview.py
index f8eaa088..918fff0e 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -8293,6 +8293,26 @@ class BinaryView:
_new_name = _types.QualifiedName(new_name)._to_core_struct()
core.BNRenameAnalysisType(self.handle, _old_name, _new_name)
+ def get_system_call_type(self, id: int, platform: Optional['_platform.Platform'] = None) -> Optional['_types.Type']:
+ if platform is None:
+ platform = self.platform
+ if platform is None:
+ raise Exception("Unable to retrieve system call type without a platform")
+ handle = core.BNGetAnalysisSystemCallType(self.handle, platform.handle, id)
+ if handle is None:
+ return None
+ return _types.Type.create(handle, platform=platform)
+
+ def get_system_call_name(self, id: int, platform: Optional['_platform.Platform'] = None) -> Optional[str]:
+ if platform is None:
+ platform = self.platform
+ if platform is None:
+ raise Exception("Unable to retrieve system call type without a platform")
+ result = core.BNGetAnalysisSystemCallName(self.handle, platform.handle, id)
+ if result is None:
+ return None
+ return result
+
def import_library_type(self, name: str, lib: Optional[typelibrary.TypeLibrary] = None) -> Optional['_types.Type']:
"""
``import_library_type`` recursively imports a type from the specified type library, or, if