summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h8
-rw-r--r--binaryninjacore.h10
-rw-r--r--function.cpp27
-rw-r--r--python/function.py41
4 files changed, 65 insertions, 21 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index bf3cc5ad..39a0be59 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -10447,13 +10447,11 @@ namespace BinaryNinja {
BNIntegerDisplayType GetIntegerConstantDisplayType(
Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand);
- void SetIntegerConstantDisplayType(
- Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, BNIntegerDisplayType type);
-
Ref<Type> GetIntegerConstantDisplayTypeEnumType(
Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand);
- void SetIntegerConstantDisplayTypeEnumType(
- Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, Ref<Type> type);
+ void SetIntegerConstantDisplayType(
+ Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, BNIntegerDisplayType type, Ref<Type> enumType = nullptr);
+ std::pair<BNIntegerDisplayType, Ref<Type>> GetIntegerConstantDisplayTypeAndEnumType(Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand);
BNHighlightColor GetInstructionHighlight(Architecture* arch, uint64_t addr);
void SetAutoInstructionHighlight(Architecture* arch, uint64_t addr, BNHighlightColor color);
diff --git a/binaryninjacore.h b/binaryninjacore.h
index a3210c52..9472339e 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -37,14 +37,14 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
-#define BN_CURRENT_CORE_ABI_VERSION 50
+#define BN_CURRENT_CORE_ABI_VERSION 51
// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
-#define BN_MINIMUM_CORE_ABI_VERSION 50
+#define BN_MINIMUM_CORE_ABI_VERSION 51
#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
@@ -4474,11 +4474,9 @@ extern "C"
BINARYNINJACOREAPI BNIntegerDisplayType BNGetIntegerConstantDisplayType(
BNFunction* func, BNArchitecture* arch, uint64_t instrAddr, uint64_t value, size_t operand);
BINARYNINJACOREAPI void BNSetIntegerConstantDisplayType(BNFunction* func, BNArchitecture* arch, uint64_t instrAddr,
- uint64_t value, size_t operand, BNIntegerDisplayType type);
- BINARYNINJACOREAPI BNType* BNGetIntegerConstantDisplayTypeEnumerationType(
+ uint64_t value, size_t operand, BNIntegerDisplayType type, const char* typeID);
+ BINARYNINJACOREAPI char* BNGetIntegerConstantDisplayTypeEnumerationType(
BNFunction* func, BNArchitecture* arch, uint64_t instrAddr, uint64_t value, size_t operand);
- BINARYNINJACOREAPI void BNSetIntegerConstantDisplayTypeEnumerationType(
- BNFunction* func, BNArchitecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, BNType* type);
BINARYNINJACOREAPI bool BNIsFunctionTooLarge(BNFunction* func);
BINARYNINJACOREAPI bool BNIsFunctionAnalysisSkipped(BNFunction* func);
diff --git a/function.cpp b/function.cpp
index 601df3aa..27a91952 100644
--- a/function.cpp
+++ b/function.cpp
@@ -1865,26 +1865,37 @@ BNIntegerDisplayType Function::GetIntegerConstantDisplayType(
void Function::SetIntegerConstantDisplayType(
- Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, BNIntegerDisplayType type)
+ Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, BNIntegerDisplayType type, Ref<Type> enumType)
{
- BNSetIntegerConstantDisplayType(m_object, arch->GetObject(), instrAddr, value, operand, type);
+ if (enumType)
+ BNSetIntegerConstantDisplayType(m_object, arch->GetObject(), instrAddr, value, operand, type, enumType->GetRegisteredName()->GetTypeId().c_str());
+ else
+ BNSetIntegerConstantDisplayType(m_object, arch->GetObject(), instrAddr, value, operand, type, nullptr);
}
Ref<Type> Function::GetIntegerConstantDisplayTypeEnumType(
Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand)
{
- BNType* apiType = BNGetIntegerConstantDisplayTypeEnumerationType(m_object, arch->GetObject(), instrAddr, value, operand);
+ char* apiType = BNGetIntegerConstantDisplayTypeEnumerationType(m_object, arch->GetObject(), instrAddr, value, operand);
+ std::string apiTypeStr = std::string(apiType);
if (apiType)
- return new Type(apiType);
- return nullptr;
+ BNFreeString(apiType);
+ Ref<Type> type = GetView()->GetTypeById(apiTypeStr);
+ return type;
}
-void Function::SetIntegerConstantDisplayTypeEnumType(
- Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, Ref<Type> type)
+std::pair<BNIntegerDisplayType, Ref<Type>> Function::GetIntegerConstantDisplayTypeAndEnumType(Architecture* arch,
+ uint64_t instrAddr, uint64_t value, size_t operand)
{
- BNSetIntegerConstantDisplayTypeEnumerationType(m_object, arch->GetObject(), instrAddr, value, operand, type->m_object);
+ auto displayType = BNGetIntegerConstantDisplayType(m_object, arch->GetObject(), instrAddr, value, operand);
+ char* apiType = BNGetIntegerConstantDisplayTypeEnumerationType(m_object, arch->GetObject(), instrAddr, value, operand);
+ std::string apiTypeStr = std::string(apiType);
+ if (apiType)
+ BNFreeString(apiType);
+ Ref<Type> type = GetView()->GetTypeById(apiTypeStr);
+ return {displayType, type};
}
diff --git a/python/function.py b/python/function.py
index e311d890..a3d53feb 100644
--- a/python/function.py
+++ b/python/function.py
@@ -2702,6 +2702,8 @@ class Function:
"""
Get the current text display type for an integer token in the disassembly or IL views
+ See also see :py:func:`get_int_display_type_and_typeid`
+
:param int instr_addr: Address of the instruction or IL line containing the token
:param int value: ``value`` field of the InstructionTextToken object for the token, usually the constant displayed
:param int operand: Operand index of the token, defined as the number of OperandSeparatorTokens in the disassembly line before the token
@@ -2713,9 +2715,27 @@ class Function:
core.BNGetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand)
)
+ def get_int_enum_display_typeid(self, instr_addr: int, value: int, operand: int,
+ arch: Optional['architecture.Architecture'] = None) -> str:
+ """
+ Get the current text display enum type for an integer token in the disassembly or IL views.
+
+ See also see :py:func:`get_int_display_type_and_typeid`
+
+ :param int instr_addr: Address of the instruction or IL line containing the token
+ :param int value: ``value`` field of the InstructionTextToken object for the token, usually the constant displayed
+ :param int operand: Operand index of the token, defined as the number of OperandSeparatorTokens in the disassembly line before the token
+ :param Architecture arch: (optional) Architecture of the instruction or IL line containing the token
+ :return: TypeID for the integer token
+ """
+ if arch is None:
+ arch = self.arch
+ type_id = core.BNGetIntegerConstantDisplayTypeEnumerationType(self.handle, arch.handle, instr_addr, value, operand)
+ return type_id
+
def set_int_display_type(
self, instr_addr: int, value: int, operand: int, display_type: IntegerDisplayType,
- arch: Optional['architecture.Architecture'] = None
+ arch: Optional['architecture.Architecture'] = None, enum_display_typeid = None
) -> None:
"""
Change the text display type for an integer token in the disassembly or IL views
@@ -2725,12 +2745,29 @@ class Function:
:param int operand: Operand index of the token, defined as the number of OperandSeparatorTokens in the disassembly line before the token
:param enums.IntegerDisplayType display_type: Desired display type
:param Architecture arch: (optional) Architecture of the instruction or IL line containing the token
+ :param str enum_display_typeid: (optional) Whenever passing EnumDisplayType to ``display_type``, passing a type ID here will specify the Enumeration display type. Must be a valid type ID and resolve to an enumeration type.
"""
if arch is None:
arch = self.arch
if isinstance(display_type, str):
display_type = IntegerDisplayType[display_type]
- core.BNSetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand, display_type)
+ core.BNSetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand, display_type, enum_display_typeid)
+
+ def get_int_display_type_and_typeid(self, instr_addr: int, value: int, operand: int,
+ arch: Optional['architecture.Architecture'] = None) -> (IntegerDisplayType, str):
+ """
+ Get the current text display type for an integer token in the disassembly or IL views
+
+ :param int instr_addr: Address of the instruction or IL line containing the token
+ :param int value: ``value`` field of the InstructionTextToken object for the token, usually the constant displayed
+ :param int operand: Operand index of the token, defined as the number of OperandSeparatorTokens in the disassembly line before the token
+ :param Architecture arch: (optional) Architecture of the instruction or IL line containing the token
+ """
+ if arch is None:
+ arch = self.arch
+ display_type = core.BNGetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand)
+ type_id = core.BNGetIntegerConstantDisplayTypeEnumerationType(self.handle, arch.handle, instr_addr, value, operand)
+ return display_type, type_id
def reanalyze(self, update_type: FunctionUpdateType = FunctionUpdateType.UserFunctionUpdate) -> None:
"""