LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
FatBinary.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_FAT_BINARY_H
17#define LIEF_MACHO_FAT_BINARY_H
18#include <string>
19#include <vector>
20#include <memory>
21
22#include "LIEF/visibility.h"
23#include "LIEF/iterators.hpp"
24#include "LIEF/MachO/Header.hpp"
25
26namespace LIEF {
27class Parser;
28namespace MachO {
29
30class Parser;
31class Builder;
32class Binary;
33class LIEF_API FatBinary {
37
38 friend class LIEF::Parser;
39 friend class Parser;
40 friend class Builder;
41
42 public:
43 using binaries_t = std::vector<std::unique_ptr<Binary>>;
46 using it_binaries = ref_iterator<binaries_t&, Binary*>;
49 using it_const_binaries = const_ref_iterator<const binaries_t&, Binary*>;
52
53 FatBinary(const FatBinary&) = delete;
54 FatBinary& operator=(const FatBinary&) = delete;
55
56 virtual ~FatBinary();
57 size_t size() const {
60 return binaries_.size();
61 }
62 bool empty() const {
65 return binaries_.empty();
66 }
67
68 it_binaries begin() {
69 return binaries_;
70 }
71 it_const_binaries begin() const {
72 return binaries_;
73 }
74
75 it_binaries end() {
76 return it_binaries(binaries_).end();
77 }
78
79 it_const_binaries end() const {
80 return it_const_binaries(binaries_).end();
81 }
82
83 void release_all_binaries();
84 std::unique_ptr<Binary> pop_back();
88 Binary* at(size_t index);
92 const Binary* at(size_t index) const;
93
94 Binary* back();
95 const Binary* back() const;
96
97 Binary* front();
98 const Binary* front() const;
99
100 Binary* operator[](size_t index) {
101 return at(index);
102 }
103 const Binary* operator[](size_t index) const {
104 return at(index);
105 }
106 std::unique_ptr<Binary> take(size_t index);
112 std::unique_ptr<Binary> take(Header::CPU_TYPE cpu);
116 void write(const std::string& filename);
120 std::vector<uint8_t> raw();
123
124 LIEF_API friend std::ostream& operator<<(std::ostream& os, const FatBinary& fatbinary);
125
126 private:
127 LIEF_LOCAL FatBinary();
128 LIEF_LOCAL FatBinary(binaries_t binaries);
129 binaries_t binaries_;
130};
131
132} // namespace MachO
133} // namespace LIEF
134#endif
Header.hpp
LIEF::MachO::Binary
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
LIEF::MachO::Builder
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:58
LIEF::MachO::FatBinary
Class which represent a Mach-O (fat) binary This object is also used for representing Mach-O binaries...
Definition FatBinary.hpp:36
LIEF::MachO::FatBinary::end
it_binaries end()
Definition FatBinary.hpp:75
LIEF::MachO::FatBinary::front
Binary * front()
LIEF::MachO::FatBinary::pop_back
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...
LIEF::MachO::FatBinary::empty
bool empty() const
Checks whether this object contains MachO::Binary.
Definition FatBinary.hpp:64
LIEF::MachO::FatBinary::take
std::unique_ptr< Binary > take(Header::CPU_TYPE cpu)
Take the underlying MachO::Binary that matches the given architecture If no binary with the architect...
LIEF::MachO::FatBinary::raw
std::vector< uint8_t > raw()
Reconstruct the Fat binary object and return his content as bytes.
LIEF::MachO::FatBinary::FatBinary
FatBinary(const FatBinary &)=delete
LIEF::MachO::FatBinary::operator<<
friend std::ostream & operator<<(std::ostream &os, const FatBinary &fatbinary)
LIEF::MachO::FatBinary::take
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...
LIEF::MachO::FatBinary::at
const Binary * at(size_t index) const
LIEF::MachO::FatBinary::back
const Binary * back() const
LIEF::MachO::FatBinary::operator[]
Binary * operator[](size_t index)
Definition FatBinary.hpp:100
LIEF::MachO::FatBinary::begin
it_binaries begin()
Definition FatBinary.hpp:68
LIEF::MachO::FatBinary::begin
it_const_binaries begin() const
Definition FatBinary.hpp:71
LIEF::MachO::FatBinary::back
Binary * back()
LIEF::MachO::FatBinary::~FatBinary
virtual ~FatBinary()
LIEF::MachO::FatBinary::front
const Binary * front() const
LIEF::MachO::FatBinary::write
void write(const std::string &filename)
Reconstruct the Fat binary object and write it in filename
LIEF::MachO::FatBinary::operator=
FatBinary & operator=(const FatBinary &)=delete
LIEF::MachO::FatBinary::end
it_const_binaries end() const
Definition FatBinary.hpp:79
LIEF::MachO::FatBinary::at
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...
LIEF::MachO::FatBinary::size
size_t size() const
Number of MachO::Binary wrapped by this object.
Definition FatBinary.hpp:59
LIEF::MachO::FatBinary::operator[]
const Binary * operator[](size_t index) const
Definition FatBinary.hpp:103
LIEF::MachO::FatBinary::release_all_binaries
void release_all_binaries()
LIEF::MachO::Parser
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:42
LIEF::Parser
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:30
LIEF::ref_iterator::end
ref_iterator end() const
Definition iterators.hpp:193
iterators.hpp
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42