From 7038897105235644749844401411645589822198 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Sat, 11 May 2024 17:15:53 -0400 Subject: Based pointers --- binaryninjaapi.h | 5 +++++ binaryninjacore.h | 13 +++++++++++++ python/types.py | 35 ++++++++++++++++++++++++++++++++--- type.cpp | 31 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index ffc4fd86..477d1b60 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -8594,6 +8594,8 @@ namespace BinaryNinja { uint64_t GetElementCount() const; uint64_t GetOffset() const; + BNPointerBaseType GetPointerBaseType() const; + int64_t GetPointerBaseOffset() const; std::set GetPointerSuffix() const; std::string GetPointerSuffixString() const; @@ -8984,11 +8986,14 @@ namespace BinaryNinja { uint64_t GetElementCount() const; uint64_t GetOffset() const; uint32_t GetSystemCallNumber() const; + BNPointerBaseType GetPointerBaseType() const; + int64_t GetPointerBaseOffset() const; TypeBuilder& SetOffset(uint64_t offset); TypeBuilder& SetFunctionCanReturn(const Confidence& canReturn); TypeBuilder& SetPure(const Confidence& pure); TypeBuilder& SetParameters(const std::vector& params); + TypeBuilder& SetPointerBase(BNPointerBaseType baseType, int64_t baseOffset); std::set GetPointerSuffix() const; std::string GetPointerSuffixString() const; diff --git a/binaryninjacore.h b/binaryninjacore.h index 361f86df..3cc746e1 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -805,6 +805,14 @@ extern "C" LvalueSuffix, } BNPointerSuffix; + typedef enum BNPointerBaseType + { + AbsolutePointerBaseType, + RelativeToConstantPointerBaseType, + RelativeToBinaryStartPointerBaseType, + RelativeToVariableAddressPointerBaseType, + } BNPointerBaseType; + // Caution: these enumeration values are used a lookups into the static NameTypeStrings in the core // if you modify this you must also modify the string lookups as well typedef enum BNNameType @@ -5868,6 +5876,8 @@ extern "C" BINARYNINJACOREAPI BNQualifiedName BNTypeGetStructureName(BNType* type); BINARYNINJACOREAPI BNNamedTypeReference* BNGetRegisteredTypeName(BNType* type); BINARYNINJACOREAPI BNReferenceType BNTypeGetReferenceType(BNType* type); + BINARYNINJACOREAPI BNPointerBaseType BNTypeGetPointerBaseType(BNType* type); + BINARYNINJACOREAPI int64_t BNTypeGetPointerBaseOffset(BNType* type); BINARYNINJACOREAPI char* BNGetTypeAlternateName(BNType* type); BINARYNINJACOREAPI uint32_t BNTypeGetSystemCallNumber(BNType* type); BINARYNINJACOREAPI bool BNTypeIsSystemCall(BNType* type); @@ -5920,6 +5930,7 @@ extern "C" BINARYNINJACOREAPI uint64_t BNGetTypeBuilderElementCount(BNTypeBuilder* type); BINARYNINJACOREAPI uint64_t BNGetTypeBuilderOffset(BNTypeBuilder* type); BINARYNINJACOREAPI void BNSetTypeBuilderOffset(BNTypeBuilder* type, uint64_t offset); + BINARYNINJACOREAPI void BNSetTypeBuilderPointerBase(BNTypeBuilder* type, BNPointerBaseType baseType, int64_t baseOffset); BINARYNINJACOREAPI void BNSetFunctionTypeBuilderCanReturn(BNTypeBuilder* type, BNBoolWithConfidence* canReturn); BINARYNINJACOREAPI void BNSetTypeBuilderPure(BNTypeBuilder* type, BNBoolWithConfidence* pure); BINARYNINJACOREAPI void BNSetFunctionTypeBuilderParameters( @@ -5933,6 +5944,8 @@ extern "C" BINARYNINJACOREAPI BNOffsetWithConfidence BNGetTypeBuilderStackAdjustment(BNTypeBuilder* type); BINARYNINJACOREAPI BNQualifiedName BNTypeBuilderGetStructureName(BNTypeBuilder* type); BINARYNINJACOREAPI BNReferenceType BNTypeBuilderGetReferenceType(BNTypeBuilder* type); + BINARYNINJACOREAPI BNPointerBaseType BNTypeBuilderGetPointerBaseType(BNTypeBuilder* type); + BINARYNINJACOREAPI int64_t BNTypeBuilderGetPointerBaseOffset(BNTypeBuilder* type); BINARYNINJACOREAPI char* BNGetTypeBuilderAlternateName(BNTypeBuilder* type); BINARYNINJACOREAPI bool BNTypeBuilderIsSystemCall(BNTypeBuilder* type); BINARYNINJACOREAPI uint32_t BNTypeBuilderGetSystemCallNumber(BNTypeBuilder* type); diff --git a/python/types.py b/python/types.py index 57918612..d240dce9 100644 --- a/python/types.py +++ b/python/types.py @@ -27,9 +27,11 @@ import uuid # Binary Ninja components from . import _binaryninjacore as core from .enums import ( - StructureVariant, SymbolType, SymbolBinding, TypeClass, NamedTypeReferenceClass, ReferenceType, VariableSourceType, - TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType, TokenEscapingType, - NameType, PointerSuffix + StructureVariant, SymbolType, SymbolBinding, TypeClass, NamedTypeReferenceClass, + ReferenceType, VariableSourceType, + TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType, + TokenEscapingType, + NameType, PointerSuffix, PointerBaseType ) from . import callingconvention from . import function as _function @@ -998,6 +1000,25 @@ class PointerBuilder(TypeBuilder): core.BNFreeInstructionText(tokens, count.value) return result + def set_pointer_base(self, base_type: PointerBaseType, base_offset: int): + core.BNSetTypeBuilderPointerBase(self._handle, base_type, base_offset) + + @property + def pointer_base_type(self) -> PointerBaseType: + return PointerBaseType(core.BNTypeBuilderGetPointerBaseType(self._handle)) + + @pointer_base_type.setter + def pointer_base_type(self, value: PointerBaseType): + self.set_pointer_base(value, self.pointer_base_offset) + + @property + def pointer_base_offset(self) -> int: + return core.BNTypeBuilderGetPointerBaseOffset(self._handle) + + @pointer_base_offset.setter + def pointer_base_offset(self, value: int): + self.set_pointer_base(self.pointer_base_type, value) + class ArrayBuilder(TypeBuilder): @classmethod @@ -2857,6 +2878,14 @@ class PointerType(Type): core.BNFreeInstructionText(tokens, count.value) return result + @property + def pointer_base_type(self) -> PointerBaseType: + return PointerBaseType(core.BNTypeGetPointerBaseType(self._handle)) + + @property + def pointer_base_offset(self) -> int: + return core.BNTypeGetPointerBaseOffset(self._handle) + class ArrayType(Type): @classmethod diff --git a/type.cpp b/type.cpp index 8731e8ae..9ebdc156 100644 --- a/type.cpp +++ b/type.cpp @@ -686,6 +686,18 @@ uint64_t Type::GetOffset() const } +BNPointerBaseType Type::GetPointerBaseType() const +{ + return BNTypeGetPointerBaseType(m_object); +} + + +int64_t Type::GetPointerBaseOffset() const +{ + return BNTypeGetPointerBaseOffset(m_object); +} + + Confidence Type::GetStackAdjustment() const { BNOffsetWithConfidence result = BNGetTypeStackAdjustment(m_object); @@ -1966,6 +1978,13 @@ TypeBuilder& TypeBuilder::SetParameters(const std::vector& pa } +TypeBuilder& TypeBuilder::SetPointerBase(BNPointerBaseType baseType, int64_t baseOffset) +{ + BNSetTypeBuilderPointerBase(m_object, baseType, baseOffset); + return *this; +} + + std::set TypeBuilder::GetPointerSuffix() const { size_t count = 0; @@ -2058,6 +2077,18 @@ uint32_t TypeBuilder::GetSystemCallNumber() const } +BNPointerBaseType TypeBuilder::GetPointerBaseType() const +{ + return BNTypeBuilderGetPointerBaseType(m_object); +} + + +int64_t TypeBuilder::GetPointerBaseOffset() const +{ + return BNTypeBuilderGetPointerBaseOffset(m_object); +} + + QualifiedName TypeBuilder::GetStructureName() const { BNQualifiedName name = BNTypeBuilderGetStructureName(m_object); -- cgit v1.3.1