Skip to content

Commit 5094770

Browse files
committed
Add TypeContainer::GetEmptyTypeContainer
1 parent 1b579ce commit 5094770

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

binaryninjaapi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18573,6 +18573,12 @@ namespace BinaryNinja {
1857318573

1857418574
BNTypeContainer* GetObject() const { return m_object; }
1857518575

18576+
/*! Get an empty type container which contains no types (immutable)
18577+
18578+
\return Empty type container
18579+
*/
18580+
static TypeContainer GetEmptyTypeContainer();
18581+
1857618582
/*! Get an id string for the Type Container. This will be unique within a given
1857718583
analysis session, but may not be globally unique.
1857818584

binaryninjacore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,7 @@ extern "C"
32803280
TypeArchiveTypeContainerType,
32813281
DebugInfoTypeContainerType,
32823282
PlatformTypeContainerType,
3283+
EmptyTypeContainerType,
32833284
OtherTypeContainerType
32843285
} BNTypeContainerType;
32853286

@@ -5305,6 +5306,7 @@ extern "C"
53055306
const char* autoTypeSource, bool importDepencencies, BNTypeParserResult* result,
53065307
BNTypeParserError** errors, size_t* errorCount
53075308
);
5309+
BINARYNINJACOREAPI BNTypeContainer* BNGetEmptyTypeContainer();
53085310

53095311
BINARYNINJACOREAPI BNTagType* BNCreateTagType(BNBinaryView* view);
53105312
BINARYNINJACOREAPI BNTagType* BNNewTagTypeReference(BNTagType* tagType);

python/typecontainer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def __del__(self):
6666
def __repr__(self):
6767
return f"<type container {self.name}>"
6868

69+
@classmethod
70+
def empty(cls):
71+
"""
72+
Get an empty Type Container which contains no types (immutable)
73+
Useful when a function requires a Type Container but you don't have one.
74+
:return: Empty type container
75+
"""
76+
handle = core.BNGetEmptyTypeContainer()
77+
return TypeContainer(handle=handle)
78+
6979
@property
7080
def id(self) -> str:
7181
"""

rust/src/type_container.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ impl TypeContainer {
4242
}
4343
}
4444

45+
/// Get an empty type container that contains no types (immutable)
46+
pub fn empty() -> TypeContainer {
47+
let result = unsafe { BNGetEmptyTypeContainer() };
48+
unsafe { Self::from_raw(NonNull::new(result).unwrap()) }
49+
}
50+
4551
/// Get an id string for the Type Container. This will be unique within a given
4652
/// analysis session, but may not be globally unique.
4753
pub fn id(&self) -> String {

typecontainer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ TypeContainer& TypeContainer::operator=(TypeContainer&& other)
9393
}
9494

9595

96+
TypeContainer TypeContainer::GetEmptyTypeContainer()
97+
{
98+
auto* container = BNGetEmptyTypeContainer();
99+
return TypeContainer(container);
100+
}
101+
102+
96103
std::string TypeContainer::GetId() const
97104
{
98105
char* id = BNTypeContainerGetId(m_object);

0 commit comments

Comments
 (0)