Skip to content

Commit 7038897

Browse files
committed
Based pointers
1 parent 0824604 commit 7038897

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

binaryninjaapi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8594,6 +8594,8 @@ namespace BinaryNinja {
85948594

85958595
uint64_t GetElementCount() const;
85968596
uint64_t GetOffset() const;
8597+
BNPointerBaseType GetPointerBaseType() const;
8598+
int64_t GetPointerBaseOffset() const;
85978599

85988600
std::set<BNPointerSuffix> GetPointerSuffix() const;
85998601
std::string GetPointerSuffixString() const;
@@ -8984,11 +8986,14 @@ namespace BinaryNinja {
89848986
uint64_t GetElementCount() const;
89858987
uint64_t GetOffset() const;
89868988
uint32_t GetSystemCallNumber() const;
8989+
BNPointerBaseType GetPointerBaseType() const;
8990+
int64_t GetPointerBaseOffset() const;
89878991

89888992
TypeBuilder& SetOffset(uint64_t offset);
89898993
TypeBuilder& SetFunctionCanReturn(const Confidence<bool>& canReturn);
89908994
TypeBuilder& SetPure(const Confidence<bool>& pure);
89918995
TypeBuilder& SetParameters(const std::vector<FunctionParameter>& params);
8996+
TypeBuilder& SetPointerBase(BNPointerBaseType baseType, int64_t baseOffset);
89928997

89938998
std::set<BNPointerSuffix> GetPointerSuffix() const;
89948999
std::string GetPointerSuffixString() const;

binaryninjacore.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,14 @@ extern "C"
805805
LvalueSuffix,
806806
} BNPointerSuffix;
807807

808+
typedef enum BNPointerBaseType
809+
{
810+
AbsolutePointerBaseType,
811+
RelativeToConstantPointerBaseType,
812+
RelativeToBinaryStartPointerBaseType,
813+
RelativeToVariableAddressPointerBaseType,
814+
} BNPointerBaseType;
815+
808816
// Caution: these enumeration values are used a lookups into the static NameTypeStrings in the core
809817
// if you modify this you must also modify the string lookups as well
810818
typedef enum BNNameType
@@ -5868,6 +5876,8 @@ extern "C"
58685876
BINARYNINJACOREAPI BNQualifiedName BNTypeGetStructureName(BNType* type);
58695877
BINARYNINJACOREAPI BNNamedTypeReference* BNGetRegisteredTypeName(BNType* type);
58705878
BINARYNINJACOREAPI BNReferenceType BNTypeGetReferenceType(BNType* type);
5879+
BINARYNINJACOREAPI BNPointerBaseType BNTypeGetPointerBaseType(BNType* type);
5880+
BINARYNINJACOREAPI int64_t BNTypeGetPointerBaseOffset(BNType* type);
58715881
BINARYNINJACOREAPI char* BNGetTypeAlternateName(BNType* type);
58725882
BINARYNINJACOREAPI uint32_t BNTypeGetSystemCallNumber(BNType* type);
58735883
BINARYNINJACOREAPI bool BNTypeIsSystemCall(BNType* type);
@@ -5920,6 +5930,7 @@ extern "C"
59205930
BINARYNINJACOREAPI uint64_t BNGetTypeBuilderElementCount(BNTypeBuilder* type);
59215931
BINARYNINJACOREAPI uint64_t BNGetTypeBuilderOffset(BNTypeBuilder* type);
59225932
BINARYNINJACOREAPI void BNSetTypeBuilderOffset(BNTypeBuilder* type, uint64_t offset);
5933+
BINARYNINJACOREAPI void BNSetTypeBuilderPointerBase(BNTypeBuilder* type, BNPointerBaseType baseType, int64_t baseOffset);
59235934
BINARYNINJACOREAPI void BNSetFunctionTypeBuilderCanReturn(BNTypeBuilder* type, BNBoolWithConfidence* canReturn);
59245935
BINARYNINJACOREAPI void BNSetTypeBuilderPure(BNTypeBuilder* type, BNBoolWithConfidence* pure);
59255936
BINARYNINJACOREAPI void BNSetFunctionTypeBuilderParameters(
@@ -5933,6 +5944,8 @@ extern "C"
59335944
BINARYNINJACOREAPI BNOffsetWithConfidence BNGetTypeBuilderStackAdjustment(BNTypeBuilder* type);
59345945
BINARYNINJACOREAPI BNQualifiedName BNTypeBuilderGetStructureName(BNTypeBuilder* type);
59355946
BINARYNINJACOREAPI BNReferenceType BNTypeBuilderGetReferenceType(BNTypeBuilder* type);
5947+
BINARYNINJACOREAPI BNPointerBaseType BNTypeBuilderGetPointerBaseType(BNTypeBuilder* type);
5948+
BINARYNINJACOREAPI int64_t BNTypeBuilderGetPointerBaseOffset(BNTypeBuilder* type);
59365949
BINARYNINJACOREAPI char* BNGetTypeBuilderAlternateName(BNTypeBuilder* type);
59375950
BINARYNINJACOREAPI bool BNTypeBuilderIsSystemCall(BNTypeBuilder* type);
59385951
BINARYNINJACOREAPI uint32_t BNTypeBuilderGetSystemCallNumber(BNTypeBuilder* type);

python/types.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
# Binary Ninja components
2828
from . import _binaryninjacore as core
2929
from .enums import (
30-
StructureVariant, SymbolType, SymbolBinding, TypeClass, NamedTypeReferenceClass, ReferenceType, VariableSourceType,
31-
TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType, TokenEscapingType,
32-
NameType, PointerSuffix
30+
StructureVariant, SymbolType, SymbolBinding, TypeClass, NamedTypeReferenceClass,
31+
ReferenceType, VariableSourceType,
32+
TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType,
33+
TokenEscapingType,
34+
NameType, PointerSuffix, PointerBaseType
3335
)
3436
from . import callingconvention
3537
from . import function as _function
@@ -998,6 +1000,25 @@ def get_pointer_suffix_tokens(self, base_confidence: int = core.max_confidence)
9981000
core.BNFreeInstructionText(tokens, count.value)
9991001
return result
10001002

1003+
def set_pointer_base(self, base_type: PointerBaseType, base_offset: int):
1004+
core.BNSetTypeBuilderPointerBase(self._handle, base_type, base_offset)
1005+
1006+
@property
1007+
def pointer_base_type(self) -> PointerBaseType:
1008+
return PointerBaseType(core.BNTypeBuilderGetPointerBaseType(self._handle))
1009+
1010+
@pointer_base_type.setter
1011+
def pointer_base_type(self, value: PointerBaseType):
1012+
self.set_pointer_base(value, self.pointer_base_offset)
1013+
1014+
@property
1015+
def pointer_base_offset(self) -> int:
1016+
return core.BNTypeBuilderGetPointerBaseOffset(self._handle)
1017+
1018+
@pointer_base_offset.setter
1019+
def pointer_base_offset(self, value: int):
1020+
self.set_pointer_base(self.pointer_base_type, value)
1021+
10011022

10021023
class ArrayBuilder(TypeBuilder):
10031024
@classmethod
@@ -2857,6 +2878,14 @@ def get_pointer_suffix_tokens(self, base_confidence: int = core.max_confidence)
28572878
core.BNFreeInstructionText(tokens, count.value)
28582879
return result
28592880

2881+
@property
2882+
def pointer_base_type(self) -> PointerBaseType:
2883+
return PointerBaseType(core.BNTypeGetPointerBaseType(self._handle))
2884+
2885+
@property
2886+
def pointer_base_offset(self) -> int:
2887+
return core.BNTypeGetPointerBaseOffset(self._handle)
2888+
28602889

28612890
class ArrayType(Type):
28622891
@classmethod

type.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,18 @@ uint64_t Type::GetOffset() const
686686
}
687687

688688

689+
BNPointerBaseType Type::GetPointerBaseType() const
690+
{
691+
return BNTypeGetPointerBaseType(m_object);
692+
}
693+
694+
695+
int64_t Type::GetPointerBaseOffset() const
696+
{
697+
return BNTypeGetPointerBaseOffset(m_object);
698+
}
699+
700+
689701
Confidence<int64_t> Type::GetStackAdjustment() const
690702
{
691703
BNOffsetWithConfidence result = BNGetTypeStackAdjustment(m_object);
@@ -1966,6 +1978,13 @@ TypeBuilder& TypeBuilder::SetParameters(const std::vector<FunctionParameter>& pa
19661978
}
19671979

19681980

1981+
TypeBuilder& TypeBuilder::SetPointerBase(BNPointerBaseType baseType, int64_t baseOffset)
1982+
{
1983+
BNSetTypeBuilderPointerBase(m_object, baseType, baseOffset);
1984+
return *this;
1985+
}
1986+
1987+
19691988
std::set<BNPointerSuffix> TypeBuilder::GetPointerSuffix() const
19701989
{
19711990
size_t count = 0;
@@ -2058,6 +2077,18 @@ uint32_t TypeBuilder::GetSystemCallNumber() const
20582077
}
20592078

20602079

2080+
BNPointerBaseType TypeBuilder::GetPointerBaseType() const
2081+
{
2082+
return BNTypeBuilderGetPointerBaseType(m_object);
2083+
}
2084+
2085+
2086+
int64_t TypeBuilder::GetPointerBaseOffset() const
2087+
{
2088+
return BNTypeBuilderGetPointerBaseOffset(m_object);
2089+
}
2090+
2091+
20612092
QualifiedName TypeBuilder::GetStructureName() const
20622093
{
20632094
BNQualifiedName name = BNTypeBuilderGetStructureName(m_object);

0 commit comments

Comments
 (0)