summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2024-05-10 20:01:13 -0400
committerGlenn Smith <glenn@vector35.com>2024-05-23 18:12:07 -0400
commit0824604746724984472975400443871294158813 (patch)
tree7eed161fcfd448af057db0144150310c8edfc37b
parent3375478963786425457931027834955525009658 (diff)
Expose Type::PointerSuffix
-rw-r--r--binaryninjaapi.h11
-rw-r--r--binaryninjacore.h11
-rw-r--r--python/types.py65
-rw-r--r--type.cpp78
4 files changed, 163 insertions, 2 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index d8db649b..ffc4fd86 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -8595,6 +8595,10 @@ namespace BinaryNinja {
uint64_t GetElementCount() const;
uint64_t GetOffset() const;
+ std::set<BNPointerSuffix> GetPointerSuffix() const;
+ std::string GetPointerSuffixString() const;
+ std::vector<InstructionTextToken> GetPointerSuffixTokens(uint8_t baseConfidence = BN_FULL_CONFIDENCE) const;
+
std::string GetString(Platform* platform = nullptr, BNTokenEscapingType escaping = NoTokenEscapingType) const;
std::string GetTypeAndName(const QualifiedName& name, BNTokenEscapingType escaping = NoTokenEscapingType) const;
std::string GetStringBeforeName(Platform* platform = nullptr, BNTokenEscapingType escaping = NoTokenEscapingType) const;
@@ -8986,6 +8990,13 @@ namespace BinaryNinja {
TypeBuilder& SetPure(const Confidence<bool>& pure);
TypeBuilder& SetParameters(const std::vector<FunctionParameter>& params);
+ std::set<BNPointerSuffix> GetPointerSuffix() const;
+ std::string GetPointerSuffixString() const;
+ std::vector<InstructionTextToken> GetPointerSuffixTokens(uint8_t baseConfidence = BN_FULL_CONFIDENCE) const;
+
+ TypeBuilder& AddPointerSuffix(BNPointerSuffix ps);
+ TypeBuilder& SetPointerSuffix(const std::set<BNPointerSuffix>& suffix);
+
std::string GetString(Platform* platform = nullptr) const;
std::string GetTypeAndName(const QualifiedName& name) const;
std::string GetStringBeforeName(Platform* platform = nullptr) const;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index b865fadc..361f86df 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -802,7 +802,7 @@ extern "C"
UnalignedSuffix,
RestrictSuffix,
ReferenceSuffix,
- LvalueSuffix
+ LvalueSuffix,
} BNPointerSuffix;
// Caution: these enumeration values are used a lookups into the static NameTypeStrings in the core
@@ -5871,6 +5871,10 @@ extern "C"
BINARYNINJACOREAPI char* BNGetTypeAlternateName(BNType* type);
BINARYNINJACOREAPI uint32_t BNTypeGetSystemCallNumber(BNType* type);
BINARYNINJACOREAPI bool BNTypeIsSystemCall(BNType* type);
+ BINARYNINJACOREAPI BNPointerSuffix* BNGetTypePointerSuffix(BNType* type, size_t* count);
+ BINARYNINJACOREAPI char* BNGetTypePointerSuffixString(BNType* type);
+ BINARYNINJACOREAPI BNInstructionTextToken* BNGetTypePointerSuffixTokens(BNType* type, uint8_t baseConfidence, size_t* count);
+ BINARYNINJACOREAPI void BNFreePointerSuffixList(BNPointerSuffix* suffix, size_t count);
BINARYNINJACOREAPI char* BNGetTypeString(BNType* type, BNPlatform* platform, BNTokenEscapingType escaping);
BINARYNINJACOREAPI char* BNGetTypeStringBeforeName(BNType* type, BNPlatform* platform, BNTokenEscapingType escaping);
@@ -5933,6 +5937,11 @@ extern "C"
BINARYNINJACOREAPI bool BNTypeBuilderIsSystemCall(BNTypeBuilder* type);
BINARYNINJACOREAPI uint32_t BNTypeBuilderGetSystemCallNumber(BNTypeBuilder* type);
BINARYNINJACOREAPI void BNTypeBuilderSetStackAdjustment(BNTypeBuilder* type, BNOffsetWithConfidence* adjust);
+ BINARYNINJACOREAPI BNPointerSuffix* BNGetTypeBuilderPointerSuffix(BNTypeBuilder* type, size_t* count);
+ BINARYNINJACOREAPI char* BNGetTypeBuilderPointerSuffixString(BNTypeBuilder* type);
+ BINARYNINJACOREAPI BNInstructionTextToken* BNGetTypeBuilderPointerSuffixTokens(BNTypeBuilder* type, uint8_t baseConfidence, size_t* count);
+ BINARYNINJACOREAPI void BNAddTypeBuilderPointerSuffix(BNTypeBuilder* type, BNPointerSuffix ps);
+ BINARYNINJACOREAPI void BNSetTypeBuilderPointerSuffix(BNTypeBuilder* type, BNPointerSuffix* suffix, size_t count);
BINARYNINJACOREAPI char* BNGetTypeBuilderString(BNTypeBuilder* type, BNPlatform* platform);
BINARYNINJACOREAPI char* BNGetTypeBuilderStringBeforeName(BNTypeBuilder* type, BNPlatform* platform);
diff --git a/python/types.py b/python/types.py
index aea8f02c..57918612 100644
--- a/python/types.py
+++ b/python/types.py
@@ -29,7 +29,7 @@ from . import _binaryninjacore as core
from .enums import (
StructureVariant, SymbolType, SymbolBinding, TypeClass, NamedTypeReferenceClass, ReferenceType, VariableSourceType,
TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType, TokenEscapingType,
- NameType
+ NameType, PointerSuffix
)
from . import callingconvention
from . import function as _function
@@ -963,6 +963,41 @@ class PointerBuilder(TypeBuilder):
def origin(self, origin: 'NamedTypeReferenceType'):
core.BNSetTypeBuilderNamedTypeReference(self._handle, origin.ntr_handle)
+ @property
+ def pointer_suffix(self) -> List[PointerSuffix]:
+ count = ctypes.c_size_t(0)
+ suffix = core.BNGetTypeBuilderPointerSuffix(self._handle, count)
+ assert suffix is not None, "core.BNGetTypeBuilderPointerSuffix returned None"
+ try:
+ result = []
+ for i in range(count.value):
+ result.append(PointerSuffix(suffix[i]))
+ return result
+ finally:
+ core.BNFreePointerSuffixList(suffix, count)
+
+ @pointer_suffix.setter
+ def pointer_suffix(self, value: List[PointerSuffix]):
+ suffix = (core.PointerSuffixEnum * len(value))()
+ for i, s in enumerate(value):
+ suffix[i] = core.PointerSuffixEnum(s)
+ core.BNSetTypeBuilderPointerSuffix(self._handle, suffix, len(value))
+
+ def add_pointer_suffix(self, suffix: PointerSuffix):
+ core.BNAddTypeBuilderPointerSuffix(self._handle, suffix)
+
+ @property
+ def pointer_suffix_string(self) -> str:
+ return core.BNGetTypeBuilderPointerSuffixString(self._handle)
+
+ def get_pointer_suffix_tokens(self, base_confidence: int = core.max_confidence) -> List['_function.InstructionTextToken']:
+ count = ctypes.c_ulonglong()
+ tokens = core.BNGetTypeBuilderPointerSuffixTokens(self._handle, base_confidence, count)
+ assert tokens is not None, "core.BNGetTypeBuilderPointerSuffixTokens returned None"
+ result = _function.InstructionTextToken._from_core_struct(tokens, count.value)
+ core.BNFreeInstructionText(tokens, count.value)
+ return result
+
class ArrayBuilder(TypeBuilder):
@classmethod
@@ -2794,6 +2829,34 @@ class PointerType(Type):
def children(self) -> List[Type]:
return [self.target]
+ @property
+ def pointer_suffix(self) -> List[PointerSuffix]:
+ count = ctypes.c_size_t(0)
+ suffix = core.BNGetTypePointerSuffix(self.handle, count)
+ assert suffix is not None, "core.BNGetTypePointerSuffix returned None"
+ try:
+ result = []
+ for i in range(count.value):
+ result.append(suffix[i])
+ return result
+ finally:
+ core.BNFreePointerSuffixList(suffix, count)
+
+ @property
+ def pointer_suffix_string(self) -> str:
+ return core.BNGetTypePointerSuffixString(self.handle)
+
+ def get_pointer_suffix_tokens(self, base_confidence: int = core.max_confidence) -> List['_function.InstructionTextToken']:
+ count = ctypes.c_ulonglong()
+ platform = None
+ if self._platform is not None:
+ platform = self._platform.handle
+ tokens = core.BNGetTypePointerSuffixTokens(self._handle, base_confidence, count)
+ assert tokens is not None, "core.BNGetTypePointerSuffixTokens returned None"
+ result = _function.InstructionTextToken._from_core_struct(tokens, count.value)
+ core.BNFreeInstructionText(tokens, count.value)
+ return result
+
class ArrayType(Type):
@classmethod
diff --git a/type.cpp b/type.cpp
index 3cfa26f9..8731e8ae 100644
--- a/type.cpp
+++ b/type.cpp
@@ -693,6 +693,36 @@ Confidence<int64_t> Type::GetStackAdjustment() const
}
+std::set<BNPointerSuffix> Type::GetPointerSuffix() const
+{
+ size_t count = 0;
+ BNPointerSuffix* suffix = BNGetTypePointerSuffix(m_object, &count);
+ std::set<BNPointerSuffix> result(suffix, suffix + count);
+ BNFreePointerSuffixList(suffix, count);
+ return result;
+
+}
+
+
+std::string Type::GetPointerSuffixString() const
+{
+ char* string = BNGetTypePointerSuffixString(m_object);
+ std::string result(string);
+ BNFreeString(string);
+ return result;
+}
+
+
+std::vector<InstructionTextToken> Type::GetPointerSuffixTokens(uint8_t baseConfidence) const
+{
+ size_t count = 0;
+ BNInstructionTextToken* tokens = BNGetTypePointerSuffixTokens(m_object, baseConfidence, &count);
+ std::vector<InstructionTextToken> result = InstructionTextToken::ConvertInstructionTextTokenList(tokens, count);
+ BNFreeInstructionText(tokens, count);
+ return result;
+}
+
+
string Type::GetString(Platform* platform, BNTokenEscapingType escaping) const
{
char* str = BNGetTypeString(m_object, platform ? platform->GetObject() : nullptr, escaping);
@@ -1936,6 +1966,54 @@ TypeBuilder& TypeBuilder::SetParameters(const std::vector<FunctionParameter>& pa
}
+std::set<BNPointerSuffix> TypeBuilder::GetPointerSuffix() const
+{
+ size_t count = 0;
+ BNPointerSuffix* suffix = BNGetTypeBuilderPointerSuffix(m_object, &count);
+ std::set<BNPointerSuffix> result(suffix, suffix + count);
+ BNFreePointerSuffixList(suffix, count);
+ return result;
+}
+
+
+std::string TypeBuilder::GetPointerSuffixString() const
+{
+ char* string = BNGetTypeBuilderPointerSuffixString(m_object);
+ std::string result(string);
+ BNFreeString(string);
+ return result;
+}
+
+
+std::vector<InstructionTextToken> TypeBuilder::GetPointerSuffixTokens(uint8_t baseConfidence) const
+{
+ size_t count = 0;
+ BNInstructionTextToken* tokens = BNGetTypeBuilderPointerSuffixTokens(m_object, baseConfidence, &count);
+ std::vector<InstructionTextToken> result = InstructionTextToken::ConvertInstructionTextTokenList(tokens, count);
+ BNFreeInstructionText(tokens, count);
+ return result;
+}
+
+
+TypeBuilder& TypeBuilder::AddPointerSuffix(BNPointerSuffix ps)
+{
+ BNAddTypeBuilderPointerSuffix(m_object, ps);
+ return *this;
+}
+
+
+TypeBuilder& TypeBuilder::SetPointerSuffix(const std::set<BNPointerSuffix>& suffix)
+{
+ std::vector<BNPointerSuffix> apiSuffix;
+ for (auto& s: suffix)
+ {
+ apiSuffix.push_back(s);
+ }
+ BNSetTypeBuilderPointerSuffix(m_object, apiSuffix.data(), apiSuffix.size());
+ return *this;
+}
+
+
QualifiedName TypeBuilder::GetTypeName() const
{
BNQualifiedName name = BNTypeBuilderGetTypeName(m_object);