LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
MachO/Parser.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_MACHO_PARSER_H
17#define LIEF_MACHO_PARSER_H
18#include <string>
19#include <vector>
20#include <memory>
21
22#include "LIEF/errors.hpp"
23#include "LIEF/visibility.h"
24
26
28
29namespace LIEF {
30class BinaryStream;
31
32namespace MachO {
33class Binary;
34class FatBinary;
35
43 public:
44 Parser& operator=(const Parser& copy) = delete;
45 Parser(const Parser& copy) = delete;
46
47 ~Parser() override;
48
57 static std::unique_ptr<FatBinary>
58 parse(const std::string& filename,
59 const ParserConfig& conf = ParserConfig::deep());
60
69 static std::unique_ptr<FatBinary>
70 parse(const std::vector<uint8_t>& data,
71 const ParserConfig& conf = ParserConfig::deep());
72
73
75 static std::unique_ptr<FatBinary>
76 parse(std::unique_ptr<BinaryStream> stream,
77 const ParserConfig& conf = ParserConfig::deep());
78
80 static std::unique_ptr<FatBinary>
81 parse_from_memory(uintptr_t address,
82 const ParserConfig& conf = ParserConfig::deep());
83
86 static std::unique_ptr<FatBinary>
87 parse_from_memory(uintptr_t address, size_t size,
88 const ParserConfig& conf = ParserConfig::deep());
89
90 private:
91 LIEF_LOCAL Parser(const std::string& file, const ParserConfig& conf);
92 LIEF_LOCAL Parser(std::vector<uint8_t> data, const ParserConfig& conf);
94
96 LIEF_LOCAL ok_error_t parse_fat();
97
98 LIEF_LOCAL ok_error_t undo_reloc_bindings(uintptr_t base_address);
99
100 std::unique_ptr<BinaryStream> stream_;
101 std::vector<std::unique_ptr<Binary>> binaries_;
102 ParserConfig config_;
103};
104}
105}
106#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Class which represents a MachO binary.
Definition MachO/Binary.hpp:88
Class which represent a Mach-O (fat) binary This object is also used for representing Mach-O binaries...
Definition FatBinary.hpp:36
static std::unique_ptr< FatBinary > parse_from_memory(uintptr_t address, size_t size, const ParserConfig &conf=ParserConfig::deep())
Parse the Mach-O binary from the address given in the first parameter and the size given in the secon...
Parser(const Parser &copy)=delete
static std::unique_ptr< FatBinary > parse(std::unique_ptr< BinaryStream > stream, const ParserConfig &conf=ParserConfig::deep())
Parser a Mach-O binary from the provided BinaryStream.
static std::unique_ptr< FatBinary > parse_from_memory(uintptr_t address, const ParserConfig &conf=ParserConfig::deep())
Parse the Mach-O binary from the address given in the first parameter.
static std::unique_ptr< FatBinary > parse(const std::vector< uint8_t > &data, const ParserConfig &conf=ParserConfig::deep())
Parse a Mach-O file from the raw content provided by the data parameter.
Parser & operator=(const Parser &copy)=delete
static std::unique_ptr< FatBinary > parse(const std::string &filename, const ParserConfig &conf=ParserConfig::deep())
Parse a Mach-O file from the path provided by the filename parameter.
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:30
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:114
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:40
This structure is used to tweak the MachO Parser (MachO::Parser).
Definition MachO/ParserConfig.hpp:24
static ParserConfig deep()
Return a parser configuration such as all the objects supported by LIEF are parsed.
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44