summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.cpp9
-rw-r--r--binaryninjaapi.h27
-rw-r--r--binaryninjacore.h19
-rw-r--r--binaryview.cpp54
-rw-r--r--python/__init__.py4
-rw-r--r--python/binaryview.py126
-rw-r--r--python/types.py63
-rw-r--r--type.cpp90
8 files changed, 354 insertions, 38 deletions
diff --git a/binaryninjaapi.cpp b/binaryninjaapi.cpp
index e1dab528..099f35eb 100644
--- a/binaryninjaapi.cpp
+++ b/binaryninjaapi.cpp
@@ -237,3 +237,12 @@ void BinaryNinja::SetWorkerThreadCount(size_t count)
{
BNSetWorkerThreadCount(count);
}
+
+
+string BinaryNinja::GetUniqueIdentifierString()
+{
+ char* str = BNGetUniqueIdentifierString();
+ string result = str;
+ BNFreeString(str);
+ return result;
+}
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 4e3f3d57..92eeba30 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -409,6 +409,8 @@ namespace BinaryNinja
BNMessageBoxButtonResult ShowMessageBox(const std::string& title, const std::string& text,
BNMessageBoxButtonSet buttons = OKButtonSet, BNMessageBoxIcon icon = InformationIcon);
+ std::string GetUniqueIdentifierString();
+
class QualifiedName
{
std::vector<std::string> m_name;
@@ -1027,11 +1029,15 @@ namespace BinaryNinja
std::map<QualifiedName, Ref<Type>> GetTypes();
Ref<Type> GetTypeByName(const QualifiedName& name);
+ Ref<Type> GetTypeById(const std::string& id);
+ std::string GetTypeId(const QualifiedName& name);
+ QualifiedName GetTypeNameById(const std::string& id);
bool IsTypeAutoDefined(const QualifiedName& name);
- void DefineType(const QualifiedName& name, Ref<Type> type);
+ QualifiedName DefineType(const std::string& id, const QualifiedName& defaultName, Ref<Type> type);
void DefineUserType(const QualifiedName& name, Ref<Type> type);
- void UndefineType(const QualifiedName& name);
+ void UndefineType(const std::string& id);
void UndefineUserType(const QualifiedName& name);
+ void RenameType(const QualifiedName& oldName, const QualifiedName& newName);
bool FindNextData(uint64_t start, const DataBuffer& data, uint64_t& result, BNFindFlag flags = NoFindFlags);
@@ -1611,12 +1617,18 @@ namespace BinaryNinja
static Ref<Type> StructureType(Structure* strct);
static Ref<Type> NamedType(NamedTypeReference* ref, size_t width = 0, size_t align = 1);
static Ref<Type> NamedType(const QualifiedName& name, Type* type);
+ static Ref<Type> NamedType(const std::string& id, const QualifiedName& name, Type* type);
+ static Ref<Type> NamedType(BinaryView* view, const QualifiedName& name);
static Ref<Type> EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, bool issigned = false);
static Ref<Type> PointerType(Architecture* arch, Type* type, bool cnst = false, bool vltl = false,
BNReferenceType refType = PointerReferenceType);
static Ref<Type> ArrayType(Type* type, uint64_t elem);
static Ref<Type> FunctionType(Type* returnValue, CallingConvention* callingConvention,
const std::vector<NameAndType>& params, bool varArg = false);
+
+ static std::string GenerateAutoTypeId(const std::string& source, const QualifiedName& name);
+ static std::string GenerateAutoPlatformTypeId(const QualifiedName& name);
+ static std::string GenerateAutoDemangledTypeId(const QualifiedName& name);
};
class NamedTypeReference: public CoreRefCountObject<BNNamedTypeReference, BNNewNamedTypeReference,
@@ -1624,12 +1636,21 @@ namespace BinaryNinja
{
public:
NamedTypeReference(BNNamedTypeReference* nt);
- NamedTypeReference(BNNamedTypeReferenceClass cls = UnknownNamedTypeClass,
+ NamedTypeReference(BNNamedTypeReferenceClass cls = UnknownNamedTypeClass, const std::string& id = "",
const QualifiedName& name = QualifiedName());
BNNamedTypeReferenceClass GetTypeClass() const;
void SetTypeClass(BNNamedTypeReferenceClass cls);
+ std::string GetTypeId() const;
+ void SetTypeId(const std::string& id);
QualifiedName GetName() const;
void SetName(const QualifiedName& name);
+
+ static Ref<NamedTypeReference> GenerateAutoTypeReference(BNNamedTypeReferenceClass cls,
+ const std::string& source, const QualifiedName& name);
+ static Ref<NamedTypeReference> GenerateAutoPlatformTypeReference(BNNamedTypeReferenceClass cls,
+ const QualifiedName& name);
+ static Ref<NamedTypeReference> GenerateAutoDemangledTypeReference(BNNamedTypeReferenceClass cls,
+ const QualifiedName& name);
};
struct StructureMember
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 7d3bc14c..b454da64 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1234,6 +1234,8 @@ extern "C"
BINARYNINJACOREAPI void BNRegisterObjectDestructionCallbacks(BNObjectDestructionCallbacks* callbacks);
BINARYNINJACOREAPI void BNUnregisterObjectDestructionCallbacks(BNObjectDestructionCallbacks* callbacks);
+ BINARYNINJACOREAPI char* BNGetUniqueIdentifierString(void);
+
// Plugin initialization
BINARYNINJACOREAPI void BNInitCorePlugins(void);
BINARYNINJACOREAPI void BNInitUserPlugins(void);
@@ -1807,11 +1809,19 @@ extern "C"
BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetAnalysisTypeList(BNBinaryView* view, size_t* count);
BINARYNINJACOREAPI void BNFreeTypeList(BNQualifiedNameAndType* types, size_t count);
BINARYNINJACOREAPI BNType* BNGetAnalysisTypeByName(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI BNType* BNGetAnalysisTypeById(BNBinaryView* view, const char* id);
+ BINARYNINJACOREAPI char* BNGetAnalysisTypeId(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI BNQualifiedName BNGetAnalysisTypeNameById(BNBinaryView* view, const char* id);
BINARYNINJACOREAPI bool BNIsAnalysisTypeAutoDefined(BNBinaryView* view, BNQualifiedName* name);
- BINARYNINJACOREAPI void BNDefineAnalysisType(BNBinaryView* view, BNQualifiedName* name, BNType* type);
+ BINARYNINJACOREAPI BNQualifiedName BNDefineAnalysisType(BNBinaryView* view, const char* id,
+ BNQualifiedName* defaultName, BNType* type);
BINARYNINJACOREAPI void BNDefineUserAnalysisType(BNBinaryView* view, BNQualifiedName* name, BNType* type);
- BINARYNINJACOREAPI void BNUndefineAnalysisType(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI void BNUndefineAnalysisType(BNBinaryView* view, const char* id);
BINARYNINJACOREAPI void BNUndefineUserAnalysisType(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI void BNRenameAnalysisType(BNBinaryView* view, BNQualifiedName* oldName, BNQualifiedName* newName);
+ BINARYNINJACOREAPI char* BNGenerateAutoTypeId(const char* source, BNQualifiedName* name);
+ BINARYNINJACOREAPI char* BNGenerateAutoPlatformTypeId(BNQualifiedName* name);
+ BINARYNINJACOREAPI char* BNGenerateAutoDemangledTypeId(BNQualifiedName* name);
BINARYNINJACOREAPI void BNReanalyzeAllFunctions(BNBinaryView* view);
BINARYNINJACOREAPI void BNReanalyzeFunction(BNFunction* func);
@@ -2006,10 +2016,13 @@ extern "C"
BINARYNINJACOREAPI void BNFreeTokenList(BNInstructionTextToken* tokens, size_t count);
BINARYNINJACOREAPI BNType* BNCreateNamedTypeReference(BNNamedTypeReference* nt, size_t width, size_t align);
- BINARYNINJACOREAPI BNType* BNCreateNamedTypeReferenceFromType(BNQualifiedName* name, BNType* type);
+ BINARYNINJACOREAPI BNType* BNCreateNamedTypeReferenceFromTypeAndId(const char* id, BNQualifiedName* name, BNType* type);
+ BINARYNINJACOREAPI BNType* BNCreateNamedTypeReferenceFromType(BNBinaryView* view, BNQualifiedName* name);
BINARYNINJACOREAPI BNNamedTypeReference* BNCreateNamedType(void);
BINARYNINJACOREAPI void BNSetTypeReferenceClass(BNNamedTypeReference* nt, BNNamedTypeReferenceClass cls);
BINARYNINJACOREAPI BNNamedTypeReferenceClass BNGetTypeReferenceClass(BNNamedTypeReference* nt);
+ BINARYNINJACOREAPI void BNSetTypeReferenceId(BNNamedTypeReference* nt, const char* id);
+ BINARYNINJACOREAPI char* BNGetTypeReferenceId(BNNamedTypeReference* nt);
BINARYNINJACOREAPI void BNSetTypeReferenceName(BNNamedTypeReference* nt, BNQualifiedName* name);
BINARYNINJACOREAPI BNQualifiedName BNGetTypeReferenceName(BNNamedTypeReference* nt);
BINARYNINJACOREAPI void BNFreeQualifiedName(BNQualifiedName* name);
diff --git a/binaryview.cpp b/binaryview.cpp
index cc8bb733..1b1574e1 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1496,6 +1496,35 @@ Ref<Type> BinaryView::GetTypeByName(const QualifiedName& name)
}
+Ref<Type> BinaryView::GetTypeById(const string& id)
+{
+ BNType* type = BNGetAnalysisTypeById(m_object, id.c_str());
+ if (!type)
+ return nullptr;
+ return new Type(type);
+}
+
+
+QualifiedName BinaryView::GetTypeNameById(const string& id)
+{
+ BNQualifiedName name = BNGetAnalysisTypeNameById(m_object, id.c_str());
+ QualifiedName result = QualifiedName::FromAPIObject(&name);
+ BNFreeQualifiedName(&name);
+ return result;
+}
+
+
+string BinaryView::GetTypeId(const QualifiedName& name)
+{
+ BNQualifiedName nameObj = name.GetAPIObject();
+ char* id = BNGetAnalysisTypeId(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
+ string result = id;
+ BNFreeString(id);
+ return result;
+}
+
+
bool BinaryView::IsTypeAutoDefined(const QualifiedName& name)
{
BNQualifiedName nameObj = name.GetAPIObject();
@@ -1505,11 +1534,14 @@ bool BinaryView::IsTypeAutoDefined(const QualifiedName& name)
}
-void BinaryView::DefineType(const QualifiedName& name, Ref<Type> type)
+QualifiedName BinaryView::DefineType(const string& id, const QualifiedName& defaultName, Ref<Type> type)
{
- BNQualifiedName nameObj = name.GetAPIObject();
- BNDefineAnalysisType(m_object, &nameObj, type->GetObject());
+ BNQualifiedName nameObj = defaultName.GetAPIObject();
+ BNQualifiedName regName = BNDefineAnalysisType(m_object, id.c_str(), &nameObj, type->GetObject());
QualifiedName::FreeAPIObject(&nameObj);
+ QualifiedName result = QualifiedName::FromAPIObject(&regName);
+ BNFreeQualifiedName(&regName);
+ return result;
}
@@ -1521,11 +1553,9 @@ void BinaryView::DefineUserType(const QualifiedName& name, Ref<Type> type)
}
-void BinaryView::UndefineType(const QualifiedName& name)
+void BinaryView::UndefineType(const string& id)
{
- BNQualifiedName nameObj = name.GetAPIObject();
- BNUndefineAnalysisType(m_object, &nameObj);
- QualifiedName::FreeAPIObject(&nameObj);
+ BNUndefineAnalysisType(m_object, id.c_str());
}
@@ -1537,6 +1567,16 @@ void BinaryView::UndefineUserType(const QualifiedName& name)
}
+void BinaryView::RenameType(const QualifiedName& oldName, const QualifiedName& newName)
+{
+ BNQualifiedName oldNameObj = oldName.GetAPIObject();
+ BNQualifiedName newNameObj = newName.GetAPIObject();
+ BNRenameAnalysisType(m_object, &oldNameObj, &newNameObj);
+ QualifiedName::FreeAPIObject(&oldNameObj);
+ QualifiedName::FreeAPIObject(&newNameObj);
+}
+
+
bool BinaryView::FindNextData(uint64_t start, const DataBuffer& data, uint64_t& result, BNFindFlag flags)
{
return BNFindNextData(m_object, start, data.GetBufferObject(), &result, flags);
diff --git a/python/__init__.py b/python/__init__.py
index a1ea02f5..9b87aa47 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -51,6 +51,10 @@ def shutdown():
core.BNShutdown()
+def get_unique_identifier():
+ return core.BNGetUniqueIdentifierString()
+
+
class _DestructionCallbackHandler(object):
def __init__(self):
self._cb = core.BNObjectDestructionCallbacks()
diff --git a/python/binaryview.py b/python/binaryview.py
index ba706fe5..2cdacb4c 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -2881,7 +2881,7 @@ class BinaryView(object):
:Example:
>>> type, name = bv.parse_type_string("int foo")
- >>> bv.define_type(name, type)
+ >>> bv.define_user_type(name, type)
>>> bv.get_type_by_name(name)
<type: int32_t>
>>>
@@ -2892,6 +2892,71 @@ class BinaryView(object):
return None
return types.Type(obj)
+ def get_type_by_id(self, id):
+ """
+ ``get_type_by_id`` returns the defined type whose unique identifier corresponds with the provided ``id``
+
+ :param str id: Unique identifier to lookup
+ :return: A :py:Class:`Type` or None if the type does not exist
+ :rtype: Type or None
+ :Example:
+
+ >>> type, name = bv.parse_type_string("int foo")
+ >>> type_id = Type.generate_auto_type_id("source", name)
+ >>> bv.define_type(type_id, name, type)
+ >>> bv.get_type_by_id(type_id)
+ <type: int32_t>
+ >>>
+ """
+ obj = core.BNGetAnalysisTypeById(self.handle, id)
+ if not obj:
+ return None
+ return types.Type(obj)
+
+ def get_type_name_by_id(self, id):
+ """
+ ``get_type_name_by_id`` returns the defined type name whose unique identifier corresponds with the provided ``id``
+
+ :param str id: Unique identifier to lookup
+ :return: A QualifiedName or None if the type does not exist
+ :rtype: QualifiedName or None
+ :Example:
+
+ >>> type, name = bv.parse_type_string("int foo")
+ >>> type_id = Type.generate_auto_type_id("source", name)
+ >>> bv.define_type(type_id, name, type)
+ 'foo'
+ >>> bv.get_type_name_by_id(type_id)
+ 'foo'
+ >>>
+ """
+ name = core.BNGetAnalysisTypeNameById(self.handle, id)
+ result = types.QualifiedName._from_core_struct(name)
+ core.BNFreeQualifiedName(name)
+ if len(result) == 0:
+ return None
+ return result
+
+ def get_type_id(self, name):
+ """
+ ``get_type_id`` returns the unique indentifier of the defined type whose name corresponds with the
+ provided ``name``
+
+ :param QualifiedName name: Type name to lookup
+ :return: The unique identifier of the type
+ :rtype: str
+ :Example:
+
+ >>> type, name = bv.parse_type_string("int foo")
+ >>> type_id = Type.generate_auto_type_id("source", name)
+ >>> registered_name = bv.define_type(type_id, name, type)
+ >>> bv.get_type_id(registered_name) == type_id
+ True
+ >>>
+ """
+ name = types.QualifiedName(name)._get_core_struct()
+ return core.BNGetAnalysisTypeId(self.handle, name)
+
def is_type_auto_defined(self, name):
"""
``is_type_auto_defined`` queries the user type list of name. If name is not in the *user* type list then the name
@@ -2910,23 +2975,28 @@ class BinaryView(object):
name = types.QualifiedName(name)._get_core_struct()
return core.BNIsAnalysisTypeAutoDefined(self.handle, name)
- def define_type(self, name, type_obj):
+ def define_type(self, type_id, default_name, type_obj):
"""
``define_type`` registers a :py:Class:`Type` ``type_obj`` of the given ``name`` in the global list of types for
- the current :py:Class:`BinaryView`.
+ the current :py:Class:`BinaryView`. This method should only be used for automatically generated types.
- :param QualifiedName name: Name of the type to be registered
+ :param str type_id: Unique identifier for the automatically generated type
+ :param QualifiedName default_name: Name of the type to be registered
:param Type type_obj: Type object to be registered
- :rtype: None
+ :return: Registered name of the type. May not be the same as the requested name if the user has renamed types.
+ :rtype: QualifiedName
:Example:
>>> type, name = bv.parse_type_string("int foo")
- >>> bv.define_type(name, type)
- >>> bv.get_type_by_name(name)
+ >>> registered_name = bv.define_type(Type.generate_auto_type_id("source", name), name, type)
+ >>> bv.get_type_by_name(registered_name)
<type: int32_t>
"""
- name = types.QualifiedName(name)._get_core_struct()
- core.BNDefineAnalysisType(self.handle, name, type_obj.handle)
+ name = types.QualifiedName(default_name)._get_core_struct()
+ reg_name = core.BNDefineAnalysisType(self.handle, type_id, name, type_obj.handle)
+ result = types.QualifiedName._from_core_struct(reg_name)
+ core.BNFreeQualifiedName(reg_name)
+ return result
def define_user_type(self, name, type_obj):
"""
@@ -2946,24 +3016,24 @@ class BinaryView(object):
name = types.QualifiedName(name)._get_core_struct()
core.BNDefineUserAnalysisType(self.handle, name, type_obj.handle)
- def undefine_type(self, name):
+ def undefine_type(self, type_id):
"""
``undefine_type`` removes a :py:Class:`Type` from the global list of types for the current :py:Class:`BinaryView`
- :param QualifiedName name: Name of type to be undefined
+ :param str type_id: Unique identifier of type to be undefined
:rtype: None
:Example:
>>> type, name = bv.parse_type_string("int foo")
- >>> bv.define_type(name, type)
+ >>> type_id = Type.generate_auto_type_id("source", name)
+ >>> bv.define_type(type_id, name, type)
>>> bv.get_type_by_name(name)
<type: int32_t>
- >>> bv.undefine_type(name)
+ >>> bv.undefine_type(type_id)
>>> bv.get_type_by_name(name)
>>>
"""
- name = types.QualifiedName(name)._get_core_struct()
- core.BNUndefineAnalysisType(self.handle, name)
+ core.BNUndefineAnalysisType(self.handle, type_id)
def undefine_user_type(self, name):
"""
@@ -2975,16 +3045,38 @@ class BinaryView(object):
:Example:
>>> type, name = bv.parse_type_string("int foo")
- >>> bv.define_type(name, type)
+ >>> bv.define_user_type(name, type)
>>> bv.get_type_by_name(name)
<type: int32_t>
- >>> bv.undefine_type(name)
+ >>> bv.undefine_user_type(name)
>>> bv.get_type_by_name(name)
>>>
"""
name = types.QualifiedName(name)._get_core_struct()
core.BNUndefineUserAnalysisType(self.handle, name)
+ def rename_type(self, old_name, new_name):
+ """
+ ``rename_type`` renames a type in the global list of types for the current :py:Class:`BinaryView`
+
+ :param QualifiedName old_name: Existing name of type to be renamed
+ :param QualifiedName new_name: New name of type to be renamed
+ :rtype: None
+ :Example:
+
+ >>> type, name = bv.parse_type_string("int foo")
+ >>> bv.define_user_type(name, type)
+ >>> bv.get_type_by_name("foo")
+ <type: int32_t>
+ >>> bv.rename_type("foo", "bar")
+ >>> bv.get_type_by_name("bar")
+ <type: int32_t>
+ >>>
+ """
+ old_name = types.QualifiedName(old_name)._get_core_struct()
+ new_name = types.QualifiedName(new_name)._get_core_struct()
+ core.BNRenameAnalysisType(self.handle, old_name, new_name)
+
def find_next_data(self, start, data, flags = 0):
"""
``find_next_data`` searchs for the bytes in data starting at the virtual address ``start`` either, case-sensitive,
diff --git a/python/types.py b/python/types.py
index 1dd2157e..1cc02691 100644
--- a/python/types.py
+++ b/python/types.py
@@ -299,7 +299,7 @@ class Type(object):
result = core.BNGetTypeNamedTypeReference(self.handle)
if result is None:
return None
- return NamedTypeReference(result)
+ return NamedTypeReference(handle = result)
@property
def count(self):
@@ -393,11 +393,23 @@ class Type(object):
return Type(core.BNCreateNamedTypeReference(named_type.handle, width, align))
@classmethod
+ def named_type_from_type_and_id(self, type_id, name, t):
+ name = QualifiedName(name)._get_core_struct()
+ if t is not None:
+ t = t.handle
+ return Type(core.BNCreateNamedTypeReferenceFromTypeAndId(type_id, name, t))
+
+ @classmethod
def named_type_from_type(self, name, t):
name = QualifiedName(name)._get_core_struct()
if t is not None:
t = t.handle
- return Type(core.BNCreateNamedTypeReferenceFromType(name, t))
+ return Type(core.BNCreateNamedTypeReferenceFromTypeAndId("", name, t))
+
+ @classmethod
+ def named_type_from_registered_type(self, view, name):
+ name = QualifiedName(name)._get_core_struct()
+ return Type(core.BNCreateNamedTypeReferenceFromType(view.handle, name))
@classmethod
def enumeration_type(self, arch, e, width=None):
@@ -428,6 +440,21 @@ class Type(object):
return Type(core.BNCreateFunctionType(ret.handle, calling_convention, param_buf, len(params),
variable_arguments))
+ @classmethod
+ def generate_auto_type_id(self, source, name):
+ name = QualifiedName(name)._get_core_struct()
+ return core.BNGenerateAutoTypeId(source, name)
+
+ @classmethod
+ def generate_auto_platform_type_id(self, name):
+ name = QualifiedName(name)._get_core_struct()
+ return core.BNGenerateAutoTypeId(name)
+
+ @classmethod
+ def generate_auto_demangled_type_id(self, name):
+ name = QualifiedName(name)._get_core_struct()
+ return core.BNGenerateAutoTypeId(name)
+
def __setattr__(self, name, value):
try:
object.__setattr__(self, name, value)
@@ -436,10 +463,12 @@ class Type(object):
class NamedTypeReference(object):
- def __init__(self, type_class = NamedTypeReferenceClass.UnknownNamedTypeClass, name = None, handle = None):
+ def __init__(self, type_class = NamedTypeReferenceClass.UnknownNamedTypeClass, type_id = None, name = None, handle = None):
if handle is None:
self.handle = core.BNCreateNamedType()
core.BNSetTypeReferenceClass(self.handle, type_class)
+ if type_id is not None:
+ core.BNSetTypeReferenceId(self.handle, type_id)
if name is not None:
name = QualifiedName(name)._get_core_struct()
core.BNSetTypeReferenceName(self.handle, name)
@@ -451,16 +480,23 @@ class NamedTypeReference(object):
@property
def type_class(self):
- return core.BNGetTypeReferenceClass(self.handle)
+ return NamedTypeReferenceClass(core.BNGetTypeReferenceClass(self.handle))
@type_class.setter
def type_class(self, value):
core.BNSetTypeReferenceClass(self.handle, value)
@property
+ def type_id(self):
+ return core.BNGetTypeReferenceId(self.handle)
+
+ @type_id.setter
+ def type_id(self, value):
+ core.BNSetTypeReferenceId(self.handle, value)
+
+ @property
def name(self):
- count = ctypes.c_ulonglong()
- name = core.BNGetTypeReferenceName(self.handle, count)
+ name = core.BNGetTypeReferenceName(self.handle)
result = QualifiedName._from_core_struct(name)
core.BNFreeQualifiedName(name)
return result
@@ -481,6 +517,21 @@ class NamedTypeReference(object):
return "<named type: enum %s>" % str(self.name)
return "<named type: unknown %s>" % str(self.name)
+ @classmethod
+ def generate_auto_type_ref(self, type_class, source, name):
+ type_id = Type.generate_auto_type_id(source, name)
+ return NamedTypeReference(type_class, type_id, name)
+
+ @classmethod
+ def generate_auto_platform_type_ref(self, type_class, source, name):
+ type_id = Type.generate_auto_platform_type_id(source, name)
+ return NamedTypeReference(type_class, type_id, name)
+
+ @classmethod
+ def generate_auto_demangled_type_ref(self, type_class, source, name):
+ type_id = Type.generate_auto_demangled_type_id(source, name)
+ return NamedTypeReference(type_class, type_id, name)
+
class StructureMember(object):
def __init__(self, t, name, offset):
diff --git a/type.cpp b/type.cpp
index e71077e6..dd1fb8d6 100644
--- a/type.cpp
+++ b/type.cpp
@@ -512,8 +512,24 @@ Ref<Type> Type::NamedType(NamedTypeReference* ref, size_t width, size_t align)
Ref<Type> Type::NamedType(const QualifiedName& name, Type* type)
{
+ return NamedType("", name, type);
+}
+
+
+Ref<Type> Type::NamedType(const string& id, const QualifiedName& name, Type* type)
+{
BNQualifiedName nameObj = name.GetAPIObject();
- Type* result = new Type(BNCreateNamedTypeReferenceFromType(&nameObj, type ? type->GetObject() : nullptr));
+ Type* result = new Type(BNCreateNamedTypeReferenceFromTypeAndId(id.c_str(), &nameObj,
+ type ? type->GetObject() : nullptr));
+ QualifiedName::FreeAPIObject(&nameObj);
+ return result;
+}
+
+
+Ref<Type> Type::NamedType(BinaryView* view, const QualifiedName& name)
+{
+ BNQualifiedName nameObj = name.GetAPIObject();
+ Type* result = new Type(BNCreateNamedTypeReferenceFromType(view->GetObject(), &nameObj));
QualifiedName::FreeAPIObject(&nameObj);
return result;
}
@@ -561,16 +577,47 @@ void Type::SetFunctionCanReturn(bool canReturn)
}
+string Type::GenerateAutoTypeId(const string& source, const QualifiedName& name)
+{
+ BNQualifiedName nameObj = name.GetAPIObject();
+ string result = BNGenerateAutoTypeId(source.c_str(), &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
+ return result;
+}
+
+
+string Type::GenerateAutoPlatformTypeId(const QualifiedName& name)
+{
+ BNQualifiedName nameObj = name.GetAPIObject();
+ string result = BNGenerateAutoPlatformTypeId(&nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
+ return result;
+}
+
+
+string Type::GenerateAutoDemangledTypeId(const QualifiedName& name)
+{
+ BNQualifiedName nameObj = name.GetAPIObject();
+ string result = BNGenerateAutoDemangledTypeId(&nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
+ return result;
+}
+
+
NamedTypeReference::NamedTypeReference(BNNamedTypeReference* nt)
{
m_object = nt;
}
-NamedTypeReference::NamedTypeReference(BNNamedTypeReferenceClass cls, const QualifiedName& names)
+NamedTypeReference::NamedTypeReference(BNNamedTypeReferenceClass cls, const string& id, const QualifiedName& names)
{
m_object = BNCreateNamedType();
BNSetTypeReferenceClass(m_object, cls);
+ if (id.size() != 0)
+ {
+ BNSetTypeReferenceId(m_object, id.c_str());
+ }
if (names.size() != 0)
{
BNQualifiedName nameObj = names.GetAPIObject();
@@ -592,6 +639,21 @@ BNNamedTypeReferenceClass NamedTypeReference::GetTypeClass() const
}
+string NamedTypeReference::GetTypeId() const
+{
+ char* str = BNGetTypeReferenceId(m_object);
+ string result = str;
+ BNFreeString(str);
+ return result;
+}
+
+
+void NamedTypeReference::SetTypeId(const string& id)
+{
+ BNSetTypeReferenceId(m_object, id.c_str());
+}
+
+
void NamedTypeReference::SetName(const QualifiedName& names)
{
BNQualifiedName nameObj = names.GetAPIObject();
@@ -609,6 +671,30 @@ QualifiedName NamedTypeReference::GetName() const
}
+Ref<NamedTypeReference> NamedTypeReference::GenerateAutoTypeReference(BNNamedTypeReferenceClass cls,
+ const string& source, const QualifiedName& name)
+{
+ string id = Type::GenerateAutoTypeId(source, name);
+ return new NamedTypeReference(cls, id, name);
+}
+
+
+Ref<NamedTypeReference> NamedTypeReference::GenerateAutoPlatformTypeReference(BNNamedTypeReferenceClass cls,
+ const QualifiedName& name)
+{
+ string id = Type::GenerateAutoPlatformTypeId(name);
+ return new NamedTypeReference(cls, id, name);
+}
+
+
+Ref<NamedTypeReference> NamedTypeReference::GenerateAutoDemangledTypeReference(BNNamedTypeReferenceClass cls,
+ const QualifiedName& name)
+{
+ string id = Type::GenerateAutoDemangledTypeId(name);
+ return new NamedTypeReference(cls, id, name);
+}
+
+
Structure::Structure()
{
m_object = BNCreateStructure();