Clean Mach-O headers

This commit is contained in:
rthomas 2020-11-20 06:43:12 +01:00
parent 3b7c8fb203
commit 294428973a
76 changed files with 961 additions and 735 deletions

View File

@ -17,6 +17,7 @@
#include "LIEF/MachO/Binary.h"
#include "LIEF/MachO/Parser.hpp"
#include "LIEF/MachO/FatBinary.hpp"
#include "Binary.hpp"

View File

@ -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

View File

@ -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<uint8_t>& 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

View File

@ -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<uint8_t>::max();
public:
BinaryParser(const std::string& file, const ParserConfig& conf = ParserConfig::deep());
BinaryParser(const std::vector<uint8_t>& 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<uint8_t>& 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<VectorStream>&& stream, uint64_t fat_offset = 0, const ParserConfig& conf = ParserConfig::deep());
BinaryParser(std::unique_ptr<VectorStream>&& stream, uint64_t fat_offset = 0, const ParserConfig& conf = ParserConfig::deep());
void init(void);
void init(void);
template<class MACHO_T>
void parse(void);
template<class MACHO_T>
void parse(void);
template<class MACHO_T>
void parse_header(void);
template<class MACHO_T>
void parse_header(void);
template<class MACHO_T>
void parse_load_commands(void);
template<class MACHO_T>
void parse_load_commands(void);
template<class MACHO_T>
void parse_relocations(Section& section);
template<class MACHO_T>
void parse_relocations(Section& section);
// Dyld info parser
// ================
// Dyld info parser
// ================
// Rebase
// ------
template<class MACHO_T>
void parse_dyldinfo_rebases(void);
// Rebase
// ------
template<class MACHO_T>
void parse_dyldinfo_rebases(void);
// Bindings
// --------
template<class MACHO_T>
void parse_dyldinfo_binds(void);
// Bindings
// --------
template<class MACHO_T>
void parse_dyldinfo_binds(void);
template<class MACHO_T>
void parse_dyldinfo_generic_bind(void);
template<class MACHO_T>
void parse_dyldinfo_generic_bind(void);
template<class MACHO_T>
void parse_dyldinfo_weak_bind(void);
template<class MACHO_T>
void parse_dyldinfo_weak_bind(void);
template<class MACHO_T>
void parse_dyldinfo_lazy_bind(void);
template<class MACHO_T>
void parse_dyldinfo_lazy_bind(void);
template<class MACHO_T>
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<class MACHO_T>
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<class MACHO_T>
void do_rebase(uint8_t type, uint8_t segment_idx, uint64_t segment_address);
template<class MACHO_T>
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<VectorStream> stream_;
Binary* binary_ ;
MACHO_TYPES type_;
bool is64_;
ParserConfig config_;
std::set<uint64_t> visited_;
std::unique_ptr<VectorStream> stream_;
Binary* binary_{nullptr};
MACHO_TYPES type_;
bool is64_;
ParserConfig config_;
std::set<uint64_t> visited_;
};

View File

@ -15,22 +15,20 @@
*/
#ifndef LIEF_MACHO_BINDING_INFO_COMMAND_H_
#define LIEF_MACHO_BINDING_INFO_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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 {

View File

@ -15,7 +15,6 @@
*/
#ifndef LIEF_MACHO_BUILD_VERSION_COMMAND_H_
#define LIEF_MACHO_BUILD_VERSION_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
@ -27,7 +26,8 @@
namespace LIEF {
namespace MachO {
struct build_tool_version;
struct build_version_command;
class LIEF_API BuildToolVersion : public LIEF::Object {
public:

View File

@ -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:

View File

@ -15,10 +15,8 @@
*/
#ifndef LIEF_MACHO_CODE_SIGNATURE_COMMAND_H_
#define LIEF_MACHO_CODE_SIGNATURE_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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<uint8_t> raw_signature_;
uint32_t data_offset_;
uint32_t data_size_;
std::vector<uint8_t> raw_signature_;
};

View File

@ -16,8 +16,6 @@
*/
#ifndef LIEF_MACHO_DATA_CODE_ENTRY_H_
#define LIEF_MACHO_DATA_CODE_ENTRY_H_
#include <string>
#include <vector>
#include <iostream>
#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 {

View File

@ -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 {

View File

@ -15,7 +15,7 @@
*/
#ifndef LIEF_MACHO_DYLD_ENVIROMENT_COMMAND_H_
#define LIEF_MACHO_DYLD_ENVIROMENT_COMMAND_H_
#include <string>
#include <iostream>
#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);

View File

@ -18,23 +18,23 @@
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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<uint32_t, uint32_t>;
//! @brief Tuple of ``offset`` and ``size``
using info_t = std::pair<uint32_t, uint32_t>;
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:
//! <seg-index, seg-offset, type>
//! 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:
//! <seg-index, seg-offset, type>
//! 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:
//! <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
//! 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:
//! <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
//! 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<BindingInfo*, std::function<bool(BindingInfo*, BindingInfo*)>>;
using bind_container_t = std::set<BindingInfo*, std::function<bool(BindingInfo*, BindingInfo*)>>;
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};
};
}

