From d9b1df165f9daad6a5229718ecd0ee50a5ef6bf1 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Mon, 16 Nov 2020 17:51:46 +0800 Subject: add support for type xref and variable xref --- binaryninjaapi.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 5be370c0..eac2f6b8 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1072,6 +1072,7 @@ __attribute__ ((format (printf, 1, 2))) virtual bool operator==(const NameList& other) const; virtual bool operator!=(const NameList& other) const; virtual bool operator<(const NameList& other) const; + virtual bool operator>(const NameList& other) const; virtual NameList operator+(const NameList& other) const; @@ -1166,6 +1167,26 @@ __attribute__ ((format (printf, 1, 2))) static Ref ImportedFunctionFromImportAddressSymbol(Symbol* sym, uint64_t addr); }; + // TODO: This describes how the xref source references the target + enum ReferenceType + { + UnspecifiedReferenceType = 0x0, + ReadReferenceType = 0x1, + WriteReferenceType = 0x2, + ExecuteReferenceType = 0x4, + + // A type is referenced by a data variable + DataVariableReferenceType = 0x8, + + // A type is referenced by another type + DirectTypeReferenceType = 0x10, + IndirectTypeReferenceType = 0x20, + }; + + // ReferenceSource describes code reference source; TypeReferenceSource describes type reference source. + // When we query references, code references return vector, data references return vector, + // type references return vector. + struct ReferenceSource { Ref func; @@ -1173,6 +1194,22 @@ __attribute__ ((format (printf, 1, 2))) uint64_t addr; }; + struct ILReferenceSource + { + Ref func; + Ref arch; + uint64_t addr; + BNFunctionGraphType type; + size_t exprId; + }; + + struct TypeReferenceSource + { + QualifiedName name; + uint64_t offset; + BNTypeReferenceType type; + }; + struct InstructionTextToken { enum @@ -1573,6 +1610,7 @@ __attribute__ ((format (printf, 1, 2))) Ref GetAnalysisFunction(Platform* platform, uint64_t addr); Ref GetRecentAnalysisFunctionForAddress(uint64_t addr); std::vector> GetAnalysisFunctionsForAddress(uint64_t addr); + std::vector> GetAnalysisFunctionsContainingAddress(uint64_t addr); Ref GetAnalysisEntryPoint(); Ref GetRecentBasicBlockForAddress(uint64_t addr); @@ -1591,6 +1629,21 @@ __attribute__ ((format (printf, 1, 2))) void AddUserDataReference(uint64_t fromAddr, uint64_t toAddr); void RemoveUserDataReference(uint64_t fromAddr, uint64_t toAddr); + // References to type + std::vector GetCodeReferencesForType(const QualifiedName& type); + std::vector GetDataReferencesForType(const QualifiedName& type); + std::vector GetTypeReferencesForType(const QualifiedName& type); + + // References to type field + 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); + + std::vector GetCodeReferencesForTypeFrom(ReferenceSource src); + std::vector GetCodeReferencesForTypeFrom(ReferenceSource src, uint64_t len); + std::vector GetCodeReferencesForTypeFieldFrom(ReferenceSource src); + std::vector GetCodeReferencesForTypeFieldFrom(ReferenceSource src, uint64_t len); + std::vector GetCallees(ReferenceSource addr); std::vector GetCallers(uint64_t addr); @@ -2492,6 +2545,12 @@ __attribute__ ((format (printf, 1, 2))) static Variable FromIdentifier(uint64_t id); }; + struct VariableReferenceSource + { + Variable var; + ILReferenceSource source; + }; + struct FunctionParameter { std::string name; @@ -2610,6 +2669,9 @@ __attribute__ ((format (printf, 1, 2))) Ref WithReplacedStructure(Structure* from, Structure* to); Ref WithReplacedEnumeration(Enumeration* from, Enumeration* to); Ref WithReplacedNamedTypeReference(NamedTypeReference* from, NamedTypeReference* to); + + bool AddTypeMemberTokens(BinaryView* data, std::vector& tokens, int64_t offset, + std::vector& nameList, size_t size = 0, bool indirect = false); }; class TypeBuilder @@ -3043,6 +3105,10 @@ __attribute__ ((format (printf, 1, 2))) void AddUserCodeReference(Architecture* fromArch, uint64_t fromAddr, uint64_t toAddr); 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); Ref GetLowLevelIL() const; Ref GetLowLevelILIfAvailable() const; @@ -3060,6 +3126,14 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetStackVariablesReferencedByInstruction(Architecture* arch, uint64_t addr); std::vector GetConstantsReferencedByInstruction(Architecture* arch, uint64_t addr); + std::vector GetMediumLevelILVariableReferences(const Variable& var); + std::vector GetMediumLevelILVariableReferencesFrom(Architecture* arch, uint64_t addr); + std::vector GetMediumLevelILVariableReferencesInRange(Architecture* arch, uint64_t addr, uint64_t len); + + std::vector GetHighLevelILVariableReferences(const Variable& var); + std::vector GetHighLevelILVariableReferencesFrom(Architecture* arch, uint64_t addr); + std::vector GetHighLevelILVariableReferencesInRange(Architecture* arch, uint64_t addr, uint64_t len); + Ref GetLiftedIL() const; Ref GetLiftedILIfAvailable() const; size_t GetLiftedILForInstruction(Architecture* arch, uint64_t addr); @@ -4379,6 +4453,7 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetExprText(ExprId expr, bool asFullAst = true); std::vector GetExprText(const HighLevelILInstruction& instr, bool asFullAst = true); + std::vector GetInstructionText(size_t i, bool asFullAst = true); Confidence> GetExprType(size_t expr); Confidence> GetExprType(const HighLevelILInstruction& expr); @@ -5309,6 +5384,7 @@ __attribute__ ((format (printf, 1, 2))) DisassemblyTextRenderer(Function* func, DisassemblySettings* settings = nullptr); DisassemblyTextRenderer(LowLevelILFunction* func, DisassemblySettings* settings = nullptr); DisassemblyTextRenderer(MediumLevelILFunction* func, DisassemblySettings* settings = nullptr); + DisassemblyTextRenderer(HighLevelILFunction* func, DisassemblySettings* settings = nullptr); DisassemblyTextRenderer(BNDisassemblyTextRenderer* renderer); Ref GetFunction() const; -- cgit v1.3.1