LIEF: Library to Instrument Executable Formats Version
Loading...
Searching...
No Matches
MachO/Parser.hpp
1/* Copyright 2017 - 2023 R. Thomas
2 * Copyright 2017 - 2023 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/types.hpp"
23#include "LIEF/errors.hpp"
24#include "LIEF/visibility.h"
25
26#include "LIEF/Abstract/Parser.hpp"
27
28#include "LIEF/MachO/ParserConfig.hpp"
29
30namespace LIEF {
31class BinaryStream;
32
33namespace MachO {
34class Binary;
35class FatBinary;
36
43class LIEF_API Parser : public LIEF::Parser {
44 public:
45 Parser& operator=(const Parser& copy) = delete;
46 Parser(const Parser& copy) = delete;
47
48 ~Parser() override;
49
58 static std::unique_ptr<FatBinary> parse(const std::string& filename,
59 const ParserConfig& conf = ParserConfig::deep());
60
69 static std::unique_ptr<FatBinary> parse(const std::vector<uint8_t>& data,
70 const ParserConfig& conf = ParserConfig::deep());
71
72
74 static std::unique_ptr<FatBinary> parse(std::unique_ptr<BinaryStream> stream,
75 const ParserConfig& conf = ParserConfig::deep());
76
78 static std::unique_ptr<FatBinary> parse_from_memory(uintptr_t address,
79 const ParserConfig& conf = ParserConfig::deep());
80
83 static std::unique_ptr<FatBinary> parse_from_memory(uintptr_t address, size_t size,
84 const ParserConfig& conf = ParserConfig::deep());
85
86 private:
87 Parser(const std::string& file, const ParserConfig& conf);
88 Parser(std::vector<uint8_t> data, const ParserConfig& conf);
89 Parser();
90
91 ok_error_t build();
92 ok_error_t build_fat();
93
94 ok_error_t undo_reloc_bindings(uintptr_t base_address);
95
96 std::unique_ptr<BinaryStream> stream_;
97 std::vector<std::unique_ptr<Binary>> binaries_;
98 ParserConfig config_;
99};
100}
101}
102#endif
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:43
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