View File

@ -15,7 +15,8 @@
*/
#ifndef LIEF_MACHO_DYLIB_COMMAND_H_
#define LIEF_MACHO_DYLIB_COMMAND_H_
#include <array>
#include <string>
#include <iostream>
#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:

View File

@ -15,7 +15,7 @@
*/
#ifndef LIEF_MACHO_DYLINKER_COMMAND_H_
#define LIEF_MACHO_DYLINKER_COMMAND_H_
#include <string>
#include <iostream>
#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_;
};
}

View File

@ -15,10 +15,7 @@
*/
#ifndef LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H_
#define LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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);

View File

@ -15,10 +15,7 @@
*/
#ifndef LIEF_MACHO_ENCRYPTION_INFO_COMMAND_H_
#define LIEF_MACHO_ENCRYPTION_INFO_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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);

View File

@ -15,10 +15,8 @@
*/
#ifndef LIEF_MACHO_EXPORT_INFO_COMMAND_H_
#define LIEF_MACHO_EXPORT_INFO_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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<EXPORT_SYMBOL_FLAGS>;
using flag_list_t = std::vector<EXPORT_SYMBOL_FLAGS>;
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};
};

View File

@ -15,14 +15,13 @@
*/
#ifndef LIEF_MACHO_FAT_BINARY_H_
#define LIEF_MACHO_FAT_BINARY_H_
#include <string>
#include <vector>
#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 {

View File

@ -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<uint64_t>& 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<uint64_t>& functions(void) const;
std::vector<uint64_t>& functions(void);
std::vector<uint64_t>& 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<uint64_t>& funcs);
void data_offset(uint32_t offset);
void data_size(uint32_t size);
void functions(const std::vector<uint64_t>& 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<uint64_t> functions_;
uint32_t data_offset_;
uint32_t data_size_;
std::vector<uint64_t> functions_;
};

View File

@ -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<HEADER_FLAGS>;

View File

@ -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:

View File

@ -15,47 +15,44 @@
*/
#ifndef LIEF_MACHO_MAIN_COMMAND_H_
#define LIEF_MACHO_MAIN_COMMAND_H_
#include <iostream>
#include <set>
#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_;
};
}

View File

@ -16,43 +16,44 @@
#ifndef LIEF_MACHO_PARSER_H_
#define LIEF_MACHO_PARSER_H_
#include <string>
#include <list>
#include <vector>
#include <memory>
#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<FatBinary> parse(const std::string& filename, const ParserConfig& conf = ParserConfig::deep());
static std::unique_ptr<FatBinary> parse(const std::vector<uint8_t>& data, const std::string& name = "", const ParserConfig& conf = ParserConfig::deep());
static std::unique_ptr<FatBinary> parse(const std::string& filename, const ParserConfig& conf = ParserConfig::deep());
static std::unique_ptr<FatBinary> parse(const std::vector<uint8_t>& data, const std::string& name = "", const ParserConfig& conf = ParserConfig::deep());
private:
Parser(const std::string& file, const ParserConfig& conf);
Parser(const std::vector<uint8_t>& data, const std::string& name, const ParserConfig& conf);
Parser(void);
Parser(const std::string& file, const ParserConfig& conf);
Parser(const std::vector<uint8_t>& 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<VectorStream> stream_;
std::vector<Binary*> binaries_;
ParserConfig config_;
std::unique_ptr<VectorStream> stream_;
std::vector<Binary*> binaries_;
ParserConfig config_;
};
}
}

View File

@ -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_;
};
}

View File

@ -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_;
};
}

View File

@ -15,16 +15,11 @@
*/
#ifndef LIEF_MACHO_RELOCATION_DYLD_COMMAND_H_
#define LIEF_MACHO_RELOCATION_DYLD_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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;
};
}

View File

@ -15,80 +15,77 @@
*/
#ifndef LIEF_MACHO_RELOCATION_OBJECT_COMMAND_H_
#define LIEF_MACHO_RELOCATION_OBJECT_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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_;
};
}

View File

@ -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;

View File

@ -19,20 +19,23 @@
#include <string>
#include <vector>
#include <iostream>
#include <functional>
#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_;

View File

@ -15,10 +15,8 @@
*/
#ifndef LIEF_MACHO_SEGMENT_SPLIT_INFO_H_
#define LIEF_MACHO_SEGMENT_SPLIT_INFO_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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<uint8_t> raw_;
uint32_t data_offset_;
uint32_t data_size_;
std::vector<uint8_t> raw_;
};

View File

