LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
Abstract/Header.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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_ABSTRACT_HEADER_H
17#define LIEF_ABSTRACT_HEADER_H
18
19#include <ostream>
20#include <cstdint>
21#include <vector>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25#include "LIEF/enums.hpp"
26
27namespace LIEF {
28namespace ELF {
29class Binary;
30}
31
32namespace PE {
33class Binary;
34}
35
36namespace MachO {
37class Binary;
38}
39
40class LIEF_API Header : public Object {
41 public:
57
58 enum class ENDIANNESS {
62 };
63
64 enum MODES : uint64_t {
65 NONE = 0,
66
67 BITS_16 = 1LLU << 0,
68 BITS_32 = 1LLU << 1,
69 BITS_64 = 1LLU << 2,
70 THUMB = 1LLU << 3,
71
72 ARM64E = 1LLU << 4,
73 };
74
81
82 static Header from(const LIEF::ELF::Binary& elf);
83 static Header from(const LIEF::PE::Binary& pe);
84 static Header from(const LIEF::MachO::Binary& macho);
85
86 Header() = default;
87 Header(const Header&) = default;
88 Header& operator=(const Header&) = default;
89 ~Header() override = default;
90
93 return architecture_;
94 }
95
97 MODES modes() const {
98 return modes_;
99 }
100
102 std::vector<MODES> modes_list() const;
103
104 bool is(MODES m) const {
105 return ((uint64_t)m & (uint64_t)modes_) != 0;
106 }
107
109 return object_type_;
110 }
111 uint64_t entrypoint() const {
112 return entrypoint_;
113 }
114
116 return endianness_;
117 }
118
119 bool is_32() const {
120 return ((uint64_t)modes_ & (uint64_t)MODES::BITS_32) != 0;
121 }
122
123 bool is_64() const {
124 return ((uint64_t)modes_ & (uint64_t)MODES::BITS_64) != 0;
125 }
126
127 void accept(Visitor& visitor) const override;
128
129 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Header& hdr);
130
131 protected:
133 OBJECT_TYPES object_type_ = OBJECT_TYPES::UNKNOWN;
134 uint64_t entrypoint_ = 0;
135 ENDIANNESS endianness_ = ENDIANNESS::UNKNOWN;
136 MODES modes_ = MODES::NONE;
137};
138
143}
144
146
147#endif
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
uint64_t entrypoint() const
Definition Abstract/Header.hpp:111
ARCHITECTURES architecture() const
Target architecture.
Definition Abstract/Header.hpp:92
static Header from(const LIEF::ELF::Binary &elf)
std::vector< MODES > modes_list() const
MODES as a vector.
MODES modes() const
Optional features for the given architecture.
Definition Abstract/Header.hpp:97
Header()=default
static Header from(const LIEF::MachO::Binary &macho)
Header(const Header &)=default
OBJECT_TYPES object_type() const
Definition Abstract/Header.hpp:108
ARCHITECTURES
Definition Abstract/Header.hpp:42
@ LOONGARCH
Definition Abstract/Header.hpp:54
@ MIPS
Definition Abstract/Header.hpp:46
@ SYSZ
Definition Abstract/Header.hpp:51
@ ARM
Definition Abstract/Header.hpp:44
@ UNKNOWN
Definition Abstract/Header.hpp:43
@ X86_64
Definition Abstract/Header.hpp:48
@ RISCV
Definition Abstract/Header.hpp:53
@ XCORE
Definition Abstract/Header.hpp:52
@ PPC64
Definition Abstract/Header.hpp:55
@ SPARC
Definition Abstract/Header.hpp:50
@ ARM64
Definition Abstract/Header.hpp:45
@ PPC
Definition Abstract/Header.hpp:49
@ X86
Definition Abstract/Header.hpp:47
OBJECT_TYPES
Definition Abstract/Header.hpp:75
@ EXECUTABLE
Definition Abstract/Header.hpp:77
@ UNKNOWN
Definition Abstract/Header.hpp:76
@ OBJECT
Definition Abstract/Header.hpp:79
@ LIBRARY
Definition Abstract/Header.hpp:78
friend std::ostream & operator<<(std::ostream &os, const Header &hdr)
bool is(MODES m) const
Definition Abstract/Header.hpp:104
ENDIANNESS endianness() const
Definition Abstract/Header.hpp:115
ENDIANNESS
Definition Abstract/Header.hpp:58
@ LITTLE
Definition Abstract/Header.hpp:61
@ UNKNOWN
Definition Abstract/Header.hpp:59
@ BIG
Definition Abstract/Header.hpp:60
Header & operator=(const Header &)=default
void accept(Visitor &visitor) const override
static Header from(const LIEF::PE::Binary &pe)
~Header() override=default
bool is_32() const
Definition Abstract/Header.hpp:119
MODES
Definition Abstract/Header.hpp:64
@ BITS_16
Definition Abstract/Header.hpp:67
@ NONE
Definition Abstract/Header.hpp:65
@ BITS_64
32-bits architecture
Definition Abstract/Header.hpp:69
@ ARM64E
Support ARM Thumb mode.
Definition Abstract/Header.hpp:72
@ THUMB
64-bits architecture
Definition Abstract/Header.hpp:70
@ BITS_32
16-bits architecture
Definition Abstract/Header.hpp:68
bool is_64() const
Definition Abstract/Header.hpp:123
Class which represents a MachO binary.
Definition MachO/Binary.hpp:88
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:57
Definition Visitor.hpp:210
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:40
const char * to_string(Binary::VA_TYPES e)
#define LIEF_API
Definition visibility.h:41