LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
MachO/Parser.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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;
35class LIEF_API Parser : public LIEF::Parser {
43 public:
44 Parser& operator=(const Parser& copy) = delete;
45 Parser(const Parser& copy) = delete;
46
47 ~Parser() override;
48 static std::unique_ptr<FatBinary> parse(const std::string& filename,
58 const ParserConfig& conf = ParserConfig::deep());
59 static std::unique_ptr<FatBinary> parse(const std::vector<uint8_t>& data,
69 const ParserConfig& conf = ParserConfig::deep());
70
71 static std::unique_ptr<FatBinary> parse(std::unique_ptr<BinaryStream> stream,
74 const ParserConfig& conf = ParserConfig::deep());
75 static std::unique_ptr<FatBinary> parse_from_memory(uintptr_t address,
78 const ParserConfig& conf = ParserConfig::deep());
79 static std::unique_ptr<FatBinary> parse_from_memory(uintptr_t address, size_t size,
83 const ParserConfig& conf = ParserConfig::deep());
84
85 private:
86 LIEF_LOCAL Parser(const std::string& file, const ParserConfig& conf);
87 LIEF_LOCAL Parser(std::vector<uint8_t> data, const ParserConfig& conf);
88 LIEF_LOCAL Parser();
89
90 LIEF_LOCAL ok_error_t build();
91 LIEF_LOCAL ok_error_t build_fat();
92
93 LIEF_LOCAL ok_error_t undo_reloc_bindings(uintptr_t base_address);
94
95 std::unique_ptr<BinaryStream> stream_;
96 std::vector<std::unique_ptr<Binary>> binaries_;
97 ParserConfig config_;
98};
99}
100}
101#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:85
Class which represent a Mach-O (fat) binary This object is also used for representing Mach-O binaries...
Definition FatBinary.hpp:36
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:42
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.
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:36
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42