From d811fffd69ffba789b960edd4fa31cc3d3f5905e Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 16 Mar 2023 19:54:07 -0400 Subject: Add support for deriving structures from other structures --- binaryninjaapi.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 92898ae4..5f2987bf 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2617,12 +2617,16 @@ namespace BinaryNinja { static LinearDisassemblyLine FromAPIObject(BNLinearDisassemblyLine* line); }; + class NamedTypeReference; + struct TypeDefinitionLine { BNTypeDefinitionLineType lineType; std::vector tokens; Ref type, rootType; std::string rootTypeName; + Ref baseType; + uint64_t baseOffset; uint64_t offset; size_t fieldIndex; @@ -2890,7 +2894,6 @@ namespace BinaryNinja { struct PossibleValueSet; class Metadata; class Structure; - class NamedTypeReference; struct ParsedType; struct TypeParserResult; class Component; @@ -3841,6 +3844,16 @@ namespace BinaryNinja { */ std::vector GetDataReferencesForTypeField(const QualifiedName& type, uint64_t offset); + /*! Returns a list of virtual addresses of data which are referenced from the type \c type . + + Only data referenced by structures with the \c __data_var_refs attribute are included. + + \param type QualifiedName of the type + \param offset Offset of the field, relative to the start of the type + \return List of addresses referenced from the type field + */ + std::vector GetDataReferencesFromForTypeField(const QualifiedName& type, uint64_t offset); + /*! Returns a list of type references to a specific type field \param type QualifiedName of the type @@ -7440,6 +7453,29 @@ namespace BinaryNinja { BNMemberScope scope; }; + /*! + \ingroup types + */ + struct InheritedStructureMember + { + Ref base; + uint64_t baseOffset; + StructureMember member; + size_t memberIndex; + }; + + /*! + \ingroup types + */ + struct BaseStructure + { + Ref type; + uint64_t offset, width; + + BaseStructure(NamedTypeReference* type, uint64_t offset, uint64_t width); + BaseStructure(Type* type, uint64_t offset); + }; + /*! Structure is a class that wraps built structures and retrieves info about them. \see StructureBuilder is used for building structures @@ -7450,12 +7486,25 @@ namespace BinaryNinja { public: Structure(BNStructure* s); - /*! Get a list of Structure members + /*! Get a list of base structures. Offsets that are not defined by this structure will be filled + in by the fields of the base structure(s). + + \return The list of base structures + */ + std::vector GetBaseStructures() const; + + /*! Get a list of Structure members, excluding those inherited from base structures \return The list of structure members */ std::vector GetMembers() const; + /*! Get a list of Structure members, including those inherited from base structures + + \return The list of structure members + */ + std::vector GetMembersIncludingInherited(BinaryView* view) const; + /*! Get a structure member by name \param name Name of the member to retrieve @@ -7487,6 +7536,15 @@ namespace BinaryNinja { */ uint64_t GetWidth() const; + /*! Get the structure pointer offset in bytes. Pointers to this structure will implicitly + have this offset subtracted from the pointer to arrive at the start of the structure. + Effectively, the pointer offset becomes the new start of the structure, and fields + before it are accessed using negative offsets from the pointer. + + \return The structure pointer offset in bytes + */ + int64_t GetPointerOffset() const; + /*! Get the structure alignment \return The structure alignment @@ -7505,6 +7563,12 @@ namespace BinaryNinja { */ bool IsUnion() const; + /*! Whether structure field references propagate the references to data variable field values + + \return Whether the structure propagates data variable references + */ + bool PropagateDataVariableReferences() const; + /*! Get the structure type \return The structure type @@ -7557,6 +7621,9 @@ namespace BinaryNinja { */ Ref Finalize() const; + std::vector GetBaseStructures() const; + StructureBuilder& SetBaseStructures(const std::vector& bases); + /*! GetMembers returns a list of structure members \return vector of StructureMember objects @@ -7574,11 +7641,15 @@ namespace BinaryNinja { bool GetMemberAtOffset(int64_t offset, StructureMember& result, size_t& idx) const; uint64_t GetWidth() const; StructureBuilder& SetWidth(size_t width); + int64_t GetPointerOffset() const; + StructureBuilder& SetPointerOffset(int64_t offset); size_t GetAlignment() const; StructureBuilder& SetAlignment(size_t align); bool IsPacked() const; StructureBuilder& SetPacked(bool packed); bool IsUnion() const; + bool PropagateDataVariableReferences() const; + StructureBuilder& SetPropagateDataVariableReferences(bool value); /*! Set the structure type -- cgit v1.3.1