summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--architecture.cpp24
-rw-r--r--binaryninjaapi.h8
-rw-r--r--binaryninjacore.h34
-rw-r--r--binaryview.cpp72
-rw-r--r--python/__init__.py166
-rw-r--r--type.cpp78
6 files changed, 161 insertions, 221 deletions
diff --git a/architecture.cpp b/architecture.cpp
index 657d7bf0..0e25fa85 100644
--- a/architecture.cpp
+++ b/architecture.cpp
@@ -769,23 +769,17 @@ bool Architecture::ParseTypesFromSource(const string& source, const string& file
for (size_t i = 0; i < result.typeCount; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < result.types[i].nameCount; j++)
- name.push_back(result.types[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&result.types[i].name);
types[name] = new Type(BNNewTypeReference(result.types[i].type));
}
for (size_t i = 0; i < result.variableCount; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < result.variables[i].nameCount; j++)
- name.push_back(result.variables[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&result.variables[i].name);
types[name] = new Type(BNNewTypeReference(result.variables[i].type));
}
for (size_t i = 0; i < result.functionCount; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < result.functions[i].nameCount; j++)
- name.push_back(result.functions[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&result.functions[i].name);
types[name] = new Type(BNNewTypeReference(result.functions[i].type));
}
BNFreeTypeParserResult(&result);
@@ -817,23 +811,17 @@ bool Architecture::ParseTypesFromSourceFile(const string& fileName, map<Qualifie
for (size_t i = 0; i < result.typeCount; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < result.types[i].nameCount; j++)
- name.push_back(result.types[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&result.types[i].name);
types[name] = new Type(BNNewTypeReference(result.types[i].type));
}
for (size_t i = 0; i < result.variableCount; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < result.variables[i].nameCount; j++)
- name.push_back(result.variables[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&result.variables[i].name);
variables[name] = new Type(BNNewTypeReference(result.variables[i].type));
}
for (size_t i = 0; i < result.functionCount; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < result.functions[i].nameCount; j++)
- name.push_back(result.functions[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&result.functions[i].name);
functions[name] = new Type(BNNewTypeReference(result.functions[i].type));
}
BNFreeTypeParserResult(&result);
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 478cc090..afbff4da 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -448,6 +448,10 @@ namespace BinaryNinja
size_t size() const;
std::string GetString() const;
+
+ BNQualifiedName GetAPIObject() const;
+ static void FreeAPIObject(BNQualifiedName* name);
+ static QualifiedName FromAPIObject(BNQualifiedName* name);
};
class DataBuffer
@@ -632,8 +636,8 @@ namespace BinaryNinja
static void DataVariableUpdatedCallback(void* ctxt, BNBinaryView* data, BNDataVariable* var);
static void StringFoundCallback(void* ctxt, BNBinaryView* data, BNStringType type, uint64_t offset, size_t len);
static void StringRemovedCallback(void* ctxt, BNBinaryView* data, BNStringType type, uint64_t offset, size_t len);
- static void TypeDefinedCallback(void* ctxt, BNBinaryView* data, const char** name, size_t nameCount, BNType* type);
- static void TypeUndefinedCallback(void* ctxt, BNBinaryView* data, const char** name, size_t nameCount, BNType* type);
+ static void TypeDefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type);
+ static void TypeUndefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type);
public:
BinaryDataNotification();
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 26f37536..02f753cf 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -631,6 +631,12 @@ extern "C"
bool (*navigate)(void* ctxt, const char* view, uint64_t offset);
};
+ struct BNQualifiedName
+ {
+ char** name;
+ size_t nameCount;
+ };
+
struct BNBinaryDataNotification
{
void* context;
@@ -645,8 +651,8 @@ extern "C"
void (*dataVariableUpdated)(void* ctxt, BNBinaryView* view, BNDataVariable* var);
void (*stringFound)(void* ctxt, BNBinaryView* view, BNStringType type, uint64_t offset, size_t len);
void (*stringRemoved)(void* ctxt, BNBinaryView* view, BNStringType type, uint64_t offset, size_t len);
- void (*typeDefined)(void* ctxt, BNBinaryView* view, const char** name, size_t nameCount, BNType* type);
- void (*typeUndefined)(void* ctxt, BNBinaryView* view, const char** name, size_t nameCount, BNType* type);
+ void (*typeDefined)(void* ctxt, BNBinaryView* view, BNQualifiedName* name, BNType* type);
+ void (*typeUndefined)(void* ctxt, BNBinaryView* view, BNQualifiedName* name, BNType* type);
};
struct BNFileAccessor
@@ -854,8 +860,7 @@ extern "C"
struct BNQualifiedNameAndType
{
- char** name;
- size_t nameCount;
+ BNQualifiedName name;
BNType* type;
};
@@ -1800,12 +1805,12 @@ extern "C"
BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetAnalysisTypeList(BNBinaryView* view, size_t* count);
BINARYNINJACOREAPI void BNFreeTypeList(BNQualifiedNameAndType* types, size_t count);
- BINARYNINJACOREAPI BNType* BNGetAnalysisTypeByName(BNBinaryView* view, const char** name, size_t nameCount);
- BINARYNINJACOREAPI bool BNIsAnalysisTypeAutoDefined(BNBinaryView* view, const char** name, size_t nameCount);
- BINARYNINJACOREAPI void BNDefineAnalysisType(BNBinaryView* view, const char** name, size_t nameCount, BNType* type);
- BINARYNINJACOREAPI void BNDefineUserAnalysisType(BNBinaryView* view, const char** name, size_t nameCount, BNType* type);
- BINARYNINJACOREAPI void BNUndefineAnalysisType(BNBinaryView* view, const char** name, size_t nameCount);
- BINARYNINJACOREAPI void BNUndefineUserAnalysisType(BNBinaryView* view, const char** name, size_t nameCount);
+ BINARYNINJACOREAPI BNType* BNGetAnalysisTypeByName(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI bool BNIsAnalysisTypeAutoDefined(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI void BNDefineAnalysisType(BNBinaryView* view, BNQualifiedName* name, BNType* type);
+ BINARYNINJACOREAPI void BNDefineUserAnalysisType(BNBinaryView* view, BNQualifiedName* name, BNType* type);
+ BINARYNINJACOREAPI void BNUndefineAnalysisType(BNBinaryView* view, BNQualifiedName* name);
+ BINARYNINJACOREAPI void BNUndefineUserAnalysisType(BNBinaryView* view, BNQualifiedName* name);
BINARYNINJACOREAPI void BNReanalyzeAllFunctions(BNBinaryView* view);
BINARYNINJACOREAPI void BNReanalyzeFunction(BNFunction* func);
@@ -1969,7 +1974,7 @@ extern "C"
BNNameAndType* params, size_t paramCount, bool varArg);
BINARYNINJACOREAPI BNType* BNNewTypeReference(BNType* type);
BINARYNINJACOREAPI BNType* BNDuplicateType(BNType* type);
- BINARYNINJACOREAPI char* BNGetTypeAndName(BNType* type, const char** nameList, size_t nameCount);
+ BINARYNINJACOREAPI char* BNGetTypeAndName(BNType* type, BNQualifiedName* name);
BINARYNINJACOREAPI void BNFreeType(BNType* type);
BINARYNINJACOREAPI BNTypeClass BNGetTypeClass(BNType* type);
@@ -2000,12 +2005,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(const char** name, size_t nameCount, BNType* type);
+ BINARYNINJACOREAPI BNType* BNCreateNamedTypeReferenceFromType(BNQualifiedName* name, BNType* type);
BINARYNINJACOREAPI BNNamedTypeReference* BNCreateNamedType(void);
BINARYNINJACOREAPI void BNSetTypeReferenceClass(BNNamedTypeReference* nt, BNNamedTypeReferenceClass cls);
BINARYNINJACOREAPI BNNamedTypeReferenceClass BNGetTypeReferenceClass(BNNamedTypeReference* nt);
- BINARYNINJACOREAPI void BNSetTypeReferenceName(BNNamedTypeReference* nt, const char** name, size_t size);
- BINARYNINJACOREAPI char** BNGetTypeReferenceName(BNNamedTypeReference* nt, size_t* size);
+ BINARYNINJACOREAPI void BNSetTypeReferenceName(BNNamedTypeReference* nt, BNQualifiedName* name);
+ BINARYNINJACOREAPI BNQualifiedName BNGetTypeReferenceName(BNNamedTypeReference* nt);
+ BINARYNINJACOREAPI void BNFreeQualifiedName(BNQualifiedName* name);
BINARYNINJACOREAPI void BNFreeNamedTypeReference(BNNamedTypeReference* nt);
BINARYNINJACOREAPI BNNamedTypeReference* BNNewNamedTypeReference(BNNamedTypeReference* nt);
diff --git a/binaryview.cpp b/binaryview.cpp
index 8394fc57..bef23750 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -129,29 +129,21 @@ void BinaryDataNotification::StringRemovedCallback(void* ctxt, BNBinaryView* obj
}
-void BinaryDataNotification::TypeDefinedCallback(void* ctxt, BNBinaryView* data, const char** name, size_t nameCount,
- BNType* type)
+void BinaryDataNotification::TypeDefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type)
{
BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
Ref<Type> typeObj = new Type(BNNewTypeReference(type));
- QualifiedName nameList;
- for (size_t i = 0; i < nameCount; i++)
- nameList.push_back(name[i]);
- notify->OnTypeDefined(view, nameList, typeObj);
+ notify->OnTypeDefined(view, QualifiedName::FromAPIObject(name), typeObj);
}
-void BinaryDataNotification::TypeUndefinedCallback(void* ctxt, BNBinaryView* data, const char** name, size_t nameCount,
- BNType* type)
+void BinaryDataNotification::TypeUndefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type)
{
BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
Ref<Type> typeObj = new Type(BNNewTypeReference(type));
- QualifiedName nameList;
- for (size_t i = 0; i < nameCount; i++)
- nameList.push_back(name[i]);
- notify->OnTypeUndefined(view, nameList, typeObj);
+ notify->OnTypeUndefined(view, QualifiedName::FromAPIObject(name), typeObj);
}
@@ -1467,8 +1459,7 @@ bool BinaryView::ParseTypeString(const string& text, QualifiedNameAndType& resul
return false;
}
- for (size_t i = 0; i < nt.nameCount; i++)
- result.name.push_back(nt.name[i]);
+ result.name = QualifiedName::FromAPIObject(&nt.name);
result.type = new Type(BNNewTypeReference(nt.type));
errors = "";
BNFreeQualifiedNameAndType(&nt);
@@ -1484,9 +1475,7 @@ map<QualifiedName, Ref<Type>> BinaryView::GetTypes()
map<QualifiedName, Ref<Type>> result;
for (size_t i = 0; i < count; i++)
{
- QualifiedName name;
- for (size_t j = 0; j < types[i].nameCount; j++)
- name.push_back(types[i].name[j]);
+ QualifiedName name = QualifiedName::FromAPIObject(&types[i].name);
result[name] = new Type(BNNewTypeReference(types[i].type));
}
@@ -1497,12 +1486,9 @@ map<QualifiedName, Ref<Type>> BinaryView::GetTypes()
Ref<Type> BinaryView::GetTypeByName(const QualifiedName& name)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
-
- BNType* type = BNGetAnalysisTypeByName(m_object, nameList, name.size());
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ BNType* type = BNGetAnalysisTypeByName(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
if (!type)
return nullptr;
@@ -1512,52 +1498,42 @@ Ref<Type> BinaryView::GetTypeByName(const QualifiedName& name)
bool BinaryView::IsTypeAutoDefined(const QualifiedName& name)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
- bool result = BNIsAnalysisTypeAutoDefined(m_object, nameList, name.size());
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ bool result = BNIsAnalysisTypeAutoDefined(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
return result;
}
void BinaryView::DefineType(const QualifiedName& name, Ref<Type> type)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
- BNDefineAnalysisType(m_object, nameList, name.size(), type->GetObject());
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ BNDefineAnalysisType(m_object, &nameObj, type->GetObject());
+ QualifiedName::FreeAPIObject(&nameObj);
}
void BinaryView::DefineUserType(const QualifiedName& name, Ref<Type> type)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
- BNDefineUserAnalysisType(m_object, nameList, name.size(), type->GetObject());
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ BNDefineUserAnalysisType(m_object, &nameObj, type->GetObject());
+ QualifiedName::FreeAPIObject(&nameObj);
}
void BinaryView::UndefineType(const QualifiedName& name)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
- BNUndefineAnalysisType(m_object, nameList, name.size());
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ BNUndefineAnalysisType(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
}
void BinaryView::UndefineUserType(const QualifiedName& name)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
- BNUndefineUserAnalysisType(m_object, nameList, name.size());
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ BNUndefineUserAnalysisType(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
}
diff --git a/python/__init__.py b/python/__init__.py
index b5ced583..c2db468d 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -664,6 +664,8 @@ class QualifiedName(object):
def __init__(self, name = []):
if isinstance(name, str):
self.name = [name]
+ elif isinstance(name, QualifiedName):
+ self.name = name.name
else:
self.name = name
@@ -724,6 +726,22 @@ class QualifiedName(object):
def __iter__(self):
return iter(self.name)
+ def _get_core_struct(self):
+ result = core.BNQualifiedName()
+ name_list = (ctypes.c_char_p * len(self.name))()
+ for i in xrange(0, len(self.name)):
+ name_list[i] = self.name[i]
+ result.name = name_list
+ result.nameCount = len(self.name)
+ return result
+
+ @classmethod
+ def _from_core_struct(cls, name):
+ result = []
+ for i in xrange(0, name.nameCount):
+ result.append(name.name[i])
+ return QualifiedName(result)
+
class BinaryDataNotificationCallbacks(object):
def __init__(self, view, notify):
self.view = view
@@ -825,21 +843,17 @@ class BinaryDataNotificationCallbacks(object):
except:
log_error(traceback.format_exc())
- def _type_defined(self, ctxt, name, name_count, type_obj):
+ def _type_defined(self, ctxt, name, type_obj):
try:
- name_list = []
- for i in xrange(0, name_count):
- name_list.append(name[i])
- self.notify.type_defined(self.view, QualifiedName(name_list), Type(core.BNNewTypeReference(type_obj)))
+ qualified_name = QualifiedName._from_core_struct(name[0])
+ self.notify.type_defined(self.view, qualified_name, Type(core.BNNewTypeReference(type_obj)))
except:
log_error(traceback.format_exc())
- def _type_undefined(self, ctxt, name, name_count, type_obj):
+ def _type_undefined(self, ctxt, name, type_obj):
try:
- name_list = []
- for i in xrange(0, name_count):
- name_list.append(name[i])
- self.notify.type_undefined(self.view, QualifiedName(name_list), Type(core.BNNewTypeReference(type_obj)))
+ qualified_name = QualifiedName._from_core_struct(name[0])
+ self.notify.type_undefined(self.view, qualified_name, Type(core.BNNewTypeReference(type_obj)))
except:
log_error(traceback.format_exc())
@@ -1464,10 +1478,8 @@ class BinaryView(object):
type_list = core.BNGetAnalysisTypeList(self.handle, count)
result = {}
for i in xrange(0, count.value):
- name = []
- for j in xrange(0, type_list[i].nameCount):
- name.append(type_list[i].name[j])
- result[QualifiedName(name)] = Type(core.BNNewTypeReference(type_list[i].type))
+ name = QualifiedName._from_core_struct(type_list[i].name)
+ result[name] = Type(core.BNNewTypeReference(type_list[i].type))
core.BNFreeTypeList(type_list, count.value)
return result
@@ -3438,10 +3450,7 @@ class BinaryView(object):
core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte)))
raise SyntaxError, error_str
type_obj = Type(core.BNNewTypeReference(result.type))
- name = []
- for i in xrange(0, result.nameCount):
- name.append(result.name[i])
- name = QualifiedName(name)
+ name = QualifiedName._from_core_struct(result.name)
core.BNFreeQualifiedNameAndType(result)
return type_obj, name
@@ -3460,12 +3469,8 @@ class BinaryView(object):
<type: int32_t>
>>>
"""
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- obj = core.BNGetAnalysisTypeByName(self.handle, name_list, len(name))
+ name = QualifiedName(name)._get_core_struct()
+ obj = core.BNGetAnalysisTypeByName(self.handle, name)
if not obj:
return None
return Type(obj)
@@ -3485,12 +3490,8 @@ class BinaryView(object):
False
>>>
"""
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- return core.BNIsAnalysisTypeAutoDefined(self.handle, name_list, len(name))
+ name = QualifiedName(name)._get_core_struct()
+ return core.BNIsAnalysisTypeAutoDefined(self.handle, name)
def define_type(self, name, type_obj):
"""
@@ -3507,12 +3508,8 @@ class BinaryView(object):
>>> bv.get_type_by_name(name)
<type: int32_t>
"""
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- core.BNDefineAnalysisType(self.handle, name_list, len(name), type_obj.handle)
+ name = QualifiedName(name)._get_core_struct()
+ core.BNDefineAnalysisType(self.handle, name, type_obj.handle)
def define_user_type(self, name, type_obj):
"""
@@ -3529,12 +3526,8 @@ class BinaryView(object):
>>> bv.get_type_by_name(name)
<type: int32_t>
"""
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- core.BNDefineUserAnalysisType(self.handle, name_list, len(name), type_obj.handle)
+ name = QualifiedName(name)._get_core_struct()
+ core.BNDefineUserAnalysisType(self.handle, name, type_obj.handle)
def undefine_type(self, name):
"""
@@ -3552,12 +3545,8 @@ class BinaryView(object):
>>> bv.get_type_by_name(name)
>>>
"""
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- core.BNUndefineAnalysisType(self.handle, name_list, len(name))
+ name = QualifiedName(name)._get_core_struct()
+ core.BNUndefineAnalysisType(self.handle, name)
def undefine_user_type(self, name):
"""
@@ -3576,12 +3565,8 @@ class BinaryView(object):
>>> bv.get_type_by_name(name)
>>>
"""
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- core.BNUndefineUserAnalysisType(self.handle, name_list, len(name))
+ name = QualifiedName(name)._get_core_struct()
+ core.BNUndefineUserAnalysisType(self.handle, name)
def find_next_data(self, start, data, flags = 0):
"""
@@ -4470,14 +4455,10 @@ class Type(object):
@classmethod
def named_type_from_type(self, name, t):
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
+ name = QualifiedName(name)._get_core_struct()
if t is not None:
t = t.handle
- return Type(core.BNCreateNamedTypeReferenceFromType(name_list, len(name), t))
+ return Type(core.BNCreateNamedTypeReferenceFromType(name, t))
@classmethod
def enumeration_type(self, arch, e, width = None):
@@ -4521,12 +4502,8 @@ class NamedTypeReference(object):
self.handle = core.BNCreateNamedType()
core.BNSetTypeReferenceClass(self.handle, type_class)
if name is not None:
- if isinstance(name, str):
- name = [name]
- name_list = (ctypes.c_char_p * len(name))()
- for i in xrange(0, len(name)):
- name_list[i] = name[i]
- core.BNSetTypeReferenceName(self.handle, name_list, len(name))
+ name = QualifiedName(name)._get_core_struct()
+ core.BNSetTypeReferenceName(self.handle, name)
else:
self.handle = handle
@@ -4544,20 +4521,15 @@ class NamedTypeReference(object):
@property
def name(self):
count = ctypes.c_ulonglong()
- nameList = core.BNGetTypeReferenceName(self.handle, count)
- result = []
- for i in xrange(count.value):
- result.append(nameList[i])
- return QualifiedName(result)
+ name = core.BNGetTypeReferenceName(self.handle, count)
+ result = QualifiedName._from_core_struct(name)
+ core.BNFreeQualifiedName(name)
+ return result
@name.setter
def name(self, value):
- if isinstance(value, str):
- value = [value]
- name_list = (ctypes.c_char_p * len(value))()
- for i in xrange(0, len(value)):
- name_list[i] = value[i]
- core.BNSetTypeReferenceName(self.handle, name_list, len(value))
+ value = QualifiedName(value)._get_core_struct()
+ core.BNSetTypeReferenceName(self.handle, value)
def __repr__(self):
if self.type_class == core.TypedefNamedTypeClass:
@@ -4646,8 +4618,6 @@ class Structure(object):
raise AttributeError, "attribute '%s' is read only" % name
def __repr__(self):
- if len(self.name) > 0:
- return "<struct: %s>" % self.name
return "<struct: size %#x>" % self.width
def append(self, t, name = ""):
@@ -4696,8 +4666,6 @@ class Enumeration(object):
raise AttributeError, "attribute '%s' is read only" % name
def __repr__(self):
- if len(self.name) > 0:
- return "<enum: %s>" % self.name
return "<enum: %s>" % repr(self.members)
def append(self, name, value = None):
@@ -7581,20 +7549,14 @@ class Architecture(object):
variables = {}
functions = {}
for i in xrange(0, parse.typeCount):
- name = []
- for j in xrange(0, parse.types[i].nameCount):
- name.append(parse.types[i].name[j])
- types[QualifiedName(name)] = Type(core.BNNewTypeReference(parse.types[i].type))
+ name = QualifiedName._from_core_struct(parse.types[i].name)
+ types[name] = Type(core.BNNewTypeReference(parse.types[i].type))
for i in xrange(0, parse.variableCount):
- name = []
- for j in xrange(0, parse.variables[i].nameCount):
- name.append(parse.variables[i].name[j])
- variables[QualifiedName(name)] = Type(core.BNNewTypeReference(parse.variables[i].type))
+ name = QualifiedName._from_core_struct(parse.variables[i].name)
+ variables[name] = Type(core.BNNewTypeReference(parse.variables[i].type))
for i in xrange(0, parse.functionCount):
- name = []
- for j in xrange(0, parse.functions[i].nameCount):
- name.append(parse.functions[i].name[j])
- functions[QualifiedName(name)] = Type(core.BNNewTypeReference(parse.functions[i].type))
+ name = QualifiedName._from_core_struct(parse.functions[i].name)
+ functions[name] = Type(core.BNNewTypeReference(parse.functions[i].type))
core.BNFreeTypeParserResult(parse)
return TypeParserResult(types, variables, functions)
@@ -7631,20 +7593,14 @@ class Architecture(object):
variables = {}
functions = {}
for i in xrange(0, parse.typeCount):
- name = []
- for j in xrange(0, parse.types[i].nameCount):
- name.append(parse.types[i].name[j])
- types[QualifiedName(name)] = Type(core.BNNewTypeReference(parse.types[i].type))
+ name = QualifiedName._from_core_struct(parse.types[i].name)
+ types[name] = Type(core.BNNewTypeReference(parse.types[i].type))
for i in xrange(0, parse.variableCount):
- name = []
- for j in xrange(0, parse.variables[i].nameCount):
- name.append(parse.variables[i].name[j])
- variables[QualifiedName(name)] = Type(core.BNNewTypeReference(parse.variables[i].type))
+ name = QualifiedName._from_core_struct(parse.variables[i].name)
+ variables[name] = Type(core.BNNewTypeReference(parse.variables[i].type))
for i in xrange(0, parse.functionCount):
- name = []
- for j in xrange(0, parse.functions[i].nameCount):
- name.append(parse.functions[i].name[j])
- functions[QualifiedName(name)] = Type(core.BNNewTypeReference(parse.functions[i].type))
+ name = QualifiedName._from_core_struct(parse.functions[i].name)
+ functions[name] = Type(core.BNNewTypeReference(parse.functions[i].type))
core.BNFreeTypeParserResult(parse)
return TypeParserResult(types, variables, functions)
diff --git a/type.cpp b/type.cpp
index ae8f04d3..e71077e6 100644
--- a/type.cpp
+++ b/type.cpp
@@ -209,6 +209,34 @@ string QualifiedName::GetString() const
}
+BNQualifiedName QualifiedName::GetAPIObject() const
+{
+ BNQualifiedName result;
+ result.nameCount = m_name.size();
+ result.name = new char*[m_name.size()];
+ for (size_t i = 0; i < m_name.size(); i++)
+ result.name[i] = BNAllocString(m_name[i].c_str());
+ return result;
+}
+
+
+void QualifiedName::FreeAPIObject(BNQualifiedName* name)
+{
+ for (size_t i = 0; i < name->nameCount; i++)
+ BNFreeString(name->name[i]);
+ delete[] name->name;
+}
+
+
+QualifiedName QualifiedName::FromAPIObject(BNQualifiedName* name)
+{
+ QualifiedName result;
+ for (size_t i = 0; i < name->nameCount; i++)
+ result.push_back(name->name[i]);
+ return result;
+}
+
+
Type::Type(BNType* type)
{
m_object = type;
@@ -344,13 +372,9 @@ string Type::GetString() const
string Type::GetTypeAndName(const QualifiedName& nameList) const
{
- const char ** str = new const char*[nameList.size()];
- for (size_t i = 0; i < nameList.size(); i++)
- {
- str[i] = nameList[i].c_str();
- }
- char* outName = BNGetTypeAndName(m_object, str, nameList.size());
- delete [] str;
+ BNQualifiedName name = nameList.GetAPIObject();
+ char* outName = BNGetTypeAndName(m_object, &name);
+ QualifiedName::FreeAPIObject(&name);
return outName;
}
@@ -488,12 +512,9 @@ Ref<Type> Type::NamedType(NamedTypeReference* ref, size_t width, size_t align)
Ref<Type> Type::NamedType(const QualifiedName& name, Type* type)
{
- const char** nameList = new const char*[name.size()];
- for (size_t i = 0; i < name.size(); i++)
- nameList[i] = name[i].c_str();
- Type* result = new Type(BNCreateNamedTypeReferenceFromType(nameList, name.size(),
- type ? type->GetObject() : nullptr));
- delete[] nameList;
+ BNQualifiedName nameObj = name.GetAPIObject();
+ Type* result = new Type(BNCreateNamedTypeReferenceFromType(&nameObj, type ? type->GetObject() : nullptr));
+ QualifiedName::FreeAPIObject(&nameObj);
return result;
}
@@ -550,13 +571,12 @@ NamedTypeReference::NamedTypeReference(BNNamedTypeReferenceClass cls, const Qual
{
m_object = BNCreateNamedType();
BNSetTypeReferenceClass(m_object, cls);
- const char ** nameList = new const char*[names.size()];
- for (size_t i = 0; i < names.size(); i++)
+ if (names.size() != 0)
{
- nameList[i] = names[i].c_str();
+ BNQualifiedName nameObj = names.GetAPIObject();
+ BNSetTypeReferenceName(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
}
- BNSetTypeReferenceName(m_object, nameList, names.size());
- delete [] nameList;
}
@@ -574,27 +594,17 @@ BNNamedTypeReferenceClass NamedTypeReference::GetTypeClass() const
void NamedTypeReference::SetName(const QualifiedName& names)
{
- const char ** nameList = new const char*[names.size()];
- for (size_t i = 0; i < names.size(); i++)
- {
- nameList[i] = names[i].c_str();
- }
- BNSetTypeReferenceName(m_object, nameList, names.size());
- delete [] nameList;
+ BNQualifiedName nameObj = names.GetAPIObject();
+ BNSetTypeReferenceName(m_object, &nameObj);
+ QualifiedName::FreeAPIObject(&nameObj);
}
QualifiedName NamedTypeReference::GetName() const
{
- size_t size;
- char** name = BNGetTypeReferenceName(m_object, &size);
- QualifiedName result;
- for (size_t i = 0; i < size; i++)
- {
- result.push_back(name[i]);
- BNFreeString(name[i]);
- }
- delete [] name;
+ BNQualifiedName name = BNGetTypeReferenceName(m_object);
+ QualifiedName result = QualifiedName::FromAPIObject(&name);
+ BNFreeQualifiedName(&name);
return result;
}