diff options
| author | KyleMiles <krm504@nyu.edu> | 2022-01-27 22:43:28 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2022-01-28 00:24:06 -0500 |
| commit | 6812c973c9fa9b4ad642ab81856c05f87bd6fcc4 (patch) | |
| tree | dace4156d03148bcaf02df138ab4e0d93e61bc6f /type.cpp | |
| parent | 519c9db22367f2659d1a54599fab47e6313be06e (diff) | |
Format All Files
Diffstat (limited to 'type.cpp')
| -rw-r--r-- | type.cpp | 199 |
1 files changed, 89 insertions, 110 deletions
@@ -25,37 +25,28 @@ using namespace BinaryNinja; using namespace std; -NameList::NameList(const string& join): m_join(join) -{ -} +NameList::NameList(const string& join) : m_join(join) {} -NameList::NameList(const string& name, const string& join): m_join(join) +NameList::NameList(const string& name, const string& join) : m_join(join) { if (!name.empty()) m_name.push_back(name); } -NameList::NameList(const vector<string>& name, const string& join): m_join(join), m_name(name) -{ -} +NameList::NameList(const vector<string>& name, const string& join) : m_join(join), m_name(name) {} -NameList::NameList(const NameList& name, const string& join): m_join(join), m_name(name.m_name) -{ -} +NameList::NameList(const NameList& name, const string& join) : m_join(join), m_name(name.m_name) {} -NameList::NameList(const NameList& name): m_join(name.m_join), m_name(name.m_name) -{ -} +NameList::NameList(const NameList& name) : m_join(name.m_join), m_name(name.m_name) {} -NameList::~NameList() -{} +NameList::~NameList() {} NameList& NameList::operator=(const string& name) { - m_name = vector<string>{name}; + m_name = vector<string> {name}; return *this; } @@ -215,7 +206,7 @@ string NameList::GetString() const { bool first = true; string out; - for (auto &name : m_name) + for (auto& name : m_name) { if (!first) { @@ -262,34 +253,24 @@ NameList NameList::FromAPIObject(BNNameList* name) } +QualifiedName::QualifiedName() : NameList("::") {} -QualifiedName::QualifiedName(): NameList("::") -{ -} +QualifiedName::QualifiedName(const string& name) : NameList(name, "::") {} -QualifiedName::QualifiedName(const string& name): NameList(name, "::") -{ -} - -QualifiedName::QualifiedName(const vector<string>& name): NameList(name, "::") -{ -} +QualifiedName::QualifiedName(const vector<string>& name) : NameList(name, "::") {} -QualifiedName::QualifiedName(const QualifiedName& name): NameList(name.m_name, "::") -{ -} +QualifiedName::QualifiedName(const QualifiedName& name) : NameList(name.m_name, "::") {} -QualifiedName::~QualifiedName() -{} +QualifiedName::~QualifiedName() {} QualifiedName& QualifiedName::operator=(const string& name) { - m_name = vector<string>{name}; + m_name = vector<string> {name}; m_join = "::"; return *this; } @@ -350,33 +331,24 @@ QualifiedName QualifiedName::FromAPIObject(BNQualifiedName* name) } -NameSpace::NameSpace(): NameList("::") -{ -} +NameSpace::NameSpace() : NameList("::") {} -NameSpace::NameSpace(const string& name): NameList(name, "::") -{ -} +NameSpace::NameSpace(const string& name) : NameList(name, "::") {} -NameSpace::NameSpace(const vector<string>& name): NameList(name, "::") -{ -} +NameSpace::NameSpace(const vector<string>& name) : NameList(name, "::") {} -NameSpace::NameSpace(const NameSpace& name): NameList(name.m_name, "::") -{ -} +NameSpace::NameSpace(const NameSpace& name) : NameList(name.m_name, "::") {} -NameSpace::~NameSpace() -{} +NameSpace::~NameSpace() {} NameSpace& NameSpace::operator=(const string& name) { - m_name = vector<string>{name}; + m_name = vector<string> {name}; m_join = "::"; return *this; } @@ -636,8 +608,8 @@ string Type::GetStringAfterName(Platform* platform) const vector<InstructionTextToken> Type::GetTokens(Platform* platform, uint8_t baseConfidence) const { size_t count; - BNInstructionTextToken* tokens = BNGetTypeTokens(m_object, - platform ? platform->GetObject() : nullptr, baseConfidence, &count); + BNInstructionTextToken* tokens = + BNGetTypeTokens(m_object, platform ? platform->GetObject() : nullptr, baseConfidence, &count); return InstructionTextToken::ConvertAndFreeInstructionTextTokenList(tokens, count); } @@ -646,8 +618,8 @@ vector<InstructionTextToken> Type::GetTokens(Platform* platform, uint8_t baseCon vector<InstructionTextToken> Type::GetTokensBeforeName(Platform* platform, uint8_t baseConfidence) const { size_t count; - BNInstructionTextToken* tokens = BNGetTypeTokensBeforeName(m_object, - platform ? platform->GetObject() : nullptr, baseConfidence, &count); + BNInstructionTextToken* tokens = + BNGetTypeTokensBeforeName(m_object, platform ? platform->GetObject() : nullptr, baseConfidence, &count); return InstructionTextToken::ConvertAndFreeInstructionTextTokenList(tokens, count); } @@ -655,8 +627,8 @@ vector<InstructionTextToken> Type::GetTokensBeforeName(Platform* platform, uint8 vector<InstructionTextToken> Type::GetTokensAfterName(Platform* platform, uint8_t baseConfidence) const { size_t count; - BNInstructionTextToken* tokens = BNGetTypeTokensAfterName(m_object, - platform ? platform->GetObject() : nullptr, baseConfidence, &count); + BNInstructionTextToken* tokens = + BNGetTypeTokensAfterName(m_object, platform ? platform->GetObject() : nullptr, baseConfidence, &count); return InstructionTextToken::ConvertAndFreeInstructionTextTokenList(tokens, count); } @@ -707,7 +679,8 @@ Ref<Type> Type::StructureType(Structure* strct) } -Ref<Type> Type::NamedType(NamedTypeReference* ref, size_t width, size_t align, const Confidence<bool>& cnst, const Confidence<bool>& vltl) +Ref<Type> Type::NamedType( + NamedTypeReference* ref, size_t width, size_t align, const Confidence<bool>& cnst, const Confidence<bool>& vltl) { BNBoolWithConfidence cnstConf; cnstConf.value = cnst.GetValue(); @@ -730,8 +703,7 @@ Ref<Type> Type::NamedType(const QualifiedName& name, Type* type) Ref<Type> Type::NamedType(const string& id, const QualifiedName& name, Type* type) { BNQualifiedName nameObj = name.GetAPIObject(); - BNType* coreObj = BNCreateNamedTypeReferenceFromTypeAndId(id.c_str(), &nameObj, - type ? type->GetObject() : nullptr); + BNType* coreObj = BNCreateNamedTypeReferenceFromTypeAndId(id.c_str(), &nameObj, type ? type->GetObject() : nullptr); QualifiedName::FreeAPIObject(&nameObj); return coreObj ? new Type(coreObj) : nullptr; } @@ -764,8 +736,8 @@ Ref<Type> Type::EnumerationType(Enumeration* enm, size_t width, const Confidence } -Ref<Type> Type::PointerType(Architecture* arch, const Confidence<Ref<Type>>& type, - const Confidence<bool>& cnst, const Confidence<bool>& vltl, BNReferenceType refType) +Ref<Type> Type::PointerType(Architecture* arch, const Confidence<Ref<Type>>& type, const Confidence<bool>& cnst, + const Confidence<bool>& vltl, BNReferenceType refType) { BNTypeWithConfidence typeConf; typeConf.type = type->GetObject(); @@ -783,8 +755,8 @@ Ref<Type> Type::PointerType(Architecture* arch, const Confidence<Ref<Type>>& typ } -Ref<Type> Type::PointerType(size_t width, const Confidence<Ref<Type>>& type, - const Confidence<bool>& cnst, const Confidence<bool>& vltl, BNReferenceType refType) +Ref<Type> Type::PointerType(size_t width, const Confidence<Ref<Type>>& type, const Confidence<bool>& cnst, + const Confidence<bool>& vltl, BNReferenceType refType) { BNTypeWithConfidence typeConf; typeConf.type = type->GetObject(); @@ -812,9 +784,8 @@ Ref<Type> Type::ArrayType(const Confidence<Ref<Type>>& type, uint64_t elem) Ref<Type> Type::FunctionType(const Confidence<Ref<Type>>& returnValue, - const Confidence<Ref<CallingConvention>>& callingConvention, - const std::vector<FunctionParameter>& params, const Confidence<bool>& varArg, - const Confidence<int64_t>& stackAdjust) + const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params, + const Confidence<bool>& varArg, const Confidence<int64_t>& stackAdjust) { BNTypeWithConfidence returnValueConf; returnValueConf.type = returnValue->GetObject(); @@ -844,8 +815,8 @@ Ref<Type> Type::FunctionType(const Confidence<Ref<Type>>& returnValue, stackAdjustConf.value = stackAdjust.GetValue(); stackAdjustConf.confidence = stackAdjust.GetConfidence(); - Type* type = new Type(BNCreateFunctionType(&returnValueConf, &callingConventionConf, - paramArray, params.size(), &varArgConf, &stackAdjustConf)); + Type* type = new Type(BNCreateFunctionType( + &returnValueConf, &callingConventionConf, paramArray, params.size(), &varArgConf, &stackAdjustConf)); delete[] paramArray; return type; } @@ -991,7 +962,7 @@ Ref<Type> Type::WithReplacedNamedTypeReference(NamedTypeReference* from, NamedTy bool Type::AddTypeMemberTokens(BinaryView* data, vector<InstructionTextToken>& tokens, int64_t offset, - vector<string>& nameList, size_t size, bool indirect) + vector<string>& nameList, size_t size, bool indirect) { size_t tokenCount; BNInstructionTextToken* list; @@ -999,10 +970,12 @@ bool Type::AddTypeMemberTokens(BinaryView* data, vector<InstructionTextToken>& t size_t nameCount; char** names = nullptr; - if (!BNAddTypeMemberTokens(m_object, data->GetObject(), &list, &tokenCount, offset, &names, &nameCount, size, indirect)) + if (!BNAddTypeMemberTokens( + m_object, data->GetObject(), &list, &tokenCount, offset, &names, &nameCount, size, indirect)) return false; - vector<InstructionTextToken> newTokens = InstructionTextToken::ConvertAndFreeInstructionTextTokenList(list, tokenCount); + vector<InstructionTextToken> newTokens = + InstructionTextToken::ConvertAndFreeInstructionTextTokenList(list, tokenCount); tokens.insert(tokens.end(), newTokens.begin(), newTokens.end()); nameList.clear(); @@ -1323,8 +1296,8 @@ string TypeBuilder::GetStringAfterName(Platform* platform) const vector<InstructionTextToken> TypeBuilder::GetTokens(Platform* platform, uint8_t baseConfidence) const { size_t count; - BNInstructionTextToken* tokens = BNGetTypeBuilderTokens(m_object, - platform ? platform->GetObject() : nullptr, baseConfidence, &count); + BNInstructionTextToken* tokens = + BNGetTypeBuilderTokens(m_object, platform ? platform->GetObject() : nullptr, baseConfidence, &count); return InstructionTextToken::ConvertAndFreeInstructionTextTokenList(tokens, count); } @@ -1333,8 +1306,8 @@ vector<InstructionTextToken> TypeBuilder::GetTokens(Platform* platform, uint8_t vector<InstructionTextToken> TypeBuilder::GetTokensBeforeName(Platform* platform, uint8_t baseConfidence) const { size_t count; - BNInstructionTextToken* tokens = BNGetTypeBuilderTokensBeforeName(m_object, - platform ? platform->GetObject() : nullptr, baseConfidence, &count); + BNInstructionTextToken* tokens = + BNGetTypeBuilderTokensBeforeName(m_object, platform ? platform->GetObject() : nullptr, baseConfidence, &count); return InstructionTextToken::ConvertAndFreeInstructionTextTokenList(tokens, count); } @@ -1342,8 +1315,8 @@ vector<InstructionTextToken> TypeBuilder::GetTokensBeforeName(Platform* platform vector<InstructionTextToken> TypeBuilder::GetTokensAfterName(Platform* platform, uint8_t baseConfidence) const { size_t count; - BNInstructionTextToken* tokens = BNGetTypeBuilderTokensAfterName(m_object, - platform ? platform->GetObject() : nullptr, baseConfidence, &count); + BNInstructionTextToken* tokens = + BNGetTypeBuilderTokensAfterName(m_object, platform ? platform->GetObject() : nullptr, baseConfidence, &count); return InstructionTextToken::ConvertAndFreeInstructionTextTokenList(tokens, count); } @@ -1394,7 +1367,8 @@ TypeBuilder TypeBuilder::StructureType(StructureBuilder* strct) } -TypeBuilder TypeBuilder::NamedType(NamedTypeReference* ref, size_t width, size_t align, const Confidence<bool>& cnst, const Confidence<bool>& vltl) +TypeBuilder TypeBuilder::NamedType( + NamedTypeReference* ref, size_t width, size_t align, const Confidence<bool>& cnst, const Confidence<bool>& vltl) { BNBoolWithConfidence cnstConf; cnstConf.value = cnst.GetValue(); @@ -1407,7 +1381,8 @@ TypeBuilder TypeBuilder::NamedType(NamedTypeReference* ref, size_t width, size_t } -TypeBuilder TypeBuilder::NamedType(NamedTypeReferenceBuilder* ref, size_t width, size_t align, const Confidence<bool>& cnst, const Confidence<bool>& vltl) +TypeBuilder TypeBuilder::NamedType(NamedTypeReferenceBuilder* ref, size_t width, size_t align, + const Confidence<bool>& cnst, const Confidence<bool>& vltl) { BNBoolWithConfidence cnstConf; cnstConf.value = cnst.GetValue(); @@ -1416,7 +1391,8 @@ TypeBuilder TypeBuilder::NamedType(NamedTypeReferenceBuilder* ref, size_t width, BNBoolWithConfidence vltlConf; vltlConf.value = vltl.GetValue(); vltlConf.confidence = vltl.GetConfidence(); - return TypeBuilder(BNCreateNamedTypeReferenceBuilderWithBuilder(ref->GetObject(), width, align, &cnstConf, &vltlConf)); + return TypeBuilder( + BNCreateNamedTypeReferenceBuilderWithBuilder(ref->GetObject(), width, align, &cnstConf, &vltlConf)); } @@ -1429,8 +1405,8 @@ TypeBuilder TypeBuilder::NamedType(const QualifiedName& name, Type* type) TypeBuilder TypeBuilder::NamedType(const string& id, const QualifiedName& name, Type* type) { BNQualifiedName nameObj = name.GetAPIObject(); - BNTypeBuilder* coreObj = BNCreateNamedTypeReferenceBuilderFromTypeAndId(id.c_str(), &nameObj, - type ? type->GetObject() : nullptr); + BNTypeBuilder* coreObj = + BNCreateNamedTypeReferenceBuilderFromTypeAndId(id.c_str(), &nameObj, type ? type->GetObject() : nullptr); QualifiedName::FreeAPIObject(&nameObj); return coreObj ? TypeBuilder(coreObj) : VoidType(); } @@ -1445,25 +1421,29 @@ TypeBuilder TypeBuilder::NamedType(BinaryView* view, const QualifiedName& name) } -TypeBuilder TypeBuilder::EnumerationType(Architecture* arch, Enumeration* enm, size_t width, const Confidence<bool>& isSigned) +TypeBuilder TypeBuilder::EnumerationType( + Architecture* arch, Enumeration* enm, size_t width, const Confidence<bool>& isSigned) { BNBoolWithConfidence isSignedConf; isSignedConf.value = isSigned.GetValue(); isSignedConf.confidence = isSigned.GetConfidence(); - return TypeBuilder(BNCreateEnumerationTypeBuilder(arch ? arch->GetObject() : nullptr, enm->GetObject(), width, &isSignedConf)); + return TypeBuilder( + BNCreateEnumerationTypeBuilder(arch ? arch->GetObject() : nullptr, enm->GetObject(), width, &isSignedConf)); } -TypeBuilder TypeBuilder::EnumerationType(Architecture* arch, EnumerationBuilder* enm, size_t width, const Confidence<bool>& isSigned) +TypeBuilder TypeBuilder::EnumerationType( + Architecture* arch, EnumerationBuilder* enm, size_t width, const Confidence<bool>& isSigned) { BNBoolWithConfidence isSignedConf; isSignedConf.value = isSigned.GetValue(); isSignedConf.confidence = isSigned.GetConfidence(); - return TypeBuilder(BNCreateEnumerationTypeBuilderWithBuilder(arch->GetObject(), enm->GetObject(), width, &isSignedConf)); + return TypeBuilder( + BNCreateEnumerationTypeBuilderWithBuilder(arch->GetObject(), enm->GetObject(), width, &isSignedConf)); } TypeBuilder TypeBuilder::PointerType(Architecture* arch, const Confidence<Ref<Type>>& type, - const Confidence<bool>& cnst, const Confidence<bool>& vltl, BNReferenceType refType) + const Confidence<bool>& cnst, const Confidence<bool>& vltl, BNReferenceType refType) { BNTypeWithConfidence typeConf; typeConf.type = type->GetObject(); @@ -1481,8 +1461,8 @@ TypeBuilder TypeBuilder::PointerType(Architecture* arch, const Confidence<Ref<Ty } -TypeBuilder TypeBuilder::PointerType(size_t width, const Confidence<Ref<Type>>& type, - const Confidence<bool>& cnst, const Confidence<bool>& vltl, BNReferenceType refType) +TypeBuilder TypeBuilder::PointerType(size_t width, const Confidence<Ref<Type>>& type, const Confidence<bool>& cnst, + const Confidence<bool>& vltl, BNReferenceType refType) { BNTypeWithConfidence typeConf; typeConf.type = type->GetObject(); @@ -1527,9 +1507,8 @@ static BNFunctionParameter* GetParamArray(const std::vector<FunctionParameter>& } TypeBuilder TypeBuilder::FunctionType(const Confidence<Ref<Type>>& returnValue, - const Confidence<Ref<CallingConvention>>& callingConvention, - const std::vector<FunctionParameter>& params, const Confidence<bool>& varArg, - const Confidence<int64_t>& stackAdjust) + const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params, + const Confidence<bool>& varArg, const Confidence<int64_t>& stackAdjust) { BNTypeWithConfidence returnValueConf; returnValueConf.type = returnValue->GetObject(); @@ -1550,8 +1529,8 @@ TypeBuilder TypeBuilder::FunctionType(const Confidence<Ref<Type>>& returnValue, stackAdjustConf.value = stackAdjust.GetValue(); stackAdjustConf.confidence = stackAdjust.GetConfidence(); - TypeBuilder type(BNCreateFunctionTypeBuilder(&returnValueConf, &callingConventionConf, - paramArray, paramCount, &varArgConf, &stackAdjustConf)); + TypeBuilder type(BNCreateFunctionTypeBuilder( + &returnValueConf, &callingConventionConf, paramArray, paramCount, &varArgConf, &stackAdjustConf)); delete[] paramArray; return type; } @@ -1667,24 +1646,24 @@ QualifiedName NamedTypeReference::GetName() const } -Ref<NamedTypeReference> NamedTypeReference::GenerateAutoTypeReference(BNNamedTypeReferenceClass cls, - const string& source, const QualifiedName& name) +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::GenerateAutoDemangledTypeReference(BNNamedTypeReferenceClass cls, - const QualifiedName& name) +Ref<NamedTypeReference> NamedTypeReference::GenerateAutoDemangledTypeReference( + BNNamedTypeReferenceClass cls, const QualifiedName& name) { string id = Type::GenerateAutoDemangledTypeId(name); return new NamedTypeReference(cls, id, name); } -Ref<NamedTypeReference> NamedTypeReference::GenerateAutoDebugTypeReference(BNNamedTypeReferenceClass cls, - const QualifiedName& name) +Ref<NamedTypeReference> NamedTypeReference::GenerateAutoDebugTypeReference( + BNNamedTypeReferenceClass cls, const QualifiedName& name) { string id = Type::GenerateAutoDebugTypeId(name); return new NamedTypeReference(cls, id, name); @@ -1697,10 +1676,9 @@ NamedTypeReferenceBuilder::NamedTypeReferenceBuilder(BNNamedTypeReferenceBuilder } -NamedTypeReferenceBuilder::NamedTypeReferenceBuilder(BNNamedTypeReferenceClass cls, const std::string& id, - const QualifiedName& name) +NamedTypeReferenceBuilder::NamedTypeReferenceBuilder( + BNNamedTypeReferenceClass cls, const std::string& id, const QualifiedName& name) { - BNQualifiedName n = name.GetAPIObject(); m_object = BNCreateNamedTypeBuilder(cls, id.c_str(), &n); QualifiedName::FreeAPIObject(&n); @@ -2087,8 +2065,8 @@ BNStructureVariant StructureBuilder::GetStructureType() const } -StructureBuilder& StructureBuilder::AddMember(const Confidence<Ref<Type>>& type, const string& name, - BNMemberAccess access, BNMemberScope scope) +StructureBuilder& StructureBuilder::AddMember( + const Confidence<Ref<Type>>& type, const string& name, BNMemberAccess access, BNMemberScope scope) { BNTypeWithConfidence tc; tc.type = type->GetObject(); @@ -2098,8 +2076,8 @@ StructureBuilder& StructureBuilder::AddMember(const Confidence<Ref<Type>>& type, } -StructureBuilder& StructureBuilder::AddMemberAtOffset(const Confidence<Ref<Type>>& type, - const string& name, uint64_t offset, bool overwriteExisting, BNMemberAccess access, BNMemberScope scope) +StructureBuilder& StructureBuilder::AddMemberAtOffset(const Confidence<Ref<Type>>& type, const string& name, + uint64_t offset, bool overwriteExisting, BNMemberAccess access, BNMemberScope scope) { BNTypeWithConfidence tc; tc.type = type->GetObject(); @@ -2116,7 +2094,8 @@ StructureBuilder& StructureBuilder::RemoveMember(size_t idx) } -StructureBuilder& StructureBuilder::ReplaceMember(size_t idx, const Confidence<Ref<Type>>& type, const std::string& name, bool overwriteExisting) +StructureBuilder& StructureBuilder::ReplaceMember( + size_t idx, const Confidence<Ref<Type>>& type, const std::string& name, bool overwriteExisting) { BNTypeWithConfidence tc; tc.type = type->GetObject(); @@ -2272,8 +2251,8 @@ EnumerationBuilder& EnumerationBuilder::ReplaceMember(size_t idx, const string& } -bool BinaryNinja::PreprocessSource(const string& source, const string& fileName, string& output, string& errors, - const vector<string>& includeDirs) +bool BinaryNinja::PreprocessSource( + const string& source, const string& fileName, string& output, string& errors, const vector<string>& includeDirs) { char* outStr; char* errorStr; @@ -2282,8 +2261,8 @@ bool BinaryNinja::PreprocessSource(const string& source, const string& fileName, for (size_t i = 0; i < includeDirs.size(); i++) includeDirList[i] = includeDirs[i].c_str(); - bool result = BNPreprocessSource(source.c_str(), fileName.c_str(), &outStr, &errorStr, - includeDirList, includeDirs.size()); + bool result = + BNPreprocessSource(source.c_str(), fileName.c_str(), &outStr, &errorStr, includeDirList, includeDirs.size()); output = outStr; errors = errorStr; |
