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