From 7c9ada78241e08bf36bd04d989f742a6de721575 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Wed, 5 May 2021 17:23:49 +0800 Subject: Add the ability to automatically create struct members --- binaryninjaapi.h | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 89f5fd84..459ddcb5 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1163,6 +1163,14 @@ __attribute__ ((format (printf, 1, 2))) uint64_t addr; }; + struct TypeFieldReference + { + Ref func; + Ref arch; + uint64_t addr; + size_t size; + }; + struct ILReferenceSource { Ref func; @@ -1400,6 +1408,8 @@ __attribute__ ((format (printf, 1, 2))) struct QualifiedNameAndType; struct PossibleValueSet; class Metadata; + class Structure; + class QueryMetadataException: public std::exception { const std::string m_error; @@ -1609,7 +1619,7 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetTypeReferencesForType(const QualifiedName& type); // References to type field - std::vector GetCodeReferencesForTypeField(const QualifiedName& type, uint64_t offset); + std::vector GetCodeReferencesForTypeField(const QualifiedName& type, uint64_t offset); std::vector GetDataReferencesForTypeField(const QualifiedName& type, uint64_t offset); std::vector GetTypeReferencesForTypeField(const QualifiedName& type, uint64_t offset); @@ -1618,7 +1628,17 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetCodeReferencesForTypeFieldFrom(ReferenceSource src); std::vector GetCodeReferencesForTypeFieldFrom(ReferenceSource src, uint64_t len); - std::vector GetAllFieldsReferencedByCode(const QualifiedName& type); + std::vector GetAllFieldsReferenced(const QualifiedName& type); + std::map> GetAllSizesReferenced( + const QualifiedName& type); + std::map>>> + GetAllTypesReferenced(const QualifiedName& type); + std::vector GetSizesReferenced(const QualifiedName& type, + uint64_t offset); + std::vector>> GetTypesReferenced( + const QualifiedName& type, uint64_t offset); + + Ref CreateStructureBasedOnFieldAccesses(const QualifiedName& type); std::vector GetCallees(ReferenceSource addr); std::vector GetCallers(uint64_t addr); @@ -1828,6 +1848,11 @@ __attribute__ ((format (printf, 1, 2))) static bool ParseExpression(Ref view, const std::string& expression, uint64_t &offset, uint64_t here, std::string& errorString); bool HasSymbols() const; bool HasDataVariables() const; + + Ref CreateStructureFromOffsetAccess(const QualifiedName& type, + bool* newMemberAdded) const; + Confidence> CreateStructureMemberFromAccess(const QualifiedName& name, + uint64_t offset) const; }; @@ -2668,6 +2693,8 @@ __attribute__ ((format (printf, 1, 2))) bool AddTypeMemberTokens(BinaryView* data, std::vector& tokens, int64_t offset, std::vector& nameList, size_t size = 0, bool indirect = false); + + static std::string GetSizeSuffix(size_t size); }; class TypeBuilder @@ -2854,9 +2881,10 @@ __attribute__ ((format (printf, 1, 2))) StructureBuilder& SetStructureType(BNStructureType type); BNStructureType GetStructureType() const; StructureBuilder& AddMember(const Confidence>& type, const std::string& name); - StructureBuilder& AddMemberAtOffset(const Confidence>& type, const std::string& name, uint64_t offset); + StructureBuilder& AddMemberAtOffset(const Confidence>& type, + const std::string& name, uint64_t offset, bool overwriteExisting = true); StructureBuilder& RemoveMember(size_t idx); - StructureBuilder& ReplaceMember(size_t idx, const Confidence>& type, const std::string& name); + StructureBuilder& ReplaceMember(size_t idx, const Confidence>& type, const std::string& name, bool overwriteExisting = true); }; struct EnumerationMember @@ -3106,8 +3134,10 @@ __attribute__ ((format (printf, 1, 2))) void RemoveUserCodeReference(Architecture* fromArch, uint64_t fromAddr, uint64_t toAddr); void AddUserTypeReference(Architecture* fromArch, uint64_t fromAddr, const QualifiedName& name); void RemoveUserTypeReference(Architecture* fromArch, uint64_t fromAddr, const QualifiedName& name); - void AddUserTypeFieldReference(Architecture* fromArch, uint64_t fromAddr, const QualifiedName& name, uint64_t offset); - void RemoveUserTypeFieldReference(Architecture* fromArch, uint64_t fromAddr, const QualifiedName& name, uint64_t offset); + void AddUserTypeFieldReference(Architecture* fromArch, uint64_t fromAddr, + const QualifiedName& name, uint64_t offset, size_t size = 0); + void RemoveUserTypeFieldReference(Architecture* fromArch, uint64_t fromAddr, + const QualifiedName& name, uint64_t offset, size_t size = 0); Ref GetLowLevelIL() const; Ref GetLowLevelILIfAvailable() const; -- cgit v1.3.1