LIEF: Library to Instrument Executable Formats Version
Loading...
Searching...
No Matches
FatBinary.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_FAT_BINARY_H
17#define LIEF_MACHO_FAT_BINARY_H
18#include <string>
19#include <vector>
20#include <memory>
21
22#include "LIEF/types.hpp"
23#include "LIEF/visibility.h"
24
25#include "LIEF/MachO/enums.hpp"
26#include "LIEF/iterators.hpp"
27
28namespace LIEF {
29class Parser;
30namespace MachO {
31
32class Parser;
33class Builder;
34class Binary;
35
38class LIEF_API FatBinary {
39
40 friend class LIEF::Parser;
41 friend class Parser;
42 friend class Builder;
43
44 public:
45
47 using binaries_t = std::vector<std::unique_ptr<Binary>>;
48
51
54
55 FatBinary(const FatBinary&) = delete;
56 FatBinary& operator=(const FatBinary&) = delete;
57
58 virtual ~FatBinary();
59
61 size_t size() const;
62
64 bool empty() const;
65
66 it_binaries begin();
67 it_const_binaries begin() const;
68
69 it_binaries end();
70 it_const_binaries end() const;
71
72 void release_all_binaries();
73
76 std::unique_ptr<Binary> pop_back();
77
80 Binary* at(size_t index);
81 const Binary* at(size_t index) const;
82
83 Binary* back();
84 const Binary* back() const;
85
86 Binary* front();
87 const Binary* front() const;
88
89 Binary* operator[](size_t index);
90 const Binary* operator[](size_t index) const;
91
96 std::unique_ptr<Binary> take(size_t index);
97
100 std::unique_ptr<Binary> take(CPU_TYPES cpu);
101
104 void write(const std::string& filename);
105
107 std::vector<uint8_t> raw();
108
109 LIEF_API friend std::ostream& operator<<(std::ostream& os, const FatBinary& fatbinary);
110
111 private:
112 FatBinary();
113 FatBinary(binaries_t binaries);
114 binaries_t binaries_;
115};
116
117} // namespace MachO
118} // namespace LIEF
119#endif
Class which represents a MachO binary.
Definition MachO/Binary.hpp:74
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:58
Class which represent a Mach-O (fat) binary This object is also used for representing Mach-O binaries...
Definition FatBinary.hpp:38
std::unique_ptr< Binary > pop_back()
Get a pointer to the last MachO::Binary object presents in this Fat Binary. It returns a nullptr if n...
bool empty() const
Checks whether this object contains MachO::Binary.
std::unique_ptr< Binary > take(CPU_TYPES cpu)
Take the underlying MachO::Binary that matches the given architecture If no binary with the architect...
std::vector< uint8_t > raw()
Reconstruct the Fat binary object and return his content as bytes.
std::unique_ptr< Binary > take(size_t index)
Extract a MachO::Binary object. Gives ownership to the caller, and remove it from this FatBinary obje...
void write(const std::string &filename)
Reconstruct the Fat binary object and write it in filename
std::vector< std::unique_ptr< Binary > > binaries_t
Internal containter used to store Binary objects within a Fat Mach-O.
Definition FatBinary.hpp:47
Binary * at(size_t index)
Get a pointer to the MachO::Binary specified by the index. It returns a nullptr if the binary does no...
size_t size() const
Number of MachO::Binary wrapped by this object.
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:43
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:30
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32