diff --git a/api/c/MachO/Parser.cpp b/api/c/MachO/Parser.cpp index b120235..f35cd25 100644 --- a/api/c/MachO/Parser.cpp +++ b/api/c/MachO/Parser.cpp @@ -17,6 +17,7 @@ #include "LIEF/MachO/Binary.h" #include "LIEF/MachO/Parser.hpp" +#include "LIEF/MachO/FatBinary.hpp" #include "Binary.hpp" diff --git a/include/LIEF/MachO.hpp b/include/LIEF/MachO.hpp index eb937b4..fd6e1c2 100644 --- a/include/LIEF/MachO.hpp +++ b/include/LIEF/MachO.hpp @@ -16,11 +16,48 @@ #ifndef LIEF_MACHO_H_ #define LIEF_MACHO_H_ -#include "LIEF/MachO/Parser.hpp" -#include "LIEF/MachO/Builder.hpp" #include "LIEF/MachO/Binary.hpp" -#include "LIEF/MachO/utils.hpp" -#include "LIEF/MachO/RelocationObject.hpp" +#include "LIEF/MachO/BinaryParser.hpp" +#include "LIEF/MachO/BindingInfo.hpp" +#include "LIEF/MachO/Builder.hpp" +#include "LIEF/MachO/BuildVersion.hpp" +#include "LIEF/MachO/CodeSignature.hpp" +#include "LIEF/MachO/DataCodeEntry.hpp" +#include "LIEF/MachO/DataInCode.hpp" +#include "LIEF/MachO/DyldEnvironment.hpp" +#include "LIEF/MachO/DyldInfo.hpp" +#include "LIEF/MachO/DylibCommand.hpp" +#include "LIEF/MachO/DylinkerCommand.hpp" +#include "LIEF/MachO/DynamicSymbolCommand.hpp" +#include "LIEF/MachO/EncryptionInfo.hpp" +#include "LIEF/MachO/enums.hpp" +#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/ExportInfo.hpp" +#include "LIEF/MachO/FatBinary.hpp" +#include "LIEF/MachO/FunctionStarts.hpp" +#include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Header.hpp" +#include "LIEF/MachO/json.hpp" +#include "LIEF/MachO/LoadCommand.hpp" +#include "LIEF/MachO/MainCommand.hpp" +#include "LIEF/MachO/ParserConfig.hpp" +#include "LIEF/MachO/Parser.hpp" #include "LIEF/MachO/RelocationDyld.hpp" +#include "LIEF/MachO/Relocation.hpp" +#include "LIEF/MachO/RelocationObject.hpp" +#include "LIEF/MachO/RPathCommand.hpp" +#include "LIEF/MachO/Section.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/SegmentSplitInfo.hpp" +#include "LIEF/MachO/SourceVersion.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/SubFramework.hpp" +#include "LIEF/MachO/SymbolCommand.hpp" +#include "LIEF/MachO/Symbol.hpp" +#include "LIEF/MachO/ThreadCommand.hpp" +#include "LIEF/MachO/type_traits.hpp" +#include "LIEF/MachO/utils.hpp" +#include "LIEF/MachO/UUIDCommand.hpp" +#include "LIEF/MachO/VersionMin.hpp" #endif diff --git a/include/LIEF/MachO/Binary.hpp b/include/LIEF/MachO/Binary.hpp index 48cc2ae..e6d6bcf 100644 --- a/include/LIEF/MachO/Binary.hpp +++ b/include/LIEF/MachO/Binary.hpp @@ -24,30 +24,7 @@ #include "LIEF/Abstract/Binary.hpp" #include "LIEF/MachO/type_traits.hpp" -#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/Header.hpp" -#include "LIEF/MachO/LoadCommand.hpp" -#include "LIEF/MachO/SegmentCommand.hpp" -#include "LIEF/MachO/DylibCommand.hpp" -#include "LIEF/MachO/DylinkerCommand.hpp" -#include "LIEF/MachO/UUIDCommand.hpp" -#include "LIEF/MachO/Symbol.hpp" -#include "LIEF/MachO/SymbolCommand.hpp" -#include "LIEF/MachO/MainCommand.hpp" -#include "LIEF/MachO/DynamicSymbolCommand.hpp" -#include "LIEF/MachO/DyldInfo.hpp" -#include "LIEF/MachO/FunctionStarts.hpp" -#include "LIEF/MachO/SourceVersion.hpp" -#include "LIEF/MachO/VersionMin.hpp" -#include "LIEF/MachO/ThreadCommand.hpp" -#include "LIEF/MachO/RPathCommand.hpp" -#include "LIEF/MachO/CodeSignature.hpp" -#include "LIEF/MachO/DataInCode.hpp" -#include "LIEF/MachO/SegmentSplitInfo.hpp" -#include "LIEF/MachO/SubFramework.hpp" -#include "LIEF/MachO/DyldEnvironment.hpp" -#include "LIEF/MachO/EncryptionInfo.hpp" -#include "LIEF/MachO/BuildVersion.hpp" namespace LIEF { namespace MachO { @@ -55,6 +32,28 @@ namespace MachO { class BinaryParser; class Builder; class DyldInfo; +class BuildVersion; +class EncryptionInfo; +class DyldEnvironment; +class SubFramework; +class SegmentSplitInfo; +class DataInCode; +class CodeSignature; +class RPathCommand; +class ThreadCommand; +class VersionMin; +class SourceVersion; +class FunctionStarts; +class DynamicSymbolCommand; +class MainCommand; +class SymbolCommand; +class Symbol; +class UUIDCommand; +class DylinkerCommand; +class DylibCommand; +class SegmentCommand; +class LoadCommand; +class Header; //! Class which represent a MachO binary class LIEF_API Binary : public LIEF::Binary { @@ -279,7 +278,6 @@ class LIEF_API Binary : public LIEF::Binary { //! @param[in] patch_value Patch to apply virtual void patch_address(uint64_t address, const std::vector& patch_value, LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override; - //! Patch the address with the given value //! //! @param[in] address Address to patch diff --git a/include/LIEF/MachO/BinaryParser.hpp b/include/LIEF/MachO/BinaryParser.hpp index 5e5734a..4aa22f2 100644 --- a/include/LIEF/MachO/BinaryParser.hpp +++ b/include/LIEF/MachO/BinaryParser.hpp @@ -23,20 +23,20 @@ #include "LIEF/types.hpp" #include "LIEF/visibility.h" -#include "LIEF/BinaryStream/VectorStream.hpp" #include "LIEF/Abstract/Parser.hpp" +#include "LIEF/MachO/enums.hpp" #include "LIEF/MachO/ParserConfig.hpp" -#include "LIEF/MachO/Structures.hpp" -#include "LIEF/MachO/Binary.hpp" -#include "LIEF/MachO/LoadCommand.hpp" -#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/type_traits.hpp" namespace LIEF { -namespace MachO { +class VectorStream; +namespace MachO { +class Section; class Parser; +class ParserConfig; //! @brief Class used to parse **single** binary (i.e. **not** FAT) //! @see MachO::Parser @@ -49,86 +49,86 @@ class LIEF_API BinaryParser : public LIEF::Parser { constexpr static size_t MAX_COMMANDS = std::numeric_limits::max(); public: - BinaryParser(const std::string& file, const ParserConfig& conf = ParserConfig::deep()); - BinaryParser(const std::vector& data, uint64_t fat_offset = 0, const ParserConfig& conf = ParserConfig::deep()); - BinaryParser(void); + BinaryParser(const std::string& file, const ParserConfig& conf = ParserConfig::deep()); + BinaryParser(const std::vector& data, uint64_t fat_offset = 0, const ParserConfig& conf = ParserConfig::deep()); + BinaryParser(void); - BinaryParser& operator=(const BinaryParser& copy) = delete; - BinaryParser(const BinaryParser& copy) = delete; + BinaryParser& operator=(const BinaryParser& copy) = delete; + BinaryParser(const BinaryParser& copy) = delete; - ~BinaryParser(void); + ~BinaryParser(void); - Binary* get_binary(void); + Binary* get_binary(void); private: - BinaryParser(std::unique_ptr&& stream, uint64_t fat_offset = 0, const ParserConfig& conf = ParserConfig::deep()); + BinaryParser(std::unique_ptr&& stream, uint64_t fat_offset = 0, const ParserConfig& conf = ParserConfig::deep()); - void init(void); + void init(void); - template - void parse(void); + template + void parse(void); - template - void parse_header(void); + template + void parse_header(void); - template - void parse_load_commands(void); + template + void parse_load_commands(void); - template - void parse_relocations(Section& section); + template + void parse_relocations(Section& section); - // Dyld info parser - // ================ + // Dyld info parser + // ================ - // Rebase - // ------ - template - void parse_dyldinfo_rebases(void); + // Rebase + // ------ + template + void parse_dyldinfo_rebases(void); - // Bindings - // -------- - template - void parse_dyldinfo_binds(void); + // Bindings + // -------- + template + void parse_dyldinfo_binds(void); - template - void parse_dyldinfo_generic_bind(void); + template + void parse_dyldinfo_generic_bind(void); - template - void parse_dyldinfo_weak_bind(void); + template + void parse_dyldinfo_weak_bind(void); - template - void parse_dyldinfo_lazy_bind(void); + template + void parse_dyldinfo_lazy_bind(void); - template - void do_bind(BINDING_CLASS cls, - uint8_t type, - uint8_t segment_idx, - uint64_t segment_offset, - const std::string& symbol_name, - int32_t ord, - int64_t addend, - bool is_weak, - bool is_non_weak_definition, - it_segments& segments, - uint64_t offset = 0 - ); + template + void do_bind(BINDING_CLASS cls, + uint8_t type, + uint8_t segment_idx, + uint64_t segment_offset, + const std::string& symbol_name, + int32_t ord, + int64_t addend, + bool is_weak, + bool is_non_weak_definition, + it_segments& segments, + uint64_t offset = 0 + ); - template - void do_rebase(uint8_t type, uint8_t segment_idx, uint64_t segment_address); + template + void do_rebase(uint8_t type, uint8_t segment_idx, uint64_t segment_address); - // Exports - // ------- - void parse_dyldinfo_export(void); + // Exports + // ------- + void parse_dyldinfo_export(void); - void parse_export_trie(uint64_t start, uint64_t end, const std::string& prefix); + void parse_export_trie(uint64_t start, uint64_t end, const std::string& prefix); - std::unique_ptr stream_; - Binary* binary_ ; - MACHO_TYPES type_; - bool is64_; - ParserConfig config_; - std::set visited_; + std::unique_ptr stream_; + Binary* binary_{nullptr}; + MACHO_TYPES type_; + bool is64_; + ParserConfig config_; + std::set visited_; }; diff --git a/include/LIEF/MachO/BindingInfo.hpp b/include/LIEF/MachO/BindingInfo.hpp index b1ae9bf..b6ed438 100644 --- a/include/LIEF/MachO/BindingInfo.hpp +++ b/include/LIEF/MachO/BindingInfo.hpp @@ -15,22 +15,20 @@ */ #ifndef LIEF_MACHO_BINDING_INFO_COMMAND_H_ #define LIEF_MACHO_BINDING_INFO_COMMAND_H_ -#include -#include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" +#include "LIEF/Object.hpp" #include "LIEF/MachO/enums.hpp" -#include "LIEF/MachO/DylibCommand.hpp" - namespace LIEF { namespace MachO { - +class DylibCommand; +class SegmentCommand; +class Symbol; class BinaryParser; class LIEF_API BindingInfo : public Object { diff --git a/include/LIEF/MachO/BuildVersion.hpp b/include/LIEF/MachO/BuildVersion.hpp index 2bfb80d..6ac34fa 100644 --- a/include/LIEF/MachO/BuildVersion.hpp +++ b/include/LIEF/MachO/BuildVersion.hpp @@ -15,7 +15,6 @@ */ #ifndef LIEF_MACHO_BUILD_VERSION_COMMAND_H_ #define LIEF_MACHO_BUILD_VERSION_COMMAND_H_ -#include #include #include #include @@ -27,7 +26,8 @@ namespace LIEF { namespace MachO { - +struct build_tool_version; +struct build_version_command; class LIEF_API BuildToolVersion : public LIEF::Object { public: diff --git a/include/LIEF/MachO/Builder.hpp b/include/LIEF/MachO/Builder.hpp index 9de8a6f..e994fa4 100644 --- a/include/LIEF/MachO/Builder.hpp +++ b/include/LIEF/MachO/Builder.hpp @@ -25,13 +25,26 @@ #include "LIEF/exception.hpp" #include "LIEF/iostream.hpp" -#include "LIEF/MachO/Binary.hpp" -#include "LIEF/MachO/FatBinary.hpp" -#include "LIEF/MachO/EnumToString.hpp" - namespace LIEF { namespace MachO { - +class Binary; +class FatBinary; +class DylibCommand; +class DylinkerCommand; +class VersionMin; +class SourceVersion; +class FunctionStarts; +class MainCommand; +class DyldInfo; +class SymbolCommand; +class DynamicSymbolCommand; +class DataInCode; +class CodeSignature; +class SegmentSplitInfo; +class SubFramework; +class DyldEnvironment; +class ThreadCommand; +class BuildVersion; class LIEF_API Builder { public: diff --git a/include/LIEF/MachO/CodeSignature.hpp b/include/LIEF/MachO/CodeSignature.hpp index 324f813..01220d0 100644 --- a/include/LIEF/MachO/CodeSignature.hpp +++ b/include/LIEF/MachO/CodeSignature.hpp @@ -15,10 +15,8 @@ */ #ifndef LIEF_MACHO_CODE_SIGNATURE_COMMAND_H_ #define LIEF_MACHO_CODE_SIGNATURE_COMMAND_H_ -#include #include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" @@ -29,39 +27,40 @@ namespace LIEF { namespace MachO { class BinaryParser; +struct linkedit_data_command; class LIEF_API CodeSignature : public LoadCommand { friend class BinaryParser; public: - CodeSignature(void); - CodeSignature(const linkedit_data_command *cmd); + CodeSignature(void); + CodeSignature(const linkedit_data_command *cmd); - CodeSignature& operator=(const CodeSignature& copy); - CodeSignature(const CodeSignature& copy); + CodeSignature& operator=(const CodeSignature& copy); + CodeSignature(const CodeSignature& copy); - virtual CodeSignature* clone(void) const override; + virtual CodeSignature* clone(void) const override; - uint32_t data_offset(void) const; + uint32_t data_offset(void) const; - uint32_t data_size(void) const; + uint32_t data_size(void) const; - void data_offset(uint32_t offset); - void data_size(uint32_t size); + void data_offset(uint32_t offset); + void data_size(uint32_t size); - virtual ~CodeSignature(void); + virtual ~CodeSignature(void); - bool operator==(const CodeSignature& rhs) const; - bool operator!=(const CodeSignature& rhs) const; + bool operator==(const CodeSignature& rhs) const; + bool operator!=(const CodeSignature& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - uint32_t data_offset_; - uint32_t data_size_; - std::vector raw_signature_; + uint32_t data_offset_; + uint32_t data_size_; + std::vector raw_signature_; }; diff --git a/include/LIEF/MachO/DataCodeEntry.hpp b/include/LIEF/MachO/DataCodeEntry.hpp index 37d7ec6..17a08bb 100644 --- a/include/LIEF/MachO/DataCodeEntry.hpp +++ b/include/LIEF/MachO/DataCodeEntry.hpp @@ -16,8 +16,6 @@ */ #ifndef LIEF_MACHO_DATA_CODE_ENTRY_H_ #define LIEF_MACHO_DATA_CODE_ENTRY_H_ -#include -#include #include #include "LIEF/visibility.h" @@ -27,6 +25,7 @@ namespace LIEF { namespace MachO { +struct data_in_code_entry; //! Interface of an entry in DataInCode class LIEF_API DataCodeEntry : public LIEF::Object { diff --git a/include/LIEF/MachO/DataInCode.hpp b/include/LIEF/MachO/DataInCode.hpp index 5967486..b302c0f 100644 --- a/include/LIEF/MachO/DataInCode.hpp +++ b/include/LIEF/MachO/DataInCode.hpp @@ -27,8 +27,8 @@ namespace LIEF { namespace MachO { - class BinaryParser; +struct linkedit_data_command; //! Interface of the LC_DATA_IN_CODE command class LIEF_API DataInCode : public LoadCommand { diff --git a/include/LIEF/MachO/DyldEnvironment.hpp b/include/LIEF/MachO/DyldEnvironment.hpp index 40470e0..7f93185 100644 --- a/include/LIEF/MachO/DyldEnvironment.hpp +++ b/include/LIEF/MachO/DyldEnvironment.hpp @@ -15,7 +15,7 @@ */ #ifndef LIEF_MACHO_DYLD_ENVIROMENT_COMMAND_H_ #define LIEF_MACHO_DYLD_ENVIROMENT_COMMAND_H_ - +#include #include #include "LIEF/types.hpp" @@ -23,9 +23,10 @@ #include "LIEF/MachO/LoadCommand.hpp" - namespace LIEF { namespace MachO { +struct dylinker_command; + class LIEF_API DyldEnvironment : public LoadCommand { public: DyldEnvironment(void); diff --git a/include/LIEF/MachO/DyldInfo.hpp b/include/LIEF/MachO/DyldInfo.hpp index 2c263e3..1cca583 100644 --- a/include/LIEF/MachO/DyldInfo.hpp +++ b/include/LIEF/MachO/DyldInfo.hpp @@ -18,23 +18,23 @@ #include #include #include -#include -#include "LIEF/BinaryStream/VectorStream.hpp" #include "LIEF/visibility.h" #include "LIEF/types.hpp" #include "LIEF/MachO/LoadCommand.hpp" #include "LIEF/MachO/type_traits.hpp" -#include "LIEF/MachO/BindingInfo.hpp" -#include "LIEF/MachO/ExportInfo.hpp" - namespace LIEF { +class VectorStream; namespace MachO { class Builder; class BinaryParser; +class BindingInfo; +class ExportInfo; + +struct dyld_info_command; //! LC_DYLD_INFO and LC_DYLD_INFO_ONLY command model class LIEF_API DyldInfo : public LoadCommand { @@ -44,238 +44,237 @@ class LIEF_API DyldInfo : public LoadCommand { friend class Builder; public: - //! @brief Tuple of ``offset`` and ``size`` - using info_t = std::pair; + //! @brief Tuple of ``offset`` and ``size`` + using info_t = std::pair; - DyldInfo(void); - DyldInfo(const dyld_info_command *dyld_info_cmd); + DyldInfo(void); + DyldInfo(const dyld_info_command *dyld_info_cmd); - DyldInfo& operator=(DyldInfo other); - DyldInfo(const DyldInfo& copy); + DyldInfo& operator=(DyldInfo other); + DyldInfo(const DyldInfo& copy); - void swap(DyldInfo& other); + void swap(DyldInfo& other); - virtual DyldInfo* clone(void) const override; + virtual DyldInfo* clone(void) const override; - virtual ~DyldInfo(void); + virtual ~DyldInfo(void); - //! @brief *Rebase* information - //! - //! Dyld rebases an image whenever dyld loads it at an address different - //! from its preferred address. The rebase information is a stream - //! of byte sized opcodes whose symbolic names start with REBASE_OPCODE_. - //! Conceptually the rebase information is a table of tuples: - //! - //! The opcodes are a compressed way to encode the table by only - //! encoding when a column changes. In addition simple patterns - //! like "every n'th offset for m times" can be encoded in a few - //! bytes. - //! - //! @see ``/usr/include/mach-o/loader.h`` - const info_t& rebase(void) const; + //! @brief *Rebase* information + //! + //! Dyld rebases an image whenever dyld loads it at an address different + //! from its preferred address. The rebase information is a stream + //! of byte sized opcodes whose symbolic names start with REBASE_OPCODE_. + //! Conceptually the rebase information is a table of tuples: + //! + //! The opcodes are a compressed way to encode the table by only + //! encoding when a column changes. In addition simple patterns + //! like "every n'th offset for m times" can be encoded in a few + //! bytes. + //! + //! @see ``/usr/include/mach-o/loader.h`` + const info_t& rebase(void) const; - //! @brief Return Rebase's opcodes as raw data - const buffer_t& rebase_opcodes(void) const; - buffer_t& rebase_opcodes(void); + //! @brief Return Rebase's opcodes as raw data + const buffer_t& rebase_opcodes(void) const; + buffer_t& rebase_opcodes(void); - //! @brief Set new opcodes - void rebase_opcodes(const buffer_t& raw); + //! @brief Set new opcodes + void rebase_opcodes(const buffer_t& raw); - //! Return the rebase opcodes in a humman-readable way - std::string show_rebases_opcodes(void) const; + //! Return the rebase opcodes in a humman-readable way + std::string show_rebases_opcodes(void) const; - //! @brief *Bind* information - //! - //! Dyld binds an image during the loading process, if the image - //! requires any pointers to be initialized to symbols in other images. - //! The rebase information is a stream of byte sized - //! opcodes whose symbolic names start with BIND_OPCODE_. - //! Conceptually the bind information is a table of tuples: - //! - //! The opcodes are a compressed way to encode the table by only - //! encoding when a column changes. In addition simple patterns - //! like for runs of pointers initialzed to the same value can be - //! encoded in a few bytes. - //! - //! @see ``/usr/include/mach-o/loader.h`` - const info_t& bind(void) const; + //! @brief *Bind* information + //! + //! Dyld binds an image during the loading process, if the image + //! requires any pointers to be initialized to symbols in other images. + //! The rebase information is a stream of byte sized + //! opcodes whose symbolic names start with BIND_OPCODE_. + //! Conceptually the bind information is a table of tuples: + //! + //! The opcodes are a compressed way to encode the table by only + //! encoding when a column changes. In addition simple patterns + //! like for runs of pointers initialzed to the same value can be + //! encoded in a few bytes. + //! + //! @see ``/usr/include/mach-o/loader.h`` + const info_t& bind(void) const; - //! @brief Return Binding's opcodes as raw data - const buffer_t& bind_opcodes(void) const; - buffer_t& bind_opcodes(void); + //! @brief Return Binding's opcodes as raw data + const buffer_t& bind_opcodes(void) const; + buffer_t& bind_opcodes(void); - //! @brief Set new opcodes - void bind_opcodes(const buffer_t& raw); + //! @brief Set new opcodes + void bind_opcodes(const buffer_t& raw); - //! Return the bind opcodes in a humman-readable way - std::string show_bind_opcodes(void) const; + //! Return the bind opcodes in a humman-readable way + std::string show_bind_opcodes(void) const; - //! @brief *Weak Bind* information - //! - //! Some C++ programs require dyld to unique symbols so that all - //! images in the process use the same copy of some code/data. - //! This step is done after binding. The content of the weak_bind - //! info is an opcode stream like the bind_info. But it is sorted - //! alphabetically by symbol name. This enable dyld to walk - //! all images with weak binding information in order and look - //! for collisions. If there are no collisions, dyld does - //! no updating. That means that some fixups are also encoded - //! in the bind_info. For instance, all calls to "operator new" - //! are first bound to libstdc++.dylib using the information - //! in bind_info. Then if some image overrides operator new - //! that is detected when the weak_bind information is processed - //! and the call to operator new is then rebound. - //! - //! @see ``/usr/include/mach-o/loader.h`` - const info_t& weak_bind(void) const; + //! @brief *Weak Bind* information + //! + //! Some C++ programs require dyld to unique symbols so that all + //! images in the process use the same copy of some code/data. + //! This step is done after binding. The content of the weak_bind + //! info is an opcode stream like the bind_info. But it is sorted + //! alphabetically by symbol name. This enable dyld to walk + //! all images with weak binding information in order and look + //! for collisions. If there are no collisions, dyld does + //! no updating. That means that some fixups are also encoded + //! in the bind_info. For instance, all calls to "operator new" + //! are first bound to libstdc++.dylib using the information + //! in bind_info. Then if some image overrides operator new + //! that is detected when the weak_bind information is processed + //! and the call to operator new is then rebound. + //! + //! @see ``/usr/include/mach-o/loader.h`` + const info_t& weak_bind(void) const; - //! @brief Return **Weak** Binding's opcodes as raw data - const buffer_t& weak_bind_opcodes(void) const; - buffer_t& weak_bind_opcodes(void); + //! @brief Return **Weak** Binding's opcodes as raw data + const buffer_t& weak_bind_opcodes(void) const; + buffer_t& weak_bind_opcodes(void); - //! @brief Set new opcodes - void weak_bind_opcodes(const buffer_t& raw); + //! @brief Set new opcodes + void weak_bind_opcodes(const buffer_t& raw); - //! Return the bind opcodes in a humman-readable way - std::string show_weak_bind_opcodes(void) const; + //! Return the bind opcodes in a humman-readable way + std::string show_weak_bind_opcodes(void) const; - //! @brief *Lazy Bind* information - //! - //! Some uses of external symbols do not need to be bound immediately. - //! Instead they can be lazily bound on first use. The lazy_bind - //! are contains a stream of BIND opcodes to bind all lazy symbols. - //! Normal use is that dyld ignores the lazy_bind section when - //! loading an image. Instead the static linker arranged for the - //! lazy pointer to initially point to a helper function which - //! pushes the offset into the lazy_bind area for the symbol - //! needing to be bound, then jumps to dyld which simply adds - //! the offset to lazy_bind_off to get the information on what - //! to bind. - //! - //! @see ``/usr/include/mach-o/loader.h`` - const info_t& lazy_bind(void) const; + //! @brief *Lazy Bind* information + //! + //! Some uses of external symbols do not need to be bound immediately. + //! Instead they can be lazily bound on first use. The lazy_bind + //! are contains a stream of BIND opcodes to bind all lazy symbols. + //! Normal use is that dyld ignores the lazy_bind section when + //! loading an image. Instead the static linker arranged for the + //! lazy pointer to initially point to a helper function which + //! pushes the offset into the lazy_bind area for the symbol + //! needing to be bound, then jumps to dyld which simply adds + //! the offset to lazy_bind_off to get the information on what + //! to bind. + //! + //! @see ``/usr/include/mach-o/loader.h`` + const info_t& lazy_bind(void) const; - //! @brief Return **Lazy** Binding's opcodes as raw data - const buffer_t& lazy_bind_opcodes(void) const; - buffer_t& lazy_bind_opcodes(void); + //! @brief Return **Lazy** Binding's opcodes as raw data + const buffer_t& lazy_bind_opcodes(void) const; + buffer_t& lazy_bind_opcodes(void); - //! @brief Set new opcodes - void lazy_bind_opcodes(const buffer_t& raw); + //! @brief Set new opcodes + void lazy_bind_opcodes(const buffer_t& raw); - //! Return the lazy opcodes in a humman-readable way - std::string show_lazy_bind_opcodes(void) const; + //! Return the lazy opcodes in a humman-readable way + std::string show_lazy_bind_opcodes(void) const; - //! @brief Iterator over BindingInfo entries - it_binding_info bindings(void); - it_const_binding_info bindings(void) const; + //! @brief Iterator over BindingInfo entries + it_binding_info bindings(void); + it_const_binding_info bindings(void) const; - //! @brief *Export* information - //! - //! The symbols exported by a dylib are encoded in a trie. This - //! is a compact representation that factors out common prefixes. - //! It also reduces LINKEDIT pages in RAM because it encodes all - //! information (name, address, flags) in one small, contiguous range. - //! The export area is a stream of nodes. The first node sequentially - //! is the start node for the trie. - //! - //! Nodes for a symbol start with a byte that is the length of - //! the exported symbol information for the string so far. - //! If there is no exported symbol, the byte is zero. If there - //! is exported info, it follows the length byte. The exported - //! info normally consists of a flags and offset both encoded - //! in uleb128. The offset is location of the content named - //! by the symbol. It is the offset from the mach_header for - //! the image. - //! - //! After the initial byte and optional exported symbol information - //! is a byte of how many edges (0-255) that this node has leaving - //! it, followed by each edge. - //! Each edge is a zero terminated cstring of the addition chars - //! in the symbol, followed by a uleb128 offset for the node that - //! edge points to. - //! - //! @see ``/usr/include/mach-o/loader.h`` - const info_t& export_info(void) const; + //! @brief *Export* information + //! + //! The symbols exported by a dylib are encoded in a trie. This + //! is a compact representation that factors out common prefixes. + //! It also reduces LINKEDIT pages in RAM because it encodes all + //! information (name, address, flags) in one small, contiguous range. + //! The export area is a stream of nodes. The first node sequentially + //! is the start node for the trie. + //! + //! Nodes for a symbol start with a byte that is the length of + //! the exported symbol information for the string so far. + //! If there is no exported symbol, the byte is zero. If there + //! is exported info, it follows the length byte. The exported + //! info normally consists of a flags and offset both encoded + //! in uleb128. The offset is location of the content named + //! by the symbol. It is the offset from the mach_header for + //! the image. + //! + //! After the initial byte and optional exported symbol information + //! is a byte of how many edges (0-255) that this node has leaving + //! it, followed by each edge. + //! Each edge is a zero terminated cstring of the addition chars + //! in the symbol, followed by a uleb128 offset for the node that + //! edge points to. + //! + //! @see ``/usr/include/mach-o/loader.h`` + const info_t& export_info(void) const; - //! @brief Iterator over ExportInfo entries - it_export_info exports(void); - it_const_export_info exports(void) const; + //! @brief Iterator over ExportInfo entries + it_export_info exports(void); + it_const_export_info exports(void) const; - //! @brief Return Export's trie as raw data - const buffer_t& export_trie(void) const; - buffer_t& export_trie(void); + //! @brief Return Export's trie as raw data + const buffer_t& export_trie(void) const; + buffer_t& export_trie(void); - //! @brief Set new trie - void export_trie(const buffer_t& raw); + //! @brief Set new trie + void export_trie(const buffer_t& raw); - //! Return the export trie in a humman-readable way - std::string show_export_trie(void) const; + //! Return the export trie in a humman-readable way + std::string show_export_trie(void) const; - void rebase(const info_t& info); - void bind(const info_t& info); - void weak_bind(const info_t& info); - void lazy_bind(const info_t& info); - void export_info(const info_t& info); + void rebase(const info_t& info); + void bind(const info_t& info); + void weak_bind(const info_t& info); + void lazy_bind(const info_t& info); + void export_info(const info_t& info); - void set_rebase_offset(uint32_t offset); - void set_rebase_size(uint32_t size); + void set_rebase_offset(uint32_t offset); + void set_rebase_size(uint32_t size); - void set_bind_offset(uint32_t offset); - void set_bind_size(uint32_t size); + void set_bind_offset(uint32_t offset); + void set_bind_size(uint32_t size); - void set_weak_bind_offset(uint32_t offset); - void set_weak_bind_size(uint32_t size); + void set_weak_bind_offset(uint32_t offset); + void set_weak_bind_size(uint32_t size); - void set_lazy_bind_offset(uint32_t offset); - void set_lazy_bind_size(uint32_t size); + void set_lazy_bind_offset(uint32_t offset); + void set_lazy_bind_size(uint32_t size); - void set_export_offset(uint32_t offset); - void set_export_size(uint32_t size); + void set_export_offset(uint32_t offset); + void set_export_size(uint32_t size); - bool operator==(const DyldInfo& rhs) const; - bool operator!=(const DyldInfo& rhs) const; + bool operator==(const DyldInfo& rhs) const; + bool operator!=(const DyldInfo& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - using bind_container_t = std::set>; + using bind_container_t = std::set>; - void show_bindings(std::ostream& os, const buffer_t& buffer, bool is_lazy = false) const; + void show_bindings(std::ostream& os, const buffer_t& buffer, bool is_lazy = false) const; - void show_trie(std::ostream& output, std::string output_prefix, VectorStream& stream, uint64_t start, uint64_t end, const std::string& prefix) const; + void show_trie(std::ostream& output, std::string output_prefix, VectorStream& stream, uint64_t start, uint64_t end, const std::string& prefix) const; - DyldInfo& update_standard_bindings(const bind_container_t& bindings); - DyldInfo& update_weak_bindings(const bind_container_t& bindings); - DyldInfo& update_lazy_bindings(const bind_container_t& bindings); + DyldInfo& update_standard_bindings(const bind_container_t& bindings); + DyldInfo& update_weak_bindings(const bind_container_t& bindings); + DyldInfo& update_lazy_bindings(const bind_container_t& bindings); - DyldInfo& update_rebase_info(void); - DyldInfo& update_binding_info(void); - DyldInfo& update_export_trie(void); + DyldInfo& update_rebase_info(void); + DyldInfo& update_binding_info(void); + DyldInfo& update_export_trie(void); - info_t rebase_; - buffer_t rebase_opcodes_; + info_t rebase_; + buffer_t rebase_opcodes_; - info_t bind_; - buffer_t bind_opcodes_; + info_t bind_; + buffer_t bind_opcodes_; - info_t weak_bind_; - buffer_t weak_bind_opcodes_; + info_t weak_bind_; + buffer_t weak_bind_opcodes_; - info_t lazy_bind_; - buffer_t lazy_bind_opcodes_; + info_t lazy_bind_; + buffer_t lazy_bind_opcodes_; - info_t export_; - buffer_t export_trie_; + info_t export_; + buffer_t export_trie_; - export_info_t export_info_; - binding_info_t binding_info_; - - Binary* binary_{nullptr}; + export_info_t export_info_; + binding_info_t binding_info_; + Binary* binary_{nullptr}; }; } diff --git a/include/LIEF/MachO/DylibCommand.hpp b/include/LIEF/MachO/DylibCommand.hpp index 3bd616d..21d1613 100644 --- a/include/LIEF/MachO/DylibCommand.hpp +++ b/include/LIEF/MachO/DylibCommand.hpp @@ -15,7 +15,8 @@ */ #ifndef LIEF_MACHO_DYLIB_COMMAND_H_ #define LIEF_MACHO_DYLIB_COMMAND_H_ - +#include +#include #include #include "LIEF/types.hpp" @@ -23,9 +24,9 @@ #include "LIEF/MachO/LoadCommand.hpp" - namespace LIEF { namespace MachO { +struct dylib_command; class LIEF_API DylibCommand : public LoadCommand { public: diff --git a/include/LIEF/MachO/DylinkerCommand.hpp b/include/LIEF/MachO/DylinkerCommand.hpp index 03b4c03..44cb197 100644 --- a/include/LIEF/MachO/DylinkerCommand.hpp +++ b/include/LIEF/MachO/DylinkerCommand.hpp @@ -15,7 +15,7 @@ */ #ifndef LIEF_MACHO_DYLINKER_COMMAND_H_ #define LIEF_MACHO_DYLINKER_COMMAND_H_ - +#include #include #include "LIEF/types.hpp" @@ -26,32 +26,34 @@ namespace LIEF { namespace MachO { +struct dylinker_command; + class LIEF_API DylinkerCommand : public LoadCommand { public: - DylinkerCommand(void); - DylinkerCommand(const dylinker_command *cmd); + DylinkerCommand(void); + DylinkerCommand(const dylinker_command *cmd); - DylinkerCommand& operator=(const DylinkerCommand& copy); - DylinkerCommand(const DylinkerCommand& copy); + DylinkerCommand& operator=(const DylinkerCommand& copy); + DylinkerCommand(const DylinkerCommand& copy); - virtual DylinkerCommand* clone(void) const override; + virtual DylinkerCommand* clone(void) const override; - virtual ~DylinkerCommand(void); + virtual ~DylinkerCommand(void); - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; - const std::string& name(void) const; + const std::string& name(void) const; - void name(const std::string& name); + void name(const std::string& name); - bool operator==(const DylinkerCommand& rhs) const; - bool operator!=(const DylinkerCommand& rhs) const; + bool operator==(const DylinkerCommand& rhs) const; + bool operator!=(const DylinkerCommand& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; private: - std::string name_; + std::string name_; }; } diff --git a/include/LIEF/MachO/DynamicSymbolCommand.hpp b/include/LIEF/MachO/DynamicSymbolCommand.hpp index 0b6da4a..4285433 100644 --- a/include/LIEF/MachO/DynamicSymbolCommand.hpp +++ b/include/LIEF/MachO/DynamicSymbolCommand.hpp @@ -15,10 +15,7 @@ */ #ifndef LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H_ #define LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H_ -#include -#include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" @@ -27,6 +24,8 @@ namespace LIEF { namespace MachO { +struct dysymtab_command; + class LIEF_API DynamicSymbolCommand : public LoadCommand { public: DynamicSymbolCommand(void); diff --git a/include/LIEF/MachO/EncryptionInfo.hpp b/include/LIEF/MachO/EncryptionInfo.hpp index 80f246f..23ad4ff 100644 --- a/include/LIEF/MachO/EncryptionInfo.hpp +++ b/include/LIEF/MachO/EncryptionInfo.hpp @@ -15,10 +15,7 @@ */ #ifndef LIEF_MACHO_ENCRYPTION_INFO_COMMAND_H_ #define LIEF_MACHO_ENCRYPTION_INFO_COMMAND_H_ -#include -#include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" @@ -27,7 +24,7 @@ namespace LIEF { namespace MachO { - +struct encryption_info_command; class LIEF_API EncryptionInfo : public LoadCommand { public: EncryptionInfo(void); diff --git a/include/LIEF/MachO/ExportInfo.hpp b/include/LIEF/MachO/ExportInfo.hpp index 4cb8a1a..1233351 100644 --- a/include/LIEF/MachO/ExportInfo.hpp +++ b/include/LIEF/MachO/ExportInfo.hpp @@ -15,10 +15,8 @@ */ #ifndef LIEF_MACHO_EXPORT_INFO_COMMAND_H_ #define LIEF_MACHO_EXPORT_INFO_COMMAND_H_ -#include #include #include -#include #include "LIEF/visibility.h" #include "LIEF/Object.hpp" @@ -26,72 +24,73 @@ #include "LIEF/MachO/enums.hpp" - namespace LIEF { namespace MachO { class BinaryParser; +class Symbol; +class DylibCommand; class LIEF_API ExportInfo : public Object { friend class BinaryParser; public: - using flag_list_t = std::vector; + using flag_list_t = std::vector; - ExportInfo(void); - ExportInfo(uint64_t address, uint64_t flags, uint64_t offset = 0); + ExportInfo(void); + ExportInfo(uint64_t address, uint64_t flags, uint64_t offset = 0); - ExportInfo& operator=(ExportInfo copy); - ExportInfo(const ExportInfo& copy); - void swap(ExportInfo& other); + ExportInfo& operator=(ExportInfo copy); + ExportInfo(const ExportInfo& copy); + void swap(ExportInfo& other); - uint64_t node_offset(void) const; + uint64_t node_offset(void) const; - uint64_t flags(void) const; - void flags(uint64_t flags); + uint64_t flags(void) const; + void flags(uint64_t flags); - flag_list_t flags_list(void) const; + flag_list_t flags_list(void) const; - bool has(EXPORT_SYMBOL_FLAGS flag) const; + bool has(EXPORT_SYMBOL_FLAGS flag) const; - EXPORT_SYMBOL_KINDS kind(void) const; + EXPORT_SYMBOL_KINDS kind(void) const; - uint64_t other(void) const; + uint64_t other(void) const; - uint64_t address(void) const; - void address(uint64_t addr); + uint64_t address(void) const; + void address(uint64_t addr); - bool has_symbol(void) const; + bool has_symbol(void) const; - const Symbol& symbol(void) const; - Symbol& symbol(void); + const Symbol& symbol(void) const; + Symbol& symbol(void); - Symbol* alias(void); - const Symbol* alias(void) const; + Symbol* alias(void); + const Symbol* alias(void) const; - DylibCommand* alias_library(void); - const DylibCommand* alias_library(void) const; + DylibCommand* alias_library(void); + const DylibCommand* alias_library(void) const; - virtual ~ExportInfo(void); + virtual ~ExportInfo(void); - bool operator==(const ExportInfo& rhs) const; - bool operator!=(const ExportInfo& rhs) const; + bool operator==(const ExportInfo& rhs) const; + bool operator!=(const ExportInfo& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportInfo& export_info); + LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportInfo& export_info); private: - uint64_t node_offset_; - uint64_t flags_; - uint64_t address_; - uint64_t other_; - Symbol* symbol_{nullptr}; + uint64_t node_offset_; + uint64_t flags_; + uint64_t address_; + uint64_t other_; + Symbol* symbol_{nullptr}; - Symbol* alias_{nullptr}; - DylibCommand* alias_location_{nullptr}; + Symbol* alias_{nullptr}; + DylibCommand* alias_location_{nullptr}; }; diff --git a/include/LIEF/MachO/FatBinary.hpp b/include/LIEF/MachO/FatBinary.hpp index fb6a17d..4237c88 100644 --- a/include/LIEF/MachO/FatBinary.hpp +++ b/include/LIEF/MachO/FatBinary.hpp @@ -15,14 +15,13 @@ */ #ifndef LIEF_MACHO_FAT_BINARY_H_ #define LIEF_MACHO_FAT_BINARY_H_ - +#include #include #include "LIEF/types.hpp" #include "LIEF/visibility.h" -#include "LIEF/MachO/Binary.hpp" - +#include "LIEF/MachO/type_traits.hpp" namespace LIEF { class Parser; @@ -30,6 +29,7 @@ namespace MachO { class Parser; class Builder; +class Binary; class LIEF_API FatBinary { diff --git a/include/LIEF/MachO/FunctionStarts.hpp b/include/LIEF/MachO/FunctionStarts.hpp index e3439e3..98136a4 100644 --- a/include/LIEF/MachO/FunctionStarts.hpp +++ b/include/LIEF/MachO/FunctionStarts.hpp @@ -27,52 +27,53 @@ namespace LIEF { namespace MachO { +struct linkedit_data_command; class LIEF_API FunctionStarts : public LoadCommand { public: - FunctionStarts(void); - FunctionStarts(const linkedit_data_command *cmd); + FunctionStarts(void); + FunctionStarts(const linkedit_data_command *cmd); - FunctionStarts& operator=(const FunctionStarts& copy); - FunctionStarts(const FunctionStarts& copy); + FunctionStarts& operator=(const FunctionStarts& copy); + FunctionStarts(const FunctionStarts& copy); - virtual FunctionStarts* clone(void) const override; + virtual FunctionStarts* clone(void) const override; - //! @brief Offset in the binary where *start functions* are located - uint32_t data_offset(void) const; + //! @brief Offset in the binary where *start functions* are located + uint32_t data_offset(void) const; - //! @brief Size of the functions list in the binary - uint32_t data_size(void) const; + //! @brief Size of the functions list in the binary + uint32_t data_size(void) const; - //! @brief Addresses of every function entry point in the executable. - //! - //! This allows for functions to exist that have no entries in the symbol table. - //! - //! @warning The address is relative to the ``__TEXT`` segment - const std::vector& functions(void) const; + //! @brief Addresses of every function entry point in the executable. + //! + //! This allows for functions to exist that have no entries in the symbol table. + //! + //! @warning The address is relative to the ``__TEXT`` segment + const std::vector& functions(void) const; - std::vector& functions(void); + std::vector& functions(void); - //! @brief Add a new function - void add_function(uint64_t address); + //! @brief Add a new function + void add_function(uint64_t address); - void data_offset(uint32_t offset); - void data_size(uint32_t size); - void functions(const std::vector& funcs); + void data_offset(uint32_t offset); + void data_size(uint32_t size); + void functions(const std::vector& funcs); - virtual ~FunctionStarts(void); + virtual ~FunctionStarts(void); - bool operator==(const FunctionStarts& rhs) const; - bool operator!=(const FunctionStarts& rhs) const; + bool operator==(const FunctionStarts& rhs) const; + bool operator!=(const FunctionStarts& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - uint32_t data_offset_; - uint32_t data_size_; - std::vector functions_; + uint32_t data_offset_; + uint32_t data_size_; + std::vector functions_; }; diff --git a/include/LIEF/MachO/Header.hpp b/include/LIEF/MachO/Header.hpp index 0b3902d..f689f1f 100644 --- a/include/LIEF/MachO/Header.hpp +++ b/include/LIEF/MachO/Header.hpp @@ -24,10 +24,13 @@ #include "LIEF/Abstract/enums.hpp" -#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/enums.hpp" namespace LIEF { namespace MachO { +struct mach_header_64; +struct mach_header; + class LIEF_API Header : public Object { public: using flags_list_t = std::set; diff --git a/include/LIEF/MachO/LoadCommand.hpp b/include/LIEF/MachO/LoadCommand.hpp index 869f829..a671ee9 100644 --- a/include/LIEF/MachO/LoadCommand.hpp +++ b/include/LIEF/MachO/LoadCommand.hpp @@ -23,12 +23,12 @@ #include "LIEF/Object.hpp" #include "LIEF/visibility.h" -#include "LIEF/MachO/Structures.hpp" - +#include "LIEF/MachO/enums.hpp" namespace LIEF { namespace MachO { class Builder; +struct load_command; class LIEF_API LoadCommand : public Object { friend class Builder; public: diff --git a/include/LIEF/MachO/MainCommand.hpp b/include/LIEF/MachO/MainCommand.hpp index 9688ee9..7139a33 100644 --- a/include/LIEF/MachO/MainCommand.hpp +++ b/include/LIEF/MachO/MainCommand.hpp @@ -15,47 +15,44 @@ */ #ifndef LIEF_MACHO_MAIN_COMMAND_H_ #define LIEF_MACHO_MAIN_COMMAND_H_ - #include -#include #include "LIEF/visibility.h" -#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/enums.hpp" #include "LIEF/MachO/LoadCommand.hpp" namespace LIEF { namespace MachO { - +struct entry_point_command; class LIEF_API MainCommand : public LoadCommand { public: - MainCommand(void); - MainCommand(const entry_point_command *cmd); + MainCommand(void); + MainCommand(const entry_point_command *cmd); - MainCommand& operator=(const MainCommand& copy); - MainCommand(const MainCommand& copy); + MainCommand& operator=(const MainCommand& copy); + MainCommand(const MainCommand& copy); - virtual MainCommand* clone(void) const override; + virtual MainCommand* clone(void) const override; - virtual ~MainCommand(void); + virtual ~MainCommand(void); - uint64_t entrypoint(void) const; - uint64_t stack_size(void) const; + uint64_t entrypoint(void) const; + uint64_t stack_size(void) const; - void entrypoint(uint64_t entrypoint); - void stack_size(uint64_t stacksize); + void entrypoint(uint64_t entrypoint); + void stack_size(uint64_t stacksize); - bool operator==(const MainCommand& rhs) const; - bool operator!=(const MainCommand& rhs) const; + bool operator==(const MainCommand& rhs) const; + bool operator!=(const MainCommand& rhs) const; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; private: - uint64_t entrypoint_; - uint64_t stackSize_; - + uint64_t entrypoint_; + uint64_t stackSize_; }; } diff --git a/include/LIEF/MachO/Parser.hpp b/include/LIEF/MachO/Parser.hpp index 996a288..9403c53 100644 --- a/include/LIEF/MachO/Parser.hpp +++ b/include/LIEF/MachO/Parser.hpp @@ -16,43 +16,44 @@ #ifndef LIEF_MACHO_PARSER_H_ #define LIEF_MACHO_PARSER_H_ #include -#include +#include +#include #include "LIEF/types.hpp" #include "LIEF/visibility.h" -#include "LIEF/BinaryStream/VectorStream.hpp" #include "LIEF/Abstract/Parser.hpp" #include "LIEF/MachO/ParserConfig.hpp" -#include "LIEF/MachO/Structures.hpp" -#include "LIEF/MachO/Binary.hpp" -#include "LIEF/MachO/FatBinary.hpp" - namespace LIEF { +class VectorStream; + namespace MachO { +class Binary; +class FatBinary; + class LIEF_API Parser : public LIEF::Parser { public: - Parser& operator=(const Parser& copy) = delete; - Parser(const Parser& copy) = delete; + Parser& operator=(const Parser& copy) = delete; + Parser(const Parser& copy) = delete; - ~Parser(void); + ~Parser(void); - static std::unique_ptr parse(const std::string& filename, const ParserConfig& conf = ParserConfig::deep()); - static std::unique_ptr parse(const std::vector& data, const std::string& name = "", const ParserConfig& conf = ParserConfig::deep()); + static std::unique_ptr parse(const std::string& filename, const ParserConfig& conf = ParserConfig::deep()); + static std::unique_ptr parse(const std::vector& data, const std::string& name = "", const ParserConfig& conf = ParserConfig::deep()); private: - Parser(const std::string& file, const ParserConfig& conf); - Parser(const std::vector& data, const std::string& name, const ParserConfig& conf); - Parser(void); + Parser(const std::string& file, const ParserConfig& conf); + Parser(const std::vector& data, const std::string& name, const ParserConfig& conf); + Parser(void); - void build(void); - void build_fat(void); + void build(void); + void build_fat(void); - std::unique_ptr stream_; - std::vector binaries_; - ParserConfig config_; + std::unique_ptr stream_; + std::vector binaries_; + ParserConfig config_; }; } } diff --git a/include/LIEF/MachO/ParserConfig.hpp b/include/LIEF/MachO/ParserConfig.hpp index 6a3771b..8a08ad3 100644 --- a/include/LIEF/MachO/ParserConfig.hpp +++ b/include/LIEF/MachO/ParserConfig.hpp @@ -22,36 +22,36 @@ namespace MachO { class LIEF_API ParserConfig { public: - ParserConfig(void); - ParserConfig& operator=(const ParserConfig&); - ParserConfig(const ParserConfig&); - ~ParserConfig(void); + ParserConfig(void); + ParserConfig& operator=(const ParserConfig&); + ParserConfig(const ParserConfig&); + ~ParserConfig(void); - //! @brief Return a configuration so that the all objects supported by - //! LIEF are parsed - //! - //! With this configuration: - //! * ``parse_dyldinfo_deeply`` is set to ``true`` - static ParserConfig deep(void); + //! @brief Return a configuration so that the all objects supported by + //! LIEF are parsed + //! + //! With this configuration: + //! * ``parse_dyldinfo_deeply`` is set to ``true`` + static ParserConfig deep(void); - //! Return a configuration so that the parsing is quick - //! - //! With this configuration: - //! * ``parse_dyldinfo_deeply`` is set to ``false`` - static ParserConfig quick(void); + //! Return a configuration so that the parsing is quick + //! + //! With this configuration: + //! * ``parse_dyldinfo_deeply`` is set to ``false`` + static ParserConfig quick(void); - //! @brief If ``flag`` is set to ``true``, - //! Exports, Bindings and Rebases opcodes are - //! parsed. - //! - //! @warning Enabling this flag can slow down the parsing - ParserConfig& parse_dyldinfo_deeply(bool flag); + //! @brief If ``flag`` is set to ``true``, + //! Exports, Bindings and Rebases opcodes are + //! parsed. + //! + //! @warning Enabling this flag can slow down the parsing + ParserConfig& parse_dyldinfo_deeply(bool flag); - //! @brief Whether or not bindings, exports, and rebases are parsed - bool parse_dyldinfo_deeply(void) const; + //! @brief Whether or not bindings, exports, and rebases are parsed + bool parse_dyldinfo_deeply(void) const; private: - bool dyldinfo_deeply_; + bool dyldinfo_deeply_; }; } diff --git a/include/LIEF/MachO/RPathCommand.hpp b/include/LIEF/MachO/RPathCommand.hpp index d8ef65b..65f2fa7 100644 --- a/include/LIEF/MachO/RPathCommand.hpp +++ b/include/LIEF/MachO/RPathCommand.hpp @@ -25,31 +25,32 @@ namespace LIEF { namespace MachO { +struct rpath_command; class LIEF_API RPathCommand : public LoadCommand { public: - RPathCommand(void); - RPathCommand(const rpath_command *rpathCmd); + RPathCommand(void); + RPathCommand(const rpath_command *rpathCmd); - RPathCommand& operator=(const RPathCommand& copy); - RPathCommand(const RPathCommand& copy); + RPathCommand& operator=(const RPathCommand& copy); + RPathCommand(const RPathCommand& copy); - virtual RPathCommand* clone(void) const override; + virtual RPathCommand* clone(void) const override; - virtual ~RPathCommand(void); + virtual ~RPathCommand(void); - const std::string& path(void) const; - void path(const std::string& path); + const std::string& path(void) const; + void path(const std::string& path); - bool operator==(const RPathCommand& rhs) const; - bool operator!=(const RPathCommand& rhs) const; + bool operator==(const RPathCommand& rhs) const; + bool operator!=(const RPathCommand& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - std::string path_; + std::string path_; }; } diff --git a/include/LIEF/MachO/RelocationDyld.hpp b/include/LIEF/MachO/RelocationDyld.hpp index 043a684..05dc2bd 100644 --- a/include/LIEF/MachO/RelocationDyld.hpp +++ b/include/LIEF/MachO/RelocationDyld.hpp @@ -15,16 +15,11 @@ */ #ifndef LIEF_MACHO_RELOCATION_DYLD_COMMAND_H_ #define LIEF_MACHO_RELOCATION_DYLD_COMMAND_H_ -#include -#include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" -#include "LIEF/Object.hpp" -#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/Relocation.hpp" namespace LIEF { @@ -37,42 +32,41 @@ class LIEF_API RelocationDyld : public Relocation { friend class BinaryParser; public: - using Relocation::Relocation; - RelocationDyld(void); + using Relocation::Relocation; + RelocationDyld(void); - RelocationDyld& operator=(const RelocationDyld&); - RelocationDyld(const RelocationDyld&); + RelocationDyld& operator=(const RelocationDyld&); + RelocationDyld(const RelocationDyld&); - virtual ~RelocationDyld(void); + virtual ~RelocationDyld(void); - virtual Relocation* clone(void) const override; + virtual Relocation* clone(void) const override; - //! @brief Indicates whether the item containing the address to be - //! relocated is part of a CPU instruction that uses PC-relative addressing. - //! - //! For addresses contained in PC-relative instructions, the CPU adds the address of - //! the instruction to the address contained in the instruction. - virtual bool is_pc_relative(void) const override; + //! @brief Indicates whether the item containing the address to be + //! relocated is part of a CPU instruction that uses PC-relative addressing. + //! + //! For addresses contained in PC-relative instructions, the CPU adds the address of + //! the instruction to the address contained in the instruction. + virtual bool is_pc_relative(void) const override; - //! @brief Origin of the relocation - virtual RELOCATION_ORIGINS origin(void) const override; + //! @brief Origin of the relocation + virtual RELOCATION_ORIGINS origin(void) const override; - virtual void pc_relative(bool val) override; + virtual void pc_relative(bool val) override; - bool operator==(const RelocationDyld& rhs) const; - bool operator!=(const RelocationDyld& rhs) const; + bool operator==(const RelocationDyld& rhs) const; + bool operator!=(const RelocationDyld& rhs) const; - bool operator<(const RelocationDyld& rhs) const; - bool operator>=(const RelocationDyld& rhs) const; + bool operator<(const RelocationDyld& rhs) const; + bool operator>=(const RelocationDyld& rhs) const; - bool operator>(const RelocationDyld& rhs) const; - bool operator<=(const RelocationDyld& rhs) const; + bool operator>(const RelocationDyld& rhs) const; + bool operator<=(const RelocationDyld& rhs) const; - virtual void accept(Visitor& visitor) const override; - - virtual std::ostream& print(std::ostream& os) const override; + virtual void accept(Visitor& visitor) const override; + virtual std::ostream& print(std::ostream& os) const override; }; } diff --git a/include/LIEF/MachO/RelocationObject.hpp b/include/LIEF/MachO/RelocationObject.hpp index eebcd3d..d67abf6 100644 --- a/include/LIEF/MachO/RelocationObject.hpp +++ b/include/LIEF/MachO/RelocationObject.hpp @@ -15,80 +15,77 @@ */ #ifndef LIEF_MACHO_RELOCATION_OBJECT_COMMAND_H_ #define LIEF_MACHO_RELOCATION_OBJECT_COMMAND_H_ -#include -#include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" -#include "LIEF/Object.hpp" -#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/Relocation.hpp" namespace LIEF { namespace MachO { class BinaryParser; +struct relocation_info; +struct scattered_relocation_info; class LIEF_API RelocationObject : public Relocation { friend class BinaryParser; public: - using Relocation::Relocation; - RelocationObject(void); - RelocationObject(const relocation_info *relocinfo); - RelocationObject(const scattered_relocation_info *scattered_relocinfo); + using Relocation::Relocation; + RelocationObject(void); + RelocationObject(const relocation_info *relocinfo); + RelocationObject(const scattered_relocation_info *scattered_relocinfo); - RelocationObject& operator=(RelocationObject other); - RelocationObject(const RelocationObject& other); + RelocationObject& operator=(RelocationObject other); + RelocationObject(const RelocationObject& other); - void swap(RelocationObject& other); + void swap(RelocationObject& other); - virtual ~RelocationObject(void); + virtual ~RelocationObject(void); - virtual RelocationObject* clone(void) const override; + virtual RelocationObject* clone(void) const override; - virtual bool is_pc_relative(void) const override; + virtual bool is_pc_relative(void) const override; - virtual size_t size(void) const override; + virtual size_t size(void) const override; - virtual uint64_t address(void) const override; + virtual uint64_t address(void) const override; - //! @brief ``true`` if the relocation is a scattered one - bool is_scattered(void) const; + //! @brief ``true`` if the relocation is a scattered one + bool is_scattered(void) const; - //! @brief For **scattered** relocations, - //! The address of the relocatable expression for the item in the file that needs - //! to be updated if the address is changed. - //! - //! For relocatable expressions with the difference of two section addresses, - //! the address from which to subtract (in mathematical terms, the minuend) - //! is contained in the first relocation entry and the address to subtract (the subtrahend) - //! is contained in the second relocation entry. - int32_t value(void) const; + //! @brief For **scattered** relocations, + //! The address of the relocatable expression for the item in the file that needs + //! to be updated if the address is changed. + //! + //! For relocatable expressions with the difference of two section addresses, + //! the address from which to subtract (in mathematical terms, the minuend) + //! is contained in the first relocation entry and the address to subtract (the subtrahend) + //! is contained in the second relocation entry. + int32_t value(void) const; - //! @brief Origin of the relocation - virtual RELOCATION_ORIGINS origin(void) const override; + //! @brief Origin of the relocation + virtual RELOCATION_ORIGINS origin(void) const override; - virtual void pc_relative(bool val) override; - virtual void size(size_t size) override; + virtual void pc_relative(bool val) override; + virtual void size(size_t size) override; - void value(int32_t value); + void value(int32_t value); - bool operator==(const RelocationObject& rhs) const; - bool operator!=(const RelocationObject& rhs) const; + bool operator==(const RelocationObject& rhs) const; + bool operator!=(const RelocationObject& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - bool is_pcrel_; - bool is_scattered_; - int32_t value_; + bool is_pcrel_; + bool is_scattered_; + int32_t value_; }; } diff --git a/include/LIEF/MachO/Section.hpp b/include/LIEF/MachO/Section.hpp index 489beb6..f25b7c5 100644 --- a/include/LIEF/MachO/Section.hpp +++ b/include/LIEF/MachO/Section.hpp @@ -27,7 +27,6 @@ #include "LIEF/MachO/LoadCommand.hpp" #include "LIEF/MachO/type_traits.hpp" -#include "LIEF/MachO/Relocation.hpp" namespace LIEF { namespace MachO { @@ -36,6 +35,9 @@ class BinaryParser; class SegmentCommand; class Binary; +struct section_32; +struct section_64; + class LIEF_API Section : public LIEF::Section { friend class BinaryParser; diff --git a/include/LIEF/MachO/SegmentCommand.hpp b/include/LIEF/MachO/SegmentCommand.hpp index 1298cf9..d02e477 100644 --- a/include/LIEF/MachO/SegmentCommand.hpp +++ b/include/LIEF/MachO/SegmentCommand.hpp @@ -19,20 +19,23 @@ #include #include #include -#include #include "LIEF/types.hpp" #include "LIEF/visibility.h" #include "LIEF/MachO/type_traits.hpp" #include "LIEF/MachO/LoadCommand.hpp" -#include "LIEF/MachO/Section.hpp" namespace LIEF { namespace MachO { + class BinaryParser; class Binary; +class Section; + +struct segment_command_32; +struct segment_command_64; //! @class SegmentCommand //! @brief Class which represent a MachO Segment @@ -114,21 +117,13 @@ class LIEF_API SegmentCommand : public LoadCommand { //! @brief Indicates the offset in this file of the data to be mapped at virtualAddress_. uint64_t fileOffset_{0}; - uint64_t fileSize_{0}; - uint32_t maxProtection_{0}; - uint32_t initProtection_{0}; - uint32_t nbSections_{0}; - uint32_t flags_{0}; - content_t data_; - sections_t sections_; - relocations_t relocations_; diff --git a/include/LIEF/MachO/SegmentSplitInfo.hpp b/include/LIEF/MachO/SegmentSplitInfo.hpp index 1aafe48..279855b 100644 --- a/include/LIEF/MachO/SegmentSplitInfo.hpp +++ b/include/LIEF/MachO/SegmentSplitInfo.hpp @@ -15,10 +15,8 @@ */ #ifndef LIEF_MACHO_SEGMENT_SPLIT_INFO_H_ #define LIEF_MACHO_SEGMENT_SPLIT_INFO_H_ -#include #include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" @@ -27,39 +25,40 @@ namespace LIEF { namespace MachO { - class BinaryParser; +struct linkedit_data_command; + class LIEF_API SegmentSplitInfo : public LoadCommand { friend class BinaryParser; public: - SegmentSplitInfo(void); - SegmentSplitInfo(const linkedit_data_command *cmd); + SegmentSplitInfo(void); + SegmentSplitInfo(const linkedit_data_command *cmd); - SegmentSplitInfo& operator=(const SegmentSplitInfo& copy); - SegmentSplitInfo(const SegmentSplitInfo& copy); + SegmentSplitInfo& operator=(const SegmentSplitInfo& copy); + SegmentSplitInfo(const SegmentSplitInfo& copy); - virtual SegmentSplitInfo* clone(void) const override; + virtual SegmentSplitInfo* clone(void) const override; - uint32_t data_offset(void) const; - uint32_t data_size(void) const; + uint32_t data_offset(void) const; + uint32_t data_size(void) const; - void data_offset(uint32_t offset); - void data_size(uint32_t size); + void data_offset(uint32_t offset); + void data_size(uint32_t size); - virtual ~SegmentSplitInfo(void); + virtual ~SegmentSplitInfo(void); - bool operator==(const SegmentSplitInfo& rhs) const; - bool operator!=(const SegmentSplitInfo& rhs) const; + bool operator==(const SegmentSplitInfo& rhs) const; + bool operator!=(const SegmentSplitInfo& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - uint32_t data_offset_; - uint32_t data_size_; - std::vector raw_; + uint32_t data_offset_; + uint32_t data_size_; + std::vector raw_; }; diff --git a/include/LIEF/MachO/SourceVersion.hpp b/include/LIEF/MachO/SourceVersion.hpp index 0f48610..7e8675d 100644 --- a/include/LIEF/MachO/SourceVersion.hpp +++ b/include/LIEF/MachO/SourceVersion.hpp @@ -15,8 +15,6 @@ */ #ifndef LIEF_MACHO_SOURCE_VERSION_COMMAND_H_ #define LIEF_MACHO_SOURCE_VERSION_COMMAND_H_ -#include -#include #include #include @@ -27,36 +25,36 @@ namespace LIEF { namespace MachO { - +struct source_version_command; class LIEF_API SourceVersion : public LoadCommand { public: - //! @brief Version is an array of **5** integers - using version_t = std::array; + //! @brief Version is an array of **5** integers + using version_t = std::array; - SourceVersion(void); - SourceVersion(const source_version_command *version_cmd); + SourceVersion(void); + SourceVersion(const source_version_command *version_cmd); - SourceVersion& operator=(const SourceVersion& copy); - SourceVersion(const SourceVersion& copy); + SourceVersion& operator=(const SourceVersion& copy); + SourceVersion(const SourceVersion& copy); - virtual SourceVersion* clone(void) const override; + virtual SourceVersion* clone(void) const override; - virtual ~SourceVersion(void); + virtual ~SourceVersion(void); - //! @brief Return the version as an array - const SourceVersion::version_t& version(void) const; - void version(const SourceVersion::version_t& version); + //! @brief Return the version as an array + const SourceVersion::version_t& version(void) const; + void version(const SourceVersion::version_t& version); - bool operator==(const SourceVersion& rhs) const; - bool operator!=(const SourceVersion& rhs) const; + bool operator==(const SourceVersion& rhs) const; + bool operator!=(const SourceVersion& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - SourceVersion::version_t version_; + SourceVersion::version_t version_; }; } diff --git a/include/LIEF/MachO/SubFramework.hpp b/include/LIEF/MachO/SubFramework.hpp index cb2be4c..b9d4051 100644 --- a/include/LIEF/MachO/SubFramework.hpp +++ b/include/LIEF/MachO/SubFramework.hpp @@ -16,9 +16,7 @@ #ifndef LIEF_MACHO_SUB_FRAMEWORK_H_ #define LIEF_MACHO_SUB_FRAMEWORK_H_ #include -#include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" @@ -30,6 +28,8 @@ namespace MachO { class BinaryParser; +struct sub_framework_command; + class LIEF_API SubFramework : public LoadCommand { friend class BinaryParser; public: diff --git a/include/LIEF/MachO/Symbol.hpp b/include/LIEF/MachO/Symbol.hpp index f228892..20eeac8 100644 --- a/include/LIEF/MachO/Symbol.hpp +++ b/include/LIEF/MachO/Symbol.hpp @@ -24,15 +24,18 @@ #include "LIEF/Abstract/Symbol.hpp" #include "LIEF/MachO/LoadCommand.hpp" - -#include "LIEF/MachO/ExportInfo.hpp" -#include "LIEF/MachO/BindingInfo.hpp" - +#include "LIEF/MachO/enums.hpp" namespace LIEF { namespace MachO { class BinaryParser; +class BindingInfo; +class ExportInfo; +class DylibCommand; + +struct nlist_32; +struct nlist_64; class LIEF_API Symbol : public LIEF::Symbol { diff --git a/include/LIEF/MachO/SymbolCommand.hpp b/include/LIEF/MachO/SymbolCommand.hpp index ef334dd..f059ca1 100644 --- a/include/LIEF/MachO/SymbolCommand.hpp +++ b/include/LIEF/MachO/SymbolCommand.hpp @@ -15,8 +15,6 @@ */ #ifndef LIEF_MACHO_SYMBOL_COMMAND_H_ #define LIEF_MACHO_SYMBOL_COMMAND_H_ - -#include #include #include "LIEF/visibility.h" @@ -26,47 +24,49 @@ namespace LIEF { namespace MachO { +struct symtab_command; + class LIEF_API SymbolCommand : public LoadCommand { public: - SymbolCommand(void); - SymbolCommand(const symtab_command *command); + SymbolCommand(void); + SymbolCommand(const symtab_command *command); - SymbolCommand& operator=(const SymbolCommand& copy); - SymbolCommand(const SymbolCommand& copy); + SymbolCommand& operator=(const SymbolCommand& copy); + SymbolCommand(const SymbolCommand& copy); - virtual SymbolCommand* clone(void) const override; + virtual SymbolCommand* clone(void) const override; - virtual ~SymbolCommand(void); + virtual ~SymbolCommand(void); - //! Offset from the start of the file to the n_list associated with the command - uint32_t symbol_offset(void) const; + //! Offset from the start of the file to the n_list associated with the command + uint32_t symbol_offset(void) const; - //! Number of symbols registered - uint32_t numberof_symbols(void) const; + //! Number of symbols registered + uint32_t numberof_symbols(void) const; - //! Offset from the start of the file to the string table - uint32_t strings_offset(void) const; + //! Offset from the start of the file to the string table + uint32_t strings_offset(void) const; - //! Size of the size string table - uint32_t strings_size(void) const; + //! Size of the size string table + uint32_t strings_size(void) const; - void symbol_offset(uint32_t offset); - void numberof_symbols(uint32_t nb); - void strings_offset(uint32_t offset); - void strings_size(uint32_t size); + void symbol_offset(uint32_t offset); + void numberof_symbols(uint32_t nb); + void strings_offset(uint32_t offset); + void strings_size(uint32_t size); - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - bool operator==(const SymbolCommand& rhs) const; - bool operator!=(const SymbolCommand& rhs) const; + bool operator==(const SymbolCommand& rhs) const; + bool operator!=(const SymbolCommand& rhs) const; private: - uint32_t symbolOffset_; - uint32_t numberOfSymbols_; - uint32_t stringsOffset_; - uint32_t stringsSize_; + uint32_t symbolOffset_; + uint32_t numberOfSymbols_; + uint32_t stringsOffset_; + uint32_t stringsSize_; }; } diff --git a/include/LIEF/MachO/ThreadCommand.hpp b/include/LIEF/MachO/ThreadCommand.hpp index 1d6874e..9a05c97 100644 --- a/include/LIEF/MachO/ThreadCommand.hpp +++ b/include/LIEF/MachO/ThreadCommand.hpp @@ -15,10 +15,8 @@ */ #ifndef LIEF_MACHO_THREAD_COMMAND_H_ #define LIEF_MACHO_THREAD_COMMAND_H_ -#include #include #include -#include #include "LIEF/visibility.h" #include "LIEF/types.hpp" @@ -29,47 +27,48 @@ namespace LIEF { namespace MachO { class BinaryParser; +struct thread_command; class LIEF_API ThreadCommand : public LoadCommand { friend class BinaryParser; public: - ThreadCommand(void); - ThreadCommand(const thread_command *cmd, CPU_TYPES arch=CPU_TYPES::CPU_TYPE_ANY); - ThreadCommand(uint32_t flavor, uint32_t count, CPU_TYPES arch=CPU_TYPES::CPU_TYPE_ANY); + ThreadCommand(void); + ThreadCommand(const thread_command *cmd, CPU_TYPES arch=CPU_TYPES::CPU_TYPE_ANY); + ThreadCommand(uint32_t flavor, uint32_t count, CPU_TYPES arch=CPU_TYPES::CPU_TYPE_ANY); - ThreadCommand& operator=(const ThreadCommand& copy); - ThreadCommand(const ThreadCommand& copy); + ThreadCommand& operator=(const ThreadCommand& copy); + ThreadCommand(const ThreadCommand& copy); - virtual ThreadCommand* clone(void) const override; + virtual ThreadCommand* clone(void) const override; - virtual ~ThreadCommand(void); + virtual ~ThreadCommand(void); - uint32_t flavor(void) const; - uint32_t count(void) const; - CPU_TYPES architecture(void) const; + uint32_t flavor(void) const; + uint32_t count(void) const; + CPU_TYPES architecture(void) const; - const std::vector& state(void) const; - std::vector& state(void); + const std::vector& state(void) const; + std::vector& state(void); - uint64_t pc(void) const; + uint64_t pc(void) const; - void state(const std::vector& state); - void flavor(uint32_t flavor); - void count(uint32_t count); - void architecture(CPU_TYPES arch); + void state(const std::vector& state); + void flavor(uint32_t flavor); + void count(uint32_t count); + void architecture(CPU_TYPES arch); - bool operator==(const ThreadCommand& rhs) const; - bool operator!=(const ThreadCommand& rhs) const; + bool operator==(const ThreadCommand& rhs) const; + bool operator!=(const ThreadCommand& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - uint32_t flavor_; - uint32_t count_; - CPU_TYPES architecture_; - std::vector state_; + uint32_t flavor_; + uint32_t count_; + CPU_TYPES architecture_; + std::vector state_; }; diff --git a/include/LIEF/MachO/UUIDCommand.hpp b/include/LIEF/MachO/UUIDCommand.hpp index 1ba3e6f..0791c80 100644 --- a/include/LIEF/MachO/UUIDCommand.hpp +++ b/include/LIEF/MachO/UUIDCommand.hpp @@ -15,8 +15,6 @@ */ #ifndef LIEF_MACHO_UUID_COMMAND_H_ #define LIEF_MACHO_UUID_COMMAND_H_ -#include -#include #include #include @@ -27,32 +25,35 @@ namespace LIEF { namespace MachO { + +struct uuid_command; + using uuid_t = std::array; class LIEF_API UUIDCommand : public LoadCommand { public: - UUIDCommand(void); - UUIDCommand(const uuid_command *uuidCmd); + UUIDCommand(void); + UUIDCommand(const uuid_command *uuidCmd); - UUIDCommand& operator=(const UUIDCommand& copy); - UUIDCommand(const UUIDCommand& copy); + UUIDCommand& operator=(const UUIDCommand& copy); + UUIDCommand(const UUIDCommand& copy); - virtual UUIDCommand* clone(void) const override; + virtual UUIDCommand* clone(void) const override; - virtual ~UUIDCommand(void); + virtual ~UUIDCommand(void); - uuid_t uuid(void) const; - void uuid(const uuid_t& uuid); + uuid_t uuid(void) const; + void uuid(const uuid_t& uuid); - bool operator==(const UUIDCommand& rhs) const; - bool operator!=(const UUIDCommand& rhs) const; + bool operator==(const UUIDCommand& rhs) const; + bool operator!=(const UUIDCommand& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - uuid_t uuid_; + uuid_t uuid_; }; } diff --git a/include/LIEF/MachO/VersionMin.hpp b/include/LIEF/MachO/VersionMin.hpp index 4a7bbde..3d7987c 100644 --- a/include/LIEF/MachO/VersionMin.hpp +++ b/include/LIEF/MachO/VersionMin.hpp @@ -15,8 +15,6 @@ */ #ifndef LIEF_MACHO_VERSION_MIN_COMMAND_H_ #define LIEF_MACHO_VERSION_MIN_COMMAND_H_ -#include -#include #include #include @@ -27,41 +25,42 @@ namespace LIEF { namespace MachO { +struct version_min_command; class LIEF_API VersionMin : public LoadCommand { public: - //! @brief Version is an array of **3** integers - using version_t = std::array; + //! @brief Version is an array of **3** integers + using version_t = std::array; - VersionMin(void); - VersionMin(const version_min_command *version_cmd); + VersionMin(void); + VersionMin(const version_min_command *version_cmd); - VersionMin& operator=(const VersionMin& copy); - VersionMin(const VersionMin& copy); + VersionMin& operator=(const VersionMin& copy); + VersionMin(const VersionMin& copy); - virtual VersionMin* clone(void) const override; + virtual VersionMin* clone(void) const override; - virtual ~VersionMin(void); + virtual ~VersionMin(void); - //! @brief Return the version as an array - const VersionMin::version_t& version(void) const; - void version(const VersionMin::version_t& version); + //! @brief Return the version as an array + const VersionMin::version_t& version(void) const; + void version(const VersionMin::version_t& version); - //! @brief Return the sdk as an array - const VersionMin::version_t& sdk(void) const; - void sdk(const VersionMin::version_t& sdk); + //! @brief Return the sdk as an array + const VersionMin::version_t& sdk(void) const; + void sdk(const VersionMin::version_t& sdk); - bool operator==(const VersionMin& rhs) const; - bool operator!=(const VersionMin& rhs) const; + bool operator==(const VersionMin& rhs) const; + bool operator!=(const VersionMin& rhs) const; - virtual void accept(Visitor& visitor) const override; + virtual void accept(Visitor& visitor) const override; - virtual std::ostream& print(std::ostream& os) const override; + virtual std::ostream& print(std::ostream& os) const override; private: - VersionMin::version_t version_; - VersionMin::version_t sdk_; + VersionMin::version_t version_; + VersionMin::version_t sdk_; }; } diff --git a/include/LIEF/MachO/hash.hpp b/include/LIEF/MachO/hash.hpp index 58c7c74..cc4ab45 100644 --- a/include/LIEF/MachO/hash.hpp +++ b/include/LIEF/MachO/hash.hpp @@ -18,11 +18,42 @@ #include "LIEF/visibility.h" #include "LIEF/hash.hpp" -#include "LIEF/MachO.hpp" namespace LIEF { namespace MachO { +class Binary; +class Header; +class LoadCommand; +class UUIDCommand; +class SymbolCommand; +class SegmentCommand; +class Section; +class MainCommand; +class DynamicSymbolCommand; +class DylinkerCommand; +class DylibCommand; +class ThreadCommand; +class RPathCommand; +class Symbol; +class Relocation; +class RelocationObject; +class RelocationDyld; +class BindingInfo; +class ExportInfo; +class FunctionStarts; +class CodeSignature; +class DataInCode; +class DataCodeEntry; +class VersionMin; +class SourceVersion; +class SegmentSplitInfo; +class SubFramework; +class DyldEnvironment; +class EncryptionInfo; +class BuildVersion; +class BuildToolVersion; + class LIEF_API Hash : public LIEF::Hash { public: static size_t hash(const Object& obj); diff --git a/include/LIEF/MachO/json.hpp b/include/LIEF/MachO/json.hpp index b407a52..b4f0b2f 100644 --- a/include/LIEF/MachO/json.hpp +++ b/include/LIEF/MachO/json.hpp @@ -27,10 +27,43 @@ namespace LIEF { namespace MachO { + +class Binary; +class Header; +class LoadCommand; +class UUIDCommand; +class SymbolCommand; +class SegmentCommand; +class Section; +class MainCommand; +class DynamicSymbolCommand; +class DylinkerCommand; +class DylibCommand; +class ThreadCommand; +class RPathCommand; +class Symbol; +class Relocation; +class RelocationObject; +class RelocationDyld; +class BindingInfo; +class ExportInfo; +class FunctionStarts; +class CodeSignature; +class DataInCode; +class DataCodeEntry; +class VersionMin; +class SourceVersion; +class SegmentSplitInfo; +class SubFramework; +class DyldEnvironment; +class EncryptionInfo; +class BuildVersion; +class BuildToolVersion; + + LIEF_API json to_json(const Object& v); LIEF_API std::string to_json_str(const Object& v); - class LIEF_API JsonVisitor : public LIEF::JsonVisitor { public: using LIEF::JsonVisitor::JsonVisitor; diff --git a/include/LIEF/MachO/utils.hpp b/include/LIEF/MachO/utils.hpp index a3d5714..05aae8c 100644 --- a/include/LIEF/MachO/utils.hpp +++ b/include/LIEF/MachO/utils.hpp @@ -18,13 +18,13 @@ #include "LIEF/types.hpp" #include "LIEF/visibility.h" -#include "LIEF/MachO/Binary.hpp" #include #include namespace LIEF { namespace MachO { +class Binary; LIEF_API bool is_macho(const std::string& file); diff --git a/src/Abstract/Parser.cpp b/src/Abstract/Parser.cpp index f009407..5f4aea8 100644 --- a/src/Abstract/Parser.cpp +++ b/src/Abstract/Parser.cpp @@ -30,6 +30,8 @@ #include "LIEF/MachO/utils.hpp" #include "LIEF/MachO/Parser.hpp" +#include "LIEF/MachO/FatBinary.hpp" +#include "LIEF/MachO/Binary.hpp" #include "LIEF/exception.hpp" diff --git a/src/MachO/Binary.cpp b/src/MachO/Binary.cpp index 1360069..92ea836 100644 --- a/src/MachO/Binary.cpp +++ b/src/MachO/Binary.cpp @@ -13,18 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "logging.hpp" -#include "LIEF/utils.hpp" -#include "LIEF/MachO/Binary.hpp" -#include "LIEF/MachO/Builder.hpp" -#include "Object.tcc" -#include "Binary.tcc" - -#include "LIEF/MachO/hash.hpp" - -#include "LIEF/exception.hpp" - #include #include #include @@ -35,6 +23,48 @@ #define getpagesize() 0x1000 #endif +#include "logging.hpp" + + +#include "Object.tcc" +#include "Binary.tcc" + +#include "LIEF/utils.hpp" +#include "LIEF/BinaryStream/VectorStream.hpp" + +#include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Binary.hpp" +#include "LIEF/MachO/Builder.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/MainCommand.hpp" +#include "LIEF/MachO/ThreadCommand.hpp" +#include "LIEF/MachO/Symbol.hpp" +#include "LIEF/MachO/SymbolCommand.hpp" +#include "LIEF/MachO/SegmentSplitInfo.hpp" +#include "LIEF/MachO/DylibCommand.hpp" +#include "LIEF/MachO/Section.hpp" +#include "LIEF/MachO/Relocation.hpp" +#include "LIEF/MachO/DataInCode.hpp" +#include "LIEF/MachO/CodeSignature.hpp" +#include "LIEF/MachO/FunctionStarts.hpp" +#include "LIEF/MachO/DynamicSymbolCommand.hpp" +#include "LIEF/MachO/DyldInfo.hpp" +#include "LIEF/MachO/ExportInfo.hpp" +#include "LIEF/MachO/BindingInfo.hpp" +#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/DylinkerCommand.hpp" +#include "LIEF/MachO/UUIDCommand.hpp" +#include "LIEF/MachO/VersionMin.hpp" +#include "LIEF/MachO/RPathCommand.hpp" +#include "LIEF/MachO/SubFramework.hpp" +#include "LIEF/MachO/DyldEnvironment.hpp" +#include "LIEF/MachO/EncryptionInfo.hpp" +#include "LIEF/MachO/SourceVersion.hpp" + + +#include "LIEF/exception.hpp" + + namespace LIEF { namespace MachO { diff --git a/src/MachO/Binary.tcc b/src/MachO/Binary.tcc index 7cf71d7..9445a39 100644 --- a/src/MachO/Binary.tcc +++ b/src/MachO/Binary.tcc @@ -14,6 +14,10 @@ * limitations under the License. */ #include "logging.hpp" +#include "LIEF/MachO/Binary.hpp" +#include "LIEF/MachO/LoadCommand.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/Relocation.hpp" namespace LIEF { namespace MachO { diff --git a/src/MachO/BinaryParser.cpp b/src/MachO/BinaryParser.cpp index e3c5b10..13702b1 100644 --- a/src/MachO/BinaryParser.cpp +++ b/src/MachO/BinaryParser.cpp @@ -17,16 +17,14 @@ #include #include #include -#include #include -#include +#include "BinaryParser.tcc" #include "LIEF/BinaryStream/VectorStream.hpp" #include "LIEF/exception.hpp" #include "LIEF/MachO/BinaryParser.hpp" -#include "BinaryParser.tcc" #include "LIEF/MachO/utils.hpp" #include "LIEF/MachO/Header.hpp" @@ -37,6 +35,7 @@ #include "LIEF/MachO/SymbolCommand.hpp" #include "LIEF/MachO/Symbol.hpp" #include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/ExportInfo.hpp" #include "filesystem/filesystem.h" diff --git a/src/MachO/BinaryParser.tcc b/src/MachO/BinaryParser.tcc index f8c806c..e64ebea 100644 --- a/src/MachO/BinaryParser.tcc +++ b/src/MachO/BinaryParser.tcc @@ -16,6 +16,11 @@ #include "logging.hpp" +#include "LIEF/BinaryStream/VectorStream.hpp" + +#include "LIEF/MachO/Binary.hpp" +#include "LIEF/MachO/BinaryParser.hpp" +#include "LIEF/MachO/Section.hpp" #include "LIEF/MachO/DyldInfo.hpp" #include "LIEF/MachO/FunctionStarts.hpp" #include "LIEF/MachO/SourceVersion.hpp" @@ -24,6 +29,23 @@ #include "LIEF/MachO/RelocationObject.hpp" #include "LIEF/MachO/RelocationDyld.hpp" #include "LIEF/MachO/SubFramework.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/DylibCommand.hpp" +#include "LIEF/MachO/RPathCommand.hpp" +#include "LIEF/MachO/UUIDCommand.hpp" +#include "LIEF/MachO/DylinkerCommand.hpp" +#include "LIEF/MachO/ThreadCommand.hpp" +#include "LIEF/MachO/SymbolCommand.hpp" +#include "LIEF/MachO/Symbol.hpp" +#include "LIEF/MachO/DynamicSymbolCommand.hpp" +#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/CodeSignature.hpp" +#include "LIEF/MachO/DataInCode.hpp" +#include "LIEF/MachO/MainCommand.hpp" +#include "LIEF/MachO/SegmentSplitInfo.hpp" +#include "LIEF/MachO/DyldEnvironment.hpp" +#include "LIEF/MachO/EncryptionInfo.hpp" +#include "LIEF/MachO/BindingInfo.hpp" #include "Object.tcc" diff --git a/src/MachO/BindingInfo.cpp b/src/MachO/BindingInfo.cpp index f20bbdb..94b2896 100644 --- a/src/MachO/BindingInfo.cpp +++ b/src/MachO/BindingInfo.cpp @@ -21,6 +21,7 @@ #include "LIEF/MachO/Symbol.hpp" #include "LIEF/MachO/BindingInfo.hpp" #include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/DylibCommand.hpp" namespace LIEF { namespace MachO { diff --git a/src/MachO/BuildVersion.cpp b/src/MachO/BuildVersion.cpp index 491d6d2..d05e6ca 100644 --- a/src/MachO/BuildVersion.cpp +++ b/src/MachO/BuildVersion.cpp @@ -18,6 +18,8 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/BuildVersion.hpp" namespace LIEF { diff --git a/src/MachO/Builder.cpp b/src/MachO/Builder.cpp index 4c01b42..6f4897a 100644 --- a/src/MachO/Builder.cpp +++ b/src/MachO/Builder.cpp @@ -20,13 +20,16 @@ #include "logging.hpp" -#include "LIEF/MachO/Builder.hpp" #include "LIEF/exception.hpp" +#include "LIEF/BinaryStream/BinaryStream.hpp" + +#include "LIEF/MachO/Builder.hpp" +#include "LIEF/MachO/FatBinary.hpp" +#include "LIEF/MachO/UUIDCommand.hpp" #include "Builder.tcc" #include "Object.tcc" - namespace LIEF { namespace MachO { diff --git a/src/MachO/Builder.tcc b/src/MachO/Builder.tcc index 85a582c..c87733c 100644 --- a/src/MachO/Builder.tcc +++ b/src/MachO/Builder.tcc @@ -16,6 +16,30 @@ #include "logging.hpp" #include "LIEF/utils.hpp" +#include "LIEF/MachO/Builder.hpp" +#include "LIEF/MachO/Binary.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/Section.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/DylibCommand.hpp" +#include "LIEF/MachO/DylinkerCommand.hpp" +#include "LIEF/MachO/VersionMin.hpp" +#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/SourceVersion.hpp" +#include "LIEF/MachO/MainCommand.hpp" +#include "LIEF/MachO/DyldInfo.hpp" +#include "LIEF/MachO/FunctionStarts.hpp" +#include "LIEF/MachO/Symbol.hpp" +#include "LIEF/MachO/SymbolCommand.hpp" +#include "LIEF/MachO/DynamicSymbolCommand.hpp" +#include "LIEF/MachO/DataInCode.hpp" +#include "LIEF/MachO/CodeSignature.hpp" +#include "LIEF/MachO/SegmentSplitInfo.hpp" +#include "LIEF/MachO/SubFramework.hpp" +#include "LIEF/MachO/DyldEnvironment.hpp" +#include "LIEF/MachO/ThreadCommand.hpp" +#include "LIEF/MachO/BuildVersion.hpp" + namespace LIEF { namespace MachO { diff --git a/src/MachO/CodeSignature.cpp b/src/MachO/CodeSignature.cpp index f0bb37b..dd17dab 100644 --- a/src/MachO/CodeSignature.cpp +++ b/src/MachO/CodeSignature.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/CodeSignature.hpp" namespace LIEF { diff --git a/src/MachO/DataCodeEntry.cpp b/src/MachO/DataCodeEntry.cpp index 11cfe3d..554c2c8 100644 --- a/src/MachO/DataCodeEntry.cpp +++ b/src/MachO/DataCodeEntry.cpp @@ -18,6 +18,8 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/DataCodeEntry.hpp" namespace LIEF { diff --git a/src/MachO/DataInCode.cpp b/src/MachO/DataInCode.cpp index ac5ada1..fd9f549 100644 --- a/src/MachO/DataInCode.cpp +++ b/src/MachO/DataInCode.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/DataInCode.hpp" namespace LIEF { diff --git a/src/MachO/DyldEnvironment.cpp b/src/MachO/DyldEnvironment.cpp index a480efa..e7c571f 100644 --- a/src/MachO/DyldEnvironment.cpp +++ b/src/MachO/DyldEnvironment.cpp @@ -16,7 +16,7 @@ #include #include "LIEF/MachO/hash.hpp" - +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/DyldEnvironment.hpp" namespace LIEF { diff --git a/src/MachO/DyldInfo.cpp b/src/MachO/DyldInfo.cpp index eb196d0..518ff44 100644 --- a/src/MachO/DyldInfo.cpp +++ b/src/MachO/DyldInfo.cpp @@ -34,6 +34,10 @@ #include "LIEF/MachO/BindingInfo.hpp" #include "LIEF/MachO/ExportInfo.hpp" #include "LIEF/MachO/RelocationDyld.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/Symbol.hpp" +#include "LIEF/MachO/DylibCommand.hpp" #include "TrieNode.hpp" #include "Object.tcc" diff --git a/src/MachO/DylibCommand.cpp b/src/MachO/DylibCommand.cpp index a3a9dc8..6ac8f1a 100644 --- a/src/MachO/DylibCommand.cpp +++ b/src/MachO/DylibCommand.cpp @@ -17,6 +17,7 @@ #include "LIEF/utils.hpp" #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/DylibCommand.hpp" namespace LIEF { diff --git a/src/MachO/DylinkerCommand.cpp b/src/MachO/DylinkerCommand.cpp index d8fe069..83ab48c 100644 --- a/src/MachO/DylinkerCommand.cpp +++ b/src/MachO/DylinkerCommand.cpp @@ -17,6 +17,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/DylinkerCommand.hpp" namespace LIEF { diff --git a/src/MachO/DynamicSymbolCommand.cpp b/src/MachO/DynamicSymbolCommand.cpp index f55a9db..b0f4b5f 100644 --- a/src/MachO/DynamicSymbolCommand.cpp +++ b/src/MachO/DynamicSymbolCommand.cpp @@ -17,6 +17,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/DynamicSymbolCommand.hpp" namespace LIEF { diff --git a/src/MachO/EncryptionInfo.cpp b/src/MachO/EncryptionInfo.cpp index 57d1175..6fac6b2 100644 --- a/src/MachO/EncryptionInfo.cpp +++ b/src/MachO/EncryptionInfo.cpp @@ -17,7 +17,7 @@ #include #include "LIEF/MachO/hash.hpp" - +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/EncryptionInfo.hpp" namespace LIEF { diff --git a/src/MachO/ExportInfo.cpp b/src/MachO/ExportInfo.cpp index 666ddad..abc29c8 100644 --- a/src/MachO/ExportInfo.cpp +++ b/src/MachO/ExportInfo.cpp @@ -21,6 +21,7 @@ #include "LIEF/MachO/Symbol.hpp" #include "LIEF/MachO/ExportInfo.hpp" #include "LIEF/MachO/EnumToString.hpp" +#include "LIEF/MachO/DylibCommand.hpp" namespace LIEF { namespace MachO { diff --git a/src/MachO/FatBinary.cpp b/src/MachO/FatBinary.cpp index c6b2f7a..40a0c3c 100644 --- a/src/MachO/FatBinary.cpp +++ b/src/MachO/FatBinary.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/FatBinary.hpp" #include "LIEF/MachO/Builder.hpp" +#include "LIEF/MachO/Binary.hpp" namespace LIEF { namespace MachO { diff --git a/src/MachO/FunctionStarts.cpp b/src/MachO/FunctionStarts.cpp index d0c83b0..3f2615a 100644 --- a/src/MachO/FunctionStarts.cpp +++ b/src/MachO/FunctionStarts.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/FunctionStarts.hpp" namespace LIEF { diff --git a/src/MachO/MainCommand.cpp b/src/MachO/MainCommand.cpp index cb11fc2..475b459 100644 --- a/src/MachO/MainCommand.cpp +++ b/src/MachO/MainCommand.cpp @@ -17,6 +17,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/MainCommand.hpp" namespace LIEF { diff --git a/src/MachO/Parser.cpp b/src/MachO/Parser.cpp index 613f580..130f66f 100644 --- a/src/MachO/Parser.cpp +++ b/src/MachO/Parser.cpp @@ -24,7 +24,11 @@ #include "logging.hpp" #include "LIEF/exception.hpp" +#include "LIEF/BinaryStream/VectorStream.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/FatBinary.hpp" +#include "LIEF/MachO/Binary.hpp" #include "LIEF/MachO/Parser.hpp" #include "LIEF/MachO/BinaryParser.hpp" #include "LIEF/MachO/utils.hpp" diff --git a/src/MachO/RPathCommand.cpp b/src/MachO/RPathCommand.cpp index 2576e45..8e7e0b7 100644 --- a/src/MachO/RPathCommand.cpp +++ b/src/MachO/RPathCommand.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/RPathCommand.hpp" namespace LIEF { diff --git a/src/MachO/Section.cpp b/src/MachO/Section.cpp index c433c2e..1cabdc1 100644 --- a/src/MachO/Section.cpp +++ b/src/MachO/Section.cpp @@ -23,6 +23,7 @@ #include "LIEF/MachO/hash.hpp" #include "LIEF/MachO/Section.hpp" +#include "LIEF/MachO/Relocation.hpp" #include "LIEF/MachO/SegmentCommand.hpp" #include "LIEF/MachO/EnumToString.hpp" diff --git a/src/MachO/SegmentCommand.cpp b/src/MachO/SegmentCommand.cpp index 68bde8f..ae8e566 100644 --- a/src/MachO/SegmentCommand.cpp +++ b/src/MachO/SegmentCommand.cpp @@ -17,6 +17,9 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/Section.hpp" +#include "LIEF/MachO/Relocation.hpp" #include "LIEF/MachO/SegmentCommand.hpp" namespace LIEF { diff --git a/src/MachO/SegmentSplitInfo.cpp b/src/MachO/SegmentSplitInfo.cpp index ed68d92..02d8e13 100644 --- a/src/MachO/SegmentSplitInfo.cpp +++ b/src/MachO/SegmentSplitInfo.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/SegmentSplitInfo.hpp" namespace LIEF { diff --git a/src/MachO/SourceVersion.cpp b/src/MachO/SourceVersion.cpp index ace06e7..bfb831e 100644 --- a/src/MachO/SourceVersion.cpp +++ b/src/MachO/SourceVersion.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/SourceVersion.hpp" namespace LIEF { diff --git a/src/MachO/SubFramework.cpp b/src/MachO/SubFramework.cpp index 61c607b..cd0d0e3 100644 --- a/src/MachO/SubFramework.cpp +++ b/src/MachO/SubFramework.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/SubFramework.hpp" namespace LIEF { diff --git a/src/MachO/SymbolCommand.cpp b/src/MachO/SymbolCommand.cpp index 272fa6b..9527462 100644 --- a/src/MachO/SymbolCommand.cpp +++ b/src/MachO/SymbolCommand.cpp @@ -15,6 +15,7 @@ */ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/SymbolCommand.hpp" namespace LIEF { diff --git a/src/MachO/ThreadCommand.cpp b/src/MachO/ThreadCommand.cpp index 331bcdc..f094d16 100644 --- a/src/MachO/ThreadCommand.cpp +++ b/src/MachO/ThreadCommand.cpp @@ -19,6 +19,7 @@ #include "logging.hpp" #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/ThreadCommand.hpp" namespace LIEF { diff --git a/src/MachO/UUIDCommand.cpp b/src/MachO/UUIDCommand.cpp index bfc8c5e..1bde5c1 100644 --- a/src/MachO/UUIDCommand.cpp +++ b/src/MachO/UUIDCommand.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/UUIDCommand.hpp" namespace LIEF { diff --git a/src/MachO/VersionMin.cpp b/src/MachO/VersionMin.cpp index df4a485..f0a9d76 100644 --- a/src/MachO/VersionMin.cpp +++ b/src/MachO/VersionMin.cpp @@ -18,6 +18,7 @@ #include "LIEF/MachO/hash.hpp" +#include "LIEF/MachO/Structures.hpp" #include "LIEF/MachO/VersionMin.hpp" namespace LIEF { diff --git a/src/MachO/json.cpp b/src/MachO/json.cpp index 6aa9302..1866368 100644 --- a/src/MachO/json.cpp +++ b/src/MachO/json.cpp @@ -203,7 +203,7 @@ void JsonVisitor::visit(const LoadCommand& cmd) { this->node_["command"] = to_string(cmd.command()); this->node_["command_size"] = cmd.size(); this->node_["command_offset"] = cmd.command_offset(); - this->node_["data_hash"] = Hash::hash(cmd.data()); + this->node_["data_hash"] = LIEF::hash(cmd.data()); } void JsonVisitor::visit(const UUIDCommand& uuid) { @@ -237,7 +237,7 @@ void JsonVisitor::visit(const SegmentCommand& segment) { this->node_["numberof_sections"] = segment.numberof_sections(); this->node_["flags"] = segment.flags(); this->node_["sections"] = sections; - this->node_["content_hash"] = Hash::hash(segment.content()); + this->node_["content_hash"] = LIEF::hash(segment.content()); } void JsonVisitor::visit(const Section& section) { @@ -258,7 +258,7 @@ void JsonVisitor::visit(const Section& section) { this->node_["reserved1"] = section.reserved1(); this->node_["reserved2"] = section.reserved2(); this->node_["reserved3"] = section.reserved3(); - this->node_["content_hash"] = Hash::hash(section.content()); + this->node_["content_hash"] = LIEF::hash(section.content()); } void JsonVisitor::visit(const MainCommand& maincmd) { diff --git a/src/MachO/utils.cpp b/src/MachO/utils.cpp index 730b76c..0db6f53 100644 --- a/src/MachO/utils.cpp +++ b/src/MachO/utils.cpp @@ -13,18 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "LIEF/MachO/utils.hpp" -#include "LIEF/MachO/Structures.hpp" - -#include "LIEF/exception.hpp" -#include "logging.hpp" #include #include #include -#include #include +#include "LIEF/MachO/utils.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/DynamicSymbolCommand.hpp" +#include "LIEF/MachO/SegmentSplitInfo.hpp" +#include "LIEF/MachO/DyldInfo.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" +#include "LIEF/MachO/Binary.hpp" +#include "LIEF/MachO/SymbolCommand.hpp" +#include "LIEF/MachO/DataInCode.hpp" +#include "LIEF/MachO/FunctionStarts.hpp" +#include "LIEF/MachO/CodeSignature.hpp" + +#include "LIEF/exception.hpp" +#include "logging.hpp" + + namespace LIEF { namespace MachO { diff --git a/src/Object.tcc b/src/Object.tcc index bba59e6..6f3f5c8 100644 --- a/src/Object.tcc +++ b/src/Object.tcc @@ -14,6 +14,7 @@ * limitations under the License. */ #include +#include "LIEF/Object.hpp" namespace LIEF {