LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
MachO/Parser.hpp
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
25#include "LIEF/Abstract/Parser.hpp"
26
27#include "LIEF/MachO/ParserConfig.hpp"
28
29namespace LIEF {
30class BinaryStream;
31
32namespace MachO {
33class Binary;
34class FatBinary;
35
42class 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
57 static std::unique_ptr<FatBinary> parse(const std::string& filename,
58 const ParserConfig& conf = ParserConfig::deep());
59
68 static std::unique_ptr<FatBinary> parse(const std::vector<uint8_t>& data,
69 const ParserConfig& conf = ParserConfig::deep());
70
71
73 static std::unique_ptr<FatBinary> parse(std::unique_ptr<BinaryStream> stream,
74 const ParserConfig& conf = ParserConfig::deep());
75
77 static std::unique_ptr<FatBinary> parse_from_memory(uintptr_t address,
78 const ParserConfig& conf = ParserConfig::deep());
79
82 static std::unique_ptr<FatBinary> parse_from_memory(uintptr_t address, size_t size,
83 const ParserConfig& conf = ParserConfig::deep());
84
85 private:
86 Parser(const std::string& file, const ParserConfig& conf);
87 Parser(std::vector<uint8_t> data, const ParserConfig& conf);
88 Parser();
89
90 ok_error_t build();
91 ok_error_t build_fat();
92
93 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
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...
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.
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
LIEF namespace.
Definition Abstract/Binary.hpp:32
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:106
This structure is used to tweak the MachO Parser (MachO::Parser)
Definition MachO/ParserConfig.hpp:24