LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
endianness_support.hpp
Go to the documentation of this file.
1/* Copyright 2021 - 2024 R. Thomas
2 * Copyright 2021 - 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_ENDIANNESS_SUPPORT_H
17#define LIEF_ENDIANNESS_SUPPORT_H
18#include <cstdint>
19#include "LIEF/config.h"
20
21#define LIEF_ENDIAN_SUPPORT(X) \
22 template<> \
23 void swap_endian<X>(X* hdr)
24
25namespace LIEF {
26
27namespace ELF {
28namespace details {
29struct Elf32_Auxv;
30struct Elf32_Dyn;
31struct Elf32_Ehdr;
32struct Elf32_FileEntry;
33struct Elf32_Phdr;
34struct Elf32_Rel;
35struct Elf32_Rela;
36struct Elf32_Shdr;
37struct Elf32_Sym;
38struct Elf32_Verdaux;
39struct Elf32_Verdef;
40struct Elf32_Vernaux;
41struct Elf32_Verneed;
42struct Elf64_Auxv;
43struct Elf64_Dyn;
44struct Elf64_Ehdr;
45struct Elf64_FileEntry;
46struct Elf64_Phdr;
47struct Elf64_Rel;
48struct Elf64_Rela;
49struct Elf64_Shdr;
50struct Elf64_Sym;
51struct Elf64_Verdaux;
52struct Elf64_Verdef;
53struct Elf64_Vernaux;
54struct Elf64_Verneed;
55}
56}
57
58namespace MachO {
59namespace details {
60struct arm_thread_state64_t;
61struct arm_thread_state_t;
62struct build_tool_version;
63struct build_version_command;
64struct data_in_code_entry;
65struct dyld_info_command;
66struct dylib_command;
67struct dylib_module_32;
68struct dylib_module_64;
69struct dylib_reference;
70struct dylib_table_of_contents;
71struct dylinker_command;
72struct dysymtab_command;
73struct encryption_info_command;
74struct entry_point_command;
75struct fileset_entry_command;
76struct fvmfile_command;
77struct ident_command;
78struct linkedit_data_command;
79struct linker_option_command;
80struct load_command;
81struct mach_header;
82struct mach_header_64;
83struct nlist_32;
84struct nlist_64;
85struct prebind_cksum_command;
86struct prebound_dylib_command;
87struct relocation_info;
88struct routines_command_32;
89struct routines_command_64;
90struct rpath_command;
91struct scattered_relocation_info;
92struct section_32;
93struct section_64;
94struct segment_command_32;
95struct segment_command_64;
96struct source_version_command;
97struct sub_client_command;
98struct sub_framework_command;
99struct sub_library_command;
100struct sub_umbrella_command;
101struct symseg_command;
102struct symtab_command;
103struct thread_command;
104struct twolevel_hint;
105struct twolevel_hints_command;
106struct uuid_command;
107struct version_min_command;
108struct x86_thread_state64_t;
109struct x86_thread_state_t;
110struct ppc_thread_state_t;
111struct ppc_thread_state64_t;
112}
113}
114
115template<typename T>
116void swap_endian(T*) {
117}
118
119template<typename T>
120T get_swapped_endian(const T& other) {
121 T tmp = other;
122 swap_endian(&tmp);
123 return tmp;
124}
125
128
133
138
139#if defined (LIEF_ELF_SUPPORT)
140LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Auxv);
141LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Dyn);
142LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Ehdr);
143LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_FileEntry);
144LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Phdr);
145LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Rel);
146LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Rela);
147LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Shdr);
148LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Sym);
149LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Verdaux);
150LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Verdef);
151LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Vernaux);
152LIEF_ENDIAN_SUPPORT(ELF::details::Elf32_Verneed);
153LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Auxv);
154LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Dyn);
155LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Ehdr);
156LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_FileEntry);
157LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Phdr);
158LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Rel);
159LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Rela);
160LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Shdr);
161LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Sym);
162LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Verdaux);
163LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Verdef);
164LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Vernaux);
165LIEF_ENDIAN_SUPPORT(ELF::details::Elf64_Verneed);
166#endif
167
168#if defined (LIEF_MACHO_SUPPORT)
169LIEF_ENDIAN_SUPPORT(MachO::details::arm_thread_state64_t);
170LIEF_ENDIAN_SUPPORT(MachO::details::arm_thread_state_t);
171LIEF_ENDIAN_SUPPORT(MachO::details::build_tool_version);
172LIEF_ENDIAN_SUPPORT(MachO::details::build_version_command);
173LIEF_ENDIAN_SUPPORT(MachO::details::data_in_code_entry);
174LIEF_ENDIAN_SUPPORT(MachO::details::dyld_info_command);
175LIEF_ENDIAN_SUPPORT(MachO::details::dylib_command);
176LIEF_ENDIAN_SUPPORT(MachO::details::dylib_module_32);
177LIEF_ENDIAN_SUPPORT(MachO::details::dylib_module_64);
178LIEF_ENDIAN_SUPPORT(MachO::details::dylib_reference);
179LIEF_ENDIAN_SUPPORT(MachO::details::dylib_table_of_contents);
180LIEF_ENDIAN_SUPPORT(MachO::details::dylinker_command);
181LIEF_ENDIAN_SUPPORT(MachO::details::dysymtab_command);
182LIEF_ENDIAN_SUPPORT(MachO::details::encryption_info_command);
183LIEF_ENDIAN_SUPPORT(MachO::details::entry_point_command);
184LIEF_ENDIAN_SUPPORT(MachO::details::fileset_entry_command);
185LIEF_ENDIAN_SUPPORT(MachO::details::fvmfile_command);
186LIEF_ENDIAN_SUPPORT(MachO::details::ident_command);
187LIEF_ENDIAN_SUPPORT(MachO::details::linkedit_data_command);
188LIEF_ENDIAN_SUPPORT(MachO::details::linker_option_command);
189LIEF_ENDIAN_SUPPORT(MachO::details::load_command);
190LIEF_ENDIAN_SUPPORT(MachO::details::mach_header);
191LIEF_ENDIAN_SUPPORT(MachO::details::mach_header_64);
192LIEF_ENDIAN_SUPPORT(MachO::details::nlist_32);
193LIEF_ENDIAN_SUPPORT(MachO::details::nlist_64);
194LIEF_ENDIAN_SUPPORT(MachO::details::prebind_cksum_command);
195LIEF_ENDIAN_SUPPORT(MachO::details::prebound_dylib_command);
196LIEF_ENDIAN_SUPPORT(MachO::details::relocation_info);
197LIEF_ENDIAN_SUPPORT(MachO::details::routines_command_32);
198LIEF_ENDIAN_SUPPORT(MachO::details::routines_command_64);
199LIEF_ENDIAN_SUPPORT(MachO::details::rpath_command);
200LIEF_ENDIAN_SUPPORT(MachO::details::scattered_relocation_info);
201LIEF_ENDIAN_SUPPORT(MachO::details::section_32);
202LIEF_ENDIAN_SUPPORT(MachO::details::section_64);
203LIEF_ENDIAN_SUPPORT(MachO::details::segment_command_32);
204LIEF_ENDIAN_SUPPORT(MachO::details::segment_command_64);
205LIEF_ENDIAN_SUPPORT(MachO::details::source_version_command);
206LIEF_ENDIAN_SUPPORT(MachO::details::sub_client_command);
207LIEF_ENDIAN_SUPPORT(MachO::details::sub_framework_command);
208LIEF_ENDIAN_SUPPORT(MachO::details::sub_library_command);
209LIEF_ENDIAN_SUPPORT(MachO::details::sub_umbrella_command);
210LIEF_ENDIAN_SUPPORT(MachO::details::symseg_command);
211LIEF_ENDIAN_SUPPORT(MachO::details::symtab_command);
212LIEF_ENDIAN_SUPPORT(MachO::details::thread_command);
213LIEF_ENDIAN_SUPPORT(MachO::details::twolevel_hint);
214LIEF_ENDIAN_SUPPORT(MachO::details::twolevel_hints_command);
215LIEF_ENDIAN_SUPPORT(MachO::details::uuid_command);
216LIEF_ENDIAN_SUPPORT(MachO::details::version_min_command);
217LIEF_ENDIAN_SUPPORT(MachO::details::x86_thread_state64_t);
218LIEF_ENDIAN_SUPPORT(MachO::details::x86_thread_state_t);
219LIEF_ENDIAN_SUPPORT(MachO::details::ppc_thread_state64_t);
220LIEF_ENDIAN_SUPPORT(MachO::details::ppc_thread_state_t);
221#endif
222
223}
224
225#endif // LIEF_CONVERT_H
#define LIEF_ENDIAN_SUPPORT(X)
Definition endianness_support.hpp:21
Definition DynamicEntry.hpp:29
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:36
T get_swapped_endian(const T &other)
Definition endianness_support.hpp:120
void swap_endian(T *)
Definition endianness_support.hpp:116