From 09a68bdd84d4789626f5c8b8631f61e7a41ca03d Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 11 Jan 2017 15:42:08 -0500 Subject: Use named type references for registered types, use qualified names for types --- python/generator.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'python/generator.cpp') diff --git a/python/generator.cpp b/python/generator.cpp index 08485315..4c313fdd 100644 --- a/python/generator.cpp +++ b/python/generator.cpp @@ -97,11 +97,8 @@ void OutputType(FILE* out, Type* type, bool isReturnType = false, bool isCallbac else fprintf(out, "ctypes.c_double"); break; - case StructureTypeClass: - fprintf(out, "%s", type->GetQualifiedName(type->GetStructure()->GetName()).c_str()); - break; - case EnumerationTypeClass: - fprintf(out, "%s", type->GetQualifiedName(type->GetEnumeration()->GetName()).c_str()); + case NamedTypeReferenceClass: + fprintf(out, "%s", type->GetQualifiedName(type->GetNamedTypeReference()->GetName()).c_str()); break; case PointerTypeClass: if (isCallback || (type->GetChildType()->GetClass() == VoidTypeClass)) @@ -156,7 +153,7 @@ int main(int argc, char* argv[]) Architecture::Register(new GeneratorArchitecture()); // Parse API header to get type and function information - map> types, vars, funcs; + map, Ref> types, vars, funcs; string errors; bool ok = Architecture::GetByName("generator")->ParseTypesFromSourceFile(argv[1], types, vars, funcs, errors); fprintf(stderr, "%s", errors.c_str()); @@ -187,21 +184,25 @@ int main(int argc, char* argv[]) map enumMembers; for (auto& i : types) { + string name; + if (i.first.size() != 1) + continue; + name = i.first[0]; if (i.second->GetClass() == StructureTypeClass) { - fprintf(out, "class %s(ctypes.Structure):\n", i.first.c_str()); + fprintf(out, "class %s(ctypes.Structure):\n", name.c_str()); fprintf(out, " pass\n"); } else if (i.second->GetClass() == EnumerationTypeClass) { - fprintf(out, "%s = ctypes.c_int\n", i.first.c_str()); + fprintf(out, "%s = ctypes.c_int\n", name.c_str()); for (auto& j : i.second->GetEnumeration()->GetMembers()) fprintf(out, "%s = %" PRId64 "\n", j.name.c_str(), j.value); - fprintf(out, "%s_names = {\n", i.first.c_str()); + fprintf(out, "%s_names = {\n", name.c_str()); for (auto& j : i.second->GetEnumeration()->GetMembers()) fprintf(out, " %" PRId64 ": \"%s\",\n", j.value, j.name.c_str()); fprintf(out, "}\n"); - fprintf(out, "%s_by_name = {\n", i.first.c_str()); + fprintf(out, "%s_by_name = {\n", name.c_str()); for (auto& j : i.second->GetEnumeration()->GetMembers()) fprintf(out, " \"%s\": %" PRId64 ",\n", j.name.c_str(), j.value); fprintf(out, "}\n"); @@ -211,7 +212,7 @@ int main(int argc, char* argv[]) else if ((i.second->GetClass() == BoolTypeClass) || (i.second->GetClass() == IntegerTypeClass) || (i.second->GetClass() == FloatTypeClass) || (i.second->GetClass() == ArrayTypeClass)) { - fprintf(out, "%s = ", i.first.c_str()); + fprintf(out, "%s = ", name.c_str()); OutputType(out, i.second); fprintf(out, "\n"); } @@ -225,9 +226,13 @@ int main(int argc, char* argv[]) fprintf(out, "\n# Structure definitions\n"); for (auto& i : types) { + string name; + if (i.first.size() != 1) + continue; + name = i.first[0]; if ((i.second->GetClass() == StructureTypeClass) && (i.second->GetStructure()->GetMembers().size() != 0)) { - fprintf(out, "%s._fields_ = [\n", i.first.c_str()); + fprintf(out, "%s._fields_ = [\n", name.c_str()); for (auto& j : i.second->GetStructure()->GetMembers()) { fprintf(out, " (\"%s\", ", j.name.c_str()); @@ -241,6 +246,11 @@ int main(int argc, char* argv[]) fprintf(out, "\n# Function definitions\n"); for (auto& i : funcs) { + string name; + if (i.first.size() != 1) + continue; + name = i.first[0]; + // Check for a string result, these will be automatically wrapped to free the string // memory and return a Python string bool stringResult = (i.second->GetChildType()->GetClass() == PointerTypeClass) && @@ -249,7 +259,7 @@ int main(int argc, char* argv[]) // Pointer returns will be automatically wrapped to return None on null pointer bool pointerResult = (i.second->GetChildType()->GetClass() == PointerTypeClass); bool callbackConvention = false; - if (i.first == "BNAllocString") + if (name == "BNAllocString") { // Don't perform automatic wrapping of string allocation, and return a void // pointer so that callback functions (which is the only valid use of BNAllocString) @@ -258,11 +268,11 @@ int main(int argc, char* argv[]) callbackConvention = true; } - string funcName = i.first; + string funcName = name; if (stringResult || pointerResult) funcName = string("_") + funcName; - fprintf(out, "%s = core.%s\n", funcName.c_str(), i.first.c_str()); + fprintf(out, "%s = core.%s\n", funcName.c_str(), name.c_str()); fprintf(out, "%s.restype = ", funcName.c_str()); OutputType(out, i.second->GetChildType(), true, callbackConvention); fprintf(out, "\n"); @@ -272,7 +282,7 @@ int main(int argc, char* argv[]) for (auto& j : i.second->GetParameters()) { fprintf(out, " "); - if (i.first == "BNFreeString") + if (name == "BNFreeString") { // BNFreeString expects a pointer to a string allocated by the core, so do not use // a c_char_p here, as that would be allocated by the Python runtime. This can @@ -291,7 +301,7 @@ int main(int argc, char* argv[]) if (stringResult) { // Emit wrapper to get Python string and free native memory - fprintf(out, "def %s(*args):\n", i.first.c_str()); + fprintf(out, "def %s(*args):\n", name.c_str()); fprintf(out, " result = %s(*args)\n", funcName.c_str()); fprintf(out, " string = ctypes.cast(result, ctypes.c_char_p).value\n"); fprintf(out, " BNFreeString(result)\n"); @@ -300,7 +310,7 @@ int main(int argc, char* argv[]) else if (pointerResult) { // Emit wrapper to return None on null pointer - fprintf(out, "def %s(*args):\n", i.first.c_str()); + fprintf(out, "def %s(*args):\n", name.c_str()); fprintf(out, " result = %s(*args)\n", funcName.c_str()); fprintf(out, " if not result:\n"); fprintf(out, " return None\n"); -- cgit v1.3.1 From 844e1aa5b4f89de2ffc1990824b094c553068642 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 11 Jan 2017 21:18:08 -0500 Subject: Create qualified name object --- architecture.cpp | 20 ++--- binaryninjaapi.h | 95 +++++++++++++++------- binaryview.cpp | 67 +++------------- demangle.cpp | 4 +- python/generator.cpp | 4 +- type.cpp | 218 ++++++++++++++++++++++++++++++++++++++++++++------- 6 files changed, 281 insertions(+), 127 deletions(-) (limited to 'python/generator.cpp') diff --git a/architecture.cpp b/architecture.cpp index d0d87df4..657d7bf0 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -746,8 +746,8 @@ void Architecture::SetBinaryViewTypeConstant(const string& type, const string& n bool Architecture::ParseTypesFromSource(const string& source, const string& fileName, - map, Ref>& types, map, Ref>& variables, - map, Ref>& functions, string& errors, const vector& includeDirs) + map>& types, map>& variables, + map>& functions, string& errors, const vector& includeDirs) { BNTypeParserResult result; char* errorStr; @@ -769,21 +769,21 @@ bool Architecture::ParseTypesFromSource(const string& source, const string& file for (size_t i = 0; i < result.typeCount; i++) { - vector name; + QualifiedName name; for (size_t j = 0; j < result.types[i].nameCount; j++) name.push_back(result.types[i].name[j]); types[name] = new Type(BNNewTypeReference(result.types[i].type)); } for (size_t i = 0; i < result.variableCount; i++) { - vector name; + QualifiedName name; for (size_t j = 0; j < result.variables[i].nameCount; j++) name.push_back(result.variables[i].name[j]); types[name] = new Type(BNNewTypeReference(result.variables[i].type)); } for (size_t i = 0; i < result.functionCount; i++) { - vector name; + QualifiedName name; for (size_t j = 0; j < result.functions[i].nameCount; j++) name.push_back(result.functions[i].name[j]); types[name] = new Type(BNNewTypeReference(result.functions[i].type)); @@ -793,8 +793,8 @@ bool Architecture::ParseTypesFromSource(const string& source, const string& file } -bool Architecture::ParseTypesFromSourceFile(const string& fileName, map, Ref>& types, - map, Ref>& variables, map, Ref>& functions, +bool Architecture::ParseTypesFromSourceFile(const string& fileName, map>& types, + map>& variables, map>& functions, string& errors, const vector& includeDirs) { BNTypeParserResult result; @@ -817,21 +817,21 @@ bool Architecture::ParseTypesFromSourceFile(const string& fileName, map name; + QualifiedName name; for (size_t j = 0; j < result.types[i].nameCount; j++) name.push_back(result.types[i].name[j]); types[name] = new Type(BNNewTypeReference(result.types[i].type)); } for (size_t i = 0; i < result.variableCount; i++) { - vector name; + QualifiedName name; for (size_t j = 0; j < result.variables[i].nameCount; j++) name.push_back(result.variables[i].name[j]); variables[name] = new Type(BNNewTypeReference(result.variables[i].type)); } for (size_t i = 0; i < result.functionCount; i++) { - vector name; + QualifiedName name; for (size_t j = 0; j < result.functions[i].nameCount; j++) name.push_back(result.functions[i].name[j]); functions[name] = new Type(BNNewTypeReference(result.functions[i].type)); diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 15c86a58..478cc090 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -277,6 +277,7 @@ namespace BinaryNinja class MainThreadAction; class MainThreadActionHandler; class InteractionHandler; + class QualifiedName; struct FormInputField; /*! Logs to the error console with the given BNLogLevel. @@ -368,7 +369,7 @@ namespace BinaryNinja bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType, - std::vector& outVarName); + QualifiedName& outVarName); void RegisterMainThread(MainThreadActionHandler* handler); Ref ExecuteOnMainThread(const std::function& action); @@ -408,6 +409,47 @@ namespace BinaryNinja BNMessageBoxButtonResult ShowMessageBox(const std::string& title, const std::string& text, BNMessageBoxButtonSet buttons = OKButtonSet, BNMessageBoxIcon icon = InformationIcon); + class QualifiedName + { + std::vector m_name; + + public: + QualifiedName(); + QualifiedName(const std::string& name); + QualifiedName(const std::vector& name); + QualifiedName(const QualifiedName& name); + + QualifiedName& operator=(const std::string& name); + QualifiedName& operator=(const std::vector& name); + QualifiedName& operator=(const QualifiedName& name); + + bool operator==(const QualifiedName& other) const; + bool operator!=(const QualifiedName& other) const; + bool operator<(const QualifiedName& other) const; + + QualifiedName operator+(const QualifiedName& other) const; + + std::string& operator[](size_t i); + const std::string& operator[](size_t i) const; + std::vector::iterator begin(); + std::vector::iterator end(); + std::vector::const_iterator begin() const; + std::vector::const_iterator end() const; + std::string& front(); + const std::string& front() const; + std::string& back(); + const std::string& back() const; + void insert(std::vector::iterator loc, const std::string& name); + void insert(std::vector::iterator loc, std::vector::iterator b, + std::vector::iterator e); + void erase(std::vector::iterator i); + void clear(); + void push_back(const std::string& name); + size_t size() const; + + std::string GetString() const; + }; + class DataBuffer { BNDataBuffer* m_buffer; @@ -610,8 +652,8 @@ namespace BinaryNinja virtual void OnDataVariableUpdated(BinaryView* view, const DataVariable& var) { (void)view; (void)var; } virtual void OnStringFound(BinaryView* data, BNStringType type, uint64_t offset, size_t len) { (void)data; (void)type; (void)offset; (void)len; } virtual void OnStringRemoved(BinaryView* data, BNStringType type, uint64_t offset, size_t len) { (void)data; (void)type; (void)offset; (void)len; } - virtual void OnTypeDefined(BinaryView* data, const std::vector& name, Type* type) { (void)data; (void)name; (void)type; } - virtual void OnTypeUndefined(BinaryView* data, const std::vector& name, Type* type) { (void)data; (void)name; (void)type; } + virtual void OnTypeDefined(BinaryView* data, const QualifiedName& name, Type* type) { (void)data; (void)name; (void)type; } + virtual void OnTypeUndefined(BinaryView* data, const QualifiedName& name, Type* type) { (void)data; (void)name; (void)type; } }; class FileAccessor @@ -979,19 +1021,13 @@ namespace BinaryNinja bool ParseTypeString(const std::string& text, QualifiedNameAndType& result, std::string& errors); - std::map, Ref> GetTypes(); - Ref GetTypeByName(const std::string& name); - Ref GetTypeByName(const std::vector& name); - bool IsTypeAutoDefined(const std::string& name); - bool IsTypeAutoDefined(const std::vector& name); - void DefineType(const std::string& name, Ref type); - void DefineType(const std::vector& name, Ref type); - void DefineUserType(const std::string& name, Ref type); - void DefineUserType(const std::vector& name, Ref type); - void UndefineType(const std::string& name); - void UndefineType(const std::vector& name); - void UndefineUserType(const std::string& name); - void UndefineUserType(const std::vector& name); + std::map> GetTypes(); + Ref GetTypeByName(const QualifiedName& name); + bool IsTypeAutoDefined(const QualifiedName& name); + void DefineType(const QualifiedName& name, Ref type); + void DefineUserType(const QualifiedName& name, Ref type); + void UndefineType(const QualifiedName& name); + void UndefineUserType(const QualifiedName& name); bool FindNextData(uint64_t start, const DataBuffer& data, uint64_t& result, BNFindFlag flags = NoFindFlags); @@ -1441,14 +1477,14 @@ namespace BinaryNinja void SetBinaryViewTypeConstant(const std::string& type, const std::string& name, uint64_t value); bool ParseTypesFromSource(const std::string& source, const std::string& fileName, - std::map, Ref>& types, - std::map, Ref>& variables, - std::map, Ref>& functions, std::string& errors, + std::map>& types, + std::map>& variables, + std::map>& functions, std::string& errors, const std::vector& includeDirs = std::vector()); bool ParseTypesFromSourceFile(const std::string& fileName, - std::map, Ref>& types, - std::map, Ref>& variables, - std::map, Ref>& functions, std::string& errors, + std::map>& types, + std::map>& variables, + std::map>& functions, std::string& errors, const std::vector& includeDirs = std::vector()); void RegisterCallingConvention(CallingConvention* cc); @@ -1523,7 +1559,7 @@ namespace BinaryNinja struct QualifiedNameAndType { - std::vector name; + QualifiedName name; Ref type; }; @@ -1553,7 +1589,7 @@ namespace BinaryNinja void SetFunctionCanReturn(bool canReturn); std::string GetString() const; - std::string GetTypeAndName(const std::vector& name) const; + std::string GetTypeAndName(const QualifiedName& name) const; std::string GetStringBeforeName() const; std::string GetStringAfterName() const; @@ -1569,15 +1605,13 @@ namespace BinaryNinja static Ref FloatType(size_t width, const std::string& typeName = ""); static Ref StructureType(Structure* strct); static Ref NamedType(NamedTypeReference* ref, size_t width = 0, size_t align = 1); - static Ref NamedType(const std::vector& name, Type* type); + static Ref NamedType(const QualifiedName& name, Type* type); static Ref EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, bool issigned = false); static Ref PointerType(Architecture* arch, Type* type, bool cnst = false, bool vltl = false, BNReferenceType refType = PointerReferenceType); static Ref ArrayType(Type* type, uint64_t elem); static Ref FunctionType(Type* returnValue, CallingConvention* callingConvention, const std::vector& params, bool varArg = false); - - static std::string GetQualifiedName(const std::vector& names); }; class NamedTypeReference: public CoreRefCountObject& name = {}); + NamedTypeReference(BNNamedTypeReferenceClass cls = UnknownNamedTypeClass, + const QualifiedName& name = QualifiedName()); BNNamedTypeReferenceClass GetTypeClass() const; void SetTypeClass(BNNamedTypeReferenceClass cls); - std::vector GetName() const; - void SetName(const std::vector& name); + QualifiedName GetName() const; + void SetName(const QualifiedName& name); }; struct StructureMember diff --git a/binaryview.cpp b/binaryview.cpp index 9fdd5748..8394fc57 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -135,7 +135,7 @@ void BinaryDataNotification::TypeDefinedCallback(void* ctxt, BNBinaryView* data, BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; Ref view = new BinaryView(BNNewViewReference(data)); Ref typeObj = new Type(BNNewTypeReference(type)); - vector nameList; + QualifiedName nameList; for (size_t i = 0; i < nameCount; i++) nameList.push_back(name[i]); notify->OnTypeDefined(view, nameList, typeObj); @@ -148,7 +148,7 @@ void BinaryDataNotification::TypeUndefinedCallback(void* ctxt, BNBinaryView* dat BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; Ref view = new BinaryView(BNNewViewReference(data)); Ref typeObj = new Type(BNNewTypeReference(type)); - vector nameList; + QualifiedName nameList; for (size_t i = 0; i < nameCount; i++) nameList.push_back(name[i]); notify->OnTypeUndefined(view, nameList, typeObj); @@ -1476,15 +1476,15 @@ bool BinaryView::ParseTypeString(const string& text, QualifiedNameAndType& resul } -map, Ref> BinaryView::GetTypes() +map> BinaryView::GetTypes() { size_t count; BNQualifiedNameAndType* types = BNGetAnalysisTypeList(m_object, &count); - map, Ref> result; + map> result; for (size_t i = 0; i < count; i++) { - vector name; + QualifiedName name; for (size_t j = 0; j < types[i].nameCount; j++) name.push_back(types[i].name[j]); result[name] = new Type(BNNewTypeReference(types[i].type)); @@ -1495,17 +1495,7 @@ map, Ref> BinaryView::GetTypes() } -Ref BinaryView::GetTypeByName(const string& name) -{ - const char* nameStr = name.c_str(); - BNType* type = BNGetAnalysisTypeByName(m_object, &nameStr, 1); - if (!type) - return nullptr; - return new Type(type); -} - - -Ref BinaryView::GetTypeByName(const vector& name) +Ref BinaryView::GetTypeByName(const QualifiedName& name) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) @@ -1520,14 +1510,7 @@ Ref BinaryView::GetTypeByName(const vector& name) } -bool BinaryView::IsTypeAutoDefined(const string& name) -{ - const char* nameStr = name.c_str(); - return BNIsAnalysisTypeAutoDefined(m_object, &nameStr, 1); -} - - -bool BinaryView::IsTypeAutoDefined(const vector& name) +bool BinaryView::IsTypeAutoDefined(const QualifiedName& name) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) @@ -1538,14 +1521,7 @@ bool BinaryView::IsTypeAutoDefined(const vector& name) } -void BinaryView::DefineType(const string& name, Ref type) -{ - const char* nameStr = name.c_str(); - BNDefineAnalysisType(m_object, &nameStr, 1, type->GetObject()); -} - - -void BinaryView::DefineType(const vector& name, Ref type) +void BinaryView::DefineType(const QualifiedName& name, Ref type) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) @@ -1555,14 +1531,7 @@ void BinaryView::DefineType(const vector& name, Ref type) } -void BinaryView::DefineUserType(const string& name, Ref type) -{ - const char* nameStr = name.c_str(); - BNDefineUserAnalysisType(m_object, &nameStr, 1, type->GetObject()); -} - - -void BinaryView::DefineUserType(const vector& name, Ref type) +void BinaryView::DefineUserType(const QualifiedName& name, Ref type) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) @@ -1572,14 +1541,7 @@ void BinaryView::DefineUserType(const vector& name, Ref type) } -void BinaryView::UndefineType(const string& name) -{ - const char* nameStr = name.c_str(); - BNUndefineAnalysisType(m_object, &nameStr, 1); -} - - -void BinaryView::UndefineType(const vector& name) +void BinaryView::UndefineType(const QualifiedName& name) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) @@ -1589,14 +1551,7 @@ void BinaryView::UndefineType(const vector& name) } -void BinaryView::UndefineUserType(const string& name) -{ - const char* nameStr = name.c_str(); - BNUndefineUserAnalysisType(m_object, &nameStr, 1); -} - - -void BinaryView::UndefineUserType(const vector& name) +void BinaryView::UndefineUserType(const QualifiedName& name) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) diff --git a/demangle.cpp b/demangle.cpp index a12303ca..70a2fe08 100644 --- a/demangle.cpp +++ b/demangle.cpp @@ -6,7 +6,7 @@ using namespace std; bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType, - std::vector& outVarName) + QualifiedName& outVarName) { BNType* localType = (*outType)->GetObject(); char** localVarName = nullptr; @@ -26,7 +26,7 @@ bool DemangleMS(Architecture* arch, bool DemangleGNU3(Architecture* arch, const std::string& mangledName, Type** outType, - std::vector& outVarName) + QualifiedName& outVarName) { BNType* localType = (*outType)->GetObject(); char** localVarName = nullptr; diff --git a/python/generator.cpp b/python/generator.cpp index 4c313fdd..485655c2 100644 --- a/python/generator.cpp +++ b/python/generator.cpp @@ -98,7 +98,7 @@ void OutputType(FILE* out, Type* type, bool isReturnType = false, bool isCallbac fprintf(out, "ctypes.c_double"); break; case NamedTypeReferenceClass: - fprintf(out, "%s", type->GetQualifiedName(type->GetNamedTypeReference()->GetName()).c_str()); + fprintf(out, "%s", type->GetNamedTypeReference()->GetName().GetString().c_str()); break; case PointerTypeClass: if (isCallback || (type->GetChildType()->GetClass() == VoidTypeClass)) @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) Architecture::Register(new GeneratorArchitecture()); // Parse API header to get type and function information - map, Ref> types, vars, funcs; + map> types, vars, funcs; string errors; bool ok = Architecture::GetByName("generator")->ParseTypesFromSourceFile(argv[1], types, vars, funcs, errors); fprintf(stderr, "%s", errors.c_str()); diff --git a/type.cpp b/type.cpp index 0571f743..ae8f04d3 100644 --- a/type.cpp +++ b/type.cpp @@ -24,6 +24,191 @@ using namespace BinaryNinja; using namespace std; +QualifiedName::QualifiedName() +{ +} + + +QualifiedName::QualifiedName(const string& name) +{ + m_name.push_back(name); +} + + +QualifiedName::QualifiedName(const vector& name): m_name(name) +{ +} + + +QualifiedName::QualifiedName(const QualifiedName& name): m_name(name.m_name) +{ +} + + +QualifiedName& QualifiedName::operator=(const string& name) +{ + m_name = vector{name}; + return *this; +} + + +QualifiedName& QualifiedName::operator=(const vector& name) +{ + m_name = name; + return *this; +} + + +QualifiedName& QualifiedName::operator=(const QualifiedName& name) +{ + m_name = name.m_name; + return *this; +} + + +bool QualifiedName::operator==(const QualifiedName& other) const +{ + return m_name == other.m_name; +} + + +bool QualifiedName::operator!=(const QualifiedName& other) const +{ + return m_name != other.m_name; +} + + +bool QualifiedName::operator<(const QualifiedName& other) const +{ + return m_name < other.m_name; +} + + +QualifiedName QualifiedName::operator+(const QualifiedName& other) const +{ + QualifiedName result(*this); + result.m_name.insert(result.m_name.end(), other.m_name.begin(), other.m_name.end()); + return result; +} + + +string& QualifiedName::operator[](size_t i) +{ + return m_name[i]; +} + + +const string& QualifiedName::operator[](size_t i) const +{ + return m_name[i]; +} + + +vector::iterator QualifiedName::begin() +{ + return m_name.begin(); +} + + +vector::iterator QualifiedName::end() +{ + return m_name.end(); +} + + +vector::const_iterator QualifiedName::begin() const +{ + return m_name.begin(); +} + + +vector::const_iterator QualifiedName::end() const +{ + return m_name.end(); +} + + +string& QualifiedName::front() +{ + return m_name.front(); +} + + +const string& QualifiedName::front() const +{ + return m_name.front(); +} + + +string& QualifiedName::back() +{ + return m_name.back(); +} + + +const string& QualifiedName::back() const +{ + return m_name.back(); +} + + +void QualifiedName::insert(vector::iterator loc, const string& name) +{ + m_name.insert(loc, name); +} + + +void QualifiedName::insert(vector::iterator loc, vector::iterator b, vector::iterator e) +{ + m_name.insert(loc, b, e); +} + + +void QualifiedName::erase(vector::iterator i) +{ + m_name.erase(i); +} + + +void QualifiedName::clear() +{ + m_name.clear(); +} + + +void QualifiedName::push_back(const string& name) +{ + m_name.push_back(name); +} + + +size_t QualifiedName::size() const +{ + return m_name.size(); +} + + +string QualifiedName::GetString() const +{ + bool first = true; + string out; + for (auto &name : m_name) + { + if (!first) + { + out += "::" + name; + } + else + { + out += name; + } + if (name.length() != 0) + first = false; + } + return out; +} + + Type::Type(BNType* type) { m_object = type; @@ -148,27 +333,6 @@ uint64_t Type::GetElementCount() const } -string Type::GetQualifiedName(const vector& names) -{ - bool first = true; - string out; - for (auto &name : names) - { - if (!first) - { - out += "::" + name; - } - else - { - out += name; - } - if (name.length() != 0) - first = false; - } - return out; -} - - string Type::GetString() const { char* str = BNGetTypeString(m_object); @@ -178,7 +342,7 @@ string Type::GetString() const } -string Type::GetTypeAndName(const vector& nameList) 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++) @@ -322,7 +486,7 @@ Ref Type::NamedType(NamedTypeReference* ref, size_t width, size_t align) } -Ref Type::NamedType(const vector& name, Type* type) +Ref Type::NamedType(const QualifiedName& name, Type* type) { const char** nameList = new const char*[name.size()]; for (size_t i = 0; i < name.size(); i++) @@ -382,7 +546,7 @@ NamedTypeReference::NamedTypeReference(BNNamedTypeReference* nt) } -NamedTypeReference::NamedTypeReference(BNNamedTypeReferenceClass cls, const vector& names) +NamedTypeReference::NamedTypeReference(BNNamedTypeReferenceClass cls, const QualifiedName& names) { m_object = BNCreateNamedType(); BNSetTypeReferenceClass(m_object, cls); @@ -408,7 +572,7 @@ BNNamedTypeReferenceClass NamedTypeReference::GetTypeClass() const } -void NamedTypeReference::SetName(const vector& names) +void NamedTypeReference::SetName(const QualifiedName& names) { const char ** nameList = new const char*[names.size()]; for (size_t i = 0; i < names.size(); i++) @@ -420,11 +584,11 @@ void NamedTypeReference::SetName(const vector& names) } -vector NamedTypeReference::GetName() const +QualifiedName NamedTypeReference::GetName() const { size_t size; char** name = BNGetTypeReferenceName(m_object, &size); - vector result; + QualifiedName result; for (size_t i = 0; i < size; i++) { result.push_back(name[i]); -- cgit v1.3.1