@ -15,8 +15,6 @@
*/
#ifndef LIEF_MACHO_SOURCE_VERSION_COMMAND_H_
#define LIEF_MACHO_SOURCE_VERSION_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
@ -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<uint32_t, 5>;
//! @brief Version is an array of **5** integers
using version_t = std::array<uint32_t, 5>;
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_;
};
}

View File

@ -16,9 +16,7 @@
#ifndef LIEF_MACHO_SUB_FRAMEWORK_H_
#define LIEF_MACHO_SUB_FRAMEWORK_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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:

View File

@ -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 {

View File

@ -15,8 +15,6 @@
*/
#ifndef LIEF_MACHO_SYMBOL_COMMAND_H_
#define LIEF_MACHO_SYMBOL_COMMAND_H_
#include <string>
#include <iostream>
#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_;
};
}

View File

@ -15,10 +15,8 @@
*/
#ifndef LIEF_MACHO_THREAD_COMMAND_H_
#define LIEF_MACHO_THREAD_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
#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<uint8_t>& state(void) const;
std::vector<uint8_t>& state(void);
const std::vector<uint8_t>& state(void) const;
std::vector<uint8_t>& state(void);
uint64_t pc(void) const;
uint64_t pc(void) const;
void state(const std::vector<uint8_t>& state);
void flavor(uint32_t flavor);
void count(uint32_t count);
void architecture(CPU_TYPES arch);
void state(const std::vector<uint8_t>& 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<uint8_t> state_;
uint32_t flavor_;
uint32_t count_;
CPU_TYPES architecture_;
std::vector<uint8_t> state_;
};

View File

@ -15,8 +15,6 @@
*/
#ifndef LIEF_MACHO_UUID_COMMAND_H_
#define LIEF_MACHO_UUID_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
@ -27,32 +25,35 @@
namespace LIEF {
namespace MachO {
struct uuid_command;
using uuid_t = std::array<uint8_t, 16>;
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_;
};
}

View File

@ -15,8 +15,6 @@
*/
#ifndef LIEF_MACHO_VERSION_MIN_COMMAND_H_
#define LIEF_MACHO_VERSION_MIN_COMMAND_H_
#include <string>
#include <vector>
#include <iostream>
#include <array>
@ -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<uint32_t, 3>;
//! @brief Version is an array of **3** integers
using version_t = std::array<uint32_t, 3>;
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_;
};
}

View File

@ -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);

View File

@ -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;

View File

@ -18,13 +18,13 @@
#include "LIEF/types.hpp"
#include "LIEF/visibility.h"
#include "LIEF/MachO/Binary.hpp"
#include <string>
#include <vector>
namespace LIEF {
namespace MachO {
class Binary;
LIEF_API bool is_macho(const std::string& file);

View File

@ -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"

View File

@ -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 <algorithm>
#include <numeric>
#include <sstream>
@ -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 {

View File

@ -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 {

View File

@ -17,16 +17,14 @@
#include <iterator>
#include <iostream>
#include <algorithm>
#include <regex>
#include <stdexcept>
#include <functional>
#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"

View File

@ -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"

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/CodeSignature.hpp"
namespace LIEF {

View File

@ -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 {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/DataInCode.hpp"
namespace LIEF {

View File

@ -16,7 +16,7 @@
#include <iomanip>
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/DyldEnvironment.hpp"
namespace LIEF {

View File

@ -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"

View File

@ -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 {

View File

@ -17,6 +17,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/DylinkerCommand.hpp"
namespace LIEF {

View File

@ -17,6 +17,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/DynamicSymbolCommand.hpp"
namespace LIEF {

View File

@ -17,7 +17,7 @@
#include <iomanip>
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/EncryptionInfo.hpp"
namespace LIEF {

View File

@ -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 {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/FatBinary.hpp"
#include "LIEF/MachO/Builder.hpp"
#include "LIEF/MachO/Binary.hpp"
namespace LIEF {
namespace MachO {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/FunctionStarts.hpp"
namespace LIEF {

View File

@ -17,6 +17,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/MainCommand.hpp"
namespace LIEF {

View File

@ -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"

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/RPathCommand.hpp"
namespace LIEF {

View File

@ -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"

View File

@ -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 {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/SegmentSplitInfo.hpp"
namespace LIEF {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/SourceVersion.hpp"
namespace LIEF {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/SubFramework.hpp"
namespace LIEF {

View File

@ -15,6 +15,7 @@
*/
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/SymbolCommand.hpp"
namespace LIEF {

View File

@ -19,6 +19,7 @@
#include "logging.hpp"
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/ThreadCommand.hpp"
namespace LIEF {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/UUIDCommand.hpp"
namespace LIEF {

View File

@ -18,6 +18,7 @@
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/Structures.hpp"
#include "LIEF/MachO/VersionMin.hpp"
namespace LIEF {

View File

@ -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) {

View File

@ -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 <fstream>
#include <iterator>
#include <string>
#include <stdexcept>
#include <vector>
#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 {

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <iomanip>
#include "LIEF/Object.hpp"
namespace LIEF {