From 2a6e3a266fdb3c2ad82cf222e05c6b0662e50606 Mon Sep 17 00:00:00 2001 From: Romain Thomas Date: Sun, 28 Jan 2024 09:58:33 +0100 Subject: [PATCH] Re-scope ELF enums --- api/c/ELF/Binary.cpp | 9 +- api/c/ELF/CMakeLists.txt | 1 - api/c/ELF/DynamicEntry.cpp | 85 +- api/c/ELF/EnumToString.cpp | 80 - api/c/ELF/Header.cpp | 11 +- api/c/ELF/Section.cpp | 2 +- api/c/ELF/Segment.cpp | 5 +- api/c/ELF/Symbol.cpp | 10 +- api/c/include/LIEF/ELF.h | 1 - api/c/include/LIEF/ELF/Binary.h | 6 +- api/c/include/LIEF/ELF/DynamicEntry.h | 9 +- api/c/include/LIEF/ELF/EnumToString.h | 47 - api/c/include/LIEF/ELF/Header.h | 32 +- api/c/include/LIEF/ELF/Section.h | 32 +- api/c/include/LIEF/ELF/Segment.h | 20 +- api/c/include/LIEF/ELF/Symbol.h | 26 +- api/c/include/LIEF/ELF/enums.h | 979 +++++++++- api/c/include/LIEF/ELF/utils.h | 4 +- api/python/examples/abstract_json.py | 2 +- api/python/examples/abstract_reader.py | 7 +- api/python/examples/change_elf_interpreter.py | 2 +- api/python/examples/dex_json.py | 2 +- api/python/examples/dex_reader.py | 7 +- api/python/examples/elf_reader.py | 28 +- .../examples/elf_remove_section_table.py | 2 +- api/python/examples/elf_unstrip.py | 12 +- api/python/examples/oat_reader.py | 7 +- api/python/examples/pe_forwardinfo.py | 2 +- api/python/examples/pe_from_scratch.py | 2 +- api/python/examples/pe_reader.py | 7 +- api/python/examples/pe_resources_manager.py | 2 +- api/python/examples/vdex_json.py | 2 +- api/python/examples/vdex_reader.py | 7 +- api/python/src/ELF/CMakeLists.txt | 1 + api/python/src/ELF/enums.cpp | 1482 ++------------- api/python/src/ELF/init.cpp | 1 + api/python/src/ELF/objects/CMakeLists.txt | 1 + api/python/src/ELF/objects/pyBinary.cpp | 37 +- api/python/src/ELF/objects/pyBuilder.cpp | 22 +- api/python/src/ELF/objects/pyDynamicEntry.cpp | 145 +- .../src/ELF/objects/pyDynamicEntryArray.cpp | 7 +- .../src/ELF/objects/pyDynamicEntryFlags.cpp | 96 +- .../src/ELF/objects/pyDynamicEntryLibrary.cpp | 2 +- .../src/ELF/objects/pyDynamicEntryRpath.cpp | 16 +- .../src/ELF/objects/pyDynamicEntryRunPath.cpp | 19 +- .../src/ELF/objects/pyDynamicSharedObject.cpp | 2 +- api/python/src/ELF/objects/pyHeader.cpp | 191 +- api/python/src/ELF/objects/pyNote.cpp | 14 +- api/python/src/ELF/objects/pyParserConfig.cpp | 13 +- api/python/src/ELF/objects/pyRelocation.cpp | 39 +- .../src/ELF/objects/pyRelocationTypes.cpp | 46 + api/python/src/ELF/objects/pySection.cpp | 126 +- api/python/src/ELF/objects/pySegment.cpp | 82 +- api/python/src/ELF/objects/pySymbol.cpp | 55 +- .../src/ELF/objects/pySymbolVersionAux.cpp | 2 +- api/python/src/ELF/pyProcessorFlags.cpp | 96 + doc/sphinx/api/c/elf.rst | 3 - doc/sphinx/api/cpp/elf.rst | 181 +- doc/sphinx/api/python/elf.rst | 220 +-- doc/sphinx/changelog.rst | 23 +- doc/sphinx/compilation.rst | 9 +- .../tutorials/03_elf_change_symbols.rst | 4 +- doc/sphinx/tutorials/04_elf_hooking.rst | 2 +- .../tutorials/05_elf_infect_plt_got.rst | 2 +- doc/sphinx/tutorials/08_elf_bin2lib.rst | 2 +- doc/sphinx/tutorials/09_frida_lief.rst | 4 +- examples/c/elf_reader.c | 101 +- examples/cpp/elf_builder.cpp | 2 +- include/LIEF/Abstract/Header.hpp | 2 +- include/LIEF/ELF.hpp | 1 - include/LIEF/ELF/Binary.hpp | 261 ++- include/LIEF/ELF/DynamicEntry.hpp | 198 +- include/LIEF/ELF/DynamicEntryArray.hpp | 61 +- include/LIEF/ELF/DynamicEntryFlags.hpp | 110 +- include/LIEF/ELF/DynamicEntryLibrary.hpp | 34 +- include/LIEF/ELF/DynamicEntryRpath.hpp | 52 +- include/LIEF/ELF/DynamicEntryRunPath.hpp | 51 +- include/LIEF/ELF/DynamicSharedObject.hpp | 36 +- include/LIEF/ELF/EnumToString.hpp | 36 - include/LIEF/ELF/GnuHash.hpp | 44 +- include/LIEF/ELF/Header.hpp | 462 +++-- include/LIEF/ELF/Note.hpp | 14 +- .../LIEF/ELF/NoteDetails/NoteGnuProperty.hpp | 8 +- .../LIEF/ELF/NoteDetails/core/CoreAuxv.hpp | 6 +- .../LIEF/ELF/NoteDetails/core/CoreFile.hpp | 6 +- .../ELF/NoteDetails/core/CorePrPsInfo.hpp | 6 +- .../ELF/NoteDetails/core/CorePrStatus.hpp | 14 +- include/LIEF/ELF/Parser.hpp | 27 +- include/LIEF/ELF/ParserConfig.hpp | 12 +- include/LIEF/ELF/ProcessorFlags.hpp | 115 ++ include/LIEF/ELF/Relocation.hpp | 291 ++- include/LIEF/ELF/RelocationSizes.hpp | 38 - include/LIEF/ELF/Relocations/AArch64.def | 282 +-- include/LIEF/ELF/Relocations/ARM.def | 276 +-- include/LIEF/ELF/Relocations/Hexagon.def | 188 +- include/LIEF/ELF/Relocations/LoongArch.def | 178 +- include/LIEF/ELF/Relocations/Mips.def | 224 +-- include/LIEF/ELF/Relocations/PowerPC.def | 114 +- include/LIEF/ELF/Relocations/PowerPC64.def | 168 +- include/LIEF/ELF/Relocations/Sparc.def | 168 +- include/LIEF/ELF/Relocations/SystemZ.def | 124 +- include/LIEF/ELF/Relocations/i386.def | 81 +- include/LIEF/ELF/Relocations/x86_64.def | 86 +- include/LIEF/ELF/Section.hpp | 264 ++- include/LIEF/ELF/Segment.hpp | 214 ++- include/LIEF/ELF/Symbol.hpp | 251 ++- include/LIEF/ELF/SymbolVersion.hpp | 42 +- include/LIEF/ELF/SymbolVersionAux.hpp | 27 +- .../LIEF/ELF/SymbolVersionAuxRequirement.hpp | 41 +- include/LIEF/ELF/SymbolVersionDefinition.hpp | 42 +- include/LIEF/ELF/SymbolVersionRequirement.hpp | 43 +- include/LIEF/ELF/SysvHash.hpp | 30 +- include/LIEF/ELF/enums.hpp | 1060 ++--------- include/LIEF/ELF/enums.inc | 978 ---------- include/LIEF/ELF/undef.h | 2 - src/ELF/Binary.cpp | 838 +++----- src/ELF/Binary.tcc | 100 +- src/ELF/Builder.cpp | 38 +- src/ELF/Builder.tcc | 182 +- src/ELF/CMakeLists.txt | 2 + src/ELF/DynamicEntry.cpp | 243 ++- src/ELF/DynamicEntryArray.cpp | 74 +- src/ELF/DynamicEntryFlags.cpp | 240 ++- src/ELF/DynamicEntryLibrary.cpp | 37 +- src/ELF/DynamicEntryRpath.cpp | 58 +- src/ELF/DynamicEntryRunPath.cpp | 59 +- src/ELF/DynamicSharedObject.cpp | 37 +- src/ELF/EnumToString.cpp | 1692 ++--------------- src/ELF/ExeLayout.hpp | 119 +- src/ELF/GnuHash.cpp | 44 - src/ELF/Header.cpp | 832 +++----- src/ELF/Layout.cpp | 14 +- src/ELF/Layout.hpp | 6 +- src/ELF/Note.cpp | 30 +- src/ELF/NoteDetails/NoteGnuProperty.cpp | 12 +- src/ELF/NoteDetails/core/CoreAuxv.cpp | 6 +- src/ELF/NoteDetails/core/CoreFile.cpp | 10 +- src/ELF/NoteDetails/core/CorePrPsInfo.cpp | 4 +- src/ELF/NoteDetails/core/CorePrStatus.cpp | 72 +- src/ELF/ObjectFileLayout.hpp | 2 +- src/ELF/Parser.cpp | 179 +- src/ELF/Parser.tcc | 261 +-- src/ELF/ProcessorFlags.cpp | 95 + src/ELF/Relocation.cpp | 413 +--- src/ELF/RelocationSizes.cpp | 1441 +++++++------- src/ELF/RelocationStrings.cpp | 215 +++ src/ELF/Section.cpp | 376 ++-- src/ELF/Segment.cpp | 270 +-- src/ELF/Structures.hpp | 130 -- src/ELF/Symbol.cpp | 223 +-- src/ELF/SymbolVersion.cpp | 43 - src/ELF/SymbolVersionAux.cpp | 26 - src/ELF/SymbolVersionAuxRequirement.cpp | 44 - src/ELF/SymbolVersionDefinition.cpp | 44 - src/ELF/SymbolVersionRequirement.cpp | 49 - src/ELF/SysvHash.cpp | 27 - src/ELF/json.cpp | 38 +- src/ELF/utils.cpp | 8 - src/OAT/Parser.cpp | 4 +- tests/elf/check_bin_examples.py | 14 +- tests/elf/test_466.py | 12 +- tests/elf/test_808.py | 2 +- tests/elf/test_add_content.py | 15 +- tests/elf/test_add_section.py | 20 +- tests/elf/test_add_segment.py | 26 +- tests/elf/test_architectures.py | 14 +- tests/elf/test_bin2lib.py | 31 +- tests/elf/test_binary_size.py | 2 +- tests/elf/test_bss.py | 16 +- tests/elf/test_builder.py | 20 +- tests/elf/test_core.py | 22 +- tests/elf/test_corrupted.py | 2 +- tests/elf/test_dynamic.py | 35 +- tests/elf/test_elf.py | 92 +- tests/elf/test_elf_config.py | 8 +- tests/elf/test_empty_gnu_hash.py | 5 +- tests/elf/test_equality.py | 4 +- tests/elf/test_hash.py | 11 +- tests/elf/test_i872.py | 24 +- tests/elf/test_issues.py | 4 +- tests/elf/test_loongarch.py | 2 +- tests/elf/test_modify_relocations.py | 14 +- tests/elf/test_notes.py | 47 +- tests/elf/test_object_files.py | 20 +- tests/elf/test_parser.py | 48 +- tests/elf/test_parser_simple.py | 28 +- tests/elf/test_remove_section.py | 2 +- tests/elf/test_replace_segment.py | 26 +- tests/elf/test_section_frame.py | 18 +- tests/elf/test_sectionless.py | 2 +- tests/elf/test_static.py | 8 +- tests/elf/test_str_hash.py | 64 +- 192 files changed, 8772 insertions(+), 11789 deletions(-) delete mode 100644 api/c/ELF/EnumToString.cpp delete mode 100644 api/c/include/LIEF/ELF/EnumToString.h create mode 100644 api/python/src/ELF/objects/pyRelocationTypes.cpp create mode 100644 api/python/src/ELF/pyProcessorFlags.cpp create mode 100644 include/LIEF/ELF/ProcessorFlags.hpp delete mode 100644 include/LIEF/ELF/RelocationSizes.hpp create mode 100644 src/ELF/ProcessorFlags.cpp create mode 100644 src/ELF/RelocationStrings.cpp diff --git a/api/c/ELF/Binary.cpp b/api/c/ELF/Binary.cpp index f3220b8fb6..1f53a073cb 100644 --- a/api/c/ELF/Binary.cpp +++ b/api/c/ELF/Binary.cpp @@ -36,7 +36,7 @@ namespace LIEF { namespace ELF { void init_c_binary(Elf_Binary_t* c_binary, Binary* binary) { c_binary->handler = reinterpret_cast(binary); - c_binary->type = static_cast(binary->type()); + c_binary->type = static_cast(binary->type()); c_binary->interpreter = nullptr; if (binary->has_interpreter()) { const std::string& interp = binary->interpreter(); @@ -48,7 +48,6 @@ void init_c_binary(Elf_Binary_t* c_binary, Binary* binary) { reinterpret_cast(const_cast(c_binary->interpreter))[interp.size()] = '\0'; } - init_c_header(c_binary, binary); init_c_sections(c_binary, binary); init_c_segments(c_binary, binary); @@ -81,9 +80,9 @@ Elf_Binary_t* elf_parse(const char *file) { int elf_binary_save_header(Elf_Binary_t* binary) { Header& hdr = reinterpret_cast(binary->handler)->header(); - hdr.file_type(static_cast(binary->header.file_type)); - hdr.machine_type(static_cast(binary->header.machine_type)); - hdr.object_file_version(static_cast(binary->header.object_file_version)); + hdr.file_type(LIEF::ELF::Header::FILE_TYPE(binary->header.file_type)); + hdr.machine_type(LIEF::ELF::ARCH(binary->header.machine_type)); + hdr.object_file_version(LIEF::ELF::Header::VERSION(binary->header.object_file_version)); hdr.program_headers_offset(binary->header.program_headers_offset); hdr.section_headers_offset(binary->header.section_headers_offset); hdr.processor_flag(binary->header.processor_flags); diff --git a/api/c/ELF/CMakeLists.txt b/api/c/ELF/CMakeLists.txt index 538b4848bc..77fbfe0534 100644 --- a/api/c/ELF/CMakeLists.txt +++ b/api/c/ELF/CMakeLists.txt @@ -5,6 +5,5 @@ target_sources(LIB_LIEF PRIVATE DynamicEntry.cpp Header.cpp Binary.cpp - EnumToString.cpp utils.cpp ) diff --git a/api/c/ELF/DynamicEntry.cpp b/api/c/ELF/DynamicEntry.cpp index 363e661c83..59217d1a78 100644 --- a/api/c/ELF/DynamicEntry.cpp +++ b/api/c/ELF/DynamicEntry.cpp @@ -34,13 +34,12 @@ void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) { for (size_t i = 0; i < dyn_entries.size(); ++i) { DynamicEntry& entry = dyn_entries[i]; switch(entry.tag()) { - case DYNAMIC_TAGS::DT_NEEDED: + case DynamicEntry::TAG::NEEDED: { - auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_Library_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); e->name = reinterpret_cast(&entry)->name().c_str(); @@ -48,12 +47,12 @@ void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) { break; } - case DYNAMIC_TAGS::DT_SONAME: + case DynamicEntry::TAG::SONAME: { auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_SharedObject_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); e->name = reinterpret_cast(&entry)->name().c_str(); @@ -61,42 +60,42 @@ void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) { break; } - case DYNAMIC_TAGS::DT_RPATH: + case DynamicEntry::TAG::RPATH: { auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_Rpath_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); - e->rpath = reinterpret_cast(&entry)->name().c_str(); + e->rpath = reinterpret_cast(&entry)->rpath().c_str(); c_binary->dynamic_entries[i] = reinterpret_cast(e); break; } - case DYNAMIC_TAGS::DT_RUNPATH: + case DynamicEntry::TAG::RUNPATH: { auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_RunPath_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); - e->runpath = reinterpret_cast(&entry)->name().c_str(); + e->runpath = reinterpret_cast(&entry)->runpath().c_str(); c_binary->dynamic_entries[i] = reinterpret_cast(e); break; } - case DYNAMIC_TAGS::DT_INIT_ARRAY: - case DYNAMIC_TAGS::DT_FINI_ARRAY: - case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + case DynamicEntry::TAG::INIT_ARRAY: + case DynamicEntry::TAG::FINI_ARRAY: + case DynamicEntry::TAG::PREINIT_ARRAY: { auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_Array_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); const std::vector& array = reinterpret_cast(&entry)->array(); e->array = static_cast(malloc((array.size() + 1) * sizeof(uint64_t))); @@ -109,55 +108,33 @@ void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) { break; } - case DYNAMIC_TAGS::DT_FLAGS: + case DynamicEntry::TAG::FLAGS: { auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_Flags_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); const DynamicEntryFlags::flags_list_t& flags = reinterpret_cast(&entry)->flags(); - e->flags = static_cast(malloc((flags.size() + 1) * sizeof(enum LIEF_ELF_DYNAMIC_FLAGS))); - e->flags_1 = nullptr; - - auto it = std::begin(flags); - - for (size_t i = 0; it != std::end(flags); ++i, ++it) { - e->flags[i] = static_cast(*it); - } - e->flags[flags.size()] = static_cast(0); c_binary->dynamic_entries[i] = reinterpret_cast(e); break; } - case DYNAMIC_TAGS::DT_FLAGS_1: + case DynamicEntry::TAG::FLAGS_1: { auto* e = static_cast( malloc(sizeof(Elf_DynamicEntry_Flags_t))); - e->tag = static_cast(entry.tag()); + e->tag = static_cast(entry.tag()); e->value = entry.value(); const DynamicEntryFlags::flags_list_t& flags = reinterpret_cast(&entry)->flags(); - e->flags_1 = static_cast(malloc((flags.size() + 1) * sizeof(enum LIEF_ELF_DYNAMIC_FLAGS_1))); - e->flags = nullptr; - - auto it = std::begin(flags); - - for (size_t i = 0; it != std::end(flags); ++i, ++it) { - e->flags_1[i] = static_cast(*it); - } - - e->flags_1[flags.size()] = static_cast(0); c_binary->dynamic_entries[i] = reinterpret_cast(e); break; } - - - default: { c_binary->dynamic_entries[i] = @@ -170,7 +147,6 @@ void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) { } c_binary->dynamic_entries[dyn_entries.size()] = nullptr; - } @@ -179,34 +155,34 @@ void destroy_dynamic_entries(Elf_Binary_t* c_binary) { Elf_DynamicEntry_t **dynamic_entries = c_binary->dynamic_entries; for (size_t idx = 0; dynamic_entries[idx] != nullptr; ++idx) { - switch(static_cast(dynamic_entries[idx]->tag)) { - case DYNAMIC_TAGS::DT_NEEDED: + switch(DynamicEntry::TAG(dynamic_entries[idx]->tag)) { + case DynamicEntry::TAG::NEEDED: { free(reinterpret_cast(dynamic_entries[idx])); break; } - case DYNAMIC_TAGS::DT_SONAME: + case DynamicEntry::TAG::SONAME: { free(reinterpret_cast(dynamic_entries[idx])); break; } - case DYNAMIC_TAGS::DT_RPATH: + case DynamicEntry::TAG::RPATH: { free(reinterpret_cast(dynamic_entries[idx])); break; } - case DYNAMIC_TAGS::DT_RUNPATH: + case DynamicEntry::TAG::RUNPATH: { free(reinterpret_cast(dynamic_entries[idx])); break; } - case DYNAMIC_TAGS::DT_INIT_ARRAY: - case DYNAMIC_TAGS::DT_FINI_ARRAY: - case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + case DynamicEntry::TAG::INIT_ARRAY: + case DynamicEntry::TAG::FINI_ARRAY: + case DynamicEntry::TAG::PREINIT_ARRAY: { Elf_DynamicEntry_Array_t* entry_array=reinterpret_cast(dynamic_entries[idx]); free(entry_array->array); @@ -214,24 +190,21 @@ void destroy_dynamic_entries(Elf_Binary_t* c_binary) { break; } - case DYNAMIC_TAGS::DT_FLAGS: + case DynamicEntry::TAG::FLAGS: { Elf_DynamicEntry_Flags_t* entry_flags=reinterpret_cast(dynamic_entries[idx]); - free(entry_flags->flags); free(entry_flags); break; } - case DYNAMIC_TAGS::DT_FLAGS_1: + case DynamicEntry::TAG::FLAGS_1: { Elf_DynamicEntry_Flags_t* entry_flags=reinterpret_cast(dynamic_entries[idx]); - free(entry_flags->flags_1); free(entry_flags); break; } default: { - free(dynamic_entries[idx]); } @@ -244,5 +217,3 @@ void destroy_dynamic_entries(Elf_Binary_t* c_binary) { } } - - diff --git a/api/c/ELF/EnumToString.cpp b/api/c/ELF/EnumToString.cpp deleted file mode 100644 index 59375ce36c..0000000000 --- a/api/c/ELF/EnumToString.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright 2017 - 2023 R. Thomas - * Copyright 2017 - 2023 Quarkslab - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "LIEF/ELF/EnumToString.h" -#include "LIEF/ELF/EnumToString.hpp" - -#include "LIEF/ELF/enums.h" -#include "LIEF/ELF/enums.hpp" - -extern "C" -{ - const char* E_TYPE_to_string(enum LIEF_ELF_E_TYPE e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* SYMBOL_BINDINGS_to_string(enum LIEF_ELF_SYMBOL_BINDINGS e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* VERSION_to_string(enum LIEF_ELF_VERSION e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* ARCH_to_string(enum LIEF_ELF_ARCH e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* SEGMENT_TYPES_to_string(enum LIEF_ELF_SEGMENT_TYPES e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* DYNAMIC_TAGS_to_string(enum LIEF_ELF_DYNAMIC_TAGS e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* ELF_SECTION_TYPES_to_string(enum LIEF_ELF_ELF_SECTION_TYPES e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* ELF_SECTION_FLAGS_to_string(enum LIEF_ELF_ELF_SECTION_FLAGS e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* ELF_SYMBOL_TYPES_to_string(enum LIEF_ELF_ELF_SYMBOL_TYPES e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* ELF_CLASS_to_string(enum LIEF_ELF_ELF_CLASS e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* ELF_DATA_to_string(enum LIEF_ELF_ELF_DATA e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* OS_ABI_to_string(enum LIEF_ELF_OS_ABI e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* DYNAMIC_FLAGS_to_string(enum LIEF_ELF_DYNAMIC_FLAGS e) { - return LIEF::ELF::to_string(static_cast(e)); - } - - const char* DYNAMIC_FLAGS_1_to_string(enum LIEF_ELF_DYNAMIC_FLAGS_1 e) { - return LIEF::ELF::to_string(static_cast(e)); - } - -} diff --git a/api/c/ELF/Header.cpp b/api/c/ELF/Header.cpp index 4e6a642883..066955b584 100644 --- a/api/c/ELF/Header.cpp +++ b/api/c/ELF/Header.cpp @@ -21,9 +21,9 @@ namespace ELF { void init_c_header(Elf_Binary_t* c_binary, Binary* binary) { const Header& hdr = binary->header(); - c_binary->header.file_type = static_cast(hdr.file_type()); - c_binary->header.machine_type = static_cast(hdr.machine_type()); - c_binary->header.object_file_version = static_cast(hdr.object_file_version()); + c_binary->header.file_type = static_cast(hdr.file_type()); + c_binary->header.machine_type = static_cast(hdr.machine_type()); + c_binary->header.object_file_version = static_cast(hdr.object_file_version()); c_binary->header.program_headers_offset = hdr.program_headers_offset(); c_binary->header.section_headers_offset = hdr.section_headers_offset(); c_binary->header.processor_flags = hdr.processor_flag(); @@ -35,10 +35,7 @@ void init_c_header(Elf_Binary_t* c_binary, Binary* binary) { c_binary->header.name_string_table_idx = hdr.section_name_table_idx(); c_binary->header.entrypoint = hdr.entrypoint(); const Header::identity_t& ident = hdr.identity(); - std::copy( - std::begin(ident), - std::end(ident), - c_binary->header.identity); + std::copy(std::begin(ident), std::end(ident), c_binary->header.identity); } diff --git a/api/c/ELF/Section.cpp b/api/c/ELF/Section.cpp index 273bfca171..0fabf2b7e8 100644 --- a/api/c/ELF/Section.cpp +++ b/api/c/ELF/Section.cpp @@ -31,7 +31,7 @@ void init_c_sections(Elf_Binary_t* c_binary, Binary* binary) { c_binary->sections[i]->name = b_section.fullname().c_str(); c_binary->sections[i]->flags = b_section.flags(); - c_binary->sections[i]->type = static_cast(b_section.type()); + c_binary->sections[i]->type = static_cast(b_section.type()); c_binary->sections[i]->virtual_address = b_section.virtual_address(); c_binary->sections[i]->offset = b_section.file_offset(); c_binary->sections[i]->original_size = b_section.original_size(); diff --git a/api/c/ELF/Segment.cpp b/api/c/ELF/Segment.cpp index 2ccd4136f6..c1bc0337a3 100644 --- a/api/c/ELF/Segment.cpp +++ b/api/c/ELF/Segment.cpp @@ -29,7 +29,7 @@ void init_c_segments(Elf_Binary_t* c_binary, Binary* binary) { span segment_content = segment.content(); c_binary->segments[i] = static_cast(malloc(sizeof(Elf_Segment_t))); - c_binary->segments[i]->type = static_cast(segment.type()); + c_binary->segments[i]->type = static_cast(segment.type()); c_binary->segments[i]->flags = static_cast(segment.flags()); c_binary->segments[i]->virtual_address = segment.virtual_address(); c_binary->segments[i]->virtual_size = segment.virtual_size(); @@ -44,10 +44,7 @@ void init_c_segments(Elf_Binary_t* c_binary, Binary* binary) { } - - void destroy_segments(Elf_Binary_t* c_binary) { - Elf_Segment_t **segments = c_binary->segments; for (size_t idx = 0; segments[idx] != nullptr; ++idx) { free(segments[idx]); diff --git a/api/c/ELF/Symbol.cpp b/api/c/ELF/Symbol.cpp index b591bd156c..44cb0a9ea7 100644 --- a/api/c/ELF/Symbol.cpp +++ b/api/c/ELF/Symbol.cpp @@ -28,8 +28,8 @@ void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary) { Symbol& b_sym = dyn_symb[i]; c_binary->dynamic_symbols[i] = static_cast(malloc(sizeof(Elf_Symbol_t))); c_binary->dynamic_symbols[i]->name = b_sym.name().c_str(); - c_binary->dynamic_symbols[i]->type = static_cast(b_sym.type()); - c_binary->dynamic_symbols[i]->binding = static_cast(b_sym.binding()); + c_binary->dynamic_symbols[i]->type = static_cast(b_sym.type()); + c_binary->dynamic_symbols[i]->binding = static_cast(b_sym.binding()); c_binary->dynamic_symbols[i]->other = b_sym.other(); c_binary->dynamic_symbols[i]->shndx = b_sym.shndx(); c_binary->dynamic_symbols[i]->value = b_sym.value(); @@ -40,8 +40,6 @@ void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary) { } c_binary->dynamic_symbols[dyn_symb.size()] = nullptr; - - } @@ -55,8 +53,8 @@ void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary) { Symbol& b_sym = static_symb[i]; c_binary->static_symbols[i] = static_cast(malloc(sizeof(Elf_Symbol_t))); c_binary->static_symbols[i]->name = b_sym.name().c_str(); - c_binary->static_symbols[i]->type = static_cast(b_sym.type()); - c_binary->static_symbols[i]->binding = static_cast(b_sym.binding()); + c_binary->static_symbols[i]->type = static_cast(b_sym.type()); + c_binary->static_symbols[i]->binding = static_cast(b_sym.binding()); c_binary->static_symbols[i]->other = b_sym.other(); c_binary->static_symbols[i]->shndx = b_sym.shndx(); c_binary->static_symbols[i]->value = b_sym.value(); diff --git a/api/c/include/LIEF/ELF.h b/api/c/include/LIEF/ELF.h index a21be96227..9beab7e660 100644 --- a/api/c/include/LIEF/ELF.h +++ b/api/c/include/LIEF/ELF.h @@ -21,7 +21,6 @@ #include "LIEF/ELF/Section.h" #include "LIEF/ELF/Header.h" #include "LIEF/ELF/DynamicEntry.h" -#include "LIEF/ELF/EnumToString.h" #include "LIEF/ELF/utils.h" #endif diff --git a/api/c/include/LIEF/ELF/Binary.h b/api/c/include/LIEF/ELF/Binary.h index 078f5be137..cd78c4229a 100644 --- a/api/c/include/LIEF/ELF/Binary.h +++ b/api/c/include/LIEF/ELF/Binary.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_BINARY_H_ -#define C_LIEF_ELF_BINARY_H_ +#ifndef LIEF_C_ELF_BINARY_H +#define LIEF_C_ELF_BINARY_H #include @@ -37,7 +37,7 @@ struct Elf_Binary_t { void* handler; const char* name; const char* interpreter; - enum LIEF_ELF_ELF_CLASS type; + uint32_t type; Elf_Header_t header; Elf_Section_t **sections; Elf_Segment_t **segments; diff --git a/api/c/include/LIEF/ELF/DynamicEntry.h b/api/c/include/LIEF/ELF/DynamicEntry.h index 3b26c3bf42..ba4c18edd2 100644 --- a/api/c/include/LIEF/ELF/DynamicEntry.h +++ b/api/c/include/LIEF/ELF/DynamicEntry.h @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_DYNAMIC_ENTRY_H_ -#define C_LIEF_ELF_DYNAMIC_ENTRY_H_ +#ifndef LIEF_C_ELF_DYNAMIC_ENTRY_H +#define LIEF_C_ELF_DYNAMIC_ENTRY_H #include -#include "LIEF/ELF/enums.h" - #ifdef __cplusplus extern "C" { #endif @@ -59,12 +57,9 @@ struct Elf_DynamicEntry_RunPath_t { const char* runpath; }; - struct Elf_DynamicEntry_Flags_t { uint64_t tag; uint64_t value; - enum LIEF_ELF_DYNAMIC_FLAGS *flags; - enum LIEF_ELF_DYNAMIC_FLAGS_1 *flags_1; }; typedef struct Elf_DynamicEntry_t Elf_DynamicEntry_t; diff --git a/api/c/include/LIEF/ELF/EnumToString.h b/api/c/include/LIEF/ELF/EnumToString.h deleted file mode 100644 index d84912e8d8..0000000000 --- a/api/c/include/LIEF/ELF/EnumToString.h +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright 2017 - 2023 R. Thomas - * Copyright 2017 - 2023 Quarkslab - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef C_LIEF_ELF_ENUM_TO_STRING_H_ -#define C_LIEF_ELF_ENUM_TO_STRING_H_ - -#include "LIEF/visibility.h" - -#include "LIEF/ELF/enums.h" - -#ifdef __cplusplus -extern "C" { -#endif - -LIEF_API const char* SYMBOL_BINDINGS_to_string(enum LIEF_ELF_SYMBOL_BINDINGS e); -LIEF_API const char* E_TYPE_to_string(enum LIEF_ELF_E_TYPE e); -LIEF_API const char* VERSION_to_string(enum LIEF_ELF_VERSION e); -LIEF_API const char* ARCH_to_string(enum LIEF_ELF_ARCH e); -LIEF_API const char* SEGMENT_TYPES_to_string(enum LIEF_ELF_SEGMENT_TYPES e); -LIEF_API const char* DYNAMIC_TAGS_to_string(enum LIEF_ELF_DYNAMIC_TAGS e); -LIEF_API const char* ELF_SECTION_TYPES_to_string(enum LIEF_ELF_ELF_SECTION_TYPES e); -LIEF_API const char* ELF_SECTION_FLAGS_to_string(enum LIEF_ELF_ELF_SECTION_FLAGS e); -LIEF_API const char* ELF_SYMBOL_TYPES_to_string(enum LIEF_ELF_ELF_SYMBOL_TYPES e); -LIEF_API const char* ELF_CLASS_to_string(enum LIEF_ELF_ELF_CLASS e); -LIEF_API const char* ELF_DATA_to_string(enum LIEF_ELF_ELF_DATA e); -LIEF_API const char* OS_ABI_to_string(enum LIEF_ELF_OS_ABI e); -LIEF_API const char* DYNAMIC_FLAGS_to_string(enum LIEF_ELF_DYNAMIC_FLAGS e); -LIEF_API const char* DYNAMIC_FLAGS_1_to_string(enum LIEF_ELF_DYNAMIC_FLAGS_1 e); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/api/c/include/LIEF/ELF/Header.h b/api/c/include/LIEF/ELF/Header.h index 1559b26ae8..145e1c96ae 100644 --- a/api/c/include/LIEF/ELF/Header.h +++ b/api/c/include/LIEF/ELF/Header.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_HEADER_H_ -#define C_LIEF_ELF_HEADER_H_ +#ifndef LIEF_C_ELF_HEADER_H +#define LIEF_C_ELF_HEADER_H #include #include "LIEF/ELF/enums.h" @@ -24,20 +24,20 @@ extern "C" { #endif struct Elf_Header_t { - uint8_t identity[LIEF_ELF_EI_NIDENT]; - enum LIEF_ELF_E_TYPE file_type; - enum LIEF_ELF_ARCH machine_type; - enum LIEF_ELF_VERSION object_file_version; - uint64_t entrypoint; - uint64_t program_headers_offset; - uint64_t section_headers_offset; - uint32_t processor_flags; - uint32_t header_size; - uint32_t program_header_size; - uint32_t numberof_segments; - uint32_t section_header_size; - uint32_t numberof_sections; - uint32_t name_string_table_idx; + uint8_t identity[LIEF_EI_NIDENT]; + uint32_t file_type; + uint32_t machine_type; + uint32_t object_file_version; + uint64_t entrypoint; + uint64_t program_headers_offset; + uint64_t section_headers_offset; + uint32_t processor_flags; + uint32_t header_size; + uint32_t program_header_size; + uint32_t numberof_segments; + uint32_t section_header_size; + uint32_t numberof_sections; + uint32_t name_string_table_idx; }; typedef struct Elf_Header_t Elf_Header_t; diff --git a/api/c/include/LIEF/ELF/Section.h b/api/c/include/LIEF/ELF/Section.h index 7cb1abcef0..6422528c2d 100644 --- a/api/c/include/LIEF/ELF/Section.h +++ b/api/c/include/LIEF/ELF/Section.h @@ -13,31 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_SECTION_H_ -#define C_LIEF_ELF_SECTION_H_ +#ifndef LIEF_C_ELF_SECTION_H +#define LIEF_C_ELF_SECTION_H #include -#include "LIEF/ELF/enums.h" - #ifdef __cplusplus extern "C" { #endif struct Elf_Section_t { - const char* name; - uint32_t flags; - enum LIEF_ELF_ELF_SECTION_TYPES type; - uint64_t virtual_address; - uint64_t offset; - uint64_t original_size; - uint32_t link; - uint32_t info; - uint64_t alignment; - uint64_t entry_size; - uint64_t size; - uint8_t* content; - double entropy; + const char* name; + uint32_t flags; + uint32_t type; + uint64_t virtual_address; + uint64_t offset; + uint64_t original_size; + uint32_t link; + uint32_t info; + uint64_t alignment; + uint64_t entry_size; + uint64_t size; + uint8_t* content; + double entropy; }; typedef struct Elf_Section_t Elf_Section_t; diff --git a/api/c/include/LIEF/ELF/Segment.h b/api/c/include/LIEF/ELF/Segment.h index 66d6e091ac..367c32d0e4 100644 --- a/api/c/include/LIEF/ELF/Segment.h +++ b/api/c/include/LIEF/ELF/Segment.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_SEGMENT_H_ -#define C_LIEF_ELF_SEGMENT_H_ +#ifndef LIEF_C_ELF_SEGMENT_H_ +#define LIEF_C_ELF_SEGMENT_H_ #include #include "LIEF/ELF/enums.h" @@ -24,14 +24,14 @@ extern "C" { #endif struct Elf_Segment_t { - enum LIEF_ELF_SEGMENT_TYPES type; - uint32_t flags; - uint64_t virtual_address; - uint64_t virtual_size; - uint64_t offset; - uint64_t alignment; - uint64_t size; - uint8_t* content; + uint32_t type; + uint32_t flags; + uint64_t virtual_address; + uint64_t virtual_size; + uint64_t offset; + uint64_t alignment; + uint64_t size; + uint8_t* content; }; typedef struct Elf_Segment_t Elf_Segment_t; diff --git a/api/c/include/LIEF/ELF/Symbol.h b/api/c/include/LIEF/ELF/Symbol.h index 6ca329965c..9c5b357406 100644 --- a/api/c/include/LIEF/ELF/Symbol.h +++ b/api/c/include/LIEF/ELF/Symbol.h @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_SYMBOL_H_ -#define C_LIEF_ELF_SYMBOL_H_ +#ifndef LIEF_C_ELF_SYMBOL_H +#define LIEF_C_ELF_SYMBOL_H #include - -#include "LIEF/ELF/enums.h" #include "LIEF/types.h" #ifdef __cplusplus @@ -26,16 +24,16 @@ extern "C" { #endif struct Elf_Symbol_t { - const char* name; - enum LIEF_ELF_ELF_SYMBOL_TYPES type; - enum LIEF_ELF_SYMBOL_BINDINGS binding; - uint8_t information; - uint8_t other; - uint16_t shndx; - uint64_t value; - uint64_t size; - bool is_exported; /**< Whether or not the symbol is exported */ - bool is_imported; /**< Whether or not the symbol is imported */ + const char* name; + uint32_t type; + uint32_t binding; + uint8_t information; + uint8_t other; + uint16_t shndx; + uint64_t value; + uint64_t size; + bool is_exported; /**< Whether or not the symbol is exported */ + bool is_imported; /**< Whether or not the symbol is imported */ }; typedef struct Elf_Symbol_t Elf_Symbol_t; diff --git a/api/c/include/LIEF/ELF/enums.h b/api/c/include/LIEF/ELF/enums.h index a949555298..d91a116398 100644 --- a/api/c/include/LIEF/ELF/enums.h +++ b/api/c/include/LIEF/ELF/enums.h @@ -6,15 +6,980 @@ extern "C" { #endif -#define _LIEF_EN(N) LIEF_ELF_##N -#define _LIEF_EN_2(N, TYPE) LIEF_ELF_##N -#define _LIEF_EI(X) LIEF_ELF_##X +/** e_ident size and indices. */ +enum LIEF_IDENTITY { + LIEF_EI_MAG0 = 0, /**< File identification index. */ + LIEF_EI_MAG1 = 1, /**< File identification index. */ + LIEF_EI_MAG2 = 2, /**< File identification index. */ + LIEF_EI_MAG3 = 3, /**< File identification index. */ + LIEF_EI_CLASS = 4, /**< File class. */ + LIEF_EI_DATA = 5, /**< Data encoding. */ + LIEF_EI_VERSION = 6, /**< File version. */ + LIEF_EI_OSABI = 7, /**< OS/ABI identification. */ + LIEF_EI_ABIVERSION = 8, /**< ABI version. */ + LIEF_EI_PAD = 9, /**< Start of padding bytes. */ + LIEF_EI_NIDENT = 16 /**< Number of bytes in e_ident. */ +}; -#include "LIEF/ELF/enums.inc" -#undef _LIEF_EN -#undef _LIEF_EN_2 -#undef _LIEF_EI +/** Enum associated with *e_type* */ +enum LIEF_E_TYPE { + LIEF_ET_NONE = 0, /**< No file type */ + LIEF_ET_REL = 1, /**< Relocatable file */ + LIEF_ET_EXEC = 2, /**< Executable file */ + LIEF_ET_DYN = 3, /**< Shared object file */ + LIEF_ET_CORE = 4, /**< Core file */ + LIEF_ET_LOPROC = 0xff00, /**< Beginning of processor-specific codes */ + LIEF_ET_HIPROC = 0xffff /**< Processor-specific */ +}; + + +/** Versioning */ +enum LIEF_VERSION { + LIEF_EV_NONE = 0, + LIEF_EV_CURRENT = 1 /**< Default value */ +}; + +/** + * @brief Machine architectures + * See current registered ELF machine architectures at: + * http://www.sco.com/developers/gabi/latest/ch4.eheader.html + */ +enum LIEF_ARCH { + LIEF_EM_NONE = 0, /**< No machine */ + LIEF_EM_M32 = 1, /**< AT&T WE 32100 */ + LIEF_EM_SPARC = 2, /**< SPARC */ + LIEF_EM_386 = 3, /**< Intel 386 */ + LIEF_EM_68K = 4, /**< Motorola 68000 */ + LIEF_EM_88K = 5, /**< Motorola 88000 */ + LIEF_EM_IAMCU = 6, /**< Intel MCU */ + LIEF_EM_860 = 7, /**< Intel 80860 */ + LIEF_EM_MIPS = 8, /**< MIPS R3000 */ + LIEF_EM_S370 = 9, /**< IBM System/370 */ + LIEF_EM_MIPS_RS3_LE = 10, /**< MIPS RS3000 Little-endian */ + LIEF_EM_PARISC = 15, /**< Hewlett-Packard PA-RISC */ + LIEF_EM_VPP500 = 17, /**< Fujitsu VPP500 */ + LIEF_EM_SPARC32PLUS = 18, /**< Enhanced instruction set SPARC */ + LIEF_EM_960 = 19, /**< Intel 80960 */ + LIEF_EM_PPC = 20, /**< PowerPC */ + LIEF_EM_PPC64 = 21, /**< PowerPC64 */ + LIEF_EM_S390 = 22, /**< IBM System/390 */ + LIEF_EM_SPU = 23, /**< IBM SPU/SPC */ + LIEF_EM_V800 = 36, /**< NEC V800 */ + LIEF_EM_FR20 = 37, /**< Fujitsu FR20 */ + LIEF_EM_RH32 = 38, /**< TRW RH-32 */ + LIEF_EM_RCE = 39, /**< Motorola RCE */ + LIEF_EM_ARM = 40, /**< ARM */ + LIEF_EM_ALPHA = 41, /**< DEC Alpha */ + LIEF_EM_SH = 42, /**< Hitachi SH */ + LIEF_EM_SPARCV9 = 43, /**< SPARC V9 */ + LIEF_EM_TRICORE = 44, /**< Siemens TriCore */ + LIEF_EM_ARC = 45, /**< Argonaut RISC Core */ + LIEF_EM_H8_300 = 46, /**< Hitachi H8/300 */ + LIEF_EM_H8_300H = 47, /**< Hitachi H8/300H */ + LIEF_EM_H8S = 48, /**< Hitachi H8S */ + LIEF_EM_H8_500 = 49, /**< Hitachi H8/500 */ + LIEF_EM_IA_64 = 50, /**< Intel IA-64 processor architecture */ + LIEF_EM_MIPS_X = 51, /**< Stanford MIPS-X */ + LIEF_EM_COLDFIRE = 52, /**< Motorola ColdFire */ + LIEF_EM_68HC12 = 53, /**< Motorola M68HC12 */ + LIEF_EM_MMA = 54, /**< Fujitsu MMA Multimedia Accelerator */ + LIEF_EM_PCP = 55, /**< Siemens PCP */ + LIEF_EM_NCPU = 56, /**< Sony nCPU embedded RISC processor */ + LIEF_EM_NDR1 = 57, /**< Denso NDR1 microprocessor */ + LIEF_EM_STARCORE = 58, /**< Motorola Star*Core processor */ + LIEF_EM_ME16 = 59, /**< Toyota ME16 processor */ + LIEF_EM_ST100 = 60, /**< STMicroelectronics ST100 processor */ + LIEF_EM_TINYJ = 61, /**< Advanced Logic Corp. TinyJ embedded processor family */ + LIEF_EM_X86_64 = 62, /**< AMD x86-64 architecture */ + LIEF_EM_PDSP = 63, /**< Sony DSP Processor */ + LIEF_EM_PDP10 = 64, /**< Digital Equipment Corp. PDP-10 */ + LIEF_EM_PDP11 = 65, /**< Digital Equipment Corp. PDP-11 */ + LIEF_EM_FX66 = 66, /**< Siemens FX66 microcontroller */ + LIEF_EM_ST9PLUS = 67, /**< STMicroelectronics ST9+ 8/16 bit microcontroller */ + LIEF_EM_ST7 = 68, /**< STMicroelectronics ST7 8-bit microcontroller */ + LIEF_EM_68HC16 = 69, /**< Motorola MC68HC16 Microcontroller */ + LIEF_EM_68HC11 = 70, /**< Motorola MC68HC11 Microcontroller */ + LIEF_EM_68HC08 = 71, /**< Motorola MC68HC08 Microcontroller */ + LIEF_EM_68HC05 = 72, /**< Motorola MC68HC05 Microcontroller */ + LIEF_EM_SVX = 73, /**< Silicon Graphics SVx */ + LIEF_EM_ST19 = 74, /**< STMicroelectronics ST19 8-bit microcontroller */ + LIEF_EM_VAX = 75, /**< Digital VAX */ + LIEF_EM_CRIS = 76, /**< Axis Communications 32-bit embedded processor */ + LIEF_EM_JAVELIN = 77, /**< Infineon Technologies 32-bit embedded processor */ + LIEF_EM_FIREPATH = 78, /**< Element 14 64-bit DSP Processor */ + LIEF_EM_ZSP = 79, /**< LSI Logic 16-bit DSP Processor */ + LIEF_EM_MMIX = 80, /**< Donald Knuth's educational 64-bit processor */ + LIEF_EM_HUANY = 81, /**< Harvard University machine-independent object files */ + LIEF_EM_PRISM = 82, /**< SiTera Prism */ + LIEF_EM_AVR = 83, /**< Atmel AVR 8-bit microcontroller */ + LIEF_EM_FR30 = 84, /**< Fujitsu FR30 */ + LIEF_EM_D10V = 85, /**< Mitsubishi D10V */ + LIEF_EM_D30V = 86, /**< Mitsubishi D30V */ + LIEF_EM_V850 = 87, /**< NEC v850 */ + LIEF_EM_M32R = 88, /**< Mitsubishi M32R */ + LIEF_EM_MN10300 = 89, /**< Matsushita MN10300 */ + LIEF_EM_MN10200 = 90, /**< Matsushita MN10200 */ + LIEF_EM_PJ = 91, /**< picoJava */ + LIEF_EM_OPENRISC = 92, /**< OpenRISC 32-bit embedded processor */ + LIEF_EM_ARC_COMPACT = 93, /**< ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5 */ + LIEF_EM_XTENSA = 94, /**< Tensilica Xtensa Architecture */ + LIEF_EM_VIDEOCORE = 95, /**< Alphamosaic VideoCore processor */ + LIEF_EM_TMM_GPP = 96, /**< Thompson Multimedia General Purpose Processor */ + LIEF_EM_NS32K = 97, /**< National Semiconductor 32000 series */ + LIEF_EM_TPC = 98, /**< Tenor Network TPC processor */ + LIEF_EM_SNP1K = 99, /**< Trebia SNP 1000 processor */ + LIEF_EM_ST200 = 100, /**< STMicroelectronics (www.st.com ST200 */ + LIEF_EM_IP2K = 101, /**< Ubicom IP2xxx microcontroller family */ + LIEF_EM_MAX = 102, /**< MAX Processor */ + LIEF_EM_CR = 103, /**< National Semiconductor CompactRISC microprocessor */ + LIEF_EM_F2MC16 = 104, /**< Fujitsu F2MC16 */ + LIEF_EM_MSP430 = 105, /**< Texas Instruments embedded microcontroller msp430 */ + LIEF_EM_BLACKFIN = 106, /**< Analog Devices Blackfin (DSP processor */ + LIEF_EM_SE_C33 = 107, /**< S1C33 Family of Seiko Epson processors */ + LIEF_EM_SEP = 108, /**< Sharp embedded microprocessor */ + LIEF_EM_ARCA = 109, /**< Arca RISC Microprocessor */ + LIEF_EM_UNICORE = 110, /**< Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ + LIEF_EM_EXCESS = 111, /**< eXcess: 16/32/64-bit configurable embedded CPU */ + LIEF_EM_DXP = 112, /**< Icera Semiconductor Inc. Deep Execution Processor */ + LIEF_EM_ALTERA_NIOS2 = 113, /**< Altera Nios II soft-core processor */ + LIEF_EM_CRX = 114, /**< National Semiconductor CompactRISC CRX */ + LIEF_EM_XGATE = 115, /**< Motorola XGATE embedded processor */ + LIEF_EM_C166 = 116, /**< Infineon C16x/XC16x processor */ + LIEF_EM_M16C = 117, /**< Renesas M16C series microprocessors */ + LIEF_EM_DSPIC30F = 118, /**< Microchip Technology dsPIC30F Digital Signal */ + /* Controller */ + LIEF_EM_CE = 119, /**< Freescale Communication Engine RISC core */ + LIEF_EM_M32C = 120, /**< Renesas M32C series microprocessors */ + LIEF_EM_TSK3000 = 131, /**< Altium TSK3000 core */ + LIEF_EM_RS08 = 132, /**< Freescale RS08 embedded processor */ + LIEF_EM_SHARC = 133, /**< Analog Devices SHARC family of 32-bit DSP */ + /* processors */ + LIEF_EM_ECOG2 = 134, /**< Cyan Technology eCOG2 microprocessor */ + LIEF_EM_SCORE7 = 135, /**< Sunplus S+core7 RISC processor */ + LIEF_EM_DSP24 = 136, /**< New Japan Radio (NJR 24-bit DSP Processor */ + LIEF_EM_VIDEOCORE3 = 137, /**< Broadcom VideoCore III processor */ + LIEF_EM_LATTICEMICO32 = 138, /**< RISC processor for Lattice FPGA architecture */ + LIEF_EM_SE_C17 = 139, /**< Seiko Epson C17 family */ + LIEF_EM_TI_C6000 = 140, /**< The Texas Instruments TMS320C6000 DSP family */ + LIEF_EM_TI_C2000 = 141, /**< The Texas Instruments TMS320C2000 DSP family */ + LIEF_EM_TI_C5500 = 142, /**< The Texas Instruments TMS320C55x DSP family */ + LIEF_EM_MMDSP_PLUS = 160, /**< STMicroelectronics 64bit VLIW Data Signal Processor */ + LIEF_EM_CYPRESS_M8C = 161, /**< Cypress M8C microprocessor */ + LIEF_EM_R32C = 162, /**< Renesas R32C series microprocessors */ + LIEF_EM_TRIMEDIA = 163, /**< NXP Semiconductors TriMedia architecture family */ + LIEF_EM_HEXAGON = 164, /**< Qualcomm Hexagon processor */ + LIEF_EM_8051 = 165, /**< Intel 8051 and variants */ + LIEF_EM_STXP7X = 166, /**< STMicroelectronics STxP7x family of configurable */ + /* and extensible RISC processors */ + LIEF_EM_NDS32 = 167, /* Andes Technology compact code size embedded RISC */ + /* processor family */ + LIEF_EM_ECOG1 = 168, /**< Cyan Technology eCOG1X family */ + LIEF_EM_ECOG1X = 168, /**< Cyan Technology eCOG1X family */ + LIEF_EM_MAXQ30 = 169, /**< Dallas Semiconductor MAXQ30 Core Micro-controllers */ + LIEF_EM_XIMO16 = 170, /**< New Japan Radio (NJR 16-bit DSP Processor */ + LIEF_EM_MANIK = 171, /**< M2000 Reconfigurable RISC Microprocessor */ + LIEF_EM_CRAYNV2 = 172, /**< Cray Inc. NV2 vector architecture */ + LIEF_EM_RX = 173, /**< Renesas RX family */ + LIEF_EM_METAG = 174, /**< Imagination Technologies META processor */ + /* architecture */ + LIEF_EM_MCST_ELBRUS = 175, /**< MCST Elbrus general purpose hardware architecture */ + LIEF_EM_ECOG16 = 176, /**< Cyan Technology eCOG16 family */ + LIEF_EM_CR16 = 177, /**< National Semiconductor CompactRISC CR16 16-bit */ + /* microprocessor */ + LIEF_EM_ETPU = 178, /**< Freescale Extended Time Processing Unit */ + LIEF_EM_SLE9X = 179, /**< Infineon Technologies SLE9X core */ + LIEF_EM_L10M = 180, /**< Intel L10M */ + LIEF_EM_K10M = 181, /**< Intel K10M */ + LIEF_EM_AARCH64 = 183, /**< ARM AArch64 */ + LIEF_EM_AVR32 = 185, /**< Atmel Corporation 32-bit microprocessor family */ + LIEF_EM_STM8 = 186, /**< STMicroeletronics STM8 8-bit microcontroller */ + LIEF_EM_TILE64 = 187, /**< Tilera TILE64 multicore architecture family */ + LIEF_EM_TILEPRO = 188, /**< Tilera TILEPro multicore architecture family */ + LIEF_EM_CUDA = 190, /**< NVIDIA CUDA architecture */ + LIEF_EM_TILEGX = 191, /**< Tilera TILE-Gx multicore architecture family */ + LIEF_EM_CLOUDSHIELD = 192, /**< CloudShield architecture family */ + LIEF_EM_COREA_1ST = 193, /**< KIPO-KAIST Core-A 1st generation processor family */ + LIEF_EM_COREA_2ND = 194, /**< KIPO-KAIST Core-A 2nd generation processor family */ + LIEF_EM_ARC_COMPACT2 = 195, /**< Synopsys ARCompact V2 */ + LIEF_EM_OPEN8 = 196, /**< Open8 8-bit RISC soft processor core */ + LIEF_EM_RL78 = 197, /**< Renesas RL78 family */ + LIEF_EM_VIDEOCORE5 = 198, /**< Broadcom VideoCore V processor */ + LIEF_EM_78KOR = 199, /**< Renesas 78KOR family */ + LIEF_EM_56800EX = 200, /**< Freescale 56800EX Digital Signal Controller (DSC */ + LIEF_EM_BA1 = 201, /**< Beyond BA1 CPU architecture */ + LIEF_EM_BA2 = 202, /**< Beyond BA2 CPU architecture */ + LIEF_EM_XCORE = 203, /**< XMOS xCORE processor family */ + LIEF_EM_MCHP_PIC = 204, /**< Microchip 8-bit PIC(r family */ + LIEF_EM_INTEL205 = 205, /**< Reserved by Intel */ + LIEF_EM_INTEL206 = 206, /**< Reserved by Intel */ + LIEF_EM_INTEL207 = 207, /**< Reserved by Intel */ + LIEF_EM_INTEL208 = 208, /**< Reserved by Intel */ + LIEF_EM_INTEL209 = 209, /**< Reserved by Intel */ + LIEF_EM_KM32 = 210, /**< KM211 KM32 32-bit processor */ + LIEF_EM_KMX32 = 211, /**< KM211 KMX32 32-bit processor */ + LIEF_EM_KMX16 = 212, /**< KM211 KMX16 16-bit processor */ + LIEF_EM_KMX8 = 213, /**< KM211 KMX8 8-bit processor */ + LIEF_EM_KVARC = 214, /**< KM211 KVARC processor */ + LIEF_EM_CDP = 215, /**< Paneve CDP architecture family */ + LIEF_EM_COGE = 216, /**< Cognitive Smart Memory Processor */ + LIEF_EM_COOL = 217, /**< iCelero CoolEngine */ + LIEF_EM_NORC = 218, /**< Nanoradio Optimized RISC */ + LIEF_EM_CSR_KALIMBA = 219, /**< CSR Kalimba architecture family */ + LIEF_EM_AMDGPU = 224, /**< AMD GPU architecture */ + LIEF_EM_RISCV = 243, /**< RISC-V */ + LIEF_EM_BPF = 247, /**< eBPF Filter */ + LIEF_EM_LOONGARCH = 258 /**< LoongArch */ +}; + + +/** Object file classes. */ +enum LIEF_ELF_CLASS { + LIEF_ELFCLASSNONE = 0, /**< Unknown */ + LIEF_ELFCLASS32 = 1, /**< 32-bit object file */ + LIEF_ELFCLASS64 = 2 /**< 64-bit object file */ +}; + +/** Object file byte orderings. */ +enum LIEF_ELF_DATA { + LIEF_ELFDATANONE = 0, /**< Invalid data encoding. */ + LIEF_ELFDATA2LSB = 1, /**< Little-endian object file */ + LIEF_ELFDATA2MSB = 2 /**< Big-endian object file */ +}; + +/** OS ABI identification. */ +enum LIEF_OS_ABI { + LIEF_OSABI_SYSTEMV = 0, /**< UNIX System V ABI */ + LIEF_OSABI_HPUX = 1, /**< HP-UX operating system */ + LIEF_OSABI_NETBSD = 2, /**< NetBSD */ + LIEF_OSABI_GNU = 3, /**< GNU/Linux */ + LIEF_OSABI_LINUX = 3, /**< Historical alias for ELFOSABI_GNU. */ + LIEF_OSABI_HURD = 4, /**< GNU/Hurd */ + LIEF_OSABI_SOLARIS = 6, /**< Solaris */ + LIEF_OSABI_AIX = 7, /**< AIX */ + LIEF_OSABI_IRIX = 8, /**< IRIX */ + LIEF_OSABI_FREEBSD = 9, /**< FreeBSD */ + LIEF_OSABI_TRU64 = 10, /**< TRU64 UNIX */ + LIEF_OSABI_MODESTO = 11, /**< Novell Modesto */ + LIEF_OSABI_OPENBSD = 12, /**< OpenBSD */ + LIEF_OSABI_OPENVMS = 13, /**< OpenVMS */ + LIEF_OSABI_NSK = 14, /**< Hewlett-Packard Non-Stop Kernel */ + LIEF_OSABI_AROS = 15, /**< AROS */ + LIEF_OSABI_FENIXOS = 16, /**< FenixOS */ + LIEF_OSABI_CLOUDABI = 17, /**< Nuxi CloudABI */ + LIEF_OSABI_C6000_ELFABI = 64, /**< Bare-metal TMS320C6000 */ + LIEF_OSABI_AMDGPU_HSA = 64, /**< AMD HSA runtime */ + LIEF_OSABI_C6000_LINUX = 65, /**< Linux TMS320C6000 */ + LIEF_OSABI_ARM = 97, /**< ARM */ + LIEF_OSABI_STANDALONE = 255 /**< Standalone (embedded application */ +}; + +/* ELF Relocations */ + +#define ELF_RELOC(name, value) name = value, + +/** x86_64 relocations. */ +enum LIEF_RELOC_x86_64 { + #include "LIEF/ELF/Relocations/x86_64.def" +}; + +/** i386 relocations. */ +enum RELOC_i386 { + #include "LIEF/ELF/Relocations/i386.def" +}; + +/* ELF Relocation types for PPC32 */ +enum LIEF_RELOC_POWERPC32 { + #include "LIEF/ELF/Relocations/PowerPC.def" +}; + +/* ELF Relocation types for PPC64 */ +enum LIEF_RELOC_POWERPC64 { + #include "LIEF/ELF/Relocations/PowerPC64.def" +}; + +/* ELF Relocation types for AArch64 */ +enum LIEF_RELOC_AARCH64 { + #include "LIEF/ELF/Relocations/AArch64.def" +}; + +/* ELF Relocation types for ARM */ +enum LIEF_RELOC_ARM { + #include "LIEF/ELF/Relocations/ARM.def" +}; + +/* ELF Relocation types for Mips */ +enum LIEF_RELOC_MIPS { + #include "LIEF/ELF/Relocations/Mips.def" +}; + +/* ELF Relocation types for Hexagon */ +enum LIEF_RELOC_HEXAGON { + #include "LIEF/ELF/Relocations/Hexagon.def" +}; + +/* ELF Relocation types for S390/zSeries */ +enum LIEF_RELOC_SYSTEMZ { + #include "LIEF/ELF/Relocations/SystemZ.def" +}; + +/* ELF Relocation type for Sparc. */ +enum LIEF_RELOC_SPARC { + #include "LIEF/ELF/Relocations/Sparc.def" +}; + +/* ELF Relocation types for LoongArch. */ +enum LIEF_RELOC_LOONGARCH { + #include "LIEF/ELF/Relocations/LoongArch.def" +}; + +#undef ELF_RELOC + +/* Specific e_flags for PPC64 */ +enum LIEF_PPC64_EFLAGS { + /* e_flags bits specifying ABI: */ + /* 1 for original ABI using function descriptors, */ + /* 2 for revised ABI without function descriptors, */ + /* 0 for unspecified or not using any features affected by the differences. */ + LIEF_EF_PPC64_ABI = 3 +}; + +/* ARM Specific e_flags */ +enum LIEF_ARM_EFLAGS { + LIEF_EF_ARM_SOFT_FLOAT = 0x00000200U, + LIEF_EF_ARM_VFP_FLOAT = 0x00000400U, + LIEF_EF_ARM_EABI_UNKNOWN = 0x00000000U, + LIEF_EF_ARM_EABI_VER1 = 0x01000000U, + LIEF_EF_ARM_EABI_VER2 = 0x02000000U, + LIEF_EF_ARM_EABI_VER3 = 0x03000000U, + LIEF_EF_ARM_EABI_VER4 = 0x04000000U, + LIEF_EF_ARM_EABI_VER5 = 0x05000000U, + LIEF_EF_ARM_EABIMASK = 0xFF000000U +}; + +/* Mips Specific e_flags */ +enum LIEF_MIPS_EFLAGS { + LIEF_EF_MIPS_NOREORDER = 0x00000001, /* Don't reorder instructions */ + LIEF_EF_MIPS_PIC = 0x00000002, /* Position independent code */ + LIEF_EF_MIPS_CPIC = 0x00000004, /* Call object with Position independent code */ + LIEF_EF_MIPS_ABI2 = 0x00000020, /* File uses N32 ABI */ + LIEF_EF_MIPS_32BITMODE = 0x00000100, /* Code compiled for a 64-bit machine */ + /* in 32-bit mode */ + LIEF_EF_MIPS_FP64 = 0x00000200, /* Code compiled for a 32-bit machine */ + /* but uses 64-bit FP registers */ + LIEF_EF_MIPS_NAN2008 = 0x00000400, /* Uses IEE 754-2008 NaN encoding */ + + /* ABI flags */ + LIEF_EF_MIPS_ABI_O32 = 0x00001000, /* This file follows the first MIPS 32 bit ABI */ + LIEF_EF_MIPS_ABI_O64 = 0x00002000, /* O32 ABI extended for 64-bit architecture. */ + LIEF_EF_MIPS_ABI_EABI32 = 0x00003000, /* EABI in 32 bit mode. */ + LIEF_EF_MIPS_ABI_EABI64 = 0x00004000, /* EABI in 64 bit mode. */ + LIEF_EF_MIPS_ABI = 0x0000f000, /* Mask for selecting EF_MIPS_ABI_ variant. */ + + /* MIPS machine variant */ + LIEF_EF_MIPS_MACH_3900 = 0x00810000, /* Toshiba R3900 */ + LIEF_EF_MIPS_MACH_4010 = 0x00820000, /* LSI R4010 */ + LIEF_EF_MIPS_MACH_4100 = 0x00830000, /* NEC VR4100 */ + LIEF_EF_MIPS_MACH_4650 = 0x00850000, /* MIPS R4650 */ + LIEF_EF_MIPS_MACH_4120 = 0x00870000, /* NEC VR4120 */ + LIEF_EF_MIPS_MACH_4111 = 0x00880000, /* NEC VR4111/VR4181 */ + LIEF_EF_MIPS_MACH_SB1 = 0x008a0000, /* Broadcom SB-1 */ + LIEF_EF_MIPS_MACH_OCTEON = 0x008b0000, /* Cavium Networks Octeon */ + LIEF_EF_MIPS_MACH_XLR = 0x008c0000, /* RMI Xlr */ + LIEF_EF_MIPS_MACH_OCTEON2 = 0x008d0000, /* Cavium Networks Octeon2 */ + LIEF_EF_MIPS_MACH_OCTEON3 = 0x008e0000, /* Cavium Networks Octeon3 */ + LIEF_EF_MIPS_MACH_5400 = 0x00910000, /* NEC VR5400 */ + LIEF_EF_MIPS_MACH_5900 = 0x00920000, /* MIPS R5900 */ + LIEF_EF_MIPS_MACH_5500 = 0x00980000, /* NEC VR5500 */ + LIEF_EF_MIPS_MACH_9000 = 0x00990000, /* Unknown */ + LIEF_EF_MIPS_MACH_LS2E = 0x00a00000, /* ST Microelectronics Loongson 2E */ + LIEF_EF_MIPS_MACH_LS2F = 0x00a10000, /* ST Microelectronics Loongson 2F */ + LIEF_EF_MIPS_MACH_LS3A = 0x00a20000, /* Loongson 3A */ + LIEF_EF_MIPS_MACH = 0x00ff0000, /* EF_MIPS_MACH_xxx selection mask */ + + /* ARCH_ASE */ + LIEF_EF_MIPS_MICROMIPS = 0x02000000, /* microMIPS */ + LIEF_EF_MIPS_ARCH_ASE_M16 = 0x04000000, /* Has Mips-16 ISA extensions */ + LIEF_EF_MIPS_ARCH_ASE_MDMX = 0x08000000, /* Has MDMX multimedia extensions */ + LIEF_EF_MIPS_ARCH_ASE = 0x0f000000, /* Mask for EF_MIPS_ARCH_ASE_xxx flags */ + + /* ARCH */ + LIEF_EF_MIPS_ARCH_1 = 0x00000000, /* MIPS1 instruction set */ + LIEF_EF_MIPS_ARCH_2 = 0x10000000, /* MIPS2 instruction set */ + LIEF_EF_MIPS_ARCH_3 = 0x20000000, /* MIPS3 instruction set */ + LIEF_EF_MIPS_ARCH_4 = 0x30000000, /* MIPS4 instruction set */ + LIEF_EF_MIPS_ARCH_5 = 0x40000000, /* MIPS5 instruction set */ + LIEF_EF_MIPS_ARCH_32 = 0x50000000, /* MIPS32 instruction set per linux not elf.h */ + LIEF_EF_MIPS_ARCH_64 = 0x60000000, /* MIPS64 instruction set per linux not elf.h */ + LIEF_EF_MIPS_ARCH_32R2 = 0x70000000, /* mips32r2, mips32r3, mips32r5 */ + LIEF_EF_MIPS_ARCH_64R2 = 0x80000000, /* mips64r2, mips64r3, mips64r5 */ + LIEF_EF_MIPS_ARCH_32R6 = 0x90000000, /* mips32r6 */ + LIEF_EF_MIPS_ARCH_64R6 = 0xa0000000, /* mips64r6 */ + LIEF_EF_MIPS_ARCH = 0xf0000000 /* Mask for applying EF_MIPS_ARCH_ variant */ +}; + +/* Hexagon Specific e_flags */ +/* Release 5 ABI */ +enum LIEF_HEXAGON_EFLAGS { + /* Object processor version flags, bits[3:0] */ + LIEF_EF_HEXAGON_MACH_V2 = 0x00000001, /* Hexagon V2 */ + LIEF_EF_HEXAGON_MACH_V3 = 0x00000002, /* Hexagon V3 */ + LIEF_EF_HEXAGON_MACH_V4 = 0x00000003, /* Hexagon V4 */ + LIEF_EF_HEXAGON_MACH_V5 = 0x00000004, /* Hexagon V5 */ + + /* Highest ISA version flags */ + LIEF_EF_HEXAGON_ISA_MACH = 0x00000000, /* Same as specified in bits[3:0] */ + /* of e_flags */ + LIEF_EF_HEXAGON_ISA_V2 = 0x00000010, /* Hexagon V2 ISA */ + LIEF_EF_HEXAGON_ISA_V3 = 0x00000020, /* Hexagon V3 ISA */ + LIEF_EF_HEXAGON_ISA_V4 = 0x00000030, /* Hexagon V4 ISA */ + LIEF_EF_HEXAGON_ISA_V5 = 0x00000040 /* Hexagon V5 ISA */ +}; + + +/* LoongArch Specific e_flags */ +enum LIEF_LOONGARCH_EFLAGS { + LIEF_EF_LOONGARCH_ABI_SOFT_FLOAT = 0x1, + LIEF_EF_LOONGARCH_ABI_SINGLE_FLOAT = 0x2, + LIEF_EF_LOONGARCH_ABI_DOUBLE_FLOAT = 0x3 +}; + +/** Special section indices. */ +enum LIEF_SYMBOL_SECTION_INDEX { + LIEF_SHN_UNDEF = 0, /**< Undefined, missing, irrelevant, or meaningless */ + LIEF_SHN_LORESERVE = 0xff00, /**< Lowest reserved index */ + LIEF_SHN_LOPROC = 0xff00, /**< Lowest processor-specific index */ + LIEF_SHN_HIPROC = 0xff1f, /**< Highest processor-specific index */ + LIEF_SHN_LOOS = 0xff20, /**< Lowest operating system-specific index */ + LIEF_SHN_HIOS = 0xff3f, /**< Highest operating system-specific index */ + LIEF_SHN_ABS = 0xfff1, /**< Symbol has absolute value; does not need relocation */ + LIEF_SHN_COMMON = 0xfff2, /**< FORTRAN COMMON or C external global variables */ + LIEF_SHN_XINDEX = 0xffff, /**< Mark that the index is >= SHN_LORESERVE */ + LIEF_SHN_HIRESERVE = 0xffff /**< Highest reserved index */ +}; + +/** Section types. */ +enum LIEF_ELF_SECTION_TYPES { + LIEF_SHT_NULL = 0, /**< No associated section (inactive entry. */ + LIEF_SHT_PROGBITS = 1, /**< Program-defined contents. */ + LIEF_SHT_SYMTAB = 2, /**< Symbol table. */ + LIEF_SHT_STRTAB = 3, /**< String table. */ + LIEF_SHT_RELA = 4, /**< Relocation entries; explicit addends. */ + LIEF_SHT_HASH = 5, /**< Symbol hash table. */ + LIEF_SHT_DYNAMIC = 6, /**< Information for dynamic linking. */ + LIEF_SHT_NOTE = 7, /**< Information about the file. */ + LIEF_SHT_NOBITS = 8, /**< Data occupies no space in the file. */ + LIEF_SHT_REL = 9, /**< Relocation entries; no explicit addends. */ + LIEF_SHT_SHLIB = 10, /**< Reserved. */ + LIEF_SHT_DYNSYM = 11, /**< Symbol table. */ + LIEF_SHT_INIT_ARRAY = 14, /**< Pointers to initialization functions. */ + LIEF_SHT_FINI_ARRAY = 15, /**< Pointers to termination functions. */ + LIEF_SHT_PREINIT_ARRAY = 16, /**< Pointers to pre-init functions. */ + LIEF_SHT_GROUP = 17, /**< Section group. */ + LIEF_SHT_SYMTAB_SHNDX = 18, /**< Indices for SHN_XINDEX entries. */ + LIEF_SHT_LOOS = 0x60000000, /**< Lowest operating system-specific type. */ + LIEF_SHT_ANDROID_REL = 0x60000001, /**< Packed relocations (Android specific. */ + LIEF_SHT_ANDROID_RELA = 0x60000002, /**< Packed relocations (Android specific. */ + LIEF_SHT_LLVM_ADDRSIG = 0x6fff4c03, /**< This section is used to mark symbols as address-significant. */ + LIEF_SHT_RELR = 0x6fffff00, /**< New relr relocations (Android specific. */ + LIEF_SHT_GNU_ATTRIBUTES = 0x6ffffff5, /**< Object attributes. */ + LIEF_SHT_GNU_HASH = 0x6ffffff6, /**< GNU-style hash table. */ + LIEF_SHT_GNU_verdef = 0x6ffffffd, /**< GNU version definitions. */ + LIEF_SHT_GNU_verneed = 0x6ffffffe, /**< GNU version references. */ + LIEF_SHT_GNU_versym = 0x6fffffff, /**< GNU symbol versions table. */ + LIEF_SHT_HIOS = 0x6fffffff, /**< Highest operating system-specific type. */ + LIEF_SHT_LOPROC = 0x70000000, /**< Lowest processor arch-specific type. */ + LIEF_SHT_ARM_EXIDX = 0x70000001U, /**< Exception Index table */ + LIEF_SHT_ARM_PREEMPTMAP = 0x70000002U, /**< BPABI DLL dynamic linking pre-emption map */ + LIEF_SHT_ARM_ATTRIBUTES = 0x70000003U, /**< Object file compatibility attributes */ + LIEF_SHT_ARM_DEBUGOVERLAY = 0x70000004U, + LIEF_SHT_ARM_OVERLAYSECTION = 0x70000005U, + LIEF_SHT_HEX_ORDERED = 0x70000000, /**< Link editor is to sort the entries in */ + + /* this section based on their sizes */ + LIEF_SHT_X86_64_UNWIND = 0x70000001, /**< Unwind information */ + LIEF_SHT_MIPS_REGINFO = 0x70000006, /**< Register usage information */ + LIEF_SHT_MIPS_OPTIONS = 0x7000000d, /**< General options */ + LIEF_SHT_MIPS_ABIFLAGS = 0x7000002a, /**< ABI information. */ + + LIEF_SHT_HIPROC = 0x7fffffff, /**< Highest processor arch-specific type. */ + LIEF_SHT_LOUSER = 0x80000000, /**< Lowest type reserved for applications. */ + LIEF_SHT_HIUSER = 0xffffffff /**< Highest type reserved for applications. */ +}; + + + +/** Section flags. */ +enum LIEF_ELF_SECTION_FLAGS { + LIEF_SHF_NONE = 0x0, + LIEF_SHF_WRITE = 0x1, /**< Section data should be writable during execution. */ + LIEF_SHF_ALLOC = 0x2, /**< Section occupies memory during program execution. */ + LIEF_SHF_EXECINSTR = 0x4, /**< Section contains executable machine instructions. */ + LIEF_SHF_MERGE = 0x10, /**< The data in this section may be merged. */ + LIEF_SHF_STRINGS = 0x20, /**< The data in this section is null-terminated strings. */ + LIEF_SHF_INFO_LINK = 0x40U, /**< A field in this section holds a section header table index. */ + LIEF_SHF_LINK_ORDER = 0x80U, /**< Adds special ordering requirements for link editors. */ + LIEF_SHF_OS_NONCONFORMING = 0x100U, /**< This section requires special OS-specific processing to avoid incorrect behavior */ + LIEF_SHF_GROUP = 0x200U, /**< This section is a member of a section group. */ + LIEF_SHF_TLS = 0x400U, /**< This section holds Thread-Local Storage. */ + LIEF_SHF_EXCLUDE = 0x80000000U, /**< This section is excluded from the final executable or shared library. */ + /* Start of target-specific flags. */ + + /* XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped + * together by the linker to form the constant pool and the cp register is + * set to the start of the constant pool by the boot code. + */ + LIEF_XCORE_SHF_CP_SECTION = 0x800U, + + /* XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped + * together by the linker to form the data section and the dp register is + * set to the start of the section by the boot code. + */ + LIEF_XCORE_SHF_DP_SECTION = 0x1000U, + LIEF_SHF_MASKOS = 0x0ff00000, + LIEF_SHF_MASKPROC = 0xf0000000, /**< Bits indicating processor-specific flags. */ + + /* If an object file section does not have this flag set, then it may not hold + * more than 2GB and can be freely referred to in objects using smaller code + * models. Otherwise, only objects using larger code models can refer to them. + * For example, a medium code model object can refer to data in a section that + * sets this flag besides being able to refer to data in a section that does + * not set it; likewise, a small code model object can refer only to code in a + * section that does not set this flag. + */ + LIEF_SHF_X86_64_LARGE = 0x10000000, + + /* All sections with the GPREL flag are grouped into a global data area + * for faster accesses. + */ + LIEF_SHF_HEX_GPREL = 0x10000000, + + /* Section contains text/data which may be replicated in other sections. + * Linker must retain only one copy. + */ + LIEF_SHF_MIPS_NODUPES = 0x01000000, + + LIEF_SHF_MIPS_NAMES = 0x02000000, /**< Linker must generate implicit hidden weak names. */ + LIEF_SHF_MIPS_LOCAL = 0x04000000, /**< Section data local to process. */ + LIEF_SHF_MIPS_NOSTRIP = 0x08000000, /**< Do not strip this section. */ + LIEF_SHF_MIPS_GPREL = 0x10000000, /**< Section must be part of global data area. */ + LIEF_SHF_MIPS_MERGE = 0x20000000, /**< This section should be merged. */ + LIEF_SHF_MIPS_ADDR = 0x40000000, /**< Address size to be inferred from section entry size. */ + LIEF_SHF_MIPS_STRING = 0x80000000 /**< Section data is string data by default. */ +}; + + +/** Symbol bindings. */ +enum LIEF_SYMBOL_BINDINGS { + LIEF_STB_LOCAL = 0, /**< Local symbol, not visible outside obj file containing def */ + LIEF_STB_GLOBAL = 1, /**< Global symbol, visible to all object files being combined */ + LIEF_STB_WEAK = 2, /**< Weak symbol, like global but lower-precedence */ + LIEF_STB_GNU_UNIQUE = 10, + LIEF_STB_LOOS = 10, /**< Lowest operating system-specific binding type */ + LIEF_STB_HIOS = 12, /**< Highest operating system-specific binding type */ + LIEF_STB_LOPROC = 13, /**< Lowest processor-specific binding type */ + LIEF_STB_HIPROC = 15 /**< Highest processor-specific binding type */ +}; + + +/* Symbol types. */ +enum LIEF_ELF_SYMBOL_TYPES { + LIEF_STT_NOTYPE = 0, /* Symbol's type is not specified */ + LIEF_STT_OBJECT = 1, /* Symbol is a data object (variable, array, etc. */ + LIEF_STT_FUNC = 2, /* Symbol is executable code (function, etc. */ + LIEF_STT_SECTION = 3, /* Symbol refers to a section */ + LIEF_STT_FILE = 4, /* Local, absolute symbol that refers to a file */ + LIEF_STT_COMMON = 5, /* An uninitialized common block */ + LIEF_STT_TLS = 6, /* Thread local data object */ + LIEF_STT_GNU_IFUNC = 10, /* GNU indirect function */ + LIEF_STT_LOOS = 10, /* Lowest operating system-specific symbol type */ + LIEF_STT_HIOS = 12, /* Highest operating system-specific symbol type */ + LIEF_STT_LOPROC = 13, /* Lowest processor-specific symbol type */ + LIEF_STT_HIPROC = 15 /* Highest processor-specific symbol type */ +}; + +enum LIEF_ELF_SYMBOL_VISIBILITY { + LIEF_STV_DEFAULT = 0, /* Visibility is specified by binding type */ + LIEF_STV_INTERNAL = 1, /* Defined by processor supplements */ + LIEF_STV_HIDDEN = 2, /* Not visible to other components */ + LIEF_STV_PROTECTED = 3 /* Visible in other components but not preemptable */ +}; + + +/** @brief Segment types. */ +enum LIEF_SEGMENT_TYPES { + LIEF_PT_NULL = 0, /**< Unused segment. */ + LIEF_PT_LOAD = 1, /**< Loadable segment. */ + LIEF_PT_DYNAMIC = 2, /**< Dynamic linking information. */ + LIEF_PT_INTERP = 3, /**< Interpreter pathname. */ + LIEF_PT_NOTE = 4, /**< Auxiliary information. */ + LIEF_PT_SHLIB = 5, /**< Reserved. */ + LIEF_PT_PHDR = 6, /**< The program header table itself. */ + LIEF_PT_TLS = 7, /**< The thread-local storage template. */ + LIEF_PT_LOOS = 0x60000000, /**< Lowest operating system-specific pt entry type. */ + LIEF_PT_HIOS = 0x6fffffff, /**< Highest operating system-specific pt entry type. */ + LIEF_PT_LOPROC = 0x70000000, /**< Lowest processor-specific program hdr entry type. */ + LIEF_PT_HIPROC = 0x7fffffff, /**< Highest processor-specific program hdr entry type. */ + + /* x86-64 program header types. */ + /* These all contain stack unwind tables. */ + LIEF_PT_GNU_EH_FRAME = 0x6474e550, + LIEF_PT_SUNW_EH_FRAME = 0x6474e550, + LIEF_PT_SUNW_UNWIND = 0x6464e550, + + LIEF_PT_GNU_STACK = 0x6474e551, /**< Indicates stack executability. */ + LIEF_PT_GNU_PROPERTY = 0x6474e553, /**< GNU property */ + LIEF_PT_GNU_RELRO = 0x6474e552, /**< Read-only after relocation. */ + + /* ARM program header types. */ + LIEF_PT_ARM_ARCHEXT = 0x70000000, /**< Platform architecture compatibility info */ + + /* These all contain stack unwind tables. */ + LIEF_PT_ARM_EXIDX = 0x70000001, + LIEF_PT_ARM_UNWIND = 0x70000001, + + /* MIPS program header types. */ + LIEF_PT_MIPS_REGINFO = 0x70000000, /**< Register usage information. */ + LIEF_PT_MIPS_RTPROC = 0x70000001, /**< Runtime procedure table. */ + LIEF_PT_MIPS_OPTIONS = 0x70000002, /**< Options segment. */ + LIEF_PT_MIPS_ABIFLAGS = 0x70000003 /**< Abiflags segment. */ +}; + + +/** Segment flags. */ +enum LIEF_ELF_SEGMENT_FLAGS { + LIEF_PF_NONE = 0, + LIEF_PF_X = 1, /**< Execute */ + LIEF_PF_W = 2, /**< Write */ + LIEF_PF_R = 4, /**< Read */ + LIEF_PF_MASKOS = 0x0ff00000,/**< Bits for operating system-specific semantics. */ + LIEF_PF_MASKPROC = 0xf0000000 /**< Bits for processor-specific semantics. */ +}; + + +/** Dynamic table entry tags. */ +enum LIEF_DYNAMIC_TAGS { + LIEF_DT_NULL = 0, /**< Marks end of dynamic array. */ + LIEF_DT_NEEDED = 1, /**< String table offset of needed library. */ + LIEF_DT_PLTRELSZ = 2, /**< Size of relocation entries in PLT. */ + LIEF_DT_PLTGOT = 3, /**< Address associated with linkage table. */ + LIEF_DT_HASH = 4, /**< Address of symbolic hash table. */ + LIEF_DT_STRTAB = 5, /**< Address of dynamic string table. */ + LIEF_DT_SYMTAB = 6, /**< Address of dynamic symbol table. */ + LIEF_DT_RELA = 7, /**< Address of relocation table (Rela entries. */ + LIEF_DT_RELASZ = 8, /**< Size of Rela relocation table. */ + LIEF_DT_RELAENT = 9, /**< Size of a Rela relocation entry. */ + LIEF_DT_STRSZ = 10, /**< Total size of the string table. */ + LIEF_DT_SYMENT = 11, /**< Size of a symbol table entry. */ + LIEF_DT_INIT = 12, /**< Address of initialization function. */ + LIEF_DT_FINI = 13, /**< Address of termination function. */ + LIEF_DT_SONAME = 14, /**< String table offset of a shared objects name. */ + LIEF_DT_RPATH = 15, /**< String table offset of library search path. */ + LIEF_DT_SYMBOLIC = 16, /**< Changes symbol resolution algorithm. */ + LIEF_DT_REL = 17, /**< Address of relocation table (Rel entries. */ + LIEF_DT_RELSZ = 18, /**< Size of Rel relocation table. */ + LIEF_DT_RELENT = 19, /**< Size of a Rel relocation entry. */ + LIEF_DT_PLTREL = 20, /**< Type of relocation entry used for linking. */ + LIEF_DT_DEBUG = 21, /**< Reserved for debugger. */ + LIEF_DT_TEXTREL = 22, /**< Relocations exist for non-writable segments. */ + LIEF_DT_JMPREL = 23, /**< Address of relocations associated with PLT. */ + LIEF_DT_BIND_NOW = 24, /**< Process all relocations before execution. */ + LIEF_DT_INIT_ARRAY = 25, /**< Pointer to array of initialization functions. */ + LIEF_DT_FINI_ARRAY = 26, /**< Pointer to array of termination functions. */ + LIEF_DT_INIT_ARRAYSZ = 27, /**< Size of DT_INIT_ARRAY. */ + LIEF_DT_FINI_ARRAYSZ = 28, /**< Size of DT_FINI_ARRAY. */ + LIEF_DT_RUNPATH = 29, /**< String table offset of lib search path. */ + LIEF_DT_FLAGS = 30, /**< Flags. */ + LIEF_DT_ENCODING = 32, /**< Values from here to DT_LOOS follow the rules for the interpretation of the d_un union. */ + + LIEF_DT_PREINIT_ARRAY = 32, /**< Pointer to array of preinit functions. */ + LIEF_DT_PREINIT_ARRAYSZ = 33, /**< Size of the DT_PREINIT_ARRAY array. */ + + LIEF_DT_LOOS = 0x60000000, /**< Start of environment specific tags. */ + LIEF_DT_HIOS = 0x6FFFFFFF, /**< End of environment specific tags. */ + LIEF_DT_LOPROC = 0x70000000, /**< Start of processor specific tags. */ + LIEF_DT_HIPROC = 0x7FFFFFFF, /**< End of processor specific tags. */ + + LIEF_DT_GNU_HASH = 0x6FFFFEF5, /**< Reference to the GNU hash table. */ + LIEF_DT_RELACOUNT = 0x6FFFFFF9, /**< ELF32_Rela count. */ + LIEF_DT_RELCOUNT = 0x6FFFFFFA, /**< ELF32_Rel count. */ + + LIEF_DT_FLAGS_1 = 0x6FFFFFFB, /**< Flags_1. */ + LIEF_DT_VERSYM = 0x6FFFFFF0, /**< The address of .gnu.version section. */ + LIEF_DT_VERDEF = 0x6FFFFFFC, /**< The address of the version definition table. */ + LIEF_DT_VERDEFNUM = 0x6FFFFFFD, /**< The number of entries in DT_VERDEF. */ + LIEF_DT_VERNEED = 0x6FFFFFFE, /**< The address of the version Dependency table. */ + LIEF_DT_VERNEEDNUM = 0x6FFFFFFF, /**< The number of entries in DT_VERNEED. */ + + /* Mips specific dynamic table entry tags. */ + LIEF_DT_MIPS_RLD_VERSION = 0x70000001, /**< 32 bit version number for runtime linker interface. */ + LIEF_DT_MIPS_TIME_STAMP = 0x70000002, /**< Time stamp. */ + LIEF_DT_MIPS_ICHECKSUM = 0x70000003, /**< Checksum of external strings and common sizes. */ + LIEF_DT_MIPS_IVERSION = 0x70000004, /**< Index of version string in string table. */ + LIEF_DT_MIPS_FLAGS = 0x70000005, /**< 32 bits of flags. */ + LIEF_DT_MIPS_BASE_ADDRESS = 0x70000006, /**< Base address of the segment. */ + LIEF_DT_MIPS_MSYM = 0x70000007, /**< Address of .msym section. */ + LIEF_DT_MIPS_CONFLICT = 0x70000008, /**< Address of .conflict section. */ + LIEF_DT_MIPS_LIBLIST = 0x70000009, /**< Address of .liblist section. */ + LIEF_DT_MIPS_LOCAL_GOTNO = 0x7000000a, /**< Number of local global offset table entries. */ + LIEF_DT_MIPS_CONFLICTNO = 0x7000000b, /**< Number of entries in the .conflict section. */ + LIEF_DT_MIPS_LIBLISTNO = 0x70000010, /**< Number of entries in the .liblist section. */ + LIEF_DT_MIPS_SYMTABNO = 0x70000011, /**< Number of entries in the .dynsym section. */ + LIEF_DT_MIPS_UNREFEXTNO = 0x70000012, /**< Index of first external dynamic symbol not referenced locally. */ + LIEF_DT_MIPS_GOTSYM = 0x70000013, /**< Index of first dynamic symbol in global offset table. */ + LIEF_DT_MIPS_HIPAGENO = 0x70000014, /**< Number of page table entries in global offset table. */ + LIEF_DT_MIPS_RLD_MAP = 0x70000016, /**< Address of run time loader map, used for debugging. */ + LIEF_DT_MIPS_DELTA_CLASS = 0x70000017, /**< Delta C++ class definition. */ + LIEF_DT_MIPS_DELTA_CLASS_NO = 0x70000018, /**< Number of entries in DT_MIPS_DELTA_CLASS. */ + LIEF_DT_MIPS_DELTA_INSTANCE = 0x70000019, /**< Delta C++ class instances. */ + LIEF_DT_MIPS_DELTA_INSTANCE_NO = 0x7000001A, /**< Number of entries in DT_MIPS_DELTA_INSTANCE. */ + LIEF_DT_MIPS_DELTA_RELOC = 0x7000001B, /**< Delta relocations. */ + LIEF_DT_MIPS_DELTA_RELOC_NO = 0x7000001C, /**< Number of entries in DT_MIPS_DELTA_RELOC. */ + LIEF_DT_MIPS_DELTA_SYM = 0x7000001D, /**< Delta symbols that Delta relocations refer to. */ + LIEF_DT_MIPS_DELTA_SYM_NO = 0x7000001E, /**< Number of entries in DT_MIPS_DELTA_SYM. */ + LIEF_DT_MIPS_DELTA_CLASSSYM = 0x70000020, /**< Delta symbols that hold class declarations. */ + LIEF_DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021, /**< Number of entries in DT_MIPS_DELTA_CLASSSYM. */ + LIEF_DT_MIPS_CXX_FLAGS = 0x70000022, /**< Flags indicating information about C++ flavor. */ + LIEF_DT_MIPS_PIXIE_INIT = 0x70000023, /**< Pixie information. */ + LIEF_DT_MIPS_SYMBOL_LIB = 0x70000024, /**< Address of .MIPS.symlib */ + LIEF_DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025, /**< The GOT index of the first PTE for a segment */ + LIEF_DT_MIPS_LOCAL_GOTIDX = 0x70000026, /**< The GOT index of the first PTE for a local symbol */ + LIEF_DT_MIPS_HIDDEN_GOTIDX = 0x70000027, /**< The GOT index of the first PTE for a hidden symbol */ + LIEF_DT_MIPS_PROTECTED_GOTIDX = 0x70000028, /**< The GOT index of the first PTE for a protected symbol */ + LIEF_DT_MIPS_OPTIONS = 0x70000029, /**< Address of `.MIPS.options'. */ + LIEF_DT_MIPS_INTERFACE = 0x7000002A, /**< Address of `.interface'. */ + LIEF_DT_MIPS_DYNSTR_ALIGN = 0x7000002B, /**< Unknown. */ + LIEF_DT_MIPS_INTERFACE_SIZE = 0x7000002C, /**< Size of the .interface section. */ + LIEF_DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002D, /**< Size of rld_text_resolve function stored in the GOT. */ + LIEF_DT_MIPS_PERF_SUFFIX = 0x7000002E, /**< Default suffix of DSO to be added by rld on dlopen( calls. */ + LIEF_DT_MIPS_COMPACT_SIZE = 0x7000002F, /**< Size of compact relocation section (O32. */ + LIEF_DT_MIPS_GP_VALUE = 0x70000030, /**< GP value for auxiliary GOTs. */ + LIEF_DT_MIPS_AUX_DYNAMIC = 0x70000031, /**< Address of auxiliary .dynamic. */ + LIEF_DT_MIPS_PLTGOT = 0x70000032, /**< Address of the base of the PLTGOT. */ + LIEF_DT_MIPS_RWPLT = 0x70000034, /**< Points to the base of a writable PLT. */ + + /* Android specific dynamic table entry tags. */ + LIEF_DT_ANDROID_REL_OFFSET = 0x6000000D, /**< The offset of packed relocation data (older version < M) (Android specific. */ + LIEF_DT_ANDROID_REL_SIZE = 0x6000000E, /**< The size of packed relocation data in bytes (older version < M) (Android specific. */ + LIEF_DT_ANDROID_REL = 0x6000000F, /**< The offset of packed relocation data (Android specific. */ + LIEF_DT_ANDROID_RELSZ = 0x60000010, /**< The size of packed relocation data in bytes (Android specific. */ + LIEF_DT_ANDROID_RELA = 0x60000011, /**< The offset of packed relocation data (Android specific. */ + LIEF_DT_ANDROID_RELASZ = 0x60000012, /**< The size of packed relocation data in bytes (Android specific. */ + LIEF_DT_RELR = 0x6FFFE000, /**< The offset of new relr relocation data (Android specific. */ + LIEF_DT_RELRSZ = 0x6FFFE001, /**< The size of nre relr relocation data in bytes (Android specific. */ + LIEF_DT_RELRENT = 0x6FFFE003, /**< The size of a new relr relocation entry (Android specific. */ + LIEF_DT_RELRCOUNT = 0x6FFFE005 /**< Specifies the relative count of new relr relocation entries (Android specific. */ +}; + +/** DT_FLAGS and DT_FLAGS_1 values. */ +enum LIEF_DYNAMIC_FLAGS { + LIEF_DF_ORIGIN = 0x00000001, /**< The object may reference $ORIGIN. */ + LIEF_DF_SYMBOLIC = 0x00000002, /**< Search the shared lib before searching the exe. */ + LIEF_DF_TEXTREL = 0x00000004, /**< Relocations may modify a non-writable segment. */ + LIEF_DF_BIND_NOW = 0x00000008, /**< Process all relocations on load. */ + LIEF_DF_STATIC_TLS = 0x00000010, /**< Reject attempts to load dynamically. */ +}; + +enum LIEF_DYNAMIC_FLAGS_1 { + LIEF_DF_1_NOW = 0x00000001, /**< Set RTLD_NOW for this object. */ + LIEF_DF_1_GLOBAL = 0x00000002, /**< Set RTLD_GLOBAL for this object. */ + LIEF_DF_1_GROUP = 0x00000004, /**< Set RTLD_GROUP for this object. */ + LIEF_DF_1_NODELETE = 0x00000008, /**< Set RTLD_NODELETE for this object. */ + LIEF_DF_1_LOADFLTR = 0x00000010, /**< Trigger filtee loading at runtime. */ + LIEF_DF_1_INITFIRST = 0x00000020, /**< Set RTLD_INITFIRST for this object. */ + LIEF_DF_1_NOOPEN = 0x00000040, /**< Set RTLD_NOOPEN for this object. */ + LIEF_DF_1_ORIGIN = 0x00000080, /**< $ORIGIN must be handled. */ + LIEF_DF_1_DIRECT = 0x00000100, /**< Direct binding enabled. */ + LIEF_DF_1_TRANS = 0x00000200, + LIEF_DF_1_INTERPOSE = 0x00000400, /**< Object is used to interpose. */ + LIEF_DF_1_NODEFLIB = 0x00000800, /**< Ignore default lib search path. */ + LIEF_DF_1_NODUMP = 0x00001000, /**< Object can't be dldump'ed. */ + LIEF_DF_1_CONFALT = 0x00002000, /**< Configuration alternative created. */ + LIEF_DF_1_ENDFILTEE = 0x00004000, /**< Filtee terminates filters search. */ + LIEF_DF_1_DISPRELDNE = 0x00008000, /**< Disp reloc applied at build time. */ + LIEF_DF_1_DISPRELPND = 0x00010000, /**< Disp reloc applied at run-time. */ + LIEF_DF_1_NODIRECT = 0x00020000, /**< Object has no-direct binding. */ + LIEF_DF_1_IGNMULDEF = 0x00040000, + LIEF_DF_1_NOKSYMS = 0x00080000, + LIEF_DF_1_NOHDR = 0x00100000, + LIEF_DF_1_EDITED = 0x00200000, /**< Object is modified after built. */ + LIEF_DF_1_NORELOC = 0x00400000, + LIEF_DF_1_SYMINTPOSE = 0x00800000, /**< Object has individual interposers. */ + LIEF_DF_1_GLOBAUDIT = 0x01000000, /**< Global auditing required. */ + LIEF_DF_1_SINGLETON = 0x02000000, /**< Singleton symbols are used. */ + LIEF_DF_1_PIE = 0x08000000 /**< Singleton symbols are used. */ +}; + +/* DT_MIPS_FLAGS values. */ +enum { + LIEF_RHF_NONE = 0x00000000, /* No flags. */ + LIEF_RHF_QUICKSTART = 0x00000001, /* Uses shortcut pointers. */ + LIEF_RHF_NOTPOT = 0x00000002, /* Hash size is not a power of two. */ + LIEF_RHS_NO_LIBRARY_REPLACEMENT = 0x00000004, /* Ignore LD_LIBRARY_PATH. */ + LIEF_RHF_NO_MOVE = 0x00000008, /* DSO address may not be relocated. */ + LIEF_RHF_SGI_ONLY = 0x00000010, /* SGI specific features. */ + LIEF_RHF_GUARANTEE_INIT = 0x00000020, /* Guarantee that .init will finish */ + /* executing before any non-init */ + /* code in DSO is called. */ + LIEF_RHF_DELTA_C_PLUS_PLUS = 0x00000040, /* Contains Delta C++ code. */ + LIEF_RHF_GUARANTEE_START_INIT = 0x00000080, /* Guarantee that .init will start */ + /* executing before any non-init */ + /* code in DSO is called. */ + LIEF_RHF_PIXIE = 0x00000100, /* Generated by pixie. */ + LIEF_RHF_DEFAULT_DELAY_LOAD = 0x00000200, /* Delay-load DSO by default. */ + LIEF_RHF_REQUICKSTART = 0x00000400, /* Object may be requickstarted */ + LIEF_RHF_REQUICKSTARTED = 0x00000800, /* Object has been requickstarted */ + LIEF_RHF_CORD = 0x00001000, /* Generated by cord. */ + LIEF_RHF_NO_UNRES_UNDEF = 0x00002000, /* Object contains no unresolved */ + /* undef symbols. */ + LIEF_RHF_RLD_ORDER_SAFE = 0x00004000 /* Symbol table is in a safe order. */ +}; + +/** ElfXX_VerDef structure version (GNU versioning) */ +enum { + LIEF_VER_DEF_NONE = 0, + LIEF_VER_DEF_CURRENT = 1 +}; + +/** VerDef Flags (ElfXX_VerDef::vd_flags) */ +enum { + LIEF_VER_FLG_BASE = 0x1, + LIEF_VER_FLG_WEAK = 0x2, + LIEF_VER_FLG_INFO = 0x4 +}; + +/** Special constants for the version table. (SHT_GNU_versym/.gnu.version) */ +enum { + LIEF_VER_NDX_LOCAL = 0, /**< Unversioned local symbol */ + LIEF_VER_NDX_GLOBAL = 1, /**< Unversioned global symbol */ + LIEF_VERSYM_VERSION = 0x7fff, /**< Version Index mask */ + LIEF_VERSYM_HIDDEN = 0x8000 /**< Hidden bit (non-default version */ +}; + +/** ElfXX_VerNeed structure version (GNU versioning) */ +enum { + LIEF_VER_NEED_NONE = 0, + LIEF_VER_NEED_CURRENT = 1 +}; + +enum LIEF_AUX_TYPE { + LIEF_AT_NULL = 0, /**< End of vector */ + LIEF_AT_IGNORE = 1, /**< Entry should be ignored */ + LIEF_AT_EXECFD = 2, /**< File descriptor of program */ + LIEF_AT_PHDR = 3, /**< Program headers for program */ + LIEF_AT_PHENT = 4, /**< Size of program header entry */ + LIEF_AT_PHNUM = 5, /**< Number of program headers */ + LIEF_AT_PAGESZ = 6, /**< System page size */ + LIEF_AT_BASE = 7, /**< Base address of interpreter */ + LIEF_AT_FLAGS = 8, /**< Flags */ + LIEF_AT_ENTRY = 9, /**< Entry point of program */ + LIEF_AT_NOTELF = 10, /**< Program is not ELF */ + LIEF_AT_UID = 11, /**< Real uid */ + LIEF_AT_EUID = 12, /**< Effective uid */ + LIEF_AT_GID = 13, /**< Real gid */ + LIEF_AT_EGID = 14, /**< Effective gid */ + LIEF_AT_CLKTCK = 17, /**< Frequency of times( */ + + /* Some more special a_type values describing the hardware. */ + + LIEF_AT_PLATFORM = 15, /**< String identifying platform. */ + LIEF_AT_HWCAP = 16, /**< Machine dependent hints about processor capabilities. */ + + /* This entry gives some information about the FPU initialization + performed by the kernel. */ + + LIEF_AT_FPUCW = 18, /**< Used FPU control word. */ + + /* Cache block sizes. */ + LIEF_AT_DCACHEBSIZE = 19, /**< Data cache block size. */ + LIEF_AT_ICACHEBSIZE = 20, /**< Instruction cache block size. */ + LIEF_AT_UCACHEBSIZE = 21, /**< Unified cache block size. */ + + /* A special ignored value for PPC, used by the kernel to control the + interpretation of the AUXV. Must be > 16. */ + + LIEF_AT_IGNOREPPC = 22, /**< Entry should be ignored. */ + LIEF_AT_SECURE = 23, /**< Boolean, was exec setuid-like? */ + LIEF_AT_BASE_PLATFORM = 24, /**< String identifying real platforms.*/ + LIEF_AT_RANDOM = 25, /**< Address of 16 random bytes. */ + LIEF_AT_HWCAP2 = 26, /**< Extension of AT_HWCAP. */ + LIEF_AT_EXECFN = 31, /**< Filename of executable. */ + + /* Pointer to the global system page used for system calls and other + nice things. */ + LIEF_AT_SYSINFO = 32, + LIEF_AT_SYSINFO_EHDR = 33, + + /* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains + log2 of line size; mask those to get cache size. */ + LIEF_AT_L1I_CACHESHAPE = 34, + LIEF_AT_L1D_CACHESHAPE = 35, + LIEF_AT_L2_CACHESHAPE = 36, + LIEF_AT_L3_CACHESHAPE = 37 +}; + +/** Methods that can be used by the LIEF::ELF::Parser + to count the number of dynamic symbols */ +enum LIEF_DYNSYM_COUNT_METHODS { + LIEF_COUNT_AUTO = 0, /**< Automatic detection */ + LIEF_COUNT_SECTION = 1, /**< Count based on sections (not very reliable */ + LIEF_COUNT_HASH = 2, /**< Count based on hash table (reliable */ + LIEF_COUNT_RELOCATIONS = 3, /**< Count based on PLT/GOT relocations (very reliable but not accurate */ +}; + +enum LIEF_NOTE_TYPES { + LIEF_NT_UNKNOWN = 0, + LIEF_NT_GNU_ABI_TAG = 1, + LIEF_NT_GNU_HWCAP = 2, + LIEF_NT_GNU_BUILD_ID = 3, + LIEF_NT_GNU_GOLD_VERSION = 4, + LIEF_NT_GNU_PROPERTY_TYPE_0 = 5, + LIEF_NT_GNU_BUILD_ATTRIBUTE_OPEN = 0x100, + LIEF_NT_GNU_BUILD_ATTRIBUTE_FUNC = 0x101, + LIEF_NT_CRASHPAD = 0x4f464e49, +}; + +enum LIEF_NOTE_TYPES_CORE { + LIEF_NT_CORE_UNKNOWN = 0, + LIEF_NT_PRSTATUS = 1, + LIEF_NT_PRFPREG = 2, + LIEF_NT_PRPSINFO = 3, + LIEF_NT_TASKSTRUCT = 4, + LIEF_NT_AUXV = 6, + LIEF_NT_SIGINFO = 0x53494749, + LIEF_NT_FILE = 0x46494c45, + LIEF_NT_PRXFPREG = 0x46e62b7f, + + LIEF_NT_ARM_VFP = 0x400, + LIEF_NT_ARM_TLS = 0x401, + LIEF_NT_ARM_HW_BREAK = 0x402, + LIEF_NT_ARM_HW_WATCH = 0x403, + LIEF_NT_ARM_SYSTEM_CALL = 0x404, + LIEF_NT_ARM_SVE = 0x405, + + LIEF_NT_386_TLS = 0x200, + LIEF_NT_386_IOPERM = 0x201, + LIEF_NT_386_XSTATE = 0x202, + +}; + + +enum LIEF_NOTE_ABIS { + LIEF_ELF_NOTE_UNKNOWN = ~(unsigned int)(0), + LIEF_ELF_NOTE_OS_LINUX = 0, + LIEF_ELF_NOTE_OS_GNU = 1, + LIEF_ELF_NOTE_OS_SOLARIS2 = 2, + LIEF_ELF_NOTE_OS_FREEBSD = 3, + LIEF_ELF_NOTE_OS_NETBSD = 4, + LIEF_ELF_NOTE_OS_SYLLABLE = 5, +}; + +enum LIEF_RELOCATION_PURPOSES { + LIEF_RELOC_PURPOSE_NONE = 0, + LIEF_RELOC_PURPOSE_PLTGOT = 1, + LIEF_RELOC_PURPOSE_DYNAMIC = 2, + LIEF_RELOC_PURPOSE_OBJECT = 3, +}; #ifdef __cplusplus } diff --git a/api/c/include/LIEF/ELF/utils.h b/api/c/include/LIEF/ELF/utils.h index b0d368a430..9f0c5ba4c2 100644 --- a/api/c/include/LIEF/ELF/utils.h +++ b/api/c/include/LIEF/ELF/utils.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef C_LIEF_ELF_UTILS_H_ -#define C_LIEF_ELF_UTILS_H_ +#ifndef LIEF_C_ELF_UTILS_H +#define LIEF_C_ELF_UTILS_H #include diff --git a/api/python/examples/abstract_json.py b/api/python/examples/abstract_json.py index 8a6463264d..c1a0124d57 100644 --- a/api/python/examples/abstract_json.py +++ b/api/python/examples/abstract_json.py @@ -17,7 +17,7 @@ def main(): args = parser.parse_args() binary = lief.parse(args.binary) - json_data = json.loads(lief.to_json_from_abstract(binary)) + json_data = json.loads(lief.to_json(binary.abstract)) print(json.dumps(json_data, sort_keys = True, indent = 4)) if __name__ == "__main__": diff --git a/api/python/examples/abstract_reader.py b/api/python/examples/abstract_reader.py index 908555f7a4..87d47a6cd0 100644 --- a/api/python/examples/abstract_reader.py +++ b/api/python/examples/abstract_reader.py @@ -177,12 +177,7 @@ def main(): args = parser.parse_args() - binary = None - try: - binary = lief.parse(args.binary) - except lief.exception as e: - print(e) - sys.exit(1) + binary = lief.parse(args.binary) binary = binary.abstract if args.show_header or args.show_all: diff --git a/api/python/examples/change_elf_interpreter.py b/api/python/examples/change_elf_interpreter.py index 9db034863e..b360ad5a1f 100644 --- a/api/python/examples/change_elf_interpreter.py +++ b/api/python/examples/change_elf_interpreter.py @@ -15,7 +15,7 @@ def change_interpreter(target, interpreter, output=None): print("Wrong interpreter! ({})".format(interpreter)) return 1 - binary = lief.parse(target) + binary = lief.ELF.parse(target) if not binary.has_interpreter: print("The given target doesn't have interpreter!") return 1 diff --git a/api/python/examples/dex_json.py b/api/python/examples/dex_json.py index 0bfb66b4d9..22ada2c04e 100644 --- a/api/python/examples/dex_json.py +++ b/api/python/examples/dex_json.py @@ -15,7 +15,7 @@ def main(): parser.add_argument('file', help='DEX binary') args = parser.parse_args() - if not lief.DEX.is_dex(args.file): + if not lief.is_dex(args.file): print("{} is not a DEX file".format(args.file)) return 1 dexfile = lief.DEX.parse(args.file) diff --git a/api/python/examples/dex_reader.py b/api/python/examples/dex_reader.py index ec7c258a31..c530f6699d 100644 --- a/api/python/examples/dex_reader.py +++ b/api/python/examples/dex_reader.py @@ -208,12 +208,7 @@ def main(): lief.logging.set_level(args.main_verbosity) - binary = None - try: - dexfile = DEX.parse(args.file) - except lief.exception as e: - print(e) - sys.exit(1) + dexfile = DEX.parse(args.file) print_information(dexfile) diff --git a/api/python/examples/elf_reader.py b/api/python/examples/elf_reader.py index 50c83d03df..0385aecb08 100644 --- a/api/python/examples/elf_reader.py +++ b/api/python/examples/elf_reader.py @@ -134,13 +134,13 @@ def print_segments(binary): sections = segment.sections s = ", ".join([section.name for section in sections]) flags_str = ["-"] * 3 - if ELF.SEGMENT_FLAGS.R in segment: + if ELF.Segment.FLAGS.R in segment: flags_str[0] = "r" - if ELF.SEGMENT_FLAGS.W in segment: + if ELF.Segment.FLAGS.W in segment: flags_str[1] = "w" - if ELF.SEGMENT_FLAGS.X in segment: + if ELF.Segment.FLAGS.X in segment: flags_str[2] = "x" flags_str = "".join(flags_str) @@ -167,18 +167,18 @@ def print_dynamic_entries(binary): f_value = "|{:<16} | 0x{:<8x}| {:<20}|" print(f_title.format("Tag", "Value", "Info")) for entry in dynamic_entries: - if entry.tag == ELF.DYNAMIC_TAGS.NULL: + if entry.tag == ELF.DynamicEntry.TAG.NULL: continue - if entry.tag in [ELF.DYNAMIC_TAGS.SONAME, ELF.DYNAMIC_TAGS.NEEDED, ELF.DYNAMIC_TAGS.RUNPATH, ELF.DYNAMIC_TAGS.RPATH]: + if entry.tag in [ELF.DynamicEntry.TAG.SONAME, ELF.DynamicEntry.TAG.NEEDED, ELF.DynamicEntry.TAG.RUNPATH, ELF.DynamicEntry.TAG.RPATH]: print(f_value.format(str(entry.tag).split(".")[-1], entry.value, entry.name)) - elif type(entry) is ELF.DynamicEntryArray: # [ELF.DYNAMIC_TAGS.INIT_ARRAY,ELF.DYNAMIC_TAGS.FINI_ARRAY]: + elif type(entry) is ELF.DynamicEntryArray: # [ELF.DynamicEntry.TAG.INIT_ARRAY,ELF.DynamicEntry.TAG.FINI_ARRAY]: print(f_value.format(str(entry.tag).split(".")[-1], entry.value, ", ".join(map(hex, entry.array)))) - elif entry.tag == ELF.DYNAMIC_TAGS.FLAGS: - flags_str = " - ".join([str(ELF.DYNAMIC_FLAGS(s)).split(".")[-1] for s in entry.flags]) + elif entry.tag == ELF.DynamicEntry.TAG.FLAGS: + flags_str = " - ".join([str(ELF.DynamicEntryFlags.FLAG(s)).split(".")[-1] for s in entry.flags]) print(f_value.format(str(entry.tag).split(".")[-1], entry.value, flags_str)) - elif entry.tag == ELF.DYNAMIC_TAGS.FLAGS_1: - flags_str = " - ".join([str(ELF.DYNAMIC_FLAGS_1(s)).split(".")[-1] for s in entry.flags]) + elif entry.tag == ELF.DynamicEntry.TAG.FLAGS_1: + flags_str = " - ".join([str(ELF.DynamicEntryFlags.FLAG(s)).split(".")[-1] for s in entry.flags]) print(f_value.format(str(entry.tag).split(".")[-1], entry.value, flags_str)) else: print(f_value.format(str(entry.tag).split(".")[-1], entry.value, "")) @@ -267,7 +267,7 @@ def print_relocations(binary, relocations): symbol: lief.ELF.Symbol = relocation.symbol if len(symbol.name) > 0: symbol_name = symbol.name - elif symbol.type == lief.ELF.SYMBOL_TYPES.SECTION: + elif symbol.type == lief.ELF.Symbol.TYPE.SECTION: shndx = symbol.shndx sections = binary.sections if 0 < shndx and shndx < len(sections): @@ -402,19 +402,19 @@ def print_notes(binary): note_details = note.details - if type(note_details) == lief.ELF.AndroidNote: + if isinstance(note_details, lief.ELF.AndroidIdent): print(format_dec.format("SDK Version:", note_details.sdk_version)) print(format_str.format("NDK Version:", note_details.ndk_version)) print(format_str.format("NDK build number:", note_details.ndk_build_number)) - if type(note_details) == lief.ELF.NoteAbi: + if isinstance(note_details, lief.ELF.NoteAbi): version = note_details.version version_str = "{:d}.{:d}.{:d}".format(version[0], version[1], version[2]) print(format_str.format("ABI:", note_details.abi)) print(format_str.format("Version:", version_str)) - if ELF.NOTE_TYPES(note.type) == ELF.NOTE_TYPES.GOLD_VERSION: + if note.type == ELF.Note.TYPE.GNU_GOLD_VERSION: print(format_str.format("Version:", "".join(map(chr, note.description)))) if note.is_core: diff --git a/api/python/examples/elf_remove_section_table.py b/api/python/examples/elf_remove_section_table.py index c9066e6770..a8eac49394 100644 --- a/api/python/examples/elf_remove_section_table.py +++ b/api/python/examples/elf_remove_section_table.py @@ -23,7 +23,7 @@ from lief import ELF def remove_section_table(filename, output): - binary = lief.parse(filename) # Build an ELF binary + binary = lief.ELF.parse(filename) # Build an ELF binary header = binary.header header.section_header_offset = 0; diff --git a/api/python/examples/elf_unstrip.py b/api/python/examples/elf_unstrip.py index d60a05b97b..5626445342 100644 --- a/api/python/examples/elf_unstrip.py +++ b/api/python/examples/elf_unstrip.py @@ -20,7 +20,7 @@ def main(): symtab_section = ELF.Section() symtab_section.name = "" - symtab_section.type = ELF.SECTION_TYPES.SYMTAB + symtab_section.type = ELF.Section.TYPE.SYMTAB symtab_section.entry_size = 0x18 symtab_section.alignment = 8 symtab_section.link = len(binary.sections) + 1 @@ -28,7 +28,7 @@ def main(): symstr_section = ELF.Section() symstr_section.name = "" - symstr_section.type = ELF.SECTION_TYPES.STRTAB + symstr_section.type = ELF.Section.TYPE.STRTAB symstr_section.entry_size = 1 symstr_section.alignment = 1 symstr_section.content = [0] * 100 @@ -38,18 +38,18 @@ def main(): symbol = ELF.Symbol() symbol.name = "" - symbol.type = ELF.SYMBOL_TYPES.NOTYPE + symbol.type = ELF.Symbol.TYPE.NOTYPE symbol.value = 0 - symbol.binding = ELF.SYMBOL_BINDINGS.LOCAL + symbol.binding = ELF.Symbol.BINDING.LOCAL symbol.size = 0 symbol.shndx = 0 symbol = binary.add_static_symbol(symbol) symbol = ELF.Symbol() symbol.name = "main" - symbol.type = ELF.SYMBOL_TYPES.FUNC + symbol.type = ELF.Symbol.TYPE.FUNC symbol.value = 0x402A00 - symbol.binding = ELF.SYMBOL_BINDINGS.LOCAL + symbol.binding = ELF.Symbol.BINDING.LOCAL symbol.shndx = 14 symbol = binary.add_static_symbol(symbol) diff --git a/api/python/examples/oat_reader.py b/api/python/examples/oat_reader.py index ac7d2ba48c..8549e780ba 100644 --- a/api/python/examples/oat_reader.py +++ b/api/python/examples/oat_reader.py @@ -183,12 +183,7 @@ def main(): lief.logging.set_level(args.main_verbosity) - binary = None - try: - binary = OAT.parse(args.binary) - except lief.exception as e: - print(e) - sys.exit(1) + binary = OAT.parse(args.binary) print_information(binary) diff --git a/api/python/examples/pe_forwardinfo.py b/api/python/examples/pe_forwardinfo.py index 8a85fd7f23..fc7d689209 100644 --- a/api/python/examples/pe_forwardinfo.py +++ b/api/python/examples/pe_forwardinfo.py @@ -1,7 +1,7 @@ import lief import sys -pe = lief.parse(sys.argv[1]) +pe = lief.PE.parse(sys.argv[1]) exports = pe.get_export() for e in filter(lambda e: e.is_forwarded, exports.entries): diff --git a/api/python/examples/pe_from_scratch.py b/api/python/examples/pe_from_scratch.py index 03fbdad0d6..fe97ba9927 100644 --- a/api/python/examples/pe_from_scratch.py +++ b/api/python/examples/pe_from_scratch.py @@ -3,7 +3,7 @@ # Description: # Create a PE which pop a MessageBox -# with the message "Hello World" +# with the message "Hello World" from lief import PE diff --git a/api/python/examples/pe_reader.py b/api/python/examples/pe_reader.py index a42b6a626b..89b83343be 100644 --- a/api/python/examples/pe_reader.py +++ b/api/python/examples/pe_reader.py @@ -565,12 +565,7 @@ def main(): args = parser.parse_args() lief.logging.set_level(args.main_verbosity) - binary = None - try: - binary = PE.parse(args.pe_file) - except lief.exception as e: - print(e) - sys.exit(1) + binary = PE.parse(args.pe_file) if binary is None: sys.exit(1) diff --git a/api/python/examples/pe_resources_manager.py b/api/python/examples/pe_resources_manager.py index d127717c7f..ce373f83e3 100644 --- a/api/python/examples/pe_resources_manager.py +++ b/api/python/examples/pe_resources_manager.py @@ -2,7 +2,7 @@ import sys import lief -b = lief.parse(sys.argv[1]) +b = lief.PE.parse(sys.argv[1]) manager = b.resources_manager print(manager) print(manager.manifest) diff --git a/api/python/examples/vdex_json.py b/api/python/examples/vdex_json.py index 844cfb3043..d0c1fac252 100644 --- a/api/python/examples/vdex_json.py +++ b/api/python/examples/vdex_json.py @@ -15,7 +15,7 @@ def main(): parser.add_argument('file', help='VDEX file') args = parser.parse_args() - if not lief.VDEX.is_vdex(args.file): + if not lief.is_vdex(args.file): print("{} is not a VDEX file".format(args.file)) return 1 dexfile = lief.VDEX.parse(args.file) diff --git a/api/python/examples/vdex_reader.py b/api/python/examples/vdex_reader.py index 83a7c6a03d..f3e15cbc9a 100644 --- a/api/python/examples/vdex_reader.py +++ b/api/python/examples/vdex_reader.py @@ -120,12 +120,7 @@ def main(): lief.logging.set_level(args.main_verbosity) - vdexfile = None - try: - vdexfile = DEX.parse(args.file) - except lief.exception as e: - print(e) - sys.exit(1) + vdexfile = DEX.parse(args.file) print_information(vdexfile) diff --git a/api/python/src/ELF/CMakeLists.txt b/api/python/src/ELF/CMakeLists.txt index e764944dcb..bec2b8e48e 100644 --- a/api/python/src/ELF/CMakeLists.txt +++ b/api/python/src/ELF/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(pyLIEF PRIVATE init.cpp enums.cpp + pyProcessorFlags.cpp ) add_subdirectory(objects) diff --git a/api/python/src/ELF/enums.cpp b/api/python/src/ELF/enums.cpp index c9a953dc54..fa76297cc3 100644 --- a/api/python/src/ELF/enums.cpp +++ b/api/python/src/ELF/enums.cpp @@ -18,1309 +18,189 @@ #include "LIEF/ELF/EnumToString.hpp" #include "enums_wrapper.hpp" -#define PY_ENUM(x) to_string(x), x - namespace LIEF::ELF::py { void init_enums(nb::module_& m) { - enum_(m, "ELF_CLASS") - .value(PY_ENUM(ELF_CLASS::ELFCLASSNONE)) - .value(PY_ENUM(ELF_CLASS::ELFCLASS32)) - .value(PY_ENUM(ELF_CLASS::ELFCLASS64)); - - enum_(m, "ELF_DATA") - .value(PY_ENUM(ELF_DATA::ELFDATANONE)) - .value(PY_ENUM(ELF_DATA::ELFDATA2LSB)) - .value(PY_ENUM(ELF_DATA::ELFDATA2MSB)); - - enum_(m, "OS_ABI") - .value(PY_ENUM(OS_ABI::ELFOSABI_SYSTEMV)) - .value(PY_ENUM(OS_ABI::ELFOSABI_HPUX)) - .value(PY_ENUM(OS_ABI::ELFOSABI_NETBSD)) - .value(PY_ENUM(OS_ABI::ELFOSABI_LINUX)) - .value("GNU", OS_ABI::ELFOSABI_GNU) - .value(PY_ENUM(OS_ABI::ELFOSABI_HURD)) - .value(PY_ENUM(OS_ABI::ELFOSABI_SOLARIS)) - .value(PY_ENUM(OS_ABI::ELFOSABI_AIX)) - .value(PY_ENUM(OS_ABI::ELFOSABI_IRIX)) - .value(PY_ENUM(OS_ABI::ELFOSABI_FREEBSD)) - .value(PY_ENUM(OS_ABI::ELFOSABI_TRU64)) - .value(PY_ENUM(OS_ABI::ELFOSABI_MODESTO)) - .value(PY_ENUM(OS_ABI::ELFOSABI_OPENBSD)) - .value(PY_ENUM(OS_ABI::ELFOSABI_OPENVMS)) - .value(PY_ENUM(OS_ABI::ELFOSABI_NSK)) - .value(PY_ENUM(OS_ABI::ELFOSABI_AROS)) - .value(PY_ENUM(OS_ABI::ELFOSABI_FENIXOS)) - .value(PY_ENUM(OS_ABI::ELFOSABI_CLOUDABI)) - .value(PY_ENUM(OS_ABI::ELFOSABI_AMDGPU_HSA)) - .value("C6000_ELFABI", OS_ABI::ELFOSABI_C6000_ELFABI) - .value(PY_ENUM(OS_ABI::ELFOSABI_C6000_LINUX)) - .value(PY_ENUM(OS_ABI::ELFOSABI_ARM)) - .value(PY_ENUM(OS_ABI::ELFOSABI_STANDALONE)); - - // Enum for the *e_type* of ElfXX_Ehdr - enum_(m, "E_TYPE") - .value(PY_ENUM(E_TYPE::ET_NONE)) - .value(PY_ENUM(E_TYPE::ET_REL)) - .value(PY_ENUM(E_TYPE::ET_EXEC)) - .value(PY_ENUM(E_TYPE::ET_DYN)) - .value(PY_ENUM(E_TYPE::ET_CORE)) - .value(PY_ENUM(E_TYPE::ET_LOPROC)) - .value(PY_ENUM(E_TYPE::ET_HIPROC)); - - //! Enum for the *e_version* of ElfXX_Ehdr; - enum_(m, "VERSION") - .value(PY_ENUM(VERSION::EV_NONE)) - .value(PY_ENUM(VERSION::EV_CURRENT)); - - // Enum for the *e_machine* of ElfXX_Ehdr + #define ENTRY(X) .value(to_string(ARCH::X), ARCH::X) enum_(m, "ARCH") - .value(PY_ENUM(ARCH::EM_NONE)) - .value(PY_ENUM(ARCH::EM_M32)) - .value(PY_ENUM(ARCH::EM_SPARC)) - .value(PY_ENUM(ARCH::EM_386)) - .value(PY_ENUM(ARCH::EM_68K)) - .value(PY_ENUM(ARCH::EM_88K)) - .value(PY_ENUM(ARCH::EM_IAMCU)) - .value(PY_ENUM(ARCH::EM_860)) - .value(PY_ENUM(ARCH::EM_MIPS)) - .value(PY_ENUM(ARCH::EM_S370)) - .value(PY_ENUM(ARCH::EM_MIPS_RS3_LE)) - .value(PY_ENUM(ARCH::EM_PARISC)) - .value(PY_ENUM(ARCH::EM_VPP500)) - .value(PY_ENUM(ARCH::EM_SPARC32PLUS)) - .value(PY_ENUM(ARCH::EM_960)) - .value(PY_ENUM(ARCH::EM_PPC)) - .value(PY_ENUM(ARCH::EM_PPC64)) - .value(PY_ENUM(ARCH::EM_S390)) - .value(PY_ENUM(ARCH::EM_SPU)) - .value(PY_ENUM(ARCH::EM_V800)) - .value(PY_ENUM(ARCH::EM_FR20)) - .value(PY_ENUM(ARCH::EM_RH32)) - .value(PY_ENUM(ARCH::EM_RCE)) - .value(PY_ENUM(ARCH::EM_ARM)) - .value(PY_ENUM(ARCH::EM_ALPHA)) - .value(PY_ENUM(ARCH::EM_SH)) - .value(PY_ENUM(ARCH::EM_SPARCV9)) - .value(PY_ENUM(ARCH::EM_TRICORE)) - .value(PY_ENUM(ARCH::EM_ARC)) - .value(PY_ENUM(ARCH::EM_H8_300)) - .value(PY_ENUM(ARCH::EM_H8_300H)) - .value(PY_ENUM(ARCH::EM_H8S)) - .value(PY_ENUM(ARCH::EM_H8_500)) - .value(PY_ENUM(ARCH::EM_IA_64)) - .value(PY_ENUM(ARCH::EM_MIPS_X)) - .value(PY_ENUM(ARCH::EM_COLDFIRE)) - .value(PY_ENUM(ARCH::EM_68HC12)) - .value(PY_ENUM(ARCH::EM_MMA)) - .value(PY_ENUM(ARCH::EM_PCP)) - .value(PY_ENUM(ARCH::EM_NCPU)) - .value(PY_ENUM(ARCH::EM_NDR1)) - .value(PY_ENUM(ARCH::EM_STARCORE)) - .value(PY_ENUM(ARCH::EM_ME16)) - .value(PY_ENUM(ARCH::EM_ST100)) - .value(PY_ENUM(ARCH::EM_TINYJ)) - .value(PY_ENUM(ARCH::EM_X86_64)) - .value(PY_ENUM(ARCH::EM_PDSP)) - .value(PY_ENUM(ARCH::EM_PDP10)) - .value(PY_ENUM(ARCH::EM_PDP11)) - .value(PY_ENUM(ARCH::EM_FX66)) - .value(PY_ENUM(ARCH::EM_ST9PLUS)) - .value(PY_ENUM(ARCH::EM_ST7)) - .value(PY_ENUM(ARCH::EM_68HC16)) - .value(PY_ENUM(ARCH::EM_68HC11)) - .value(PY_ENUM(ARCH::EM_68HC08)) - .value(PY_ENUM(ARCH::EM_68HC05)) - .value(PY_ENUM(ARCH::EM_SVX)) - .value(PY_ENUM(ARCH::EM_ST19)) - .value(PY_ENUM(ARCH::EM_VAX)) - .value(PY_ENUM(ARCH::EM_CRIS)) - .value(PY_ENUM(ARCH::EM_JAVELIN)) - .value(PY_ENUM(ARCH::EM_FIREPATH)) - .value(PY_ENUM(ARCH::EM_ZSP)) - .value(PY_ENUM(ARCH::EM_MMIX)) - .value(PY_ENUM(ARCH::EM_HUANY)) - .value(PY_ENUM(ARCH::EM_PRISM)) - .value(PY_ENUM(ARCH::EM_AVR)) - .value(PY_ENUM(ARCH::EM_FR30)) - .value(PY_ENUM(ARCH::EM_D10V)) - .value(PY_ENUM(ARCH::EM_D30V)) - .value(PY_ENUM(ARCH::EM_V850)) - .value(PY_ENUM(ARCH::EM_M32R)) - .value(PY_ENUM(ARCH::EM_MN10300)) - .value(PY_ENUM(ARCH::EM_MN10200)) - .value(PY_ENUM(ARCH::EM_PJ)) - .value(PY_ENUM(ARCH::EM_OPENRISC)) - .value(PY_ENUM(ARCH::EM_ARC_COMPACT)) - .value(PY_ENUM(ARCH::EM_XTENSA)) - .value(PY_ENUM(ARCH::EM_VIDEOCORE)) - .value(PY_ENUM(ARCH::EM_TMM_GPP)) - .value(PY_ENUM(ARCH::EM_NS32K)) - .value(PY_ENUM(ARCH::EM_TPC)) - .value(PY_ENUM(ARCH::EM_SNP1K)) - .value(PY_ENUM(ARCH::EM_ST200)) - .value(PY_ENUM(ARCH::EM_IP2K)) - .value(PY_ENUM(ARCH::EM_MAX)) - .value(PY_ENUM(ARCH::EM_CR)) - .value(PY_ENUM(ARCH::EM_F2MC16)) - .value(PY_ENUM(ARCH::EM_MSP430)) - .value(PY_ENUM(ARCH::EM_BLACKFIN)) - .value(PY_ENUM(ARCH::EM_SE_C33)) - .value(PY_ENUM(ARCH::EM_SEP)) - .value(PY_ENUM(ARCH::EM_ARCA)) - .value(PY_ENUM(ARCH::EM_UNICORE)) - .value(PY_ENUM(ARCH::EM_EXCESS)) - .value(PY_ENUM(ARCH::EM_DXP)) - .value(PY_ENUM(ARCH::EM_ALTERA_NIOS2)) - .value(PY_ENUM(ARCH::EM_CRX)) - .value(PY_ENUM(ARCH::EM_XGATE)) - .value(PY_ENUM(ARCH::EM_C166)) - .value(PY_ENUM(ARCH::EM_M16C)) - .value(PY_ENUM(ARCH::EM_DSPIC30F)) - .value(PY_ENUM(ARCH::EM_CE)) - .value(PY_ENUM(ARCH::EM_M32C)) - .value(PY_ENUM(ARCH::EM_TSK3000)) - .value(PY_ENUM(ARCH::EM_RS08)) - .value(PY_ENUM(ARCH::EM_SHARC)) - .value(PY_ENUM(ARCH::EM_ECOG2)) - .value(PY_ENUM(ARCH::EM_SCORE7)) - .value(PY_ENUM(ARCH::EM_DSP24)) - .value(PY_ENUM(ARCH::EM_VIDEOCORE3)) - .value(PY_ENUM(ARCH::EM_LATTICEMICO32)) - .value(PY_ENUM(ARCH::EM_SE_C17)) - .value(PY_ENUM(ARCH::EM_TI_C6000)) - .value(PY_ENUM(ARCH::EM_TI_C2000)) - .value(PY_ENUM(ARCH::EM_TI_C5500)) - .value(PY_ENUM(ARCH::EM_MMDSP_PLUS)) - .value(PY_ENUM(ARCH::EM_CYPRESS_M8C)) - .value(PY_ENUM(ARCH::EM_R32C)) - .value(PY_ENUM(ARCH::EM_TRIMEDIA)) - .value(PY_ENUM(ARCH::EM_HEXAGON)) - .value(PY_ENUM(ARCH::EM_8051)) - .value(PY_ENUM(ARCH::EM_STXP7X)) - .value(PY_ENUM(ARCH::EM_NDS32)) - .value("ECOG1", ARCH::EM_ECOG1) - .value("ECOG1X", ARCH::EM_ECOG1X) - .value(PY_ENUM(ARCH::EM_MAXQ30)) - .value(PY_ENUM(ARCH::EM_XIMO16)) - .value(PY_ENUM(ARCH::EM_MANIK)) - .value(PY_ENUM(ARCH::EM_CRAYNV2)) - .value(PY_ENUM(ARCH::EM_RX)) - .value(PY_ENUM(ARCH::EM_METAG)) - .value(PY_ENUM(ARCH::EM_MCST_ELBRUS)) - .value(PY_ENUM(ARCH::EM_ECOG16)) - .value(PY_ENUM(ARCH::EM_CR16)) - .value(PY_ENUM(ARCH::EM_ETPU)) - .value(PY_ENUM(ARCH::EM_SLE9X)) - .value(PY_ENUM(ARCH::EM_L10M)) - .value(PY_ENUM(ARCH::EM_K10M)) - .value(PY_ENUM(ARCH::EM_AARCH64)) - .value(PY_ENUM(ARCH::EM_AVR32)) - .value(PY_ENUM(ARCH::EM_STM8)) - .value(PY_ENUM(ARCH::EM_TILE64)) - .value(PY_ENUM(ARCH::EM_TILEPRO)) - .value(PY_ENUM(ARCH::EM_CUDA)) - .value(PY_ENUM(ARCH::EM_TILEGX)) - .value(PY_ENUM(ARCH::EM_CLOUDSHIELD)) - .value(PY_ENUM(ARCH::EM_COREA_1ST)) - .value(PY_ENUM(ARCH::EM_COREA_2ND)) - .value(PY_ENUM(ARCH::EM_ARC_COMPACT2)) - .value(PY_ENUM(ARCH::EM_OPEN8)) - .value(PY_ENUM(ARCH::EM_RL78)) - .value(PY_ENUM(ARCH::EM_VIDEOCORE5)) - .value(PY_ENUM(ARCH::EM_78KOR)) - .value(PY_ENUM(ARCH::EM_56800EX)) - .value(PY_ENUM(ARCH::EM_BA1)) - .value(PY_ENUM(ARCH::EM_BA2)) - .value(PY_ENUM(ARCH::EM_XCORE)) - .value(PY_ENUM(ARCH::EM_MCHP_PIC)) - .value(PY_ENUM(ARCH::EM_INTEL205)) - .value(PY_ENUM(ARCH::EM_INTEL206)) - .value(PY_ENUM(ARCH::EM_INTEL207)) - .value(PY_ENUM(ARCH::EM_INTEL208)) - .value(PY_ENUM(ARCH::EM_INTEL209)) - .value(PY_ENUM(ARCH::EM_KM32)) - .value(PY_ENUM(ARCH::EM_KMX32)) - .value(PY_ENUM(ARCH::EM_KMX16)) - .value(PY_ENUM(ARCH::EM_KMX8)) - .value(PY_ENUM(ARCH::EM_KVARC)) - .value(PY_ENUM(ARCH::EM_CDP)) - .value(PY_ENUM(ARCH::EM_COGE)) - .value(PY_ENUM(ARCH::EM_COOL)) - .value(PY_ENUM(ARCH::EM_NORC)) - .value(PY_ENUM(ARCH::EM_CSR_KALIMBA)) - .value(PY_ENUM(ARCH::EM_AMDGPU)) - .value(PY_ENUM(ARCH::EM_RISCV)) - .value(PY_ENUM(ARCH::EM_BPF)) - .value(PY_ENUM(ARCH::EM_LOONGARCH)); - - - //! Enum for the *sh_type* of ElfXX_Shdr; - enum_(m, "SECTION_TYPES") - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_NULL)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_PROGBITS)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_SYMTAB)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_STRTAB)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_RELA)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_HASH)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_DYNAMIC)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_NOTE)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_NOBITS)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_REL)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_SHLIB)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_DYNSYM)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_INIT_ARRAY)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_FINI_ARRAY)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_PREINIT_ARRAY)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_GROUP)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_SYMTAB_SHNDX)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_LOOS)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_GNU_ATTRIBUTES)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_GNU_HASH)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_GNU_verdef)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_GNU_verneed)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_GNU_versym)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ANDROID_REL)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ANDROID_RELA)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_LLVM_ADDRSIG)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_RELR)) - - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ARM_EXIDX)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ARM_PREEMPTMAP)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ARM_ATTRIBUTES)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ARM_DEBUGOVERLAY)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_ARM_OVERLAYSECTION)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_HEX_ORDERED)) - .value("X86_64_UNWIND", ELF_SECTION_TYPES::SHT_X86_64_UNWIND) - //.value(PY_ENUM(ELF_SECTION_TYPES::SHT_MIPS_REGINFO)) - //.value(PY_ENUM(ELF_SECTION_TYPES::SHT_MIPS_OPTIONS)) - //.value(PY_ENUM(ELF_SECTION_TYPES::SHT_MIPS_ABIFLAGS)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_HIPROC)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_LOUSER)) - .value(PY_ENUM(ELF_SECTION_TYPES::SHT_HIUSER)); - - - //! Enum for the *sh_flags* field of ElfXX_Shdr; - enum_(m, "SECTION_FLAGS", nb::is_arithmetic()) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_NONE)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_WRITE)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_ALLOC)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_EXECINSTR)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_MERGE)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_STRINGS)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_INFO_LINK)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_LINK_ORDER)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_OS_NONCONFORMING)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_GROUP)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_TLS)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_EXCLUDE)) - .value("SHF_CP_SECTION", ELF_SECTION_FLAGS::XCORE_SHF_CP_SECTION) - .value(PY_ENUM(ELF_SECTION_FLAGS::XCORE_SHF_DP_SECTION)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_MASKOS)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_MASKPROC)) - .value(PY_ENUM(ELF_SECTION_FLAGS::SHF_HEX_GPREL)); - - //! Enum for the *p_type* field of ElfXX_Phdr - enum_(m, "SEGMENT_TYPES") - .value(PY_ENUM(SEGMENT_TYPES::PT_NULL)) - .value(PY_ENUM(SEGMENT_TYPES::PT_LOAD)) - .value(PY_ENUM(SEGMENT_TYPES::PT_DYNAMIC)) - .value(PY_ENUM(SEGMENT_TYPES::PT_INTERP)) - .value(PY_ENUM(SEGMENT_TYPES::PT_NOTE)) - .value(PY_ENUM(SEGMENT_TYPES::PT_SHLIB)) - .value(PY_ENUM(SEGMENT_TYPES::PT_PHDR)) - .value(PY_ENUM(SEGMENT_TYPES::PT_TLS)) - .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_EH_FRAME)) - .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_PROPERTY)) - .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_STACK)) - .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_RELRO)) - .value(PY_ENUM(SEGMENT_TYPES::PT_ARM_ARCHEXT)) - .value(PY_ENUM(SEGMENT_TYPES::PT_ARM_EXIDX)) - .value("UNWIND", SEGMENT_TYPES::PT_ARM_UNWIND); - - //! Enum for the *p_flags* field of ElfXX_Phdr - enum_(m, "SEGMENT_FLAGS", nb::is_arithmetic()) - .value(PY_ENUM(ELF_SEGMENT_FLAGS::PF_NONE)) - .value(PY_ENUM(ELF_SEGMENT_FLAGS::PF_X)) - .value(PY_ENUM(ELF_SEGMENT_FLAGS::PF_W)) - .value(PY_ENUM(ELF_SEGMENT_FLAGS::PF_R)); - - enum_(m, "DYNAMIC_TAGS") - .value(PY_ENUM(DYNAMIC_TAGS::DT_NULL)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_NEEDED)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_PLTRELSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_PLTGOT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_HASH)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_STRTAB)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMTAB)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELA)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELASZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELAENT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_STRSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMENT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_INIT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_FINI)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_SONAME)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RPATH)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMBOLIC)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_REL)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELENT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_PLTREL)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_DEBUG)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_TEXTREL)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_JMPREL)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_BIND_NOW)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_INIT_ARRAY)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_FINI_ARRAY)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_INIT_ARRAYSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_FINI_ARRAYSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RUNPATH)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_FLAGS)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_PREINIT_ARRAY)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_GNU_HASH)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELACOUNT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELCOUNT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_FLAGS_1)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_VERSYM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_VERDEF)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_VERDEFNUM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_VERNEED)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_VERNEEDNUM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMTAB_SHNDX)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELRSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELR)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_RELRENT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RLD_VERSION)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_TIME_STAMP)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_ICHECKSUM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_IVERSION)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_FLAGS)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_BASE_ADDRESS)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_MSYM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_CONFLICT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LIBLIST)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LOCAL_GOTNO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_CONFLICTNO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LIBLISTNO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_SYMTABNO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_UNREFEXTNO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_GOTSYM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_HIPAGENO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RLD_MAP)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASS)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASS_NO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_INSTANCE)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_INSTANCE_NO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_RELOC)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_RELOC_NO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_SYM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_SYM_NO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASSSYM)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASSSYM_NO)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_CXX_FLAGS)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PIXIE_INIT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_SYMBOL_LIB)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LOCALPAGE_GOTIDX)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LOCAL_GOTIDX)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_HIDDEN_GOTIDX)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PROTECTED_GOTIDX)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_OPTIONS)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_INTERFACE)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DYNSTR_ALIGN)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_INTERFACE_SIZE)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RLD_TEXT_RESOLVE_ADDR)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PERF_SUFFIX)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_COMPACT_SIZE)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_GP_VALUE)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_AUX_DYNAMIC)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PLTGOT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RWPLT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_REL_OFFSET)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_REL_SIZE)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_REL)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELA)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELASZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELR)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELRSZ)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELRENT)) - .value(PY_ENUM(DYNAMIC_TAGS::DT_ANDROID_RELRCOUNT)); - - - enum_(m, "SYMBOL_TYPES") - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_NOTYPE)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_OBJECT)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_FUNC)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_SECTION)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_FILE)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_COMMON)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_TLS)) - .value(PY_ENUM(ELF_SYMBOL_TYPES::STT_GNU_IFUNC)); - - - enum_(m, "SYMBOL_BINDINGS") - .value(PY_ENUM(SYMBOL_BINDINGS::STB_LOCAL)) - .value(PY_ENUM(SYMBOL_BINDINGS::STB_GLOBAL)) - .value(PY_ENUM(SYMBOL_BINDINGS::STB_WEAK)) - .value(PY_ENUM(SYMBOL_BINDINGS::STB_GNU_UNIQUE)); - - - enum_(m, "RELOCATION_X86_64") - .value(PY_ENUM(RELOC_x86_64::R_X86_64_NONE)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOT32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PLT32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_COPY)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GLOB_DAT)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_JUMP_SLOT)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_RELATIVE)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPCREL)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_32S)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_16)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC16)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_8)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC8)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_DTPMOD64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_DTPOFF64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_TPOFF64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSGD)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSLD)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_DTPOFF32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTTPOFF)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_TPOFF32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTOFF64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPC32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOT64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPCREL64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPC64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPLT64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PLTOFF64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_SIZE32)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_SIZE64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPC32_TLSDESC)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSDESC_CALL)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSDESC)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_IRELATIVE)) - - .value(PY_ENUM(RELOC_x86_64::R_X86_64_RELATIVE64)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC32_BND)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_PLT32_BND)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPCRELX)) - .value(PY_ENUM(RELOC_x86_64::R_X86_64_REX_GOTPCRELX)); - - - enum_(m, "RELOCATION_ARM") - .value(PY_ENUM(RELOC_ARM::R_ARM_NONE)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PC24)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ABS32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_REL32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_PC_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ABS16)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ABS12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_ABS5)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ABS8)) - .value(PY_ENUM(RELOC_ARM::R_ARM_SBREL32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_CALL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_PC8)) - .value(PY_ENUM(RELOC_ARM::R_ARM_BREL_ADJ)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DESC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_SWI8)) - .value(PY_ENUM(RELOC_ARM::R_ARM_XPC25)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_XPC22)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DTPMOD32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DTPOFF32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_TPOFF32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_COPY)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GLOB_DAT)) - .value(PY_ENUM(RELOC_ARM::R_ARM_JUMP_SLOT)) - .value(PY_ENUM(RELOC_ARM::R_ARM_RELATIVE)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOTOFF32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_BASE_PREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_BREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PLT32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_CALL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_JUMP24)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP24)) - .value(PY_ENUM(RELOC_ARM::R_ARM_BASE_ABS)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PCREL_7_0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PCREL_15_8)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PCREL_23_15)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SBREL_11_0_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SBREL_19_12_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SBREL_27_20_CK)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TARGET1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_SBREL31)) - .value(PY_ENUM(RELOC_ARM::R_ARM_V4BX)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TARGET2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PREL31)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_ABS_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVT_ABS)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_PREL_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVT_PREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_ABS_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVT_ABS)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_PREL_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVT_PREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP19)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP6)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_ALU_PREL_11_0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_PC12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ABS32_NOI)) - .value(PY_ENUM(RELOC_ARM::R_ARM_REL32_NOI)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G0_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G1_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_PC_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_PC_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_PC_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_PC_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_PC_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_PC_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_PC_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_PC_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G0_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G1_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SB_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SB_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SB_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_SB_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_SB_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_SB_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_SB_G0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_SB_G1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_SB_G2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_BREL_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVT_BREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_BREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_BREL_NC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVT_BREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_BREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_GOTDESC)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_CALL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DESCSEQ)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_TLS_CALL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PLT32_ABS)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_ABS)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_PREL)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_BREL12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOTOFF12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GOTRELAX)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GNU_VTENTRY)) - .value(PY_ENUM(RELOC_ARM::R_ARM_GNU_VTINHERIT)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP11)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP8)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_GD32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LDM32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LDO32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_IE32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LE32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LDO12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LE12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_IE12GP)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_0)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_1)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_2)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_3)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_4)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_5)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_6)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_7)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_8)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_9)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_10)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_11)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_12)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_13)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_14)) - .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_15)) - .value(PY_ENUM(RELOC_ARM::R_ARM_ME_TOO)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_TLS_DESCSEQ16)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_TLS_DESCSEQ32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_IRELATIVE)) - .value(PY_ENUM(RELOC_ARM::R_ARM_RXPC25)) - .value(PY_ENUM(RELOC_ARM::R_ARM_RSBREL32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_THM_RPC22)) - .value(PY_ENUM(RELOC_ARM::R_ARM_RREL32)) - .value(PY_ENUM(RELOC_ARM::R_ARM_RPC24)) - .value(PY_ENUM(RELOC_ARM::R_ARM_RBASE)); - - - enum_(m, "RELOCATION_i386") - .value(PY_ENUM(RELOC_i386::R_386_NONE)) - .value(PY_ENUM(RELOC_i386::R_386_32)) - .value(PY_ENUM(RELOC_i386::R_386_PC32)) - .value(PY_ENUM(RELOC_i386::R_386_GOT32)) - .value(PY_ENUM(RELOC_i386::R_386_PLT32)) - .value(PY_ENUM(RELOC_i386::R_386_COPY)) - .value(PY_ENUM(RELOC_i386::R_386_GLOB_DAT)) - .value(PY_ENUM(RELOC_i386::R_386_JUMP_SLOT)) - .value(PY_ENUM(RELOC_i386::R_386_RELATIVE)) - .value(PY_ENUM(RELOC_i386::R_386_GOTOFF)) - .value(PY_ENUM(RELOC_i386::R_386_GOTPC)) - .value(PY_ENUM(RELOC_i386::R_386_32PLT)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_TPOFF)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_IE)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GOTIE)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LE)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GD)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM)) - .value(PY_ENUM(RELOC_i386::R_386_16)) - .value(PY_ENUM(RELOC_i386::R_386_PC16)) - .value(PY_ENUM(RELOC_i386::R_386_8)) - .value(PY_ENUM(RELOC_i386::R_386_PC8)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_PUSH)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_CALL)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_POP)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_PUSH)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_CALL)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_POP)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LDO_32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_IE_32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_LE_32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_DTPMOD32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_DTPOFF32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_TPOFF32)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_GOTDESC)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_DESC_CALL)) - .value(PY_ENUM(RELOC_i386::R_386_TLS_DESC)) - .value(PY_ENUM(RELOC_i386::R_386_IRELATIVE)) - .value(PY_ENUM(RELOC_i386::R_386_NUM)); - - - enum_(m, "RELOCATION_AARCH64") - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_NONE)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ABS64)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ABS32)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ABS16)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_PREL64)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_PREL32)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_PREL16)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G0)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G1_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G2)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G2_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_UABS_G3)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_SABS_G0)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_SABS_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_SABS_G2)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LD_PREL_LO19)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ADR_PREL_LO21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ADR_PREL_PG_HI21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ADR_PREL_PG_HI21_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ADD_ABS_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LDST8_ABS_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TSTBR14)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_CONDBR19)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_JUMP26)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_CALL26)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LDST16_ABS_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LDST32_ABS_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LDST64_ABS_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G0)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G1_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G2)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G2_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_PREL_G3)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LDST128_ABS_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G0)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G1_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G2)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G2_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G3)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_GOTREL64)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_GOTREL32)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_GOT_LD_PREL19)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LD64_GOTOFF_LO15)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_ADR_GOT_PAGE)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LD64_GOT_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_LD64_GOTPAGE_LO15)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSGD_ADR_PREL21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSGD_ADR_PAGE21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSGD_ADD_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSGD_MOVW_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSGD_MOVW_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_ADR_PREL21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_ADR_PAGE21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_ADD_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LD_PREL19)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G2)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G0)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_HI12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST8_DTPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST16_DTPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST32_DTPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST64_DTPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSIE_MOVW_GOTTPREL_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSIE_LD_GOTTPREL_PREL19)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G2)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G1_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G0)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_HI12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST8_TPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST16_TPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST32_TPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST64_TPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_LD_PREL19)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_ADR_PREL21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_ADR_PAGE21)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_LD64_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_ADD_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_OFF_G1)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_OFF_G0_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_LDR)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_ADD)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC_CALL)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST128_TPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST128_DTPREL_LO12)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_COPY)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_GLOB_DAT)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_JUMP_SLOT)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_RELATIVE)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLS_DTPREL64)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLS_DTPMOD64)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLS_TPREL64)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_TLSDESC)) - .value(PY_ENUM(RELOC_AARCH64::R_AARCH64_IRELATIVE)); - - enum_(m, "RELOCATION_PPC") - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_NONE)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR32)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR24)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR14)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR14_BRTAKEN)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_ADDR14_BRNTAKEN)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL24)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL14)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL14_BRTAKEN)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL14_BRNTAKEN)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_PLTREL24)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_JMP_SLOT)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_RELATIVE)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_LOCAL24PC)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL32)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TLS)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_DTPMOD32)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TPREL16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TPREL16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TPREL32)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_DTPREL16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_DTPREL16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_DTPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_DTPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_DTPREL32)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSGD16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSGD16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSGD16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSGD16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSLD16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSLD16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSLD16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TLSLD16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TPREL16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TPREL16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_TPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_DTPREL16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_DTPREL16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_DTPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_GOT_DTPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TLSGD)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_TLSLD)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL16)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL16_LO)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL16_HI)) - .value(PY_ENUM(RELOC_POWERPC32::R_PPC_REL16_HA)); - - enum_(m, "RELOCATION_PPC64") - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_NONE)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR32)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR24)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR14)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR14_BRTAKEN)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR14_BRNTAKEN)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL24)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL14)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL14_BRTAKEN)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL14_BRNTAKEN)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_JMP_SLOT)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_RELATIVE)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL32)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR64)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_HIGHER)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_HIGHERA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_HIGHEST)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_HIGHESTA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL64)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_ADDR16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TOC16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TLS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPMOD64)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL64)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL64)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSGD16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSLD16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TPREL16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TPREL16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_TPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_HA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_HIGHER)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_HIGHERA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_HIGHEST)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TPREL16_HIGHESTA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_LO_DS)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHER)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHERA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHEST)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHESTA)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TLSGD)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_TLSLD)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL16)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL16_LO)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL16_HI)) - .value(PY_ENUM(RELOC_POWERPC64::R_PPC64_REL16_HA)); - - enum_(m, "RELOCATION_MIPS") - .value(PY_ENUM(RELOC_MIPS::R_MIPS_NONE)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_32)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_REL32)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_26)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GPREL16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_LITERAL)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GOT16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PC16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_CALL16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GPREL32)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_UNUSED1)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_UNUSED2)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_UNUSED3)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_SHIFT5)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_SHIFT6)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_64)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GOT_DISP)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GOT_PAGE)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GOT_OFST)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GOT_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GOT_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_SUB)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_INSERT_A)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_INSERT_B)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_DELETE)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_HIGHER)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_HIGHEST)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_CALL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_CALL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_SCN_DISP)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_REL16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_ADD_IMMEDIATE)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PJUMP)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_RELGOT)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_JALR)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_DTPMOD32)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_DTPREL32)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_DTPMOD64)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_DTPREL64)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_GD)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_LDM)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_DTPREL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_DTPREL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_GOTTPREL)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_TPREL32)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_TPREL64)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_TPREL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_TLS_TPREL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_GLOB_DAT)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PC21_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PC26_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PC18_S3)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PC19_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PCHI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_PCLO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_26)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_GPREL)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_GOT16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_CALL16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_GD)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_LDM)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_DTPREL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_DTPREL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_GOTTPREL)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_TPREL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS16_TLS_TPREL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_COPY)) - .value(PY_ENUM(RELOC_MIPS::R_MIPS_JUMP_SLOT)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_26_S1)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GPREL16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_LITERAL)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GOT16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC7_S1)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC10_S1)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC16_S1)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_CALL16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GOT_DISP)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GOT_PAGE)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GOT_OFST)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GOT_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GOT_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_SUB)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_HIGHER)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_HIGHEST)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_CALL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_CALL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_SCN_DISP)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_JALR)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_HI0_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_GD)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_LDM)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_DTPREL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_DTPREL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_GOTTPREL)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_TPREL_HI16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_TLS_TPREL_LO16)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_GPREL7_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC23_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC21_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC26_S2)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC18_S3)) - .value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC19_S2)); - - enum_(m, "RELOCATION_LOONGARCH") - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_NONE)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_32)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_64)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_RELATIVE)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_COPY)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_JUMP_SLOT)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD32)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD64)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPREL32)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPREL64)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_TPREL32)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_TPREL64)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_IRELATIVE)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_MARK_LA)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_MARK_PCREL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PCREL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_ABSOLUTE)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_DUP)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_GPREL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_TPREL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GOT)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GD)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PLT_PCREL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_ASSERT)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_NOT)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_SUB)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_SL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_SR)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_ADD)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_AND)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_IF_ELSE)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_5)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U_10_12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16_S2)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_5_20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_5_10_16_S2)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_10_10_16_S2)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD8)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD16)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD24)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD32)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD64)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB8)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB16)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB24)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB32)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB64)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GNU_VTINHERIT)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GNU_VTENTRY)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_B16)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_B21)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_B26)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS64_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS64_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA64_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA64_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_PC_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_PC_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_PC_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_PC_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE64_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE64_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_LO12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_LO20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_HI12)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LD_PC_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LD_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_GD_PC_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_GD_HI20)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_32_PCREL)) - .value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_RELAX)); - - enum_(m, "DYNSYM_COUNT_METHODS") - .value(PY_ENUM(DYNSYM_COUNT_METHODS::COUNT_AUTO)) - .value(PY_ENUM(DYNSYM_COUNT_METHODS::COUNT_SECTION)) - .value(PY_ENUM(DYNSYM_COUNT_METHODS::COUNT_HASH)) - .value(PY_ENUM(DYNSYM_COUNT_METHODS::COUNT_RELOCATIONS)); - - - enum_(m, "RELOCATION_PURPOSES") - .value(PY_ENUM(RELOCATION_PURPOSES::RELOC_PURPOSE_NONE)) - .value(PY_ENUM(RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT)) - .value(PY_ENUM(RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC)) - .value(PY_ENUM(RELOCATION_PURPOSES::RELOC_PURPOSE_OBJECT)); - - - enum_(m, "ARM_EFLAGS", nb::is_arithmetic()) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_SOFT_FLOAT)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_VFP_FLOAT)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_EABI_UNKNOWN)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_EABI_VER1)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_EABI_VER2)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_EABI_VER3)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_EABI_VER4)) - .value(PY_ENUM(ARM_EFLAGS::EF_ARM_EABI_VER5)); - - - enum_(m, "PPC64_EFLAGS", nb::is_arithmetic()) - .value(PY_ENUM(PPC64_EFLAGS::EF_PPC64_ABI)); - - enum_(m, "MIPS_EFLAGS", nb::is_arithmetic()) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_NOREORDER)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_PIC)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_CPIC)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ABI2)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_32BITMODE)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_FP64)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_NAN2008)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ABI_O32)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ABI_O64)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ABI_EABI32)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ABI_EABI64)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_3900)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_4010)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_4100)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_4650)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_4120)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_4111)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_SB1)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_OCTEON)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_XLR)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_OCTEON2)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_OCTEON3)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_5400)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_5900)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_5500)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_9000)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_LS2E)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_LS2F)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MACH_LS3A)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_MICROMIPS)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_ASE_M16)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_ASE_MDMX)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_1)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_2)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_3)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_4)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_5)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_32)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_64)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_32R2)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_64R2)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_32R6)) - .value(PY_ENUM(MIPS_EFLAGS::EF_MIPS_ARCH_64R6)); - - enum_(m, "HEXAGON_EFLAGS", nb::is_arithmetic()) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_MACH_V2)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_MACH_V3)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_MACH_V4)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_MACH_V5)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_MACH)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_V2)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_V3)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_V4)) - .value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_V5)); - - enum_(m, "LOONGARCH_EFLAGS", nb::is_arithmetic()) - .value(PY_ENUM(LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SOFT_FLOAT)) - .value(PY_ENUM(LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SINGLE_FLOAT)) - .value(PY_ENUM(LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_DOUBLE_FLOAT)); - - enum_(m, "IDENTITY") - .value(PY_ENUM(IDENTITY::EI_MAG0)) - .value(PY_ENUM(IDENTITY::EI_MAG1)) - .value(PY_ENUM(IDENTITY::EI_MAG2)) - .value(PY_ENUM(IDENTITY::EI_MAG3)) - .value(PY_ENUM(IDENTITY::EI_CLASS)) - .value(PY_ENUM(IDENTITY::EI_DATA)) - .value(PY_ENUM(IDENTITY::EI_VERSION)) - .value(PY_ENUM(IDENTITY::EI_OSABI)) - .value(PY_ENUM(IDENTITY::EI_ABIVERSION)) - .value(PY_ENUM(IDENTITY::EI_PAD)) - .value(PY_ENUM(IDENTITY::EI_NIDENT)); - - - enum_(m, "SYMBOL_SECTION_INDEX") - .value(PY_ENUM(SYMBOL_SECTION_INDEX::SHN_UNDEF)) - .value(PY_ENUM(SYMBOL_SECTION_INDEX::SHN_ABS)) - .value(PY_ENUM(SYMBOL_SECTION_INDEX::SHN_COMMON)) - .value(PY_ENUM(SYMBOL_SECTION_INDEX::SHN_HIRESERVE)); - - - enum_(m, "DYNAMIC_FLAGS", nb::is_arithmetic()) - .value(PY_ENUM(DYNAMIC_FLAGS::DF_ORIGIN)) - .value(PY_ENUM(DYNAMIC_FLAGS::DF_SYMBOLIC)) - .value(PY_ENUM(DYNAMIC_FLAGS::DF_TEXTREL)) - .value(PY_ENUM(DYNAMIC_FLAGS::DF_BIND_NOW)) - .value(PY_ENUM(DYNAMIC_FLAGS::DF_STATIC_TLS)); - - enum_(m, "DYNAMIC_FLAGS_1", nb::is_arithmetic()) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NOW)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_GLOBAL)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_GROUP)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NODELETE)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_LOADFLTR)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_INITFIRST)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NOOPEN)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_ORIGIN)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_DIRECT)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_TRANS)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_INTERPOSE)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NODEFLIB)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NODUMP)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_CONFALT)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_ENDFILTEE)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_DISPRELDNE)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_DISPRELPND)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NODIRECT)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_IGNMULDEF)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NOKSYMS)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NOHDR)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_EDITED)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_NORELOC)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_SYMINTPOSE)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_GLOBAUDIT)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_SINGLETON)) - .value(PY_ENUM(DYNAMIC_FLAGS_1::DF_1_PIE)); - - enum_(m, "SYMBOL_VISIBILITY") - .value(PY_ENUM(ELF_SYMBOL_VISIBILITY::STV_DEFAULT)) - .value(PY_ENUM(ELF_SYMBOL_VISIBILITY::STV_HIDDEN)) - .value(PY_ENUM(ELF_SYMBOL_VISIBILITY::STV_INTERNAL)) - .value(PY_ENUM(ELF_SYMBOL_VISIBILITY::STV_PROTECTED)); - + ENTRY(NONE) + ENTRY(M32) + ENTRY(SPARC) + ENTRY(I386) + ENTRY(M68K) + ENTRY(M88K) + ENTRY(IAMCU) + ENTRY(I860) + ENTRY(MIPS) + ENTRY(S370) + ENTRY(MIPS_RS3_LE) + ENTRY(PARISC) + ENTRY(VPP500) + ENTRY(SPARC32PLUS) + ENTRY(I60) + ENTRY(PPC) + ENTRY(PPC64) + ENTRY(S390) + ENTRY(SPU) + ENTRY(V800) + ENTRY(FR20) + ENTRY(RH32) + ENTRY(RCE) + ENTRY(ARM) + ENTRY(ALPHA) + ENTRY(SH) + ENTRY(SPARCV9) + ENTRY(TRICORE) + ENTRY(ARC) + ENTRY(H8_300) + ENTRY(H8_300H) + ENTRY(H8S) + ENTRY(H8_500) + ENTRY(IA_64) + ENTRY(MIPS_X) + ENTRY(COLDFIRE) + ENTRY(M68HC12) + ENTRY(MMA) + ENTRY(PCP) + ENTRY(NCPU) + ENTRY(NDR1) + ENTRY(STARCORE) + ENTRY(ME16) + ENTRY(ST100) + ENTRY(TINYJ) + ENTRY(X86_64) + ENTRY(PDSP) + ENTRY(PDP10) + ENTRY(PDP11) + ENTRY(FX66) + ENTRY(ST9PLUS) + ENTRY(ST7) + ENTRY(M68HC16) + ENTRY(M68HC11) + ENTRY(M68HC08) + ENTRY(M68HC05) + ENTRY(SVX) + ENTRY(ST19) + ENTRY(VAX) + ENTRY(CRIS) + ENTRY(JAVELIN) + ENTRY(FIREPATH) + ENTRY(ZSP) + ENTRY(MMIX) + ENTRY(HUANY) + ENTRY(PRISM) + ENTRY(AVR) + ENTRY(FR30) + ENTRY(D10V) + ENTRY(D30V) + ENTRY(V850) + ENTRY(M32R) + ENTRY(MN10300) + ENTRY(MN10200) + ENTRY(PJ) + ENTRY(OPENRISC) + ENTRY(ARC_COMPACT) + ENTRY(XTENSA) + ENTRY(VIDEOCORE) + ENTRY(TMM_GPP) + ENTRY(NS32K) + ENTRY(TPC) + ENTRY(SNP1K) + ENTRY(ST200) + ENTRY(IP2K) + ENTRY(MAX) + ENTRY(CR) + ENTRY(F2MC16) + ENTRY(MSP430) + ENTRY(BLACKFIN) + ENTRY(SE_C33) + ENTRY(SEP) + ENTRY(ARCA) + ENTRY(UNICORE) + ENTRY(EXCESS) + ENTRY(DXP) + ENTRY(ALTERA_NIOS2) + ENTRY(CRX) + ENTRY(XGATE) + ENTRY(C166) + ENTRY(M16C) + ENTRY(DSPIC30F) + ENTRY(CE) + ENTRY(M32C) + ENTRY(TSK3000) + ENTRY(RS08) + ENTRY(SHARC) + ENTRY(ECOG2) + ENTRY(SCORE7) + ENTRY(DSP24) + ENTRY(VIDEOCORE3) + ENTRY(LATTICEMICO32) + ENTRY(SE_C17) + ENTRY(TI_C6000) + ENTRY(TI_C2000) + ENTRY(TI_C5500) + ENTRY(MMDSP_PLUS) + ENTRY(CYPRESS_M8C) + ENTRY(R32C) + ENTRY(TRIMEDIA) + ENTRY(HEXAGON) + ENTRY(M8051) + ENTRY(STXP7X) + ENTRY(NDS32) + ENTRY(ECOG1) + ENTRY(ECOG1X) + ENTRY(MAXQ30) + ENTRY(XIMO16) + ENTRY(MANIK) + ENTRY(CRAYNV2) + ENTRY(RX) + ENTRY(METAG) + ENTRY(MCST_ELBRUS) + ENTRY(ECOG16) + ENTRY(CR16) + ENTRY(ETPU) + ENTRY(SLE9X) + ENTRY(L10M) + ENTRY(K10M) + ENTRY(AARCH64) + ENTRY(AVR32) + ENTRY(STM8) + ENTRY(TILE64) + ENTRY(TILEPRO) + ENTRY(CUDA) + ENTRY(TILEGX) + ENTRY(CLOUDSHIELD) + ENTRY(COREA_1ST) + ENTRY(COREA_2ND) + ENTRY(ARC_COMPACT2) + ENTRY(OPEN8) + ENTRY(RL78) + ENTRY(VIDEOCORE5) + ENTRY(M78KOR) + ENTRY(M56800EX) + ENTRY(BA1) + ENTRY(BA2) + ENTRY(XCORE) + ENTRY(MCHP_PIC) + ENTRY(INTEL205) + ENTRY(INTEL206) + ENTRY(INTEL207) + ENTRY(INTEL208) + ENTRY(INTEL209) + ENTRY(KM32) + ENTRY(KMX32) + ENTRY(KMX16) + ENTRY(KMX8) + ENTRY(KVARC) + ENTRY(CDP) + ENTRY(COGE) + ENTRY(COOL) + ENTRY(NORC) + ENTRY(CSR_KALIMBA) + ENTRY(AMDGPU) + ENTRY(RISCV) + ENTRY(BPF) + ENTRY(LOONGARCH) + ; + #undef ENTRY } } diff --git a/api/python/src/ELF/init.cpp b/api/python/src/ELF/init.cpp index e51c8540f2..f0a45df183 100644 --- a/api/python/src/ELF/init.cpp +++ b/api/python/src/ELF/init.cpp @@ -73,6 +73,7 @@ void init_objects(nb::module_& m) { CREATE(Parser, m); CREATE(SymbolVersion, m); CREATE(Binary, m); + CREATE(PROCESSOR_FLAGS, m); CREATE(Header, m); CREATE(Section, m); CREATE(Segment, m); diff --git a/api/python/src/ELF/objects/CMakeLists.txt b/api/python/src/ELF/objects/CMakeLists.txt index 032af23055..f2dd133501 100644 --- a/api/python/src/ELF/objects/CMakeLists.txt +++ b/api/python/src/ELF/objects/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(pyLIEF PRIVATE pyParserConfig.cpp pyNote.cpp pyRelocation.cpp + pyRelocationTypes.cpp pySection.cpp pySegment.cpp pySymbol.cpp diff --git a/api/python/src/ELF/objects/pyBinary.cpp b/api/python/src/ELF/objects/pyBinary.cpp index a33018d990..dd34852170 100644 --- a/api/python/src/ELF/objects/pyBinary.cpp +++ b/api/python/src/ELF/objects/pyBinary.cpp @@ -41,6 +41,7 @@ #include "LIEF/ELF/SymbolVersion.hpp" #include "LIEF/ELF/SymbolVersionDefinition.hpp" #include "LIEF/ELF/SymbolVersionRequirement.hpp" +#include "LIEF/ELF/SymbolVersionAuxRequirement.hpp" #include "LIEF/ELF/SysvHash.hpp" #include "pyIterator.hpp" @@ -322,10 +323,10 @@ void create(nb::module_& m) { nb::rv_policy::reference_internal) .def("get", - nb::overload_cast(&Binary::get), + nb::overload_cast(&Binary::get), R"delim( Return the first binary's :class:`~lief.ELF.DynamicEntry` from the given - :class:`~lief.ELF.DYNAMIC_TAGS`. + :class:`~lief.ELF.DynamicEntry.TAG`. It returns None if the dynamic entry can't be found. )delim"_doc, @@ -333,7 +334,7 @@ void create(nb::module_& m) { nb::rv_policy::reference_internal) .def("get", - nb::overload_cast(&Binary::get), + nb::overload_cast(&Binary::get), R"delim( Return the first binary's :class:`~lief.ELF.Segment` from the given :class:`~lief.ELF.SEGMENT_TYPES` @@ -355,7 +356,7 @@ void create(nb::module_& m) { nb::rv_policy::reference_internal) .def("get", - nb::overload_cast(&Binary::get), + nb::overload_cast(&Binary::get), R"delim( Return the first binary's :class:`~lief.ELF.Section` from the given :class:`~lief.ELF.ELF_SECTION_TYPES` @@ -366,15 +367,15 @@ void create(nb::module_& m) { nb::rv_policy::reference_internal) .def("has", - nb::overload_cast(&Binary::has, nb::const_), + nb::overload_cast(&Binary::has, nb::const_), R"delim( Check if it exists a :class:`~lief.ELF.DynamicEntry` with the given - :class:`~lief.ELF.DYNAMIC_TAGS` + :class:`~lief.ELF.DynamicEntry.TAG` )delim"_doc, "tag"_a) .def("has", - nb::overload_cast(&Binary::has, nb::const_), + nb::overload_cast(&Binary::has, nb::const_), "Check if a " RST_CLASS_REF(lief.ELF.Segment) " of *type* (" RST_CLASS_REF(lief.ELF.SEGMENT_TYPES) ") exists"_doc, "type"_a) @@ -384,7 +385,7 @@ void create(nb::module_& m) { "type"_a) .def("has", - nb::overload_cast(&Binary::has, nb::const_), + nb::overload_cast(&Binary::has, nb::const_), "Check if a " RST_CLASS_REF(lief.ELF.Section) " of *type* (" RST_CLASS_REF(lief.ELF.SECTION_TYPES) ") exists"_doc, "type"_a) @@ -500,8 +501,8 @@ void create(nb::module_& m) { "dynamic_entry"_a) .def("remove", - nb::overload_cast(&Binary::remove), - "Remove **all** the " RST_CLASS_REF(lief.ELF.DynamicEntry) " with the given " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) ""_doc, + nb::overload_cast(&Binary::remove), + "Remove **all** the " RST_CLASS_REF(lief.ELF.DynamicEntry) " with the given " RST_CLASS_REF(lief.ELF.DynamicEntry.TAG) ""_doc, "tag"_a) .def("remove", @@ -733,7 +734,7 @@ void create(nb::module_& m) { return &self; }, nb::rv_policy::reference_internal) .def(nb::self -= DynamicEntry(), nb::rv_policy::reference_internal) - .def(nb::self -= DYNAMIC_TAGS(), nb::rv_policy::reference_internal) + .def(nb::self -= DynamicEntry::TAG(), nb::rv_policy::reference_internal) .def("__isub__", [] (Binary& self, const Note& note) { self -= note; return &self; @@ -741,7 +742,7 @@ void create(nb::module_& m) { .def(nb::self -= Note::TYPE(), nb::rv_policy::reference_internal) .def("__getitem__", - nb::overload_cast(&Binary::operator[]), + nb::overload_cast(&Binary::operator[]), nb::rv_policy::reference_internal) .def("__getitem__", @@ -749,27 +750,27 @@ void create(nb::module_& m) { nb::rv_policy::reference_internal) .def("__getitem__", - nb::overload_cast(&Binary::operator[]), + nb::overload_cast(&Binary::operator[]), nb::rv_policy::reference_internal) .def("__getitem__", - nb::overload_cast(&Binary::operator[]), + nb::overload_cast(&Binary::operator[]), nb::rv_policy::reference_internal) .def("__contains__", - nb::overload_cast(&Binary::has, nb::const_), + nb::overload_cast(&Binary::has, nb::const_), "Check if a " RST_CLASS_REF(lief.ELF.Segment) " of *type* (" RST_CLASS_REF(lief.ELF.SEGMENT_TYPES) ") exists"_doc) .def("__contains__", - nb::overload_cast(&Binary::has, nb::const_), - "Check if the " RST_CLASS_REF(lief.ELF.DynamicEntry) " associated with the given " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " exists"_doc) + nb::overload_cast(&Binary::has, nb::const_), + "Check if the " RST_CLASS_REF(lief.ELF.DynamicEntry) " associated with the given " RST_CLASS_REF(lief.ELF.DynamicEntry.TAG) " exists"_doc) .def("__contains__", nb::overload_cast(&Binary::has, nb::const_), "Check if the " RST_CLASS_REF(lief.ELF.Note) " associated with the given " RST_CLASS_REF(lief.ELF.Note.TYPE) " exists"_doc) .def("__contains__", - nb::overload_cast(&Binary::has, nb::const_), + nb::overload_cast(&Binary::has, nb::const_), "Check if the " RST_CLASS_REF(lief.ELF.Section) " associated with the given " RST_CLASS_REF(lief.ELF.SECTION_TYPES) " exists"_doc) LIEF_DEFAULT_STR(Binary); diff --git a/api/python/src/ELF/objects/pyBuilder.cpp b/api/python/src/ELF/objects/pyBuilder.cpp index fc212141cb..cd9994f268 100644 --- a/api/python/src/ELF/objects/pyBuilder.cpp +++ b/api/python/src/ELF/objects/pyBuilder.cpp @@ -37,21 +37,21 @@ void create(nb::module_& m) { .def_rw("force_relocate", &Builder::config_t::force_relocate, "Force to relocate all the ELF structures that can be relocated (mostly for testing)"_doc) - .def_rw("dt_hash", &Builder::config_t::dt_hash, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.HASH`"_doc) - .def_rw("dyn_str", &Builder::config_t::dyn_str, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.STRTAB`"_doc) + .def_rw("dt_hash", &Builder::config_t::dt_hash, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.HASH`"_doc) + .def_rw("dyn_str", &Builder::config_t::dyn_str, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.STRTAB`"_doc) .def_rw("dynamic_section", &Builder::config_t::dynamic_section, "Rebuild the `PT_DYNAMIC` segment"_doc) - .def_rw("fini_array", &Builder::config_t::fini_array, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.FINI_ARRAY`"_doc) - .def_rw("init_array", &Builder::config_t::init_array, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.INIT_ARRAY`"_doc) + .def_rw("fini_array", &Builder::config_t::fini_array, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.FINI_ARRAY`"_doc) + .def_rw("init_array", &Builder::config_t::init_array, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.INIT_ARRAY`"_doc) .def_rw("interpreter", &Builder::config_t::interpreter, "Rebuild the `PT_INTERP` segment"_doc) - .def_rw("jmprel", &Builder::config_t::jmprel, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.JMPREL`"_doc) + .def_rw("jmprel", &Builder::config_t::jmprel, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.JMPREL`"_doc) .def_rw("notes", &Builder::config_t::notes, "Rebuild `PT_NOTES` segment(s)"_doc) - .def_rw("preinit_array", &Builder::config_t::preinit_array, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.PREINIT_ARRAY`"_doc) - .def_rw("rela", &Builder::config_t::rela, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.RELA`"_doc) + .def_rw("preinit_array", &Builder::config_t::preinit_array, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.PREINIT_ARRAY`"_doc) + .def_rw("rela", &Builder::config_t::rela, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.RELA`"_doc) .def_rw("static_symtab", &Builder::config_t::static_symtab, "Rebuild `.symtab` section"_doc) - .def_rw("sym_verdef", &Builder::config_t::sym_verdef, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.VERDEF`"_doc) - .def_rw("sym_verneed", &Builder::config_t::sym_verneed, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.VERNEED`"_doc) - .def_rw("sym_versym", &Builder::config_t::sym_versym, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.VERSYM`"_doc) - .def_rw("symtab", &Builder::config_t::symtab, "Rebuild :attr:`~lief.ELF.DYNAMIC_TAGS.SYMTAB`"_doc); + .def_rw("sym_verdef", &Builder::config_t::sym_verdef, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.VERDEF`"_doc) + .def_rw("sym_verneed", &Builder::config_t::sym_verneed, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.VERNEED`"_doc) + .def_rw("sym_versym", &Builder::config_t::sym_versym, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.VERSYM`"_doc) + .def_rw("symtab", &Builder::config_t::symtab, "Rebuild :attr:`~lief.ELF.DynamicEntry.TAG.SYMTAB`"_doc); builder .def(nb::init(), diff --git a/api/python/src/ELF/objects/pyDynamicEntry.cpp b/api/python/src/ELF/objects/pyDynamicEntry.cpp index 1b03d91584..8fb7de5b0b 100644 --- a/api/python/src/ELF/objects/pyDynamicEntry.cpp +++ b/api/python/src/ELF/objects/pyDynamicEntry.cpp @@ -18,6 +18,7 @@ #include #include "ELF/pyELF.hpp" +#include "enums_wrapper.hpp" #include "LIEF/ELF/DynamicEntry.hpp" @@ -25,22 +26,154 @@ namespace LIEF::ELF::py { template<> void create(nb::module_& m) { - nb::class_(m, "DynamicEntry", + nb::class_ entry(m, "DynamicEntry", R"delim( Class which represents an entry in the dynamic table These entries are located in the ``.dynamic`` section or the ``PT_DYNAMIC`` segment - )delim"_doc) + )delim"_doc); + + #define ENTRY(X) .value(to_string(DynamicEntry::TAG::X), DynamicEntry::TAG::X) + enum_(entry, "TAG") + ENTRY(UNKNOWN) + .value("NULL", DynamicEntry::TAG::DT_NULL) + ENTRY(NEEDED) + ENTRY(PLTRELSZ) + ENTRY(PLTGOT) + ENTRY(HASH) + ENTRY(STRTAB) + ENTRY(SYMTAB) + ENTRY(RELA) + ENTRY(RELASZ) + ENTRY(RELAENT) + ENTRY(STRSZ) + ENTRY(SYMENT) + ENTRY(INIT) + ENTRY(FINI) + ENTRY(SONAME) + ENTRY(RPATH) + ENTRY(SYMBOLIC) + ENTRY(REL) + ENTRY(RELSZ) + ENTRY(RELENT) + ENTRY(PLTREL) + ENTRY(DEBUG) + ENTRY(TEXTREL) + ENTRY(JMPREL) + ENTRY(BIND_NOW) + ENTRY(INIT_ARRAY) + ENTRY(FINI_ARRAY) + ENTRY(INIT_ARRAYSZ) + ENTRY(FINI_ARRAYSZ) + ENTRY(RUNPATH) + ENTRY(FLAGS) + ENTRY(PREINIT_ARRAY) + ENTRY(PREINIT_ARRAYSZ) + ENTRY(SYMTAB_SHNDX) + ENTRY(RELRSZ) + ENTRY(RELR) + ENTRY(RELRENT) + ENTRY(GNU_HASH) + ENTRY(RELACOUNT) + ENTRY(RELCOUNT) + ENTRY(FLAGS_1) + ENTRY(VERSYM) + ENTRY(VERDEF) + ENTRY(VERDEFNUM) + ENTRY(VERNEED) + ENTRY(VERNEEDNUM) + ENTRY(ANDROID_REL_OFFSET) + ENTRY(ANDROID_REL_SIZE) + ENTRY(ANDROID_REL) + ENTRY(ANDROID_RELSZ) + ENTRY(ANDROID_RELA) + ENTRY(ANDROID_RELASZ) + ENTRY(ANDROID_RELR) + ENTRY(ANDROID_RELRSZ) + ENTRY(ANDROID_RELRENT) + ENTRY(ANDROID_RELRCOUNT) + ENTRY(MIPS_RLD_VERSION) + ENTRY(MIPS_TIME_STAMP) + ENTRY(MIPS_ICHECKSUM) + ENTRY(MIPS_IVERSION) + ENTRY(MIPS_FLAGS) + ENTRY(MIPS_BASE_ADDRESS) + ENTRY(MIPS_MSYM) + ENTRY(MIPS_CONFLICT) + ENTRY(MIPS_LIBLIST) + ENTRY(MIPS_LOCAL_GOTNO) + ENTRY(MIPS_CONFLICTNO) + ENTRY(MIPS_LIBLISTNO) + ENTRY(MIPS_SYMTABNO) + ENTRY(MIPS_UNREFEXTNO) + ENTRY(MIPS_GOTSYM) + ENTRY(MIPS_HIPAGENO) + ENTRY(MIPS_RLD_MAP) + ENTRY(MIPS_DELTA_CLASS) + ENTRY(MIPS_DELTA_CLASS_NO) + ENTRY(MIPS_DELTA_INSTANCE) + ENTRY(MIPS_DELTA_INSTANCE_NO) + ENTRY(MIPS_DELTA_RELOC) + ENTRY(MIPS_DELTA_RELOC_NO) + ENTRY(MIPS_DELTA_SYM) + ENTRY(MIPS_DELTA_SYM_NO) + ENTRY(MIPS_DELTA_CLASSSYM) + ENTRY(MIPS_DELTA_CLASSSYM_NO) + ENTRY(MIPS_CXX_FLAGS) + ENTRY(MIPS_PIXIE_INIT) + ENTRY(MIPS_SYMBOL_LIB) + ENTRY(MIPS_LOCALPAGE_GOTIDX) + ENTRY(MIPS_LOCAL_GOTIDX) + ENTRY(MIPS_HIDDEN_GOTIDX) + ENTRY(MIPS_PROTECTED_GOTIDX) + ENTRY(MIPS_OPTIONS) + ENTRY(MIPS_INTERFACE) + ENTRY(MIPS_DYNSTR_ALIGN) + ENTRY(MIPS_INTERFACE_SIZE) + ENTRY(MIPS_RLD_TEXT_RESOLVE_ADDR) + ENTRY(MIPS_PERF_SUFFIX) + ENTRY(MIPS_COMPACT_SIZE) + ENTRY(MIPS_GP_VALUE) + ENTRY(MIPS_AUX_DYNAMIC) + ENTRY(MIPS_PLTGOT) + ENTRY(MIPS_RWPLT) + ENTRY(MIPS_RLD_MAP_REL) + ENTRY(MIPS_XHASH) + + ENTRY(AARCH64_BTI_PLT) + ENTRY(AARCH64_PAC_PLT) + ENTRY(AARCH64_VARIANT_PCS) + ENTRY(AARCH64_MEMTAG_MODE) + ENTRY(AARCH64_MEMTAG_HEAP) + ENTRY(AARCH64_MEMTAG_STACK) + ENTRY(AARCH64_MEMTAG_GLOBALS) + ENTRY(AARCH64_MEMTAG_GLOBALSSZ) + + ENTRY(HEXAGON_SYMSZ) + ENTRY(HEXAGON_VER) + ENTRY(HEXAGON_PLT) + + ENTRY(PPC_GOT) + ENTRY(PPC_OPT) + + ENTRY(PPC64_GLINK) + ENTRY(PPC64_OPT) + + ENTRY(RISCV_VARIANT_CC) + ; + #undef ENTRY + + entry .def(nb::init<>(), "Default constructor"_doc) - .def(nb::init(), - "Constructor from a " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " and value"_doc, + .def(nb::init(), + "Constructor from a " RST_CLASS_REF(lief.ELF.DynamicEntry.TAG) " and value"_doc, "tag"_a, "value"_a) .def_prop_rw("tag", nb::overload_cast<>(&DynamicEntry::tag, nb::const_), - nb::overload_cast(&DynamicEntry::tag), - "Return the entry's " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " which represent the entry type"_doc) + nb::overload_cast(&DynamicEntry::tag), + "Return the entry's " RST_CLASS_REF(lief.ELF.DynamicEntry.TAG) " which represent the entry type"_doc) .def_prop_rw("value", nb::overload_cast<>(&DynamicEntry::value, nb::const_), diff --git a/api/python/src/ELF/objects/pyDynamicEntryArray.cpp b/api/python/src/ELF/objects/pyDynamicEntryArray.cpp index 625c406523..4a633b4704 100644 --- a/api/python/src/ELF/objects/pyDynamicEntryArray.cpp +++ b/api/python/src/ELF/objects/pyDynamicEntryArray.cpp @@ -40,11 +40,9 @@ void create(nb::module_& m) { The underlying values are 64-bits integers to cover both: ELF32 and ELF64 binaries. )delim"_doc) - .def(nb::init<>()) - .def(nb::init(), - "Constructor with " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " and value"_doc, - "tag"_a, "value"_a) + .def(nb::init(), + "tag"_a, "array"_a) .def_prop_rw("array", nb::overload_cast<>(&DynamicEntryArray::array, nb::const_), @@ -70,7 +68,6 @@ void create(nb::module_& m) { "function"_a, nb::rv_policy::reference_internal) - .def(nb::self += uint64_t()) .def(nb::self -= uint64_t()) diff --git a/api/python/src/ELF/objects/pyDynamicEntryFlags.cpp b/api/python/src/ELF/objects/pyDynamicEntryFlags.cpp index 0b6e1dc9ad..25bc0e628c 100644 --- a/api/python/src/ELF/objects/pyDynamicEntryFlags.cpp +++ b/api/python/src/ELF/objects/pyDynamicEntryFlags.cpp @@ -18,9 +18,10 @@ #include #include -#include +#include #include "ELF/pyELF.hpp" +#include "enums_wrapper.hpp" #include "LIEF/ELF/DynamicEntryFlags.hpp" #include "LIEF/ELF/DynamicEntry.hpp" @@ -29,61 +30,76 @@ namespace LIEF::ELF::py { template<> void create(nb::module_& m) { - nb::class_(m, "DynamicEntryFlags") - .def(nb::init<>()) - - .def(nb::init(), - "Constructor with " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " and value"_doc, - "tag"_a, "value"_a) - + nb::class_ entry(m, "DynamicEntryFlags"); + + #define ENTRY(X) .value(to_string(DynamicEntryFlags::FLAG::X), DynamicEntryFlags::FLAG::X) + enum_(entry, "FLAG") + ENTRY(ORIGIN) + ENTRY(SYMBOLIC) + ENTRY(TEXTREL) + ENTRY(BIND_NOW) + ENTRY(STATIC_TLS) + ENTRY(NOW) + ENTRY(GLOBAL) + ENTRY(GROUP) + ENTRY(NODELETE) + ENTRY(LOADFLTR) + ENTRY(INITFIRST) + ENTRY(NOOPEN) + ENTRY(HANDLE_ORIGIN) + ENTRY(DIRECT) + ENTRY(TRANS) + ENTRY(INTERPOSE) + ENTRY(NODEFLIB) + ENTRY(NODUMP) + ENTRY(CONFALT) + ENTRY(ENDFILTEE) + ENTRY(DISPRELDNE) + ENTRY(DISPRELPND) + ENTRY(NODIRECT) + ENTRY(IGNMULDEF) + ENTRY(NOKSYMS) + ENTRY(NOHDR) + ENTRY(EDITED) + ENTRY(NORELOC) + ENTRY(SYMINTPOSE) + ENTRY(GLOBAUDIT) + ENTRY(SINGLETON) + ENTRY(PIE) + ENTRY(KMOD) + ENTRY(WEAKFILTER) + ENTRY(NOCOMMON) + ; + #undef ENTRY + + entry .def_prop_ro("flags", &DynamicEntryFlags::flags, - "Return list of " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS) " or " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS_1) " (integer)"_doc, + "Return list of :class:`~.FLAG`"_doc, nb::rv_policy::move) .def("has", - nb::overload_cast(&DynamicEntryFlags::has, nb::const_), - "Check if this entry contains the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS) ""_doc, + nb::overload_cast(&DynamicEntryFlags::has, nb::const_), + "Check if this entry contains the given :class:`~.FLAG`"_doc, "flag"_a) - .def("has", - nb::overload_cast(&DynamicEntryFlags::has, nb::const_), - "Check if this entry contains the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS_1) ""_doc, - "flag"_a) - - .def("add", - nb::overload_cast(&DynamicEntryFlags::add), - "Add the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS) ""_doc, - "flag"_a) .def("add", - nb::overload_cast(&DynamicEntryFlags::add), - "Add the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS_1) ""_doc, + nb::overload_cast(&DynamicEntryFlags::add), + "Add the given :class:`~.FLAG`"_doc, "flag"_a) .def("remove", - nb::overload_cast(&DynamicEntryFlags::remove), - "Remove the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS) ""_doc, + nb::overload_cast(&DynamicEntryFlags::remove), + "Remove the given :class:`~.FLAG`"_doc, "flag"_a) - .def("remove", - nb::overload_cast(&DynamicEntryFlags::remove), - "Remove the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS_1) ""_doc, - "flag"_a) - - .def(nb::self += DYNAMIC_FLAGS()) - .def(nb::self += DYNAMIC_FLAGS_1()) - - .def(nb::self -= DYNAMIC_FLAGS()) - .def(nb::self -= DYNAMIC_FLAGS_1()) - - .def("__contains__", - nb::overload_cast(&DynamicEntryFlags::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS) " is present"_doc) + .def(nb::self += DynamicEntryFlags::FLAG()) + .def(nb::self -= DynamicEntryFlags::FLAG()) .def("__contains__", - nb::overload_cast(&DynamicEntryFlags::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.DYNAMIC_FLAGS_1) " is present"_doc) + nb::overload_cast(&DynamicEntryFlags::has, nb::const_), + "Check if the given :class:`~.FLAG` is present"_doc) LIEF_DEFAULT_STR(DynamicEntryFlags); } diff --git a/api/python/src/ELF/objects/pyDynamicEntryLibrary.cpp b/api/python/src/ELF/objects/pyDynamicEntryLibrary.cpp index 7ccc616b72..2bb80fd7c9 100644 --- a/api/python/src/ELF/objects/pyDynamicEntryLibrary.cpp +++ b/api/python/src/ELF/objects/pyDynamicEntryLibrary.cpp @@ -42,7 +42,7 @@ void create(nb::module_& m) { [] (const DynamicEntryLibrary& obj) { return LIEF::py::safe_string(obj.name()); }, - nb::overload_cast(&DynamicEntryLibrary::name), + nb::overload_cast(&DynamicEntryLibrary::name), "Library associated with this entry (e.g. ``libc.so.6``)"_doc) LIEF_DEFAULT_STR(DynamicEntryLibrary); diff --git a/api/python/src/ELF/objects/pyDynamicEntryRpath.cpp b/api/python/src/ELF/objects/pyDynamicEntryRpath.cpp index 891438a888..dae824a49a 100644 --- a/api/python/src/ELF/objects/pyDynamicEntryRpath.cpp +++ b/api/python/src/ELF/objects/pyDynamicEntryRpath.cpp @@ -44,13 +44,6 @@ void create(nb::module_& m) { "Constructor from a list of paths"_doc, "paths"_a) - .def_prop_rw("name", - [] (const DynamicEntryRpath& obj) { - return LIEF::py::safe_string(obj.name()); - }, - nb::overload_cast(&DynamicEntryRpath::name), - "The actual rpath as a string"_doc) - .def_prop_rw("rpath", [] (const DynamicEntryRpath& obj) { return LIEF::py::safe_string(obj.rpath()); @@ -63,20 +56,17 @@ void create(nb::module_& m) { nb::overload_cast&>(&DynamicEntryRpath::paths), "Paths as a list"_doc) - .def("insert", - &DynamicEntryRpath::insert, + .def("insert", &DynamicEntryRpath::insert, "Insert a ``path`` at the given ``position``"_doc, "position"_a, "path"_a, nb::rv_policy::reference_internal) - .def("append", - &DynamicEntryRpath::append, + .def("append", &DynamicEntryRpath::append, "Append the given ``path`` "_doc, "path"_a, nb::rv_policy::reference_internal) - .def("remove", - &DynamicEntryRpath::remove, + .def("remove", &DynamicEntryRpath::remove, "Remove the given ``path`` "_doc, "path"_a, nb::rv_policy::reference_internal) diff --git a/api/python/src/ELF/objects/pyDynamicEntryRunPath.cpp b/api/python/src/ELF/objects/pyDynamicEntryRunPath.cpp index 63c6c1496c..343bbff971 100644 --- a/api/python/src/ELF/objects/pyDynamicEntryRunPath.cpp +++ b/api/python/src/ELF/objects/pyDynamicEntryRunPath.cpp @@ -44,18 +44,11 @@ void create(nb::module_& m) { "Constructor from a list of paths"_doc, "paths"_a) - .def_prop_rw("name", - [] (const DynamicEntryRunPath& obj) { - return LIEF::py::safe_string(obj.name()); - }, - nb::overload_cast(&DynamicEntryRunPath::name), - "Runpath raw value"_doc) - .def_prop_rw("runpath", [] (const DynamicEntryRunPath& obj) { return LIEF::py::safe_string(obj.runpath()); }, - nb::overload_cast(&DynamicEntryRunPath::runpath), + nb::overload_cast(&DynamicEntryRunPath::runpath), "Runpath raw value"_doc) .def_prop_rw("paths", @@ -63,20 +56,16 @@ void create(nb::module_& m) { nb::overload_cast&>(&DynamicEntryRunPath::paths), "Paths as a list"_doc) - .def("insert", - &DynamicEntryRunPath::insert, + .def("insert", &DynamicEntryRunPath::insert, "Insert a ``path`` at the given ``position``"_doc, "position"_a, "path"_a, nb::rv_policy::reference_internal) - .def("append", - &DynamicEntryRunPath::append, + .def("append", &DynamicEntryRunPath::append, "Append the given ``path`` "_doc, "path"_a, nb::rv_policy::reference_internal) - - .def("remove", - &DynamicEntryRunPath::remove, + .def("remove", &DynamicEntryRunPath::remove, "Remove the given ``path`` ", "path"_a, nb::rv_policy::reference_internal) diff --git a/api/python/src/ELF/objects/pyDynamicSharedObject.cpp b/api/python/src/ELF/objects/pyDynamicSharedObject.cpp index 437af6320b..8ee433d923 100644 --- a/api/python/src/ELF/objects/pyDynamicSharedObject.cpp +++ b/api/python/src/ELF/objects/pyDynamicSharedObject.cpp @@ -43,7 +43,7 @@ void create(nb::module_& m) { [] (const DynamicSharedObject& obj) { return LIEF::py::safe_string(obj.name()); }, - nb::overload_cast(&DynamicSharedObject::name), + nb::overload_cast(&DynamicSharedObject::name), "Return the library name"_doc) LIEF_DEFAULT_STR(DynamicSharedObject); diff --git a/api/python/src/ELF/objects/pyHeader.cpp b/api/python/src/ELF/objects/pyHeader.cpp index 6fc09c3b32..f2ab5392b8 100644 --- a/api/python/src/ELF/objects/pyHeader.cpp +++ b/api/python/src/ELF/objects/pyHeader.cpp @@ -18,9 +18,11 @@ #include #include +#include #include #include "ELF/pyELF.hpp" +#include "enums_wrapper.hpp" #include "LIEF/ELF/Header.hpp" @@ -29,36 +31,115 @@ namespace LIEF::ELF::py { template<> void create
(nb::module_& m) { - nb::class_(m, "Header", + nb::class_ header(m, "Header", R"delim( - Class which represents the ELF's header. This is the ELF structure - that starts an ELF file. - )delim"_doc) + Class which represents the ELF's header. This class mirrors the raw ELF + ``Elfxx_Ehdr`` structure. + )delim"_doc); + + #define ENTRY(X, D) .value(to_string(Header::FILE_TYPE::X), Header::FILE_TYPE::X, D) + enum_(header, "FILE_TYPE", + R"delim( + The type of the underlying ELF file. This enum matches the semantic of + ``ET_NONE``, ``ET_REL``, ... + )delim"_doc + ) + ENTRY(NONE, "Can't be determined/Invalid"_doc) + ENTRY(REL, "Relocatable file (or object file)"_doc) + ENTRY(EXEC, "non-pie executable"_doc) + ENTRY(DYN, "Shared library **or** a pie-executable"_doc) + ENTRY(CORE, "Core dump file"_doc) + ; + #undef ENTRY + + #define ENTRY(X, D) .value(to_string(Header::VERSION::X), Header::VERSION::X, D) + enum_(header, "VERSION", + R"delim( + Match the result of ``Elfxx_Ehdr.e_version`` + )delim"_doc + ) + ENTRY(NONE, "Invalid ELF version"_doc) + ENTRY(CURRENT, "Current version (default)"_doc) + ; + #undef ENTRY + + #define ENTRY(X, D) .value(to_string(Header::CLASS::X), Header::CLASS::X, D) + enum_(header, "CLASS", + R"delim( + Match the result of ``Elfxx_Ehdr.e_ident[EI_CLASS]`` + )delim"_doc + ) + ENTRY(NONE, "Invalid class"_doc) + ENTRY(ELF32, "32-bit objects"_doc) + ENTRY(ELF64, "64-bit objects"_doc) + ; + #undef ENTRY + + #define ENTRY(X) .value(to_string(Header::OS_ABI::X), Header::OS_ABI::X) + enum_(header, "OS_ABI") + ENTRY(SYSTEMV) + ENTRY(HPUX) + ENTRY(NETBSD) + ENTRY(GNU) + ENTRY(LINUX) + ENTRY(HURD) + ENTRY(SOLARIS) + ENTRY(AIX) + ENTRY(IRIX) + ENTRY(FREEBSD) + ENTRY(TRU64) + ENTRY(MODESTO) + ENTRY(OPENBSD) + ENTRY(OPENVMS) + ENTRY(NSK) + ENTRY(AROS) + ENTRY(FENIXOS) + ENTRY(CLOUDABI) + ENTRY(C6000_ELFABI) + ENTRY(AMDGPU_HSA) + ENTRY(C6000_LINUX) + ENTRY(ARM) + ENTRY(STANDALONE) + ; + #undef ENTRY + + #define ENTRY(X, D) .value(to_string(Header::ELF_DATA::X), Header::ELF_DATA::X, D) + enum_(header, "ELF_DATA", + R"delim( + Match the result ``Elfxx_Ehdr.e_ident[EI_DATA]`` + )delim"_doc + ) + ENTRY(NONE, "Invalid data encoding"_doc) + ENTRY(LSB, "2's complement, little endian"_doc) + ENTRY(MSB, "2's complement, big endian"_doc) + ; + #undef ENTRY + + header .def(nb::init<>()) .def_prop_rw("identity_class", nb::overload_cast<>(&Header::identity_class, nb::const_), - nb::overload_cast(&Header::identity_class), - "Header's " RST_CLASS_REF(lief.ELF.ELF_CLASS) "."_doc) + nb::overload_cast(&Header::identity_class), + "Header's class."_doc) .def_prop_rw("identity_data", nb::overload_cast<>(&Header::identity_data, nb::const_), - nb::overload_cast(&Header::identity_data), - "Specify the data encoding (" RST_CLASS_REF(lief.ELF.ELF_DATA) ")"_doc) + nb::overload_cast(&Header::identity_data), + "Specify the data encoding"_doc) .def_prop_rw("identity_version", nb::overload_cast<>(&Header::identity_version, nb::const_), - nb::overload_cast(&Header::identity_version), - "Return header's " RST_CLASS_REF(lief.ELF.VERSION) "."_doc) + nb::overload_cast(&Header::identity_version)) .def_prop_rw("identity_os_abi", nb::overload_cast<>(&Header::identity_os_abi, nb::const_), - nb::overload_cast(&Header::identity_os_abi), - "Identifies the version of the ABI for which the object is prepared (" RST_CLASS_REF(lief.ELF.OS_ABI) ")."_doc) + nb::overload_cast(&Header::identity_os_abi), + "Identifies the version of the ABI for which the object is prepared."_doc) .def_prop_rw("identity_abi_version", nb::overload_cast<>(&Header::identity_abi_version, nb::const_), - nb::overload_cast(&Header::identity_abi_version), + nb::overload_cast(&Header::identity_abi_version), "Return the ABI version (integer)."_doc) .def_prop_rw("identity", @@ -89,19 +170,19 @@ void create
(nb::module_& m) { .def_prop_rw("file_type", nb::overload_cast<>(&Header::file_type, nb::const_), - nb::overload_cast(&Header::file_type), - "Return binary's " RST_CLASS_REF(lief.ELF.E_TYPE) ". This field determines if the binary \ - is a executable, a library..."_doc) + nb::overload_cast(&Header::file_type), + "Return binary's type. This field determines if the binary is a " + "executable, a library..."_doc) .def_prop_rw("machine_type", nb::overload_cast<>(&Header::machine_type, nb::const_), nb::overload_cast(&Header::machine_type), - "Return the target architecture (" RST_CLASS_REF(lief.ELF.ARCH) ")"_doc) + "Return the target architecture"_doc) .def_prop_rw("object_file_version", nb::overload_cast<>(&Header::object_file_version, nb::const_), - nb::overload_cast(&Header::object_file_version), - "Return the " RST_CLASS_REF(lief.ELF.VERSION) ""_doc) + nb::overload_cast(&Header::object_file_version), + "Return the version"_doc) .def_prop_rw("entrypoint", nb::overload_cast<>(&Header::entrypoint, nb::const_), @@ -123,42 +204,17 @@ void create
(nb::module_& m) { nb::overload_cast(&Header::processor_flag), "Processor-specific flags"_doc) - .def_prop_ro("arm_flags_list", - &Header::arm_flags_list, - "Return a list of " RST_CLASS_REF(lief.ELF.ARM_EFLAGS) " present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc, - nb::rv_policy::reference_internal) - - .def_prop_ro("mips_flags_list", - &Header::mips_flags_list, - "Return a list of " RST_CLASS_REF(lief.ELF.MIPS_EFLAGS) " present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc, - nb::rv_policy::reference_internal) - - .def_prop_ro("ppc64_flags_list", - &Header::ppc64_flags_list, - "Return a list of " RST_CLASS_REF(lief.ELF.PPC64_EFLAGS) " present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc, - nb::rv_policy::reference_internal) - - .def_prop_ro("hexagon_flags_list", - &Header::hexagon_flags_list, - "Return a list of " RST_CLASS_REF(lief.ELF.HEXAGON_EFLAGS) " present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc, - nb::rv_policy::reference_internal) - - .def_prop_ro("loongarch_flags_list", - &Header::loongarch_flags_list, - "Return a list of " RST_CLASS_REF(lief.ELF.LOONGARCH_EFLAGS) " present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc, - nb::rv_policy::reference_internal) + .def("has", &Header::has, + "Check if the given processor flag is present"_doc) + + .def_prop_ro("flags_list", &Header::flags_list, + "Processor flags as a list"_doc) .def_prop_rw("header_size", nb::overload_cast<>(&Header::header_size, nb::const_), nb::overload_cast(&Header::header_size), R"delim( Return the size of the ELF header - This size should be 64 for an ``ELF64`` binary and 52 for an ``ELF32``. )delim"_doc) @@ -166,9 +222,8 @@ void create
(nb::module_& m) { nb::overload_cast<>(&Header::program_header_size, nb::const_), nb::overload_cast(&Header::program_header_size), R"delim( - Return the size of a Segment header (:class:`lief.ELF.Segment`) - - This size should be 56 for a ``ELF64`` binary and 32 for an ``ELF32``. + Return the size of the raw ``Elfxx_Phdr`` structure (see :class:`lief.ELF.Segment`) + This size should be 56 for an ``ELF64`` binary and 32 for an ``ELF32``. )delim"_doc) .def_prop_rw("numberof_segments", @@ -180,9 +235,9 @@ void create
(nb::module_& m) { nb::overload_cast<>(&Header::section_header_size, nb::const_), nb::overload_cast(&Header::section_header_size), R"delim( - Return the size of a Section header (:class:`lief.ELF.Section`) + Return the size of the raw ``Elfxx_Shdr`` (:class:`lief.ELF.Section`) - This size should be 64 for a ``ELF64`` binary and 40 for an ``ELF32``. + This size should be 64 for an ``ELF64`` binary and 40 for an ``ELF32``. )delim"_doc) .def_prop_rw("numberof_sections", @@ -195,34 +250,6 @@ void create
(nb::module_& m) { nb::overload_cast(&Header::section_name_table_idx), "Return the section index which contains sections' names"_doc) - .def("__contains__", - nb::overload_cast(&Header::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.ARM_EFLAGS) " is present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc) - - - .def("__contains__", - nb::overload_cast(&Header::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.MIPS_EFLAGS) " is present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc) - - - .def("__contains__", - nb::overload_cast(&Header::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.PPC64_EFLAGS) " is present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc) - - - .def("__contains__", - nb::overload_cast(&Header::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.HEXAGON_EFLAGS) " is present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc) - - .def("__contains__", - nb::overload_cast(&Header::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.LOONGARCH_EFLAGS) " is present in " - ":attr:`~lief.ELF.Header.processor_flag`"_doc) - LIEF_DEFAULT_STR(Header); } diff --git a/api/python/src/ELF/objects/pyNote.cpp b/api/python/src/ELF/objects/pyNote.cpp index 80234b4af0..12704252b0 100644 --- a/api/python/src/ELF/objects/pyNote.cpp +++ b/api/python/src/ELF/objects/pyNote.cpp @@ -87,8 +87,8 @@ void create(nb::module_& m) { ; #undef ENTRY - const auto create_overload_0 = nb::overload_cast(&Note::create); - const auto create_overload_1 = nb::overload_cast(&Note::create); + const auto create_overload_0 = nb::overload_cast(&Note::create); + const auto create_overload_1 = nb::overload_cast(&Note::create); note .def_static("create", create_overload_0, R"doc( @@ -98,10 +98,10 @@ void create(nb::module_& m) { Depending on the note, the filetype, the architecture and the ELF class might be needed. )doc"_doc, "name"_a, "original_type"_a, "description"_a, - "file_type"_a = E_TYPE::ET_NONE, "arch"_a = ARCH::EM_NONE, "cls"_a = ELF_CLASS::ELFCLASSNONE) + "file_type"_a = Header::FILE_TYPE::NONE, "arch"_a = ARCH::NONE, "cls"_a = Header::CLASS::NONE) .def_static("create", - [] (nb::bytes bytes, E_TYPE ftype, ARCH arch, ELF_CLASS cls) -> std::unique_ptr { + [] (nb::bytes bytes, Header::FILE_TYPE ftype, ARCH arch, Header::CLASS cls) -> std::unique_ptr { std::unique_ptr stream = to_stream(bytes); if (!stream) { return nullptr; @@ -115,8 +115,8 @@ void create(nb::module_& m) { be needed. )doc"_doc, "raw"_a, - "file_type"_a = E_TYPE::ET_NONE, "arch"_a = ARCH::EM_NONE, - "cls"_a = ELF_CLASS::ELFCLASSNONE) + "file_type"_a = Header::FILE_TYPE::NONE, "arch"_a = ARCH::NONE, + "cls"_a = Header::CLASS::NONE) .def_static("create", create_overload_1, R"doc( @@ -126,7 +126,7 @@ void create(nb::module_& m) { be needed. )doc"_doc, "name"_a, "type"_a, "description"_a, - "arch"_a = ARCH::EM_NONE, "cls"_a = ELF_CLASS::ELFCLASSNONE) + "arch"_a = ARCH::NONE, "cls"_a = Header::CLASS::NONE) .def_prop_rw("name", nb::overload_cast<>(&Note::name, nb::const_), diff --git a/api/python/src/ELF/objects/pyParserConfig.cpp b/api/python/src/ELF/objects/pyParserConfig.cpp index 9510d5b5ec..2c896821aa 100644 --- a/api/python/src/ELF/objects/pyParserConfig.cpp +++ b/api/python/src/ELF/objects/pyParserConfig.cpp @@ -16,16 +16,25 @@ #include "ELF/pyELF.hpp" #include "LIEF/ELF/ParserConfig.hpp" +#include "enums_wrapper.hpp" + namespace LIEF::ELF::py { template<> void create(nb::module_& m) { - nb::class_(m, "ParserConfig", + nb::class_ pconfig(m, "ParserConfig", R"delim( This class is used to tweak the ELF Parser - )delim"_doc) + )delim"_doc); + + enum_(pconfig, "DYNSYM_COUNT") + .value("AUTO", ParserConfig::DYNSYM_COUNT::AUTO) + .value("SECTION", ParserConfig::DYNSYM_COUNT::SECTION) + .value("HASH", ParserConfig::DYNSYM_COUNT::HASH) + .value("RELOCATIONS", ParserConfig::DYNSYM_COUNT::RELOCATIONS); + pconfig .def(nb::init<>()) .def_rw("parse_relocations", &ParserConfig::parse_relocations, "Whether relocations (including plt-like relocations) should be parsed."_doc) diff --git a/api/python/src/ELF/objects/pyRelocation.cpp b/api/python/src/ELF/objects/pyRelocation.cpp index 73fd48d141..33a32b9f5c 100644 --- a/api/python/src/ELF/objects/pyRelocation.cpp +++ b/api/python/src/ELF/objects/pyRelocation.cpp @@ -18,6 +18,7 @@ #include #include "ELF/pyELF.hpp" +#include "enums_wrapper.hpp" #include "LIEF/ELF/Relocation.hpp" #include "LIEF/ELF/Symbol.hpp" @@ -25,19 +26,28 @@ namespace LIEF::ELF::py { +void init_relocation_types(nb::class_& m); + template<> void create(nb::module_& m) { - - // Relocation object - nb::class_(m, "Relocation", + nb::class_ reloc(m, "Relocation", R"delim( Class that represents an ELF relocation. - )delim"_doc) + )delim"_doc); + + init_relocation_types(reloc); + + enum_(reloc, "PURPOSE") + .value("NONE", Relocation::PURPOSE::NONE) + .value("PLTGOT", Relocation::PURPOSE::PLTGOT) + .value("DYNAMIC", Relocation::PURPOSE::DYNAMIC) + .value("OBJECT", Relocation::PURPOSE::OBJECT); + reloc .def(nb::init<>()) .def(nb::init(), "arch"_a) - .def(nb::init(), - "address"_a, "type"_a = 0, "addend"_a = 0, "is_rela"_a = false) + .def(nb::init(), + "address"_a, "type"_a = Relocation::TYPE::UNKNOWN, "is_rela"_a = false) .def_prop_rw("addend", nb::overload_cast<>(&Relocation::addend, nb::const_), @@ -51,25 +61,16 @@ void create(nb::module_& m) { .def_prop_rw("purpose", nb::overload_cast<>(&Relocation::purpose, nb::const_), - nb::overload_cast(&Relocation::purpose), + nb::overload_cast(&Relocation::purpose), R"delim( - Purpose of the relocation (:class:`~lief.ELF.RELOCATION_PURPOSES`). - + Purpose of the relocation. This value provides the information about how the relocation is used (PLT/GOT resolution, ``.o`` file, ...) )delim"_doc) .def_prop_rw("type", nb::overload_cast<>(&Relocation::type, nb::const_), - nb::overload_cast(&Relocation::type), - R"delim( - Relocation type. This value depends on the underlying architecture. - - See: - * :class:`~lief.ELF.RELOCATION_X86_64` - * :class:`~lief.ELF.RELOCATION_i386` - * :class:`~lief.ELF.RELOCATION_AARCH64` - * :class:`~lief.ELF.RELOCATION_ARM` - )delim"_doc) + nb::overload_cast(&Relocation::type), + R"delim(Relocation type.)delim"_doc) .def_prop_ro("has_symbol", &Relocation::has_symbol, diff --git a/api/python/src/ELF/objects/pyRelocationTypes.cpp b/api/python/src/ELF/objects/pyRelocationTypes.cpp new file mode 100644 index 0000000000..ce495ae86d --- /dev/null +++ b/api/python/src/ELF/objects/pyRelocationTypes.cpp @@ -0,0 +1,46 @@ +/* Copyright 2017 - 2023 R. Thomas + * Copyright 2017 - 2023 Quarkslab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +#include "ELF/pyELF.hpp" +#include "enums_wrapper.hpp" + +#include "LIEF/ELF/Relocation.hpp" + +namespace LIEF::ELF::py { + +void init_relocation_types(nb::class_& m) { + + #define ELF_RELOC(X, _) .value(to_string(Relocation::TYPE::X), Relocation::TYPE::X) + enum_(m, "TYPE") + #include "LIEF/ELF/Relocations/x86_64.def" + #include "LIEF/ELF/Relocations/AArch64.def" + #include "LIEF/ELF/Relocations/ARM.def" + #include "LIEF/ELF/Relocations/Hexagon.def" + #include "LIEF/ELF/Relocations/i386.def" + #include "LIEF/ELF/Relocations/LoongArch.def" + #include "LIEF/ELF/Relocations/Mips.def" + #include "LIEF/ELF/Relocations/PowerPC.def" + #include "LIEF/ELF/Relocations/PowerPC64.def" + #include "LIEF/ELF/Relocations/Sparc.def" + #include "LIEF/ELF/Relocations/SystemZ.def" + ; + #undef ELF_RELOC +} + +} diff --git a/api/python/src/ELF/objects/pySection.cpp b/api/python/src/ELF/objects/pySection.cpp index 5069d09779..457d5795a9 100644 --- a/api/python/src/ELF/objects/pySection.cpp +++ b/api/python/src/ELF/objects/pySection.cpp @@ -15,6 +15,7 @@ */ #include "ELF/pyELF.hpp" #include "pyIterator.hpp" +#include "enums_wrapper.hpp" #include #include @@ -35,12 +36,90 @@ void create
(nb::module_& m) { using namespace LIEF::py; nb::class_ sec(m, "Section", - R"delim( - Class which represents an ELF section. - )delim"_doc); + R"delim( + Class which represents an ELF section. + )delim"_doc + ); init_ref_iterator(sec, "it_segments"); + #define ENTRY(X) .value(to_string(Section::FLAGS::X), Section::FLAGS::X) + enum_(sec, "FLAGS", nb::is_arithmetic()) + ENTRY(NONE) + ENTRY(WRITE) + ENTRY(ALLOC) + ENTRY(EXECINSTR) + ENTRY(MERGE) + ENTRY(STRINGS) + ENTRY(INFO_LINK) + ENTRY(LINK_ORDER) + ENTRY(OS_NONCONFORMING) + ENTRY(GROUP) + ENTRY(TLS) + ENTRY(COMPRESSED) + ENTRY(GNU_RETAIN) + ENTRY(EXCLUDE) + ENTRY(XCORE_SHF_DP_SECTION) + ENTRY(XCORE_SHF_CP_SECTION) + ENTRY(X86_64_LARGE) + ENTRY(HEX_GPREL) + + ENTRY(MIPS_NODUPES) + ENTRY(MIPS_NAMES) + ENTRY(MIPS_LOCAL) + ENTRY(MIPS_NOSTRIP) + ENTRY(MIPS_GPREL) + ENTRY(MIPS_MERGE) + ENTRY(MIPS_ADDR) + ENTRY(MIPS_STRING) + ENTRY(ARM_PURECODE) + ; + #undef ENTRY + + #define ENTRY(X) .value(to_string(Section::TYPE::X), Section::TYPE::X) + enum_(sec, "TYPE") + ENTRY(SHT_NULL) + ENTRY(PROGBITS) + ENTRY(SYMTAB) + ENTRY(STRTAB) + ENTRY(RELA) + ENTRY(HASH) + ENTRY(DYNAMIC) + ENTRY(NOTE) + ENTRY(NOBITS) + ENTRY(REL) + ENTRY(SHLIB) + ENTRY(DYNSYM) + ENTRY(INIT_ARRAY) + ENTRY(FINI_ARRAY) + ENTRY(PREINIT_ARRAY) + ENTRY(GROUP) + ENTRY(SYMTAB_SHNDX) + ENTRY(RELR) + + ENTRY(ANDROID_REL) + ENTRY(ANDROID_RELA) + ENTRY(LLVM_ADDRSIG) + ENTRY(ANDROID_RELR) + ENTRY(GNU_ATTRIBUTES) + ENTRY(GNU_HASH) + ENTRY(GNU_VERDEF) + ENTRY(GNU_VERNEED) + ENTRY(GNU_VERSYM) + + ENTRY(ARM_EXIDX) + ENTRY(ARM_PREEMPTMAP) + ENTRY(ARM_ATTRIBUTES) + ENTRY(ARM_DEBUGOVERLAY) + ENTRY(ARM_OVERLAYSECTION) + ENTRY(HEX_ORDERED) + ENTRY(X86_64_UNWIND) + ENTRY(MIPS_REGINFO) + ENTRY(MIPS_OPTIONS) + ENTRY(MIPS_ABIFLAGS) + ; + #undef ENTRY + sec .def(nb::init<>(), "Default constructor"_doc) @@ -52,27 +131,22 @@ void create
(nb::module_& m) { .def_prop_ro("is_frame", &Section::is_frame) - .def(nb::init(), + .def(nb::init(), "Constructor from a name and a section type"_doc, - "name"_a, "type"_a = ELF_SECTION_TYPES::SHT_PROGBITS) - - //.def(nb::init([] (Section& section, std::vector& content, ELF_CLASS type) { - // return new Section(content.data(), type); - // })) + "name"_a, "type"_a = Section::TYPE::PROGBITS) .def_prop_rw("type", nb::overload_cast<>(&Section::type, nb::const_), - nb::overload_cast(&Section::type), - "Return the " RST_CLASS_REF(lief.ELF.SECTION_TYPES) ""_doc) + nb::overload_cast(&Section::type), + "Return the type of the section"_doc) .def_prop_rw("flags", nb::overload_cast<>(&Section::flags, nb::const_), nb::overload_cast(&Section::flags), "Return the section's flags as an integer"_doc) - .def_prop_ro("flags_list", - &Section::flags_list, - "Return section's flags as a list of " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) ""_doc) + .def_prop_ro("flags_list", &Section::flags_list, + "Return section's flags as a list"_doc) .def_prop_rw("file_offset", nb::overload_cast<>(&Section::file_offset, nb::const_), @@ -128,21 +202,17 @@ void create
(nb::module_& m) { "value"_a = 0, nb::rv_policy::reference_internal) - .def("add", - &Section::add, - "Add the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " to the list of " - ":attr:`~lief.ELF.Section.flags`"_doc, + .def("add", &Section::add, + "Add the given flag to the list of :attr:`~lief.ELF.Section.flags`"_doc, "flag"_a) - .def("remove", - &Section::remove, - "Remove the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " from the list of " - ":attr:`~lief.ELF.Section.flags`"_doc, + .def("remove", &Section::remove, + "Remove the given flag from the list of " ":attr:`~lief.ELF.Section.flags`"_doc, "flag"_a) .def("has", - nb::overload_cast(&Section::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " is present"_doc, + nb::overload_cast(&Section::has, nb::const_), + "Check if the given flag is present"_doc, "flag"_a) .def("has", @@ -151,12 +221,12 @@ void create
(nb::module_& m) { "in :attr:`~lief.ELF.Section.segments`"_doc, "segment"_a) - .def(nb::self += ELF_SECTION_FLAGS()) - .def(nb::self -= ELF_SECTION_FLAGS()) + .def(nb::self += Section::FLAGS()) + .def(nb::self -= Section::FLAGS()) .def("__contains__", - nb::overload_cast(&Section::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " is present"_doc) + nb::overload_cast(&Section::has, nb::const_), + "Check if the given flag is present"_doc) .def("__contains__", diff --git a/api/python/src/ELF/objects/pySegment.cpp b/api/python/src/ELF/objects/pySegment.cpp index fe9882e0a3..e6182e5703 100644 --- a/api/python/src/ELF/objects/pySegment.cpp +++ b/api/python/src/ELF/objects/pySegment.cpp @@ -1,4 +1,4 @@ -/* Copyright 2017 - 2023 R. Thomas +/* opyright 2017 - 2023 R. Thomas * Copyright 2017 - 2023 Quarkslab * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,8 @@ #include "pyIterator.hpp" #include "nanobind/extra/memoryview.hpp" +#include "enums_wrapper.hpp" + namespace LIEF::ELF::py { template<> @@ -36,12 +38,48 @@ void create(nb::module_& m) { using namespace LIEF::py; nb::class_ seg(m, "Segment", - R"delim( - Class which represents the ELF segments - )delim"_doc); + R"delim( + Class which represents the ELF segments + )delim"_doc + ); init_ref_iterator(seg, "it_sections"); + #define ENTRY(X) .value(to_string(Segment::TYPE::X), Segment::TYPE::X) + enum_(seg, "TYPE") + ENTRY(PT_NULL) + ENTRY(LOAD) + ENTRY(DYNAMIC) + ENTRY(INTERP) + ENTRY(NOTE) + ENTRY(SHLIB) + ENTRY(PHDR) + ENTRY(TLS) + ENTRY(GNU_EH_FRAME) + ENTRY(GNU_STACK) + ENTRY(GNU_PROPERTY) + ENTRY(GNU_RELRO) + ENTRY(ARM_ARCHEXT) + ENTRY(ARM_EXIDX) + ENTRY(ARM_UNWIND) + ENTRY(AARCH64_MEMTAG_MTE) + ENTRY(MIPS_REGINFO) + ENTRY(MIPS_RTPROC) + ENTRY(MIPS_OPTIONS) + ENTRY(MIPS_ABIFLAGS) + ENTRY(RISCV_ATTRIBUTES) + ; + #undef ENTRY + + #define ENTRY(X) .value(to_string(Segment::FLAGS::X), Segment::FLAGS::X) + enum_(seg, "FLAGS", nb::is_arithmetic()) + ENTRY(R) + ENTRY(W) + ENTRY(X) + ENTRY(NONE) + ; + #undef ENTRY + seg .def(nb::init<>()) .def_static("from_raw", @@ -53,12 +91,12 @@ void create(nb::module_& m) { .def_prop_rw("type", nb::overload_cast<>(&Segment::type, nb::const_), - nb::overload_cast(&Segment::type), - "Segment's type: " RST_CLASS_REF(lief.ELF.SEGMENT_TYPES) ""_doc) + nb::overload_cast(&Segment::type), + "Segment's type"_doc) .def_prop_rw("flags", nb::overload_cast<>(&Segment::flags, nb::const_), - nb::overload_cast(&Segment::flags), + nb::overload_cast(&Segment::flags), "The flag permissions associated with this segment"_doc) .def_prop_rw("file_offset", @@ -84,9 +122,9 @@ void create(nb::module_& m) { nb::overload_cast<>(&Segment::physical_address, nb::const_), nb::overload_cast(&Segment::physical_address), R"delim( - The physical address of the segment. - This value is not really relevant on systems like Linux or Android. On the other hand, - Qualcomm trustlets might use this value. + The physical address of the segment. This value is not really relevant + on systems like Linux or Android. On the other hand, Qualcomm trustlets + might use this value. Usually this value matches :attr:`~lief.ELF.Segment.virtual_address` )delim"_doc) @@ -119,21 +157,17 @@ void create(nb::module_& m) { nb::overload_cast>(&Segment::content), "The raw data associated with this segment."_doc) - .def("add", - &Segment::add, - "Add the given " RST_CLASS_REF(lief.ELF.SEGMENT_FLAGS) " to the list of " - ":attr:`~lief.ELF.Segment.flags`"_doc, + .def("add", &Segment::add, + "Add the given flag to the list of :attr:`~lief.ELF.Segment.flags`"_doc, "flag"_a) - .def("remove", - &Segment::remove, - "Remove the given " RST_CLASS_REF(lief.ELF.SEGMENT_FLAGS) " from the list of " - ":attr:`~lief.ELF.Segment.flags`"_doc, + .def("remove", &Segment::remove, + "Remove the given flag from the list of :attr:`~lief.ELF.Segment.flags`"_doc, "flag"_a) .def("has", - nb::overload_cast(&Segment::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.SEGMENT_FLAGS) " is present"_doc, + nb::overload_cast(&Segment::has, nb::const_), + "Check if the given flag is present"_doc, "flag"_a) .def("has", @@ -153,12 +187,12 @@ void create(nb::module_& m) { "Iterator over the " RST_CLASS_REF(lief.ELF.Section) " wrapped by this segment"_doc, nb::keep_alive<0, 1>()) - .def(nb::self += ELF_SEGMENT_FLAGS()) - .def(nb::self -= ELF_SEGMENT_FLAGS()) + .def(nb::self += Segment::FLAGS()) + .def(nb::self -= Segment::FLAGS()) .def("__contains__", - nb::overload_cast(&Segment::has, nb::const_), - "Check if the given " RST_CLASS_REF(lief.ELF.SEGMENT_FLAGS) " is present"_doc) + nb::overload_cast(&Segment::has, nb::const_), + "Check if the given flag is present"_doc) .def("__contains__", nb::overload_cast(&Segment::has, nb::const_), diff --git a/api/python/src/ELF/objects/pySymbol.cpp b/api/python/src/ELF/objects/pySymbol.cpp index 12d7e0e902..4dca9fb646 100644 --- a/api/python/src/ELF/objects/pySymbol.cpp +++ b/api/python/src/ELF/objects/pySymbol.cpp @@ -15,6 +15,7 @@ */ #include "ELF/pyELF.hpp" #include "pyIterator.hpp" +#include "enums_wrapper.hpp" #include "LIEF/ELF/Symbol.hpp" #include "LIEF/ELF/SymbolVersion.hpp" @@ -29,10 +30,43 @@ namespace LIEF::ELF::py { template<> void create(nb::module_& m) { - nb::class_(m, "Symbol", + nb::class_ sym(m, "Symbol", R"delim( - "Class which represents an ELF symbol" - )delim") + Class which represents an ELF symbol + )delim"_doc); + + #define ENTRY(X) .value(to_string(Symbol::BINDING::X), Symbol::BINDING::X) + enum_(sym, "BINDING") + ENTRY(LOCAL) + ENTRY(GLOBAL) + ENTRY(WEAK) + ENTRY(GNU_UNIQUE) + ; + #undef ENTRY + + #define ENTRY(X) .value(to_string(Symbol::TYPE::X), Symbol::TYPE::X) + enum_(sym, "TYPE") + ENTRY(NOTYPE) + ENTRY(OBJECT) + ENTRY(FUNC) + ENTRY(SECTION) + ENTRY(FILE) + ENTRY(COMMON) + ENTRY(TLS) + ENTRY(GNU_IFUNC) + ; + #undef ENTRY + + #define ENTRY(X) .value(to_string(Symbol::VISIBILITY::X), Symbol::VISIBILITY::X) + enum_(sym, "VISIBILITY") + ENTRY(DEFAULT) + ENTRY(INTERNAL) + ENTRY(HIDDEN) + ENTRY(PROTECTED) + ; + #undef ENTRY + + sym .def(nb::init<>()) .def_prop_ro("demangled_name", &Symbol::demangled_name, @@ -40,15 +74,13 @@ void create(nb::module_& m) { .def_prop_rw("type", nb::overload_cast<>(&Symbol::type, nb::const_), - nb::overload_cast(&Symbol::type), - "The symbol's type provides a general classification for the associated entity. " - "See: " RST_CLASS_REF(lief.ELF.SYMBOL_TYPES) ""_doc) + nb::overload_cast(&Symbol::type), + "The symbol's type provides a general classification for the associated entity."_doc) .def_prop_rw("binding", nb::overload_cast<>(&Symbol::binding, nb::const_), - nb::overload_cast(&Symbol::binding), - "A symbol's binding determines the linkage visibility and behavior. " - "See " RST_CLASS_REF(lief.ELF.SYMBOL_BINDINGS) ""_doc) + nb::overload_cast(&Symbol::binding), + "A symbol's binding determines the linkage visibility and behavior."_doc) .def_prop_rw("information", nb::overload_cast<>(&Symbol::information, nb::const_), @@ -62,10 +94,9 @@ void create(nb::module_& m) { .def_prop_rw("visibility", nb::overload_cast<>(&Symbol::visibility, nb::const_), - nb::overload_cast(&Symbol::visibility), + nb::overload_cast(&Symbol::visibility), R"delim( - Symbol :class:`~lief.ELF.SYMBOL_VISIBILITY`. - It's basically an alias on :attr:`~lief.ELF.Symbol.other` + Symbol visibility. It's basically an alias on :attr:`~.Symbol.other` )delim"_doc) .def_prop_rw("value", // Even though it is already defined in the base class (Abstract/Symbol) diff --git a/api/python/src/ELF/objects/pySymbolVersionAux.cpp b/api/python/src/ELF/objects/pySymbolVersionAux.cpp index cd4af5c39c..2f9732f70c 100644 --- a/api/python/src/ELF/objects/pySymbolVersionAux.cpp +++ b/api/python/src/ELF/objects/pySymbolVersionAux.cpp @@ -33,7 +33,7 @@ void create(nb::module_& m) { [] (const SymbolVersionAux& obj) { return LIEF::py::safe_string(obj.name()); }, - nb::overload_cast(&SymbolVersionAux::name), + nb::overload_cast(&SymbolVersionAux::name), "Symbol's name (e.g. ``GLIBC_2.2.5``)"_doc) LIEF_DEFAULT_STR(SymbolVersionAux); diff --git a/api/python/src/ELF/pyProcessorFlags.cpp b/api/python/src/ELF/pyProcessorFlags.cpp new file mode 100644 index 0000000000..b2e65b550b --- /dev/null +++ b/api/python/src/ELF/pyProcessorFlags.cpp @@ -0,0 +1,96 @@ +/* Copyright 2017 - 2023 R. Thomas + * Copyright 2017 - 2023 Quarkslab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "ELF/pyELF.hpp" +#include "enums_wrapper.hpp" + +#include "LIEF/ELF/ProcessorFlags.hpp" + +namespace LIEF::ELF::py { + +template<> +void create(nb::module_& m) { + #define ENTRY(X) .value(to_string(PROCESSOR_FLAGS::X), PROCESSOR_FLAGS::X) + enum_(m, "PROCESSOR_FLAGS") + ENTRY(ARM_EABI_UNKNOWN) + ENTRY(ARM_SOFT_FLOAT) + ENTRY(ARM_VFP_FLOAT) + ENTRY(ARM_EABI_VER1) + ENTRY(ARM_EABI_VER2) + ENTRY(ARM_EABI_VER3) + ENTRY(ARM_EABI_VER4) + ENTRY(ARM_EABI_VER5) + ENTRY(HEXAGON_MACH_V2) + ENTRY(HEXAGON_MACH_V3) + ENTRY(HEXAGON_MACH_V4) + ENTRY(HEXAGON_MACH_V5) + ENTRY(HEXAGON_ISA_V2) + ENTRY(HEXAGON_ISA_V3) + ENTRY(HEXAGON_ISA_V4) + ENTRY(HEXAGON_ISA_V5) + ENTRY(LOONGARCH_ABI_SOFT_FLOAT) + ENTRY(LOONGARCH_ABI_SINGLE_FLOAT) + ENTRY(LOONGARCH_ABI_DOUBLE_FLOAT) + ENTRY(MIPS_NOREORDER) + ENTRY(MIPS_PIC) + ENTRY(MIPS_CPIC) + ENTRY(MIPS_ABI2) + ENTRY(MIPS_32BITMODE) + ENTRY(MIPS_FP64) + ENTRY(MIPS_NAN2008) + ENTRY(MIPS_ABI_O32) + ENTRY(MIPS_ABI_O64) + ENTRY(MIPS_ABI_EABI32) + ENTRY(MIPS_ABI_EABI64) + ENTRY(MIPS_MACH_3900) + ENTRY(MIPS_MACH_4010) + ENTRY(MIPS_MACH_4100) + ENTRY(MIPS_MACH_4650) + ENTRY(MIPS_MACH_4120) + ENTRY(MIPS_MACH_4111) + ENTRY(MIPS_MACH_SB1) + ENTRY(MIPS_MACH_OCTEON) + ENTRY(MIPS_MACH_XLR) + ENTRY(MIPS_MACH_OCTEON2) + ENTRY(MIPS_MACH_OCTEON3) + ENTRY(MIPS_MACH_5400) + ENTRY(MIPS_MACH_5900) + ENTRY(MIPS_MACH_5500) + ENTRY(MIPS_MACH_9000) + ENTRY(MIPS_MACH_LS2E) + ENTRY(MIPS_MACH_LS2F) + ENTRY(MIPS_MACH_LS3A) + ENTRY(MIPS_MICROMIPS) + ENTRY(MIPS_ARCH_ASE_M16) + ENTRY(MIPS_ARCH_ASE_MDMX) + ENTRY(MIPS_ARCH_1) + ENTRY(MIPS_ARCH_2) + ENTRY(MIPS_ARCH_3) + ENTRY(MIPS_ARCH_4) + ENTRY(MIPS_ARCH_5) + ENTRY(MIPS_ARCH_32) + ENTRY(MIPS_ARCH_64) + ENTRY(MIPS_ARCH_32R2) + ENTRY(MIPS_ARCH_64R2) + ENTRY(MIPS_ARCH_32R6) + ENTRY(MIPS_ARCH_64R6) + ; + #undef ENTRY + +} + +} diff --git a/doc/sphinx/api/c/elf.rst b/doc/sphinx/api/c/elf.rst index c455322cfd..ce6e5d3fe7 100644 --- a/doc/sphinx/api/c/elf.rst +++ b/doc/sphinx/api/c/elf.rst @@ -22,8 +22,5 @@ ELF .. autodoxygenfile:: LIEF/ELF/enums.h :project: lief -.. autodoxygenfile:: LIEF/ELF/EnumToString.h - :project: lief - .. autodoxygenfile:: LIEF/ELF/utils.h :project: lief diff --git a/doc/sphinx/api/cpp/elf.rst b/doc/sphinx/api/cpp/elf.rst index 63d6a0225c..5505fd315b 100644 --- a/doc/sphinx/api/cpp/elf.rst +++ b/doc/sphinx/api/cpp/elf.rst @@ -276,8 +276,6 @@ Utilities ---------- - - Enums ***** @@ -286,183 +284,8 @@ Architectures .. doxygenenum:: LIEF::ELF::ARCH ----------- - -Identity -~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::IDENTITY - ----------- - -Binary types -~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::E_TYPE - ----------- - -Version -~~~~~~~ - -.. doxygenenum:: LIEF::ELF::VERSION - ----------- - -ELF Class -~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_CLASS - ----------- - -ELF Data -~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_DATA - ----------- - -ELF OS/ABI -~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::OS_ABI - ----------- - -Symbol section index -~~~~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::SYMBOL_SECTION_INDEX - ----------- - -Section types -~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_SECTION_TYPES - ----------- - -Section flags -~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_SECTION_FLAGS - ----------- - -Symbol bindings +Processor Flags ~~~~~~~~~~~~~~~ -.. doxygenenum:: LIEF::ELF::SYMBOL_BINDINGS - ----------- - -Symbol visibility -~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_SYMBOL_VISIBILITY - ----------- - -Symbol types -~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_SYMBOL_TYPES - ----------- - - -Segment types -~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::SEGMENT_TYPES - ----------- - -Segment flags -~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::ELF_SEGMENT_FLAGS - ----------- - -Dynamic tags -~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::DYNAMIC_TAGS - ----------- - -Dynamic flags -~~~~~~~~~~~~~ -.. doxygenenum:: LIEF::ELF::DYNAMIC_FLAGS - ----------- - -Dynamic flags 1 -~~~~~~~~~~~~~~~ -.. doxygenenum:: LIEF::ELF::DYNAMIC_FLAGS_1 - ----------- - -Dynamic symbols counting -~~~~~~~~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::DYNSYM_COUNT_METHODS - ----------- - - -Relocation purpose -~~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOCATION_PURPOSES - ----------- - -Relocations x86-64 -~~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_x86_64 - ----------- - - -Relocations x86 (i386) -~~~~~~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_i386 - ----------- - -Relocations ARM -~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_ARM - ----------- - -Relocations AARCH64 -~~~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_AARCH64 - - -Relocations MIPS -~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_MIPS - - -Relocations PPC -~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_POWERPC32 - - -Relocations PPC64 -~~~~~~~~~~~~~~~~~ - -.. doxygenenum:: LIEF::ELF::RELOC_POWERPC64 +.. doxygenenum:: LIEF::ELF::PROCESSOR_FLAGS diff --git a/doc/sphinx/api/python/elf.rst b/doc/sphinx/api/python/elf.rst index 29f3c953fe..7a3a6fd80b 100644 --- a/doc/sphinx/api/python/elf.rst +++ b/doc/sphinx/api/python/elf.rst @@ -264,229 +264,13 @@ Builder Enums ***** -Identity -~~~~~~~~ - -.. autoclass:: lief.ELF.IDENTITY - ----------- - -ELF Class -~~~~~~~~~ - -.. autoclass:: lief.ELF.ELF_CLASS - ----------- - -ELF Data -~~~~~~~~ - -.. autoclass:: lief.ELF.ELF_DATA - ----------- - -ELF OS/ABI -~~~~~~~~~~ - -.. autoclass:: lief.ELF.OS_ABI - ----------- - -Symbol section index -~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SYMBOL_SECTION_INDEX - ----------- - -Binary types -~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.E_TYPE - ----------- - -Section types -~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SECTION_TYPES - ----------- - -Section flags -~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SECTION_FLAGS - ----------- - - -Segment types -~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SEGMENT_TYPES - ----------- - -Segment flags -~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SEGMENT_FLAGS - ----------- - - Architectures ~~~~~~~~~~~~~ .. autoclass:: lief.ELF.ARCH ----------- - -Version -~~~~~~~ - -.. autoclass:: lief.ELF.VERSION - ----------- - -Dynamic tags -~~~~~~~~~~~~ -.. autoclass:: lief.ELF.DYNAMIC_TAGS - ----------- - -Dynamic flags -~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.DYNAMIC_FLAGS - ----------- - - -Dynamic flags 1 +Processor Flags ~~~~~~~~~~~~~~~ -.. autoclass:: lief.ELF.DYNAMIC_FLAGS_1 - ----------- - - -Symbol types -~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SYMBOL_TYPES - ----------- - -Symbol bindings -~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SYMBOL_BINDINGS - ----------- - - -Symbol Visibility -~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.SYMBOL_VISIBILITY - ----------- - -Relocations x86-64 -~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_X86_64 - ----------- - - -Relocations x86 (i386) -~~~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_i386 - ----------- - -Relocations ARM -~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_ARM - ----------- - - -Relocations AARCH64 -~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_AARCH64 - ----------- - -Relocations MIPS -~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_MIPS - ----------- - - -Relocations PPC -~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_PPC - ----------- - - -Relocations PPC64 -~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_PPC64 - ----------- - - -Dynamic symbols counting -~~~~~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.DYNSYM_COUNT_METHODS - ----------- - -Relocation purpose -~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.RELOCATION_PURPOSES - ----------- - - -ARM Processor flags -~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.ARM_EFLAGS - ----------- - -MIPS Processor flags -~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.MIPS_EFLAGS - ----------- - -PPC64 Processor flags -~~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.PPC64_EFLAGS - ----------- - -Hexagon Processor flags -~~~~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: lief.ELF.HEXAGON_EFLAGS - +.. autoclass:: lief.ELF.PROCESSOR_FLAGS diff --git a/doc/sphinx/changelog.rst b/doc/sphinx/changelog.rst index 9fe8e2740e..7946be49ee 100644 --- a/doc/sphinx/changelog.rst +++ b/doc/sphinx/changelog.rst @@ -4,6 +4,27 @@ Changelog 0.15.0 - Not Released Yet ------------------------- +:ELF: + * Re-scope ``DYNAMIC_TAGS`` into :class:`lief.ELF.DynamicEntry.TAG` + * Re-scope ``E_TYPE`` into :class:`lief.ELF.Header.FILE_TYPE` + * Re-scope ``VERSION`` into :class:`lief.ELF.Header.VERSION` + * Re-scope ``ELF_CLASS`` into :class:`lief.ELF.Header.CLASS` + * Re-scope ``ELF_DATA`` into :class:`lief.ELF.Header.ELF_DATA` + * Re-scope ``OS_ABI`` into :class:`lief.ELF.Header.OS_ABI` + * Re-scope ``ELF_SECTION_TYPES`` into :class:`lief.ELF.Section.TYPE` + * Re-scope ``ELF_SECTION_FLAGS`` into :class:`lief.ELF.Section.FLAGS` + * Re-scope ``SYMBOL_BINDINGS`` into :class:`lief.ELF.Symbol.BINDING` + * Re-scope ``ELF_SYMBOL_TYPES`` into :class:`lief.ELF.Symbol.TYPE` + * Re-scope ``ELF_SYMBOL_VISIBILITY`` into :class:`lief.ELF.Symbol.VISIBILITY` + * Re-scope ``SEGMENT_TYPES`` into :class:`lief.ELF.Segment.TYPE` + * Re-scope ``ELF_SEGMENT_FLAGS`` into :class:`lief.ELF.Segment.FLAG` + * Re-scope ``DYNAMIC_FLAGS_1`` into :class:`lief.ELF.DynamicEntryFlags.FLAG` + * Re-scope ``DYNAMIC_FLAGS`` into :class:`lief.ELF.DynamicEntryFlags.FLAG` + * Re-scope ``DYNSYM_COUNT_METHODS`` into :class:`lief.ELF.ParserConfig.DYNSYM_COUNT` + * Re-scope ``RELOCATION_PURPOSES`` into :class:`lief.ELF.Relocation.PURPOSE` + * ``RELOC_x86_64``, ``RELOC_i386``, ... have been re-scoped **and merged** + into :class:`lief.ELF.Relocation.TYPE` + :CMake: * ``LIEFConfig.cmake`` is now installed in ``/lib/cmake/LIEF/`` @@ -36,7 +57,7 @@ Changelog * Refactoring of the ELF note processing - * Fix relocation issue when using `-Wl,--emit-relocs` (c.f. :issue:`897` / :pr:`898` by :github_user:`adamjseitz`) + * Fix relocation issue when using ``-Wl,--emit-relocs`` (c.f. :issue:`897` / :pr:`898` by :github_user:`adamjseitz`) * Improve the computation of the dynamic symbols thanks to :github_user:`adamjseitz` (c.f. :issue:`922`) * Add support for the LoongArch architecture thanks to :github_user:`loongson-zn` (c.f. :pr:`921`) diff --git a/doc/sphinx/compilation.rst b/doc/sphinx/compilation.rst index f7de705140..ae092e11ee 100644 --- a/doc/sphinx/compilation.rst +++ b/doc/sphinx/compilation.rst @@ -128,7 +128,7 @@ by changing the `type` in the section `[lief.build]` of `config-default.toml`: .. code-block:: console - $ PYLIEF_CONF=~/lief-debug.toml python ./setup build develop --user + $ PYLIEF_CONF=~/lief-debug.toml pip install [-e] api/python With `lief-debug.toml` set to: @@ -142,13 +142,6 @@ by changing the `type` in the section `[lief.build]` of `config-default.toml`: enabled = true debug = true - Compared to the ``install`` command, ``develop`` creates a ``.egg-link`` - that links to the native LIEF library currently presents in your build directory. - - The ``--user`` flag is used to avoid creating the ``.egg-link`` system-wide (i.e. ``/usr/lib/python3.9/site-packages``). - Instead, it links the ``.egg-link`` in the user's local dir (e.g. ``~/.local/lib/python3.9/site-packages``) - - .. _lief_third_party: Third Party diff --git a/doc/sphinx/tutorials/03_elf_change_symbols.rst b/doc/sphinx/tutorials/03_elf_change_symbols.rst index 85394ff7b7..d2333cc651 100644 --- a/doc/sphinx/tutorials/03_elf_change_symbols.rst +++ b/doc/sphinx/tutorials/03_elf_change_symbols.rst @@ -16,13 +16,13 @@ dynamic table (``PT_DYNAMIC``). In addition, the functions imported from this library are referenced in the dynamic symbols table with the following attributes: * :attr:`~lief.ELF.Symbol.value` set to ``0`` -* :attr:`~lief.ELF.Symbol.type` set to :attr:`~lief.ELF.SYMBOL_TYPES.FUNC` +* :attr:`~lief.ELF.Symbol.type` set to :attr:`~lief.ELF.Symbol.TYPE.FUNC` Similarly, when a library exports functions the exported functions are registered in the dynamic symbols table with the following attributes: * :attr:`~lief.ELF.Symbol.value` set to the address of the function in the library -* :attr:`~lief.ELF.Symbol.type` set to :attr:`~lief.ELF.SYMBOL_TYPES.FUNC` +* :attr:`~lief.ELF.Symbol.type` set to :attr:`~lief.ELF.Symbol.TYPE.FUNC` Imported and exported functions are abstracted in LIEF and one can iterate over these elements through the properties: :attr:`~lief.Binary.exported_functions` and :attr:`~lief.Binary.imported_functions` diff --git a/doc/sphinx/tutorials/04_elf_hooking.rst b/doc/sphinx/tutorials/04_elf_hooking.rst index 3860718237..a5fd5bd3f6 100644 --- a/doc/sphinx/tutorials/04_elf_hooking.rst +++ b/doc/sphinx/tutorials/04_elf_hooking.rst @@ -67,7 +67,7 @@ Once the stub is injected we have to calculate the new address for the ``exp`` s new_address = segment_added.virtual_address + hook_symbol.value - code_segment.virtual_address exp_symbol.value = new_address - exp_symbol.type = lief.ELF.SYMBOL_TYPES.FUNC # it might have been GNU_IFUNC + exp_symbol.type = lief.ELF.Symbol.TYPE.FUNC # it might have been GNU_IFUNC Note that we have to update symbol's type to be regular `FUNC` because on many distributions `libm.so` is built with automatic hardware detection and exposes diff --git a/doc/sphinx/tutorials/05_elf_infect_plt_got.rst b/doc/sphinx/tutorials/05_elf_infect_plt_got.rst index 7005e43afe..74aa6b7f22 100644 --- a/doc/sphinx/tutorials/05_elf_infect_plt_got.rst +++ b/doc/sphinx/tutorials/05_elf_infect_plt_got.rst @@ -123,7 +123,7 @@ The first step is to inject the hook into the binary. To do so we will add a :cl segment_added = crackme.add(hook.segments[0]) -All assembly code of the hook stands in the first :attr:`~lief.ELF.SEGMENT_TYPES.LOAD` segment of ``hook``. +All assembly code of the hook stands in the first :attr:`~lief.ELF.Segment.TYPE.LOAD` segment of ``hook``. Once the hook added, its virtual address is :attr:`~lief.ELF.Segment.virtual_address` of ``segment_added`` and we can processed to the ``got`` patching. diff --git a/doc/sphinx/tutorials/08_elf_bin2lib.rst b/doc/sphinx/tutorials/08_elf_bin2lib.rst index 6077d18f0c..a4ff11e400 100644 --- a/doc/sphinx/tutorials/08_elf_bin2lib.rst +++ b/doc/sphinx/tutorials/08_elf_bin2lib.rst @@ -240,7 +240,7 @@ In order to circumvent this test, LIEF can be used to remove this ``DF_1_PIE`` f import sys path = sys.argv[1] bin_ = lief.parse(path) - bin_[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE) + bin_[lief.ELF.DynamicEntry.TAG.FLAGS_1].remove(lief.ELF.DynamicEntryFlags.FLAG.PIE) bin_.write(path + ".patched") diff --git a/doc/sphinx/tutorials/09_frida_lief.rst b/doc/sphinx/tutorials/09_frida_lief.rst index b0f0b711fc..312e1a34e9 100644 --- a/doc/sphinx/tutorials/09_frida_lief.rst +++ b/doc/sphinx/tutorials/09_frida_lief.rst @@ -276,11 +276,11 @@ Here is a quick summary of advantages/disadvantages of this technique .. rubric:: Notes -.. [1] Note that LIEF **does not** modify the :attr:`~lief.ELF.DYNAMIC_TAGS.DEBUG` entry ... +.. [1] Note that LIEF **does not** modify the :attr:`~lief.ELF.DynamicEntry.TAG.DEBUG` entry ... .. [2] Modification of the ELF Dynamic section is not as easy as the API looks like. -.. [3] In the ELF format they are located in the :attr:`~lief.ELF.DYNAMIC_TAGS.INIT_ARRAY` or :attr:`~lief.ELF.DYNAMIC_TAGS.INIT` entries +.. [3] In the ELF format they are located in the :attr:`~lief.ELF.DynamicEntry.TAG.INIT_ARRAY` or :attr:`~lief.ELF.DynamicEntry.TAG.INIT` entries .. [4] For those who are interested, checks are done in the ``framework_base/core/jni/com_android_internal_content_NativeLibraryHelper.cpp`` file. Actually these checks on the prefix and suffix are only done if the application is not *debuggable*. diff --git a/examples/c/elf_reader.c b/examples/c/elf_reader.c index 052077d1f9..f928873065 100644 --- a/examples/c/elf_reader.c +++ b/examples/c/elf_reader.c @@ -27,13 +27,13 @@ int main(int argc, char **argv) { fprintf(stdout, "Header\n"); fprintf(stdout, "======\n"); fprintf(stdout, "Magic: %x %x %x %x\n", identity[0], identity[1], identity[2], identity[3]); - fprintf(stdout, "Class: %s\n", ELF_CLASS_to_string(identity[LIEF_ELF_EI_CLASS])); - fprintf(stdout, "Endianness: %s\n", ELF_DATA_to_string(identity[LIEF_ELF_EI_DATA])); - fprintf(stdout, "Version: %s\n", VERSION_to_string(identity[LIEF_ELF_EI_VERSION])); - fprintf(stdout, "OS/ABI: %s\n", OS_ABI_to_string(identity[LIEF_ELF_EI_OSABI])); - fprintf(stdout, "File type: %s\n", E_TYPE_to_string(header.file_type)); - fprintf(stdout, "Architecture: %s\n", ARCH_to_string(header.machine_type)); - fprintf(stdout, "Version: %s\n", VERSION_to_string(header.object_file_version)); + fprintf(stdout, "Class: %d\n", identity[LIEF_EI_CLASS]); + fprintf(stdout, "Endianness: %d\n", identity[LIEF_EI_DATA]); + fprintf(stdout, "Version: %d\n", identity[LIEF_EI_VERSION]); + fprintf(stdout, "OS/ABI: %d\n", identity[LIEF_EI_OSABI]); + fprintf(stdout, "File type: %d\n", header.file_type); + fprintf(stdout, "Architecture: %d\n", header.machine_type); + fprintf(stdout, "Version: %d\n", header.object_file_version); fprintf(stdout, "Segments offset: 0x%" PRIx64 "\n", header.program_headers_offset); fprintf(stdout, "Sections offset: 0x%" PRIx64 "\n", header.section_headers_offset); fprintf(stdout, "Processor flags: %x\n", header.processor_flags); @@ -49,7 +49,7 @@ int main(int argc, char **argv) { Elf_Section_t* section = sections[i]; fprintf(stdout, "" "%-20s " - "%-10s " + "%d " "0x%010" PRIx64 " " "0x%010" PRIx64 " " "0x%010" PRIx64 " " @@ -59,7 +59,7 @@ int main(int argc, char **argv) { "%.6f " "\n", section->name, - ELF_SECTION_TYPES_to_string(section->type), + section->type, section->virtual_address, section->size, section->offset, @@ -91,8 +91,8 @@ int main(int argc, char **argv) { fprintf(stdout, "" "%-20s " - "%-10s " - "%-10s " + "%d " + "%d " "0x%02x " "0x%02x" "0x%010" PRIx64 " " @@ -100,8 +100,8 @@ int main(int argc, char **argv) { "%-3s " "\n", symbol->name, - ELF_SYMBOL_TYPES_to_string(symbol->type), - SYMBOL_BINDINGS_to_string(symbol->binding), + symbol->type, + symbol->binding, symbol->other, symbol->shndx, symbol->value, @@ -128,8 +128,8 @@ int main(int argc, char **argv) { fprintf(stdout, "" "%-20s " - "%-10s " - "%-10s " + "%d " + "%d " "0x%02x " "0x%02x" "0x%010" PRIx64 " " @@ -137,8 +137,8 @@ int main(int argc, char **argv) { "%-3s " "\n", symbol->name, - ELF_SYMBOL_TYPES_to_string(symbol->type), - SYMBOL_BINDINGS_to_string(symbol->binding), + symbol->type, + symbol->binding, symbol->other, symbol->shndx, symbol->value, @@ -153,7 +153,7 @@ int main(int argc, char **argv) { for (i = 0; segments[i] != NULL; ++i) { Elf_Segment_t* segment = segments[i]; fprintf(stdout, "" - "%-20s " + "%d " "0x%06" PRIx32 " " "0x%010" PRIx64 " " "0x%06" PRIx64 " " @@ -161,7 +161,7 @@ int main(int argc, char **argv) { "0x%06" PRIx64 " " "0x%06" PRIx64 " " "\n", - SEGMENT_TYPES_to_string(segment->type), + segment->type, segment->flags, segment->virtual_address, segment->virtual_size, @@ -179,111 +179,100 @@ int main(int argc, char **argv) { for (i = 0; dynamic_entries[i] != NULL; ++i) { Elf_DynamicEntry_t* entry = dynamic_entries[i]; switch(entry->tag) { - case LIEF_ELF_DT_NEEDED: + case LIEF_DT_NEEDED: { Elf_DynamicEntry_Library_t* e = (Elf_DynamicEntry_Library_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " " "%-20s " "\n", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value, e->name ); break; } - case LIEF_ELF_DT_SONAME: + case LIEF_DT_SONAME: { Elf_DynamicEntry_SharedObject_t* e = (Elf_DynamicEntry_SharedObject_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " " "%-20s " "\n", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value, e->name ); break; } - case LIEF_ELF_DT_RPATH: + case LIEF_DT_RPATH: { Elf_DynamicEntry_Rpath_t* e = (Elf_DynamicEntry_Rpath_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " " "%-20s " "\n", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value, e->rpath ); break; } - case LIEF_ELF_DT_RUNPATH: + case LIEF_DT_RUNPATH: { Elf_DynamicEntry_RunPath_t* e = (Elf_DynamicEntry_RunPath_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " " "%-20s " "\n", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value, e->runpath ); break; } - case LIEF_ELF_DT_FLAGS: + case LIEF_DT_FLAGS: { Elf_DynamicEntry_Flags_t* e = (Elf_DynamicEntry_Flags_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " ", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value); - enum LIEF_ELF_DYNAMIC_FLAGS* flags = e->flags; - for (j = 0; flags[j] != 0; ++j) { - fprintf(stdout, "%s ", DYNAMIC_FLAGS_to_string(flags[j])); - } - fprintf(stdout, "\n"); break; } - case LIEF_ELF_DT_FLAGS_1: + case LIEF_DT_FLAGS_1: { Elf_DynamicEntry_Flags_t* e = (Elf_DynamicEntry_Flags_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " ", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value); - - enum LIEF_ELF_DYNAMIC_FLAGS_1* flags = e->flags_1; - for (j = 0; flags[j] != 0; ++j) { - fprintf(stdout, "%s ", DYNAMIC_FLAGS_1_to_string(flags[j])); - } - fprintf(stdout, "\n"); break; } - case LIEF_ELF_DT_INIT_ARRAY: - case LIEF_ELF_DT_FINI_ARRAY: - case LIEF_ELF_DT_PREINIT_ARRAY: + case LIEF_DT_INIT_ARRAY: + case LIEF_DT_FINI_ARRAY: + case LIEF_DT_PREINIT_ARRAY: { Elf_DynamicEntry_Array_t* e = (Elf_DynamicEntry_Array_t*)entry; fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " ", - DYNAMIC_TAGS_to_string(e->tag), + e->tag, e->value ); uint64_t* array = e->array; @@ -298,10 +287,10 @@ int main(int argc, char **argv) { default: { fprintf(stdout, "" - "%-20s " + "0x%010" PRIx64 " " "0x%010" PRIx64 " " "\n", - DYNAMIC_TAGS_to_string(entry->tag), + entry->tag, entry->value ); break; @@ -309,8 +298,6 @@ int main(int argc, char **argv) { } } - - elf_binary_destroy(elf_binary); return EXIT_SUCCESS; diff --git a/examples/cpp/elf_builder.cpp b/examples/cpp/elf_builder.cpp index 297aaa1fe6..a4c835dfe3 100644 --- a/examples/cpp/elf_builder.cpp +++ b/examples/cpp/elf_builder.cpp @@ -31,7 +31,7 @@ int main(int argc, char **argv) { std::unique_ptr binary = LIEF::ELF::Parser::parse(argv[1]); LIEF::ELF::Segment seg; - seg.type(LIEF::ELF::SEGMENT_TYPES::PT_LOAD); + seg.type(LIEF::ELF::Segment::TYPE::LOAD); //seg.content(std::vector(0x100)); //binary->add(seg); LIEF::logging::set_level(LIEF::logging::LOGGING_LEVEL::LOG_DEBUG); diff --git a/include/LIEF/Abstract/Header.hpp b/include/LIEF/Abstract/Header.hpp index 812cedc2ac..506bb3dce6 100644 --- a/include/LIEF/Abstract/Header.hpp +++ b/include/LIEF/Abstract/Header.hpp @@ -48,7 +48,7 @@ class LIEF_API Header : public Object { bool is_64() const; //! @brief Method so that the ``visitor`` can visit us - void accept(Visitor& visitor) const override; + void accept(Visitor& visitor) const override; void architecture(ARCHITECTURES arch); void modes(const std::set& m); diff --git a/include/LIEF/ELF.hpp b/include/LIEF/ELF.hpp index 5219aff423..98485874a1 100644 --- a/include/LIEF/ELF.hpp +++ b/include/LIEF/ELF.hpp @@ -40,7 +40,6 @@ #include "LIEF/ELF/GnuHash.hpp" #include "LIEF/ELF/Note.hpp" #include "LIEF/ELF/NoteDetails.hpp" -#include "LIEF/ELF/RelocationSizes.hpp" #include "LIEF/ELF/Symbol.hpp" #include "LIEF/ELF/SymbolVersion.hpp" #include "LIEF/ELF/SymbolVersionAux.hpp" diff --git a/include/LIEF/ELF/Binary.hpp b/include/LIEF/ELF/Binary.hpp index 85da9c5be7..a12b233167 100644 --- a/include/LIEF/ELF/Binary.hpp +++ b/include/LIEF/ELF/Binary.hpp @@ -26,7 +26,10 @@ #include "LIEF/Abstract/Binary.hpp" #include "LIEF/ELF/Note.hpp" +#include "LIEF/ELF/DynamicEntry.hpp" #include "LIEF/ELF/Header.hpp" +#include "LIEF/ELF/Section.hpp" +#include "LIEF/ELF/Segment.hpp" #include "LIEF/ELF/Builder.hpp" namespace LIEF { @@ -36,7 +39,6 @@ namespace DataHandler { class Handler; } -class DynamicEntry; class ExeLayout; class GnuHash; class Layout; @@ -226,11 +228,18 @@ class LIEF_API Binary : public LIEF::Binary { Binary(const Binary& copy) = delete; //! Return binary's class (ELF32 or ELF64) - ELF_CLASS type() const; + Header::CLASS type() const { + return type_; + } //! Return @link ELF::Header Elf header @endlink - Header& header(); - const Header& header() const; + Header& header() { + return header_; + } + + const Header& header() const { + return header_; + } //! Return the last offset used in binary //! according to sections table @@ -244,19 +253,36 @@ class LIEF_API Binary : public LIEF::Binary { uint64_t next_virtual_address() const; //! Return an iterator over the binary's sections - it_sections sections(); - it_const_sections sections() const; + it_sections sections() { + return sections_; + } + + it_const_sections sections() const { + return sections_; + } //! Return the binary's entrypoint - uint64_t entrypoint() const override; + uint64_t entrypoint() const override { + return header_.entrypoint(); + } //! Return binary's segments - it_segments segments(); - it_const_segments segments() const; + it_segments segments() { + return segments_; + } + + it_const_segments segments() const { + return segments_; + } //! Return binary's dynamic entries - it_dynamic_entries dynamic_entries(); - it_const_dynamic_entries dynamic_entries() const; + it_dynamic_entries dynamic_entries() { + return dynamic_entries_; + } + + it_const_dynamic_entries dynamic_entries() const { + return dynamic_entries_; + } //! Add the given dynamic entry and return the new entry DynamicEntry& add(const DynamicEntry& entry); @@ -268,7 +294,7 @@ class LIEF_API Binary : public LIEF::Binary { void remove(const DynamicEntry& entry); //! Remove **all** dynamic entries with the given tag - void remove(DYNAMIC_TAGS tag); + void remove(DynamicEntry::TAG tag); //! Remove the given section. The ``clear`` parameter //! can be used to zeroize the original content beforehand @@ -288,8 +314,12 @@ class LIEF_API Binary : public LIEF::Binary { //! Return an iterator over the binary's dynamic symbols //! The dynamic symbols are those located in the ``.dynsym`` section - it_dynamic_symbols dynamic_symbols(); - it_const_dynamic_symbols dynamic_symbols() const; + it_dynamic_symbols dynamic_symbols() { + return dynamic_symbols_; + } + it_const_dynamic_symbols dynamic_symbols() const { + return dynamic_symbols_; + } //! Return symbols which are exported by the binary it_exported_symbols exported_symbols(); @@ -300,20 +330,39 @@ class LIEF_API Binary : public LIEF::Binary { it_const_imported_symbols imported_symbols() const; //! Return statics symbols. - it_static_symbols static_symbols(); - it_const_static_symbols static_symbols() const; + it_static_symbols static_symbols() { + return static_symbols_; + } + + it_const_static_symbols static_symbols() const { + return static_symbols_; + } //! Return the symbol versions - it_symbols_version symbols_version(); - it_const_symbols_version symbols_version() const; + it_symbols_version symbols_version() { + return symbol_version_table_; + } + it_const_symbols_version symbols_version() const { + return symbol_version_table_; + } //! Return symbols version definition - it_symbols_version_definition symbols_version_definition(); - it_const_symbols_version_definition symbols_version_definition() const; + it_symbols_version_definition symbols_version_definition() { + return symbol_version_definition_; + } + + it_const_symbols_version_definition symbols_version_definition() const { + return symbol_version_definition_; + } //! Return Symbol version requirement - it_symbols_version_requirement symbols_version_requirement(); - it_const_symbols_version_requirement symbols_version_requirement() const; + it_symbols_version_requirement symbols_version_requirement() { + return symbol_version_requirements_; + } + + it_const_symbols_version_requirement symbols_version_requirement() const { + return symbol_version_requirements_; + } //! Return dynamic relocations it_dynamic_relocations dynamic_relocations(); @@ -350,8 +399,13 @@ class LIEF_API Binary : public LIEF::Binary { it_const_object_relocations object_relocations() const; //! Return **all** relocations present in the binary - it_relocations relocations(); - it_const_relocations relocations() const; + it_relocations relocations() { + return relocations_; + } + + it_const_relocations relocations() const { + return relocations_; + } //! Return relocation associated with the given address. //! It returns a ``nullptr`` if it is not found @@ -371,20 +425,28 @@ class LIEF_API Binary : public LIEF::Binary { //! ``true`` if GNU hash is used //! //! @see gnu_hash and use_sysv_hash - bool use_gnu_hash() const; + bool use_gnu_hash() const { + return gnu_hash_ != nullptr && has(DynamicEntry::TAG::GNU_HASH); + } //! Return the GnuHash object in **readonly** //! If the ELF binary does not use the GNU hash table, return a nullptr - const GnuHash* gnu_hash() const; + const GnuHash* gnu_hash() const { + return use_gnu_hash() ? gnu_hash_.get() : nullptr; + } //! ``true`` if SYSV hash is used //! //! @see sysv_hash and use_gnu_hash - bool use_sysv_hash() const; + bool use_sysv_hash() const { + return sysv_hash_ != nullptr && has(DynamicEntry::TAG::HASH); + } //! Return the SysvHash object as a **read-only** object //! If the ELF binary does not use the legacy sysv hash table, return a nullptr - const SysvHash* sysv_hash() const; + const SysvHash* sysv_hash() const { + return use_sysv_hash() ? sysv_hash_.get() : nullptr; + } //! Check if a section with the given name exists in the binary bool has_section(const std::string& name) const; @@ -402,7 +464,9 @@ class LIEF_API Binary : public LIEF::Binary { //! Return the `.text` section. If the section //! can't be found, it returns a nullptr - Section* text_section(); + Section* text_section() { + return get_section(".text"); + } //! Return the `.dynamic` section. If the section //! can't be found, it returns a nullptr @@ -439,8 +503,13 @@ class LIEF_API Binary : public LIEF::Binary { void interpreter(const std::string& interpreter); //! Return an iterator on both static and dynamic symbols - it_symbols symbols(); - it_const_symbols symbols() const; + it_symbols symbols() { + return static_dyn_symbols(); + } + + it_const_symbols symbols() const { + return static_dyn_symbols(); + } //! Export the given symbol and create it if it doesn't exist Symbol& export_symbol(const Symbol& symbol); @@ -672,8 +741,8 @@ class LIEF_API Binary : public LIEF::Binary { Segment* segment_from_virtual_address(uint64_t address); - const Segment* segment_from_virtual_address(SEGMENT_TYPES type, uint64_t address) const; - Segment* segment_from_virtual_address(SEGMENT_TYPES type, uint64_t address); + const Segment* segment_from_virtual_address(Segment::TYPE type, uint64_t address) const; + Segment* segment_from_virtual_address(Segment::TYPE type, uint64_t address); //! Return the ELF::Segment from the @p offset. Return a nullptr //! if a segment can't be found. @@ -682,13 +751,15 @@ class LIEF_API Binary : public LIEF::Binary { //! Return the **first** ELF::DynamicEntry associated with the given tag //! If the tag can't be found, it returns a nullptr - const DynamicEntry* get(DYNAMIC_TAGS tag) const; - DynamicEntry* get(DYNAMIC_TAGS tag); + const DynamicEntry* get(DynamicEntry::TAG tag) const; + DynamicEntry* get(DynamicEntry::TAG tag) { + return const_cast(static_cast(this)->get(tag)); + } //! Return the **first** ELF::Segment associated with the given type. //! If a segment can't be found, it returns a nullptr. - const Segment* get(SEGMENT_TYPES type) const; - Segment* get(SEGMENT_TYPES type); + const Segment* get(Segment::TYPE type) const; + Segment* get(Segment::TYPE type); //! Return the **first** ELF::Note associated with the given type //! If a note can't be found, it returns a nullptr. @@ -697,20 +768,28 @@ class LIEF_API Binary : public LIEF::Binary { //! Return the **first** ELF::Section associated with the given type //! If a section can't be found, it returns a nullptr. - const Section* get(ELF_SECTION_TYPES type) const; - Section* get(ELF_SECTION_TYPES type); + const Section* get(Section::TYPE type) const; + Section* get(Section::TYPE type); //! Check if an ELF::DynamicEntry associated with the given tag exists. - bool has(DYNAMIC_TAGS tag) const; + bool has(DynamicEntry::TAG tag) const { + return get(tag) != nullptr; + } //! Check if ELF::Segment associated with the given type exists. - bool has(SEGMENT_TYPES type) const; + bool has(Segment::TYPE type) const { + return get(type) != nullptr; + } //! Check if a ELF::Note associated with the given type exists. - bool has(Note::TYPE type) const; + bool has(Note::TYPE type) const { + return get(type) != nullptr; + } //! Check if a ELF::Section associated with the given type exists. - bool has(ELF_SECTION_TYPES type) const; + bool has(Section::TYPE type) const { + return get(type) != nullptr; + } //! Return the content located at virtual address span get_content_from_virtual_address(uint64_t virtual_address, uint64_t size, @@ -737,9 +816,13 @@ class LIEF_API Binary : public LIEF::Binary { //! Return an iterator over the ELF's LIEF::ELF::Note //! //! @see has_note - it_const_notes notes() const; + it_const_notes notes() const { + return notes_; + } - it_notes notes(); + it_notes notes() { + return notes_; + } //! Return the last offset used by the ELF binary according to both: the sections table //! and the segments table @@ -777,28 +860,76 @@ class LIEF_API Binary : public LIEF::Binary { std::ostream& print(std::ostream& os) const override; - Binary& operator+=(const DynamicEntry& entry); - Binary& operator+=(const Section& section); - Binary& operator+=(const Segment& segment); - Binary& operator+=(const Note& note); + Binary& operator+=(const DynamicEntry& entry) { + add(entry); + return *this; + } + Binary& operator+=(const Section& section) { + add(section); + return *this; + } + + Binary& operator+=(const Segment& segment) { + add(segment); + return *this; + } + + Binary& operator+=(const Note& note) { + add(note); + return *this; + } + + Binary& operator-=(const DynamicEntry& entry) { + remove(entry); + return *this; + } - Binary& operator-=(const DynamicEntry& entry); - Binary& operator-=(DYNAMIC_TAGS tag); + Binary& operator-=(DynamicEntry::TAG tag) { + remove(tag); + return *this; + } - Binary& operator-=(const Note& note); - Binary& operator-=(Note::TYPE type); + Binary& operator-=(const Note& note) { + remove(note); + return *this; + } - Segment* operator[](SEGMENT_TYPES type); - const Segment* operator[](SEGMENT_TYPES type) const; + Binary& operator-=(Note::TYPE type) { + remove(type); + return *this; + } - DynamicEntry* operator[](DYNAMIC_TAGS tag); - const DynamicEntry* operator[](DYNAMIC_TAGS tag) const; + Segment* operator[](Segment::TYPE type) { + return get(type); + } - Note* operator[](Note::TYPE type); - const Note* operator[](Note::TYPE type) const; + const Segment* operator[](Segment::TYPE type) const { + return get(type); + } + + DynamicEntry* operator[](DynamicEntry::TAG tag) { + return get(tag); + } - Section* operator[](ELF_SECTION_TYPES type); - const Section* operator[](ELF_SECTION_TYPES type) const; + const DynamicEntry* operator[](DynamicEntry::TAG tag) const { + return get(tag); + } + + Note* operator[](Note::TYPE type) { + return get(type); + } + + const Note* operator[](Note::TYPE type) const { + return get(type); + } + + Section* operator[](Section::TYPE type) { + return get(type); + } + + const Section* operator[](Section::TYPE type) const { + return get(type); + } protected: struct phdr_relocation_info_t { @@ -840,7 +971,7 @@ class LIEF_API Binary : public LIEF::Binary { LIEF::Binary::functions_t eh_frame_functions() const; LIEF::Binary::functions_t armexid_functions() const; - template + template Segment* add_segment(const Segment& segment, uint64_t base); uint64_t relocate_phdr_table_auto(); @@ -849,7 +980,7 @@ class LIEF_API Binary : public LIEF::Binary { uint64_t relocate_phdr_table_v2(); uint64_t relocate_phdr_table_v3(); - template + template Segment* extend_segment(const Segment& segment, uint64_t size); template @@ -859,9 +990,9 @@ class LIEF_API Binary : public LIEF::Binary { std::string shstrtab_name() const; Section* add_frame_section(const Section& sec); - LIEF::Binary::functions_t tor_functions(DYNAMIC_TAGS tag) const; + LIEF::Binary::functions_t tor_functions(DynamicEntry::TAG tag) const; - ELF_CLASS type_ = ELF_CLASS::ELFCLASSNONE; + Header::CLASS type_ = Header::CLASS::NONE; Header header_; sections_t sections_; segments_t segments_; diff --git a/include/LIEF/ELF/DynamicEntry.hpp b/include/LIEF/ELF/DynamicEntry.hpp index a2e00b13e8..8d38087d1d 100644 --- a/include/LIEF/ELF/DynamicEntry.hpp +++ b/include/LIEF/ELF/DynamicEntry.hpp @@ -17,12 +17,12 @@ #define LIEF_ELF_DYNAMIC_ENTRY_H #include -#include #include +#include +#include #include "LIEF/visibility.h" #include "LIEF/Object.hpp" - #include "LIEF/ELF/enums.hpp" namespace LIEF { @@ -36,40 +36,204 @@ struct Elf32_Dyn; //! These entries are located in the ``.dynamic`` section or the ``PT_DYNAMIC`` segment class LIEF_API DynamicEntry : public Object { public: + static constexpr uint64_t MIPS_DISC = 0x100000000; + static constexpr uint64_t AARCH64_DISC = 0x200000000; + static constexpr uint64_t HEXAGON_DISC = 0x300000000; + static constexpr uint64_t PPC_DISC = 0x400000000; + static constexpr uint64_t PPC64_DISC = 0x500000000; + static constexpr uint64_t RISCV_DISC = 0x600000000; + + enum class TAG : uint64_t { + UNKNOWN = uint64_t(-1), + DT_NULL = 0, /**< Marks end of dynamic array. */ + NEEDED = 1, /**< String table offset of needed library. */ + PLTRELSZ = 2, /**< Size of relocation entries in PLT. */ + PLTGOT = 3, /**< Address associated with linkage table. */ + HASH = 4, /**< Address of symbolic hash table. */ + STRTAB = 5, /**< Address of dynamic string table. */ + SYMTAB = 6, /**< Address of dynamic symbol table. */ + RELA = 7, /**< Address of relocation table (Rela entries). */ + RELASZ = 8, /**< Size of Rela relocation table. */ + RELAENT = 9, /**< Size of a Rela relocation entry. */ + STRSZ = 10,/**< Total size of the string table. */ + SYMENT = 11,/**< Size of a symbol table entry. */ + INIT = 12,/**< Address of initialization function. */ + FINI = 13,/**< Address of termination function. */ + SONAME = 14,/**< String table offset of a shared objects name. */ + RPATH = 15,/**< String table offset of library search path. */ + SYMBOLIC = 16,/**< Changes symbol resolution algorithm. */ + REL = 17,/**< Address of relocation table (Rel entries). */ + RELSZ = 18,/**< Size of Rel relocation table. */ + RELENT = 19,/**< Size of a Rel relocation entry. */ + PLTREL = 20,/**< Type of relocation entry used for linking. */ + DEBUG = 21,/**< Reserved for debugger. */ + TEXTREL = 22,/**< Relocations exist for non-writable segments. */ + JMPREL = 23,/**< Address of relocations associated with PLT. */ + BIND_NOW = 24,/**< Process all relocations before execution. */ + INIT_ARRAY = 25,/**< Pointer to array of initialization functions. */ + FINI_ARRAY = 26,/**< Pointer to array of termination functions. */ + INIT_ARRAYSZ = 27,/**< Size of DT_INIT_ARRAY. */ + FINI_ARRAYSZ = 28,/**< Size of DT_FINI_ARRAY. */ + RUNPATH = 29,/**< String table offset of lib search path. */ + FLAGS = 30,/**< Flags. */ + PREINIT_ARRAY = 32,/**< Pointer to array of preinit functions. */ + PREINIT_ARRAYSZ = 33,/**< Size of the DT_PREINIT_ARRAY array. */ + SYMTAB_SHNDX = 34,/**< Address of SYMTAB_SHNDX section */ + RELRSZ = 35,/**< Total size of RELR relative relocations */ + RELR = 36,/**< Address of RELR relative relocations */ + RELRENT = 37,/**< Size of one RELR relative relocaction */ + + // GNU Extensions + GNU_HASH = 0x6FFFFEF5, /**< Reference to the GNU hash table. */ + RELACOUNT = 0x6FFFFFF9, /**< ELF32_Rela count. */ + RELCOUNT = 0x6FFFFFFA, /**< ELF32_Rel count. */ + FLAGS_1 = 0x6FFFFFFB, /**< Flags_1. */ + VERSYM = 0x6FFFFFF0, /**< The address of .gnu.version section. */ + VERDEF = 0x6FFFFFFC, /**< The address of the version definition table. */ + VERDEFNUM = 0x6FFFFFFD, /**< The number of entries in DT_VERDEF. */ + VERNEED = 0x6FFFFFFE, /**< The address of the version Dependency table. */ + VERNEEDNUM = 0x6FFFFFFF, /**< The number of entries in DT_VERNEED. */ + + // Android Extensions + ANDROID_REL_OFFSET = 0x6000000D, /**< The offset of packed relocation data (older version < M) (Android specific). */ + ANDROID_REL_SIZE = 0x6000000E, /**< The size of packed relocation data in bytes (older version < M) (Android specific). */ + ANDROID_REL = 0x6000000F, /**< The offset of packed relocation data (Android specific). */ + ANDROID_RELSZ = 0x60000010, /**< The size of packed relocation data in bytes (Android specific). */ + ANDROID_RELA = 0x60000011, /**< The offset of packed relocation data (Android specific). */ + ANDROID_RELASZ = 0x60000012, /**< The size of packed relocation data in bytes (Android specific). */ + ANDROID_RELR = 0x6FFFE000, /**< The offset of new relr relocation data (Android specific). */ + ANDROID_RELRSZ = 0x6FFFE001, /**< The size of nre relr relocation data in bytes (Android specific). */ + ANDROID_RELRENT = 0x6FFFE003, /**< The size of a new relr relocation entry (Android specific). */ + ANDROID_RELRCOUNT = 0x6FFFE005, /**< Specifies the relative count of new relr relocation entries (Android specific). */ + + /* Mips specific dynamic table entry tags. */ + MIPS_RLD_VERSION = MIPS_DISC + 0x70000001, /**< 32 bit version number for runtime linker interface. */ + MIPS_TIME_STAMP = MIPS_DISC + 0x70000002, /**< Time stamp. */ + MIPS_ICHECKSUM = MIPS_DISC + 0x70000003, /**< Checksum of external strings and common sizes. */ + MIPS_IVERSION = MIPS_DISC + 0x70000004, /**< Index of version string in string table. */ + MIPS_FLAGS = MIPS_DISC + 0x70000005, /**< 32 bits of flags. */ + MIPS_BASE_ADDRESS = MIPS_DISC + 0x70000006, /**< Base address of the segment. */ + MIPS_MSYM = MIPS_DISC + 0x70000007, /**< Address of .msym section. */ + MIPS_CONFLICT = MIPS_DISC + 0x70000008, /**< Address of .conflict section. */ + MIPS_LIBLIST = MIPS_DISC + 0x70000009, /**< Address of .liblist section. */ + MIPS_LOCAL_GOTNO = MIPS_DISC + 0x7000000a, /**< Number of local global offset table entries. */ + MIPS_CONFLICTNO = MIPS_DISC + 0x7000000b, /**< Number of entries in the .conflict section. */ + MIPS_LIBLISTNO = MIPS_DISC + 0x70000010, /**< Number of entries in the .liblist section. */ + MIPS_SYMTABNO = MIPS_DISC + 0x70000011, /**< Number of entries in the .dynsym section. */ + MIPS_UNREFEXTNO = MIPS_DISC + 0x70000012, /**< Index of first external dynamic symbol not referenced locally. */ + MIPS_GOTSYM = MIPS_DISC + 0x70000013, /**< Index of first dynamic symbol in global offset table. */ + MIPS_HIPAGENO = MIPS_DISC + 0x70000014, /**< Number of page table entries in global offset table. */ + MIPS_RLD_MAP = MIPS_DISC + 0x70000016, /**< Address of run time loader map, used for debugging. */ + MIPS_DELTA_CLASS = MIPS_DISC + 0x70000017, /**< Delta C++ class definition. */ + MIPS_DELTA_CLASS_NO = MIPS_DISC + 0x70000018, /**< Number of entries in DT_MIPS_DELTA_CLASS. */ + MIPS_DELTA_INSTANCE = MIPS_DISC + 0x70000019, /**< Delta C++ class instances. */ + MIPS_DELTA_INSTANCE_NO = MIPS_DISC + 0x7000001A, /**< Number of entries in DT_MIPS_DELTA_INSTANCE. */ + MIPS_DELTA_RELOC = MIPS_DISC + 0x7000001B, /**< Delta relocations. */ + MIPS_DELTA_RELOC_NO = MIPS_DISC + 0x7000001C, /**< Number of entries in DT_MIPS_DELTA_RELOC. */ + MIPS_DELTA_SYM = MIPS_DISC + 0x7000001D, /**< Delta symbols that Delta relocations refer to. */ + MIPS_DELTA_SYM_NO = MIPS_DISC + 0x7000001E, /**< Number of entries in DT_MIPS_DELTA_SYM. */ + MIPS_DELTA_CLASSSYM = MIPS_DISC + 0x70000020, /**< Delta symbols that hold class declarations. */ + MIPS_DELTA_CLASSSYM_NO = MIPS_DISC + 0x70000021, /**< Number of entries in DT_MIPS_DELTA_CLASSSYM. */ + MIPS_CXX_FLAGS = MIPS_DISC + 0x70000022, /**< Flags indicating information about C++ flavor. */ + MIPS_PIXIE_INIT = MIPS_DISC + 0x70000023, /**< Pixie information. */ + MIPS_SYMBOL_LIB = MIPS_DISC + 0x70000024, /**< Address of .MIPS.symlib */ + MIPS_LOCALPAGE_GOTIDX = MIPS_DISC + 0x70000025, /**< The GOT index of the first PTE for a segment */ + MIPS_LOCAL_GOTIDX = MIPS_DISC + 0x70000026, /**< The GOT index of the first PTE for a local symbol */ + MIPS_HIDDEN_GOTIDX = MIPS_DISC + 0x70000027, /**< The GOT index of the first PTE for a hidden symbol */ + MIPS_PROTECTED_GOTIDX = MIPS_DISC + 0x70000028, /**< The GOT index of the first PTE for a protected symbol */ + MIPS_OPTIONS = MIPS_DISC + 0x70000029, /**< Address of `.MIPS.options'. */ + MIPS_INTERFACE = MIPS_DISC + 0x7000002A, /**< Address of `.interface'. */ + MIPS_DYNSTR_ALIGN = MIPS_DISC + 0x7000002B, /**< Unknown. */ + MIPS_INTERFACE_SIZE = MIPS_DISC + 0x7000002C, /**< Size of the .interface section. */ + MIPS_RLD_TEXT_RESOLVE_ADDR = MIPS_DISC + 0x7000002D, /**< Size of rld_text_resolve function stored in the GOT. */ + MIPS_PERF_SUFFIX = MIPS_DISC + 0x7000002E, /**< Default suffix of DSO to be added by rld on dlopen() calls. */ + MIPS_COMPACT_SIZE = MIPS_DISC + 0x7000002F, /**< Size of compact relocation section (O32). */ + MIPS_GP_VALUE = MIPS_DISC + 0x70000030, /**< GP value for auxiliary GOTs. */ + MIPS_AUX_DYNAMIC = MIPS_DISC + 0x70000031, /**< Address of auxiliary .dynamic. */ + MIPS_PLTGOT = MIPS_DISC + 0x70000032, /**< Address of the base of the PLTGOT. */ + MIPS_RWPLT = MIPS_DISC + 0x70000034, + MIPS_RLD_MAP_REL = MIPS_DISC + 0x70000035, + MIPS_XHASH = MIPS_DISC + 0x70000036, + + AARCH64_BTI_PLT = AARCH64_DISC + 0x70000001, + AARCH64_PAC_PLT = AARCH64_DISC + 0x70000003, + AARCH64_VARIANT_PCS = AARCH64_DISC + 0x70000005, + AARCH64_MEMTAG_MODE = AARCH64_DISC + 0x70000009, + AARCH64_MEMTAG_HEAP = AARCH64_DISC + 0x7000000b, + AARCH64_MEMTAG_STACK = AARCH64_DISC + 0x7000000c, + AARCH64_MEMTAG_GLOBALS = AARCH64_DISC + 0x7000000d, + AARCH64_MEMTAG_GLOBALSSZ = AARCH64_DISC + 0x7000000f, + + HEXAGON_SYMSZ = HEXAGON_DISC + 0x70000000, + HEXAGON_VER = HEXAGON_DISC + 0x70000001, + HEXAGON_PLT = HEXAGON_DISC + 0x70000002, + + PPC_GOT = PPC_DISC + 0x70000000, + PPC_OPT = PPC_DISC + 0x70000001, + + PPC64_GLINK = PPC64_DISC + 0x70000000, + PPC64_OPT = PPC64_DISC + 0x70000003, - DynamicEntry(const details::Elf64_Dyn& header); - DynamicEntry(const details::Elf32_Dyn& header); - DynamicEntry(); - DynamicEntry(DYNAMIC_TAGS tag, uint64_t value); + RISCV_VARIANT_CC = RISCV_DISC + 0x70000003, + }; - DynamicEntry& operator=(const DynamicEntry&); - DynamicEntry(const DynamicEntry&); - ~DynamicEntry() override; + static TAG from_value(uint64_t value, ARCH arch); + static uint64_t to_value(TAG tag); + + DynamicEntry() = default; + DynamicEntry(const details::Elf64_Dyn& header, ARCH arch); + DynamicEntry(const details::Elf32_Dyn& header, ARCH arch); + + DynamicEntry(TAG tag, uint64_t value) : + tag_(tag), value_(value) + {} + + DynamicEntry& operator=(const DynamicEntry&) = default; + DynamicEntry(const DynamicEntry&) = default; + ~DynamicEntry() override = default; + + virtual std::unique_ptr clone() const { + return std::unique_ptr(new DynamicEntry(*this)); + } //! Tag of the current entry. The most common tags are: //! DT_NEEDED, DT_INIT, ... - DYNAMIC_TAGS tag() const; + TAG tag() const { + return tag_; + } //! Return the entry's value //! //! The meaning of the value strongly depends on the tag. //! It can be an offset, an index, a flag, ... - uint64_t value() const; + uint64_t value() const { + return value_; + } - void tag(DYNAMIC_TAGS tag); - void value(uint64_t value); + void tag(TAG tag) { + tag_ = tag; + } + + void value(uint64_t value) { + value_ = value; + } void accept(Visitor& visitor) const override; virtual std::ostream& print(std::ostream& os) const; - - LIEF_API friend std::ostream& operator<<(std::ostream& os, const DynamicEntry& entry); + LIEF_API friend + std::ostream& operator<<(std::ostream& os, const DynamicEntry& entry) { + return entry.print(os); + } protected: - DYNAMIC_TAGS tag_; - uint64_t value_; + TAG tag_ = TAG::DT_NULL; + uint64_t value_ = 0; }; + +LIEF_API const char* to_string(DynamicEntry::TAG e); + } } #endif diff --git a/include/LIEF/ELF/DynamicEntryArray.hpp b/include/LIEF/ELF/DynamicEntryArray.hpp index df003024b5..9f64a99538 100644 --- a/include/LIEF/ELF/DynamicEntryArray.hpp +++ b/include/LIEF/ELF/DynamicEntryArray.hpp @@ -19,6 +19,8 @@ #include "LIEF/visibility.h" #include "LIEF/ELF/DynamicEntry.hpp" +#include + namespace LIEF { namespace ELF { @@ -33,36 +35,57 @@ namespace ELF { class LIEF_API DynamicEntryArray : public DynamicEntry { public: using array_t = std::vector; - - public: using DynamicEntry::DynamicEntry; - DynamicEntryArray(); - DynamicEntryArray(DYNAMIC_TAGS tag, array_t array); + DynamicEntryArray() = delete; + DynamicEntryArray(DynamicEntry::TAG tag, array_t array) : + DynamicEntry(tag, 0), + array_(std::move(array)) + {} - DynamicEntryArray& operator=(const DynamicEntryArray&); - DynamicEntryArray(const DynamicEntryArray&); + DynamicEntryArray& operator=(const DynamicEntryArray&) = default; + DynamicEntryArray(const DynamicEntryArray&) = default; - //! Return the array values (list of pointer) - array_t& array(); + std::unique_ptr clone() const override { + return std::unique_ptr(new DynamicEntryArray(*this)); + } - const array_t& array() const; - void array(const array_t& array); + //! Return the array values (list of pointers) + array_t& array() { + return array_; + } + + const array_t& array() const { + return array_; + } + void array(const array_t& array) { + array_ = array; + } //! Insert the given function at ``pos`` DynamicEntryArray& insert(size_t pos, uint64_t function); //! Append the given function - DynamicEntryArray& append(uint64_t function); + DynamicEntryArray& append(uint64_t function) { + array_.push_back(function); + return *this; + } //! Remove the given function DynamicEntryArray& remove(uint64_t function); //! Number of function registred in this array - size_t size() const; + size_t size() const { + return array_.size(); + } + + DynamicEntryArray& operator+=(uint64_t value) { + return append(value); + } - DynamicEntryArray& operator+=(uint64_t value); - DynamicEntryArray& operator-=(uint64_t value); + DynamicEntryArray& operator-=(uint64_t value) { + return remove(value); + } const uint64_t& operator[](size_t idx) const; uint64_t& operator[](size_t idx); @@ -71,13 +94,17 @@ class LIEF_API DynamicEntryArray : public DynamicEntry { std::ostream& print(std::ostream& os) const override; - ~DynamicEntryArray() override; + ~DynamicEntryArray() override = default; - static bool classof(const DynamicEntry* entry); + static bool classof(const DynamicEntry* entry) { + const DynamicEntry::TAG tag = entry->tag(); + return tag == DynamicEntry::TAG::INIT_ARRAY || + tag == DynamicEntry::TAG::FINI_ARRAY || + tag == DynamicEntry::TAG::PREINIT_ARRAY; + } private: array_t array_; - }; } } diff --git a/include/LIEF/ELF/DynamicEntryFlags.hpp b/include/LIEF/ELF/DynamicEntryFlags.hpp index 5aff1c25ff..3c80c5b3fe 100644 --- a/include/LIEF/ELF/DynamicEntryFlags.hpp +++ b/include/LIEF/ELF/DynamicEntryFlags.hpp @@ -16,7 +16,7 @@ #ifndef LIEF_ELF_DYNAMIC_ENTRY_FLAGS_H #define LIEF_ELF_DYNAMIC_ENTRY_FLAGS_H -#include +#include #include #include "LIEF/visibility.h" @@ -26,51 +26,109 @@ namespace LIEF { namespace ELF { class LIEF_API DynamicEntryFlags : public DynamicEntry { - public: - using flags_list_t = std::set; + static constexpr uint64_t BASE = 0x100000000; + + enum class FLAG : uint64_t { + ORIGIN = 0x00000001, /**< The object may reference $ORIGIN. */ + SYMBOLIC = 0x00000002, /**< Search the shared lib before searching the exe. */ + TEXTREL = 0x00000004, /**< Relocations may modify a non-writable segment. */ + BIND_NOW = 0x00000008, /**< Process all relocations on load. */ + STATIC_TLS = 0x00000010, /**< Reject attempts to load dynamically. */ + + NOW = BASE + 0x000000001, /**< Set RTLD_NOW for this object. */ + GLOBAL = BASE + 0x000000002, /**< Set RTLD_GLOBAL for this object. */ + GROUP = BASE + 0x000000004, /**< Set RTLD_GROUP for this object. */ + NODELETE = BASE + 0x000000008, /**< Set RTLD_NODELETE for this object. */ + LOADFLTR = BASE + 0x000000010, /**< Trigger filtee loading at runtime. */ + INITFIRST = BASE + 0x000000020, /**< Set RTLD_INITFIRST for this object. */ + NOOPEN = BASE + 0x000000040, /**< Set RTLD_NOOPEN for this object. */ + HANDLE_ORIGIN = BASE + 0x000000080, /**< $ORIGIN must be handled. */ + DIRECT = BASE + 0x000000100, /**< Direct binding enabled. */ + TRANS = BASE + 0x000000200, + INTERPOSE = BASE + 0x000000400, /**< Object is used to interpose. */ + NODEFLIB = BASE + 0x000000800, /**< Ignore default lib search path. */ + NODUMP = BASE + 0x000001000, /**< Object can't be dldump'ed. */ + CONFALT = BASE + 0x000002000, /**< Configuration alternative created. */ + ENDFILTEE = BASE + 0x000004000, /**< Filtee terminates filters search. */ + DISPRELDNE = BASE + 0x000008000, /**< Disp reloc applied at build time. */ + DISPRELPND = BASE + 0x000010000, /**< Disp reloc applied at run-time. */ + NODIRECT = BASE + 0x000020000, /**< Object has no-direct binding. */ + IGNMULDEF = BASE + 0x000040000, + NOKSYMS = BASE + 0x000080000, + NOHDR = BASE + 0x000100000, + EDITED = BASE + 0x000200000, /**< Object is modified after built. */ + NORELOC = BASE + 0x000400000, + SYMINTPOSE = BASE + 0x000800000, /**< Object has individual interposers. */ + GLOBAUDIT = BASE + 0x001000000, /**< Global auditing required. */ + SINGLETON = BASE + 0x002000000, /**< Singleton symbols are used. */ + PIE = BASE + 0x008000000, /**< Singleton symbols are used. */ + KMOD = BASE + 0x010000000, + WEAKFILTER = BASE + 0x020000000, + NOCOMMON = BASE + 0x040000000, + }; + + using flags_list_t = std::vector; public: using DynamicEntry::DynamicEntry; - DynamicEntryFlags(); + DynamicEntryFlags() = delete; - DynamicEntryFlags& operator=(const DynamicEntryFlags&); - DynamicEntryFlags(const DynamicEntryFlags&); + static DynamicEntryFlags create_dt_flag(uint64_t value) { + return DynamicEntryFlags(DynamicEntry::TAG::FLAGS, value); + } - //! If the current entry has the given DYNAMIC_FLAGS - bool has(DYNAMIC_FLAGS f) const; + static DynamicEntryFlags create_dt_flag_1(uint64_t value) { + return DynamicEntryFlags(DynamicEntry::TAG::FLAGS_1, value); + } - //! If the current entry has the given DYNAMIC_FLAGS_1 - bool has(DYNAMIC_FLAGS_1 f) const; + DynamicEntryFlags& operator=(const DynamicEntryFlags&) = default; + DynamicEntryFlags(const DynamicEntryFlags&) = default; - //! Return flags as a list of integers - flags_list_t flags() const; + std::unique_ptr clone() const override { + return std::unique_ptr(new DynamicEntryFlags(*this)); + } - //! Add the given DYNAMIC_FLAGS - void add(DYNAMIC_FLAGS f); + //! If the current entry has the given FLAG + bool has(FLAG f) const; - //! Add the given DYNAMIC_FLAGS_1 - void add(DYNAMIC_FLAGS_1 f); + //! Return flags as a list of integers + flags_list_t flags() const; - //! Remove the given DYNAMIC_FLAGS - void remove(DYNAMIC_FLAGS f); + //! Add the given FLAG + void add(FLAG f); - //! Remove the given DYNAMIC_FLAGS_1 - void remove(DYNAMIC_FLAGS_1 f); + //! Remove the given FLAG + void remove(FLAG f); - DynamicEntryFlags& operator+=(DYNAMIC_FLAGS f); - DynamicEntryFlags& operator+=(DYNAMIC_FLAGS_1 f); + DynamicEntryFlags& operator+=(FLAG f) { + add(f); + return *this; + } - DynamicEntryFlags& operator-=(DYNAMIC_FLAGS f); - DynamicEntryFlags& operator-=(DYNAMIC_FLAGS_1 f); + DynamicEntryFlags& operator-=(FLAG f) { + remove(f); + return *this; + } - //! Method so that the ``visitor`` can visit us void accept(Visitor& visitor) const override; - static bool classof(const DynamicEntry* entry); + static bool classof(const DynamicEntry* entry) { + return entry->tag() == DynamicEntry::TAG::FLAGS || + entry->tag() == DynamicEntry::TAG::FLAGS_1; + } + + ~DynamicEntryFlags() = default; std::ostream& print(std::ostream& os) const override; + private: + DynamicEntryFlags(DynamicEntry::TAG tag, uint64_t flags) : + DynamicEntry(tag, flags) + {} }; + +LIEF_API const char* to_string(DynamicEntryFlags::FLAG e); + } } diff --git a/include/LIEF/ELF/DynamicEntryLibrary.hpp b/include/LIEF/ELF/DynamicEntryLibrary.hpp index 080ab9ec96..a0940e504a 100644 --- a/include/LIEF/ELF/DynamicEntryLibrary.hpp +++ b/include/LIEF/ELF/DynamicEntryLibrary.hpp @@ -17,10 +17,7 @@ #define LIEF_ELF_DYNAMIC_ENTRY_LIBRARY_H #include -#include - #include "LIEF/visibility.h" - #include "LIEF/ELF/DynamicEntry.hpp" namespace LIEF { @@ -34,17 +31,34 @@ class LIEF_API DynamicEntryLibrary : public DynamicEntry { public: using DynamicEntry::DynamicEntry; - DynamicEntryLibrary(); - DynamicEntryLibrary(std::string name); + DynamicEntryLibrary() : + DynamicEntry::DynamicEntry{DynamicEntry::TAG::NEEDED, 0} + {} + + DynamicEntryLibrary(std::string name) : + DynamicEntry::DynamicEntry{DynamicEntry::TAG::NEEDED, 0}, + libname_(std::move(name)) + {} - DynamicEntryLibrary& operator=(const DynamicEntryLibrary&); - DynamicEntryLibrary(const DynamicEntryLibrary&); + DynamicEntryLibrary& operator=(const DynamicEntryLibrary&) = default; + DynamicEntryLibrary(const DynamicEntryLibrary&) = default; + + std::unique_ptr clone() const override { + return std::unique_ptr(new DynamicEntryLibrary{*this}); + } //! Return the library associated with this entry (e.g. ``libc.so.6``) - const std::string& name() const; - void name(const std::string& name); + const std::string& name() const { + return libname_; + } + + void name(std::string name) { + libname_ = std::move(name); + } - static bool classof(const DynamicEntry* entry); + static bool classof(const DynamicEntry* entry) { + return entry->tag() == DynamicEntry::TAG::NEEDED; + } void accept(Visitor& visitor) const override; diff --git a/include/LIEF/ELF/DynamicEntryRpath.hpp b/include/LIEF/ELF/DynamicEntryRpath.hpp index 9887271286..9e4d544756 100644 --- a/include/LIEF/ELF/DynamicEntryRpath.hpp +++ b/include/LIEF/ELF/DynamicEntryRpath.hpp @@ -17,9 +17,9 @@ #define LIEF_ELF_DYNAMIC_ENTRY_RPATH_H #include +#include #include "LIEF/visibility.h" - #include "LIEF/ELF/DynamicEntry.hpp" namespace LIEF { @@ -28,27 +28,40 @@ namespace ELF { //! Class which represents a ``DT_RPATH`` entry. This attribute is //! deprecated (cf. ``man ld``) in favour of ``DT_RUNPATH`` (See DynamicRunPath) class LIEF_API DynamicEntryRpath : public DynamicEntry { - public: static constexpr char delimiter = ':'; using DynamicEntry::DynamicEntry; - DynamicEntryRpath(); + DynamicEntryRpath() : + DynamicEntry::DynamicEntry(DynamicEntry::TAG::RPATH, 0) + {} - DynamicEntryRpath(std::string rpath); + DynamicEntryRpath(std::string rpath) : + DynamicEntry::DynamicEntry(DynamicEntry::TAG::RPATH, 0), + rpath_(std::move(rpath)) + {} //! Constructor from a list of paths - DynamicEntryRpath(const std::vector& paths); + DynamicEntryRpath(const std::vector& paths) : + DynamicEntry::DynamicEntry(DynamicEntry::TAG::RPATH, 0) + { + this->paths(paths); + } - DynamicEntryRpath& operator=(const DynamicEntryRpath&); - DynamicEntryRpath(const DynamicEntryRpath&); + DynamicEntryRpath& operator=(const DynamicEntryRpath&) = default; + DynamicEntryRpath(const DynamicEntryRpath&) = default; - //! The actual rpath as a string - const std::string& name() const; - void name(const std::string& name); + std::unique_ptr clone() const override { + return std::unique_ptr(new DynamicEntryRpath(*this)); + } //! The actual rpath as a string - const std::string& rpath() const; - void rpath(const std::string& name); + const std::string& rpath() const { + return rpath_; + } + + void rpath(const std::string& name) { + rpath_ = std::move(name); + } //! Paths as a list std::vector paths() const; @@ -63,15 +76,24 @@ class LIEF_API DynamicEntryRpath : public DynamicEntry { //! Remove the given ``path`` DynamicEntryRpath& remove(const std::string& path); - DynamicEntryRpath& operator+=(const std::string& path); - DynamicEntryRpath& operator-=(const std::string& path); + DynamicEntryRpath& operator+=(std::string path) { + return append(std::move(path)); + } + + DynamicEntryRpath& operator-=(const std::string& path) { + return remove(path); + } - static bool classof(const DynamicEntry* entry); + static bool classof(const DynamicEntry* entry) { + return entry->tag() == DynamicEntry::TAG::RPATH; + } void accept(Visitor& visitor) const override; std::ostream& print(std::ostream& os) const override; + ~DynamicEntryRpath() = default; + private: std::string rpath_; }; diff --git a/include/LIEF/ELF/DynamicEntryRunPath.hpp b/include/LIEF/ELF/DynamicEntryRunPath.hpp index 4f881be28c..f1661caa74 100644 --- a/include/LIEF/ELF/DynamicEntryRunPath.hpp +++ b/include/LIEF/ELF/DynamicEntryRunPath.hpp @@ -17,9 +17,9 @@ #define LIEF_ELF_DYNAMIC_ENTRY_RUNPATH_H #include +#include #include "LIEF/visibility.h" - #include "LIEF/ELF/DynamicEntry.hpp" namespace LIEF { @@ -33,24 +33,38 @@ class LIEF_API DynamicEntryRunPath : public DynamicEntry { static constexpr char delimiter = ':'; using DynamicEntry::DynamicEntry; - DynamicEntryRunPath(); + DynamicEntryRunPath() : + DynamicEntry::DynamicEntry(DynamicEntry::TAG::RUNPATH, 0) + {} //! Constructor from (run)path - DynamicEntryRunPath(std::string runpath); + DynamicEntryRunPath(std::string runpath) : + DynamicEntry::DynamicEntry(DynamicEntry::TAG::RUNPATH, 0), + runpath_(std::move(runpath)) + {} //! Constructor from a list of paths - DynamicEntryRunPath(const std::vector& paths); + DynamicEntryRunPath(const std::vector& paths) : + DynamicEntry::DynamicEntry(DynamicEntry::TAG::RUNPATH, 0) + { + this->paths(paths); + } - DynamicEntryRunPath& operator=(const DynamicEntryRunPath&); - DynamicEntryRunPath(const DynamicEntryRunPath&); + DynamicEntryRunPath& operator=(const DynamicEntryRunPath&) = default; + DynamicEntryRunPath(const DynamicEntryRunPath&) = default; - //! Runpath raw value - const std::string& name() const; - void name(const std::string& name); + std::unique_ptr clone() const override { + return std::unique_ptr(new DynamicEntryRunPath(*this)); + } //! Runpath raw value - const std::string& runpath() const; - void runpath(const std::string& runpath); + const std::string& runpath() const { + return runpath_; + } + + void runpath(std::string runpath) { + runpath_ = std::move(runpath); + } //! Paths as a list std::vector paths() const; @@ -65,15 +79,24 @@ class LIEF_API DynamicEntryRunPath : public DynamicEntry { //! Remove the given ``path`` DynamicEntryRunPath& remove(const std::string& path); - DynamicEntryRunPath& operator+=(const std::string& path); - DynamicEntryRunPath& operator-=(const std::string& path); + DynamicEntryRunPath& operator+=(std::string path) { + return append(std::move(path)); + } + + DynamicEntryRunPath& operator-=(const std::string& path) { + return remove(path); + } void accept(Visitor& visitor) const override; - static bool classof(const DynamicEntry* entry); + static bool classof(const DynamicEntry* entry) { + return entry->tag() == DynamicEntry::TAG::RUNPATH; + } std::ostream& print(std::ostream& os) const override; + ~DynamicEntryRunPath() = default; + private: std::string runpath_; }; diff --git a/include/LIEF/ELF/DynamicSharedObject.hpp b/include/LIEF/ELF/DynamicSharedObject.hpp index 91d2e50366..068b9f0c56 100644 --- a/include/LIEF/ELF/DynamicSharedObject.hpp +++ b/include/LIEF/ELF/DynamicSharedObject.hpp @@ -19,35 +19,53 @@ #include #include "LIEF/visibility.h" - #include "LIEF/ELF/DynamicEntry.hpp" namespace LIEF { namespace ELF { //! Class which represents a ``DT_SONAME`` entry in the dynamic table -//! This kind of entry is usually used no name the original library. +//! This kind of entry is usually used to name the original library. //! //! This entry is not present for executable. class LIEF_API DynamicSharedObject : public DynamicEntry { public: using DynamicEntry::DynamicEntry; - DynamicSharedObject(); - DynamicSharedObject(std::string name); + DynamicSharedObject() : + DynamicEntry(DynamicEntry::TAG::SONAME, 0) + {} + + DynamicSharedObject(std::string name) : + DynamicEntry(DynamicEntry::TAG::SONAME, 0), + name_(std::move(name)) + {} + + DynamicSharedObject& operator=(const DynamicSharedObject&) = default; + DynamicSharedObject(const DynamicSharedObject&) = default; - DynamicSharedObject& operator=(const DynamicSharedObject&); - DynamicSharedObject(const DynamicSharedObject&); + std::unique_ptr clone() const override { + return std::unique_ptr(new DynamicSharedObject(*this)); + } //! The actual name (e.g. ``libMyLib.so``) - const std::string& name() const; - void name(const std::string& name); + const std::string& name() const { + return name_; + } + + void name(std::string name) { + name_ = std::move(name); + } void accept(Visitor& visitor) const override; std::ostream& print(std::ostream& os) const override; - static bool classof(const DynamicEntry* entry); + static bool classof(const DynamicEntry* entry) { + return entry->tag() == DynamicEntry::TAG::SONAME; + } + + ~DynamicSharedObject() override = default; private: std::string name_; diff --git a/include/LIEF/ELF/EnumToString.hpp b/include/LIEF/ELF/EnumToString.hpp index 6c30fc0fc4..414a0d96d6 100644 --- a/include/LIEF/ELF/EnumToString.hpp +++ b/include/LIEF/ELF/EnumToString.hpp @@ -20,43 +20,7 @@ namespace LIEF { namespace ELF { -LIEF_API const char* to_string(SYMBOL_BINDINGS e); -LIEF_API const char* to_string(E_TYPE e); -LIEF_API const char* to_string(VERSION e); LIEF_API const char* to_string(ARCH e); -LIEF_API const char* to_string(SEGMENT_TYPES e); -LIEF_API const char* to_string(DYNAMIC_TAGS e); -LIEF_API const char* to_string(ELF_SECTION_TYPES e); -LIEF_API const char* to_string(ELF_SECTION_FLAGS e); -LIEF_API const char* to_string(ELF_SYMBOL_TYPES e); -LIEF_API const char* to_string(RELOC_x86_64 e); -LIEF_API const char* to_string(RELOC_ARM e); -LIEF_API const char* to_string(RELOC_i386 e); -LIEF_API const char* to_string(RELOC_AARCH64 e); -LIEF_API const char* to_string(RELOC_POWERPC32 e); -LIEF_API const char* to_string(RELOC_POWERPC64 e); -LIEF_API const char* to_string(RELOC_MIPS e); -LIEF_API const char* to_string(ELF_CLASS e); -LIEF_API const char* to_string(ELF_DATA e); -LIEF_API const char* to_string(OS_ABI e); -LIEF_API const char* to_string(DYNSYM_COUNT_METHODS e); -LIEF_API const char* to_string(RELOCATION_PURPOSES e); -LIEF_API const char* to_string(IDENTITY e); -LIEF_API const char* to_string(SYMBOL_SECTION_INDEX e); -LIEF_API const char* to_string(DYNAMIC_FLAGS e); -LIEF_API const char* to_string(DYNAMIC_FLAGS_1 e); -LIEF_API const char* to_string(ELF_SEGMENT_FLAGS e); -LIEF_API const char* to_string(ELF_SYMBOL_VISIBILITY e); - -LIEF_API const char* to_string(PPC64_EFLAGS e); -LIEF_API const char* to_string(ARM_EFLAGS e); -LIEF_API const char* to_string(MIPS_EFLAGS e); -LIEF_API const char* to_string(HEXAGON_EFLAGS e); -LIEF_API const char* to_string(LOONGARCH_EFLAGS e); -LIEF_API const char* to_string(RELOC_LOONGARCH e); - - - } // namespace ELF } // namespace LIEF diff --git a/include/LIEF/ELF/GnuHash.hpp b/include/LIEF/ELF/GnuHash.hpp index cdfaf1ee67..e1f52e9238 100644 --- a/include/LIEF/ELF/GnuHash.hpp +++ b/include/LIEF/ELF/GnuHash.hpp @@ -40,49 +40,65 @@ class LIEF_API GnuHash : public Object { friend class Binary; public: - GnuHash(); + GnuHash() = default; GnuHash(uint32_t symbol_idx, uint32_t shift2, std::vector bloom_filters, std::vector buckets, std::vector hash_values = {}); - GnuHash& operator=(const GnuHash& copy); - GnuHash(const GnuHash& copy); + GnuHash& operator=(const GnuHash& copy) = default; + GnuHash(const GnuHash& copy) = default; - GnuHash(GnuHash&&); - GnuHash& operator=(GnuHash&&); + GnuHash(GnuHash&&) = default; + GnuHash& operator=(GnuHash&&) = default; - ~GnuHash() override; + ~GnuHash() override = default; //! Return the number of buckets //! @see GnuHash::buckets - uint32_t nb_buckets() const; + uint32_t nb_buckets() const { + return buckets_.size(); + } //! Index of the first symbol in the dynamic //! symbols table which accessible with the hash table - uint32_t symbol_index() const; + uint32_t symbol_index() const { + return symbol_index_; + } //! Shift count used in the bloom filter - uint32_t shift2() const; + uint32_t shift2() const { + return shift2_; + } //! Number of bloom filters used. //! It must be a power of 2 - uint32_t maskwords() const; + uint32_t maskwords() const { + return bloom_filters_.size(); + } //! Bloom filters - const std::vector& bloom_filters() const; + const std::vector& bloom_filters() const { + return bloom_filters_; + } //! Hash buckets - const std::vector& buckets() const; + const std::vector& buckets() const { + return buckets_; + } //! Hash values - const std::vector& hash_values() const; + const std::vector& hash_values() const { + return hash_values_; + } //! Check if the given hash passes the bloom filter bool check_bloom_filter(uint32_t hash) const; //! Check if the given hash passes the bucket filter - bool check_bucket(uint32_t hash) const; + bool check_bucket(uint32_t hash) const { + return buckets_[hash % nb_buckets()] > 0; + } //! Check if the symbol *probably* exists. If //! the returned value is ``false`` you can assume at ``100%`` that diff --git a/include/LIEF/ELF/Header.hpp b/include/LIEF/ELF/Header.hpp index c37ecfd56d..b51c406b8b 100644 --- a/include/LIEF/ELF/Header.hpp +++ b/include/LIEF/ELF/Header.hpp @@ -26,221 +26,321 @@ #include "LIEF/Abstract/enums.hpp" #include "LIEF/ELF/enums.hpp" +#include "LIEF/ELF/ProcessorFlags.hpp" namespace LIEF { namespace ELF { class Parser; -namespace details { -struct Elf32_Ehdr; -struct Elf64_Ehdr; -} - -//! Class which represents the ELF's header. This is the ELF structure -//! that starts an ELF file. +/// Class which represents the ELF's header. This class mirrors the raw +/// ELF `Elfxx_Ehdr` structure class LIEF_API Header : public Object { friend class Parser; public: using identity_t = std::array; using abstract_architecture_t = std::pair>; - template - using flags_list_t = std::set; - - using arm_flags_list_t = flags_list_t; - using mips_flags_list_t = flags_list_t; - using hexagon_flags_list_t = flags_list_t; - using ppc64_flags_list_t = flags_list_t; - using loongarch_flags_list_t = flags_list_t; - public: - Header(); - Header(const details::Elf32_Ehdr& header); - Header(const details::Elf64_Ehdr& header); - - Header& operator=(const Header&); - Header(const Header&); - - ~Header() override; - - //! Define the object file type. (e.g. executable, library...) - E_TYPE file_type() const; - - //! LIEF abstract object type + /// e_ident size and indices. + enum { + EI_MAG0 = 0, ///< File identification index. + EI_MAG1 = 1, ///< File identification index. + EI_MAG2 = 2, ///< File identification index. + EI_MAG3 = 3, ///< File identification index. + EI_CLASS = 4, ///< File class. + EI_DATA = 5, ///< Data encoding. + EI_VERSION = 6, ///< File version. + EI_OSABI = 7, ///< OS/ABI identification. + EI_ABIVERSION = 8, ///< ABI version. + EI_PAD = 9, ///< Start of padding bytes. + EI_NIDENT = 16 ///< Number of bytes in e_ident. + }; + + /// The type of the underlying ELF file. This enum matches + /// the semantic of `ET_NONE`, `ET_REL`, ... + enum class FILE_TYPE { + NONE = 0, ///< Can't be determined + REL = 1, ///< Relocatable file (or object file) + EXEC = 2, ///< non-pie executable + DYN = 3, ///< Shared library **or** a pie-executable + CORE = 4, ///< Core dump file + }; + + /// Match the result of `Elfxx_Ehdr.e_version` + enum class VERSION { + NONE = 0, ///< Invalid ELF version + CURRENT = 1, ///< Current version (default) + }; + + /// Match the result of `Elfxx_Ehdr.e_ident[EI_CLASS]` + enum class CLASS { + NONE = 0, /// Invalid class + ELF32, /// 32-bit objects + ELF64, /// 64-bits objects + }; + + /// Match the result `Elfxx_Ehdr.e_ident[EI_OSABI]` + enum class OS_ABI { + SYSTEMV = 0, /// UNIX System V ABI + HPUX = 1, /// HP-UX operating system + NETBSD = 2, /// NetBSD + GNU = 3, /// GNU/Linux + LINUX = 3, /// Historical alias for ELFOSABI_GNU. + HURD = 4, /// GNU/Hurd + SOLARIS = 6, /// Solaris + AIX = 7, /// AIX + IRIX = 8, /// IRIX + FREEBSD = 9, /// FreeBSD + TRU64 = 10, /// TRU64 UNIX + MODESTO = 11, /// Novell Modesto + OPENBSD = 12, /// OpenBSD + OPENVMS = 13, /// OpenVMS + NSK = 14, /// Hewlett-Packard Non-Stop Kernel + AROS = 15, /// AROS + FENIXOS = 16, /// FenixOS + CLOUDABI = 17, /// Nuxi CloudABI + C6000_ELFABI = 64, /// Bare-metal TMS320C6000 + AMDGPU_HSA = 64, /// AMD HSA runtime + C6000_LINUX = 65, /// Linux TMS320C6000 + ARM = 97, /// ARM + STANDALONE = 255 /// Standalone (embedded) application + }; + + /// Match the result `Elfxx_Ehdr.e_ident[EI_DATA]` + enum class ELF_DATA { + NONE = 0, /// Invalid data encoding + LSB = 1, /// 2's complement, little endian + MSB = 2 /// 2's complement, big endian + }; + + Header() = default; + + Header& operator=(const Header&) = default; + Header(const Header&) = default; + + ~Header() override = default; + + /// Define the object file type. (e.g. executable, library...) + FILE_TYPE file_type() const { + return file_type_; + } + + /// LIEF abstract object type OBJECT_TYPES abstract_object_type() const; - //! Target architecture - ARCH machine_type() const; + /// Target architecture + ARCH machine_type() const { + return machine_type_; + } - //! LIEF abstract architecture - //! - //! It returns Empty if it can't be abstracted + /// LIEF abstract architecture abstract_architecture_t abstract_architecture() const; - //! LIEF abstract endianness + /// LIEF abstract endianness ENDIANNESS abstract_endianness() const; - //! Version of the object file format - VERSION object_file_version() const; - - //! Executable entrypoint - uint64_t entrypoint() const; - - //! Offset of program table (also known as segments table) - uint64_t program_headers_offset() const; - - //! Offset of section table - uint64_t section_headers_offset() const; - - //! Processor-specific flags - uint32_t processor_flag() const; - - //! Check if the given flag is present in processor_flag() - bool has(ARM_EFLAGS f) const; - - //! Return a list of ARM_EFLAGS present in processor_flag() - arm_flags_list_t arm_flags_list() const; - - //! Check if the given flag is present in processor_flag() - bool has(MIPS_EFLAGS f) const; - - //! Return a list of MIPS_EFLAGS present in processor_flag() - mips_flags_list_t mips_flags_list() const; - - //! Check if the given flag is present in processor_flag() - bool has(PPC64_EFLAGS f) const; - - //! Return a list of PPC64_EFLAGS present in processor_flag() - ppc64_flags_list_t ppc64_flags_list() const; - - //! Check if the given flag is present in processor_flag() - bool has(HEXAGON_EFLAGS f) const; - - //! Return a list of HEXAGON_EFLAGS present in processor_flag() - hexagon_flags_list_t hexagon_flags_list() const; - - //! Check if the given flag is present in processor_flag() - bool has(LOONGARCH_EFLAGS f) const; - - //! Return a list of LOONGARCH_EFLAGS present in processor_flag() - loongarch_flags_list_t loongarch_flags_list() const; - - //! Size of the current header - //! - //! This size should be 64 for an ``ELF64`` binary and 52 for an ``ELF32``. - uint32_t header_size() const; - - //! Return the size of a ``Segment header`` - //! - //! This size should be 56 for a ``ELF64`` binary and 32 for an ``ELF32``. - uint32_t program_header_size() const; - - //! Return the the number of segments - uint32_t numberof_segments() const; + /// Version of the object file format + VERSION object_file_version() const { + return object_file_version_; + } + + /// Executable entrypoint + uint64_t entrypoint() const { + return entrypoint_; + } + + /// Offset of the programs table (also known as segments table) + uint64_t program_headers_offset() const { + return program_headers_offset_; + } + + /// Offset of the sections table + uint64_t section_headers_offset() const { + return section_headers_offset_; + } + + /// Processor-specific flags + uint32_t processor_flag() const { + return processor_flags_; + } + + /// Size of the current header (i.e. `sizeof(Elfxx_Ehdr)`) + /// This size should be 64 for an `ELF64` binary and 52 for an `ELF32`. + uint32_t header_size() const { + return header_size_; + } + + /// Return the size of a program header (i.e. `sizeof(Elfxx_Phdr)`) + /// This size should be 56 for an `ELF64` binary and 32 for an `ELF32`. + uint32_t program_header_size() const { + return program_header_size_; + } + + /// Return the the number of segments + uint32_t numberof_segments() const { + return numberof_segments_; + } + + /// Return the size of a section header (i.e. `sizeof(Elfxx_Shdr)`) + /// This size should be 64 for a ``ELF64`` binary and 40 for an ``ELF32``. + uint32_t section_header_size() const { + return section_header_size_; + } + + /// Return the number of sections + /// + /// @warning This value could differ from the real number of sections + /// present in the binary. It must be taken as an *indication* + uint32_t numberof_sections() const { + return numberof_sections_; + } + + /// Return the section's index which contains sections' names + uint32_t section_name_table_idx() const { + return section_string_table_idx_; + } + + /// Return the ELF identity as an ``std::array`` + identity_t& identity() { + return identity_; + } + + const identity_t& identity() const { + return identity_; + } + + /// Return the object's class. ``ELF64`` or ``ELF32`` + CLASS identity_class() const { + return CLASS(identity_[EI_CLASS]); + } + + /// Specify the data encoding + ELF_DATA identity_data() const { + return ELF_DATA(identity_[EI_DATA]); + } + + /// @see object_file_version + VERSION identity_version() const { + return VERSION(identity_[EI_VERSION]); + } + + /// Identifies the version of the ABI for which the object is prepared + OS_ABI identity_os_abi() const { + return OS_ABI(identity_[EI_OSABI]); + } + + /// ABI Version + uint32_t identity_abi_version() const { + return identity_[EI_ABIVERSION]; + } + + bool has(PROCESSOR_FLAGS flag) const; + + std::vector flags_list() const; + + void file_type(FILE_TYPE type) { + file_type_ = type; + } + + void machine_type(ARCH arch) { + machine_type_ = arch; + } + + void object_file_version(VERSION version) { + object_file_version_ = version; + } + + void entrypoint(uint64_t entry) { + entrypoint_ = entry; + } + + void program_headers_offset(uint64_t offset) { + program_headers_offset_ = offset; + } + + void section_headers_offset(uint64_t offset) { + section_headers_offset_ = offset; + } + + void processor_flag(uint32_t flags) { + processor_flags_ = flags; + } + + void header_size(uint32_t size) { + header_size_ = size; + } + + void program_header_size(uint32_t size) { + program_header_size_ = size; + } + + void numberof_segments(uint32_t n) { + numberof_segments_ = n; + } + void section_header_size(uint32_t size) { + section_header_size_ = size; + } + + void numberof_sections(uint32_t n) { + numberof_sections_ = n; + } + void section_name_table_idx(uint32_t idx) { + section_string_table_idx_ = idx; + } - //! Return the size of a ``Section header`` - //! - //! This size should be 64 for a ``ELF64`` binary and 40 for an ``ELF32``. - uint32_t section_header_size() const; - - //! Return the number of sections - //! - //! @warning This value could differ from the real number of sections - //! present in the binary. It must be taken as an *indication* - uint32_t numberof_sections() const; - - //! Return the section's index which contains sections' names - uint32_t section_name_table_idx() const; - - //! Return the ELF identity as an ``std::array`` - identity_t& identity(); - const identity_t& identity() const; + void identity(const std::string& identity); + void identity(const identity_t& identity); - //! Return the object's class. ``ELF64`` or ``ELF32`` - ELF_CLASS identity_class() const; + void identity_class(CLASS cls) { + identity_[EI_CLASS] = static_cast(cls); + } - //! Specify the data encoding - ELF_DATA identity_data() const; + void identity_data(ELF_DATA data) { + identity_[EI_DATA] = static_cast(data); + } - //! @see object_file_version - VERSION identity_version() const; + void identity_version(VERSION version) { + identity_[EI_VERSION] = static_cast(version); + } - //! Identifies the version of the ABI for which the object is prepared - OS_ABI identity_os_abi() const; + void identity_os_abi(OS_ABI osabi) { + identity_[EI_OSABI] = static_cast(osabi); + } - //! ABI Version - uint32_t identity_abi_version() const; - - void file_type(E_TYPE type); - void machine_type(ARCH machineType); - void object_file_version(VERSION version); - void entrypoint(uint64_t entryPoint); - void program_headers_offset(uint64_t programHeaderOffset); - void section_headers_offset(uint64_t sectionHeaderOffset); - void processor_flag(uint32_t processorFlag); - void header_size(uint32_t headerSize); - void program_header_size(uint32_t programHeaderSize); - void numberof_segments(uint32_t n); - void section_header_size(uint32_t sizeOfSectionHeaderEntries); - void numberof_sections(uint32_t n); - void section_name_table_idx(uint32_t sectionNameStringTableIdx); - void identity(const std::string& identity); - void identity(const identity_t& identity); - void identity_class(ELF_CLASS i_class); - void identity_data(ELF_DATA data); - void identity_version(VERSION version); - void identity_os_abi(OS_ABI osabi); - void identity_abi_version(uint32_t version); + void identity_abi_version(uint8_t version) { + identity_[EI_ABIVERSION] = version; + } void accept(Visitor& visitor) const override; - LIEF_API friend std::ostream& operator<<(std::ostream& os, const Header& hdr); private: - //! Field which represents ElfXX_Ehdr->e_ident - identity_t identity_; - - //! Field which represents ElfXX_Ehdr->e_type - E_TYPE file_type_; - - //! Field which represents ElfXX_Ehdr->e_machine - ARCH machine_type_; - - //! Field which represents ElfXX_Ehdr->e_version - VERSION object_file_version_; - - //! Field which represents ElfXX_Ehdr->e_entry - uint64_t entrypoint_; - - //! Field which represents ElfXX_Ehdr->e_phoff - uint64_t program_headers_offset_; - - //! Field which represents ElfXX_Ehdr->e_shoff - uint64_t section_headers_offset_; - - //! Field which represents ElfXX_Ehdr->e_flags - uint32_t processor_flags_; - - //! Field which represents ElfXX_Ehdr->e_ehsize - uint32_t header_size_; - - //! Field which represents ElfXX_Ehdr->e_phentsize - uint32_t program_header_size_; - - //! Field which represents ElfXX_Ehdr->e_phnum - uint32_t numberof_segments_; - - //! Field which represents ElfXX_Ehdr->e_shentsize - uint32_t section_header_size_; + template + LIEF_LOCAL Header(const T& header); - //! Field which represents ElfXX_Ehdr->e_shnum - uint32_t numberof_sections_; + identity_t identity_; + FILE_TYPE file_type_ = FILE_TYPE::NONE; + ARCH machine_type_ = ARCH::NONE; + VERSION object_file_version_ = VERSION::NONE; + uint64_t entrypoint_ = 0; + uint64_t program_headers_offset_ = 0; + uint64_t section_headers_offset_ = 0; + uint32_t processor_flags_ = 0; + uint32_t header_size_ = 0; + uint32_t program_header_size_ = 0; + uint32_t numberof_segments_ = 0; + uint32_t section_header_size_ = 0; + uint32_t numberof_sections_ = 0; + uint32_t section_string_table_idx_ = 0; +}; - //! Field which represents ElfXX_Ehdr->e_shstrndx - uint32_t section_string_table_idx_; +LIEF_API const char* to_string(Header::FILE_TYPE type); +LIEF_API const char* to_string(Header::VERSION version); +LIEF_API const char* to_string(Header::CLASS version); +LIEF_API const char* to_string(Header::OS_ABI abi); +LIEF_API const char* to_string(Header::ELF_DATA abi); -}; } } #endif diff --git a/include/LIEF/ELF/Note.hpp b/include/LIEF/ELF/Note.hpp index 5fdfb9e60b..c7a5e5cc18 100644 --- a/include/LIEF/ELF/Note.hpp +++ b/include/LIEF/ELF/Note.hpp @@ -25,7 +25,7 @@ #include "LIEF/errors.hpp" #include "LIEF/span.hpp" -#include "LIEF/ELF/enums.hpp" +#include "LIEF/ELF/Header.hpp" namespace LIEF { class BinaryStream; @@ -122,7 +122,7 @@ class LIEF_API Note : public Object { public: /// Convert the raw integer note type into a TYPE according to the owner - static result convert_type(E_TYPE ftype, uint32_t type, + static result convert_type(Header::FILE_TYPE ftype, uint32_t type, const std::string& name); /// Try to determine the ELF section name associated with the TYPE @@ -141,22 +141,22 @@ class LIEF_API Note : public Object { /// creating notes like Coredump notes. static std::unique_ptr create( const std::string& name, uint32_t type, description_t description, - E_TYPE ftype = E_TYPE::ET_NONE, ARCH arch = ARCH::EM_NONE, - ELF_CLASS cls = ELF_CLASS::ELFCLASSNONE); + Header::FILE_TYPE ftype = Header::FILE_TYPE::NONE, ARCH arch = ARCH::NONE, + Header::CLASS cls = Header::CLASS::NONE); /// Create a new note from the given parameters. Additional information /// such as the architecture or the ELF class could be required for /// creating notes like Coredump notes. static std::unique_ptr create( const std::string& name, TYPE type, description_t description, - ARCH arch = ARCH::EM_NONE, ELF_CLASS cls = ELF_CLASS::ELFCLASSNONE); + ARCH arch = ARCH::NONE, Header::CLASS cls = Header::CLASS::NONE); /// Create a new note from the given stream. Additional information /// such as the architecture or the ELF class could be required for /// creating notes like Coredump notes. static std::unique_ptr create(BinaryStream& stream, - E_TYPE ftype = E_TYPE::ET_NONE, ARCH arch = ARCH::EM_NONE, - ELF_CLASS cls = ELF_CLASS::ELFCLASSNONE); + Header::FILE_TYPE ftype = Header::FILE_TYPE::NONE, ARCH arch = ARCH::NONE, + Header::CLASS cls = Header::CLASS::NONE); Note& operator=(const Note& copy) = default; Note(const Note& copy) = default; diff --git a/include/LIEF/ELF/NoteDetails/NoteGnuProperty.hpp b/include/LIEF/ELF/NoteDetails/NoteGnuProperty.hpp index e180abab21..fe01740b91 100644 --- a/include/LIEF/ELF/NoteDetails/NoteGnuProperty.hpp +++ b/include/LIEF/ELF/NoteDetails/NoteGnuProperty.hpp @@ -71,8 +71,8 @@ class LIEF_API NoteGnuProperty : public Note { using properties_t = std::vector>; - NoteGnuProperty(ARCH arch, ELF_CLASS cls, std::string name, - uint32_t type, description_t description) : + NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name, + uint32_t type, description_t description) : Note(std::move(name), TYPE::GNU_PROPERTY_TYPE_0, type, std::move(description)), arch_(arch), class_(cls) {} @@ -104,8 +104,8 @@ class LIEF_API NoteGnuProperty : public Note { } protected: - ARCH arch_ = ARCH::EM_NONE; - ELF_CLASS class_ = ELF_CLASS::ELFCLASSNONE; + ARCH arch_ = ARCH::NONE; + Header::CLASS class_ = Header::CLASS::NONE; }; LIEF_API const char* to_string(NoteGnuProperty::Property::TYPE type); diff --git a/include/LIEF/ELF/NoteDetails/core/CoreAuxv.hpp b/include/LIEF/ELF/NoteDetails/core/CoreAuxv.hpp index 015b898583..1961ddc056 100644 --- a/include/LIEF/ELF/NoteDetails/core/CoreAuxv.hpp +++ b/include/LIEF/ELF/NoteDetails/core/CoreAuxv.hpp @@ -68,7 +68,7 @@ class LIEF_API CoreAuxv : public Note { SYSINFO_EHDR, /**< Pointer to ELF header of system-supplied DSO. */ }; - CoreAuxv(ARCH arch, ELF_CLASS cls, std::string name, + CoreAuxv(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description) : Note(std::move(name), Note::TYPE::CORE_AUXV, type, std::move(description)), arch_(arch), class_(cls) @@ -109,8 +109,8 @@ class LIEF_API CoreAuxv : public Note { } protected: - ARCH arch_ = ARCH::EM_NONE; - ELF_CLASS class_ = ELF_CLASS::ELFCLASSNONE; + ARCH arch_ = ARCH::NONE; + Header::CLASS class_ = Header::CLASS::NONE; }; LIEF_API const char* to_string(CoreAuxv::TYPE type); diff --git a/include/LIEF/ELF/NoteDetails/core/CoreFile.hpp b/include/LIEF/ELF/NoteDetails/core/CoreFile.hpp index 4a7891da32..850aa2f88b 100644 --- a/include/LIEF/ELF/NoteDetails/core/CoreFile.hpp +++ b/include/LIEF/ELF/NoteDetails/core/CoreFile.hpp @@ -46,7 +46,7 @@ class LIEF_API CoreFile : public Note { using const_iterator = files_t::const_iterator; public: - CoreFile(ARCH arch, ELF_CLASS cls, std::string name, + CoreFile(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, Note::description_t description); std::unique_ptr clone() const override { @@ -105,8 +105,8 @@ class LIEF_API CoreFile : public Note { files_t files_; uint64_t page_size_ = 0; - ARCH arch_ = ARCH::EM_NONE; - ELF_CLASS class_ = ELF_CLASS::ELFCLASSNONE; + ARCH arch_ = ARCH::NONE; + Header::CLASS class_ = Header::CLASS::NONE; }; } // namepsace ELF diff --git a/include/LIEF/ELF/NoteDetails/core/CorePrPsInfo.hpp b/include/LIEF/ELF/NoteDetails/core/CorePrPsInfo.hpp index 852fb1549b..117b648bcb 100644 --- a/include/LIEF/ELF/NoteDetails/core/CorePrPsInfo.hpp +++ b/include/LIEF/ELF/NoteDetails/core/CorePrPsInfo.hpp @@ -55,7 +55,7 @@ class LIEF_API CorePrPsInfo : public Note { return args.c_str(); } }; - CorePrPsInfo(ARCH arch, ELF_CLASS cls, std::string name, + CorePrPsInfo(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description) : Note(std::move(name), TYPE::CORE_PRPSINFO, type, std::move(description)), arch_(arch), class_(cls) @@ -85,8 +85,8 @@ class LIEF_API CorePrPsInfo : public Note { return os; } private: - ARCH arch_ = ARCH::EM_NONE; - ELF_CLASS class_ = ELF_CLASS::ELFCLASSNONE; + ARCH arch_ = ARCH::NONE; + Header::CLASS class_ = Header::CLASS::NONE; }; } // namepsace ELF diff --git a/include/LIEF/ELF/NoteDetails/core/CorePrStatus.hpp b/include/LIEF/ELF/NoteDetails/core/CorePrStatus.hpp index f779253bdc..bef214502a 100644 --- a/include/LIEF/ELF/NoteDetails/core/CorePrStatus.hpp +++ b/include/LIEF/ELF/NoteDetails/core/CorePrStatus.hpp @@ -66,14 +66,14 @@ class LIEF_API CorePrStatus : public Note { }; struct Registers { - /// Register for the x86 architecture (ARCH::EM_386). + /// Register for the x86 architecture (ARCH::I386). enum class X86 { EBX = 0, ECX, EDX, ESI, EDI, EBP, EAX, DS, ES, FS, GS, ORIG_EAX, EIP, CS, EFLAGS, ESP, SS, _COUNT }; - /// Register for the x86-64 architecture (ARCH::EM_X86_64). + /// Register for the x86-64 architecture (ARCH::X86_64). enum class X86_64 { R15 = 0, R14, R13, R12, RBP, RBX, R11, R10, R9, R8, RAX, RCX, RDX, RSI, RDI, ORIG_RAX, @@ -81,7 +81,7 @@ class LIEF_API CorePrStatus : public Note { _COUNT }; - /// Register for the ARM architecture (ARCH::EM_ARM). + /// Register for the ARM architecture (ARCH::ARM). enum class ARM { R0 = 0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, CPSR, @@ -98,7 +98,7 @@ class LIEF_API CorePrStatus : public Note { }; public: - CorePrStatus(ARCH arch, ELF_CLASS cls, std::string name, + CorePrStatus(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description) : Note(std::move(name), TYPE::CORE_PRSTATUS, type, std::move(description)), arch_(arch), class_(cls) @@ -145,7 +145,7 @@ class LIEF_API CorePrStatus : public Note { /// empty if it can't be resolved. Thus, one can access a specific register /// with: /// ```cpp - /// if (architecture() == ARCH::EM_AARCH64) { + /// if (architecture() == ARCH::AARCH64) { /// auto reg_vals = register_values() /// if (!reg_vals.empty()) { /// auto x20 = reg_vals[static_cast(Register::AARCH64::X20)] @@ -186,8 +186,8 @@ class LIEF_API CorePrStatus : public Note { } private: - ARCH arch_ = ARCH::EM_NONE; - ELF_CLASS class_ = ELF_CLASS::ELFCLASSNONE; + ARCH arch_ = ARCH::NONE; + Header::CLASS class_ = Header::CLASS::NONE; }; LIEF_API const char* to_string(CorePrStatus::Registers::X86 e); diff --git a/include/LIEF/ELF/Parser.hpp b/include/LIEF/ELF/Parser.hpp index f4f4bddf55..78372d1744 100644 --- a/include/LIEF/ELF/Parser.hpp +++ b/include/LIEF/ELF/Parser.hpp @@ -52,9 +52,13 @@ class LIEF_API Parser : public LIEF::Parser { static constexpr uint32_t NB_MAX_RELOCATIONS = 3000000; static constexpr uint32_t NB_MAX_DYNAMIC_ENTRIES = 1000; static constexpr uint32_t NB_MAX_MASKWORD = 512; - static constexpr uint32_t MAX_SECTION_SIZE = 2_GB; static constexpr uint32_t MAX_SEGMENT_SIZE = 3_GB; + enum ELF_TYPE { + ELF_UNKNOWN, + ELF32, ELF64 + }; + //! Parse an ELF file and return a LIEF::ELF::Binary object //! //! For weird binaries (e.g. sectionless) you can choose which method to use for counting dynamic symbols @@ -92,12 +96,12 @@ class LIEF_API Parser : public LIEF::Parser { Parser(const Parser&) = delete; protected: - Parser(); + Parser() = default; Parser(std::unique_ptr stream, ParserConfig config); Parser(const std::string& file, ParserConfig config); Parser(const std::vector& data, ParserConfig config); - ~Parser() override; + ~Parser() override = default; ok_error_t init(); @@ -129,7 +133,7 @@ class LIEF_API Parser : public LIEF::Parser { //! Return the number of dynamic symbols using the given method template - result get_numberof_dynamic_symbols(DYNSYM_COUNT_METHODS mtd) const; + result get_numberof_dynamic_symbols(ParserConfig::DYNSYM_COUNT mtd) const; //! Count based on hash table (reliable) template @@ -192,8 +196,8 @@ class LIEF_API Parser : public LIEF::Parser { //! Parse SymbolVersionRequirement //! //! We use the virtual address stored in the - //! DYNAMIC_TAGS::DT_VERNEED entry to get the offset. - //! and DYNAMIC_TAGS::DT_VERNEEDNUM to get the number of entries + //! DynamicEntry::TAG::VERNEED entry to get the offset. + //! and DynamicEntry::TAG::VERNEEDNUM to get the number of entries template ok_error_t parse_symbol_version_requirement(uint64_t offset, uint32_t nb_entries); @@ -201,8 +205,8 @@ class LIEF_API Parser : public LIEF::Parser { //! Parse SymbolVersionDefinition. //! //! We use the virtual address stored in - //! the DYNAMIC_TAGS::DT_VERDEF DT_VERDEF entry to get the offset. - //! DYNAMIC_TAGS::DT_VERDEFNUM gives the number of entries + //! the DynamicEntry::TAG::VERDEF DT_VERDEF entry to get the offset. + //! DynamicEntry::TAG::VERDEFNUM gives the number of entries template ok_error_t parse_symbol_version_definition(uint64_t offset, uint32_t nb_entries); @@ -210,7 +214,7 @@ class LIEF_API Parser : public LIEF::Parser { //! Parse @link SymbolVersion Symbol version @endlink. //! //! We use the virtual address stored in the - //! DYNAMIC_TAGS::DT_VERSYM entry to parse it. + //! DynamicEntry::TAG::VERSYM entry to parse it. //! //! @see http://dev.gentoo.org/~solar/elf/symbol-versioning ok_error_t parse_symbol_version(uint64_t symbol_version_offset); @@ -238,9 +242,8 @@ class LIEF_API Parser : public LIEF::Parser { static bool check_section_in_segment(const Section& section, const Segment& segment); std::unique_ptr stream_; - std::unique_ptr binary_; - ELF_CLASS type_ = ELF_CLASS::ELFCLASSNONE; - ParserConfig config_; + std::unique_ptr binary_; + ParserConfig config_; /* * parse_sections() may skip some sections so that * binary_->sections_ is not contiguous based on the index of the sections. diff --git a/include/LIEF/ELF/ParserConfig.hpp b/include/LIEF/ELF/ParserConfig.hpp index 1cd0f3ef47..e0f5e32a47 100644 --- a/include/LIEF/ELF/ParserConfig.hpp +++ b/include/LIEF/ELF/ParserConfig.hpp @@ -23,12 +23,22 @@ namespace ELF { //! This structure is used to tweak the ELF Parser (ELF::Parser) struct LIEF_API ParserConfig { + /** Methods that can be used by the LIEF::ELF::Parser + to count the number of dynamic symbols */ + enum class DYNSYM_COUNT { + AUTO = 0, /**< Automatic detection */ + SECTION = 1, /**< Count based on sections (not very reliable) */ + HASH = 2, /**< Count based on hash table (reliable) */ + RELOCATIONS = 3, /**< Count based on PLT/GOT relocations (very reliable but not accurate) */ + }; + //! This returns a ParserConfig object configured to process all the ELF //! elements. static ParserConfig all() { static const ParserConfig DEFAULT; return DEFAULT; } + bool parse_relocations = true; ///< Whether relocations (including plt-like relocations) should be parsed. bool parse_dyn_symbols = true; ///< Whether dynamic symbols (those from `.dynsym`) should be parsed bool parse_static_symbols = true; ///< Whether debug symbols (those from `.symtab`) should be parsed @@ -37,7 +47,7 @@ struct LIEF_API ParserConfig { bool parse_overlay = true; ///< Whether the overlay data should be parsed /** The method used to count the number of dynamic symbols */ - DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO; + DYNSYM_COUNT count_mtd = DYNSYM_COUNT::AUTO; }; } diff --git a/include/LIEF/ELF/ProcessorFlags.hpp b/include/LIEF/ELF/ProcessorFlags.hpp new file mode 100644 index 0000000000..e8055ef82e --- /dev/null +++ b/include/LIEF/ELF/ProcessorFlags.hpp @@ -0,0 +1,115 @@ +/* Copyright 2017 - 2023 R. Thomas + * Copyright 2017 - 2023 Quarkslab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef LIEF_ELF_PROCESSOR_FLAGS_H +#define LIEF_ELF_PROCESSOR_FLAGS_H +#include +#include "LIEF/visibility.h" + +namespace LIEF { +namespace ELF { + +static constexpr uint64_t PFLAGS_BIT = 43; +static constexpr uint64_t PFLAGS_MASK = (1LLU << PFLAGS_BIT) - 1; +static constexpr uint64_t PF_ARM_ID = 1; +static constexpr uint64_t PF_HEX_ID = 2; +static constexpr uint64_t PF_LOONGARCH_ID = 3; +static constexpr uint64_t PF_MIPS_ID = 4; + +enum class PROCESSOR_FLAGS : uint64_t { + ARM_EABI_UNKNOWN = 0x00000000 | (PF_ARM_ID << PFLAGS_BIT), + ARM_SOFT_FLOAT = 0x00000200 | (PF_ARM_ID << PFLAGS_BIT), + ARM_VFP_FLOAT = 0x00000400 | (PF_ARM_ID << PFLAGS_BIT), + ARM_EABI_VER1 = 0x01000000 | (PF_ARM_ID << PFLAGS_BIT), + ARM_EABI_VER2 = 0x02000000 | (PF_ARM_ID << PFLAGS_BIT), + ARM_EABI_VER3 = 0x03000000 | (PF_ARM_ID << PFLAGS_BIT), + ARM_EABI_VER4 = 0x04000000 | (PF_ARM_ID << PFLAGS_BIT), + ARM_EABI_VER5 = 0x05000000 | (PF_ARM_ID << PFLAGS_BIT), + + HEXAGON_MACH_V2 = 0x00000001 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V2 + HEXAGON_MACH_V3 = 0x00000002 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V3 + HEXAGON_MACH_V4 = 0x00000003 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V4 + HEXAGON_MACH_V5 = 0x00000004 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V5 + + HEXAGON_ISA_V2 = 0x00000010 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V2 ISA + HEXAGON_ISA_V3 = 0x00000020 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V3 ISA + HEXAGON_ISA_V4 = 0x00000030 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V4 ISA + HEXAGON_ISA_V5 = 0x00000040 | (PF_HEX_ID << PFLAGS_BIT), // Hexagon V5 ISA + + LOONGARCH_ABI_SOFT_FLOAT = 0x1 | (PF_LOONGARCH_ID << PFLAGS_BIT), + LOONGARCH_ABI_SINGLE_FLOAT = 0x2 | (PF_LOONGARCH_ID << PFLAGS_BIT), + LOONGARCH_ABI_DOUBLE_FLOAT = 0x3 | (PF_LOONGARCH_ID << PFLAGS_BIT), + + MIPS_NOREORDER = 0x00000001 | (PF_MIPS_ID << PFLAGS_BIT), /* Don't reorder instructions */ + MIPS_PIC = 0x00000002 | (PF_MIPS_ID << PFLAGS_BIT), /* Position independent code */ + MIPS_CPIC = 0x00000004 | (PF_MIPS_ID << PFLAGS_BIT), /* Call object with Position independent code */ + MIPS_ABI2 = 0x00000020 | (PF_MIPS_ID << PFLAGS_BIT), /* File uses N32 ABI */ + MIPS_32BITMODE = 0x00000100 | (PF_MIPS_ID << PFLAGS_BIT), /* Code compiled for a 64-bit machine */ + /* in 32-bit mode */ + MIPS_FP64 = 0x00000200 | (PF_MIPS_ID << PFLAGS_BIT), /* Code compiled for a 32-bit machine */ + /* but uses 64-bit FP registers */ + MIPS_NAN2008 = 0x00000400 | (PF_MIPS_ID << PFLAGS_BIT), /* Uses IEE 754-2008 NaN encoding */ + + /* ABI flags */ + MIPS_ABI_O32 = 0x00001000 | (PF_MIPS_ID << PFLAGS_BIT), /* This file follows the first MIPS 32 bit ABI */ + MIPS_ABI_O64 = 0x00002000 | (PF_MIPS_ID << PFLAGS_BIT), /* O32 ABI extended for 64-bit architecture. */ + MIPS_ABI_EABI32 = 0x00003000 | (PF_MIPS_ID << PFLAGS_BIT), /* EABI in 32 bit mode. */ + MIPS_ABI_EABI64 = 0x00004000 | (PF_MIPS_ID << PFLAGS_BIT), /* EABI in 64 bit mode. */ + + /* MIPS machine variant */ + MIPS_MACH_3900 = 0x00810000 | (PF_MIPS_ID << PFLAGS_BIT), /* Toshiba R3900 */ + MIPS_MACH_4010 = 0x00820000 | (PF_MIPS_ID << PFLAGS_BIT), /* LSI R4010 */ + MIPS_MACH_4100 = 0x00830000 | (PF_MIPS_ID << PFLAGS_BIT), /* NEC VR4100 */ + MIPS_MACH_4650 = 0x00850000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS R4650 */ + MIPS_MACH_4120 = 0x00870000 | (PF_MIPS_ID << PFLAGS_BIT), /* NEC VR4120 */ + MIPS_MACH_4111 = 0x00880000 | (PF_MIPS_ID << PFLAGS_BIT), /* NEC VR4111/VR4181 */ + MIPS_MACH_SB1 = 0x008a0000 | (PF_MIPS_ID << PFLAGS_BIT), /* Broadcom SB-1 */ + MIPS_MACH_OCTEON = 0x008b0000 | (PF_MIPS_ID << PFLAGS_BIT), /* Cavium Networks Octeon */ + MIPS_MACH_XLR = 0x008c0000 | (PF_MIPS_ID << PFLAGS_BIT), /* RMI Xlr */ + MIPS_MACH_OCTEON2 = 0x008d0000 | (PF_MIPS_ID << PFLAGS_BIT), /* Cavium Networks Octeon2 */ + MIPS_MACH_OCTEON3 = 0x008e0000 | (PF_MIPS_ID << PFLAGS_BIT), /* Cavium Networks Octeon3 */ + MIPS_MACH_5400 = 0x00910000 | (PF_MIPS_ID << PFLAGS_BIT), /* NEC VR5400 */ + MIPS_MACH_5900 = 0x00920000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS R5900 */ + MIPS_MACH_5500 = 0x00980000 | (PF_MIPS_ID << PFLAGS_BIT), /* NEC VR5500 */ + MIPS_MACH_9000 = 0x00990000 | (PF_MIPS_ID << PFLAGS_BIT), /* Unknown */ + MIPS_MACH_LS2E = 0x00a00000 | (PF_MIPS_ID << PFLAGS_BIT), /* ST Microelectronics Loongson 2E */ + MIPS_MACH_LS2F = 0x00a10000 | (PF_MIPS_ID << PFLAGS_BIT), /* ST Microelectronics Loongson 2F */ + MIPS_MACH_LS3A = 0x00a20000 | (PF_MIPS_ID << PFLAGS_BIT), /* Loongson 3A */ + + /* ARCH_ASE */ + MIPS_MICROMIPS = 0x02000000 | (PF_MIPS_ID << PFLAGS_BIT), /* microMIPS */ + MIPS_ARCH_ASE_M16 = 0x04000000 | (PF_MIPS_ID << PFLAGS_BIT), /* Has Mips-16 ISA extensions */ + MIPS_ARCH_ASE_MDMX = 0x08000000 | (PF_MIPS_ID << PFLAGS_BIT), /* Has MDMX multimedia extensions */ + + /* ARCH */ + MIPS_ARCH_1 = 0x00000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS1 instruction set */ + MIPS_ARCH_2 = 0x10000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS2 instruction set */ + MIPS_ARCH_3 = 0x20000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS3 instruction set */ + MIPS_ARCH_4 = 0x30000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS4 instruction set */ + MIPS_ARCH_5 = 0x40000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS5 instruction set */ + MIPS_ARCH_32 = 0x50000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS32 instruction set per linux not elf.h */ + MIPS_ARCH_64 = 0x60000000 | (PF_MIPS_ID << PFLAGS_BIT), /* MIPS64 instruction set per linux not elf.h */ + MIPS_ARCH_32R2 = 0x70000000 | (PF_MIPS_ID << PFLAGS_BIT), /* mips32r2, mips32r3, mips32r5 */ + MIPS_ARCH_64R2 = 0x80000000 | (PF_MIPS_ID << PFLAGS_BIT), /* mips64r2, mips64r3, mips64r5 */ + MIPS_ARCH_32R6 = 0x90000000 | (PF_MIPS_ID << PFLAGS_BIT), /* mips32r6 */ + MIPS_ARCH_64R6 = 0xa0000000 | (PF_MIPS_ID << PFLAGS_BIT), /* mips64r6 */ +}; + +LIEF_API const char* to_string(PROCESSOR_FLAGS flag); + + +} +} +#endif diff --git a/include/LIEF/ELF/Relocation.hpp b/include/LIEF/ELF/Relocation.hpp index 90ec419e0f..9e0ca50587 100644 --- a/include/LIEF/ELF/Relocation.hpp +++ b/include/LIEF/ELF/Relocation.hpp @@ -17,7 +17,6 @@ #define LIEF_ELF_RELOCATION_H #include -#include #include #include "LIEF/Object.hpp" @@ -36,15 +35,7 @@ class Builder; class Symbol; class Section; -namespace details { -struct Elf32_Rel; -struct Elf32_Rela; - -struct Elf64_Rel; -struct Elf64_Rela; -} - -//! Class that represents an ELF relocation. +/// Class that represents an ELF relocation. class LIEF_API Relocation : public LIEF::Relocation { friend class Parser; @@ -52,111 +43,223 @@ class LIEF_API Relocation : public LIEF::Relocation { friend class Builder; public: - Relocation(const details::Elf32_Rel& header); - Relocation(const details::Elf32_Rela& header); - Relocation(const details::Elf64_Rel& header); - Relocation(const details::Elf64_Rela& header); - Relocation(uint64_t address, uint32_t type = 0, int64_t addend = 0, bool isRela = false); - - template::value>::type> - Relocation(uint64_t address, T type, int64_t addend = 0, bool isRela = false) : - Relocation{address, static_cast(type), addend, isRela} - {} - Relocation(); - Relocation(ARCH arch); - ~Relocation() override; + /// The *purpose* of a relocation defines + enum class PURPOSE { + NONE = 0, + PLTGOT = 1, ///< The relocation is associated with the PLT/GOT resolution + DYNAMIC = 2, ///< The relocation is used for regulard data/code relocation + OBJECT = 3, ///< The relocation is used in an object file + }; + + static constexpr uint64_t R_BIT = 27; + static constexpr uint64_t R_MASK = (uint64_t(1) << R_BIT) - 1; + + static constexpr uint64_t R_X64 = uint64_t(1) << R_BIT; + static constexpr uint64_t R_AARCH64 = uint64_t(2) << R_BIT; + static constexpr uint64_t R_ARM = uint64_t(3) << R_BIT; + static constexpr uint64_t R_HEXAGON = uint64_t(4) << R_BIT; + static constexpr uint64_t R_X86 = uint64_t(5) << R_BIT; + static constexpr uint64_t R_LARCH = uint64_t(6) << R_BIT; + static constexpr uint64_t R_MIPS = uint64_t(7) << R_BIT; + static constexpr uint64_t R_PPC = uint64_t(8) << R_BIT; + static constexpr uint64_t R_PPC64 = uint64_t(9) << R_BIT; + static constexpr uint64_t R_SPARC = uint64_t(10) << R_BIT; + static constexpr uint64_t R_SYSZ = uint64_t(11) << R_BIT; + + /// The different types of the relocation + enum class TYPE : uint32_t { + UNKNOWN = uint32_t(-1), + + #define ELF_RELOC(name, value) name = (value | R_X64), + #include "LIEF/ELF/Relocations/x86_64.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_AARCH64), + #include "LIEF/ELF/Relocations/AArch64.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_ARM), + #include "LIEF/ELF/Relocations/ARM.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_HEXAGON), + #include "LIEF/ELF/Relocations/Hexagon.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_X86), + #include "LIEF/ELF/Relocations/i386.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_LARCH), + #include "LIEF/ELF/Relocations/LoongArch.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_MIPS), + #include "LIEF/ELF/Relocations/Mips.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_PPC), + #include "LIEF/ELF/Relocations/PowerPC.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_PPC64), + #include "LIEF/ELF/Relocations/PowerPC64.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_SPARC), + #include "LIEF/ELF/Relocations/Sparc.def" + #undef ELF_RELOC + + #define ELF_RELOC(name, value) name = (value | R_SYSZ), + #include "LIEF/ELF/Relocations/SystemZ.def" + #undef ELF_RELOC + }; + + static TYPE type_from(uint32_t value, ARCH arch); + + static uint32_t to_value(TYPE type) { + return static_cast(type) & R_MASK; + } + + template + LIEF_LOCAL Relocation(const T& header, PURPOSE purpose, ARCH arch); + + Relocation(uint64_t address, TYPE type = TYPE::UNKNOWN, bool is_rela = false); + + Relocation() = default; + Relocation(ARCH arch) { + architecture_ = arch; + } + ~Relocation() override = default; Relocation& operator=(Relocation other); Relocation(const Relocation& other); void swap(Relocation& other); - //! Additional value that can be involved in the relocation processing - int64_t addend() const; - - //! Type of the relocation - //! This type depends on the underlying architecture which can be accessed with architecture(). - //! - //! Depending on the architecture, it can return: - //! - //! * RELOC_x86_64 - //! * RELOC_i386 - //! * RELOC_POWERPC32 - //! * RELOC_POWERPC64 - //! * RELOC_AARCH64 - //! * RELOC_ARM - //! * RELOC_MIPS - //! * RELOC_HEXAGON - //! * RELOC_SYSTEMZ - //! * RELOC_SPARC - //! * RELOC_LOONGARCH - uint32_t type() const; - - //! Check if the relocation uses the explicit addend() field (this is usually the case for 64 bits binaries) - bool is_rela() const; - - //! Check if the relocation uses the implicit added (i.e. not present in the ELF structure) - bool is_rel() const; - - //! Relocation info which contains for instance the symbol index - uint32_t info() const; - - ARCH architecture() const; - RELOCATION_PURPOSES purpose() const; - - //! Return the size (in **bits**) of the value associated with this relocation - //! - //! Return -1 if it fails + /// Additional value that can be involved in the relocation processing + int64_t addend() const { + return addend_; + } + + /// Type of the relocation + TYPE type() const { + return type_; + } + + /// Check if the relocation uses the explicit addend() field + /// (this is usually the case for 64 bits binaries) + bool is_rela() const { + return isRela_; + } + + /// Check if the relocation uses the implicit addend + /// (i.e. not present in the ELF structure) + bool is_rel() const { + return !isRela_; + } + + /// Relocation info which contains, for instance, the symbol index + uint32_t info() const { + return info_; + } + + /// Target architecture for this relocation + ARCH architecture() const { + return architecture_; + } + + PURPOSE purpose() const { + return purpose_; + } + + /// Return the size (in **bits**) of the value associated with this relocation + /// Return -1 if the size can't be determined size_t size() const override; - //! True if the current relocation is associated with a symbol - bool has_symbol() const; + /// True if the current relocation is associated with a symbol + bool has_symbol() const { + return symbol_ != nullptr; + } - //! Symbol associated with the relocation - //! If no symbol is tied to this relocation, it returns a nullptr - Symbol* symbol(); - const Symbol* symbol() const; + /// Symbol associated with the relocation (or a nullptr) + Symbol* symbol() { + return symbol_; + } - //! True if the relocation has an associated section - bool has_section() const; + const Symbol* symbol() const { + return symbol_; + } - //! The section to which the relocation applies. - //! If no section to which the relocation applies is associtated to this relocation, it returns a nullptr - Section* section(); - const Section* section() const; + /// True if the relocation has an associated section + bool has_section() const { + return section() != nullptr; + } - //! The associated symbol table. - //! If no symbol table section is associated with this relocation, it returns a nullptr - Section* symbol_table(); - const Section* symbol_table() const; + /// The section in which the relocation is applied (or a nullptr) + Section* section() { + return section_; + } - void addend(int64_t addend); - void type(uint32_t type); - void purpose(RELOCATION_PURPOSES purpose); - void info(uint32_t v); - void symbol(Symbol* symbol); - void section(Section* section); - void symbol_table(Section* section); + const Section* section() const { + return section_; + } - void accept(Visitor& visitor) const override; + /// The associated symbol table (or a nullptr) + Section* symbol_table() { + return symbol_table_; + } + + const Section* symbol_table() const { + return symbol_table_; + } + + void addend(int64_t addend) { + addend_ = addend; + } + + void type(TYPE type) { + type_ = type; + } + void purpose(PURPOSE purpose) { + purpose_ = purpose; + } + + void info(uint32_t v) { + info_ = v; + } + + void symbol(Symbol* symbol) { + symbol_ = symbol; + } + + void section(Section* section) { + section_ = section; + } + + void symbol_table(Section* section) { + symbol_table_ = section; + } + + void accept(Visitor& visitor) const override; LIEF_API friend std::ostream& operator<<(std::ostream& os, const Relocation& entry); private: - uint32_t type_ = 0; - int64_t addend_ = 0; - bool isRela_ = false; - Symbol* symbol_ = nullptr; - ARCH architecture_ = ARCH::EM_NONE; - RELOCATION_PURPOSES purpose_ = RELOCATION_PURPOSES::RELOC_PURPOSE_NONE; - Section* section_{nullptr}; - Section* symbol_table_{nullptr}; - uint32_t info_ = 0; + TYPE type_ = TYPE::UNKNOWN; + int64_t addend_ = 0; + bool isRela_ = false; + Symbol* symbol_ = nullptr; + ARCH architecture_ = ARCH::NONE; + PURPOSE purpose_ = PURPOSE::NONE; + Section* section_ = nullptr; + Section* symbol_table_ = nullptr; + uint32_t info_ = 0; }; - +LIEF_API const char* to_string(Relocation::TYPE type); } } -#endif /* _ELF_RELOCATION_H */ +#endif diff --git a/include/LIEF/ELF/RelocationSizes.hpp b/include/LIEF/ELF/RelocationSizes.hpp deleted file mode 100644 index c98227c984..0000000000 --- a/include/LIEF/ELF/RelocationSizes.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2017 - 2023 R. Thomas - * Copyright 2017 - 2023 Quarkslab - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef LIEF_ELF_RELOCATION_SIZES_H -#define LIEF_ELF_RELOCATION_SIZES_H - -#include - -#include "LIEF/ELF/enums.hpp" - -namespace LIEF { -namespace ELF { - -int32_t get_reloc_size(RELOC_x86_64 R); -int32_t get_reloc_size(RELOC_i386 R); -int32_t get_reloc_size(RELOC_ARM R); -int32_t get_reloc_size(RELOC_AARCH64 R); -int32_t get_reloc_size(RELOC_POWERPC32 R); -int32_t get_reloc_size(RELOC_POWERPC64 R); -int32_t get_reloc_size(RELOC_MIPS R); -int32_t get_reloc_size(RELOC_LOONGARCH R); - -} -} - -#endif diff --git a/include/LIEF/ELF/Relocations/AArch64.def b/include/LIEF/ELF/Relocations/AArch64.def index a474e85315..ddea871172 100644 --- a/include/LIEF/ELF/Relocations/AArch64.def +++ b/include/LIEF/ELF/Relocations/AArch64.def @@ -4,144 +4,144 @@ #endif /* ABI release 1.0 */ -ELF_RELOC(R_AARCH64_NONE, 0) - -ELF_RELOC(R_AARCH64_ABS64, 0x101) -ELF_RELOC(R_AARCH64_ABS32, 0x102) -ELF_RELOC(R_AARCH64_ABS16, 0x103) -ELF_RELOC(R_AARCH64_PREL64, 0x104) -ELF_RELOC(R_AARCH64_PREL32, 0x105) -ELF_RELOC(R_AARCH64_PREL16, 0x106) - -ELF_RELOC(R_AARCH64_MOVW_UABS_G0, 0x107) -ELF_RELOC(R_AARCH64_MOVW_UABS_G0_NC, 0x108) -ELF_RELOC(R_AARCH64_MOVW_UABS_G1, 0x109) -ELF_RELOC(R_AARCH64_MOVW_UABS_G1_NC, 0x10a) -ELF_RELOC(R_AARCH64_MOVW_UABS_G2, 0x10b) -ELF_RELOC(R_AARCH64_MOVW_UABS_G2_NC, 0x10c) -ELF_RELOC(R_AARCH64_MOVW_UABS_G3, 0x10d) -ELF_RELOC(R_AARCH64_MOVW_SABS_G0, 0x10e) -ELF_RELOC(R_AARCH64_MOVW_SABS_G1, 0x10f) -ELF_RELOC(R_AARCH64_MOVW_SABS_G2, 0x110) - -ELF_RELOC(R_AARCH64_LD_PREL_LO19, 0x111) -ELF_RELOC(R_AARCH64_ADR_PREL_LO21, 0x112) -ELF_RELOC(R_AARCH64_ADR_PREL_PG_HI21, 0x113) -ELF_RELOC(R_AARCH64_ADR_PREL_PG_HI21_NC, 0x114) -ELF_RELOC(R_AARCH64_ADD_ABS_LO12_NC, 0x115) -ELF_RELOC(R_AARCH64_LDST8_ABS_LO12_NC, 0x116) - -ELF_RELOC(R_AARCH64_TSTBR14, 0x117) -ELF_RELOC(R_AARCH64_CONDBR19, 0x118) -ELF_RELOC(R_AARCH64_JUMP26, 0x11a) -ELF_RELOC(R_AARCH64_CALL26, 0x11b) - -ELF_RELOC(R_AARCH64_LDST16_ABS_LO12_NC, 0x11c) -ELF_RELOC(R_AARCH64_LDST32_ABS_LO12_NC, 0x11d) -ELF_RELOC(R_AARCH64_LDST64_ABS_LO12_NC, 0x11e) - -ELF_RELOC(R_AARCH64_MOVW_PREL_G0, 0x11f) -ELF_RELOC(R_AARCH64_MOVW_PREL_G0_NC, 0x120) -ELF_RELOC(R_AARCH64_MOVW_PREL_G1, 0x121) -ELF_RELOC(R_AARCH64_MOVW_PREL_G1_NC, 0x122) -ELF_RELOC(R_AARCH64_MOVW_PREL_G2, 0x123) -ELF_RELOC(R_AARCH64_MOVW_PREL_G2_NC, 0x124) -ELF_RELOC(R_AARCH64_MOVW_PREL_G3, 0x125) - -ELF_RELOC(R_AARCH64_LDST128_ABS_LO12_NC, 0x12b) - -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G0, 0x12c) -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G0_NC, 0x12d) -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G1, 0x12e) -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G1_NC, 0x12f) -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G2, 0x130) -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G2_NC, 0x131) -ELF_RELOC(R_AARCH64_MOVW_GOTOFF_G3, 0x132) - -ELF_RELOC(R_AARCH64_GOTREL64, 0x133) -ELF_RELOC(R_AARCH64_GOTREL32, 0x134) - -ELF_RELOC(R_AARCH64_GOT_LD_PREL19, 0x135) -ELF_RELOC(R_AARCH64_LD64_GOTOFF_LO15, 0x136) -ELF_RELOC(R_AARCH64_ADR_GOT_PAGE, 0x137) -ELF_RELOC(R_AARCH64_LD64_GOT_LO12_NC, 0x138) -ELF_RELOC(R_AARCH64_LD64_GOTPAGE_LO15, 0x139) - -ELF_RELOC(R_AARCH64_TLSGD_ADR_PREL21, 0x200) -ELF_RELOC(R_AARCH64_TLSGD_ADR_PAGE21, 0x201) -ELF_RELOC(R_AARCH64_TLSGD_ADD_LO12_NC, 0x202) -ELF_RELOC(R_AARCH64_TLSGD_MOVW_G1, 0x203) -ELF_RELOC(R_AARCH64_TLSGD_MOVW_G0_NC, 0x204) - -ELF_RELOC(R_AARCH64_TLSLD_ADR_PREL21, 0x205) -ELF_RELOC(R_AARCH64_TLSLD_ADR_PAGE21, 0x206) -ELF_RELOC(R_AARCH64_TLSLD_ADD_LO12_NC, 0x207) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_G1, 0x208) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_G0_NC, 0x209) -ELF_RELOC(R_AARCH64_TLSLD_LD_PREL19, 0x20a) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G2, 0x20b) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G1, 0x20c) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC, 0x20d) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G0, 0x20e) -ELF_RELOC(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC, 0x20f) -ELF_RELOC(R_AARCH64_TLSLD_ADD_DTPREL_HI12, 0x210) -ELF_RELOC(R_AARCH64_TLSLD_ADD_DTPREL_LO12, 0x211) -ELF_RELOC(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC, 0x212) -ELF_RELOC(R_AARCH64_TLSLD_LDST8_DTPREL_LO12, 0x213) -ELF_RELOC(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, 0x214) -ELF_RELOC(R_AARCH64_TLSLD_LDST16_DTPREL_LO12, 0x215) -ELF_RELOC(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, 0x216) -ELF_RELOC(R_AARCH64_TLSLD_LDST32_DTPREL_LO12, 0x217) -ELF_RELOC(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, 0x218) -ELF_RELOC(R_AARCH64_TLSLD_LDST64_DTPREL_LO12, 0x219) -ELF_RELOC(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, 0x21a) - -ELF_RELOC(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1, 0x21b) -ELF_RELOC(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, 0x21c) -ELF_RELOC(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, 0x21d) -ELF_RELOC(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, 0x21e) -ELF_RELOC(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19, 0x21f) - -ELF_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G2, 0x220) -ELF_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G1, 0x221) -ELF_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC, 0x222) -ELF_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G0, 0x223) -ELF_RELOC(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC, 0x224) -ELF_RELOC(R_AARCH64_TLSLE_ADD_TPREL_HI12, 0x225) -ELF_RELOC(R_AARCH64_TLSLE_ADD_TPREL_LO12, 0x226) -ELF_RELOC(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC, 0x227) -ELF_RELOC(R_AARCH64_TLSLE_LDST8_TPREL_LO12, 0x228) -ELF_RELOC(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC, 0x229) -ELF_RELOC(R_AARCH64_TLSLE_LDST16_TPREL_LO12, 0x22a) -ELF_RELOC(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC, 0x22b) -ELF_RELOC(R_AARCH64_TLSLE_LDST32_TPREL_LO12, 0x22c) -ELF_RELOC(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC, 0x22d) -ELF_RELOC(R_AARCH64_TLSLE_LDST64_TPREL_LO12, 0x22e) -ELF_RELOC(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC, 0x22f) - -ELF_RELOC(R_AARCH64_TLSDESC_LD_PREL19, 0x230) -ELF_RELOC(R_AARCH64_TLSDESC_ADR_PREL21, 0x231) -ELF_RELOC(R_AARCH64_TLSDESC_ADR_PAGE21, 0x232) -ELF_RELOC(R_AARCH64_TLSDESC_LD64_LO12_NC, 0x233) -ELF_RELOC(R_AARCH64_TLSDESC_ADD_LO12_NC, 0x234) -ELF_RELOC(R_AARCH64_TLSDESC_OFF_G1, 0x235) -ELF_RELOC(R_AARCH64_TLSDESC_OFF_G0_NC, 0x236) -ELF_RELOC(R_AARCH64_TLSDESC_LDR, 0x237) -ELF_RELOC(R_AARCH64_TLSDESC_ADD, 0x238) -ELF_RELOC(R_AARCH64_TLSDESC_CALL, 0x239) - -ELF_RELOC(R_AARCH64_TLSLE_LDST128_TPREL_LO12, 0x23a) -ELF_RELOC(R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC, 0x23b) - -ELF_RELOC(R_AARCH64_TLSLD_LDST128_DTPREL_LO12, 0x23c) -ELF_RELOC(R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC, 0x23d) - -ELF_RELOC(R_AARCH64_COPY, 0x400) -ELF_RELOC(R_AARCH64_GLOB_DAT, 0x401) -ELF_RELOC(R_AARCH64_JUMP_SLOT, 0x402) -ELF_RELOC(R_AARCH64_RELATIVE, 0x403) -ELF_RELOC(R_AARCH64_TLS_DTPREL64, 0x404) -ELF_RELOC(R_AARCH64_TLS_DTPMOD64, 0x405) -ELF_RELOC(R_AARCH64_TLS_TPREL64, 0x406) -ELF_RELOC(R_AARCH64_TLSDESC, 0x407) -ELF_RELOC(R_AARCH64_IRELATIVE, 0x408) +ELF_RELOC(AARCH64_NONE, 0) + +ELF_RELOC(AARCH64_ABS64, 0x101) +ELF_RELOC(AARCH64_ABS32, 0x102) +ELF_RELOC(AARCH64_ABS16, 0x103) +ELF_RELOC(AARCH64_PREL64, 0x104) +ELF_RELOC(AARCH64_PREL32, 0x105) +ELF_RELOC(AARCH64_PREL16, 0x106) + +ELF_RELOC(AARCH64_MOVW_UABS_G0, 0x107) +ELF_RELOC(AARCH64_MOVW_UABS_G0_NC, 0x108) +ELF_RELOC(AARCH64_MOVW_UABS_G1, 0x109) +ELF_RELOC(AARCH64_MOVW_UABS_G1_NC, 0x10a) +ELF_RELOC(AARCH64_MOVW_UABS_G2, 0x10b) +ELF_RELOC(AARCH64_MOVW_UABS_G2_NC, 0x10c) +ELF_RELOC(AARCH64_MOVW_UABS_G3, 0x10d) +ELF_RELOC(AARCH64_MOVW_SABS_G0, 0x10e) +ELF_RELOC(AARCH64_MOVW_SABS_G1, 0x10f) +ELF_RELOC(AARCH64_MOVW_SABS_G2, 0x110) + +ELF_RELOC(AARCH64_LD_PREL_LO19, 0x111) +ELF_RELOC(AARCH64_ADR_PREL_LO21, 0x112) +ELF_RELOC(AARCH64_ADR_PREL_PG_HI21, 0x113) +ELF_RELOC(AARCH64_ADR_PREL_PG_HI21_NC, 0x114) +ELF_RELOC(AARCH64_ADD_ABS_LO12_NC, 0x115) +ELF_RELOC(AARCH64_LDST8_ABS_LO12_NC, 0x116) + +ELF_RELOC(AARCH64_TSTBR14, 0x117) +ELF_RELOC(AARCH64_CONDBR19, 0x118) +ELF_RELOC(AARCH64_JUMP26, 0x11a) +ELF_RELOC(AARCH64_CALL26, 0x11b) + +ELF_RELOC(AARCH64_LDST16_ABS_LO12_NC, 0x11c) +ELF_RELOC(AARCH64_LDST32_ABS_LO12_NC, 0x11d) +ELF_RELOC(AARCH64_LDST64_ABS_LO12_NC, 0x11e) + +ELF_RELOC(AARCH64_MOVW_PREL_G0, 0x11f) +ELF_RELOC(AARCH64_MOVW_PREL_G0_NC, 0x120) +ELF_RELOC(AARCH64_MOVW_PREL_G1, 0x121) +ELF_RELOC(AARCH64_MOVW_PREL_G1_NC, 0x122) +ELF_RELOC(AARCH64_MOVW_PREL_G2, 0x123) +ELF_RELOC(AARCH64_MOVW_PREL_G2_NC, 0x124) +ELF_RELOC(AARCH64_MOVW_PREL_G3, 0x125) + +ELF_RELOC(AARCH64_LDST128_ABS_LO12_NC, 0x12b) + +ELF_RELOC(AARCH64_MOVW_GOTOFF_G0, 0x12c) +ELF_RELOC(AARCH64_MOVW_GOTOFF_G0_NC, 0x12d) +ELF_RELOC(AARCH64_MOVW_GOTOFF_G1, 0x12e) +ELF_RELOC(AARCH64_MOVW_GOTOFF_G1_NC, 0x12f) +ELF_RELOC(AARCH64_MOVW_GOTOFF_G2, 0x130) +ELF_RELOC(AARCH64_MOVW_GOTOFF_G2_NC, 0x131) +ELF_RELOC(AARCH64_MOVW_GOTOFF_G3, 0x132) + +ELF_RELOC(AARCH64_GOTREL64, 0x133) +ELF_RELOC(AARCH64_GOTREL32, 0x134) + +ELF_RELOC(AARCH64_GOT_LD_PREL19, 0x135) +ELF_RELOC(AARCH64_LD64_GOTOFF_LO15, 0x136) +ELF_RELOC(AARCH64_ADR_GOT_PAGE, 0x137) +ELF_RELOC(AARCH64_LD64_GOT_LO12_NC, 0x138) +ELF_RELOC(AARCH64_LD64_GOTPAGE_LO15, 0x139) + +ELF_RELOC(AARCH64_TLSGD_ADR_PREL21, 0x200) +ELF_RELOC(AARCH64_TLSGD_ADR_PAGE21, 0x201) +ELF_RELOC(AARCH64_TLSGD_ADD_LO12_NC, 0x202) +ELF_RELOC(AARCH64_TLSGD_MOVW_G1, 0x203) +ELF_RELOC(AARCH64_TLSGD_MOVW_G0_NC, 0x204) + +ELF_RELOC(AARCH64_TLSLD_ADR_PREL21, 0x205) +ELF_RELOC(AARCH64_TLSLD_ADR_PAGE21, 0x206) +ELF_RELOC(AARCH64_TLSLD_ADD_LO12_NC, 0x207) +ELF_RELOC(AARCH64_TLSLD_MOVW_G1, 0x208) +ELF_RELOC(AARCH64_TLSLD_MOVW_G0_NC, 0x209) +ELF_RELOC(AARCH64_TLSLD_LD_PREL19, 0x20a) +ELF_RELOC(AARCH64_TLSLD_MOVW_DTPREL_G2, 0x20b) +ELF_RELOC(AARCH64_TLSLD_MOVW_DTPREL_G1, 0x20c) +ELF_RELOC(AARCH64_TLSLD_MOVW_DTPREL_G1_NC, 0x20d) +ELF_RELOC(AARCH64_TLSLD_MOVW_DTPREL_G0, 0x20e) +ELF_RELOC(AARCH64_TLSLD_MOVW_DTPREL_G0_NC, 0x20f) +ELF_RELOC(AARCH64_TLSLD_ADD_DTPREL_HI12, 0x210) +ELF_RELOC(AARCH64_TLSLD_ADD_DTPREL_LO12, 0x211) +ELF_RELOC(AARCH64_TLSLD_ADD_DTPREL_LO12_NC, 0x212) +ELF_RELOC(AARCH64_TLSLD_LDST8_DTPREL_LO12, 0x213) +ELF_RELOC(AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, 0x214) +ELF_RELOC(AARCH64_TLSLD_LDST16_DTPREL_LO12, 0x215) +ELF_RELOC(AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, 0x216) +ELF_RELOC(AARCH64_TLSLD_LDST32_DTPREL_LO12, 0x217) +ELF_RELOC(AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, 0x218) +ELF_RELOC(AARCH64_TLSLD_LDST64_DTPREL_LO12, 0x219) +ELF_RELOC(AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, 0x21a) + +ELF_RELOC(AARCH64_TLSIE_MOVW_GOTTPREL_G1, 0x21b) +ELF_RELOC(AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, 0x21c) +ELF_RELOC(AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, 0x21d) +ELF_RELOC(AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, 0x21e) +ELF_RELOC(AARCH64_TLSIE_LD_GOTTPREL_PREL19, 0x21f) + +ELF_RELOC(AARCH64_TLSLE_MOVW_TPREL_G2, 0x220) +ELF_RELOC(AARCH64_TLSLE_MOVW_TPREL_G1, 0x221) +ELF_RELOC(AARCH64_TLSLE_MOVW_TPREL_G1_NC, 0x222) +ELF_RELOC(AARCH64_TLSLE_MOVW_TPREL_G0, 0x223) +ELF_RELOC(AARCH64_TLSLE_MOVW_TPREL_G0_NC, 0x224) +ELF_RELOC(AARCH64_TLSLE_ADD_TPREL_HI12, 0x225) +ELF_RELOC(AARCH64_TLSLE_ADD_TPREL_LO12, 0x226) +ELF_RELOC(AARCH64_TLSLE_ADD_TPREL_LO12_NC, 0x227) +ELF_RELOC(AARCH64_TLSLE_LDST8_TPREL_LO12, 0x228) +ELF_RELOC(AARCH64_TLSLE_LDST8_TPREL_LO12_NC, 0x229) +ELF_RELOC(AARCH64_TLSLE_LDST16_TPREL_LO12, 0x22a) +ELF_RELOC(AARCH64_TLSLE_LDST16_TPREL_LO12_NC, 0x22b) +ELF_RELOC(AARCH64_TLSLE_LDST32_TPREL_LO12, 0x22c) +ELF_RELOC(AARCH64_TLSLE_LDST32_TPREL_LO12_NC, 0x22d) +ELF_RELOC(AARCH64_TLSLE_LDST64_TPREL_LO12, 0x22e) +ELF_RELOC(AARCH64_TLSLE_LDST64_TPREL_LO12_NC, 0x22f) + +ELF_RELOC(AARCH64_TLSDESC_LD_PREL19, 0x230) +ELF_RELOC(AARCH64_TLSDESC_ADR_PREL21, 0x231) +ELF_RELOC(AARCH64_TLSDESC_ADR_PAGE21, 0x232) +ELF_RELOC(AARCH64_TLSDESC_LD64_LO12_NC, 0x233) +ELF_RELOC(AARCH64_TLSDESC_ADD_LO12_NC, 0x234) +ELF_RELOC(AARCH64_TLSDESC_OFF_G1, 0x235) +ELF_RELOC(AARCH64_TLSDESC_OFF_G0_NC, 0x236) +ELF_RELOC(AARCH64_TLSDESC_LDR, 0x237) +ELF_RELOC(AARCH64_TLSDESC_ADD, 0x238) +ELF_RELOC(AARCH64_TLSDESC_CALL, 0x239) + +ELF_RELOC(AARCH64_TLSLE_LDST128_TPREL_LO12, 0x23a) +ELF_RELOC(AARCH64_TLSLE_LDST128_TPREL_LO12_NC, 0x23b) + +ELF_RELOC(AARCH64_TLSLD_LDST128_DTPREL_LO12, 0x23c) +ELF_RELOC(AARCH64_TLSLD_LDST128_DTPREL_LO12_NC, 0x23d) + +ELF_RELOC(AARCH64_COPY, 0x400) +ELF_RELOC(AARCH64_GLOB_DAT, 0x401) +ELF_RELOC(AARCH64_JUMP_SLOT, 0x402) +ELF_RELOC(AARCH64_RELATIVE, 0x403) +ELF_RELOC(AARCH64_TLS_DTPREL64, 0x404) +ELF_RELOC(AARCH64_TLS_DTPMOD64, 0x405) +ELF_RELOC(AARCH64_TLS_TPREL64, 0x406) +ELF_RELOC(AARCH64_TLSDESC, 0x407) +ELF_RELOC(AARCH64_IRELATIVE, 0x408) diff --git a/include/LIEF/ELF/Relocations/ARM.def b/include/LIEF/ELF/Relocations/ARM.def index 685ed32d96..7bfb890601 100644 --- a/include/LIEF/ELF/Relocations/ARM.def +++ b/include/LIEF/ELF/Relocations/ARM.def @@ -4,142 +4,142 @@ #endif /* Meets 2.09 ABI Specs. */ -ELF_RELOC(R_ARM_NONE, 0x00) -ELF_RELOC(R_ARM_PC24, 0x01) -ELF_RELOC(R_ARM_ABS32, 0x02) -ELF_RELOC(R_ARM_REL32, 0x03) -ELF_RELOC(R_ARM_LDR_PC_G0, 0x04) -ELF_RELOC(R_ARM_ABS16, 0x05) -ELF_RELOC(R_ARM_ABS12, 0x06) -ELF_RELOC(R_ARM_THM_ABS5, 0x07) -ELF_RELOC(R_ARM_ABS8, 0x08) -ELF_RELOC(R_ARM_SBREL32, 0x09) -ELF_RELOC(R_ARM_THM_CALL, 0x0a) -ELF_RELOC(R_ARM_THM_PC8, 0x0b) -ELF_RELOC(R_ARM_BREL_ADJ, 0x0c) -ELF_RELOC(R_ARM_TLS_DESC, 0x0d) -ELF_RELOC(R_ARM_THM_SWI8, 0x0e) -ELF_RELOC(R_ARM_XPC25, 0x0f) -ELF_RELOC(R_ARM_THM_XPC22, 0x10) -ELF_RELOC(R_ARM_TLS_DTPMOD32, 0x11) -ELF_RELOC(R_ARM_TLS_DTPOFF32, 0x12) -ELF_RELOC(R_ARM_TLS_TPOFF32, 0x13) -ELF_RELOC(R_ARM_COPY, 0x14) -ELF_RELOC(R_ARM_GLOB_DAT, 0x15) -ELF_RELOC(R_ARM_JUMP_SLOT, 0x16) -ELF_RELOC(R_ARM_RELATIVE, 0x17) -ELF_RELOC(R_ARM_GOTOFF32, 0x18) -ELF_RELOC(R_ARM_BASE_PREL, 0x19) -ELF_RELOC(R_ARM_GOT_BREL, 0x1a) -ELF_RELOC(R_ARM_PLT32, 0x1b) -ELF_RELOC(R_ARM_CALL, 0x1c) -ELF_RELOC(R_ARM_JUMP24, 0x1d) -ELF_RELOC(R_ARM_THM_JUMP24, 0x1e) -ELF_RELOC(R_ARM_BASE_ABS, 0x1f) -ELF_RELOC(R_ARM_ALU_PCREL_7_0, 0x20) -ELF_RELOC(R_ARM_ALU_PCREL_15_8, 0x21) -ELF_RELOC(R_ARM_ALU_PCREL_23_15, 0x22) -ELF_RELOC(R_ARM_LDR_SBREL_11_0_NC, 0x23) -ELF_RELOC(R_ARM_ALU_SBREL_19_12_NC, 0x24) -ELF_RELOC(R_ARM_ALU_SBREL_27_20_CK, 0x25) -ELF_RELOC(R_ARM_TARGET1, 0x26) -ELF_RELOC(R_ARM_SBREL31, 0x27) -ELF_RELOC(R_ARM_V4BX, 0x28) -ELF_RELOC(R_ARM_TARGET2, 0x29) -ELF_RELOC(R_ARM_PREL31, 0x2a) -ELF_RELOC(R_ARM_MOVW_ABS_NC, 0x2b) -ELF_RELOC(R_ARM_MOVT_ABS, 0x2c) -ELF_RELOC(R_ARM_MOVW_PREL_NC, 0x2d) -ELF_RELOC(R_ARM_MOVT_PREL, 0x2e) -ELF_RELOC(R_ARM_THM_MOVW_ABS_NC, 0x2f) -ELF_RELOC(R_ARM_THM_MOVT_ABS, 0x30) -ELF_RELOC(R_ARM_THM_MOVW_PREL_NC, 0x31) -ELF_RELOC(R_ARM_THM_MOVT_PREL, 0x32) -ELF_RELOC(R_ARM_THM_JUMP19, 0x33) -ELF_RELOC(R_ARM_THM_JUMP6, 0x34) -ELF_RELOC(R_ARM_THM_ALU_PREL_11_0, 0x35) -ELF_RELOC(R_ARM_THM_PC12, 0x36) -ELF_RELOC(R_ARM_ABS32_NOI, 0x37) -ELF_RELOC(R_ARM_REL32_NOI, 0x38) -ELF_RELOC(R_ARM_ALU_PC_G0_NC, 0x39) -ELF_RELOC(R_ARM_ALU_PC_G0, 0x3a) -ELF_RELOC(R_ARM_ALU_PC_G1_NC, 0x3b) -ELF_RELOC(R_ARM_ALU_PC_G1, 0x3c) -ELF_RELOC(R_ARM_ALU_PC_G2, 0x3d) -ELF_RELOC(R_ARM_LDR_PC_G1, 0x3e) -ELF_RELOC(R_ARM_LDR_PC_G2, 0x3f) -ELF_RELOC(R_ARM_LDRS_PC_G0, 0x40) -ELF_RELOC(R_ARM_LDRS_PC_G1, 0x41) -ELF_RELOC(R_ARM_LDRS_PC_G2, 0x42) -ELF_RELOC(R_ARM_LDC_PC_G0, 0x43) -ELF_RELOC(R_ARM_LDC_PC_G1, 0x44) -ELF_RELOC(R_ARM_LDC_PC_G2, 0x45) -ELF_RELOC(R_ARM_ALU_SB_G0_NC, 0x46) -ELF_RELOC(R_ARM_ALU_SB_G0, 0x47) -ELF_RELOC(R_ARM_ALU_SB_G1_NC, 0x48) -ELF_RELOC(R_ARM_ALU_SB_G1, 0x49) -ELF_RELOC(R_ARM_ALU_SB_G2, 0x4a) -ELF_RELOC(R_ARM_LDR_SB_G0, 0x4b) -ELF_RELOC(R_ARM_LDR_SB_G1, 0x4c) -ELF_RELOC(R_ARM_LDR_SB_G2, 0x4d) -ELF_RELOC(R_ARM_LDRS_SB_G0, 0x4e) -ELF_RELOC(R_ARM_LDRS_SB_G1, 0x4f) -ELF_RELOC(R_ARM_LDRS_SB_G2, 0x50) -ELF_RELOC(R_ARM_LDC_SB_G0, 0x51) -ELF_RELOC(R_ARM_LDC_SB_G1, 0x52) -ELF_RELOC(R_ARM_LDC_SB_G2, 0x53) -ELF_RELOC(R_ARM_MOVW_BREL_NC, 0x54) -ELF_RELOC(R_ARM_MOVT_BREL, 0x55) -ELF_RELOC(R_ARM_MOVW_BREL, 0x56) -ELF_RELOC(R_ARM_THM_MOVW_BREL_NC, 0x57) -ELF_RELOC(R_ARM_THM_MOVT_BREL, 0x58) -ELF_RELOC(R_ARM_THM_MOVW_BREL, 0x59) -ELF_RELOC(R_ARM_TLS_GOTDESC, 0x5a) -ELF_RELOC(R_ARM_TLS_CALL, 0x5b) -ELF_RELOC(R_ARM_TLS_DESCSEQ, 0x5c) -ELF_RELOC(R_ARM_THM_TLS_CALL, 0x5d) -ELF_RELOC(R_ARM_PLT32_ABS, 0x5e) -ELF_RELOC(R_ARM_GOT_ABS, 0x5f) -ELF_RELOC(R_ARM_GOT_PREL, 0x60) -ELF_RELOC(R_ARM_GOT_BREL12, 0x61) -ELF_RELOC(R_ARM_GOTOFF12, 0x62) -ELF_RELOC(R_ARM_GOTRELAX, 0x63) -ELF_RELOC(R_ARM_GNU_VTENTRY, 0x64) -ELF_RELOC(R_ARM_GNU_VTINHERIT, 0x65) -ELF_RELOC(R_ARM_THM_JUMP11, 0x66) -ELF_RELOC(R_ARM_THM_JUMP8, 0x67) -ELF_RELOC(R_ARM_TLS_GD32, 0x68) -ELF_RELOC(R_ARM_TLS_LDM32, 0x69) -ELF_RELOC(R_ARM_TLS_LDO32, 0x6a) -ELF_RELOC(R_ARM_TLS_IE32, 0x6b) -ELF_RELOC(R_ARM_TLS_LE32, 0x6c) -ELF_RELOC(R_ARM_TLS_LDO12, 0x6d) -ELF_RELOC(R_ARM_TLS_LE12, 0x6e) -ELF_RELOC(R_ARM_TLS_IE12GP, 0x6f) -ELF_RELOC(R_ARM_PRIVATE_0, 0x70) -ELF_RELOC(R_ARM_PRIVATE_1, 0x71) -ELF_RELOC(R_ARM_PRIVATE_2, 0x72) -ELF_RELOC(R_ARM_PRIVATE_3, 0x73) -ELF_RELOC(R_ARM_PRIVATE_4, 0x74) -ELF_RELOC(R_ARM_PRIVATE_5, 0x75) -ELF_RELOC(R_ARM_PRIVATE_6, 0x76) -ELF_RELOC(R_ARM_PRIVATE_7, 0x77) -ELF_RELOC(R_ARM_PRIVATE_8, 0x78) -ELF_RELOC(R_ARM_PRIVATE_9, 0x79) -ELF_RELOC(R_ARM_PRIVATE_10, 0x7a) -ELF_RELOC(R_ARM_PRIVATE_11, 0x7b) -ELF_RELOC(R_ARM_PRIVATE_12, 0x7c) -ELF_RELOC(R_ARM_PRIVATE_13, 0x7d) -ELF_RELOC(R_ARM_PRIVATE_14, 0x7e) -ELF_RELOC(R_ARM_PRIVATE_15, 0x7f) -ELF_RELOC(R_ARM_ME_TOO, 0x80) -ELF_RELOC(R_ARM_THM_TLS_DESCSEQ16, 0x81) -ELF_RELOC(R_ARM_THM_TLS_DESCSEQ32, 0x82) -ELF_RELOC(R_ARM_IRELATIVE, 0xa0) +ELF_RELOC(ARM_NONE, 0x00) +ELF_RELOC(ARM_PC24, 0x01) +ELF_RELOC(ARM_ABS32, 0x02) +ELF_RELOC(ARM_REL32, 0x03) +ELF_RELOC(ARM_LDR_PC_G0, 0x04) +ELF_RELOC(ARM_ABS16, 0x05) +ELF_RELOC(ARM_ABS12, 0x06) +ELF_RELOC(ARM_THM_ABS5, 0x07) +ELF_RELOC(ARM_ABS8, 0x08) +ELF_RELOC(ARM_SBREL32, 0x09) +ELF_RELOC(ARM_THM_CALL, 0x0a) +ELF_RELOC(ARM_THM_PC8, 0x0b) +ELF_RELOC(ARM_BREL_ADJ, 0x0c) +ELF_RELOC(ARM_TLS_DESC, 0x0d) +ELF_RELOC(ARM_THM_SWI8, 0x0e) +ELF_RELOC(ARM_XPC25, 0x0f) +ELF_RELOC(ARM_THM_XPC22, 0x10) +ELF_RELOC(ARM_TLS_DTPMOD32, 0x11) +ELF_RELOC(ARM_TLS_DTPOFF32, 0x12) +ELF_RELOC(ARM_TLS_TPOFF32, 0x13) +ELF_RELOC(ARM_COPY, 0x14) +ELF_RELOC(ARM_GLOB_DAT, 0x15) +ELF_RELOC(ARM_JUMP_SLOT, 0x16) +ELF_RELOC(ARM_RELATIVE, 0x17) +ELF_RELOC(ARM_GOTOFF32, 0x18) +ELF_RELOC(ARM_BASE_PREL, 0x19) +ELF_RELOC(ARM_GOT_BREL, 0x1a) +ELF_RELOC(ARM_PLT32, 0x1b) +ELF_RELOC(ARM_CALL, 0x1c) +ELF_RELOC(ARM_JUMP24, 0x1d) +ELF_RELOC(ARM_THM_JUMP24, 0x1e) +ELF_RELOC(ARM_BASE_ABS, 0x1f) +ELF_RELOC(ARM_ALU_PCREL_7_0, 0x20) +ELF_RELOC(ARM_ALU_PCREL_15_8, 0x21) +ELF_RELOC(ARM_ALU_PCREL_23_15, 0x22) +ELF_RELOC(ARM_LDR_SBREL_11_0_NC, 0x23) +ELF_RELOC(ARM_ALU_SBREL_19_12_NC, 0x24) +ELF_RELOC(ARM_ALU_SBREL_27_20_CK, 0x25) +ELF_RELOC(ARM_TARGET1, 0x26) +ELF_RELOC(ARM_SBREL31, 0x27) +ELF_RELOC(ARM_V4BX, 0x28) +ELF_RELOC(ARM_TARGET2, 0x29) +ELF_RELOC(ARM_PREL31, 0x2a) +ELF_RELOC(ARM_MOVW_ABS_NC, 0x2b) +ELF_RELOC(ARM_MOVT_ABS, 0x2c) +ELF_RELOC(ARM_MOVW_PREL_NC, 0x2d) +ELF_RELOC(ARM_MOVT_PREL, 0x2e) +ELF_RELOC(ARM_THM_MOVW_ABS_NC, 0x2f) +ELF_RELOC(ARM_THM_MOVT_ABS, 0x30) +ELF_RELOC(ARM_THM_MOVW_PREL_NC, 0x31) +ELF_RELOC(ARM_THM_MOVT_PREL, 0x32) +ELF_RELOC(ARM_THM_JUMP19, 0x33) +ELF_RELOC(ARM_THM_JUMP6, 0x34) +ELF_RELOC(ARM_THM_ALU_PREL_11_0, 0x35) +ELF_RELOC(ARM_THM_PC12, 0x36) +ELF_RELOC(ARM_ABS32_NOI, 0x37) +ELF_RELOC(ARM_REL32_NOI, 0x38) +ELF_RELOC(ARM_ALU_PC_G0_NC, 0x39) +ELF_RELOC(ARM_ALU_PC_G0, 0x3a) +ELF_RELOC(ARM_ALU_PC_G1_NC, 0x3b) +ELF_RELOC(ARM_ALU_PC_G1, 0x3c) +ELF_RELOC(ARM_ALU_PC_G2, 0x3d) +ELF_RELOC(ARM_LDR_PC_G1, 0x3e) +ELF_RELOC(ARM_LDR_PC_G2, 0x3f) +ELF_RELOC(ARM_LDRS_PC_G0, 0x40) +ELF_RELOC(ARM_LDRS_PC_G1, 0x41) +ELF_RELOC(ARM_LDRS_PC_G2, 0x42) +ELF_RELOC(ARM_LDC_PC_G0, 0x43) +ELF_RELOC(ARM_LDC_PC_G1, 0x44) +ELF_RELOC(ARM_LDC_PC_G2, 0x45) +ELF_RELOC(ARM_ALU_SB_G0_NC, 0x46) +ELF_RELOC(ARM_ALU_SB_G0, 0x47) +ELF_RELOC(ARM_ALU_SB_G1_NC, 0x48) +ELF_RELOC(ARM_ALU_SB_G1, 0x49) +ELF_RELOC(ARM_ALU_SB_G2, 0x4a) +ELF_RELOC(ARM_LDR_SB_G0, 0x4b) +ELF_RELOC(ARM_LDR_SB_G1, 0x4c) +ELF_RELOC(ARM_LDR_SB_G2, 0x4d) +ELF_RELOC(ARM_LDRS_SB_G0, 0x4e) +ELF_RELOC(ARM_LDRS_SB_G1, 0x4f) +ELF_RELOC(ARM_LDRS_SB_G2, 0x50) +ELF_RELOC(ARM_LDC_SB_G0, 0x51) +ELF_RELOC(ARM_LDC_SB_G1, 0x52) +ELF_RELOC(ARM_LDC_SB_G2, 0x53) +ELF_RELOC(ARM_MOVW_BREL_NC, 0x54) +ELF_RELOC(ARM_MOVT_BREL, 0x55) +ELF_RELOC(ARM_MOVW_BREL, 0x56) +ELF_RELOC(ARM_THM_MOVW_BREL_NC, 0x57) +ELF_RELOC(ARM_THM_MOVT_BREL, 0x58) +ELF_RELOC(ARM_THM_MOVW_BREL, 0x59) +ELF_RELOC(ARM_TLS_GOTDESC, 0x5a) +ELF_RELOC(ARM_TLS_CALL, 0x5b) +ELF_RELOC(ARM_TLS_DESCSEQ, 0x5c) +ELF_RELOC(ARM_THM_TLS_CALL, 0x5d) +ELF_RELOC(ARM_PLT32_ABS, 0x5e) +ELF_RELOC(ARM_GOT_ABS, 0x5f) +ELF_RELOC(ARM_GOT_PREL, 0x60) +ELF_RELOC(ARM_GOT_BREL12, 0x61) +ELF_RELOC(ARM_GOTOFF12, 0x62) +ELF_RELOC(ARM_GOTRELAX, 0x63) +ELF_RELOC(ARM_GNU_VTENTRY, 0x64) +ELF_RELOC(ARM_GNU_VTINHERIT, 0x65) +ELF_RELOC(ARM_THM_JUMP11, 0x66) +ELF_RELOC(ARM_THM_JUMP8, 0x67) +ELF_RELOC(ARM_TLS_GD32, 0x68) +ELF_RELOC(ARM_TLS_LDM32, 0x69) +ELF_RELOC(ARM_TLS_LDO32, 0x6a) +ELF_RELOC(ARM_TLS_IE32, 0x6b) +ELF_RELOC(ARM_TLS_LE32, 0x6c) +ELF_RELOC(ARM_TLS_LDO12, 0x6d) +ELF_RELOC(ARM_TLS_LE12, 0x6e) +ELF_RELOC(ARM_TLS_IE12GP, 0x6f) +ELF_RELOC(ARM_PRIVATE_0, 0x70) +ELF_RELOC(ARM_PRIVATE_1, 0x71) +ELF_RELOC(ARM_PRIVATE_2, 0x72) +ELF_RELOC(ARM_PRIVATE_3, 0x73) +ELF_RELOC(ARM_PRIVATE_4, 0x74) +ELF_RELOC(ARM_PRIVATE_5, 0x75) +ELF_RELOC(ARM_PRIVATE_6, 0x76) +ELF_RELOC(ARM_PRIVATE_7, 0x77) +ELF_RELOC(ARM_PRIVATE_8, 0x78) +ELF_RELOC(ARM_PRIVATE_9, 0x79) +ELF_RELOC(ARM_PRIVATE_10, 0x7a) +ELF_RELOC(ARM_PRIVATE_11, 0x7b) +ELF_RELOC(ARM_PRIVATE_12, 0x7c) +ELF_RELOC(ARM_PRIVATE_13, 0x7d) +ELF_RELOC(ARM_PRIVATE_14, 0x7e) +ELF_RELOC(ARM_PRIVATE_15, 0x7f) +ELF_RELOC(ARM_ME_TOO, 0x80) +ELF_RELOC(ARM_THM_TLS_DESCSEQ16, 0x81) +ELF_RELOC(ARM_THM_TLS_DESCSEQ32, 0x82) +ELF_RELOC(ARM_IRELATIVE, 0xa0) -ELF_RELOC(R_ARM_RXPC25, 0xF9) -ELF_RELOC(R_ARM_RSBREL32, 0xFA) -ELF_RELOC(R_ARM_THM_RPC22, 0xFB) -ELF_RELOC(R_ARM_RREL32, 0xFC) -ELF_RELOC(R_ARM_RPC24, 0xFD) -ELF_RELOC(R_ARM_RBASE, 0xFE) +ELF_RELOC(ARM_RXPC25, 0xF9) +ELF_RELOC(ARM_RSBREL32, 0xFA) +ELF_RELOC(ARM_THM_RPC22, 0xFB) +ELF_RELOC(ARM_RREL32, 0xFC) +ELF_RELOC(ARM_RPC24, 0xFD) +ELF_RELOC(ARM_RBASE, 0xFE) diff --git a/include/LIEF/ELF/Relocations/Hexagon.def b/include/LIEF/ELF/Relocations/Hexagon.def index c47cf198a2..6e8a4d6caf 100644 --- a/include/LIEF/ELF/Relocations/Hexagon.def +++ b/include/LIEF/ELF/Relocations/Hexagon.def @@ -4,97 +4,97 @@ #endif /* Release 5 ABI */ -ELF_RELOC(R_HEX_NONE, 0) -ELF_RELOC(R_HEX_B22_PCREL, 1) -ELF_RELOC(R_HEX_B15_PCREL, 2) -ELF_RELOC(R_HEX_B7_PCREL, 3) -ELF_RELOC(R_HEX_LO16, 4) -ELF_RELOC(R_HEX_HI16, 5) -ELF_RELOC(R_HEX_32, 6) -ELF_RELOC(R_HEX_16, 7) -ELF_RELOC(R_HEX_8, 8) -ELF_RELOC(R_HEX_GPREL16_0, 9) -ELF_RELOC(R_HEX_GPREL16_1, 10) -ELF_RELOC(R_HEX_GPREL16_2, 11) -ELF_RELOC(R_HEX_GPREL16_3, 12) -ELF_RELOC(R_HEX_HL16, 13) -ELF_RELOC(R_HEX_B13_PCREL, 14) -ELF_RELOC(R_HEX_B9_PCREL, 15) -ELF_RELOC(R_HEX_B32_PCREL_X, 16) -ELF_RELOC(R_HEX_32_6_X, 17) -ELF_RELOC(R_HEX_B22_PCREL_X, 18) -ELF_RELOC(R_HEX_B15_PCREL_X, 19) -ELF_RELOC(R_HEX_B13_PCREL_X, 20) -ELF_RELOC(R_HEX_B9_PCREL_X, 21) -ELF_RELOC(R_HEX_B7_PCREL_X, 22) -ELF_RELOC(R_HEX_16_X, 23) -ELF_RELOC(R_HEX_12_X, 24) -ELF_RELOC(R_HEX_11_X, 25) -ELF_RELOC(R_HEX_10_X, 26) -ELF_RELOC(R_HEX_9_X, 27) -ELF_RELOC(R_HEX_8_X, 28) -ELF_RELOC(R_HEX_7_X, 29) -ELF_RELOC(R_HEX_6_X, 30) -ELF_RELOC(R_HEX_32_PCREL, 31) -ELF_RELOC(R_HEX_COPY, 32) -ELF_RELOC(R_HEX_GLOB_DAT, 33) -ELF_RELOC(R_HEX_JMP_SLOT, 34) -ELF_RELOC(R_HEX_RELATIVE, 35) -ELF_RELOC(R_HEX_PLT_B22_PCREL, 36) -ELF_RELOC(R_HEX_GOTREL_LO16, 37) -ELF_RELOC(R_HEX_GOTREL_HI16, 38) -ELF_RELOC(R_HEX_GOTREL_32, 39) -ELF_RELOC(R_HEX_GOT_LO16, 40) -ELF_RELOC(R_HEX_GOT_HI16, 41) -ELF_RELOC(R_HEX_GOT_32, 42) -ELF_RELOC(R_HEX_GOT_16, 43) -ELF_RELOC(R_HEX_DTPMOD_32, 44) -ELF_RELOC(R_HEX_DTPREL_LO16, 45) -ELF_RELOC(R_HEX_DTPREL_HI16, 46) -ELF_RELOC(R_HEX_DTPREL_32, 47) -ELF_RELOC(R_HEX_DTPREL_16, 48) -ELF_RELOC(R_HEX_GD_PLT_B22_PCREL, 49) -ELF_RELOC(R_HEX_GD_GOT_LO16, 50) -ELF_RELOC(R_HEX_GD_GOT_HI16, 51) -ELF_RELOC(R_HEX_GD_GOT_32, 52) -ELF_RELOC(R_HEX_GD_GOT_16, 53) -ELF_RELOC(R_HEX_IE_LO16, 54) -ELF_RELOC(R_HEX_IE_HI16, 55) -ELF_RELOC(R_HEX_IE_32, 56) -ELF_RELOC(R_HEX_IE_GOT_LO16, 57) -ELF_RELOC(R_HEX_IE_GOT_HI16, 58) -ELF_RELOC(R_HEX_IE_GOT_32, 59) -ELF_RELOC(R_HEX_IE_GOT_16, 60) -ELF_RELOC(R_HEX_TPREL_LO16, 61) -ELF_RELOC(R_HEX_TPREL_HI16, 62) -ELF_RELOC(R_HEX_TPREL_32, 63) -ELF_RELOC(R_HEX_TPREL_16, 64) -ELF_RELOC(R_HEX_6_PCREL_X, 65) -ELF_RELOC(R_HEX_GOTREL_32_6_X, 66) -ELF_RELOC(R_HEX_GOTREL_16_X, 67) -ELF_RELOC(R_HEX_GOTREL_11_X, 68) -ELF_RELOC(R_HEX_GOT_32_6_X, 69) -ELF_RELOC(R_HEX_GOT_16_X, 70) -ELF_RELOC(R_HEX_GOT_11_X, 71) -ELF_RELOC(R_HEX_DTPREL_32_6_X, 72) -ELF_RELOC(R_HEX_DTPREL_16_X, 73) -ELF_RELOC(R_HEX_DTPREL_11_X, 74) -ELF_RELOC(R_HEX_GD_GOT_32_6_X, 75) -ELF_RELOC(R_HEX_GD_GOT_16_X, 76) -ELF_RELOC(R_HEX_GD_GOT_11_X, 77) -ELF_RELOC(R_HEX_IE_32_6_X, 78) -ELF_RELOC(R_HEX_IE_16_X, 79) -ELF_RELOC(R_HEX_IE_GOT_32_6_X, 80) -ELF_RELOC(R_HEX_IE_GOT_16_X, 81) -ELF_RELOC(R_HEX_IE_GOT_11_X, 82) -ELF_RELOC(R_HEX_TPREL_32_6_X, 83) -ELF_RELOC(R_HEX_TPREL_16_X, 84) -ELF_RELOC(R_HEX_TPREL_11_X, 85) -ELF_RELOC(R_HEX_LD_PLT_B22_PCREL, 86) -ELF_RELOC(R_HEX_LD_GOT_LO16, 87) -ELF_RELOC(R_HEX_LD_GOT_HI16, 88) -ELF_RELOC(R_HEX_LD_GOT_32, 89) -ELF_RELOC(R_HEX_LD_GOT_16, 90) -ELF_RELOC(R_HEX_LD_GOT_32_6_X, 91) -ELF_RELOC(R_HEX_LD_GOT_16_X, 92) -ELF_RELOC(R_HEX_LD_GOT_11_X, 93) +ELF_RELOC(HEX_NONE, 0) +ELF_RELOC(HEX_B22_PCREL, 1) +ELF_RELOC(HEX_B15_PCREL, 2) +ELF_RELOC(HEX_B7_PCREL, 3) +ELF_RELOC(HEX_LO16, 4) +ELF_RELOC(HEX_HI16, 5) +ELF_RELOC(HEX_32, 6) +ELF_RELOC(HEX_16, 7) +ELF_RELOC(HEX_8, 8) +ELF_RELOC(HEX_GPREL16_0, 9) +ELF_RELOC(HEX_GPREL16_1, 10) +ELF_RELOC(HEX_GPREL16_2, 11) +ELF_RELOC(HEX_GPREL16_3, 12) +ELF_RELOC(HEX_HL16, 13) +ELF_RELOC(HEX_B13_PCREL, 14) +ELF_RELOC(HEX_B9_PCREL, 15) +ELF_RELOC(HEX_B32_PCREL_X, 16) +ELF_RELOC(HEX_32_6_X, 17) +ELF_RELOC(HEX_B22_PCREL_X, 18) +ELF_RELOC(HEX_B15_PCREL_X, 19) +ELF_RELOC(HEX_B13_PCREL_X, 20) +ELF_RELOC(HEX_B9_PCREL_X, 21) +ELF_RELOC(HEX_B7_PCREL_X, 22) +ELF_RELOC(HEX_16_X, 23) +ELF_RELOC(HEX_12_X, 24) +ELF_RELOC(HEX_11_X, 25) +ELF_RELOC(HEX_10_X, 26) +ELF_RELOC(HEX_9_X, 27) +ELF_RELOC(HEX_8_X, 28) +ELF_RELOC(HEX_7_X, 29) +ELF_RELOC(HEX_6_X, 30) +ELF_RELOC(HEX_32_PCREL, 31) +ELF_RELOC(HEX_COPY, 32) +ELF_RELOC(HEX_GLOB_DAT, 33) +ELF_RELOC(HEX_JMP_SLOT, 34) +ELF_RELOC(HEX_RELATIVE, 35) +ELF_RELOC(HEX_PLT_B22_PCREL, 36) +ELF_RELOC(HEX_GOTREL_LO16, 37) +ELF_RELOC(HEX_GOTREL_HI16, 38) +ELF_RELOC(HEX_GOTREL_32, 39) +ELF_RELOC(HEX_GOT_LO16, 40) +ELF_RELOC(HEX_GOT_HI16, 41) +ELF_RELOC(HEX_GOT_32, 42) +ELF_RELOC(HEX_GOT_16, 43) +ELF_RELOC(HEX_DTPMOD_32, 44) +ELF_RELOC(HEX_DTPREL_LO16, 45) +ELF_RELOC(HEX_DTPREL_HI16, 46) +ELF_RELOC(HEX_DTPREL_32, 47) +ELF_RELOC(HEX_DTPREL_16, 48) +ELF_RELOC(HEX_GD_PLT_B22_PCREL, 49) +ELF_RELOC(HEX_GD_GOT_LO16, 50) +ELF_RELOC(HEX_GD_GOT_HI16, 51) +ELF_RELOC(HEX_GD_GOT_32, 52) +ELF_RELOC(HEX_GD_GOT_16, 53) +ELF_RELOC(HEX_IE_LO16, 54) +ELF_RELOC(HEX_IE_HI16, 55) +ELF_RELOC(HEX_IE_32, 56) +ELF_RELOC(HEX_IE_GOT_LO16, 57) +ELF_RELOC(HEX_IE_GOT_HI16, 58) +ELF_RELOC(HEX_IE_GOT_32, 59) +ELF_RELOC(HEX_IE_GOT_16, 60) +ELF_RELOC(HEX_TPREL_LO16, 61) +ELF_RELOC(HEX_TPREL_HI16, 62) +ELF_RELOC(HEX_TPREL_32, 63) +ELF_RELOC(HEX_TPREL_16, 64) +ELF_RELOC(HEX_6_PCREL_X, 65) +ELF_RELOC(HEX_GOTREL_32_6_X, 66) +ELF_RELOC(HEX_GOTREL_16_X, 67) +ELF_RELOC(HEX_GOTREL_11_X, 68) +ELF_RELOC(HEX_GOT_32_6_X, 69) +ELF_RELOC(HEX_GOT_16_X, 70) +ELF_RELOC(HEX_GOT_11_X, 71) +ELF_RELOC(HEX_DTPREL_32_6_X, 72) +ELF_RELOC(HEX_DTPREL_16_X, 73) +ELF_RELOC(HEX_DTPREL_11_X, 74) +ELF_RELOC(HEX_GD_GOT_32_6_X, 75) +ELF_RELOC(HEX_GD_GOT_16_X, 76) +ELF_RELOC(HEX_GD_GOT_11_X, 77) +ELF_RELOC(HEX_IE_32_6_X, 78) +ELF_RELOC(HEX_IE_16_X, 79) +ELF_RELOC(HEX_IE_GOT_32_6_X, 80) +ELF_RELOC(HEX_IE_GOT_16_X, 81) +ELF_RELOC(HEX_IE_GOT_11_X, 82) +ELF_RELOC(HEX_TPREL_32_6_X, 83) +ELF_RELOC(HEX_TPREL_16_X, 84) +ELF_RELOC(HEX_TPREL_11_X, 85) +ELF_RELOC(HEX_LD_PLT_B22_PCREL, 86) +ELF_RELOC(HEX_LD_GOT_LO16, 87) +ELF_RELOC(HEX_LD_GOT_HI16, 88) +ELF_RELOC(HEX_LD_GOT_32, 89) +ELF_RELOC(HEX_LD_GOT_16, 90) +ELF_RELOC(HEX_LD_GOT_32_6_X, 91) +ELF_RELOC(HEX_LD_GOT_16_X, 92) +ELF_RELOC(HEX_LD_GOT_11_X, 93) diff --git a/include/LIEF/ELF/Relocations/LoongArch.def b/include/LIEF/ELF/Relocations/LoongArch.def index 6699e73202..7b99fc587f 100644 --- a/include/LIEF/ELF/Relocations/LoongArch.def +++ b/include/LIEF/ELF/Relocations/LoongArch.def @@ -3,100 +3,100 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_LARCH_NONE, 0) -ELF_RELOC(R_LARCH_32, 1) -ELF_RELOC(R_LARCH_64, 2) -ELF_RELOC(R_LARCH_RELATIVE, 3) -ELF_RELOC(R_LARCH_COPY, 4) -ELF_RELOC(R_LARCH_JUMP_SLOT, 5) -ELF_RELOC(R_LARCH_TLS_DTPMOD32, 6) -ELF_RELOC(R_LARCH_TLS_DTPMOD64, 7) -ELF_RELOC(R_LARCH_TLS_DTPREL32, 8) -ELF_RELOC(R_LARCH_TLS_DTPREL64, 9) -ELF_RELOC(R_LARCH_TLS_TPREL32, 10) -ELF_RELOC(R_LARCH_TLS_TPREL64, 11) -ELF_RELOC(R_LARCH_IRELATIVE, 12) +ELF_RELOC(LARCH_NONE, 0) +ELF_RELOC(LARCH_32, 1) +ELF_RELOC(LARCH_64, 2) +ELF_RELOC(LARCH_RELATIVE, 3) +ELF_RELOC(LARCH_COPY, 4) +ELF_RELOC(LARCH_JUMP_SLOT, 5) +ELF_RELOC(LARCH_TLS_DTPMOD32, 6) +ELF_RELOC(LARCH_TLS_DTPMOD64, 7) +ELF_RELOC(LARCH_TLS_DTPREL32, 8) +ELF_RELOC(LARCH_TLS_DTPREL64, 9) +ELF_RELOC(LARCH_TLS_TPREL32, 10) +ELF_RELOC(LARCH_TLS_TPREL64, 11) +ELF_RELOC(LARCH_IRELATIVE, 12) -ELF_RELOC(R_LARCH_MARK_LA, 20) -ELF_RELOC(R_LARCH_MARK_PCREL, 21) +ELF_RELOC(LARCH_MARK_LA, 20) +ELF_RELOC(LARCH_MARK_PCREL, 21) -ELF_RELOC(R_LARCH_SOP_PUSH_PCREL, 22) +ELF_RELOC(LARCH_SOP_PUSH_PCREL, 22) -ELF_RELOC(R_LARCH_SOP_PUSH_ABSOLUTE, 23) +ELF_RELOC(LARCH_SOP_PUSH_ABSOLUTE, 23) -ELF_RELOC(R_LARCH_SOP_PUSH_DUP, 24) -ELF_RELOC(R_LARCH_SOP_PUSH_GPREL, 25) -ELF_RELOC(R_LARCH_SOP_PUSH_TLS_TPREL, 26) -ELF_RELOC(R_LARCH_SOP_PUSH_TLS_GOT, 27) -ELF_RELOC(R_LARCH_SOP_PUSH_TLS_GD, 28) -ELF_RELOC(R_LARCH_SOP_PUSH_PLT_PCREL, 29) +ELF_RELOC(LARCH_SOP_PUSH_DUP, 24) +ELF_RELOC(LARCH_SOP_PUSH_GPREL, 25) +ELF_RELOC(LARCH_SOP_PUSH_TLS_TPREL, 26) +ELF_RELOC(LARCH_SOP_PUSH_TLS_GOT, 27) +ELF_RELOC(LARCH_SOP_PUSH_TLS_GD, 28) +ELF_RELOC(LARCH_SOP_PUSH_PLT_PCREL, 29) -ELF_RELOC(R_LARCH_SOP_ASSERT, 30) -ELF_RELOC(R_LARCH_SOP_NOT, 31) -ELF_RELOC(R_LARCH_SOP_SUB, 32) -ELF_RELOC(R_LARCH_SOP_SL, 33) -ELF_RELOC(R_LARCH_SOP_SR, 34) -ELF_RELOC(R_LARCH_SOP_ADD, 35) -ELF_RELOC(R_LARCH_SOP_AND, 36) -ELF_RELOC(R_LARCH_SOP_IF_ELSE, 37) -ELF_RELOC(R_LARCH_SOP_POP_32_S_10_5, 38) -ELF_RELOC(R_LARCH_SOP_POP_32_U_10_12, 39) -ELF_RELOC(R_LARCH_SOP_POP_32_S_10_12, 40) -ELF_RELOC(R_LARCH_SOP_POP_32_S_10_16, 41) -ELF_RELOC(R_LARCH_SOP_POP_32_S_10_16_S2, 42) -ELF_RELOC(R_LARCH_SOP_POP_32_S_5_20, 43) -ELF_RELOC(R_LARCH_SOP_POP_32_S_0_5_10_16_S2, 44) -ELF_RELOC(R_LARCH_SOP_POP_32_S_0_10_10_16_S2, 45) -ELF_RELOC(R_LARCH_SOP_POP_32_U, 46) +ELF_RELOC(LARCH_SOP_ASSERT, 30) +ELF_RELOC(LARCH_SOP_NOT, 31) +ELF_RELOC(LARCH_SOP_SUB, 32) +ELF_RELOC(LARCH_SOP_SL, 33) +ELF_RELOC(LARCH_SOP_SR, 34) +ELF_RELOC(LARCH_SOP_ADD, 35) +ELF_RELOC(LARCH_SOP_AND, 36) +ELF_RELOC(LARCH_SOP_IF_ELSE, 37) +ELF_RELOC(LARCH_SOP_POP_32_S_10_5, 38) +ELF_RELOC(LARCH_SOP_POP_32_U_10_12, 39) +ELF_RELOC(LARCH_SOP_POP_32_S_10_12, 40) +ELF_RELOC(LARCH_SOP_POP_32_S_10_16, 41) +ELF_RELOC(LARCH_SOP_POP_32_S_10_16_S2, 42) +ELF_RELOC(LARCH_SOP_POP_32_S_5_20, 43) +ELF_RELOC(LARCH_SOP_POP_32_S_0_5_10_16_S2, 44) +ELF_RELOC(LARCH_SOP_POP_32_S_0_10_10_16_S2, 45) +ELF_RELOC(LARCH_SOP_POP_32_U, 46) -ELF_RELOC(R_LARCH_ADD8, 47) -ELF_RELOC(R_LARCH_ADD16, 48) -ELF_RELOC(R_LARCH_ADD24, 49) -ELF_RELOC(R_LARCH_ADD32, 50) -ELF_RELOC(R_LARCH_ADD64, 51) -ELF_RELOC(R_LARCH_SUB8, 52) -ELF_RELOC(R_LARCH_SUB16, 53) -ELF_RELOC(R_LARCH_SUB24, 54) -ELF_RELOC(R_LARCH_SUB32, 55) -ELF_RELOC(R_LARCH_SUB64, 56) +ELF_RELOC(LARCH_ADD8, 47) +ELF_RELOC(LARCH_ADD16, 48) +ELF_RELOC(LARCH_ADD24, 49) +ELF_RELOC(LARCH_ADD32, 50) +ELF_RELOC(LARCH_ADD64, 51) +ELF_RELOC(LARCH_SUB8, 52) +ELF_RELOC(LARCH_SUB16, 53) +ELF_RELOC(LARCH_SUB24, 54) +ELF_RELOC(LARCH_SUB32, 55) +ELF_RELOC(LARCH_SUB64, 56) -ELF_RELOC(R_LARCH_GNU_VTINHERIT, 57) -ELF_RELOC(R_LARCH_GNU_VTENTRY, 58) +ELF_RELOC(LARCH_GNU_VTINHERIT, 57) +ELF_RELOC(LARCH_GNU_VTENTRY, 58) -ELF_RELOC(R_LARCH_B16, 64) -ELF_RELOC(R_LARCH_B21, 65) -ELF_RELOC(R_LARCH_B26, 66) -ELF_RELOC(R_LARCH_ABS_HI20, 67) -ELF_RELOC(R_LARCH_ABS_LO12, 68) -ELF_RELOC(R_LARCH_ABS64_LO20, 69) -ELF_RELOC(R_LARCH_ABS64_HI12, 70) -ELF_RELOC(R_LARCH_PCALA_HI20, 71) -ELF_RELOC(R_LARCH_PCALA_LO12, 72) -ELF_RELOC(R_LARCH_PCALA64_LO20, 73) -ELF_RELOC(R_LARCH_PCALA64_HI12, 74) -ELF_RELOC(R_LARCH_GOT_PC_HI20, 75) -ELF_RELOC(R_LARCH_GOT_PC_LO12, 76) -ELF_RELOC(R_LARCH_GOT64_PC_LO20, 77) -ELF_RELOC(R_LARCH_GOT64_PC_HI12, 78) -ELF_RELOC(R_LARCH_GOT_HI20, 79) -ELF_RELOC(R_LARCH_GOT_LO12, 80) -ELF_RELOC(R_LARCH_GOT64_LO20, 81) -ELF_RELOC(R_LARCH_GOT64_HI12, 82) -ELF_RELOC(R_LARCH_TLS_LE_HI20, 83) -ELF_RELOC(R_LARCH_TLS_LE_LO12, 84) -ELF_RELOC(R_LARCH_TLS_LE64_LO20, 85) -ELF_RELOC(R_LARCH_TLS_LE64_HI12, 86) -ELF_RELOC(R_LARCH_TLS_IE_PC_HI20, 87) -ELF_RELOC(R_LARCH_TLS_IE_PC_LO12, 88) -ELF_RELOC(R_LARCH_TLS_IE64_PC_LO20, 89) -ELF_RELOC(R_LARCH_TLS_IE64_PC_HI12, 90) -ELF_RELOC(R_LARCH_TLS_IE_HI20, 91) -ELF_RELOC(R_LARCH_TLS_IE_LO12, 92) -ELF_RELOC(R_LARCH_TLS_IE64_LO20, 93) -ELF_RELOC(R_LARCH_TLS_IE64_HI12, 94) -ELF_RELOC(R_LARCH_TLS_LD_PC_HI20, 95) -ELF_RELOC(R_LARCH_TLS_LD_HI20, 96) -ELF_RELOC(R_LARCH_TLS_GD_PC_HI20, 97) -ELF_RELOC(R_LARCH_TLS_GD_HI20, 98) -ELF_RELOC(R_LARCH_32_PCREL, 99) -ELF_RELOC(R_LARCH_RELAX, 100) +ELF_RELOC(LARCH_B16, 64) +ELF_RELOC(LARCH_B21, 65) +ELF_RELOC(LARCH_B26, 66) +ELF_RELOC(LARCH_ABS_HI20, 67) +ELF_RELOC(LARCH_ABS_LO12, 68) +ELF_RELOC(LARCH_ABS64_LO20, 69) +ELF_RELOC(LARCH_ABS64_HI12, 70) +ELF_RELOC(LARCH_PCALA_HI20, 71) +ELF_RELOC(LARCH_PCALA_LO12, 72) +ELF_RELOC(LARCH_PCALA64_LO20, 73) +ELF_RELOC(LARCH_PCALA64_HI12, 74) +ELF_RELOC(LARCH_GOT_PC_HI20, 75) +ELF_RELOC(LARCH_GOT_PC_LO12, 76) +ELF_RELOC(LARCH_GOT64_PC_LO20, 77) +ELF_RELOC(LARCH_GOT64_PC_HI12, 78) +ELF_RELOC(LARCH_GOT_HI20, 79) +ELF_RELOC(LARCH_GOT_LO12, 80) +ELF_RELOC(LARCH_GOT64_LO20, 81) +ELF_RELOC(LARCH_GOT64_HI12, 82) +ELF_RELOC(LARCH_TLS_LE_HI20, 83) +ELF_RELOC(LARCH_TLS_LE_LO12, 84) +ELF_RELOC(LARCH_TLS_LE64_LO20, 85) +ELF_RELOC(LARCH_TLS_LE64_HI12, 86) +ELF_RELOC(LARCH_TLS_IE_PC_HI20, 87) +ELF_RELOC(LARCH_TLS_IE_PC_LO12, 88) +ELF_RELOC(LARCH_TLS_IE64_PC_LO20, 89) +ELF_RELOC(LARCH_TLS_IE64_PC_HI12, 90) +ELF_RELOC(LARCH_TLS_IE_HI20, 91) +ELF_RELOC(LARCH_TLS_IE_LO12, 92) +ELF_RELOC(LARCH_TLS_IE64_LO20, 93) +ELF_RELOC(LARCH_TLS_IE64_HI12, 94) +ELF_RELOC(LARCH_TLS_LD_PC_HI20, 95) +ELF_RELOC(LARCH_TLS_LD_HI20, 96) +ELF_RELOC(LARCH_TLS_GD_PC_HI20, 97) +ELF_RELOC(LARCH_TLS_GD_HI20, 98) +ELF_RELOC(LARCH_32_PCREL, 99) +ELF_RELOC(LARCH_RELAX, 100) diff --git a/include/LIEF/ELF/Relocations/Mips.def b/include/LIEF/ELF/Relocations/Mips.def index 77e7f8e871..1d128fecc6 100644 --- a/include/LIEF/ELF/Relocations/Mips.def +++ b/include/LIEF/ELF/Relocations/Mips.def @@ -3,115 +3,115 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_MIPS_NONE, 0) -ELF_RELOC(R_MIPS_16, 1) -ELF_RELOC(R_MIPS_32, 2) -ELF_RELOC(R_MIPS_REL32, 3) -ELF_RELOC(R_MIPS_26, 4) -ELF_RELOC(R_MIPS_HI16, 5) -ELF_RELOC(R_MIPS_LO16, 6) -ELF_RELOC(R_MIPS_GPREL16, 7) -ELF_RELOC(R_MIPS_LITERAL, 8) -ELF_RELOC(R_MIPS_GOT16, 9) -ELF_RELOC(R_MIPS_PC16, 10) -ELF_RELOC(R_MIPS_CALL16, 11) -ELF_RELOC(R_MIPS_GPREL32, 12) -ELF_RELOC(R_MIPS_UNUSED1, 13) -ELF_RELOC(R_MIPS_UNUSED2, 14) -ELF_RELOC(R_MIPS_UNUSED3, 15) -ELF_RELOC(R_MIPS_SHIFT5, 16) -ELF_RELOC(R_MIPS_SHIFT6, 17) -ELF_RELOC(R_MIPS_64, 18) -ELF_RELOC(R_MIPS_GOT_DISP, 19) -ELF_RELOC(R_MIPS_GOT_PAGE, 20) -ELF_RELOC(R_MIPS_GOT_OFST, 21) -ELF_RELOC(R_MIPS_GOT_HI16, 22) -ELF_RELOC(R_MIPS_GOT_LO16, 23) -ELF_RELOC(R_MIPS_SUB, 24) -ELF_RELOC(R_MIPS_INSERT_A, 25) -ELF_RELOC(R_MIPS_INSERT_B, 26) -ELF_RELOC(R_MIPS_DELETE, 27) -ELF_RELOC(R_MIPS_HIGHER, 28) -ELF_RELOC(R_MIPS_HIGHEST, 29) -ELF_RELOC(R_MIPS_CALL_HI16, 30) -ELF_RELOC(R_MIPS_CALL_LO16, 31) -ELF_RELOC(R_MIPS_SCN_DISP, 32) -ELF_RELOC(R_MIPS_REL16, 33) -ELF_RELOC(R_MIPS_ADD_IMMEDIATE, 34) -ELF_RELOC(R_MIPS_PJUMP, 35) -ELF_RELOC(R_MIPS_RELGOT, 36) -ELF_RELOC(R_MIPS_JALR, 37) -ELF_RELOC(R_MIPS_TLS_DTPMOD32, 38) -ELF_RELOC(R_MIPS_TLS_DTPREL32, 39) -ELF_RELOC(R_MIPS_TLS_DTPMOD64, 40) -ELF_RELOC(R_MIPS_TLS_DTPREL64, 41) -ELF_RELOC(R_MIPS_TLS_GD, 42) -ELF_RELOC(R_MIPS_TLS_LDM, 43) -ELF_RELOC(R_MIPS_TLS_DTPREL_HI16, 44) -ELF_RELOC(R_MIPS_TLS_DTPREL_LO16, 45) -ELF_RELOC(R_MIPS_TLS_GOTTPREL, 46) -ELF_RELOC(R_MIPS_TLS_TPREL32, 47) -ELF_RELOC(R_MIPS_TLS_TPREL64, 48) -ELF_RELOC(R_MIPS_TLS_TPREL_HI16, 49) -ELF_RELOC(R_MIPS_TLS_TPREL_LO16, 50) -ELF_RELOC(R_MIPS_GLOB_DAT, 51) -ELF_RELOC(R_MIPS_PC21_S2, 60) -ELF_RELOC(R_MIPS_PC26_S2, 61) -ELF_RELOC(R_MIPS_PC18_S3, 62) -ELF_RELOC(R_MIPS_PC19_S2, 63) -ELF_RELOC(R_MIPS_PCHI16, 64) -ELF_RELOC(R_MIPS_PCLO16, 65) -ELF_RELOC(R_MIPS16_26, 100) -ELF_RELOC(R_MIPS16_GPREL, 101) -ELF_RELOC(R_MIPS16_GOT16, 102) -ELF_RELOC(R_MIPS16_CALL16, 103) -ELF_RELOC(R_MIPS16_HI16, 104) -ELF_RELOC(R_MIPS16_LO16, 105) -ELF_RELOC(R_MIPS16_TLS_GD, 106) -ELF_RELOC(R_MIPS16_TLS_LDM, 107) -ELF_RELOC(R_MIPS16_TLS_DTPREL_HI16, 108) -ELF_RELOC(R_MIPS16_TLS_DTPREL_LO16, 109) -ELF_RELOC(R_MIPS16_TLS_GOTTPREL, 110) -ELF_RELOC(R_MIPS16_TLS_TPREL_HI16, 111) -ELF_RELOC(R_MIPS16_TLS_TPREL_LO16, 112) -ELF_RELOC(R_MIPS_COPY, 126) -ELF_RELOC(R_MIPS_JUMP_SLOT, 127) -ELF_RELOC(R_MICROMIPS_26_S1, 133) -ELF_RELOC(R_MICROMIPS_HI16, 134) -ELF_RELOC(R_MICROMIPS_LO16, 135) -ELF_RELOC(R_MICROMIPS_GPREL16, 136) -ELF_RELOC(R_MICROMIPS_LITERAL, 137) -ELF_RELOC(R_MICROMIPS_GOT16, 138) -ELF_RELOC(R_MICROMIPS_PC7_S1, 139) -ELF_RELOC(R_MICROMIPS_PC10_S1, 140) -ELF_RELOC(R_MICROMIPS_PC16_S1, 141) -ELF_RELOC(R_MICROMIPS_CALL16, 142) -ELF_RELOC(R_MICROMIPS_GOT_DISP, 145) -ELF_RELOC(R_MICROMIPS_GOT_PAGE, 146) -ELF_RELOC(R_MICROMIPS_GOT_OFST, 147) -ELF_RELOC(R_MICROMIPS_GOT_HI16, 148) -ELF_RELOC(R_MICROMIPS_GOT_LO16, 149) -ELF_RELOC(R_MICROMIPS_SUB, 150) -ELF_RELOC(R_MICROMIPS_HIGHER, 151) -ELF_RELOC(R_MICROMIPS_HIGHEST, 152) -ELF_RELOC(R_MICROMIPS_CALL_HI16, 153) -ELF_RELOC(R_MICROMIPS_CALL_LO16, 154) -ELF_RELOC(R_MICROMIPS_SCN_DISP, 155) -ELF_RELOC(R_MICROMIPS_JALR, 156) -ELF_RELOC(R_MICROMIPS_HI0_LO16, 157) -ELF_RELOC(R_MICROMIPS_TLS_GD, 162) -ELF_RELOC(R_MICROMIPS_TLS_LDM, 163) -ELF_RELOC(R_MICROMIPS_TLS_DTPREL_HI16, 164) -ELF_RELOC(R_MICROMIPS_TLS_DTPREL_LO16, 165) -ELF_RELOC(R_MICROMIPS_TLS_GOTTPREL, 166) -ELF_RELOC(R_MICROMIPS_TLS_TPREL_HI16, 169) -ELF_RELOC(R_MICROMIPS_TLS_TPREL_LO16, 170) -ELF_RELOC(R_MICROMIPS_GPREL7_S2, 172) -ELF_RELOC(R_MICROMIPS_PC23_S2, 173) -ELF_RELOC(R_MICROMIPS_PC21_S2, 174) -ELF_RELOC(R_MICROMIPS_PC26_S2, 175) -ELF_RELOC(R_MICROMIPS_PC18_S3, 176) -ELF_RELOC(R_MICROMIPS_PC19_S2, 177) -ELF_RELOC(R_MIPS_NUM, 218) -ELF_RELOC(R_MIPS_PC32, 248) -ELF_RELOC(R_MIPS_EH, 249) +ELF_RELOC(MIPS_NONE, 0) +ELF_RELOC(MIPS_16, 1) +ELF_RELOC(MIPS_32, 2) +ELF_RELOC(MIPS_REL32, 3) +ELF_RELOC(MIPS_26, 4) +ELF_RELOC(MIPS_HI16, 5) +ELF_RELOC(MIPS_LO16, 6) +ELF_RELOC(MIPS_GPREL16, 7) +ELF_RELOC(MIPS_LITERAL, 8) +ELF_RELOC(MIPS_GOT16, 9) +ELF_RELOC(MIPS_PC16, 10) +ELF_RELOC(MIPS_CALL16, 11) +ELF_RELOC(MIPS_GPREL32, 12) +ELF_RELOC(MIPS_UNUSED1, 13) +ELF_RELOC(MIPS_UNUSED2, 14) +ELF_RELOC(MIPS_UNUSED3, 15) +ELF_RELOC(MIPS_SHIFT5, 16) +ELF_RELOC(MIPS_SHIFT6, 17) +ELF_RELOC(MIPS_64, 18) +ELF_RELOC(MIPS_GOT_DISP, 19) +ELF_RELOC(MIPS_GOT_PAGE, 20) +ELF_RELOC(MIPS_GOT_OFST, 21) +ELF_RELOC(MIPS_GOT_HI16, 22) +ELF_RELOC(MIPS_GOT_LO16, 23) +ELF_RELOC(MIPS_SUB, 24) +ELF_RELOC(MIPS_INSERT_A, 25) +ELF_RELOC(MIPS_INSERT_B, 26) +ELF_RELOC(MIPS_DELETE, 27) +ELF_RELOC(MIPS_HIGHER, 28) +ELF_RELOC(MIPS_HIGHEST, 29) +ELF_RELOC(MIPS_CALL_HI16, 30) +ELF_RELOC(MIPS_CALL_LO16, 31) +ELF_RELOC(MIPS_SCN_DISP, 32) +ELF_RELOC(MIPS_REL16, 33) +ELF_RELOC(MIPS_ADD_IMMEDIATE, 34) +ELF_RELOC(MIPS_PJUMP, 35) +ELF_RELOC(MIPS_RELGOT, 36) +ELF_RELOC(MIPS_JALR, 37) +ELF_RELOC(MIPS_TLS_DTPMOD32, 38) +ELF_RELOC(MIPS_TLS_DTPREL32, 39) +ELF_RELOC(MIPS_TLS_DTPMOD64, 40) +ELF_RELOC(MIPS_TLS_DTPREL64, 41) +ELF_RELOC(MIPS_TLS_GD, 42) +ELF_RELOC(MIPS_TLS_LDM, 43) +ELF_RELOC(MIPS_TLS_DTPREL_HI16, 44) +ELF_RELOC(MIPS_TLS_DTPREL_LO16, 45) +ELF_RELOC(MIPS_TLS_GOTTPREL, 46) +ELF_RELOC(MIPS_TLS_TPREL32, 47) +ELF_RELOC(MIPS_TLS_TPREL64, 48) +ELF_RELOC(MIPS_TLS_TPREL_HI16, 49) +ELF_RELOC(MIPS_TLS_TPREL_LO16, 50) +ELF_RELOC(MIPS_GLOB_DAT, 51) +ELF_RELOC(MIPS_PC21_S2, 60) +ELF_RELOC(MIPS_PC26_S2, 61) +ELF_RELOC(MIPS_PC18_S3, 62) +ELF_RELOC(MIPS_PC19_S2, 63) +ELF_RELOC(MIPS_PCHI16, 64) +ELF_RELOC(MIPS_PCLO16, 65) +ELF_RELOC(MIPS16_26, 100) +ELF_RELOC(MIPS16_GPREL, 101) +ELF_RELOC(MIPS16_GOT16, 102) +ELF_RELOC(MIPS16_CALL16, 103) +ELF_RELOC(MIPS16_HI16, 104) +ELF_RELOC(MIPS16_LO16, 105) +ELF_RELOC(MIPS16_TLS_GD, 106) +ELF_RELOC(MIPS16_TLS_LDM, 107) +ELF_RELOC(MIPS16_TLS_DTPREL_HI16, 108) +ELF_RELOC(MIPS16_TLS_DTPREL_LO16, 109) +ELF_RELOC(MIPS16_TLS_GOTTPREL, 110) +ELF_RELOC(MIPS16_TLS_TPREL_HI16, 111) +ELF_RELOC(MIPS16_TLS_TPREL_LO16, 112) +ELF_RELOC(MIPS_COPY, 126) +ELF_RELOC(MIPS_JUMP_SLOT, 127) +ELF_RELOC(MICROMIPS_26_S1, 133) +ELF_RELOC(MICROMIPS_HI16, 134) +ELF_RELOC(MICROMIPS_LO16, 135) +ELF_RELOC(MICROMIPS_GPREL16, 136) +ELF_RELOC(MICROMIPS_LITERAL, 137) +ELF_RELOC(MICROMIPS_GOT16, 138) +ELF_RELOC(MICROMIPS_PC7_S1, 139) +ELF_RELOC(MICROMIPS_PC10_S1, 140) +ELF_RELOC(MICROMIPS_PC16_S1, 141) +ELF_RELOC(MICROMIPS_CALL16, 142) +ELF_RELOC(MICROMIPS_GOT_DISP, 145) +ELF_RELOC(MICROMIPS_GOT_PAGE, 146) +ELF_RELOC(MICROMIPS_GOT_OFST, 147) +ELF_RELOC(MICROMIPS_GOT_HI16, 148) +ELF_RELOC(MICROMIPS_GOT_LO16, 149) +ELF_RELOC(MICROMIPS_SUB, 150) +ELF_RELOC(MICROMIPS_HIGHER, 151) +ELF_RELOC(MICROMIPS_HIGHEST, 152) +ELF_RELOC(MICROMIPS_CALL_HI16, 153) +ELF_RELOC(MICROMIPS_CALL_LO16, 154) +ELF_RELOC(MICROMIPS_SCN_DISP, 155) +ELF_RELOC(MICROMIPS_JALR, 156) +ELF_RELOC(MICROMIPS_HI0_LO16, 157) +ELF_RELOC(MICROMIPS_TLS_GD, 162) +ELF_RELOC(MICROMIPS_TLS_LDM, 163) +ELF_RELOC(MICROMIPS_TLS_DTPREL_HI16, 164) +ELF_RELOC(MICROMIPS_TLS_DTPREL_LO16, 165) +ELF_RELOC(MICROMIPS_TLS_GOTTPREL, 166) +ELF_RELOC(MICROMIPS_TLS_TPREL_HI16, 169) +ELF_RELOC(MICROMIPS_TLS_TPREL_LO16, 170) +ELF_RELOC(MICROMIPS_GPREL7_S2, 172) +ELF_RELOC(MICROMIPS_PC23_S2, 173) +ELF_RELOC(MICROMIPS_PC21_S2, 174) +ELF_RELOC(MICROMIPS_PC26_S2, 175) +ELF_RELOC(MICROMIPS_PC18_S3, 176) +ELF_RELOC(MICROMIPS_PC19_S2, 177) +ELF_RELOC(MIPS_NUM, 218) +ELF_RELOC(MIPS_PC32, 248) +ELF_RELOC(MIPS_EH, 249) diff --git a/include/LIEF/ELF/Relocations/PowerPC.def b/include/LIEF/ELF/Relocations/PowerPC.def index 169fd7d83b..22ff6967d6 100644 --- a/include/LIEF/ELF/Relocations/PowerPC.def +++ b/include/LIEF/ELF/Relocations/PowerPC.def @@ -3,60 +3,60 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_PPC_NONE, 0) /* No relocation. */ -ELF_RELOC(R_PPC_ADDR32, 1) -ELF_RELOC(R_PPC_ADDR24, 2) -ELF_RELOC(R_PPC_ADDR16, 3) -ELF_RELOC(R_PPC_ADDR16_LO, 4) -ELF_RELOC(R_PPC_ADDR16_HI, 5) -ELF_RELOC(R_PPC_ADDR16_HA, 6) -ELF_RELOC(R_PPC_ADDR14, 7) -ELF_RELOC(R_PPC_ADDR14_BRTAKEN, 8) -ELF_RELOC(R_PPC_ADDR14_BRNTAKEN, 9) -ELF_RELOC(R_PPC_REL24, 10) -ELF_RELOC(R_PPC_REL14, 11) -ELF_RELOC(R_PPC_REL14_BRTAKEN, 12) -ELF_RELOC(R_PPC_REL14_BRNTAKEN, 13) -ELF_RELOC(R_PPC_GOT16, 14) -ELF_RELOC(R_PPC_GOT16_LO, 15) -ELF_RELOC(R_PPC_GOT16_HI, 16) -ELF_RELOC(R_PPC_GOT16_HA, 17) -ELF_RELOC(R_PPC_PLTREL24, 18) -ELF_RELOC(R_PPC_JMP_SLOT, 21) -ELF_RELOC(R_PPC_RELATIVE, 22) -ELF_RELOC(R_PPC_LOCAL24PC, 23) -ELF_RELOC(R_PPC_REL32, 26) -ELF_RELOC(R_PPC_TLS, 67) -ELF_RELOC(R_PPC_DTPMOD32, 68) -ELF_RELOC(R_PPC_TPREL16, 69) -ELF_RELOC(R_PPC_TPREL16_LO, 70) -ELF_RELOC(R_PPC_TPREL16_HI, 71) -ELF_RELOC(R_PPC_TPREL16_HA, 72) -ELF_RELOC(R_PPC_TPREL32, 73) -ELF_RELOC(R_PPC_DTPREL16, 74) -ELF_RELOC(R_PPC_DTPREL16_LO, 75) -ELF_RELOC(R_PPC_DTPREL16_HI, 76) -ELF_RELOC(R_PPC_DTPREL16_HA, 77) -ELF_RELOC(R_PPC_DTPREL32, 78) -ELF_RELOC(R_PPC_GOT_TLSGD16, 79) -ELF_RELOC(R_PPC_GOT_TLSGD16_LO, 80) -ELF_RELOC(R_PPC_GOT_TLSGD16_HI, 81) -ELF_RELOC(R_PPC_GOT_TLSGD16_HA, 82) -ELF_RELOC(R_PPC_GOT_TLSLD16, 83) -ELF_RELOC(R_PPC_GOT_TLSLD16_LO, 84) -ELF_RELOC(R_PPC_GOT_TLSLD16_HI, 85) -ELF_RELOC(R_PPC_GOT_TLSLD16_HA, 86) -ELF_RELOC(R_PPC_GOT_TPREL16, 87) -ELF_RELOC(R_PPC_GOT_TPREL16_LO, 88) -ELF_RELOC(R_PPC_GOT_TPREL16_HI, 89) -ELF_RELOC(R_PPC_GOT_TPREL16_HA, 90) -ELF_RELOC(R_PPC_GOT_DTPREL16, 91) -ELF_RELOC(R_PPC_GOT_DTPREL16_LO, 92) -ELF_RELOC(R_PPC_GOT_DTPREL16_HI, 93) -ELF_RELOC(R_PPC_GOT_DTPREL16_HA, 94) -ELF_RELOC(R_PPC_TLSGD, 95) -ELF_RELOC(R_PPC_TLSLD, 96) -ELF_RELOC(R_PPC_REL16, 249) -ELF_RELOC(R_PPC_REL16_LO, 250) -ELF_RELOC(R_PPC_REL16_HI, 251) -ELF_RELOC(R_PPC_REL16_HA, 252) +ELF_RELOC(PPC_NONE, 0) /* No relocation. */ +ELF_RELOC(PPC_ADDR32, 1) +ELF_RELOC(PPC_ADDR24, 2) +ELF_RELOC(PPC_ADDR16, 3) +ELF_RELOC(PPC_ADDR16_LO, 4) +ELF_RELOC(PPC_ADDR16_HI, 5) +ELF_RELOC(PPC_ADDR16_HA, 6) +ELF_RELOC(PPC_ADDR14, 7) +ELF_RELOC(PPC_ADDR14_BRTAKEN, 8) +ELF_RELOC(PPC_ADDR14_BRNTAKEN, 9) +ELF_RELOC(PPC_REL24, 10) +ELF_RELOC(PPC_REL14, 11) +ELF_RELOC(PPC_REL14_BRTAKEN, 12) +ELF_RELOC(PPC_REL14_BRNTAKEN, 13) +ELF_RELOC(PPC_GOT16, 14) +ELF_RELOC(PPC_GOT16_LO, 15) +ELF_RELOC(PPC_GOT16_HI, 16) +ELF_RELOC(PPC_GOT16_HA, 17) +ELF_RELOC(PPC_PLTREL24, 18) +ELF_RELOC(PPC_JMP_SLOT, 21) +ELF_RELOC(PPC_RELATIVE, 22) +ELF_RELOC(PPC_LOCAL24PC, 23) +ELF_RELOC(PPC_REL32, 26) +ELF_RELOC(PPC_TLS, 67) +ELF_RELOC(PPC_DTPMOD32, 68) +ELF_RELOC(PPC_TPREL16, 69) +ELF_RELOC(PPC_TPREL16_LO, 70) +ELF_RELOC(PPC_TPREL16_HI, 71) +ELF_RELOC(PPC_TPREL16_HA, 72) +ELF_RELOC(PPC_TPREL32, 73) +ELF_RELOC(PPC_DTPREL16, 74) +ELF_RELOC(PPC_DTPREL16_LO, 75) +ELF_RELOC(PPC_DTPREL16_HI, 76) +ELF_RELOC(PPC_DTPREL16_HA, 77) +ELF_RELOC(PPC_DTPREL32, 78) +ELF_RELOC(PPC_GOT_TLSGD16, 79) +ELF_RELOC(PPC_GOT_TLSGD16_LO, 80) +ELF_RELOC(PPC_GOT_TLSGD16_HI, 81) +ELF_RELOC(PPC_GOT_TLSGD16_HA, 82) +ELF_RELOC(PPC_GOT_TLSLD16, 83) +ELF_RELOC(PPC_GOT_TLSLD16_LO, 84) +ELF_RELOC(PPC_GOT_TLSLD16_HI, 85) +ELF_RELOC(PPC_GOT_TLSLD16_HA, 86) +ELF_RELOC(PPC_GOT_TPREL16, 87) +ELF_RELOC(PPC_GOT_TPREL16_LO, 88) +ELF_RELOC(PPC_GOT_TPREL16_HI, 89) +ELF_RELOC(PPC_GOT_TPREL16_HA, 90) +ELF_RELOC(PPC_GOT_DTPREL16, 91) +ELF_RELOC(PPC_GOT_DTPREL16_LO, 92) +ELF_RELOC(PPC_GOT_DTPREL16_HI, 93) +ELF_RELOC(PPC_GOT_DTPREL16_HA, 94) +ELF_RELOC(PPC_TLSGD, 95) +ELF_RELOC(PPC_TLSLD, 96) +ELF_RELOC(PPC_REL16, 249) +ELF_RELOC(PPC_REL16_LO, 250) +ELF_RELOC(PPC_REL16_HI, 251) +ELF_RELOC(PPC_REL16_HA, 252) diff --git a/include/LIEF/ELF/Relocations/PowerPC64.def b/include/LIEF/ELF/Relocations/PowerPC64.def index 2dee5cea24..b70ac5d0ae 100644 --- a/include/LIEF/ELF/Relocations/PowerPC64.def +++ b/include/LIEF/ELF/Relocations/PowerPC64.def @@ -3,87 +3,87 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_PPC64_NONE, 0) -ELF_RELOC(R_PPC64_ADDR32, 1) -ELF_RELOC(R_PPC64_ADDR24, 2) -ELF_RELOC(R_PPC64_ADDR16, 3) -ELF_RELOC(R_PPC64_ADDR16_LO, 4) -ELF_RELOC(R_PPC64_ADDR16_HI, 5) -ELF_RELOC(R_PPC64_ADDR16_HA, 6) -ELF_RELOC(R_PPC64_ADDR14, 7) -ELF_RELOC(R_PPC64_ADDR14_BRTAKEN, 8) -ELF_RELOC(R_PPC64_ADDR14_BRNTAKEN, 9) -ELF_RELOC(R_PPC64_REL24, 10) -ELF_RELOC(R_PPC64_REL14, 11) -ELF_RELOC(R_PPC64_REL14_BRTAKEN, 12) -ELF_RELOC(R_PPC64_REL14_BRNTAKEN, 13) -ELF_RELOC(R_PPC64_GOT16, 14) -ELF_RELOC(R_PPC64_GOT16_LO, 15) -ELF_RELOC(R_PPC64_GOT16_HI, 16) -ELF_RELOC(R_PPC64_GOT16_HA, 17) -ELF_RELOC(R_PPC64_JMP_SLOT, 21) -ELF_RELOC(R_PPC64_RELATIVE, 22) -ELF_RELOC(R_PPC64_REL32, 26) -ELF_RELOC(R_PPC64_ADDR64, 38) -ELF_RELOC(R_PPC64_ADDR16_HIGHER, 39) -ELF_RELOC(R_PPC64_ADDR16_HIGHERA, 40) -ELF_RELOC(R_PPC64_ADDR16_HIGHEST, 41) -ELF_RELOC(R_PPC64_ADDR16_HIGHESTA, 42) -ELF_RELOC(R_PPC64_REL64, 44) -ELF_RELOC(R_PPC64_TOC16, 47) -ELF_RELOC(R_PPC64_TOC16_LO, 48) -ELF_RELOC(R_PPC64_TOC16_HI, 49) -ELF_RELOC(R_PPC64_TOC16_HA, 50) -ELF_RELOC(R_PPC64_TOC, 51) -ELF_RELOC(R_PPC64_ADDR16_DS, 56) -ELF_RELOC(R_PPC64_ADDR16_LO_DS, 57) -ELF_RELOC(R_PPC64_GOT16_DS, 58) -ELF_RELOC(R_PPC64_GOT16_LO_DS, 59) -ELF_RELOC(R_PPC64_TOC16_DS, 63) -ELF_RELOC(R_PPC64_TOC16_LO_DS, 64) -ELF_RELOC(R_PPC64_TLS, 67) -ELF_RELOC(R_PPC64_DTPMOD64, 68) -ELF_RELOC(R_PPC64_TPREL16, 69) -ELF_RELOC(R_PPC64_TPREL16_LO, 70) -ELF_RELOC(R_PPC64_TPREL16_HI, 71) -ELF_RELOC(R_PPC64_TPREL16_HA, 72) -ELF_RELOC(R_PPC64_TPREL64, 73) -ELF_RELOC(R_PPC64_DTPREL16, 74) -ELF_RELOC(R_PPC64_DTPREL16_LO, 75) -ELF_RELOC(R_PPC64_DTPREL16_HI, 76) -ELF_RELOC(R_PPC64_DTPREL16_HA, 77) -ELF_RELOC(R_PPC64_DTPREL64, 78) -ELF_RELOC(R_PPC64_GOT_TLSGD16, 79) -ELF_RELOC(R_PPC64_GOT_TLSGD16_LO, 80) -ELF_RELOC(R_PPC64_GOT_TLSGD16_HI, 81) -ELF_RELOC(R_PPC64_GOT_TLSGD16_HA, 82) -ELF_RELOC(R_PPC64_GOT_TLSLD16, 83) -ELF_RELOC(R_PPC64_GOT_TLSLD16_LO, 84) -ELF_RELOC(R_PPC64_GOT_TLSLD16_HI, 85) -ELF_RELOC(R_PPC64_GOT_TLSLD16_HA, 86) -ELF_RELOC(R_PPC64_GOT_TPREL16_DS, 87) -ELF_RELOC(R_PPC64_GOT_TPREL16_LO_DS, 88) -ELF_RELOC(R_PPC64_GOT_TPREL16_HI, 89) -ELF_RELOC(R_PPC64_GOT_TPREL16_HA, 90) -ELF_RELOC(R_PPC64_GOT_DTPREL16_DS, 91) -ELF_RELOC(R_PPC64_GOT_DTPREL16_LO_DS, 92) -ELF_RELOC(R_PPC64_GOT_DTPREL16_HI, 93) -ELF_RELOC(R_PPC64_GOT_DTPREL16_HA, 94) -ELF_RELOC(R_PPC64_TPREL16_DS, 95) -ELF_RELOC(R_PPC64_TPREL16_LO_DS, 96) -ELF_RELOC(R_PPC64_TPREL16_HIGHER, 97) -ELF_RELOC(R_PPC64_TPREL16_HIGHERA, 98) -ELF_RELOC(R_PPC64_TPREL16_HIGHEST, 99) -ELF_RELOC(R_PPC64_TPREL16_HIGHESTA, 100) -ELF_RELOC(R_PPC64_DTPREL16_DS, 101) -ELF_RELOC(R_PPC64_DTPREL16_LO_DS, 102) -ELF_RELOC(R_PPC64_DTPREL16_HIGHER, 103) -ELF_RELOC(R_PPC64_DTPREL16_HIGHERA, 104) -ELF_RELOC(R_PPC64_DTPREL16_HIGHEST, 105) -ELF_RELOC(R_PPC64_DTPREL16_HIGHESTA, 106) -ELF_RELOC(R_PPC64_TLSGD, 107) -ELF_RELOC(R_PPC64_TLSLD, 108) -ELF_RELOC(R_PPC64_REL16, 249) -ELF_RELOC(R_PPC64_REL16_LO, 250) -ELF_RELOC(R_PPC64_REL16_HI, 251) -ELF_RELOC(R_PPC64_REL16_HA, 252) +ELF_RELOC(PPC64_NONE, 0) +ELF_RELOC(PPC64_ADDR32, 1) +ELF_RELOC(PPC64_ADDR24, 2) +ELF_RELOC(PPC64_ADDR16, 3) +ELF_RELOC(PPC64_ADDR16_LO, 4) +ELF_RELOC(PPC64_ADDR16_HI, 5) +ELF_RELOC(PPC64_ADDR16_HA, 6) +ELF_RELOC(PPC64_ADDR14, 7) +ELF_RELOC(PPC64_ADDR14_BRTAKEN, 8) +ELF_RELOC(PPC64_ADDR14_BRNTAKEN, 9) +ELF_RELOC(PPC64_REL24, 10) +ELF_RELOC(PPC64_REL14, 11) +ELF_RELOC(PPC64_REL14_BRTAKEN, 12) +ELF_RELOC(PPC64_REL14_BRNTAKEN, 13) +ELF_RELOC(PPC64_GOT16, 14) +ELF_RELOC(PPC64_GOT16_LO, 15) +ELF_RELOC(PPC64_GOT16_HI, 16) +ELF_RELOC(PPC64_GOT16_HA, 17) +ELF_RELOC(PPC64_JMP_SLOT, 21) +ELF_RELOC(PPC64_RELATIVE, 22) +ELF_RELOC(PPC64_REL32, 26) +ELF_RELOC(PPC64_ADDR64, 38) +ELF_RELOC(PPC64_ADDR16_HIGHER, 39) +ELF_RELOC(PPC64_ADDR16_HIGHERA, 40) +ELF_RELOC(PPC64_ADDR16_HIGHEST, 41) +ELF_RELOC(PPC64_ADDR16_HIGHESTA, 42) +ELF_RELOC(PPC64_REL64, 44) +ELF_RELOC(PPC64_TOC16, 47) +ELF_RELOC(PPC64_TOC16_LO, 48) +ELF_RELOC(PPC64_TOC16_HI, 49) +ELF_RELOC(PPC64_TOC16_HA, 50) +ELF_RELOC(PPC64_TOC, 51) +ELF_RELOC(PPC64_ADDR16_DS, 56) +ELF_RELOC(PPC64_ADDR16_LO_DS, 57) +ELF_RELOC(PPC64_GOT16_DS, 58) +ELF_RELOC(PPC64_GOT16_LO_DS, 59) +ELF_RELOC(PPC64_TOC16_DS, 63) +ELF_RELOC(PPC64_TOC16_LO_DS, 64) +ELF_RELOC(PPC64_TLS, 67) +ELF_RELOC(PPC64_DTPMOD64, 68) +ELF_RELOC(PPC64_TPREL16, 69) +ELF_RELOC(PPC64_TPREL16_LO, 70) +ELF_RELOC(PPC64_TPREL16_HI, 71) +ELF_RELOC(PPC64_TPREL16_HA, 72) +ELF_RELOC(PPC64_TPREL64, 73) +ELF_RELOC(PPC64_DTPREL16, 74) +ELF_RELOC(PPC64_DTPREL16_LO, 75) +ELF_RELOC(PPC64_DTPREL16_HI, 76) +ELF_RELOC(PPC64_DTPREL16_HA, 77) +ELF_RELOC(PPC64_DTPREL64, 78) +ELF_RELOC(PPC64_GOT_TLSGD16, 79) +ELF_RELOC(PPC64_GOT_TLSGD16_LO, 80) +ELF_RELOC(PPC64_GOT_TLSGD16_HI, 81) +ELF_RELOC(PPC64_GOT_TLSGD16_HA, 82) +ELF_RELOC(PPC64_GOT_TLSLD16, 83) +ELF_RELOC(PPC64_GOT_TLSLD16_LO, 84) +ELF_RELOC(PPC64_GOT_TLSLD16_HI, 85) +ELF_RELOC(PPC64_GOT_TLSLD16_HA, 86) +ELF_RELOC(PPC64_GOT_TPREL16_DS, 87) +ELF_RELOC(PPC64_GOT_TPREL16_LO_DS, 88) +ELF_RELOC(PPC64_GOT_TPREL16_HI, 89) +ELF_RELOC(PPC64_GOT_TPREL16_HA, 90) +ELF_RELOC(PPC64_GOT_DTPREL16_DS, 91) +ELF_RELOC(PPC64_GOT_DTPREL16_LO_DS, 92) +ELF_RELOC(PPC64_GOT_DTPREL16_HI, 93) +ELF_RELOC(PPC64_GOT_DTPREL16_HA, 94) +ELF_RELOC(PPC64_TPREL16_DS, 95) +ELF_RELOC(PPC64_TPREL16_LO_DS, 96) +ELF_RELOC(PPC64_TPREL16_HIGHER, 97) +ELF_RELOC(PPC64_TPREL16_HIGHERA, 98) +ELF_RELOC(PPC64_TPREL16_HIGHEST, 99) +ELF_RELOC(PPC64_TPREL16_HIGHESTA, 100) +ELF_RELOC(PPC64_DTPREL16_DS, 101) +ELF_RELOC(PPC64_DTPREL16_LO_DS, 102) +ELF_RELOC(PPC64_DTPREL16_HIGHER, 103) +ELF_RELOC(PPC64_DTPREL16_HIGHERA, 104) +ELF_RELOC(PPC64_DTPREL16_HIGHEST, 105) +ELF_RELOC(PPC64_DTPREL16_HIGHESTA, 106) +ELF_RELOC(PPC64_TLSGD, 107) +ELF_RELOC(PPC64_TLSLD, 108) +ELF_RELOC(PPC64_REL16, 249) +ELF_RELOC(PPC64_REL16_LO, 250) +ELF_RELOC(PPC64_REL16_HI, 251) +ELF_RELOC(PPC64_REL16_HA, 252) diff --git a/include/LIEF/ELF/Relocations/Sparc.def b/include/LIEF/ELF/Relocations/Sparc.def index 7e01a4a8a0..94e72e3b05 100644 --- a/include/LIEF/ELF/Relocations/Sparc.def +++ b/include/LIEF/ELF/Relocations/Sparc.def @@ -3,87 +3,87 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_SPARC_NONE, 0) -ELF_RELOC(R_SPARC_8, 1) -ELF_RELOC(R_SPARC_16, 2) -ELF_RELOC(R_SPARC_32, 3) -ELF_RELOC(R_SPARC_DISP8, 4) -ELF_RELOC(R_SPARC_DISP16, 5) -ELF_RELOC(R_SPARC_DISP32, 6) -ELF_RELOC(R_SPARC_WDISP30, 7) -ELF_RELOC(R_SPARC_WDISP22, 8) -ELF_RELOC(R_SPARC_HI22, 9) -ELF_RELOC(R_SPARC_22, 10) -ELF_RELOC(R_SPARC_13, 11) -ELF_RELOC(R_SPARC_LO10, 12) -ELF_RELOC(R_SPARC_GOT10, 13) -ELF_RELOC(R_SPARC_GOT13, 14) -ELF_RELOC(R_SPARC_GOT22, 15) -ELF_RELOC(R_SPARC_PC10, 16) -ELF_RELOC(R_SPARC_PC22, 17) -ELF_RELOC(R_SPARC_WPLT30, 18) -ELF_RELOC(R_SPARC_COPY, 19) -ELF_RELOC(R_SPARC_GLOB_DAT, 20) -ELF_RELOC(R_SPARC_JMP_SLOT, 21) -ELF_RELOC(R_SPARC_RELATIVE, 22) -ELF_RELOC(R_SPARC_UA32, 23) -ELF_RELOC(R_SPARC_PLT32, 24) -ELF_RELOC(R_SPARC_HIPLT22, 25) -ELF_RELOC(R_SPARC_LOPLT10, 26) -ELF_RELOC(R_SPARC_PCPLT32, 27) -ELF_RELOC(R_SPARC_PCPLT22, 28) -ELF_RELOC(R_SPARC_PCPLT10, 29) -ELF_RELOC(R_SPARC_10, 30) -ELF_RELOC(R_SPARC_11, 31) -ELF_RELOC(R_SPARC_64, 32) -ELF_RELOC(R_SPARC_OLO10, 33) -ELF_RELOC(R_SPARC_HH22, 34) -ELF_RELOC(R_SPARC_HM10, 35) -ELF_RELOC(R_SPARC_LM22, 36) -ELF_RELOC(R_SPARC_PC_HH22, 37) -ELF_RELOC(R_SPARC_PC_HM10, 38) -ELF_RELOC(R_SPARC_PC_LM22, 39) -ELF_RELOC(R_SPARC_WDISP16, 40) -ELF_RELOC(R_SPARC_WDISP19, 41) -ELF_RELOC(R_SPARC_7, 43) -ELF_RELOC(R_SPARC_5, 44) -ELF_RELOC(R_SPARC_6, 45) -ELF_RELOC(R_SPARC_DISP64, 46) -ELF_RELOC(R_SPARC_PLT64, 47) -ELF_RELOC(R_SPARC_HIX22, 48) -ELF_RELOC(R_SPARC_LOX10, 49) -ELF_RELOC(R_SPARC_H44, 50) -ELF_RELOC(R_SPARC_M44, 51) -ELF_RELOC(R_SPARC_L44, 52) -ELF_RELOC(R_SPARC_REGISTER, 53) -ELF_RELOC(R_SPARC_UA64, 54) -ELF_RELOC(R_SPARC_UA16, 55) -ELF_RELOC(R_SPARC_TLS_GD_HI22, 56) -ELF_RELOC(R_SPARC_TLS_GD_LO10, 57) -ELF_RELOC(R_SPARC_TLS_GD_ADD, 58) -ELF_RELOC(R_SPARC_TLS_GD_CALL, 59) -ELF_RELOC(R_SPARC_TLS_LDM_HI22, 60) -ELF_RELOC(R_SPARC_TLS_LDM_LO10, 61) -ELF_RELOC(R_SPARC_TLS_LDM_ADD, 62) -ELF_RELOC(R_SPARC_TLS_LDM_CALL, 63) -ELF_RELOC(R_SPARC_TLS_LDO_HIX22, 64) -ELF_RELOC(R_SPARC_TLS_LDO_LOX10, 65) -ELF_RELOC(R_SPARC_TLS_LDO_ADD, 66) -ELF_RELOC(R_SPARC_TLS_IE_HI22, 67) -ELF_RELOC(R_SPARC_TLS_IE_LO10, 68) -ELF_RELOC(R_SPARC_TLS_IE_LD, 69) -ELF_RELOC(R_SPARC_TLS_IE_LDX, 70) -ELF_RELOC(R_SPARC_TLS_IE_ADD, 71) -ELF_RELOC(R_SPARC_TLS_LE_HIX22, 72) -ELF_RELOC(R_SPARC_TLS_LE_LOX10, 73) -ELF_RELOC(R_SPARC_TLS_DTPMOD32, 74) -ELF_RELOC(R_SPARC_TLS_DTPMOD64, 75) -ELF_RELOC(R_SPARC_TLS_DTPOFF32, 76) -ELF_RELOC(R_SPARC_TLS_DTPOFF64, 77) -ELF_RELOC(R_SPARC_TLS_TPOFF32, 78) -ELF_RELOC(R_SPARC_TLS_TPOFF64, 79) -ELF_RELOC(R_SPARC_GOTDATA_HIX22, 80) -ELF_RELOC(R_SPARC_GOTDATA_LOX10, 81) -ELF_RELOC(R_SPARC_GOTDATA_OP_HIX22, 82) -ELF_RELOC(R_SPARC_GOTDATA_OP_LOX10, 83) -ELF_RELOC(R_SPARC_GOTDATA_OP, 84) +ELF_RELOC(SPARC_NONE, 0) +ELF_RELOC(SPARC_8, 1) +ELF_RELOC(SPARC_16, 2) +ELF_RELOC(SPARC_32, 3) +ELF_RELOC(SPARC_DISP8, 4) +ELF_RELOC(SPARC_DISP16, 5) +ELF_RELOC(SPARC_DISP32, 6) +ELF_RELOC(SPARC_WDISP30, 7) +ELF_RELOC(SPARC_WDISP22, 8) +ELF_RELOC(SPARC_HI22, 9) +ELF_RELOC(SPARC_22, 10) +ELF_RELOC(SPARC_13, 11) +ELF_RELOC(SPARC_LO10, 12) +ELF_RELOC(SPARC_GOT10, 13) +ELF_RELOC(SPARC_GOT13, 14) +ELF_RELOC(SPARC_GOT22, 15) +ELF_RELOC(SPARC_PC10, 16) +ELF_RELOC(SPARC_PC22, 17) +ELF_RELOC(SPARC_WPLT30, 18) +ELF_RELOC(SPARC_COPY, 19) +ELF_RELOC(SPARC_GLOB_DAT, 20) +ELF_RELOC(SPARC_JMP_SLOT, 21) +ELF_RELOC(SPARC_RELATIVE, 22) +ELF_RELOC(SPARC_UA32, 23) +ELF_RELOC(SPARC_PLT32, 24) +ELF_RELOC(SPARC_HIPLT22, 25) +ELF_RELOC(SPARC_LOPLT10, 26) +ELF_RELOC(SPARC_PCPLT32, 27) +ELF_RELOC(SPARC_PCPLT22, 28) +ELF_RELOC(SPARC_PCPLT10, 29) +ELF_RELOC(SPARC_10, 30) +ELF_RELOC(SPARC_11, 31) +ELF_RELOC(SPARC_64, 32) +ELF_RELOC(SPARC_OLO10, 33) +ELF_RELOC(SPARC_HH22, 34) +ELF_RELOC(SPARC_HM10, 35) +ELF_RELOC(SPARC_LM22, 36) +ELF_RELOC(SPARC_PC_HH22, 37) +ELF_RELOC(SPARC_PC_HM10, 38) +ELF_RELOC(SPARC_PC_LM22, 39) +ELF_RELOC(SPARC_WDISP16, 40) +ELF_RELOC(SPARC_WDISP19, 41) +ELF_RELOC(SPARC_7, 43) +ELF_RELOC(SPARC_5, 44) +ELF_RELOC(SPARC_6, 45) +ELF_RELOC(SPARC_DISP64, 46) +ELF_RELOC(SPARC_PLT64, 47) +ELF_RELOC(SPARC_HIX22, 48) +ELF_RELOC(SPARC_LOX10, 49) +ELF_RELOC(SPARC_H44, 50) +ELF_RELOC(SPARC_M44, 51) +ELF_RELOC(SPARC_L44, 52) +ELF_RELOC(SPARC_REGISTER, 53) +ELF_RELOC(SPARC_UA64, 54) +ELF_RELOC(SPARC_UA16, 55) +ELF_RELOC(SPARC_TLS_GD_HI22, 56) +ELF_RELOC(SPARC_TLS_GD_LO10, 57) +ELF_RELOC(SPARC_TLS_GD_ADD, 58) +ELF_RELOC(SPARC_TLS_GD_CALL, 59) +ELF_RELOC(SPARC_TLS_LDM_HI22, 60) +ELF_RELOC(SPARC_TLS_LDM_LO10, 61) +ELF_RELOC(SPARC_TLS_LDM_ADD, 62) +ELF_RELOC(SPARC_TLS_LDM_CALL, 63) +ELF_RELOC(SPARC_TLS_LDO_HIX22, 64) +ELF_RELOC(SPARC_TLS_LDO_LOX10, 65) +ELF_RELOC(SPARC_TLS_LDO_ADD, 66) +ELF_RELOC(SPARC_TLS_IE_HI22, 67) +ELF_RELOC(SPARC_TLS_IE_LO10, 68) +ELF_RELOC(SPARC_TLS_IE_LD, 69) +ELF_RELOC(SPARC_TLS_IE_LDX, 70) +ELF_RELOC(SPARC_TLS_IE_ADD, 71) +ELF_RELOC(SPARC_TLS_LE_HIX22, 72) +ELF_RELOC(SPARC_TLS_LE_LOX10, 73) +ELF_RELOC(SPARC_TLS_DTPMOD32, 74) +ELF_RELOC(SPARC_TLS_DTPMOD64, 75) +ELF_RELOC(SPARC_TLS_DTPOFF32, 76) +ELF_RELOC(SPARC_TLS_DTPOFF64, 77) +ELF_RELOC(SPARC_TLS_TPOFF32, 78) +ELF_RELOC(SPARC_TLS_TPOFF64, 79) +ELF_RELOC(SPARC_GOTDATA_HIX22, 80) +ELF_RELOC(SPARC_GOTDATA_LOX10, 81) +ELF_RELOC(SPARC_GOTDATA_OP_HIX22, 82) +ELF_RELOC(SPARC_GOTDATA_OP_LOX10, 83) +ELF_RELOC(SPARC_GOTDATA_OP, 84) diff --git a/include/LIEF/ELF/Relocations/SystemZ.def b/include/LIEF/ELF/Relocations/SystemZ.def index 711f94011f..17a84ed266 100644 --- a/include/LIEF/ELF/Relocations/SystemZ.def +++ b/include/LIEF/ELF/Relocations/SystemZ.def @@ -3,65 +3,65 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_390_NONE, 0) -ELF_RELOC(R_390_8, 1) -ELF_RELOC(R_390_12, 2) -ELF_RELOC(R_390_16, 3) -ELF_RELOC(R_390_32, 4) -ELF_RELOC(R_390_PC32, 5) -ELF_RELOC(R_390_GOT12, 6) -ELF_RELOC(R_390_GOT32, 7) -ELF_RELOC(R_390_PLT32, 8) -ELF_RELOC(R_390_COPY, 9) -ELF_RELOC(R_390_GLOB_DAT, 10) -ELF_RELOC(R_390_JMP_SLOT, 11) -ELF_RELOC(R_390_RELATIVE, 12) -ELF_RELOC(R_390_GOTOFF, 13) -ELF_RELOC(R_390_GOTPC, 14) -ELF_RELOC(R_390_GOT16, 15) -ELF_RELOC(R_390_PC16, 16) -ELF_RELOC(R_390_PC16DBL, 17) -ELF_RELOC(R_390_PLT16DBL, 18) -ELF_RELOC(R_390_PC32DBL, 19) -ELF_RELOC(R_390_PLT32DBL, 20) -ELF_RELOC(R_390_GOTPCDBL, 21) -ELF_RELOC(R_390_64, 22) -ELF_RELOC(R_390_PC64, 23) -ELF_RELOC(R_390_GOT64, 24) -ELF_RELOC(R_390_PLT64, 25) -ELF_RELOC(R_390_GOTENT, 26) -ELF_RELOC(R_390_GOTOFF16, 27) -ELF_RELOC(R_390_GOTOFF64, 28) -ELF_RELOC(R_390_GOTPLT12, 29) -ELF_RELOC(R_390_GOTPLT16, 30) -ELF_RELOC(R_390_GOTPLT32, 31) -ELF_RELOC(R_390_GOTPLT64, 32) -ELF_RELOC(R_390_GOTPLTENT, 33) -ELF_RELOC(R_390_PLTOFF16, 34) -ELF_RELOC(R_390_PLTOFF32, 35) -ELF_RELOC(R_390_PLTOFF64, 36) -ELF_RELOC(R_390_TLS_LOAD, 37) -ELF_RELOC(R_390_TLS_GDCALL, 38) -ELF_RELOC(R_390_TLS_LDCALL, 39) -ELF_RELOC(R_390_TLS_GD32, 40) -ELF_RELOC(R_390_TLS_GD64, 41) -ELF_RELOC(R_390_TLS_GOTIE12, 42) -ELF_RELOC(R_390_TLS_GOTIE32, 43) -ELF_RELOC(R_390_TLS_GOTIE64, 44) -ELF_RELOC(R_390_TLS_LDM32, 45) -ELF_RELOC(R_390_TLS_LDM64, 46) -ELF_RELOC(R_390_TLS_IE32, 47) -ELF_RELOC(R_390_TLS_IE64, 48) -ELF_RELOC(R_390_TLS_IEENT, 49) -ELF_RELOC(R_390_TLS_LE32, 50) -ELF_RELOC(R_390_TLS_LE64, 51) -ELF_RELOC(R_390_TLS_LDO32, 52) -ELF_RELOC(R_390_TLS_LDO64, 53) -ELF_RELOC(R_390_TLS_DTPMOD, 54) -ELF_RELOC(R_390_TLS_DTPOFF, 55) -ELF_RELOC(R_390_TLS_TPOFF, 56) -ELF_RELOC(R_390_20, 57) -ELF_RELOC(R_390_GOT20, 58) -ELF_RELOC(R_390_GOTPLT20, 59) -ELF_RELOC(R_390_TLS_GOTIE20, 60) -ELF_RELOC(R_390_IRELATIVE, 61) +ELF_RELOC(SYSZ_NONE, 0) +ELF_RELOC(SYSZ_8, 1) +ELF_RELOC(SYSZ_12, 2) +ELF_RELOC(SYSZ_16, 3) +ELF_RELOC(SYSZ_32, 4) +ELF_RELOC(SYSZ_PC32, 5) +ELF_RELOC(SYSZ_GOT12, 6) +ELF_RELOC(SYSZ_GOT32, 7) +ELF_RELOC(SYSZ_PLT32, 8) +ELF_RELOC(SYSZ_COPY, 9) +ELF_RELOC(SYSZ_GLOB_DAT, 10) +ELF_RELOC(SYSZ_JMP_SLOT, 11) +ELF_RELOC(SYSZ_RELATIVE, 12) +ELF_RELOC(SYSZ_GOTOFF, 13) +ELF_RELOC(SYSZ_GOTPC, 14) +ELF_RELOC(SYSZ_GOT16, 15) +ELF_RELOC(SYSZ_PC16, 16) +ELF_RELOC(SYSZ_PC16DBL, 17) +ELF_RELOC(SYSZ_PLT16DBL, 18) +ELF_RELOC(SYSZ_PC32DBL, 19) +ELF_RELOC(SYSZ_PLT32DBL, 20) +ELF_RELOC(SYSZ_GOTPCDBL, 21) +ELF_RELOC(SYSZ_64, 22) +ELF_RELOC(SYSZ_PC64, 23) +ELF_RELOC(SYSZ_GOT64, 24) +ELF_RELOC(SYSZ_PLT64, 25) +ELF_RELOC(SYSZ_GOTENT, 26) +ELF_RELOC(SYSZ_GOTOFF16, 27) +ELF_RELOC(SYSZ_GOTOFF64, 28) +ELF_RELOC(SYSZ_GOTPLT12, 29) +ELF_RELOC(SYSZ_GOTPLT16, 30) +ELF_RELOC(SYSZ_GOTPLT32, 31) +ELF_RELOC(SYSZ_GOTPLT64, 32) +ELF_RELOC(SYSZ_GOTPLTENT, 33) +ELF_RELOC(SYSZ_PLTOFF16, 34) +ELF_RELOC(SYSZ_PLTOFF32, 35) +ELF_RELOC(SYSZ_PLTOFF64, 36) +ELF_RELOC(SYSZ_TLS_LOAD, 37) +ELF_RELOC(SYSZ_TLS_GDCALL, 38) +ELF_RELOC(SYSZ_TLS_LDCALL, 39) +ELF_RELOC(SYSZ_TLS_GD32, 40) +ELF_RELOC(SYSZ_TLS_GD64, 41) +ELF_RELOC(SYSZ_TLS_GOTIE12, 42) +ELF_RELOC(SYSZ_TLS_GOTIE32, 43) +ELF_RELOC(SYSZ_TLS_GOTIE64, 44) +ELF_RELOC(SYSZ_TLS_LDM32, 45) +ELF_RELOC(SYSZ_TLS_LDM64, 46) +ELF_RELOC(SYSZ_TLS_IE32, 47) +ELF_RELOC(SYSZ_TLS_IE64, 48) +ELF_RELOC(SYSZ_TLS_IEENT, 49) +ELF_RELOC(SYSZ_TLS_LE32, 50) +ELF_RELOC(SYSZ_TLS_LE64, 51) +ELF_RELOC(SYSZ_TLS_LDO32, 52) +ELF_RELOC(SYSZ_TLS_LDO64, 53) +ELF_RELOC(SYSZ_TLS_DTPMOD, 54) +ELF_RELOC(SYSZ_TLS_DTPOFF, 55) +ELF_RELOC(SYSZ_TLS_TPOFF, 56) +ELF_RELOC(SYSZ_20, 57) +ELF_RELOC(SYSZ_GOT20, 58) +ELF_RELOC(SYSZ_GOTPLT20, 59) +ELF_RELOC(SYSZ_TLS_GOTIE20, 60) +ELF_RELOC(SYSZ_IRELATIVE, 61) diff --git a/include/LIEF/ELF/Relocations/i386.def b/include/LIEF/ELF/Relocations/i386.def index a128cd7b78..a24059261e 100644 --- a/include/LIEF/ELF/Relocations/i386.def +++ b/include/LIEF/ELF/Relocations/i386.def @@ -4,44 +4,43 @@ #endif /* TODO: this is just a subset */ -ELF_RELOC(R_386_NONE, 0) -ELF_RELOC(R_386_32, 1) -ELF_RELOC(R_386_PC32, 2) -ELF_RELOC(R_386_GOT32, 3) -ELF_RELOC(R_386_PLT32, 4) -ELF_RELOC(R_386_COPY, 5) -ELF_RELOC(R_386_GLOB_DAT, 6) -ELF_RELOC(R_386_JUMP_SLOT, 7) -ELF_RELOC(R_386_RELATIVE, 8) -ELF_RELOC(R_386_GOTOFF, 9) -ELF_RELOC(R_386_GOTPC, 10) -ELF_RELOC(R_386_32PLT, 11) -ELF_RELOC(R_386_TLS_TPOFF, 14) -ELF_RELOC(R_386_TLS_IE, 15) -ELF_RELOC(R_386_TLS_GOTIE, 16) -ELF_RELOC(R_386_TLS_LE, 17) -ELF_RELOC(R_386_TLS_GD, 18) -ELF_RELOC(R_386_TLS_LDM, 19) -ELF_RELOC(R_386_16, 20) -ELF_RELOC(R_386_PC16, 21) -ELF_RELOC(R_386_8, 22) -ELF_RELOC(R_386_PC8, 23) -ELF_RELOC(R_386_TLS_GD_32, 24) -ELF_RELOC(R_386_TLS_GD_PUSH, 25) -ELF_RELOC(R_386_TLS_GD_CALL, 26) -ELF_RELOC(R_386_TLS_GD_POP, 27) -ELF_RELOC(R_386_TLS_LDM_32, 28) -ELF_RELOC(R_386_TLS_LDM_PUSH, 29) -ELF_RELOC(R_386_TLS_LDM_CALL, 30) -ELF_RELOC(R_386_TLS_LDM_POP, 31) -ELF_RELOC(R_386_TLS_LDO_32, 32) -ELF_RELOC(R_386_TLS_IE_32, 33) -ELF_RELOC(R_386_TLS_LE_32, 34) -ELF_RELOC(R_386_TLS_DTPMOD32, 35) -ELF_RELOC(R_386_TLS_DTPOFF32, 36) -ELF_RELOC(R_386_TLS_TPOFF32, 37) -ELF_RELOC(R_386_TLS_GOTDESC, 39) -ELF_RELOC(R_386_TLS_DESC_CALL, 40) -ELF_RELOC(R_386_TLS_DESC, 41) -ELF_RELOC(R_386_IRELATIVE, 42) -ELF_RELOC(R_386_NUM, 43) +ELF_RELOC(X86_NONE, 0) +ELF_RELOC(X86_32, 1) +ELF_RELOC(X86_PC32, 2) +ELF_RELOC(X86_GOT32, 3) +ELF_RELOC(X86_PLT32, 4) +ELF_RELOC(X86_COPY, 5) +ELF_RELOC(X86_GLOB_DAT, 6) +ELF_RELOC(X86_JUMP_SLOT, 7) +ELF_RELOC(X86_RELATIVE, 8) +ELF_RELOC(X86_GOTOFF, 9) +ELF_RELOC(X86_GOTPC, 10) +ELF_RELOC(X86_32PLT, 11) +ELF_RELOC(X86_TLS_TPOFF, 14) +ELF_RELOC(X86_TLS_IE, 15) +ELF_RELOC(X86_TLS_GOTIE, 16) +ELF_RELOC(X86_TLS_LE, 17) +ELF_RELOC(X86_TLS_GD, 18) +ELF_RELOC(X86_TLS_LDM, 19) +ELF_RELOC(X86_16, 20) +ELF_RELOC(X86_PC16, 21) +ELF_RELOC(X86_8, 22) +ELF_RELOC(X86_PC8, 23) +ELF_RELOC(X86_TLS_GD_32, 24) +ELF_RELOC(X86_TLS_GD_PUSH, 25) +ELF_RELOC(X86_TLS_GD_CALL, 26) +ELF_RELOC(X86_TLS_GD_POP, 27) +ELF_RELOC(X86_TLS_LDM_32, 28) +ELF_RELOC(X86_TLS_LDM_PUSH, 29) +ELF_RELOC(X86_TLS_LDM_CALL, 30) +ELF_RELOC(X86_TLS_LDM_POP, 31) +ELF_RELOC(X86_TLS_LDO_32, 32) +ELF_RELOC(X86_TLS_IE_32, 33) +ELF_RELOC(X86_TLS_LE_32, 34) +ELF_RELOC(X86_TLS_DTPMOD32, 35) +ELF_RELOC(X86_TLS_DTPOFF32, 36) +ELF_RELOC(X86_TLS_TPOFF32, 37) +ELF_RELOC(X86_TLS_GOTDESC, 39) +ELF_RELOC(X86_TLS_DESC_CALL, 40) +ELF_RELOC(X86_TLS_DESC, 41) +ELF_RELOC(X86_IRELATIVE, 42) diff --git a/include/LIEF/ELF/Relocations/x86_64.def b/include/LIEF/ELF/Relocations/x86_64.def index 299635dd45..10533ad0be 100644 --- a/include/LIEF/ELF/Relocations/x86_64.def +++ b/include/LIEF/ELF/Relocations/x86_64.def @@ -3,48 +3,48 @@ #error "ELF_RELOC must be defined" #endif -ELF_RELOC(R_X86_64_NONE, 0) -ELF_RELOC(R_X86_64_64, 1) -ELF_RELOC(R_X86_64_PC32, 2) -ELF_RELOC(R_X86_64_GOT32, 3) -ELF_RELOC(R_X86_64_PLT32, 4) -ELF_RELOC(R_X86_64_COPY, 5) -ELF_RELOC(R_X86_64_GLOB_DAT, 6) -ELF_RELOC(R_X86_64_JUMP_SLOT, 7) -ELF_RELOC(R_X86_64_RELATIVE, 8) -ELF_RELOC(R_X86_64_GOTPCREL, 9) -ELF_RELOC(R_X86_64_32, 10) -ELF_RELOC(R_X86_64_32S, 11) -ELF_RELOC(R_X86_64_16, 12) -ELF_RELOC(R_X86_64_PC16, 13) -ELF_RELOC(R_X86_64_8, 14) -ELF_RELOC(R_X86_64_PC8, 15) -ELF_RELOC(R_X86_64_DTPMOD64, 16) -ELF_RELOC(R_X86_64_DTPOFF64, 17) -ELF_RELOC(R_X86_64_TPOFF64, 18) -ELF_RELOC(R_X86_64_TLSGD, 19) -ELF_RELOC(R_X86_64_TLSLD, 20) -ELF_RELOC(R_X86_64_DTPOFF32, 21) -ELF_RELOC(R_X86_64_GOTTPOFF, 22) -ELF_RELOC(R_X86_64_TPOFF32, 23) -ELF_RELOC(R_X86_64_PC64, 24) -ELF_RELOC(R_X86_64_GOTOFF64, 25) -ELF_RELOC(R_X86_64_GOTPC32, 26) -ELF_RELOC(R_X86_64_GOT64, 27) -ELF_RELOC(R_X86_64_GOTPCREL64, 28) -ELF_RELOC(R_X86_64_GOTPC64, 29) -ELF_RELOC(R_X86_64_GOTPLT64, 30) -ELF_RELOC(R_X86_64_PLTOFF64, 31) -ELF_RELOC(R_X86_64_SIZE32, 32) -ELF_RELOC(R_X86_64_SIZE64, 33) -ELF_RELOC(R_X86_64_GOTPC32_TLSDESC, 34) -ELF_RELOC(R_X86_64_TLSDESC_CALL, 35) -ELF_RELOC(R_X86_64_TLSDESC, 36) -ELF_RELOC(R_X86_64_IRELATIVE, 37) +ELF_RELOC(X86_64_NONE, 0) +ELF_RELOC(X86_64_64, 1) +ELF_RELOC(X86_64_PC32, 2) +ELF_RELOC(X86_64_GOT32, 3) +ELF_RELOC(X86_64_PLT32, 4) +ELF_RELOC(X86_64_COPY, 5) +ELF_RELOC(X86_64_GLOB_DAT, 6) +ELF_RELOC(X86_64_JUMP_SLOT, 7) +ELF_RELOC(X86_64_RELATIVE, 8) +ELF_RELOC(X86_64_GOTPCREL, 9) +ELF_RELOC(X86_64_32, 10) +ELF_RELOC(X86_64_32S, 11) +ELF_RELOC(X86_64_16, 12) +ELF_RELOC(X86_64_PC16, 13) +ELF_RELOC(X86_64_8, 14) +ELF_RELOC(X86_64_PC8, 15) +ELF_RELOC(X86_64_DTPMOD64, 16) +ELF_RELOC(X86_64_DTPOFF64, 17) +ELF_RELOC(X86_64_TPOFF64, 18) +ELF_RELOC(X86_64_TLSGD, 19) +ELF_RELOC(X86_64_TLSLD, 20) +ELF_RELOC(X86_64_DTPOFF32, 21) +ELF_RELOC(X86_64_GOTTPOFF, 22) +ELF_RELOC(X86_64_TPOFF32, 23) +ELF_RELOC(X86_64_PC64, 24) +ELF_RELOC(X86_64_GOTOFF64, 25) +ELF_RELOC(X86_64_GOTPC32, 26) +ELF_RELOC(X86_64_GOT64, 27) +ELF_RELOC(X86_64_GOTPCREL64, 28) +ELF_RELOC(X86_64_GOTPC64, 29) +ELF_RELOC(X86_64_GOTPLT64, 30) +ELF_RELOC(X86_64_PLTOFF64, 31) +ELF_RELOC(X86_64_SIZE32, 32) +ELF_RELOC(X86_64_SIZE64, 33) +ELF_RELOC(X86_64_GOTPC32_TLSDESC, 34) +ELF_RELOC(X86_64_TLSDESC_CALL, 35) +ELF_RELOC(X86_64_TLSDESC, 36) +ELF_RELOC(X86_64_IRELATIVE, 37) -ELF_RELOC(R_X86_64_RELATIVE64, 38) -ELF_RELOC(R_X86_64_PC32_BND, 39) -ELF_RELOC(R_X86_64_PLT32_BND, 40) -ELF_RELOC(R_X86_64_GOTPCRELX, 41) -ELF_RELOC(R_X86_64_REX_GOTPCRELX, 42) +ELF_RELOC(X86_64_RELATIVE64, 38) +ELF_RELOC(X86_64_PC32_BND, 39) +ELF_RELOC(X86_64_PLT32_BND, 40) +ELF_RELOC(X86_64_GOTPCRELX, 41) +ELF_RELOC(X86_64_REX_GOTPCRELX, 42) diff --git a/include/LIEF/ELF/Section.hpp b/include/LIEF/ELF/Section.hpp index abf9b4c221..0541525260 100644 --- a/include/LIEF/ELF/Section.hpp +++ b/include/LIEF/ELF/Section.hpp @@ -17,12 +17,11 @@ #define LIEF_ELF_SECTION_H #include -#include #include -#include +#include +#include "LIEF/utils.hpp" #include "LIEF/visibility.h" - #include "LIEF/Abstract/Section.hpp" #include "LIEF/ELF/enums.hpp" @@ -42,10 +41,6 @@ class Builder; class ExeLayout; class ObjectFileLayout; -namespace details { -struct Elf64_Shdr; -struct Elf32_Shdr; -} //! Class wich represents an ELF Section class LIEF_API Section : public LIEF::Section { @@ -60,19 +55,121 @@ class LIEF_API Section : public LIEF::Section { using it_segments = ref_iterator; using it_const_segments = const_ref_iterator; - Section(const uint8_t *data, ELF_CLASS type); - Section(const details::Elf64_Shdr& header); - Section(const details::Elf32_Shdr& header); - Section(const std::string& name, ELF_SECTION_TYPES type = ELF_SECTION_TYPES::SHT_PROGBITS); + static constexpr uint32_t MAX_SECTION_SIZE = 2_GB; + + enum class TYPE : uint64_t { + SHT_NULL = 0, /**< No associated section (inactive entry). */ + PROGBITS = 1, /**< Program-defined contents. */ + SYMTAB = 2, /**< Symbol table. */ + STRTAB = 3, /**< String table. */ + RELA = 4, /**< Relocation entries; explicit addends. */ + HASH = 5, /**< Symbol hash table. */ + DYNAMIC = 6, /**< Information for dynamic linking. */ + NOTE = 7, /**< Information about the file. */ + NOBITS = 8, /**< Data occupies no space in the file. */ + REL = 9, /**< Relocation entries; no explicit addends. */ + SHLIB = 10, /**< Reserved. */ + DYNSYM = 11, /**< Symbol table. */ + INIT_ARRAY = 14, /**< Pointers to initialization functions. */ + FINI_ARRAY = 15, /**< Pointers to termination functions. */ + PREINIT_ARRAY = 16, /**< Pointers to pre-init functions. */ + GROUP = 17, /**< Section group. */ + SYMTAB_SHNDX = 18, /**< Indices for SHN_XINDEX entries. */ + RELR = 19, + + ANDROID_REL = 0x60000001, /**< Packed relocations (Android specific). */ + ANDROID_RELA = 0x60000002, /**< Packed relocations (Android specific). */ + LLVM_ADDRSIG = 0x6fff4c03, /**< This section is used to mark symbols as address-significant. */ + ANDROID_RELR = 0x6fffff00, /**< New relr relocations (Android specific). */ + GNU_ATTRIBUTES = 0x6ffffff5, /**< Object attributes. */ + GNU_HASH = 0x6ffffff6, /**< GNU-style hash table. */ + GNU_VERDEF = 0x6ffffffd, /**< GNU version definitions. */ + GNU_VERNEED = 0x6ffffffe, /**< GNU version references. */ + GNU_VERSYM = 0x6fffffff, /**< GNU symbol versions table. */ + + _ID_SHIFT_ = 32, + _ARM_ID_ = 1LLU, _HEX_ID_ = 2LLU, _X86_64_ID_ = 2LLU, + _MIPS_ID_ = 3LLU, + + ARM_EXIDX = 0x70000001U + (_ARM_ID_ << _ID_SHIFT_), /**< Exception Index table */ + ARM_PREEMPTMAP = 0x70000002U + (_ARM_ID_ << _ID_SHIFT_), /**< BPABI DLL dynamic linking pre-emption map */ + ARM_ATTRIBUTES = 0x70000003U + (_ARM_ID_ << _ID_SHIFT_), /**< Object file compatibility attributes */ + ARM_DEBUGOVERLAY = 0x70000004U + (_ARM_ID_ << _ID_SHIFT_), + ARM_OVERLAYSECTION = 0x70000005U + (_ARM_ID_ << _ID_SHIFT_), + + HEX_ORDERED = 0x70000000 + (_HEX_ID_ << _ID_SHIFT_), /**< Link editor is to sort the entries in */ + + /* this section based on their sizes */ + X86_64_UNWIND = 0x70000001 + (_X86_64_ID_ << _ID_SHIFT_), /**< Unwind information */ + + MIPS_REGINFO = 0x70000006 + (_MIPS_ID_ << _ID_SHIFT_), /**< Register usage information */ + MIPS_OPTIONS = 0x7000000d + (_MIPS_ID_ << _ID_SHIFT_), /**< General options */ + MIPS_ABIFLAGS = 0x7000002a + (_MIPS_ID_ << _ID_SHIFT_), /**< ABI information. */ + }; + + enum class FLAGS : uint64_t { + NONE = 0x000000000, + WRITE = 0x000000001, /**< Section data should be writable during execution. */ + ALLOC = 0x000000002, /**< Section occupies memory during program execution. */ + EXECINSTR = 0x000000004, /**< Section contains executable machine instructions. */ + MERGE = 0x000000010, /**< The data in this section may be merged. */ + STRINGS = 0x000000020, /**< The data in this section is null-terminated strings. */ + INFO_LINK = 0x000000040, /**< A field in this section holds a section header table index. */ + LINK_ORDER = 0x000000080, /**< Adds special ordering requirements for link editors. */ + OS_NONCONFORMING = 0x000000100, /**< This section requires special OS-specific processing to avoid incorrect behavior */ + GROUP = 0x000000200, /**< This section is a member of a section group. */ + TLS = 0x000000400, /**< This section holds Thread-Local Storage. */ + COMPRESSED = 0x000000800, + GNU_RETAIN = 0x000200000, + EXCLUDE = 0x080000000, + + _ID_SHIFT_ = 32, + _XCORE_ID_ = 1LLU, _HEX_ID_ = 3LLU, _X86_64_ID_ = 2LLU, + _MIPS_ID_ = 4LLU, _ARM_ID_ = 5LLU, + + XCORE_SHF_DP_SECTION = 0x010000000 + (_XCORE_ID_ << _ID_SHIFT_), + XCORE_SHF_CP_SECTION = 0x020000000 + (_XCORE_ID_ << _ID_SHIFT_), + + X86_64_LARGE = 0x010000000 + (_X86_64_ID_ << _ID_SHIFT_), + + HEX_GPREL = 0x010000000 + (_HEX_ID_ << _ID_SHIFT_), + + MIPS_NODUPES = 0x010000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_NAMES = 0x020000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_LOCAL = 0x040000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_NOSTRIP = 0x080000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_GPREL = 0x010000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_MERGE = 0x020000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_ADDR = 0x040000000 + (_MIPS_ID_ << _ID_SHIFT_), + MIPS_STRING = 0x080000000 + (_MIPS_ID_ << _ID_SHIFT_), + + ARM_PURECODE = 0x020000000 + (_ARM_ID_ << _ID_SHIFT_), + }; + + static constexpr uint64_t FLAG_MASK = (uint64_t(1) << uint8_t(FLAGS::_ID_SHIFT_)) - 1; + static constexpr uint64_t TYPE_MASK = (uint64_t(1) << uint8_t(TYPE::_ID_SHIFT_)) - 1; + + static TYPE type_from(uint32_t value, ARCH arch); + static uint32_t to_value(TYPE type) { + return static_cast(type) & TYPE_MASK; + } + - Section(); - ~Section() override; + Section(const std::string& name, TYPE type = TYPE::PROGBITS) : + LIEF::Section(name), + type_{type} + {} + + Section() = default; + ~Section() override = default; Section& operator=(Section other); Section(const Section& other); void swap(Section& other); - ELF_SECTION_TYPES type() const; + TYPE type() const { + return type_; + } //! Section's content span content() const override; @@ -82,44 +179,55 @@ class LIEF_API Section : public LIEF::Section { void content(std::vector&& data); - //! Section flags LIEF::ELF::ELF_SECTION_FLAGS - uint64_t flags() const; + //! Section flags + uint64_t flags() const { + return flags_; + } //! ``True`` if the section has the given flag - //! - //! @param[in] flag flag to test - bool has(ELF_SECTION_FLAGS flag) const; + bool has(FLAGS flag) const; //! ``True`` if the section is wrapped by the given Segment bool has(const Segment& segment) const; //! Return section flags as a ``std::set`` - std::set flags_list() const; + std::vector flags_list() const; - uint64_t size() const override; + uint64_t size() const override { + return size_; + } void size(uint64_t size) override; void offset(uint64_t offset) override; - uint64_t offset() const override; - + uint64_t offset() const override { + return offset_; + } //! @see offset - uint64_t file_offset() const; + uint64_t file_offset() const { + return this->offset(); + } //! Original size of the section's data. //! //! This value is used by the ELF::Builder to determines if it needs //! to be relocated to avoid an override of the data - uint64_t original_size() const; + uint64_t original_size() const { + return original_size_; + } //! Section file alignment - uint64_t alignment() const; + uint64_t alignment() const { + return address_align_; + } //! Section information. //! This meaning of this value depends on the section's type - uint64_t information() const; + uint64_t information() const { + return info_; + } //! This function returns the size of an element in the case of a section that contains //! an array. @@ -127,31 +235,63 @@ class LIEF_API Section : public LIEF::Section { //! For instance, the `.dynamic` section contains an array of DynamicEntry. As the //! size of the raw C structure of this entry is 0x10 (``sizeof(Elf64_Dyn)``) //! in a ELF64, the `entry_size` is set to this value. - uint64_t entry_size() const; + uint64_t entry_size() const { + return entry_size_; + } //! Index to another section - uint32_t link() const; + uint32_t link() const { + return link_; + } //! Clear the content of the section with the given ``value`` Section& clear(uint8_t value = 0); //! Add the given ELF_SECTION_FLAGS - void add(ELF_SECTION_FLAGS flag); + void add(FLAGS flag); //! Remove the given ELF_SECTION_FLAGS - void remove(ELF_SECTION_FLAGS flag); + void remove(FLAGS flag); - void type(ELF_SECTION_TYPES type); - void flags(uint64_t flags); - void clear_flags(); - void file_offset(uint64_t offset); - void link(uint32_t link); - void information(uint32_t info); - void alignment(uint64_t alignment); - void entry_size(uint64_t entry_size); + void type(TYPE type) { + type_ = type; + } - it_segments segments(); - it_const_segments segments() const; + void flags(uint64_t flags) { + flags_ = flags; + } + + void clear_flags() { + flags_ = 0; + } + + void file_offset(uint64_t offset) { + this->offset(offset); + } + + void link(uint32_t link) { + link_ = link; + } + + void information(uint32_t info) { + info_ = info; + } + + void alignment(uint64_t alignment) { + address_align_ = alignment; + } + + void entry_size(uint64_t entry_size) { + entry_size_ = entry_size; + } + + it_segments segments() { + return segments_; + } + + it_const_segments segments() const { + return segments_; + } Section& as_frame() { is_frame_ = true; @@ -164,27 +304,43 @@ class LIEF_API Section : public LIEF::Section { void accept(Visitor& visitor) const override; - Section& operator+=(ELF_SECTION_FLAGS c); - Section& operator-=(ELF_SECTION_FLAGS c); + Section& operator+=(FLAGS c) { + add(c); + return *this; + } + Section& operator-=(FLAGS c) { + remove(c); + return *this; + } LIEF_API friend std::ostream& operator<<(std::ostream& os, const Section& section); private: + template + LIEF_LOCAL Section(const T& header, ARCH arch); + span writable_content(); - ELF_SECTION_TYPES type_ = ELF_SECTION_TYPES::SHT_PROGBITS; - uint64_t flags_ = 0; - uint64_t original_size_ = 0; - uint32_t link_ = 0; - uint32_t info_ = 0; - uint64_t address_align_ = 0x1000; - uint64_t entry_size_ = 0; - segments_t segments_; - bool is_frame_ = false; + ARCH arch_ = ARCH::NONE; + TYPE type_ = TYPE::SHT_NULL; + uint64_t flags_ = 0; + uint64_t original_size_ = 0; + uint32_t link_ = 0; + uint32_t info_ = 0; + uint64_t address_align_ = 0; + uint64_t entry_size_ = 0; + segments_t segments_; + bool is_frame_ = false; DataHandler::Handler* datahandler_ = nullptr; - std::vector content_c_; + std::vector content_c_; }; +LIEF_API const char* to_string(Section::TYPE e); +LIEF_API const char* to_string(Section::FLAGS e); + } } -#endif /* _ELF_SECTION_H */ + +ENABLE_BITMASK_OPERATORS(LIEF::ELF::Section::FLAGS) + +#endif diff --git a/include/LIEF/ELF/Segment.hpp b/include/LIEF/ELF/Segment.hpp index 51d0d68192..f9c9aec3c8 100644 --- a/include/LIEF/ELF/Segment.hpp +++ b/include/LIEF/ELF/Segment.hpp @@ -40,11 +40,6 @@ class Binary; class Section; class Builder; -namespace details { -struct Elf64_Phdr; -struct Elf32_Phdr; -} - //! Class which represents the ELF segments class LIEF_API Segment : public Object { @@ -58,57 +53,139 @@ class LIEF_API Segment : public Object { using it_sections = ref_iterator; using it_const_sections = const_ref_iterator; + static constexpr uint64_t PT_BIT = 33; + static constexpr uint64_t PT_MASK = (uint64_t(1) << PT_BIT) - 1; + + static constexpr uint64_t PT_ARM = uint64_t(1) << PT_BIT; + static constexpr uint64_t PT_AARCH64 = uint64_t(2) << PT_BIT; + static constexpr uint64_t PT_MIPS = uint64_t(3) << PT_BIT; + static constexpr uint64_t PT_RISCV = uint64_t(4) << PT_BIT; + + enum class TYPE : uint64_t { + UNKNOWN = uint64_t(-1), + PT_NULL = 0, /**< Unused segment. */ + LOAD = 1, /**< Loadable segment. */ + DYNAMIC = 2, /**< Dynamic linking information. */ + INTERP = 3, /**< Interpreter pathname. */ + NOTE = 4, /**< Auxiliary information. */ + SHLIB = 5, /**< Reserved. */ + PHDR = 6, /**< The program header table itself. */ + TLS = 7, /**< The thread-local storage template. */ + + GNU_EH_FRAME = 0x6474e550, + + GNU_STACK = 0x6474e551, /**< Indicates stack executability. */ + GNU_PROPERTY = 0x6474e553, /**< GNU property */ + GNU_RELRO = 0x6474e552, /**< Read-only after relocation. */ + + ARM_ARCHEXT = 0x70000000 | PT_ARM, /**< Platform architecture compatibility info */ + ARM_EXIDX = 0x70000001 | PT_ARM, + ARM_UNWIND = 0x70000001 | PT_ARM, + + AARCH64_MEMTAG_MTE = 0x70000002 | PT_AARCH64, + + MIPS_REGINFO = 0x70000000 | PT_MIPS, /**< Register usage information. */ + MIPS_RTPROC = 0x70000001 | PT_MIPS, /**< Runtime procedure table. */ + MIPS_OPTIONS = 0x70000002 | PT_MIPS, /**< Options segment. */ + MIPS_ABIFLAGS = 0x70000003 | PT_MIPS, /**< Abiflags segment. */ + + RISCV_ATTRIBUTES = 0x70000003 | PT_RISCV, + }; + + enum class FLAGS { + NONE = 0, + X = 1, + W = 2, + R = 4, + }; + + static TYPE type_from(uint64_t value, ARCH arch); + static uint64_t to_value(TYPE type) { + return static_cast(type) & PT_MASK; + } + static result from_raw(const uint8_t* ptr, size_t size); - static result from_raw(const std::vector& raw); + static result from_raw(const std::vector& raw) { + return from_raw(raw.data(), raw.size()); + } - Segment(); - Segment(const details::Elf64_Phdr& header); - Segment(const details::Elf32_Phdr& header); - ~Segment() override; + Segment() = default; + + ~Segment() override = default; Segment& operator=(Segment other); Segment(const Segment& other); - Segment& operator=(Segment&&); - Segment(Segment&&); + Segment& operator=(Segment&&) = default; + Segment(Segment&&) = default; void swap(Segment& other); + bool is_load() const { + return type() == TYPE::LOAD; + } + + bool is_interpreter() const { + return type() == TYPE::INTERP; + } + + bool is_phdr() const { + return type() == TYPE::PHDR; + } + //! The segment's type (LOAD, DYNAMIC, ...) - SEGMENT_TYPES type() const; + TYPE type() const { + return type_; + } //! The flag permissions associated with this segment - ELF_SEGMENT_FLAGS flags() const; + FLAGS flags() const { + return FLAGS(flags_); + } //! The file offset of the data associated with this segment - uint64_t file_offset() const; + uint64_t file_offset() const { + return file_offset_; + } //! The virtual address of the segment. - uint64_t virtual_address() const; + uint64_t virtual_address() const { + return virtual_address_; + } //! The physical address of the segment. //! This value is not really relevant on systems like Linux or Android. //! On the other hand, Qualcomm trustlets might use this value. //! //! Usually this value matches virtual_address - uint64_t physical_address() const; + uint64_t physical_address() const { + return physical_address_; + } //! The **file** size of the data associated with this segment - uint64_t physical_size() const; + uint64_t physical_size() const { + return size_; + } //! The in-memory size of this segment. //! Usually, if the ``.bss`` segment is wrapped by this segment //! then, virtual_size is larger than physical_size - uint64_t virtual_size() const; + uint64_t virtual_size() const { + return virtual_size_; + } //! The offset alignment of the segment - uint64_t alignment() const; + uint64_t alignment() const { + return alignment_; + } //! The raw data associated with this segment. span content() const; //! Check if the current segment has the given flag - bool has(ELF_SEGMENT_FLAGS flag) const; + bool has(FLAGS flag) const { + return (flags_ & static_cast(flag)) != 0; + } //! Check if the current segment wraps the given ELF::Section bool has(const Section& section) const; @@ -117,20 +194,47 @@ class LIEF_API Segment : public Object { bool has(const std::string& section_name) const; //! Append the given ELF_SEGMENT_FLAGS - void add(ELF_SEGMENT_FLAGS flag); + void add(FLAGS flag); //! Remove the given ELF_SEGMENT_FLAGS - void remove(ELF_SEGMENT_FLAGS flag); + void remove(FLAGS flag); + + void type(TYPE type) { + type_ = type; + } + + void flags(FLAGS flags) { + flags_ = static_cast(flags); + } + + void flags(uint32_t flags) { + flags_ = flags; + } + + void clear_flags() { + flags_ = 0; + } - void type(SEGMENT_TYPES type); - void flags(ELF_SEGMENT_FLAGS flags); - void clear_flags(); void file_offset(uint64_t file_offset); - void virtual_address(uint64_t virtual_address); - void physical_address(uint64_t physical_address); + + void virtual_address(uint64_t virtual_address) { + virtual_address_ = virtual_address; + } + + void physical_address(uint64_t physical_address) { + physical_address_ = physical_address; + } + void physical_size(uint64_t physical_size); - void virtual_size(uint64_t virtual_size); - void alignment(uint64_t alignment); + + void virtual_size(uint64_t virtual_size) { + virtual_size_ = virtual_size; + } + + void alignment(uint64_t alignment) { + alignment_ = alignment; + } + void content(std::vector content); template T get_content_value(size_t offset) const; @@ -138,36 +242,56 @@ class LIEF_API Segment : public Object { size_t get_content_size() const; //! Iterator over the sections wrapped by this segment - it_sections sections(); - it_const_sections sections() const; + it_sections sections() { + return sections_; + } + + it_const_sections sections() const { + return sections_; + } void accept(Visitor& visitor) const override; - Segment& operator+=(ELF_SEGMENT_FLAGS flag); - Segment& operator-=(ELF_SEGMENT_FLAGS flag); + Segment& operator+=(FLAGS flag) { + add(flag); + return *this; + } + Segment& operator-=(FLAGS flag) { + remove(flag); + return *this; + } LIEF_API friend std::ostream& operator<<(std::ostream& os, const Segment& segment); private: + template + LIEF_LOCAL Segment(const T& header, ARCH arch = ARCH::NONE); + uint64_t handler_size() const; span writable_content(); - SEGMENT_TYPES type_ = SEGMENT_TYPES::PT_NULL; - ELF_SEGMENT_FLAGS flags_ = ELF_SEGMENT_FLAGS::PF_NONE; - uint64_t file_offset_ = 0; - uint64_t virtual_address_ = 0; - uint64_t physical_address_ = 0; - uint64_t size_ = 0; - uint64_t virtual_size_ = 0; - uint64_t alignment_ = 0; - uint64_t handler_size_ = 0; - sections_t sections_; + TYPE type_ = TYPE::PT_NULL; + ARCH arch_ = ARCH::NONE; + uint32_t flags_ = 0; + uint64_t file_offset_ = 0; + uint64_t virtual_address_ = 0; + uint64_t physical_address_ = 0; + uint64_t size_ = 0; + uint64_t virtual_size_ = 0; + uint64_t alignment_ = 0; + uint64_t handler_size_ = 0; + sections_t sections_; DataHandler::Handler* datahandler_ = nullptr; std::vector content_c_; }; - +LIEF_API const char* to_string(Segment::TYPE e); +LIEF_API const char* to_string(Segment::FLAGS e); } } + + +ENABLE_BITMASK_OPERATORS(LIEF::ELF::Segment::FLAGS) + #endif /* _ELF_SEGMENT_H */ diff --git a/include/LIEF/ELF/Symbol.hpp b/include/LIEF/ELF/Symbol.hpp index c81d5d0e61..678b2797eb 100644 --- a/include/LIEF/ELF/Symbol.hpp +++ b/include/LIEF/ELF/Symbol.hpp @@ -22,7 +22,6 @@ #include "LIEF/visibility.h" #include "LIEF/Abstract/Symbol.hpp" - #include "LIEF/ELF/enums.hpp" namespace LIEF { @@ -32,95 +31,187 @@ class Binary; class SymbolVersion; class Section; -namespace details { -struct Elf32_Sym; -struct Elf64_Sym; -} - -//! Class which represents an ELF symbol +/// Class which represents an ELF symbol class LIEF_API Symbol : public LIEF::Symbol { friend class Parser; friend class Binary; + public: + + enum class BINDING { + LOCAL = 0, ///< Local symbol + GLOBAL = 1, ///< Global symbols + WEAK = 2, ///< Weak symbol + GNU_UNIQUE = 10, ///< Unique symbol + }; + + /// Type of the symbol. This enum matches the `STT_xxx` values of the ELF + /// specs + enum class TYPE { + NOTYPE = 0, ///< Symbol's type is not specified + OBJECT = 1, ///< Symbol is a data object (variable, array, etc.) + FUNC = 2, ///< Symbol is executable code (function, etc.) + SECTION = 3, ///< Symbol refers to a section + FILE = 4, ///< Local, absolute symbol that refers to a file + COMMON = 5, ///< An uninitialized common block + TLS = 6, ///< Thread local data object + GNU_IFUNC = 10, ///< GNU indirect function + }; + + /// Visibility of the symbol. This enum matches the `STV_xxx` values of the + /// official ELF specs + enum class VISIBILITY { + DEFAULT = 0, ///< Visibility is specified by binding type + INTERNAL = 1, ///< Defined by processor supplements + HIDDEN = 2, ///< Not visible to other components + PROTECTED = 3 ///< Visible in other components but not preemptable + }; + + /// Special section indices + enum SECTION_INDEX { + UNDEF = 0, ///< Undefined section + ABS = 0xfff1, ///< Associated symbol is absolute + COMMON = 0xfff2, ///< Associated symbol is common + }; public: - Symbol(const details::Elf32_Sym& header, ARCH arch); - Symbol(const details::Elf64_Sym& header, ARCH arch); - Symbol(std::string name, - ELF_SYMBOL_TYPES type = ELF_SYMBOL_TYPES::STT_NOTYPE, - SYMBOL_BINDINGS binding = SYMBOL_BINDINGS::STB_WEAK, - uint8_t other = 0, uint16_t shndx = 0, - uint64_t value = 0, uint64_t size = 0); - Symbol(); + Symbol(std::string name): + LIEF::Symbol(std::move(name), 0, 0) + {} + + static BINDING binding_from(uint32_t value, ARCH) { + return BINDING(value); + } + + static TYPE type_from(uint32_t value, ARCH) { + return TYPE(value); + } + + static uint8_t to_value(BINDING binding) { + return static_cast(binding); + } - ~Symbol() override; + static uint8_t to_value(TYPE type) { + return static_cast(type); + } + + Symbol() = default; + ~Symbol() override = default; Symbol& operator=(Symbol other); Symbol(const Symbol& other); void swap(Symbol& other); - //! The symbol's type provides a general classification for the associated entity - ELF_SYMBOL_TYPES type() const; + /// The symbol's type provides a general classification for the associated entity + TYPE type() const { + return type_; + } - //! The symbol's binding determines the linkage visibility and behavior - SYMBOL_BINDINGS binding() const; + /// The symbol's binding determines the linkage visibility and behavior + BINDING binding() const { + return binding_; + } - //! This member specifies the symbol's type and binding attributes. + /// This member specifies the symbol's type and binding attributes. uint8_t information() const; - //! Alias for visibility() - uint8_t other() const; + /// Alias for visibility() + uint8_t other() const { + return other_; + } - //! ELF::Section index associated with the symbol - uint16_t section_idx() const; + /// ELF::Section index associated with the symbol + uint16_t section_idx() const { + return shndx(); + } - //! Symbol visibility - ELF_SYMBOL_VISIBILITY visibility() const; + /// Symbol visibility + VISIBILITY visibility() const { + return VISIBILITY(other_); + } - //! Section associated with the symbol or a nullptr if - //! it does not exist. - Section* section(); + /// Section associated with the symbol or a nullptr if + /// it does not exist. + Section* section() { + return section_; + } - //! This member has slightly different interpretations: - //! * In relocatable files, `value` holds alignment constraints for a symbol for which section index - //! is SHN_COMMON - //! * In relocatable files, `value` holds a section offset for a defined symbol. That is, `value` is an - //! offset from the beginning of the section associated with this symbol. - //! * In executable and shared object files, `value` holds a virtual address. To make these files's - //! symbols more useful for the dynamic linker, the section offset (file interpretation) gives way to - //! a virtual address (memory interpretation) for which the section number is irrelevant. + /// This member has slightly different interpretations: + /// * In relocatable files, `value` holds alignment constraints for a symbol for which section index + /// is SHN_COMMON + /// * In relocatable files, `value` holds a section offset for a defined symbol. That is, `value` is an + /// offset from the beginning of the section associated with this symbol. + /// * In executable and shared object files, `value` holds a virtual address. To make these files's + /// symbols more useful for the dynamic linker, the section offset (file interpretation) gives way to + /// a virtual address (memory interpretation) for which the section number is irrelevant. uint64_t value() const override { return value_; } - //! Symbol size - //! - //! Many symbols have associated sizes. For example, a data object's size is the number of - //! bytes contained in the object. This member holds `0` if the symbol has no size or - //! an unknown size. + /// Symbol size + /// + /// Many symbols have associated sizes. For example, a data object's size is the number of + /// bytes contained in the object. This member holds `0` if the symbol has no size or + /// an unknown size. uint64_t size() const override { return size_; } - //! @see Symbol::section_idx - uint16_t shndx() const; + /// @see Symbol::section_idx + uint16_t shndx() const { + return shndx_; + } + + /// Check if this symbols has a @link ELF::SymbolVersion symbol version @endlink + bool has_version() const { + return symbol_version_ != nullptr; + } + + /// Return the SymbolVersion associated with this symbol. + /// If there is no symbol version, return a nullptr + SymbolVersion* symbol_version() { + return symbol_version_; + } + + const SymbolVersion* symbol_version() const { + return symbol_version_; + } - //! Check if this symbols has a @link ELF::SymbolVersion symbol version @endlink - bool has_version() const; + bool is_local() const { + return binding() == BINDING::LOCAL; + } - //! Return the SymbolVersion associated with this symbol. - //! If there is no symbol version, return a nullptr - SymbolVersion* symbol_version(); - const SymbolVersion* symbol_version() const; + bool is_global() const { + return binding() == BINDING::GLOBAL; + } - //! Symbol's unmangled name. If not available, it returns an empty string + bool is_weak() const { + return binding() == BINDING::WEAK; + } + + /// Symbol's unmangled name. If not available, it returns an empty string std::string demangled_name() const; - void type(ELF_SYMBOL_TYPES type); - void binding(SYMBOL_BINDINGS binding); - void other(uint8_t other); - void visibility(ELF_SYMBOL_VISIBILITY visibility); + void type(TYPE type) { + type_ = type; + } + + void binding(BINDING binding) { + binding_ = binding; + } + + void other(uint8_t other) { + other_ = other; + } + + void visibility(VISIBILITY visibility) { + other_ = static_cast(visibility); + } + void information(uint8_t info); - void shndx(uint16_t idx); + + void shndx(uint16_t idx) { + shndx_ = idx; + } void value(uint64_t value) override { value_ = value; @@ -130,51 +221,53 @@ class LIEF_API Symbol : public LIEF::Symbol { size_ = size; } - void shndx(SYMBOL_SECTION_INDEX idx) { - this->shndx_ = static_cast(idx); - } - - //! Check if the current symbol is exported + /// Check if the current symbol is exported bool is_exported() const; - //! Set whether or not the symbol is exported + /// Set whether or not the symbol is exported void set_exported(bool flag = true); - //! Check if the current symbol is imported + /// Check if the current symbol is imported bool is_imported() const; - //! Set whether or not the symbol is imported + /// Set whether or not the symbol is imported void set_imported(bool flag = true); - //! True if the symbol is a static one + /// True if the symbol is a static one bool is_static() const { - return this->binding() == SYMBOL_BINDINGS::STB_GLOBAL; + return this->binding() == BINDING::GLOBAL; } - //! True if the symbol represent a function + /// True if the symbol represent a function bool is_function() const { - return this->type() == ELF_SYMBOL_TYPES::STT_FUNC; + return this->type() == TYPE::FUNC; } - //! True if the symbol represent a variable + /// True if the symbol represent a variable bool is_variable() const { - return this->type() == ELF_SYMBOL_TYPES::STT_OBJECT; + return this->type() == TYPE::OBJECT; } void accept(Visitor& visitor) const override; - LIEF_API friend std::ostream& operator<<(std::ostream& os, const Symbol& entry); private: - ELF_SYMBOL_TYPES type_ = ELF_SYMBOL_TYPES::STT_NOTYPE; - SYMBOL_BINDINGS binding_ = SYMBOL_BINDINGS::STB_LOCAL; - uint8_t other_ = 0; - uint16_t shndx_ = 0; - Section* section_ = nullptr; - SymbolVersion* symbol_version_ = nullptr; - ARCH arch_ = ARCH::EM_NONE; + template + LIEF_API Symbol(const T& header, ARCH arch); + + TYPE type_ = TYPE::NOTYPE; + BINDING binding_ = BINDING::LOCAL; + uint8_t other_ = 0; + uint16_t shndx_ = 0; + Section* section_ = nullptr; + SymbolVersion* symbol_version_ = nullptr; + ARCH arch_ = ARCH::NONE; }; + +LIEF_API const char* to_string(Symbol::BINDING binding); +LIEF_API const char* to_string(Symbol::TYPE type); +LIEF_API const char* to_string(Symbol::VISIBILITY viz); } } #endif /* _ELF_SYMBOL_H */ diff --git a/include/LIEF/ELF/SymbolVersion.hpp b/include/LIEF/ELF/SymbolVersion.hpp index 30133ffdb9..5e0d45aa89 100644 --- a/include/LIEF/ELF/SymbolVersion.hpp +++ b/include/LIEF/ELF/SymbolVersion.hpp @@ -33,19 +33,25 @@ class LIEF_API SymbolVersion : public Object { friend class Parser; public: - SymbolVersion(uint16_t value); - SymbolVersion(); + SymbolVersion(uint16_t value) : + value_(value) + {} + SymbolVersion() = default; //! Generate a *local* SymbolVersion - static SymbolVersion local(); + static SymbolVersion local() { + return SymbolVersion(0); + } //! Generate a *global* SymbolVersion - static SymbolVersion global(); + static SymbolVersion global() { + return SymbolVersion(1); + } - ~SymbolVersion() override; + ~SymbolVersion() override = default; - SymbolVersion& operator=(const SymbolVersion&); - SymbolVersion(const SymbolVersion&); + SymbolVersion& operator=(const SymbolVersion&) = default; + SymbolVersion(const SymbolVersion&) = default; //! Value associated with the symbol //! @@ -53,15 +59,24 @@ class LIEF_API SymbolVersion : public Object { //! //! * ``0`` means **Local** //! * ``1`` means **Global** - uint16_t value() const; + uint16_t value() const { + return value_; + } //! Whether the current SymbolVersion has an auxiliary one - bool has_auxiliary_version() const; + bool has_auxiliary_version() const { + return symbol_version_auxiliary() != nullptr; + } //! SymbolVersionAux associated with the current Version if any, //! or a nullptr - SymbolVersionAux* symbol_version_auxiliary(); - const SymbolVersionAux* symbol_version_auxiliary() const; + SymbolVersionAux* symbol_version_auxiliary() { + return symbol_aux_; + } + + const SymbolVersionAux* symbol_version_auxiliary() const { + return symbol_aux_; + } //! Set the version's auxiliary requirement //! The given SymbolVersionAuxRequirement must be an existing @@ -71,11 +86,12 @@ class LIEF_API SymbolVersion : public Object { //! SymbolVersionRequirement::add_aux_requirement void symbol_version_auxiliary(SymbolVersionAuxRequirement& svauxr); - void value(uint16_t v); + void value(uint16_t v) { + value_ = v; + } void accept(Visitor& visitor) const override; - LIEF_API friend std::ostream& operator<<(std::ostream& os, const SymbolVersion& symv); private: diff --git a/include/LIEF/ELF/SymbolVersionAux.hpp b/include/LIEF/ELF/SymbolVersionAux.hpp index 3191702011..d453846789 100644 --- a/include/LIEF/ELF/SymbolVersionAux.hpp +++ b/include/LIEF/ELF/SymbolVersionAux.hpp @@ -30,22 +30,31 @@ class Parser; class LIEF_API SymbolVersionAux : public Object { friend class Parser; public: - SymbolVersionAux(std::string name); - SymbolVersionAux(); - ~SymbolVersionAux() override; + SymbolVersionAux(std::string name) : + name_(std::move(name)) + {} + SymbolVersionAux() = default; + ~SymbolVersionAux() override = default; - SymbolVersionAux& operator=(const SymbolVersionAux&); - SymbolVersionAux(const SymbolVersionAux&); + SymbolVersionAux& operator=(const SymbolVersionAux&) = default; + SymbolVersionAux(const SymbolVersionAux&) = default; //! Smybol's aux name (e.g. ``GLIBC_2.2.5``) - const std::string& name() const; + const std::string& name() const { + return name_; + } - void name(const std::string& name); + void name(std::string name) { + name_ = std::move(name); + } void accept(Visitor& visitor) const override; - - LIEF_API friend std::ostream& operator<<(std::ostream& os, const SymbolVersionAux& symAux); + LIEF_API friend + std::ostream& operator<<(std::ostream& os, const SymbolVersionAux& aux) { + os << aux.name(); + return os; + } protected: std::string name_; diff --git a/include/LIEF/ELF/SymbolVersionAuxRequirement.hpp b/include/LIEF/ELF/SymbolVersionAuxRequirement.hpp index 097fb2eeb2..bf659705e0 100644 --- a/include/LIEF/ELF/SymbolVersionAuxRequirement.hpp +++ b/include/LIEF/ELF/SymbolVersionAuxRequirement.hpp @@ -38,33 +38,50 @@ class LIEF_API SymbolVersionAuxRequirement : public SymbolVersionAux { SymbolVersionAuxRequirement(const details::Elf64_Vernaux& header); SymbolVersionAuxRequirement(const details::Elf32_Vernaux& header); - SymbolVersionAuxRequirement(); + SymbolVersionAuxRequirement() = default; - SymbolVersionAuxRequirement& operator=(const SymbolVersionAuxRequirement&); - SymbolVersionAuxRequirement(const SymbolVersionAuxRequirement&); + SymbolVersionAuxRequirement& operator=(const SymbolVersionAuxRequirement&) = default; + SymbolVersionAuxRequirement(const SymbolVersionAuxRequirement&) = default; - ~SymbolVersionAuxRequirement() override; + ~SymbolVersionAuxRequirement() override = default; //! Hash value of the dependency name (use ELF hashing function) - uint32_t hash() const; + uint32_t hash() const { + return hash_; + } //! Bitmask of flags - uint16_t flags() const; + uint16_t flags() const { + return flags_; + } //! It returns the unique version index for the file which is used in the //! version symbol table. If the highest bit (bit 15) is set this //! is a hidden symbol which cannot be referenced from outside the //! object. - uint16_t other() const; + uint16_t other() const { + return other_; + } - void hash(uint32_t hash); - void flags(uint16_t flags); - void other(uint16_t other); + void hash(uint32_t hash) { + hash_ = hash; + } - void accept(Visitor& visitor) const override; + void flags(uint16_t flags) { + flags_ = flags; + } + + void other(uint16_t other) { + other_ = other; + } + void accept(Visitor& visitor) const override; - LIEF_API friend std::ostream& operator<<(std::ostream& os, const SymbolVersionAuxRequirement& symAux); + LIEF_API friend + std::ostream& operator<<(std::ostream& os, const SymbolVersionAuxRequirement& aux) { + os << aux.name(); + return os; + } private: uint32_t hash_ = 0; diff --git a/include/LIEF/ELF/SymbolVersionDefinition.hpp b/include/LIEF/ELF/SymbolVersionDefinition.hpp index 1a6974e35f..7f8750ec4c 100644 --- a/include/LIEF/ELF/SymbolVersionDefinition.hpp +++ b/include/LIEF/ELF/SymbolVersionDefinition.hpp @@ -43,7 +43,7 @@ class LIEF_API SymbolVersionDefinition : public Object { using it_version_aux = ref_iterator; using it_const_version_aux = const_ref_iterator; - SymbolVersionDefinition(); + SymbolVersionDefinition() = default; SymbolVersionDefinition(const details::Elf64_Verdef& header); SymbolVersionDefinition(const details::Elf32_Verdef& header); ~SymbolVersionDefinition() override; @@ -56,29 +56,49 @@ class LIEF_API SymbolVersionDefinition : public Object { //! //! This field should always have the value ``1``. It will be changed //! if the versioning implementation has to be changed in an incompatible way. - uint16_t version() const; + uint16_t version() const { + return version_; + } //! Version information - uint16_t flags() const; + uint16_t flags() const { + return flags_; + } //! Version index //! //! Numeric value used as an index in the LIEF::ELF::SymbolVersion table - uint16_t ndx() const; + uint16_t ndx() const { + return ndx_; + } //! Hash value of the symbol's name (using ELF hash function) - uint32_t hash() const; + uint32_t hash() const { + return hash_; + } //! SymbolVersionAux entries - it_version_aux symbols_aux(); - it_const_version_aux symbols_aux() const; + it_version_aux symbols_aux() { + return symbol_version_aux_; + } - void version(uint16_t version); - void flags(uint16_t flags); - void hash(uint32_t hash); + it_const_version_aux symbols_aux() const { + return symbol_version_aux_; + } - void accept(Visitor& visitor) const override; + void version(uint16_t version) { + version_ = version; + } + + void flags(uint16_t flags) { + flags_ = flags; + } + void hash(uint32_t hash) { + hash_ = hash; + } + + void accept(Visitor& visitor) const override; LIEF_API friend std::ostream& operator<<(std::ostream& os, const SymbolVersionDefinition& sym); diff --git a/include/LIEF/ELF/SymbolVersionRequirement.hpp b/include/LIEF/ELF/SymbolVersionRequirement.hpp index 50c614fd47..71f5d7eed9 100644 --- a/include/LIEF/ELF/SymbolVersionRequirement.hpp +++ b/include/LIEF/ELF/SymbolVersionRequirement.hpp @@ -44,10 +44,10 @@ class LIEF_API SymbolVersionRequirement : public Object { using it_aux_requirement = ref_iterator; using it_const_aux_requirement = const_ref_iterator; - SymbolVersionRequirement(); + SymbolVersionRequirement() = default; SymbolVersionRequirement(const details::Elf64_Verneed& header); SymbolVersionRequirement(const details::Elf32_Verneed& header); - ~SymbolVersionRequirement() override; + ~SymbolVersionRequirement() override = default; SymbolVersionRequirement& operator=(SymbolVersionRequirement other); SymbolVersionRequirement(const SymbolVersionRequirement& other); @@ -57,28 +57,47 @@ class LIEF_API SymbolVersionRequirement : public Object { //! //! This field should always have the value ``1``. It will be changed //! if the versioning implementation has to be changed in an incompatible way. - uint16_t version() const; + uint16_t version() const { + return version_; + } - //! Number of associated auxiliary entries - uint32_t cnt() const; + //! Number of auxiliary entries + size_t cnt() const { + return aux_requirements_.size(); + } //! Auxiliary entries as an iterator over SymbolVersionAuxRequirement - it_aux_requirement auxiliary_symbols(); - it_const_aux_requirement auxiliary_symbols() const; + it_aux_requirement auxiliary_symbols() { + return aux_requirements_; + } + + it_const_aux_requirement auxiliary_symbols() const { + return aux_requirements_; + } //! Return the library name associated with this requirement (e.g. ``libc.so.6``) - const std::string& name() const; + const std::string& name() const { + return name_; + } + + void version(uint16_t version) { + version_ = version; + } - void version(uint16_t version); - void name(const std::string& name); + void name(const std::string& name) { + name_ = name; + } //! Add a version auxiliary requirement to the existing list SymbolVersionAuxRequirement& add_aux_requirement(const SymbolVersionAuxRequirement& aux_requirement); void accept(Visitor& visitor) const override; - - LIEF_API friend std::ostream& operator<<(std::ostream& os, const SymbolVersionRequirement& symr); + LIEF_API friend + std::ostream& operator<<(std::ostream& os, const SymbolVersionRequirement& symr) { + os << symr.version() << " " << symr.name(); + return os; + } private: aux_requirement_t aux_requirements_; diff --git a/include/LIEF/ELF/SysvHash.hpp b/include/LIEF/ELF/SysvHash.hpp index 78b6ea5605..d53d411ee9 100644 --- a/include/LIEF/ELF/SysvHash.hpp +++ b/include/LIEF/ELF/SysvHash.hpp @@ -43,25 +43,33 @@ class LIEF_API SysvHash : public Object { friend class Binary; public: - SysvHash(); - SysvHash& operator=(const SysvHash& copy); - SysvHash(const SysvHash& copy); + SysvHash() = default; + SysvHash& operator=(const SysvHash& copy) = default; + SysvHash(const SysvHash& copy) = default; - SysvHash& operator=(SysvHash&&); - SysvHash(SysvHash&&); - ~SysvHash() override; + SysvHash& operator=(SysvHash&&) = default; + SysvHash(SysvHash&&) = default; + ~SysvHash() override = default; //! @brief Return the number of buckets used - uint32_t nbucket() const; + uint32_t nbucket() const { + return buckets_.size(); + } //! @brief Return the number of chain used - uint32_t nchain() const; + uint32_t nchain() const { + return chains_.size(); + } //! @brief Buckets values - const std::vector& buckets() const; + const std::vector& buckets() const { + return buckets_; + } //! @brief Chains values - const std::vector& chains() const; + const std::vector& chains() const { + return chains_; + } void nchain(uint32_t nb) { chains_.resize(nb); @@ -74,10 +82,8 @@ class LIEF_API SysvHash : public Object { private: std::vector buckets_; std::vector chains_; - }; - } // namepsace ELF } // namespace LIEF diff --git a/include/LIEF/ELF/enums.hpp b/include/LIEF/ELF/enums.hpp index a291b7ddb8..6ffe61b7fb 100644 --- a/include/LIEF/ELF/enums.hpp +++ b/include/LIEF/ELF/enums.hpp @@ -16,901 +16,199 @@ #ifndef LIEF_ELF_ENUMS_H #define LIEF_ELF_ENUMS_H #include "LIEF/enums.hpp" -#include "LIEF/ELF/undef.h" #include #include namespace LIEF { namespace ELF { - -/** e_ident size and indices. */ -enum class IDENTITY: size_t { - EI_MAG0 = 0, /**< File identification index. */ - EI_MAG1 = 1, /**< File identification index. */ - EI_MAG2 = 2, /**< File identification index. */ - EI_MAG3 = 3, /**< File identification index. */ - EI_CLASS = 4, /**< File class. */ - EI_DATA = 5, /**< Data encoding. */ - EI_VERSION = 6, /**< File version. */ - EI_OSABI = 7, /**< OS/ABI identification. */ - EI_ABIVERSION = 8, /**< ABI version. */ - EI_PAD = 9, /**< Start of padding bytes. */ - EI_NIDENT = 16 /**< Number of bytes in e_ident. */ -}; - - -/** Enum associated with *e_type* */ -enum class E_TYPE: size_t { - ET_NONE = 0, /**< No file type */ - ET_REL = 1, /**< Relocatable file */ - ET_EXEC = 2, /**< Executable file */ - ET_DYN = 3, /**< Shared object file */ - ET_CORE = 4, /**< Core file */ - ET_LOPROC = 0xff00, /**< Beginning of processor-specific codes */ - ET_HIPROC = 0xffff /**< Processor-specific */ -}; - - -/** Versioning */ -enum class VERSION: size_t { - EV_NONE = 0, - EV_CURRENT = 1 /**< Default value */ -}; - - /** * @brief Machine architectures * See current registered ELF machine architectures at: * http://www.sco.com/developers/gabi/latest/ch4.eheader.html */ -enum class ARCH: size_t { - EM_NONE = 0, /**< No machine */ - EM_M32 = 1, /**< AT&T WE 32100 */ - EM_SPARC = 2, /**< SPARC */ - EM_386 = 3, /**< Intel 386 */ - EM_68K = 4, /**< Motorola 68000 */ - EM_88K = 5, /**< Motorola 88000 */ - EM_IAMCU = 6, /**< Intel MCU */ - EM_860 = 7, /**< Intel 80860 */ - EM_MIPS = 8, /**< MIPS R3000 */ - EM_S370 = 9, /**< IBM System/370 */ - EM_MIPS_RS3_LE = 10, /**< MIPS RS3000 Little-endian */ - EM_PARISC = 15, /**< Hewlett-Packard PA-RISC */ - EM_VPP500 = 17, /**< Fujitsu VPP500 */ - EM_SPARC32PLUS = 18, /**< Enhanced instruction set SPARC */ - EM_960 = 19, /**< Intel 80960 */ - EM_PPC = 20, /**< PowerPC */ - EM_PPC64 = 21, /**< PowerPC64 */ - EM_S390 = 22, /**< IBM System/390 */ - EM_SPU = 23, /**< IBM SPU/SPC */ - EM_V800 = 36, /**< NEC V800 */ - EM_FR20 = 37, /**< Fujitsu FR20 */ - EM_RH32 = 38, /**< TRW RH-32 */ - EM_RCE = 39, /**< Motorola RCE */ - EM_ARM = 40, /**< ARM */ - EM_ALPHA = 41, /**< DEC Alpha */ - EM_SH = 42, /**< Hitachi SH */ - EM_SPARCV9 = 43, /**< SPARC V9 */ - EM_TRICORE = 44, /**< Siemens TriCore */ - EM_ARC = 45, /**< Argonaut RISC Core */ - EM_H8_300 = 46, /**< Hitachi H8/300 */ - EM_H8_300H = 47, /**< Hitachi H8/300H */ - EM_H8S = 48, /**< Hitachi H8S */ - EM_H8_500 = 49, /**< Hitachi H8/500 */ - EM_IA_64 = 50, /**< Intel IA-64 processor architecture */ - EM_MIPS_X = 51, /**< Stanford MIPS-X */ - EM_COLDFIRE = 52, /**< Motorola ColdFire */ - EM_68HC12 = 53, /**< Motorola M68HC12 */ - EM_MMA = 54, /**< Fujitsu MMA Multimedia Accelerator */ - EM_PCP = 55, /**< Siemens PCP */ - EM_NCPU = 56, /**< Sony nCPU embedded RISC processor */ - EM_NDR1 = 57, /**< Denso NDR1 microprocessor */ - EM_STARCORE = 58, /**< Motorola Star*Core processor */ - EM_ME16 = 59, /**< Toyota ME16 processor */ - EM_ST100 = 60, /**< STMicroelectronics ST100 processor */ - EM_TINYJ = 61, /**< Advanced Logic Corp. TinyJ embedded processor family */ - EM_X86_64 = 62, /**< AMD x86-64 architecture */ - EM_PDSP = 63, /**< Sony DSP Processor */ - EM_PDP10 = 64, /**< Digital Equipment Corp. PDP-10 */ - EM_PDP11 = 65, /**< Digital Equipment Corp. PDP-11 */ - EM_FX66 = 66, /**< Siemens FX66 microcontroller */ - EM_ST9PLUS = 67, /**< STMicroelectronics ST9+ 8/16 bit microcontroller */ - EM_ST7 = 68, /**< STMicroelectronics ST7 8-bit microcontroller */ - EM_68HC16 = 69, /**< Motorola MC68HC16 Microcontroller */ - EM_68HC11 = 70, /**< Motorola MC68HC11 Microcontroller */ - EM_68HC08 = 71, /**< Motorola MC68HC08 Microcontroller */ - EM_68HC05 = 72, /**< Motorola MC68HC05 Microcontroller */ - EM_SVX = 73, /**< Silicon Graphics SVx */ - EM_ST19 = 74, /**< STMicroelectronics ST19 8-bit microcontroller */ - EM_VAX = 75, /**< Digital VAX */ - EM_CRIS = 76, /**< Axis Communications 32-bit embedded processor */ - EM_JAVELIN = 77, /**< Infineon Technologies 32-bit embedded processor */ - EM_FIREPATH = 78, /**< Element 14 64-bit DSP Processor */ - EM_ZSP = 79, /**< LSI Logic 16-bit DSP Processor */ - EM_MMIX = 80, /**< Donald Knuth's educational 64-bit processor */ - EM_HUANY = 81, /**< Harvard University machine-independent object files */ - EM_PRISM = 82, /**< SiTera Prism */ - EM_AVR = 83, /**< Atmel AVR 8-bit microcontroller */ - EM_FR30 = 84, /**< Fujitsu FR30 */ - EM_D10V = 85, /**< Mitsubishi D10V */ - EM_D30V = 86, /**< Mitsubishi D30V */ - EM_V850 = 87, /**< NEC v850 */ - EM_M32R = 88, /**< Mitsubishi M32R */ - EM_MN10300 = 89, /**< Matsushita MN10300 */ - EM_MN10200 = 90, /**< Matsushita MN10200 */ - EM_PJ = 91, /**< picoJava */ - EM_OPENRISC = 92, /**< OpenRISC 32-bit embedded processor */ - EM_ARC_COMPACT = 93, /**< ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5) */ - EM_XTENSA = 94, /**< Tensilica Xtensa Architecture */ - EM_VIDEOCORE = 95, /**< Alphamosaic VideoCore processor */ - EM_TMM_GPP = 96, /**< Thompson Multimedia General Purpose Processor */ - EM_NS32K = 97, /**< National Semiconductor 32000 series */ - EM_TPC = 98, /**< Tenor Network TPC processor */ - EM_SNP1K = 99, /**< Trebia SNP 1000 processor */ - EM_ST200 = 100, /**< STMicroelectronics (www.st.com) ST200 */ - EM_IP2K = 101, /**< Ubicom IP2xxx microcontroller family */ - EM_MAX = 102, /**< MAX Processor */ - EM_CR = 103, /**< National Semiconductor CompactRISC microprocessor */ - EM_F2MC16 = 104, /**< Fujitsu F2MC16 */ - EM_MSP430 = 105, /**< Texas Instruments embedded microcontroller msp430 */ - EM_BLACKFIN = 106, /**< Analog Devices Blackfin (DSP) processor */ - EM_SE_C33 = 107, /**< S1C33 Family of Seiko Epson processors */ - EM_SEP = 108, /**< Sharp embedded microprocessor */ - EM_ARCA = 109, /**< Arca RISC Microprocessor */ - EM_UNICORE = 110, /**< Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ - EM_EXCESS = 111, /**< eXcess: 16/32/64-bit configurable embedded CPU */ - EM_DXP = 112, /**< Icera Semiconductor Inc. Deep Execution Processor */ - EM_ALTERA_NIOS2 = 113, /**< Altera Nios II soft-core processor */ - EM_CRX = 114, /**< National Semiconductor CompactRISC CRX */ - EM_XGATE = 115, /**< Motorola XGATE embedded processor */ - EM_C166 = 116, /**< Infineon C16x/XC16x processor */ - EM_M16C = 117, /**< Renesas M16C series microprocessors */ - EM_DSPIC30F = 118, /**< Microchip Technology dsPIC30F Digital Signal */ - /* Controller */ - EM_CE = 119, /**< Freescale Communication Engine RISC core */ - EM_M32C = 120, /**< Renesas M32C series microprocessors */ - EM_TSK3000 = 131, /**< Altium TSK3000 core */ - EM_RS08 = 132, /**< Freescale RS08 embedded processor */ - EM_SHARC = 133, /**< Analog Devices SHARC family of 32-bit DSP */ - /* processors */ - EM_ECOG2 = 134, /**< Cyan Technology eCOG2 microprocessor */ - EM_SCORE7 = 135, /**< Sunplus S+core7 RISC processor */ - EM_DSP24 = 136, /**< New Japan Radio (NJR) 24-bit DSP Processor */ - EM_VIDEOCORE3 = 137, /**< Broadcom VideoCore III processor */ - EM_LATTICEMICO32 = 138, /**< RISC processor for Lattice FPGA architecture */ - EM_SE_C17 = 139, /**< Seiko Epson C17 family */ - EM_TI_C6000 = 140, /**< The Texas Instruments TMS320C6000 DSP family */ - EM_TI_C2000 = 141, /**< The Texas Instruments TMS320C2000 DSP family */ - EM_TI_C5500 = 142, /**< The Texas Instruments TMS320C55x DSP family */ - EM_MMDSP_PLUS = 160, /**< STMicroelectronics 64bit VLIW Data Signal Processor */ - EM_CYPRESS_M8C = 161, /**< Cypress M8C microprocessor */ - EM_R32C = 162, /**< Renesas R32C series microprocessors */ - EM_TRIMEDIA = 163, /**< NXP Semiconductors TriMedia architecture family */ - EM_HEXAGON = 164, /**< Qualcomm Hexagon processor */ - EM_8051 = 165, /**< Intel 8051 and variants */ - EM_STXP7X = 166, /**< STMicroelectronics STxP7x family of configurable */ - /* and extensible RISC processors */ - EM_NDS32 = 167, /* Andes Technology compact code size embedded RISC */ - /* processor family */ - EM_ECOG1 = 168, /**< Cyan Technology eCOG1X family */ - EM_ECOG1X = 168, /**< Cyan Technology eCOG1X family */ - EM_MAXQ30 = 169, /**< Dallas Semiconductor MAXQ30 Core Micro-controllers */ - EM_XIMO16 = 170, /**< New Japan Radio (NJR) 16-bit DSP Processor */ - EM_MANIK = 171, /**< M2000 Reconfigurable RISC Microprocessor */ - EM_CRAYNV2 = 172, /**< Cray Inc. NV2 vector architecture */ - EM_RX = 173, /**< Renesas RX family */ - EM_METAG = 174, /**< Imagination Technologies META processor */ - /* architecture */ - EM_MCST_ELBRUS = 175, /**< MCST Elbrus general purpose hardware architecture */ - EM_ECOG16 = 176, /**< Cyan Technology eCOG16 family */ - EM_CR16 = 177, /**< National Semiconductor CompactRISC CR16 16-bit */ - /* microprocessor */ - EM_ETPU = 178, /**< Freescale Extended Time Processing Unit */ - EM_SLE9X = 179, /**< Infineon Technologies SLE9X core */ - EM_L10M = 180, /**< Intel L10M */ - EM_K10M = 181, /**< Intel K10M */ - EM_AARCH64 = 183, /**< ARM AArch64 */ - EM_AVR32 = 185, /**< Atmel Corporation 32-bit microprocessor family */ - EM_STM8 = 186, /**< STMicroeletronics STM8 8-bit microcontroller */ - EM_TILE64 = 187, /**< Tilera TILE64 multicore architecture family */ - EM_TILEPRO = 188, /**< Tilera TILEPro multicore architecture family */ - EM_CUDA = 190, /**< NVIDIA CUDA architecture */ - EM_TILEGX = 191, /**< Tilera TILE-Gx multicore architecture family */ - EM_CLOUDSHIELD = 192, /**< CloudShield architecture family */ - EM_COREA_1ST = 193, /**< KIPO-KAIST Core-A 1st generation processor family */ - EM_COREA_2ND = 194, /**< KIPO-KAIST Core-A 2nd generation processor family */ - EM_ARC_COMPACT2 = 195, /**< Synopsys ARCompact V2 */ - EM_OPEN8 = 196, /**< Open8 8-bit RISC soft processor core */ - EM_RL78 = 197, /**< Renesas RL78 family */ - EM_VIDEOCORE5 = 198, /**< Broadcom VideoCore V processor */ - EM_78KOR = 199, /**< Renesas 78KOR family */ - EM_56800EX = 200, /**< Freescale 56800EX Digital Signal Controller (DSC) */ - EM_BA1 = 201, /**< Beyond BA1 CPU architecture */ - EM_BA2 = 202, /**< Beyond BA2 CPU architecture */ - EM_XCORE = 203, /**< XMOS xCORE processor family */ - EM_MCHP_PIC = 204, /**< Microchip 8-bit PIC(r) family */ - EM_INTEL205 = 205, /**< Reserved by Intel */ - EM_INTEL206 = 206, /**< Reserved by Intel */ - EM_INTEL207 = 207, /**< Reserved by Intel */ - EM_INTEL208 = 208, /**< Reserved by Intel */ - EM_INTEL209 = 209, /**< Reserved by Intel */ - EM_KM32 = 210, /**< KM211 KM32 32-bit processor */ - EM_KMX32 = 211, /**< KM211 KMX32 32-bit processor */ - EM_KMX16 = 212, /**< KM211 KMX16 16-bit processor */ - EM_KMX8 = 213, /**< KM211 KMX8 8-bit processor */ - EM_KVARC = 214, /**< KM211 KVARC processor */ - EM_CDP = 215, /**< Paneve CDP architecture family */ - EM_COGE = 216, /**< Cognitive Smart Memory Processor */ - EM_COOL = 217, /**< iCelero CoolEngine */ - EM_NORC = 218, /**< Nanoradio Optimized RISC */ - EM_CSR_KALIMBA = 219, /**< CSR Kalimba architecture family */ - EM_AMDGPU = 224, /**< AMD GPU architecture */ - EM_RISCV = 243, /**< RISC-V */ - EM_BPF = 247, /**< eBPF Filter */ - EM_LOONGARCH = 258 /**< LoongArch */ -}; - - -/** Object file classes. */ -enum class ELF_CLASS: size_t { - ELFCLASSNONE = 0, /**< Unknown */ - ELFCLASS32 = 1, /**< 32-bit object file */ - ELFCLASS64 = 2 /**< 64-bit object file */ -}; - -/** Object file byte orderings. */ -enum class ELF_DATA: size_t { - ELFDATANONE = 0, /**< Invalid data encoding. */ - ELFDATA2LSB = 1, /**< Little-endian object file */ - ELFDATA2MSB = 2 /**< Big-endian object file */ -}; - -/** OS ABI identification. */ -enum class OS_ABI: size_t { - ELFOSABI_SYSTEMV = 0, /**< UNIX System V ABI */ - ELFOSABI_HPUX = 1, /**< HP-UX operating system */ - ELFOSABI_NETBSD = 2, /**< NetBSD */ - ELFOSABI_GNU = 3, /**< GNU/Linux */ - ELFOSABI_LINUX = 3, /**< Historical alias for ELFOSABI_GNU. */ - ELFOSABI_HURD = 4, /**< GNU/Hurd */ - ELFOSABI_SOLARIS = 6, /**< Solaris */ - ELFOSABI_AIX = 7, /**< AIX */ - ELFOSABI_IRIX = 8, /**< IRIX */ - ELFOSABI_FREEBSD = 9, /**< FreeBSD */ - ELFOSABI_TRU64 = 10, /**< TRU64 UNIX */ - ELFOSABI_MODESTO = 11, /**< Novell Modesto */ - ELFOSABI_OPENBSD = 12, /**< OpenBSD */ - ELFOSABI_OPENVMS = 13, /**< OpenVMS */ - ELFOSABI_NSK = 14, /**< Hewlett-Packard Non-Stop Kernel */ - ELFOSABI_AROS = 15, /**< AROS */ - ELFOSABI_FENIXOS = 16, /**< FenixOS */ - ELFOSABI_CLOUDABI = 17, /**< Nuxi CloudABI */ - ELFOSABI_C6000_ELFABI = 64, /**< Bare-metal TMS320C6000 */ - ELFOSABI_AMDGPU_HSA = 64, /**< AMD HSA runtime */ - ELFOSABI_C6000_LINUX = 65, /**< Linux TMS320C6000 */ - ELFOSABI_ARM = 97, /**< ARM */ - ELFOSABI_STANDALONE = 255 /**< Standalone (embedded) application */ -}; - -/* ELF Relocations */ - -#define ELF_RELOC(name, value) name = value, - -/** x86_64 relocations. */ -enum class RELOC_x86_64: size_t { - #include "LIEF/ELF/Relocations/x86_64.def" -}; - -/** i386 relocations. */ -enum RELOC_i386 { - #include "LIEF/ELF/Relocations/i386.def" -}; - -/* ELF Relocation types for PPC32 */ -enum class RELOC_POWERPC32: size_t { - #include "LIEF/ELF/Relocations/PowerPC.def" -}; - -/* ELF Relocation types for PPC64 */ -enum class RELOC_POWERPC64: size_t { - #include "LIEF/ELF/Relocations/PowerPC64.def" -}; - -/* ELF Relocation types for AArch64 */ -enum class RELOC_AARCH64: size_t { - #include "LIEF/ELF/Relocations/AArch64.def" -}; - -/* ELF Relocation types for ARM */ -enum class RELOC_ARM: size_t { - #include "LIEF/ELF/Relocations/ARM.def" -}; - -/* ELF Relocation types for Mips */ -enum class RELOC_MIPS: size_t { - #include "LIEF/ELF/Relocations/Mips.def" -}; - -/* ELF Relocation types for Hexagon */ -enum class RELOC_HEXAGON: size_t { - #include "LIEF/ELF/Relocations/Hexagon.def" -}; - -/* ELF Relocation types for S390/zSeries */ -enum class RELOC_SYSTEMZ: size_t { - #include "LIEF/ELF/Relocations/SystemZ.def" -}; - -/* ELF Relocation type for Sparc. */ -enum class RELOC_SPARC: size_t { - #include "LIEF/ELF/Relocations/Sparc.def" -}; - -/* ELF Relocation types for LoongArch. */ -enum class RELOC_LOONGARCH: size_t { - #include "LIEF/ELF/Relocations/LoongArch.def" -}; - -#undef ELF_RELOC - -/* Specific e_flags for PPC64 */ -enum class PPC64_EFLAGS: size_t { - /* e_flags bits specifying ABI: */ - /* 1 for original ABI using function descriptors, */ - /* 2 for revised ABI without function descriptors, */ - /* 0 for unspecified or not using any features affected by the differences. */ - EF_PPC64_ABI = 3 -}; - -/* ARM Specific e_flags */ -enum class ARM_EFLAGS: size_t { - EF_ARM_SOFT_FLOAT = 0x00000200U, - EF_ARM_VFP_FLOAT = 0x00000400U, - EF_ARM_EABI_UNKNOWN = 0x00000000U, - EF_ARM_EABI_VER1 = 0x01000000U, - EF_ARM_EABI_VER2 = 0x02000000U, - EF_ARM_EABI_VER3 = 0x03000000U, - EF_ARM_EABI_VER4 = 0x04000000U, - EF_ARM_EABI_VER5 = 0x05000000U, - EF_ARM_EABIMASK = 0xFF000000U -}; - -/* Mips Specific e_flags */ -enum class MIPS_EFLAGS: size_t { - EF_MIPS_NOREORDER = 0x00000001, /* Don't reorder instructions */ - EF_MIPS_PIC = 0x00000002, /* Position independent code */ - EF_MIPS_CPIC = 0x00000004, /* Call object with Position independent code */ - EF_MIPS_ABI2 = 0x00000020, /* File uses N32 ABI */ - EF_MIPS_32BITMODE = 0x00000100, /* Code compiled for a 64-bit machine */ - /* in 32-bit mode */ - EF_MIPS_FP64 = 0x00000200, /* Code compiled for a 32-bit machine */ - /* but uses 64-bit FP registers */ - EF_MIPS_NAN2008 = 0x00000400, /* Uses IEE 754-2008 NaN encoding */ - - /* ABI flags */ - EF_MIPS_ABI_O32 = 0x00001000, /* This file follows the first MIPS 32 bit ABI */ - EF_MIPS_ABI_O64 = 0x00002000, /* O32 ABI extended for 64-bit architecture. */ - EF_MIPS_ABI_EABI32 = 0x00003000, /* EABI in 32 bit mode. */ - EF_MIPS_ABI_EABI64 = 0x00004000, /* EABI in 64 bit mode. */ - EF_MIPS_ABI = 0x0000f000, /* Mask for selecting EF_MIPS_ABI_ variant. */ - - /* MIPS machine variant */ - EF_MIPS_MACH_3900 = 0x00810000, /* Toshiba R3900 */ - EF_MIPS_MACH_4010 = 0x00820000, /* LSI R4010 */ - EF_MIPS_MACH_4100 = 0x00830000, /* NEC VR4100 */ - EF_MIPS_MACH_4650 = 0x00850000, /* MIPS R4650 */ - EF_MIPS_MACH_4120 = 0x00870000, /* NEC VR4120 */ - EF_MIPS_MACH_4111 = 0x00880000, /* NEC VR4111/VR4181 */ - EF_MIPS_MACH_SB1 = 0x008a0000, /* Broadcom SB-1 */ - EF_MIPS_MACH_OCTEON = 0x008b0000, /* Cavium Networks Octeon */ - EF_MIPS_MACH_XLR = 0x008c0000, /* RMI Xlr */ - EF_MIPS_MACH_OCTEON2 = 0x008d0000, /* Cavium Networks Octeon2 */ - EF_MIPS_MACH_OCTEON3 = 0x008e0000, /* Cavium Networks Octeon3 */ - EF_MIPS_MACH_5400 = 0x00910000, /* NEC VR5400 */ - EF_MIPS_MACH_5900 = 0x00920000, /* MIPS R5900 */ - EF_MIPS_MACH_5500 = 0x00980000, /* NEC VR5500 */ - EF_MIPS_MACH_9000 = 0x00990000, /* Unknown */ - EF_MIPS_MACH_LS2E = 0x00a00000, /* ST Microelectronics Loongson 2E */ - EF_MIPS_MACH_LS2F = 0x00a10000, /* ST Microelectronics Loongson 2F */ - EF_MIPS_MACH_LS3A = 0x00a20000, /* Loongson 3A */ - EF_MIPS_MACH = 0x00ff0000, /* EF_MIPS_MACH_xxx selection mask */ - - /* ARCH_ASE */ - EF_MIPS_MICROMIPS = 0x02000000, /* microMIPS */ - EF_MIPS_ARCH_ASE_M16 = 0x04000000, /* Has Mips-16 ISA extensions */ - EF_MIPS_ARCH_ASE_MDMX = 0x08000000, /* Has MDMX multimedia extensions */ - EF_MIPS_ARCH_ASE = 0x0f000000, /* Mask for EF_MIPS_ARCH_ASE_xxx flags */ - - /* ARCH */ - EF_MIPS_ARCH_1 = 0x00000000, /* MIPS1 instruction set */ - EF_MIPS_ARCH_2 = 0x10000000, /* MIPS2 instruction set */ - EF_MIPS_ARCH_3 = 0x20000000, /* MIPS3 instruction set */ - EF_MIPS_ARCH_4 = 0x30000000, /* MIPS4 instruction set */ - EF_MIPS_ARCH_5 = 0x40000000, /* MIPS5 instruction set */ - EF_MIPS_ARCH_32 = 0x50000000, /* MIPS32 instruction set per linux not elf.h */ - EF_MIPS_ARCH_64 = 0x60000000, /* MIPS64 instruction set per linux not elf.h */ - EF_MIPS_ARCH_32R2 = 0x70000000, /* mips32r2, mips32r3, mips32r5 */ - EF_MIPS_ARCH_64R2 = 0x80000000, /* mips64r2, mips64r3, mips64r5 */ - EF_MIPS_ARCH_32R6 = 0x90000000, /* mips32r6 */ - EF_MIPS_ARCH_64R6 = 0xa0000000, /* mips64r6 */ - EF_MIPS_ARCH = 0xf0000000 /* Mask for applying EF_MIPS_ARCH_ variant */ -}; - -/* Hexagon Specific e_flags */ -/* Release 5 ABI */ -enum class HEXAGON_EFLAGS: size_t { - /* Object processor version flags, bits[3:0] */ - EF_HEXAGON_MACH_V2 = 0x00000001, /* Hexagon V2 */ - EF_HEXAGON_MACH_V3 = 0x00000002, /* Hexagon V3 */ - EF_HEXAGON_MACH_V4 = 0x00000003, /* Hexagon V4 */ - EF_HEXAGON_MACH_V5 = 0x00000004, /* Hexagon V5 */ - - /* Highest ISA version flags */ - EF_HEXAGON_ISA_MACH = 0x00000000, /* Same as specified in bits[3:0] */ - /* of e_flags */ - EF_HEXAGON_ISA_V2 = 0x00000010, /* Hexagon V2 ISA */ - EF_HEXAGON_ISA_V3 = 0x00000020, /* Hexagon V3 ISA */ - EF_HEXAGON_ISA_V4 = 0x00000030, /* Hexagon V4 ISA */ - EF_HEXAGON_ISA_V5 = 0x00000040 /* Hexagon V5 ISA */ -}; - -/* LoongArch Specific e_flags */ -enum class LOONGARCH_EFLAGS: size_t { - EF_LOONGARCH_ABI_SOFT_FLOAT = 0x1, - EF_LOONGARCH_ABI_SINGLE_FLOAT = 0x2, - EF_LOONGARCH_ABI_DOUBLE_FLOAT = 0x3 -}; - - -/** Special section indices. */ -enum class SYMBOL_SECTION_INDEX: size_t { - SHN_UNDEF = 0, /**< Undefined, missing, irrelevant, or meaningless */ - SHN_LORESERVE = 0xff00, /**< Lowest reserved index */ - SHN_LOPROC = 0xff00, /**< Lowest processor-specific index */ - SHN_HIPROC = 0xff1f, /**< Highest processor-specific index */ - SHN_LOOS = 0xff20, /**< Lowest operating system-specific index */ - SHN_HIOS = 0xff3f, /**< Highest operating system-specific index */ - SHN_ABS = 0xfff1, /**< Symbol has absolute value; does not need relocation */ - SHN_COMMON = 0xfff2, /**< FORTRAN COMMON or C external global variables */ - SHN_XINDEX = 0xffff, /**< Mark that the index is >= SHN_LORESERVE */ - SHN_HIRESERVE = 0xffff /**< Highest reserved index */ -}; - -/** Section types. */ -enum class ELF_SECTION_TYPES: size_t { - SHT_NULL = 0, /**< No associated section (inactive entry). */ - SHT_PROGBITS = 1, /**< Program-defined contents. */ - SHT_SYMTAB = 2, /**< Symbol table. */ - SHT_STRTAB = 3, /**< String table. */ - SHT_RELA = 4, /**< Relocation entries; explicit addends. */ - SHT_HASH = 5, /**< Symbol hash table. */ - SHT_DYNAMIC = 6, /**< Information for dynamic linking. */ - SHT_NOTE = 7, /**< Information about the file. */ - SHT_NOBITS = 8, /**< Data occupies no space in the file. */ - SHT_REL = 9, /**< Relocation entries; no explicit addends. */ - SHT_SHLIB = 10, /**< Reserved. */ - SHT_DYNSYM = 11, /**< Symbol table. */ - SHT_INIT_ARRAY = 14, /**< Pointers to initialization functions. */ - SHT_FINI_ARRAY = 15, /**< Pointers to termination functions. */ - SHT_PREINIT_ARRAY = 16, /**< Pointers to pre-init functions. */ - SHT_GROUP = 17, /**< Section group. */ - SHT_SYMTAB_SHNDX = 18, /**< Indices for SHN_XINDEX entries. */ - SHT_LOOS = 0x60000000, /**< Lowest operating system-specific type. */ - SHT_ANDROID_REL = 0x60000001, /**< Packed relocations (Android specific). */ - SHT_ANDROID_RELA = 0x60000002, /**< Packed relocations (Android specific). */ - SHT_LLVM_ADDRSIG = 0x6fff4c03, /**< This section is used to mark symbols as address-significant. */ - SHT_RELR = 0x6fffff00, /**< New relr relocations (Android specific). */ - SHT_GNU_ATTRIBUTES = 0x6ffffff5, /**< Object attributes. */ - SHT_GNU_HASH = 0x6ffffff6, /**< GNU-style hash table. */ - SHT_GNU_verdef = 0x6ffffffd, /**< GNU version definitions. */ - SHT_GNU_verneed = 0x6ffffffe, /**< GNU version references. */ - SHT_GNU_versym = 0x6fffffff, /**< GNU symbol versions table. */ - SHT_HIOS = 0x6fffffff, /**< Highest operating system-specific type. */ - SHT_LOPROC = 0x70000000, /**< Lowest processor arch-specific type. */ - SHT_ARM_EXIDX = 0x70000001U, /**< Exception Index table */ - SHT_ARM_PREEMPTMAP = 0x70000002U, /**< BPABI DLL dynamic linking pre-emption map */ - SHT_ARM_ATTRIBUTES = 0x70000003U, /**< Object file compatibility attributes */ - SHT_ARM_DEBUGOVERLAY = 0x70000004U, - SHT_ARM_OVERLAYSECTION = 0x70000005U, - SHT_HEX_ORDERED = 0x70000000, /**< Link editor is to sort the entries in */ - - /* this section based on their sizes */ - SHT_X86_64_UNWIND = 0x70000001, /**< Unwind information */ - SHT_MIPS_REGINFO = 0x70000006, /**< Register usage information */ - SHT_MIPS_OPTIONS = 0x7000000d, /**< General options */ - SHT_MIPS_ABIFLAGS = 0x7000002a, /**< ABI information. */ - - SHT_HIPROC = 0x7fffffff, /**< Highest processor arch-specific type. */ - SHT_LOUSER = 0x80000000, /**< Lowest type reserved for applications. */ - SHT_HIUSER = 0xffffffff /**< Highest type reserved for applications. */ -}; - - - -/** Section flags. */ -enum class ELF_SECTION_FLAGS: size_t { - SHF_NONE = 0x0, - SHF_WRITE = 0x1, /**< Section data should be writable during execution. */ - SHF_ALLOC = 0x2, /**< Section occupies memory during program execution. */ - SHF_EXECINSTR = 0x4, /**< Section contains executable machine instructions. */ - SHF_MERGE = 0x10, /**< The data in this section may be merged. */ - SHF_STRINGS = 0x20, /**< The data in this section is null-terminated strings. */ - SHF_INFO_LINK = 0x40U, /**< A field in this section holds a section header table index. */ - SHF_LINK_ORDER = 0x80U, /**< Adds special ordering requirements for link editors. */ - SHF_OS_NONCONFORMING = 0x100U, /**< This section requires special OS-specific processing to avoid incorrect behavior */ - SHF_GROUP = 0x200U, /**< This section is a member of a section group. */ - SHF_TLS = 0x400U, /**< This section holds Thread-Local Storage. */ - SHF_EXCLUDE = 0x80000000U, /**< This section is excluded from the final executable or shared library. */ - /* Start of target-specific flags. */ - - /* XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped - * together by the linker to form the constant pool and the cp register is - * set to the start of the constant pool by the boot code. - */ - XCORE_SHF_CP_SECTION = 0x800U, - - /* XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped - * together by the linker to form the data section and the dp register is - * set to the start of the section by the boot code. - */ - XCORE_SHF_DP_SECTION = 0x1000U, - SHF_MASKOS = 0x0ff00000, - SHF_MASKPROC = 0xf0000000, /**< Bits indicating processor-specific flags. */ - - /* If an object file section does not have this flag set, then it may not hold - * more than 2GB and can be freely referred to in objects using smaller code - * models. Otherwise, only objects using larger code models can refer to them. - * For example, a medium code model object can refer to data in a section that - * sets this flag besides being able to refer to data in a section that does - * not set it; likewise, a small code model object can refer only to code in a - * section that does not set this flag. - */ - SHF_X86_64_LARGE = 0x10000000, - - /* All sections with the GPREL flag are grouped into a global data area - * for faster accesses. - */ - SHF_HEX_GPREL = 0x10000000, - - /* Section contains text/data which may be replicated in other sections. - * Linker must retain only one copy. - */ - SHF_MIPS_NODUPES = 0x01000000, - - SHF_MIPS_NAMES = 0x02000000, /**< Linker must generate implicit hidden weak names. */ - SHF_MIPS_LOCAL = 0x04000000, /**< Section data local to process. */ - SHF_MIPS_NOSTRIP = 0x08000000, /**< Do not strip this section. */ - SHF_MIPS_GPREL = 0x10000000, /**< Section must be part of global data area. */ - SHF_MIPS_MERGE = 0x20000000, /**< This section should be merged. */ - SHF_MIPS_ADDR = 0x40000000, /**< Address size to be inferred from section entry size. */ - SHF_MIPS_STRING = 0x80000000 /**< Section data is string data by default. */ -}; - - -/** Symbol bindings. */ -enum class SYMBOL_BINDINGS: size_t { - STB_LOCAL = 0, /**< Local symbol, not visible outside obj file containing def */ - STB_GLOBAL = 1, /**< Global symbol, visible to all object files being combined */ - STB_WEAK = 2, /**< Weak symbol, like global but lower-precedence */ - STB_GNU_UNIQUE = 10, - STB_LOOS = 10, /**< Lowest operating system-specific binding type */ - STB_HIOS = 12, /**< Highest operating system-specific binding type */ - STB_LOPROC = 13, /**< Lowest processor-specific binding type */ - STB_HIPROC = 15 /**< Highest processor-specific binding type */ -}; - - -/* Symbol types. */ -enum class ELF_SYMBOL_TYPES: size_t { - STT_NOTYPE = 0, /* Symbol's type is not specified */ - STT_OBJECT = 1, /* Symbol is a data object (variable, array, etc.) */ - STT_FUNC = 2, /* Symbol is executable code (function, etc.) */ - STT_SECTION = 3, /* Symbol refers to a section */ - STT_FILE = 4, /* Local, absolute symbol that refers to a file */ - STT_COMMON = 5, /* An uninitialized common block */ - STT_TLS = 6, /* Thread local data object */ - STT_GNU_IFUNC = 10, /* GNU indirect function */ - STT_LOOS = 10, /* Lowest operating system-specific symbol type */ - STT_HIOS = 12, /* Highest operating system-specific symbol type */ - STT_LOPROC = 13, /* Lowest processor-specific symbol type */ - STT_HIPROC = 15 /* Highest processor-specific symbol type */ -}; - -enum class ELF_SYMBOL_VISIBILITY: size_t { - STV_DEFAULT = 0, /* Visibility is specified by binding type */ - STV_INTERNAL = 1, /* Defined by processor supplements */ - STV_HIDDEN = 2, /* Not visible to other components */ - STV_PROTECTED = 3 /* Visible in other components but not preemptable */ -}; - - -/** @brief Segment types. */ -enum class SEGMENT_TYPES: size_t { - PT_NULL = 0, /**< Unused segment. */ - PT_LOAD = 1, /**< Loadable segment. */ - PT_DYNAMIC = 2, /**< Dynamic linking information. */ - PT_INTERP = 3, /**< Interpreter pathname. */ - PT_NOTE = 4, /**< Auxiliary information. */ - PT_SHLIB = 5, /**< Reserved. */ - PT_PHDR = 6, /**< The program header table itself. */ - PT_TLS = 7, /**< The thread-local storage template. */ - PT_LOOS = 0x60000000, /**< Lowest operating system-specific pt entry type. */ - PT_HIOS = 0x6fffffff, /**< Highest operating system-specific pt entry type. */ - PT_LOPROC = 0x70000000, /**< Lowest processor-specific program hdr entry type. */ - PT_HIPROC = 0x7fffffff, /**< Highest processor-specific program hdr entry type. */ - - /* x86-64 program header types. */ - /* These all contain stack unwind tables. */ - PT_GNU_EH_FRAME = 0x6474e550, - PT_SUNW_EH_FRAME = 0x6474e550, - PT_SUNW_UNWIND = 0x6464e550, - - PT_GNU_STACK = 0x6474e551, /**< Indicates stack executability. */ - PT_GNU_PROPERTY = 0x6474e553, /**< GNU property */ - PT_GNU_RELRO = 0x6474e552, /**< Read-only after relocation. */ - - /* ARM program header types. */ - PT_ARM_ARCHEXT = 0x70000000, /**< Platform architecture compatibility info */ - - /* These all contain stack unwind tables. */ - PT_ARM_EXIDX = 0x70000001, - PT_ARM_UNWIND = 0x70000001, - - /* MIPS program header types. */ - PT_MIPS_REGINFO = 0x70000000, /**< Register usage information. */ - PT_MIPS_RTPROC = 0x70000001, /**< Runtime procedure table. */ - PT_MIPS_OPTIONS = 0x70000002, /**< Options segment. */ - PT_MIPS_ABIFLAGS = 0x70000003 /**< Abiflags segment. */ -}; - - -/** Segment flags. */ -enum class ELF_SEGMENT_FLAGS: size_t { - PF_NONE = 0, - PF_X = 1, /**< Execute */ - PF_W = 2, /**< Write */ - PF_R = 4, /**< Read */ - PF_MASKOS = 0x0ff00000,/**< Bits for operating system-specific semantics. */ - PF_MASKPROC = 0xf0000000 /**< Bits for processor-specific semantics. */ -}; - - -/** Dynamic table entry tags. */ -enum class DYNAMIC_TAGS: size_t { - DT_NULL = 0, /**< Marks end of dynamic array. */ - DT_NEEDED = 1, /**< String table offset of needed library. */ - DT_PLTRELSZ = 2, /**< Size of relocation entries in PLT. */ - DT_PLTGOT = 3, /**< Address associated with linkage table. */ - DT_HASH = 4, /**< Address of symbolic hash table. */ - DT_STRTAB = 5, /**< Address of dynamic string table. */ - DT_SYMTAB = 6, /**< Address of dynamic symbol table. */ - DT_RELA = 7, /**< Address of relocation table (Rela entries). */ - DT_RELASZ = 8, /**< Size of Rela relocation table. */ - DT_RELAENT = 9, /**< Size of a Rela relocation entry. */ - DT_STRSZ = 10, /**< Total size of the string table. */ - DT_SYMENT = 11, /**< Size of a symbol table entry. */ - DT_INIT = 12, /**< Address of initialization function. */ - DT_FINI = 13, /**< Address of termination function. */ - DT_SONAME = 14, /**< String table offset of a shared objects name. */ - DT_RPATH = 15, /**< String table offset of library search path. */ - DT_SYMBOLIC = 16, /**< Changes symbol resolution algorithm. */ - DT_REL = 17, /**< Address of relocation table (Rel entries). */ - DT_RELSZ = 18, /**< Size of Rel relocation table. */ - DT_RELENT = 19, /**< Size of a Rel relocation entry. */ - DT_PLTREL = 20, /**< Type of relocation entry used for linking. */ - DT_DEBUG = 21, /**< Reserved for debugger. */ - DT_TEXTREL = 22, /**< Relocations exist for non-writable segments. */ - DT_JMPREL = 23, /**< Address of relocations associated with PLT. */ - DT_BIND_NOW = 24, /**< Process all relocations before execution. */ - DT_INIT_ARRAY = 25, /**< Pointer to array of initialization functions. */ - DT_FINI_ARRAY = 26, /**< Pointer to array of termination functions. */ - DT_INIT_ARRAYSZ = 27, /**< Size of DT_INIT_ARRAY. */ - DT_FINI_ARRAYSZ = 28, /**< Size of DT_FINI_ARRAY. */ - DT_RUNPATH = 29, /**< String table offset of lib search path. */ - DT_FLAGS = 30, /**< Flags. */ - DT_ENCODING = 32, /**< Values from here to DT_LOOS follow the rules for the interpretation of the d_un union. */ - - DT_PREINIT_ARRAY = 32, /**< Pointer to array of preinit functions. */ - DT_PREINIT_ARRAYSZ = 33, /**< Size of the DT_PREINIT_ARRAY array. */ - DT_SYMTAB_SHNDX = 34, /**< Address of SYMTAB_SHNDX section */ - DT_RELRSZ = 35, /**< Total size of RELR relative relocations */ - DT_RELR = 36, /**< Address of RELR relative relocations */ - DT_RELRENT = 37, /**< Size of one RELR relative relocaction */ - - DT_LOOS = 0x60000000, /**< Start of environment specific tags. */ - DT_HIOS = 0x6FFFFFFF, /**< End of environment specific tags. */ - DT_LOPROC = 0x70000000, /**< Start of processor specific tags. */ - DT_HIPROC = 0x7FFFFFFF, /**< End of processor specific tags. */ - - DT_GNU_HASH = 0x6FFFFEF5, /**< Reference to the GNU hash table. */ - DT_RELACOUNT = 0x6FFFFFF9, /**< ELF32_Rela count. */ - DT_RELCOUNT = 0x6FFFFFFA, /**< ELF32_Rel count. */ - - DT_FLAGS_1 = 0x6FFFFFFB, /**< Flags_1. */ - DT_VERSYM = 0x6FFFFFF0, /**< The address of .gnu.version section. */ - DT_VERDEF = 0x6FFFFFFC, /**< The address of the version definition table. */ - DT_VERDEFNUM = 0x6FFFFFFD, /**< The number of entries in DT_VERDEF. */ - DT_VERNEED = 0x6FFFFFFE, /**< The address of the version Dependency table. */ - DT_VERNEEDNUM = 0x6FFFFFFF, /**< The number of entries in DT_VERNEED. */ - - /* Mips specific dynamic table entry tags. */ - DT_MIPS_RLD_VERSION = 0x70000001, /**< 32 bit version number for runtime linker interface. */ - DT_MIPS_TIME_STAMP = 0x70000002, /**< Time stamp. */ - DT_MIPS_ICHECKSUM = 0x70000003, /**< Checksum of external strings and common sizes. */ - DT_MIPS_IVERSION = 0x70000004, /**< Index of version string in string table. */ - DT_MIPS_FLAGS = 0x70000005, /**< 32 bits of flags. */ - DT_MIPS_BASE_ADDRESS = 0x70000006, /**< Base address of the segment. */ - DT_MIPS_MSYM = 0x70000007, /**< Address of .msym section. */ - DT_MIPS_CONFLICT = 0x70000008, /**< Address of .conflict section. */ - DT_MIPS_LIBLIST = 0x70000009, /**< Address of .liblist section. */ - DT_MIPS_LOCAL_GOTNO = 0x7000000a, /**< Number of local global offset table entries. */ - DT_MIPS_CONFLICTNO = 0x7000000b, /**< Number of entries in the .conflict section. */ - DT_MIPS_LIBLISTNO = 0x70000010, /**< Number of entries in the .liblist section. */ - DT_MIPS_SYMTABNO = 0x70000011, /**< Number of entries in the .dynsym section. */ - DT_MIPS_UNREFEXTNO = 0x70000012, /**< Index of first external dynamic symbol not referenced locally. */ - DT_MIPS_GOTSYM = 0x70000013, /**< Index of first dynamic symbol in global offset table. */ - DT_MIPS_HIPAGENO = 0x70000014, /**< Number of page table entries in global offset table. */ - DT_MIPS_RLD_MAP = 0x70000016, /**< Address of run time loader map, used for debugging. */ - DT_MIPS_DELTA_CLASS = 0x70000017, /**< Delta C++ class definition. */ - DT_MIPS_DELTA_CLASS_NO = 0x70000018, /**< Number of entries in DT_MIPS_DELTA_CLASS. */ - DT_MIPS_DELTA_INSTANCE = 0x70000019, /**< Delta C++ class instances. */ - DT_MIPS_DELTA_INSTANCE_NO = 0x7000001A, /**< Number of entries in DT_MIPS_DELTA_INSTANCE. */ - DT_MIPS_DELTA_RELOC = 0x7000001B, /**< Delta relocations. */ - DT_MIPS_DELTA_RELOC_NO = 0x7000001C, /**< Number of entries in DT_MIPS_DELTA_RELOC. */ - DT_MIPS_DELTA_SYM = 0x7000001D, /**< Delta symbols that Delta relocations refer to. */ - DT_MIPS_DELTA_SYM_NO = 0x7000001E, /**< Number of entries in DT_MIPS_DELTA_SYM. */ - DT_MIPS_DELTA_CLASSSYM = 0x70000020, /**< Delta symbols that hold class declarations. */ - DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021, /**< Number of entries in DT_MIPS_DELTA_CLASSSYM. */ - DT_MIPS_CXX_FLAGS = 0x70000022, /**< Flags indicating information about C++ flavor. */ - DT_MIPS_PIXIE_INIT = 0x70000023, /**< Pixie information. */ - DT_MIPS_SYMBOL_LIB = 0x70000024, /**< Address of .MIPS.symlib */ - DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025, /**< The GOT index of the first PTE for a segment */ - DT_MIPS_LOCAL_GOTIDX = 0x70000026, /**< The GOT index of the first PTE for a local symbol */ - DT_MIPS_HIDDEN_GOTIDX = 0x70000027, /**< The GOT index of the first PTE for a hidden symbol */ - DT_MIPS_PROTECTED_GOTIDX = 0x70000028, /**< The GOT index of the first PTE for a protected symbol */ - DT_MIPS_OPTIONS = 0x70000029, /**< Address of `.MIPS.options'. */ - DT_MIPS_INTERFACE = 0x7000002A, /**< Address of `.interface'. */ - DT_MIPS_DYNSTR_ALIGN = 0x7000002B, /**< Unknown. */ - DT_MIPS_INTERFACE_SIZE = 0x7000002C, /**< Size of the .interface section. */ - DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002D, /**< Size of rld_text_resolve function stored in the GOT. */ - DT_MIPS_PERF_SUFFIX = 0x7000002E, /**< Default suffix of DSO to be added by rld on dlopen() calls. */ - DT_MIPS_COMPACT_SIZE = 0x7000002F, /**< Size of compact relocation section (O32). */ - DT_MIPS_GP_VALUE = 0x70000030, /**< GP value for auxiliary GOTs. */ - DT_MIPS_AUX_DYNAMIC = 0x70000031, /**< Address of auxiliary .dynamic. */ - DT_MIPS_PLTGOT = 0x70000032, /**< Address of the base of the PLTGOT. */ - DT_MIPS_RWPLT = 0x70000034, /**< Points to the base of a writable PLT. */ - - /* Android specific dynamic table entry tags. */ - DT_ANDROID_REL_OFFSET = 0x6000000D, /**< The offset of packed relocation data (older version < M) (Android specific). */ - DT_ANDROID_REL_SIZE = 0x6000000E, /**< The size of packed relocation data in bytes (older version < M) (Android specific). */ - DT_ANDROID_REL = 0x6000000F, /**< The offset of packed relocation data (Android specific). */ - DT_ANDROID_RELSZ = 0x60000010, /**< The size of packed relocation data in bytes (Android specific). */ - DT_ANDROID_RELA = 0x60000011, /**< The offset of packed relocation data (Android specific). */ - DT_ANDROID_RELASZ = 0x60000012, /**< The size of packed relocation data in bytes (Android specific). */ - DT_ANDROID_RELR = 0x6FFFE000, /**< The offset of new relr relocation data (Android specific). */ - DT_ANDROID_RELRSZ = 0x6FFFE001, /**< The size of nre relr relocation data in bytes (Android specific). */ - DT_ANDROID_RELRENT = 0x6FFFE003, /**< The size of a new relr relocation entry (Android specific). */ - DT_ANDROID_RELRCOUNT = 0x6FFFE005 /**< Specifies the relative count of new relr relocation entries (Android specific). */ -}; - -/** DT_FLAGS and DT_FLAGS_1 values. */ -enum class DYNAMIC_FLAGS: size_t { - DF_ORIGIN = 0x00000001, /**< The object may reference $ORIGIN. */ - DF_SYMBOLIC = 0x00000002, /**< Search the shared lib before searching the exe. */ - DF_TEXTREL = 0x00000004, /**< Relocations may modify a non-writable segment. */ - DF_BIND_NOW = 0x00000008, /**< Process all relocations on load. */ - DF_STATIC_TLS = 0x00000010, /**< Reject attempts to load dynamically. */ -}; - -enum class DYNAMIC_FLAGS_1: size_t { - DF_1_NOW = 0x00000001, /**< Set RTLD_NOW for this object. */ - DF_1_GLOBAL = 0x00000002, /**< Set RTLD_GLOBAL for this object. */ - DF_1_GROUP = 0x00000004, /**< Set RTLD_GROUP for this object. */ - DF_1_NODELETE = 0x00000008, /**< Set RTLD_NODELETE for this object. */ - DF_1_LOADFLTR = 0x00000010, /**< Trigger filtee loading at runtime. */ - DF_1_INITFIRST = 0x00000020, /**< Set RTLD_INITFIRST for this object. */ - DF_1_NOOPEN = 0x00000040, /**< Set RTLD_NOOPEN for this object. */ - DF_1_ORIGIN = 0x00000080, /**< $ORIGIN must be handled. */ - DF_1_DIRECT = 0x00000100, /**< Direct binding enabled. */ - DF_1_TRANS = 0x00000200, - DF_1_INTERPOSE = 0x00000400, /**< Object is used to interpose. */ - DF_1_NODEFLIB = 0x00000800, /**< Ignore default lib search path. */ - DF_1_NODUMP = 0x00001000, /**< Object can't be dldump'ed. */ - DF_1_CONFALT = 0x00002000, /**< Configuration alternative created. */ - DF_1_ENDFILTEE = 0x00004000, /**< Filtee terminates filters search. */ - DF_1_DISPRELDNE = 0x00008000, /**< Disp reloc applied at build time. */ - DF_1_DISPRELPND = 0x00010000, /**< Disp reloc applied at run-time. */ - DF_1_NODIRECT = 0x00020000, /**< Object has no-direct binding. */ - DF_1_IGNMULDEF = 0x00040000, - DF_1_NOKSYMS = 0x00080000, - DF_1_NOHDR = 0x00100000, - DF_1_EDITED = 0x00200000, /**< Object is modified after built. */ - DF_1_NORELOC = 0x00400000, - DF_1_SYMINTPOSE = 0x00800000, /**< Object has individual interposers. */ - DF_1_GLOBAUDIT = 0x01000000, /**< Global auditing required. */ - DF_1_SINGLETON = 0x02000000, /**< Singleton symbols are used. */ - DF_1_PIE = 0x08000000 /**< Singleton symbols are used. */ -}; - -/* DT_MIPS_FLAGS values. */ -enum { - RHF_NONE = 0x00000000, /* No flags. */ - RHF_QUICKSTART = 0x00000001, /* Uses shortcut pointers. */ - RHF_NOTPOT = 0x00000002, /* Hash size is not a power of two. */ - RHS_NO_LIBRARY_REPLACEMENT = 0x00000004, /* Ignore LD_LIBRARY_PATH. */ - RHF_NO_MOVE = 0x00000008, /* DSO address may not be relocated. */ - RHF_SGI_ONLY = 0x00000010, /* SGI specific features. */ - RHF_GUARANTEE_INIT = 0x00000020, /* Guarantee that .init will finish */ - /* executing before any non-init */ - /* code in DSO is called. */ - RHF_DELTA_C_PLUS_PLUS = 0x00000040, /* Contains Delta C++ code. */ - RHF_GUARANTEE_START_INIT = 0x00000080, /* Guarantee that .init will start */ - /* executing before any non-init */ - /* code in DSO is called. */ - RHF_PIXIE = 0x00000100, /* Generated by pixie. */ - RHF_DEFAULT_DELAY_LOAD = 0x00000200, /* Delay-load DSO by default. */ - RHF_REQUICKSTART = 0x00000400, /* Object may be requickstarted */ - RHF_REQUICKSTARTED = 0x00000800, /* Object has been requickstarted */ - RHF_CORD = 0x00001000, /* Generated by cord. */ - RHF_NO_UNRES_UNDEF = 0x00002000, /* Object contains no unresolved */ - /* undef symbols. */ - RHF_RLD_ORDER_SAFE = 0x00004000 /* Symbol table is in a safe order. */ -}; - -/** ElfXX_VerDef structure version (GNU versioning) */ -enum { - VER_DEF_NONE = 0, - VER_DEF_CURRENT = 1 -}; - -/** VerDef Flags (ElfXX_VerDef::vd_flags) */ -enum { - VER_FLG_BASE = 0x1, - VER_FLG_WEAK = 0x2, - VER_FLG_INFO = 0x4 -}; - -/** Special constants for the version table. (SHT_GNU_versym/.gnu.version) */ -enum { - VER_NDX_LOCAL = 0, /**< Unversioned local symbol */ - VER_NDX_GLOBAL = 1, /**< Unversioned global symbol */ - VERSYM_VERSION = 0x7fff, /**< Version Index mask */ - VERSYM_HIDDEN = 0x8000 /**< Hidden bit (non-default version) */ -}; - -/** ElfXX_VerNeed structure version (GNU versioning) */ -enum { - VER_NEED_NONE = 0, - VER_NEED_CURRENT = 1 -}; - -/** Methods that can be used by the LIEF::ELF::Parser - to count the number of dynamic symbols */ -enum class DYNSYM_COUNT_METHODS: size_t { - COUNT_AUTO = 0, /**< Automatic detection */ - COUNT_SECTION = 1, /**< Count based on sections (not very reliable) */ - COUNT_HASH = 2, /**< Count based on hash table (reliable) */ - COUNT_RELOCATIONS = 3, /**< Count based on PLT/GOT relocations (very reliable but not accurate) */ -}; - -enum class RELOCATION_PURPOSES: size_t { - RELOC_PURPOSE_NONE = 0, - RELOC_PURPOSE_PLTGOT = 1, - RELOC_PURPOSE_DYNAMIC = 2, - RELOC_PURPOSE_OBJECT = 3, +enum class ARCH { + NONE = 0, /**< No machine */ + M32 = 1, /**< AT&T WE 32100 */ + SPARC = 2, /**< SPARC */ + I386 = 3, /**< Intel 386 */ + M68K = 4, /**< Motorola 68000 */ + M88K = 5, /**< Motorola 88000 */ + IAMCU = 6, /**< Intel MCU */ + I860 = 7, /**< Intel 80860 */ + MIPS = 8, /**< MIPS R3000 */ + S370 = 9, /**< IBM System/370 */ + MIPS_RS3_LE = 10, /**< MIPS RS3000 Little-endian */ + PARISC = 15, /**< Hewlett-Packard PA-RISC */ + VPP500 = 17, /**< Fujitsu VPP500 */ + SPARC32PLUS = 18, /**< Enhanced instruction set SPARC */ + I60 = 19, /**< Intel 80960 */ + PPC = 20, /**< PowerPC */ + PPC64 = 21, /**< PowerPC64 */ + S390 = 22, /**< IBM System/390 */ + SPU = 23, /**< IBM SPU/SPC */ + V800 = 36, /**< NEC V800 */ + FR20 = 37, /**< Fujitsu FR20 */ + RH32 = 38, /**< TRW RH-32 */ + RCE = 39, /**< Motorola RCE */ + ARM = 40, /**< ARM */ + ALPHA = 41, /**< DEC Alpha */ + SH = 42, /**< Hitachi SH */ + SPARCV9 = 43, /**< SPARC V9 */ + TRICORE = 44, /**< Siemens TriCore */ + ARC = 45, /**< Argonaut RISC Core */ + H8_300 = 46, /**< Hitachi H8/300 */ + H8_300H = 47, /**< Hitachi H8/300H */ + H8S = 48, /**< Hitachi H8S */ + H8_500 = 49, /**< Hitachi H8/500 */ + IA_64 = 50, /**< Intel IA-64 processor architecture */ + MIPS_X = 51, /**< Stanford MIPS-X */ + COLDFIRE = 52, /**< Motorola ColdFire */ + M68HC12 = 53, /**< Motorola M68HC12 */ + MMA = 54, /**< Fujitsu MMA Multimedia Accelerator */ + PCP = 55, /**< Siemens PCP */ + NCPU = 56, /**< Sony nCPU embedded RISC processor */ + NDR1 = 57, /**< Denso NDR1 microprocessor */ + STARCORE = 58, /**< Motorola Star*Core processor */ + ME16 = 59, /**< Toyota ME16 processor */ + ST100 = 60, /**< STMicroelectronics ST100 processor */ + TINYJ = 61, /**< Advanced Logic Corp. TinyJ embedded processor family */ + X86_64 = 62, /**< AMD x86-64 architecture */ + PDSP = 63, /**< Sony DSP Processor */ + PDP10 = 64, /**< Digital Equipment Corp. PDP-10 */ + PDP11 = 65, /**< Digital Equipment Corp. PDP-11 */ + FX66 = 66, /**< Siemens FX66 microcontroller */ + ST9PLUS = 67, /**< STMicroelectronics ST9+ 8/16 bit microcontroller */ + ST7 = 68, /**< STMicroelectronics ST7 8-bit microcontroller */ + M68HC16 = 69, /**< Motorola MC68HC16 Microcontroller */ + M68HC11 = 70, /**< Motorola MC68HC11 Microcontroller */ + M68HC08 = 71, /**< Motorola MC68HC08 Microcontroller */ + M68HC05 = 72, /**< Motorola MC68HC05 Microcontroller */ + SVX = 73, /**< Silicon Graphics SVx */ + ST19 = 74, /**< STMicroelectronics ST19 8-bit microcontroller */ + VAX = 75, /**< Digital VAX */ + CRIS = 76, /**< Axis Communications 32-bit embedded processor */ + JAVELIN = 77, /**< Infineon Technologies 32-bit embedded processor */ + FIREPATH = 78, /**< Element 14 64-bit DSP Processor */ + ZSP = 79, /**< LSI Logic 16-bit DSP Processor */ + MMIX = 80, /**< Donald Knuth's educational 64-bit processor */ + HUANY = 81, /**< Harvard University machine-independent object files */ + PRISM = 82, /**< SiTera Prism */ + AVR = 83, /**< Atmel AVR 8-bit microcontroller */ + FR30 = 84, /**< Fujitsu FR30 */ + D10V = 85, /**< Mitsubishi D10V */ + D30V = 86, /**< Mitsubishi D30V */ + V850 = 87, /**< NEC v850 */ + M32R = 88, /**< Mitsubishi M32R */ + MN10300 = 89, /**< Matsushita MN10300 */ + MN10200 = 90, /**< Matsushita MN10200 */ + PJ = 91, /**< picoJava */ + OPENRISC = 92, /**< OpenRISC 32-bit embedded processor */ + ARC_COMPACT = 93, /**< ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5) */ + XTENSA = 94, /**< Tensilica Xtensa Architecture */ + VIDEOCORE = 95, /**< Alphamosaic VideoCore processor */ + TMM_GPP = 96, /**< Thompson Multimedia General Purpose Processor */ + NS32K = 97, /**< National Semiconductor 32000 series */ + TPC = 98, /**< Tenor Network TPC processor */ + SNP1K = 99, /**< Trebia SNP 1000 processor */ + ST200 = 100, /**< STMicroelectronics (www.st.com) ST200 */ + IP2K = 101, /**< Ubicom IP2xxx microcontroller family */ + MAX = 102, /**< MAX Processor */ + CR = 103, /**< National Semiconductor CompactRISC microprocessor */ + F2MC16 = 104, /**< Fujitsu F2MC16 */ + MSP430 = 105, /**< Texas Instruments embedded microcontroller msp430 */ + BLACKFIN = 106, /**< Analog Devices Blackfin (DSP) processor */ + SE_C33 = 107, /**< S1C33 Family of Seiko Epson processors */ + SEP = 108, /**< Sharp embedded microprocessor */ + ARCA = 109, /**< Arca RISC Microprocessor */ + UNICORE = 110, /**< Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ + EXCESS = 111, /**< eXcess: 16/32/64-bit configurable embedded CPU */ + DXP = 112, /**< Icera Semiconductor Inc. Deep Execution Processor */ + ALTERA_NIOS2 = 113, /**< Altera Nios II soft-core processor */ + CRX = 114, /**< National Semiconductor CompactRISC CRX */ + XGATE = 115, /**< Motorola XGATE embedded processor */ + C166 = 116, /**< Infineon C16x/XC16x processor */ + M16C = 117, /**< Renesas M16C series microprocessors */ + DSPIC30F = 118, /**< Microchip Technology dsPIC30F Digital Signal */ + CE = 119, /**< Freescale Communication Engine RISC core */ + M32C = 120, /**< Renesas M32C series microprocessors */ + TSK3000 = 131, /**< Altium TSK3000 core */ + RS08 = 132, /**< Freescale RS08 embedded processor */ + SHARC = 133, /**< Analog Devices SHARC family of 32-bit DSP */ + ECOG2 = 134, /**< Cyan Technology eCOG2 microprocessor */ + SCORE7 = 135, /**< Sunplus S+core7 RISC processor */ + DSP24 = 136, /**< New Japan Radio (NJR) 24-bit DSP Processor */ + VIDEOCORE3 = 137, /**< Broadcom VideoCore III processor */ + LATTICEMICO32 = 138, /**< RISC processor for Lattice FPGA architecture */ + SE_C17 = 139, /**< Seiko Epson C17 family */ + TI_C6000 = 140, /**< The Texas Instruments TMS320C6000 DSP family */ + TI_C2000 = 141, /**< The Texas Instruments TMS320C2000 DSP family */ + TI_C5500 = 142, /**< The Texas Instruments TMS320C55x DSP family */ + MMDSP_PLUS = 160, /**< STMicroelectronics 64bit VLIW Data Signal Processor */ + CYPRESS_M8C = 161, /**< Cypress M8C microprocessor */ + R32C = 162, /**< Renesas R32C series microprocessors */ + TRIMEDIA = 163, /**< NXP Semiconductors TriMedia architecture family */ + HEXAGON = 164, /**< Qualcomm Hexagon processor */ + M8051 = 165, /**< Intel 8051 and variants */ + STXP7X = 166, /**< STMicroelectronics STxP7x family of configurable */ + NDS32 = 167, /* Andes Technology compact code size embedded RISC */ + ECOG1 = 168, /**< Cyan Technology eCOG1X family */ + ECOG1X = 168, /**< Cyan Technology eCOG1X family */ + MAXQ30 = 169, /**< Dallas Semiconductor MAXQ30 Core Micro-controllers */ + XIMO16 = 170, /**< New Japan Radio (NJR) 16-bit DSP Processor */ + MANIK = 171, /**< M2000 Reconfigurable RISC Microprocessor */ + CRAYNV2 = 172, /**< Cray Inc. NV2 vector architecture */ + RX = 173, /**< Renesas RX family */ + METAG = 174, /**< Imagination Technologies META processor */ + MCST_ELBRUS = 175, /**< MCST Elbrus general purpose hardware architecture */ + ECOG16 = 176, /**< Cyan Technology eCOG16 family */ + CR16 = 177, /**< National Semiconductor CompactRISC CR16 16-bit */ + ETPU = 178, /**< Freescale Extended Time Processing Unit */ + SLE9X = 179, /**< Infineon Technologies SLE9X core */ + L10M = 180, /**< Intel L10M */ + K10M = 181, /**< Intel K10M */ + AARCH64 = 183, /**< ARM AArch64 */ + AVR32 = 185, /**< Atmel Corporation 32-bit microprocessor family */ + STM8 = 186, /**< STMicroeletronics STM8 8-bit microcontroller */ + TILE64 = 187, /**< Tilera TILE64 multicore architecture family */ + TILEPRO = 188, /**< Tilera TILEPro multicore architecture family */ + CUDA = 190, /**< NVIDIA CUDA architecture */ + TILEGX = 191, /**< Tilera TILE-Gx multicore architecture family */ + CLOUDSHIELD = 192, /**< CloudShield architecture family */ + COREA_1ST = 193, /**< KIPO-KAIST Core-A 1st generation processor family */ + COREA_2ND = 194, /**< KIPO-KAIST Core-A 2nd generation processor family */ + ARC_COMPACT2 = 195, /**< Synopsys ARCompact V2 */ + OPEN8 = 196, /**< Open8 8-bit RISC soft processor core */ + RL78 = 197, /**< Renesas RL78 family */ + VIDEOCORE5 = 198, /**< Broadcom VideoCore V processor */ + M78KOR = 199, /**< Renesas 78KOR family */ + M56800EX = 200, /**< Freescale 56800EX Digital Signal Controller (DSC) */ + BA1 = 201, /**< Beyond BA1 CPU architecture */ + BA2 = 202, /**< Beyond BA2 CPU architecture */ + XCORE = 203, /**< XMOS xCORE processor family */ + MCHP_PIC = 204, /**< Microchip 8-bit PIC(r) family */ + INTEL205 = 205, /**< Reserved by Intel */ + INTEL206 = 206, /**< Reserved by Intel */ + INTEL207 = 207, /**< Reserved by Intel */ + INTEL208 = 208, /**< Reserved by Intel */ + INTEL209 = 209, /**< Reserved by Intel */ + KM32 = 210, /**< KM211 KM32 32-bit processor */ + KMX32 = 211, /**< KM211 KMX32 32-bit processor */ + KMX16 = 212, /**< KM211 KMX16 16-bit processor */ + KMX8 = 213, /**< KM211 KMX8 8-bit processor */ + KVARC = 214, /**< KM211 KVARC processor */ + CDP = 215, /**< Paneve CDP architecture family */ + COGE = 216, /**< Cognitive Smart Memory Processor */ + COOL = 217, /**< iCelero CoolEngine */ + NORC = 218, /**< Nanoradio Optimized RISC */ + CSR_KALIMBA = 219, /**< CSR Kalimba architecture family */ + AMDGPU = 224, /**< AMD GPU architecture */ + RISCV = 243, /**< RISC-V */ + BPF = 247, /**< eBPF Filter */ + LOONGARCH = 258 /**< LoongArch */ }; } } -ENABLE_BITMASK_OPERATORS(LIEF::ELF::ELF_SEGMENT_FLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::ARM_EFLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::MIPS_EFLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::HEXAGON_EFLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::LOONGARCH_EFLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::ELF_SECTION_FLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::DYNAMIC_FLAGS) -ENABLE_BITMASK_OPERATORS(LIEF::ELF::DYNAMIC_FLAGS_1) - #endif diff --git a/include/LIEF/ELF/enums.inc b/include/LIEF/ELF/enums.inc index 5104a379a8..8b13789179 100644 --- a/include/LIEF/ELF/enums.inc +++ b/include/LIEF/ELF/enums.inc @@ -1,979 +1 @@ -/** e_ident size and indices. */ -enum _LIEF_EN(IDENTITY) { - _LIEF_EI(EI_MAG0) = 0, /**< File identification index. */ - _LIEF_EI(EI_MAG1) = 1, /**< File identification index. */ - _LIEF_EI(EI_MAG2) = 2, /**< File identification index. */ - _LIEF_EI(EI_MAG3) = 3, /**< File identification index. */ - _LIEF_EI(EI_CLASS) = 4, /**< File class. */ - _LIEF_EI(EI_DATA) = 5, /**< Data encoding. */ - _LIEF_EI(EI_VERSION) = 6, /**< File version. */ - _LIEF_EI(EI_OSABI) = 7, /**< OS/ABI identification. */ - _LIEF_EI(EI_ABIVERSION) = 8, /**< ABI version. */ - _LIEF_EI(EI_PAD) = 9, /**< Start of padding bytes. */ - _LIEF_EI(EI_NIDENT) = 16 /**< Number of bytes in e_ident. */ -}; - - -/** Enum associated with *e_type* */ -enum _LIEF_EN(E_TYPE) { - _LIEF_EI(ET_NONE) = 0, /**< No file type */ - _LIEF_EI(ET_REL) = 1, /**< Relocatable file */ - _LIEF_EI(ET_EXEC) = 2, /**< Executable file */ - _LIEF_EI(ET_DYN) = 3, /**< Shared object file */ - _LIEF_EI(ET_CORE) = 4, /**< Core file */ - _LIEF_EI(ET_LOPROC) = 0xff00, /**< Beginning of processor-specific codes */ - _LIEF_EI(ET_HIPROC) = 0xffff /**< Processor-specific */ -}; - - -/** Versioning */ -enum _LIEF_EN(VERSION) { - _LIEF_EI(EV_NONE) = 0, - _LIEF_EI(EV_CURRENT) = 1 /**< Default value */ -}; - - -/** - * @brief Machine architectures - * See current registered ELF machine architectures at: - * http://www.sco.com/developers/gabi/latest/ch4.eheader.html - */ -enum _LIEF_EN(ARCH) { - _LIEF_EI(EM_NONE) = 0, /**< No machine */ - _LIEF_EI(EM_M32) = 1, /**< AT&T WE 32100 */ - _LIEF_EI(EM_SPARC) = 2, /**< SPARC */ - _LIEF_EI(EM_386) = 3, /**< Intel 386 */ - _LIEF_EI(EM_68K) = 4, /**< Motorola 68000 */ - _LIEF_EI(EM_88K) = 5, /**< Motorola 88000 */ - _LIEF_EI(EM_IAMCU) = 6, /**< Intel MCU */ - _LIEF_EI(EM_860) = 7, /**< Intel 80860 */ - _LIEF_EI(EM_MIPS) = 8, /**< MIPS R3000 */ - _LIEF_EI(EM_S370) = 9, /**< IBM System/370 */ - _LIEF_EI(EM_MIPS_RS3_LE) = 10, /**< MIPS RS3000 Little-endian */ - _LIEF_EI(EM_PARISC) = 15, /**< Hewlett-Packard PA-RISC */ - _LIEF_EI(EM_VPP500) = 17, /**< Fujitsu VPP500 */ - _LIEF_EI(EM_SPARC32PLUS) = 18, /**< Enhanced instruction set SPARC */ - _LIEF_EI(EM_960) = 19, /**< Intel 80960 */ - _LIEF_EI(EM_PPC) = 20, /**< PowerPC */ - _LIEF_EI(EM_PPC64) = 21, /**< PowerPC64 */ - _LIEF_EI(EM_S390) = 22, /**< IBM System/390 */ - _LIEF_EI(EM_SPU) = 23, /**< IBM SPU/SPC */ - _LIEF_EI(EM_V800) = 36, /**< NEC V800 */ - _LIEF_EI(EM_FR20) = 37, /**< Fujitsu FR20 */ - _LIEF_EI(EM_RH32) = 38, /**< TRW RH-32 */ - _LIEF_EI(EM_RCE) = 39, /**< Motorola RCE */ - _LIEF_EI(EM_ARM) = 40, /**< ARM */ - _LIEF_EI(EM_ALPHA) = 41, /**< DEC Alpha */ - _LIEF_EI(EM_SH) = 42, /**< Hitachi SH */ - _LIEF_EI(EM_SPARCV9) = 43, /**< SPARC V9 */ - _LIEF_EI(EM_TRICORE) = 44, /**< Siemens TriCore */ - _LIEF_EI(EM_ARC) = 45, /**< Argonaut RISC Core */ - _LIEF_EI(EM_H8_300) = 46, /**< Hitachi H8/300 */ - _LIEF_EI(EM_H8_300H) = 47, /**< Hitachi H8/300H */ - _LIEF_EI(EM_H8S) = 48, /**< Hitachi H8S */ - _LIEF_EI(EM_H8_500) = 49, /**< Hitachi H8/500 */ - _LIEF_EI(EM_IA_64) = 50, /**< Intel IA-64 processor architecture */ - _LIEF_EI(EM_MIPS_X) = 51, /**< Stanford MIPS-X */ - _LIEF_EI(EM_COLDFIRE) = 52, /**< Motorola ColdFire */ - _LIEF_EI(EM_68HC12) = 53, /**< Motorola M68HC12 */ - _LIEF_EI(EM_MMA) = 54, /**< Fujitsu MMA Multimedia Accelerator */ - _LIEF_EI(EM_PCP) = 55, /**< Siemens PCP */ - _LIEF_EI(EM_NCPU) = 56, /**< Sony nCPU embedded RISC processor */ - _LIEF_EI(EM_NDR1) = 57, /**< Denso NDR1 microprocessor */ - _LIEF_EI(EM_STARCORE) = 58, /**< Motorola Star*Core processor */ - _LIEF_EI(EM_ME16) = 59, /**< Toyota ME16 processor */ - _LIEF_EI(EM_ST100) = 60, /**< STMicroelectronics ST100 processor */ - _LIEF_EI(EM_TINYJ) = 61, /**< Advanced Logic Corp. TinyJ embedded processor family */ - _LIEF_EI(EM_X86_64) = 62, /**< AMD x86-64 architecture */ - _LIEF_EI(EM_PDSP) = 63, /**< Sony DSP Processor */ - _LIEF_EI(EM_PDP10) = 64, /**< Digital Equipment Corp. PDP-10 */ - _LIEF_EI(EM_PDP11) = 65, /**< Digital Equipment Corp. PDP-11 */ - _LIEF_EI(EM_FX66) = 66, /**< Siemens FX66 microcontroller */ - _LIEF_EI(EM_ST9PLUS) = 67, /**< STMicroelectronics ST9+ 8/16 bit microcontroller */ - _LIEF_EI(EM_ST7) = 68, /**< STMicroelectronics ST7 8-bit microcontroller */ - _LIEF_EI(EM_68HC16) = 69, /**< Motorola MC68HC16 Microcontroller */ - _LIEF_EI(EM_68HC11) = 70, /**< Motorola MC68HC11 Microcontroller */ - _LIEF_EI(EM_68HC08) = 71, /**< Motorola MC68HC08 Microcontroller */ - _LIEF_EI(EM_68HC05) = 72, /**< Motorola MC68HC05 Microcontroller */ - _LIEF_EI(EM_SVX) = 73, /**< Silicon Graphics SVx */ - _LIEF_EI(EM_ST19) = 74, /**< STMicroelectronics ST19 8-bit microcontroller */ - _LIEF_EI(EM_VAX) = 75, /**< Digital VAX */ - _LIEF_EI(EM_CRIS) = 76, /**< Axis Communications 32-bit embedded processor */ - _LIEF_EI(EM_JAVELIN) = 77, /**< Infineon Technologies 32-bit embedded processor */ - _LIEF_EI(EM_FIREPATH) = 78, /**< Element 14 64-bit DSP Processor */ - _LIEF_EI(EM_ZSP) = 79, /**< LSI Logic 16-bit DSP Processor */ - _LIEF_EI(EM_MMIX) = 80, /**< Donald Knuth's educational 64-bit processor */ - _LIEF_EI(EM_HUANY) = 81, /**< Harvard University machine-independent object files */ - _LIEF_EI(EM_PRISM) = 82, /**< SiTera Prism */ - _LIEF_EI(EM_AVR) = 83, /**< Atmel AVR 8-bit microcontroller */ - _LIEF_EI(EM_FR30) = 84, /**< Fujitsu FR30 */ - _LIEF_EI(EM_D10V) = 85, /**< Mitsubishi D10V */ - _LIEF_EI(EM_D30V) = 86, /**< Mitsubishi D30V */ - _LIEF_EI(EM_V850) = 87, /**< NEC v850 */ - _LIEF_EI(EM_M32R) = 88, /**< Mitsubishi M32R */ - _LIEF_EI(EM_MN10300) = 89, /**< Matsushita MN10300 */ - _LIEF_EI(EM_MN10200) = 90, /**< Matsushita MN10200 */ - _LIEF_EI(EM_PJ) = 91, /**< picoJava */ - _LIEF_EI(EM_OPENRISC) = 92, /**< OpenRISC 32-bit embedded processor */ - _LIEF_EI(EM_ARC_COMPACT) = 93, /**< ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5) */ - _LIEF_EI(EM_XTENSA) = 94, /**< Tensilica Xtensa Architecture */ - _LIEF_EI(EM_VIDEOCORE) = 95, /**< Alphamosaic VideoCore processor */ - _LIEF_EI(EM_TMM_GPP) = 96, /**< Thompson Multimedia General Purpose Processor */ - _LIEF_EI(EM_NS32K) = 97, /**< National Semiconductor 32000 series */ - _LIEF_EI(EM_TPC) = 98, /**< Tenor Network TPC processor */ - _LIEF_EI(EM_SNP1K) = 99, /**< Trebia SNP 1000 processor */ - _LIEF_EI(EM_ST200) = 100, /**< STMicroelectronics (www.st.com) ST200 */ - _LIEF_EI(EM_IP2K) = 101, /**< Ubicom IP2xxx microcontroller family */ - _LIEF_EI(EM_MAX) = 102, /**< MAX Processor */ - _LIEF_EI(EM_CR) = 103, /**< National Semiconductor CompactRISC microprocessor */ - _LIEF_EI(EM_F2MC16) = 104, /**< Fujitsu F2MC16 */ - _LIEF_EI(EM_MSP430) = 105, /**< Texas Instruments embedded microcontroller msp430 */ - _LIEF_EI(EM_BLACKFIN) = 106, /**< Analog Devices Blackfin (DSP) processor */ - _LIEF_EI(EM_SE_C33) = 107, /**< S1C33 Family of Seiko Epson processors */ - _LIEF_EI(EM_SEP) = 108, /**< Sharp embedded microprocessor */ - _LIEF_EI(EM_ARCA) = 109, /**< Arca RISC Microprocessor */ - _LIEF_EI(EM_UNICORE) = 110, /**< Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */ - _LIEF_EI(EM_EXCESS) = 111, /**< eXcess: 16/32/64-bit configurable embedded CPU */ - _LIEF_EI(EM_DXP) = 112, /**< Icera Semiconductor Inc. Deep Execution Processor */ - _LIEF_EI(EM_ALTERA_NIOS2) = 113, /**< Altera Nios II soft-core processor */ - _LIEF_EI(EM_CRX) = 114, /**< National Semiconductor CompactRISC CRX */ - _LIEF_EI(EM_XGATE) = 115, /**< Motorola XGATE embedded processor */ - _LIEF_EI(EM_C166) = 116, /**< Infineon C16x/XC16x processor */ - _LIEF_EI(EM_M16C) = 117, /**< Renesas M16C series microprocessors */ - _LIEF_EI(EM_DSPIC30F) = 118, /**< Microchip Technology dsPIC30F Digital Signal */ - /* Controller */ - _LIEF_EI(EM_CE) = 119, /**< Freescale Communication Engine RISC core */ - _LIEF_EI(EM_M32C) = 120, /**< Renesas M32C series microprocessors */ - _LIEF_EI(EM_TSK3000) = 131, /**< Altium TSK3000 core */ - _LIEF_EI(EM_RS08) = 132, /**< Freescale RS08 embedded processor */ - _LIEF_EI(EM_SHARC) = 133, /**< Analog Devices SHARC family of 32-bit DSP */ - /* processors */ - _LIEF_EI(EM_ECOG2) = 134, /**< Cyan Technology eCOG2 microprocessor */ - _LIEF_EI(EM_SCORE7) = 135, /**< Sunplus S+core7 RISC processor */ - _LIEF_EI(EM_DSP24) = 136, /**< New Japan Radio (NJR) 24-bit DSP Processor */ - _LIEF_EI(EM_VIDEOCORE3) = 137, /**< Broadcom VideoCore III processor */ - _LIEF_EI(EM_LATTICEMICO32) = 138, /**< RISC processor for Lattice FPGA architecture */ - _LIEF_EI(EM_SE_C17) = 139, /**< Seiko Epson C17 family */ - _LIEF_EI(EM_TI_C6000) = 140, /**< The Texas Instruments TMS320C6000 DSP family */ - _LIEF_EI(EM_TI_C2000) = 141, /**< The Texas Instruments TMS320C2000 DSP family */ - _LIEF_EI(EM_TI_C5500) = 142, /**< The Texas Instruments TMS320C55x DSP family */ - _LIEF_EI(EM_MMDSP_PLUS) = 160, /**< STMicroelectronics 64bit VLIW Data Signal Processor */ - _LIEF_EI(EM_CYPRESS_M8C) = 161, /**< Cypress M8C microprocessor */ - _LIEF_EI(EM_R32C) = 162, /**< Renesas R32C series microprocessors */ - _LIEF_EI(EM_TRIMEDIA) = 163, /**< NXP Semiconductors TriMedia architecture family */ - _LIEF_EI(EM_HEXAGON) = 164, /**< Qualcomm Hexagon processor */ - _LIEF_EI(EM_8051) = 165, /**< Intel 8051 and variants */ - _LIEF_EI(EM_STXP7X) = 166, /**< STMicroelectronics STxP7x family of configurable */ - /* and extensible RISC processors */ - _LIEF_EI(EM_NDS32) = 167, /* Andes Technology compact code size embedded RISC */ - /* processor family */ - _LIEF_EI(EM_ECOG1) = 168, /**< Cyan Technology eCOG1X family */ - _LIEF_EI(EM_ECOG1X) = 168, /**< Cyan Technology eCOG1X family */ - _LIEF_EI(EM_MAXQ30) = 169, /**< Dallas Semiconductor MAXQ30 Core Micro-controllers */ - _LIEF_EI(EM_XIMO16) = 170, /**< New Japan Radio (NJR) 16-bit DSP Processor */ - _LIEF_EI(EM_MANIK) = 171, /**< M2000 Reconfigurable RISC Microprocessor */ - _LIEF_EI(EM_CRAYNV2) = 172, /**< Cray Inc. NV2 vector architecture */ - _LIEF_EI(EM_RX) = 173, /**< Renesas RX family */ - _LIEF_EI(EM_METAG) = 174, /**< Imagination Technologies META processor */ - /* architecture */ - _LIEF_EI(EM_MCST_ELBRUS) = 175, /**< MCST Elbrus general purpose hardware architecture */ - _LIEF_EI(EM_ECOG16) = 176, /**< Cyan Technology eCOG16 family */ - _LIEF_EI(EM_CR16) = 177, /**< National Semiconductor CompactRISC CR16 16-bit */ - /* microprocessor */ - _LIEF_EI(EM_ETPU) = 178, /**< Freescale Extended Time Processing Unit */ - _LIEF_EI(EM_SLE9X) = 179, /**< Infineon Technologies SLE9X core */ - _LIEF_EI(EM_L10M) = 180, /**< Intel L10M */ - _LIEF_EI(EM_K10M) = 181, /**< Intel K10M */ - _LIEF_EI(EM_AARCH64) = 183, /**< ARM AArch64 */ - _LIEF_EI(EM_AVR32) = 185, /**< Atmel Corporation 32-bit microprocessor family */ - _LIEF_EI(EM_STM8) = 186, /**< STMicroeletronics STM8 8-bit microcontroller */ - _LIEF_EI(EM_TILE64) = 187, /**< Tilera TILE64 multicore architecture family */ - _LIEF_EI(EM_TILEPRO) = 188, /**< Tilera TILEPro multicore architecture family */ - _LIEF_EI(EM_CUDA) = 190, /**< NVIDIA CUDA architecture */ - _LIEF_EI(EM_TILEGX) = 191, /**< Tilera TILE-Gx multicore architecture family */ - _LIEF_EI(EM_CLOUDSHIELD) = 192, /**< CloudShield architecture family */ - _LIEF_EI(EM_COREA_1ST) = 193, /**< KIPO-KAIST Core-A 1st generation processor family */ - _LIEF_EI(EM_COREA_2ND) = 194, /**< KIPO-KAIST Core-A 2nd generation processor family */ - _LIEF_EI(EM_ARC_COMPACT2) = 195, /**< Synopsys ARCompact V2 */ - _LIEF_EI(EM_OPEN8) = 196, /**< Open8 8-bit RISC soft processor core */ - _LIEF_EI(EM_RL78) = 197, /**< Renesas RL78 family */ - _LIEF_EI(EM_VIDEOCORE5) = 198, /**< Broadcom VideoCore V processor */ - _LIEF_EI(EM_78KOR) = 199, /**< Renesas 78KOR family */ - _LIEF_EI(EM_56800EX) = 200, /**< Freescale 56800EX Digital Signal Controller (DSC) */ - _LIEF_EI(EM_BA1) = 201, /**< Beyond BA1 CPU architecture */ - _LIEF_EI(EM_BA2) = 202, /**< Beyond BA2 CPU architecture */ - _LIEF_EI(EM_XCORE) = 203, /**< XMOS xCORE processor family */ - _LIEF_EI(EM_MCHP_PIC) = 204, /**< Microchip 8-bit PIC(r) family */ - _LIEF_EI(EM_INTEL205) = 205, /**< Reserved by Intel */ - _LIEF_EI(EM_INTEL206) = 206, /**< Reserved by Intel */ - _LIEF_EI(EM_INTEL207) = 207, /**< Reserved by Intel */ - _LIEF_EI(EM_INTEL208) = 208, /**< Reserved by Intel */ - _LIEF_EI(EM_INTEL209) = 209, /**< Reserved by Intel */ - _LIEF_EI(EM_KM32) = 210, /**< KM211 KM32 32-bit processor */ - _LIEF_EI(EM_KMX32) = 211, /**< KM211 KMX32 32-bit processor */ - _LIEF_EI(EM_KMX16) = 212, /**< KM211 KMX16 16-bit processor */ - _LIEF_EI(EM_KMX8) = 213, /**< KM211 KMX8 8-bit processor */ - _LIEF_EI(EM_KVARC) = 214, /**< KM211 KVARC processor */ - _LIEF_EI(EM_CDP) = 215, /**< Paneve CDP architecture family */ - _LIEF_EI(EM_COGE) = 216, /**< Cognitive Smart Memory Processor */ - _LIEF_EI(EM_COOL) = 217, /**< iCelero CoolEngine */ - _LIEF_EI(EM_NORC) = 218, /**< Nanoradio Optimized RISC */ - _LIEF_EI(EM_CSR_KALIMBA) = 219, /**< CSR Kalimba architecture family */ - _LIEF_EI(EM_AMDGPU) = 224, /**< AMD GPU architecture */ - _LIEF_EI(EM_RISCV) = 243, /**< RISC-V */ - _LIEF_EI(EM_BPF) = 247, /**< eBPF Filter */ - _LIEF_EI(EM_LOONGARCH) = 258 /**< LoongArch */ -}; - - -/** Object file classes. */ -enum _LIEF_EN(ELF_CLASS) { - _LIEF_EI(ELFCLASSNONE) = 0, /**< Unknown */ - _LIEF_EI(ELFCLASS32) = 1, /**< 32-bit object file */ - _LIEF_EI(ELFCLASS64) = 2 /**< 64-bit object file */ -}; - -/** Object file byte orderings. */ -enum _LIEF_EN(ELF_DATA) { - _LIEF_EI(ELFDATANONE) = 0, /**< Invalid data encoding. */ - _LIEF_EI(ELFDATA2LSB) = 1, /**< Little-endian object file */ - _LIEF_EI(ELFDATA2MSB) = 2 /**< Big-endian object file */ -}; - -/** OS ABI identification. */ -enum _LIEF_EN(OS_ABI) { - _LIEF_EI(ELFOSABI_SYSTEMV) = 0, /**< UNIX System V ABI */ - _LIEF_EI(ELFOSABI_HPUX) = 1, /**< HP-UX operating system */ - _LIEF_EI(ELFOSABI_NETBSD) = 2, /**< NetBSD */ - _LIEF_EI(ELFOSABI_GNU) = 3, /**< GNU/Linux */ - _LIEF_EI(ELFOSABI_LINUX) = 3, /**< Historical alias for ELFOSABI_GNU. */ - _LIEF_EI(ELFOSABI_HURD) = 4, /**< GNU/Hurd */ - _LIEF_EI(ELFOSABI_SOLARIS) = 6, /**< Solaris */ - _LIEF_EI(ELFOSABI_AIX) = 7, /**< AIX */ - _LIEF_EI(ELFOSABI_IRIX) = 8, /**< IRIX */ - _LIEF_EI(ELFOSABI_FREEBSD) = 9, /**< FreeBSD */ - _LIEF_EI(ELFOSABI_TRU64) = 10, /**< TRU64 UNIX */ - _LIEF_EI(ELFOSABI_MODESTO) = 11, /**< Novell Modesto */ - _LIEF_EI(ELFOSABI_OPENBSD) = 12, /**< OpenBSD */ - _LIEF_EI(ELFOSABI_OPENVMS) = 13, /**< OpenVMS */ - _LIEF_EI(ELFOSABI_NSK) = 14, /**< Hewlett-Packard Non-Stop Kernel */ - _LIEF_EI(ELFOSABI_AROS) = 15, /**< AROS */ - _LIEF_EI(ELFOSABI_FENIXOS) = 16, /**< FenixOS */ - _LIEF_EI(ELFOSABI_CLOUDABI) = 17, /**< Nuxi CloudABI */ - _LIEF_EI(ELFOSABI_C6000_ELFABI) = 64, /**< Bare-metal TMS320C6000 */ - _LIEF_EI(ELFOSABI_AMDGPU_HSA) = 64, /**< AMD HSA runtime */ - _LIEF_EI(ELFOSABI_C6000_LINUX) = 65, /**< Linux TMS320C6000 */ - _LIEF_EI(ELFOSABI_ARM) = 97, /**< ARM */ - _LIEF_EI(ELFOSABI_STANDALONE) = 255 /**< Standalone (embedded) application */ -}; - -/* ELF Relocations */ - -#define ELF_RELOC(name, value) _LIEF_EI(name) = value, - -/** x86_64 relocations. */ -enum _LIEF_EN(RELOC_x86_64) { - #include "LIEF/ELF/Relocations/x86_64.def" -}; - -/** i386 relocations. */ -enum RELOC_i386 { - #include "LIEF/ELF/Relocations/i386.def" -}; - -/* ELF Relocation types for PPC32 */ -enum _LIEF_EN(RELOC_POWERPC32) { - #include "LIEF/ELF/Relocations/PowerPC.def" -}; - -/* ELF Relocation types for PPC64 */ -enum _LIEF_EN(RELOC_POWERPC64) { - #include "LIEF/ELF/Relocations/PowerPC64.def" -}; - -/* ELF Relocation types for AArch64 */ -enum _LIEF_EN(RELOC_AARCH64) { - #include "LIEF/ELF/Relocations/AArch64.def" -}; - -/* ELF Relocation types for ARM */ -enum _LIEF_EN(RELOC_ARM) { - #include "LIEF/ELF/Relocations/ARM.def" -}; - -/* ELF Relocation types for Mips */ -enum _LIEF_EN(RELOC_MIPS) { - #include "LIEF/ELF/Relocations/Mips.def" -}; - -/* ELF Relocation types for Hexagon */ -enum _LIEF_EN(RELOC_HEXAGON) { - #include "LIEF/ELF/Relocations/Hexagon.def" -}; - -/* ELF Relocation types for S390/zSeries */ -enum _LIEF_EN(RELOC_SYSTEMZ) { - #include "LIEF/ELF/Relocations/SystemZ.def" -}; - -/* ELF Relocation type for Sparc. */ -enum _LIEF_EN(RELOC_SPARC) { - #include "LIEF/ELF/Relocations/Sparc.def" -}; - -/* ELF Relocation types for LoongArch. */ -enum _LIEF_EN(RELOC_LOONGARCH) { - #include "LIEF/ELF/Relocations/LoongArch.def" -}; - -#undef ELF_RELOC - -/* Specific e_flags for PPC64 */ -enum _LIEF_EN(PPC64_EFLAGS) { - /* e_flags bits specifying ABI: */ - /* 1 for original ABI using function descriptors, */ - /* 2 for revised ABI without function descriptors, */ - /* 0 for unspecified or not using any features affected by the differences. */ - _LIEF_EI(EF_PPC64_ABI) = 3 -}; - -/* ARM Specific e_flags */ -enum _LIEF_EN(ARM_EFLAGS) { - _LIEF_EI(EF_ARM_SOFT_FLOAT) = 0x00000200U, - _LIEF_EI(EF_ARM_VFP_FLOAT) = 0x00000400U, - _LIEF_EI(EF_ARM_EABI_UNKNOWN) = 0x00000000U, - _LIEF_EI(EF_ARM_EABI_VER1) = 0x01000000U, - _LIEF_EI(EF_ARM_EABI_VER2) = 0x02000000U, - _LIEF_EI(EF_ARM_EABI_VER3) = 0x03000000U, - _LIEF_EI(EF_ARM_EABI_VER4) = 0x04000000U, - _LIEF_EI(EF_ARM_EABI_VER5) = 0x05000000U, - _LIEF_EI(EF_ARM_EABIMASK) = 0xFF000000U -}; - -/* Mips Specific e_flags */ -enum _LIEF_EN(MIPS_EFLAGS) { - _LIEF_EI(EF_MIPS_NOREORDER) = 0x00000001, /* Don't reorder instructions */ - _LIEF_EI(EF_MIPS_PIC) = 0x00000002, /* Position independent code */ - _LIEF_EI(EF_MIPS_CPIC) = 0x00000004, /* Call object with Position independent code */ - _LIEF_EI(EF_MIPS_ABI2) = 0x00000020, /* File uses N32 ABI */ - _LIEF_EI(EF_MIPS_32BITMODE) = 0x00000100, /* Code compiled for a 64-bit machine */ - /* in 32-bit mode */ - _LIEF_EI(EF_MIPS_FP64) = 0x00000200, /* Code compiled for a 32-bit machine */ - /* but uses 64-bit FP registers */ - _LIEF_EI(EF_MIPS_NAN2008) = 0x00000400, /* Uses IEE 754-2008 NaN encoding */ - - /* ABI flags */ - _LIEF_EI(EF_MIPS_ABI_O32) = 0x00001000, /* This file follows the first MIPS 32 bit ABI */ - _LIEF_EI(EF_MIPS_ABI_O64) = 0x00002000, /* O32 ABI extended for 64-bit architecture. */ - _LIEF_EI(EF_MIPS_ABI_EABI32) = 0x00003000, /* EABI in 32 bit mode. */ - _LIEF_EI(EF_MIPS_ABI_EABI64) = 0x00004000, /* EABI in 64 bit mode. */ - _LIEF_EI(EF_MIPS_ABI) = 0x0000f000, /* Mask for selecting EF_MIPS_ABI_ variant. */ - - /* MIPS machine variant */ - _LIEF_EI(EF_MIPS_MACH_3900) = 0x00810000, /* Toshiba R3900 */ - _LIEF_EI(EF_MIPS_MACH_4010) = 0x00820000, /* LSI R4010 */ - _LIEF_EI(EF_MIPS_MACH_4100) = 0x00830000, /* NEC VR4100 */ - _LIEF_EI(EF_MIPS_MACH_4650) = 0x00850000, /* MIPS R4650 */ - _LIEF_EI(EF_MIPS_MACH_4120) = 0x00870000, /* NEC VR4120 */ - _LIEF_EI(EF_MIPS_MACH_4111) = 0x00880000, /* NEC VR4111/VR4181 */ - _LIEF_EI(EF_MIPS_MACH_SB1) = 0x008a0000, /* Broadcom SB-1 */ - _LIEF_EI(EF_MIPS_MACH_OCTEON) = 0x008b0000, /* Cavium Networks Octeon */ - _LIEF_EI(EF_MIPS_MACH_XLR) = 0x008c0000, /* RMI Xlr */ - _LIEF_EI(EF_MIPS_MACH_OCTEON2) = 0x008d0000, /* Cavium Networks Octeon2 */ - _LIEF_EI(EF_MIPS_MACH_OCTEON3) = 0x008e0000, /* Cavium Networks Octeon3 */ - _LIEF_EI(EF_MIPS_MACH_5400) = 0x00910000, /* NEC VR5400 */ - _LIEF_EI(EF_MIPS_MACH_5900) = 0x00920000, /* MIPS R5900 */ - _LIEF_EI(EF_MIPS_MACH_5500) = 0x00980000, /* NEC VR5500 */ - _LIEF_EI(EF_MIPS_MACH_9000) = 0x00990000, /* Unknown */ - _LIEF_EI(EF_MIPS_MACH_LS2E) = 0x00a00000, /* ST Microelectronics Loongson 2E */ - _LIEF_EI(EF_MIPS_MACH_LS2F) = 0x00a10000, /* ST Microelectronics Loongson 2F */ - _LIEF_EI(EF_MIPS_MACH_LS3A) = 0x00a20000, /* Loongson 3A */ - _LIEF_EI(EF_MIPS_MACH) = 0x00ff0000, /* EF_MIPS_MACH_xxx selection mask */ - - /* ARCH_ASE */ - _LIEF_EI(EF_MIPS_MICROMIPS) = 0x02000000, /* microMIPS */ - _LIEF_EI(EF_MIPS_ARCH_ASE_M16) = 0x04000000, /* Has Mips-16 ISA extensions */ - _LIEF_EI(EF_MIPS_ARCH_ASE_MDMX) = 0x08000000, /* Has MDMX multimedia extensions */ - _LIEF_EI(EF_MIPS_ARCH_ASE) = 0x0f000000, /* Mask for EF_MIPS_ARCH_ASE_xxx flags */ - - /* ARCH */ - _LIEF_EI(EF_MIPS_ARCH_1) = 0x00000000, /* MIPS1 instruction set */ - _LIEF_EI(EF_MIPS_ARCH_2) = 0x10000000, /* MIPS2 instruction set */ - _LIEF_EI(EF_MIPS_ARCH_3) = 0x20000000, /* MIPS3 instruction set */ - _LIEF_EI(EF_MIPS_ARCH_4) = 0x30000000, /* MIPS4 instruction set */ - _LIEF_EI(EF_MIPS_ARCH_5) = 0x40000000, /* MIPS5 instruction set */ - _LIEF_EI(EF_MIPS_ARCH_32) = 0x50000000, /* MIPS32 instruction set per linux not elf.h */ - _LIEF_EI(EF_MIPS_ARCH_64) = 0x60000000, /* MIPS64 instruction set per linux not elf.h */ - _LIEF_EI(EF_MIPS_ARCH_32R2) = 0x70000000, /* mips32r2, mips32r3, mips32r5 */ - _LIEF_EI(EF_MIPS_ARCH_64R2) = 0x80000000, /* mips64r2, mips64r3, mips64r5 */ - _LIEF_EI(EF_MIPS_ARCH_32R6) = 0x90000000, /* mips32r6 */ - _LIEF_EI(EF_MIPS_ARCH_64R6) = 0xa0000000, /* mips64r6 */ - _LIEF_EI(EF_MIPS_ARCH) = 0xf0000000 /* Mask for applying EF_MIPS_ARCH_ variant */ -}; - -/* Hexagon Specific e_flags */ -/* Release 5 ABI */ -enum _LIEF_EN(HEXAGON_EFLAGS) { - /* Object processor version flags, bits[3:0] */ - _LIEF_EI(EF_HEXAGON_MACH_V2) = 0x00000001, /* Hexagon V2 */ - _LIEF_EI(EF_HEXAGON_MACH_V3) = 0x00000002, /* Hexagon V3 */ - _LIEF_EI(EF_HEXAGON_MACH_V4) = 0x00000003, /* Hexagon V4 */ - _LIEF_EI(EF_HEXAGON_MACH_V5) = 0x00000004, /* Hexagon V5 */ - - /* Highest ISA version flags */ - _LIEF_EI(EF_HEXAGON_ISA_MACH) = 0x00000000, /* Same as specified in bits[3:0] */ - /* of e_flags */ - _LIEF_EI(EF_HEXAGON_ISA_V2) = 0x00000010, /* Hexagon V2 ISA */ - _LIEF_EI(EF_HEXAGON_ISA_V3) = 0x00000020, /* Hexagon V3 ISA */ - _LIEF_EI(EF_HEXAGON_ISA_V4) = 0x00000030, /* Hexagon V4 ISA */ - _LIEF_EI(EF_HEXAGON_ISA_V5) = 0x00000040 /* Hexagon V5 ISA */ -}; - - -/* LoongArch Specific e_flags */ -enum _LIEF_EN(LOONGARCH_EFLAGS) { - _LIEF_EI(EF_LOONGARCH_ABI_SOFT_FLOAT) = 0x1, - _LIEF_EI(EF_LOONGARCH_ABI_SINGLE_FLOAT) = 0x2, - _LIEF_EI(EF_LOONGARCH_ABI_DOUBLE_FLOAT) = 0x3 -}; - -/** Special section indices. */ -enum _LIEF_EN(SYMBOL_SECTION_INDEX) { - _LIEF_EI(SHN_UNDEF) = 0, /**< Undefined, missing, irrelevant, or meaningless */ - _LIEF_EI(SHN_LORESERVE) = 0xff00, /**< Lowest reserved index */ - _LIEF_EI(SHN_LOPROC) = 0xff00, /**< Lowest processor-specific index */ - _LIEF_EI(SHN_HIPROC) = 0xff1f, /**< Highest processor-specific index */ - _LIEF_EI(SHN_LOOS) = 0xff20, /**< Lowest operating system-specific index */ - _LIEF_EI(SHN_HIOS) = 0xff3f, /**< Highest operating system-specific index */ - _LIEF_EI(SHN_ABS) = 0xfff1, /**< Symbol has absolute value; does not need relocation */ - _LIEF_EI(SHN_COMMON) = 0xfff2, /**< FORTRAN COMMON or C external global variables */ - _LIEF_EI(SHN_XINDEX) = 0xffff, /**< Mark that the index is >= SHN_LORESERVE */ - _LIEF_EI(SHN_HIRESERVE) = 0xffff /**< Highest reserved index */ -}; - -/** Section types. */ -enum _LIEF_EN(ELF_SECTION_TYPES) { - _LIEF_EI(SHT_NULL) = 0, /**< No associated section (inactive entry). */ - _LIEF_EI(SHT_PROGBITS) = 1, /**< Program-defined contents. */ - _LIEF_EI(SHT_SYMTAB) = 2, /**< Symbol table. */ - _LIEF_EI(SHT_STRTAB) = 3, /**< String table. */ - _LIEF_EI(SHT_RELA) = 4, /**< Relocation entries; explicit addends. */ - _LIEF_EI(SHT_HASH) = 5, /**< Symbol hash table. */ - _LIEF_EI(SHT_DYNAMIC) = 6, /**< Information for dynamic linking. */ - _LIEF_EI(SHT_NOTE) = 7, /**< Information about the file. */ - _LIEF_EI(SHT_NOBITS) = 8, /**< Data occupies no space in the file. */ - _LIEF_EI(SHT_REL) = 9, /**< Relocation entries; no explicit addends. */ - _LIEF_EI(SHT_SHLIB) = 10, /**< Reserved. */ - _LIEF_EI(SHT_DYNSYM) = 11, /**< Symbol table. */ - _LIEF_EI(SHT_INIT_ARRAY) = 14, /**< Pointers to initialization functions. */ - _LIEF_EI(SHT_FINI_ARRAY) = 15, /**< Pointers to termination functions. */ - _LIEF_EI(SHT_PREINIT_ARRAY) = 16, /**< Pointers to pre-init functions. */ - _LIEF_EI(SHT_GROUP) = 17, /**< Section group. */ - _LIEF_EI(SHT_SYMTAB_SHNDX) = 18, /**< Indices for SHN_XINDEX entries. */ - _LIEF_EI(SHT_LOOS) = 0x60000000, /**< Lowest operating system-specific type. */ - _LIEF_EI(SHT_ANDROID_REL) = 0x60000001, /**< Packed relocations (Android specific). */ - _LIEF_EI(SHT_ANDROID_RELA) = 0x60000002, /**< Packed relocations (Android specific). */ - _LIEF_EI(SHT_LLVM_ADDRSIG) = 0x6fff4c03, /**< This section is used to mark symbols as address-significant. */ - _LIEF_EI(SHT_RELR) = 0x6fffff00, /**< New relr relocations (Android specific). */ - _LIEF_EI(SHT_GNU_ATTRIBUTES) = 0x6ffffff5, /**< Object attributes. */ - _LIEF_EI(SHT_GNU_HASH) = 0x6ffffff6, /**< GNU-style hash table. */ - _LIEF_EI(SHT_GNU_verdef) = 0x6ffffffd, /**< GNU version definitions. */ - _LIEF_EI(SHT_GNU_verneed) = 0x6ffffffe, /**< GNU version references. */ - _LIEF_EI(SHT_GNU_versym) = 0x6fffffff, /**< GNU symbol versions table. */ - _LIEF_EI(SHT_HIOS) = 0x6fffffff, /**< Highest operating system-specific type. */ - _LIEF_EI(SHT_LOPROC) = 0x70000000, /**< Lowest processor arch-specific type. */ - _LIEF_EI(SHT_ARM_EXIDX) = 0x70000001U, /**< Exception Index table */ - _LIEF_EI(SHT_ARM_PREEMPTMAP) = 0x70000002U, /**< BPABI DLL dynamic linking pre-emption map */ - _LIEF_EI(SHT_ARM_ATTRIBUTES) = 0x70000003U, /**< Object file compatibility attributes */ - _LIEF_EI(SHT_ARM_DEBUGOVERLAY) = 0x70000004U, - _LIEF_EI(SHT_ARM_OVERLAYSECTION) = 0x70000005U, - _LIEF_EI(SHT_HEX_ORDERED) = 0x70000000, /**< Link editor is to sort the entries in */ - - /* this section based on their sizes */ - _LIEF_EI(SHT_X86_64_UNWIND) = 0x70000001, /**< Unwind information */ - _LIEF_EI(SHT_MIPS_REGINFO) = 0x70000006, /**< Register usage information */ - _LIEF_EI(SHT_MIPS_OPTIONS) = 0x7000000d, /**< General options */ - _LIEF_EI(SHT_MIPS_ABIFLAGS) = 0x7000002a, /**< ABI information. */ - - _LIEF_EI(SHT_HIPROC) = 0x7fffffff, /**< Highest processor arch-specific type. */ - _LIEF_EI(SHT_LOUSER) = 0x80000000, /**< Lowest type reserved for applications. */ - _LIEF_EI(SHT_HIUSER) = 0xffffffff /**< Highest type reserved for applications. */ -}; - - - -/** Section flags. */ -enum _LIEF_EN(ELF_SECTION_FLAGS) { - _LIEF_EI(SHF_NONE) = 0x0, - _LIEF_EI(SHF_WRITE) = 0x1, /**< Section data should be writable during execution. */ - _LIEF_EI(SHF_ALLOC) = 0x2, /**< Section occupies memory during program execution. */ - _LIEF_EI(SHF_EXECINSTR) = 0x4, /**< Section contains executable machine instructions. */ - _LIEF_EI(SHF_MERGE) = 0x10, /**< The data in this section may be merged. */ - _LIEF_EI(SHF_STRINGS) = 0x20, /**< The data in this section is null-terminated strings. */ - _LIEF_EI(SHF_INFO_LINK) = 0x40U, /**< A field in this section holds a section header table index. */ - _LIEF_EI(SHF_LINK_ORDER) = 0x80U, /**< Adds special ordering requirements for link editors. */ - _LIEF_EI(SHF_OS_NONCONFORMING) = 0x100U, /**< This section requires special OS-specific processing to avoid incorrect behavior */ - _LIEF_EI(SHF_GROUP) = 0x200U, /**< This section is a member of a section group. */ - _LIEF_EI(SHF_TLS) = 0x400U, /**< This section holds Thread-Local Storage. */ - _LIEF_EI(SHF_EXCLUDE) = 0x80000000U, /**< This section is excluded from the final executable or shared library. */ - /* Start of target-specific flags. */ - - /* XCORE_SHF_CP_SECTION - All sections with the "c" flag are grouped - * together by the linker to form the constant pool and the cp register is - * set to the start of the constant pool by the boot code. - */ - _LIEF_EI(XCORE_SHF_CP_SECTION) = 0x800U, - - /* XCORE_SHF_DP_SECTION - All sections with the "d" flag are grouped - * together by the linker to form the data section and the dp register is - * set to the start of the section by the boot code. - */ - _LIEF_EI(XCORE_SHF_DP_SECTION) = 0x1000U, - _LIEF_EI(SHF_MASKOS) = 0x0ff00000, - _LIEF_EI(SHF_MASKPROC) = 0xf0000000, /**< Bits indicating processor-specific flags. */ - - /* If an object file section does not have this flag set, then it may not hold - * more than 2GB and can be freely referred to in objects using smaller code - * models. Otherwise, only objects using larger code models can refer to them. - * For example, a medium code model object can refer to data in a section that - * sets this flag besides being able to refer to data in a section that does - * not set it; likewise, a small code model object can refer only to code in a - * section that does not set this flag. - */ - _LIEF_EI(SHF_X86_64_LARGE) = 0x10000000, - - /* All sections with the GPREL flag are grouped into a global data area - * for faster accesses. - */ - _LIEF_EI(SHF_HEX_GPREL) = 0x10000000, - - /* Section contains text/data which may be replicated in other sections. - * Linker must retain only one copy. - */ - _LIEF_EI(SHF_MIPS_NODUPES) = 0x01000000, - - _LIEF_EI(SHF_MIPS_NAMES) = 0x02000000, /**< Linker must generate implicit hidden weak names. */ - _LIEF_EI(SHF_MIPS_LOCAL) = 0x04000000, /**< Section data local to process. */ - _LIEF_EI(SHF_MIPS_NOSTRIP) = 0x08000000, /**< Do not strip this section. */ - _LIEF_EI(SHF_MIPS_GPREL) = 0x10000000, /**< Section must be part of global data area. */ - _LIEF_EI(SHF_MIPS_MERGE) = 0x20000000, /**< This section should be merged. */ - _LIEF_EI(SHF_MIPS_ADDR) = 0x40000000, /**< Address size to be inferred from section entry size. */ - _LIEF_EI(SHF_MIPS_STRING) = 0x80000000 /**< Section data is string data by default. */ -}; - - -/** Symbol bindings. */ -enum _LIEF_EN(SYMBOL_BINDINGS) { - _LIEF_EI(STB_LOCAL) = 0, /**< Local symbol, not visible outside obj file containing def */ - _LIEF_EI(STB_GLOBAL) = 1, /**< Global symbol, visible to all object files being combined */ - _LIEF_EI(STB_WEAK) = 2, /**< Weak symbol, like global but lower-precedence */ - _LIEF_EI(STB_GNU_UNIQUE) = 10, - _LIEF_EI(STB_LOOS) = 10, /**< Lowest operating system-specific binding type */ - _LIEF_EI(STB_HIOS) = 12, /**< Highest operating system-specific binding type */ - _LIEF_EI(STB_LOPROC) = 13, /**< Lowest processor-specific binding type */ - _LIEF_EI(STB_HIPROC) = 15 /**< Highest processor-specific binding type */ -}; - - -/* Symbol types. */ -enum _LIEF_EN(ELF_SYMBOL_TYPES) { - _LIEF_EI(STT_NOTYPE) = 0, /* Symbol's type is not specified */ - _LIEF_EI(STT_OBJECT) = 1, /* Symbol is a data object (variable, array, etc.) */ - _LIEF_EI(STT_FUNC) = 2, /* Symbol is executable code (function, etc.) */ - _LIEF_EI(STT_SECTION) = 3, /* Symbol refers to a section */ - _LIEF_EI(STT_FILE) = 4, /* Local, absolute symbol that refers to a file */ - _LIEF_EI(STT_COMMON) = 5, /* An uninitialized common block */ - _LIEF_EI(STT_TLS) = 6, /* Thread local data object */ - _LIEF_EI(STT_GNU_IFUNC) = 10, /* GNU indirect function */ - _LIEF_EI(STT_LOOS) = 10, /* Lowest operating system-specific symbol type */ - _LIEF_EI(STT_HIOS) = 12, /* Highest operating system-specific symbol type */ - _LIEF_EI(STT_LOPROC) = 13, /* Lowest processor-specific symbol type */ - _LIEF_EI(STT_HIPROC) = 15 /* Highest processor-specific symbol type */ -}; - -enum _LIEF_EN(ELF_SYMBOL_VISIBILITY) { - _LIEF_EI(STV_DEFAULT) = 0, /* Visibility is specified by binding type */ - _LIEF_EI(STV_INTERNAL) = 1, /* Defined by processor supplements */ - _LIEF_EI(STV_HIDDEN) = 2, /* Not visible to other components */ - _LIEF_EI(STV_PROTECTED) = 3 /* Visible in other components but not preemptable */ -}; - - -/** @brief Segment types. */ -enum _LIEF_EN(SEGMENT_TYPES) { - _LIEF_EI(PT_NULL) = 0, /**< Unused segment. */ - _LIEF_EI(PT_LOAD) = 1, /**< Loadable segment. */ - _LIEF_EI(PT_DYNAMIC) = 2, /**< Dynamic linking information. */ - _LIEF_EI(PT_INTERP) = 3, /**< Interpreter pathname. */ - _LIEF_EI(PT_NOTE) = 4, /**< Auxiliary information. */ - _LIEF_EI(PT_SHLIB) = 5, /**< Reserved. */ - _LIEF_EI(PT_PHDR) = 6, /**< The program header table itself. */ - _LIEF_EI(PT_TLS) = 7, /**< The thread-local storage template. */ - _LIEF_EI(PT_LOOS) = 0x60000000, /**< Lowest operating system-specific pt entry type. */ - _LIEF_EI(PT_HIOS) = 0x6fffffff, /**< Highest operating system-specific pt entry type. */ - _LIEF_EI(PT_LOPROC) = 0x70000000, /**< Lowest processor-specific program hdr entry type. */ - _LIEF_EI(PT_HIPROC) = 0x7fffffff, /**< Highest processor-specific program hdr entry type. */ - - /* x86-64 program header types. */ - /* These all contain stack unwind tables. */ - _LIEF_EI(PT_GNU_EH_FRAME) = 0x6474e550, - _LIEF_EI(PT_SUNW_EH_FRAME) = 0x6474e550, - _LIEF_EI(PT_SUNW_UNWIND) = 0x6464e550, - - _LIEF_EI(PT_GNU_STACK) = 0x6474e551, /**< Indicates stack executability. */ - _LIEF_EI(PT_GNU_PROPERTY) = 0x6474e553, /**< GNU property */ - _LIEF_EI(PT_GNU_RELRO) = 0x6474e552, /**< Read-only after relocation. */ - - /* ARM program header types. */ - _LIEF_EI(PT_ARM_ARCHEXT) = 0x70000000, /**< Platform architecture compatibility info */ - - /* These all contain stack unwind tables. */ - _LIEF_EI(PT_ARM_EXIDX) = 0x70000001, - _LIEF_EI(PT_ARM_UNWIND) = 0x70000001, - - /* MIPS program header types. */ - _LIEF_EI(PT_MIPS_REGINFO) = 0x70000000, /**< Register usage information. */ - _LIEF_EI(PT_MIPS_RTPROC) = 0x70000001, /**< Runtime procedure table. */ - _LIEF_EI(PT_MIPS_OPTIONS) = 0x70000002, /**< Options segment. */ - _LIEF_EI(PT_MIPS_ABIFLAGS) = 0x70000003 /**< Abiflags segment. */ -}; - - -/** Segment flags. */ -enum _LIEF_EN(ELF_SEGMENT_FLAGS) { - _LIEF_EI(PF_NONE) = 0, - _LIEF_EI(PF_X) = 1, /**< Execute */ - _LIEF_EI(PF_W) = 2, /**< Write */ - _LIEF_EI(PF_R) = 4, /**< Read */ - _LIEF_EI(PF_MASKOS) = 0x0ff00000,/**< Bits for operating system-specific semantics. */ - _LIEF_EI(PF_MASKPROC) = 0xf0000000 /**< Bits for processor-specific semantics. */ -}; - - -/** Dynamic table entry tags. */ -enum _LIEF_EN(DYNAMIC_TAGS) { - _LIEF_EI(DT_NULL) = 0, /**< Marks end of dynamic array. */ - _LIEF_EI(DT_NEEDED) = 1, /**< String table offset of needed library. */ - _LIEF_EI(DT_PLTRELSZ) = 2, /**< Size of relocation entries in PLT. */ - _LIEF_EI(DT_PLTGOT) = 3, /**< Address associated with linkage table. */ - _LIEF_EI(DT_HASH) = 4, /**< Address of symbolic hash table. */ - _LIEF_EI(DT_STRTAB) = 5, /**< Address of dynamic string table. */ - _LIEF_EI(DT_SYMTAB) = 6, /**< Address of dynamic symbol table. */ - _LIEF_EI(DT_RELA) = 7, /**< Address of relocation table (Rela entries). */ - _LIEF_EI(DT_RELASZ) = 8, /**< Size of Rela relocation table. */ - _LIEF_EI(DT_RELAENT) = 9, /**< Size of a Rela relocation entry. */ - _LIEF_EI(DT_STRSZ) = 10, /**< Total size of the string table. */ - _LIEF_EI(DT_SYMENT) = 11, /**< Size of a symbol table entry. */ - _LIEF_EI(DT_INIT) = 12, /**< Address of initialization function. */ - _LIEF_EI(DT_FINI) = 13, /**< Address of termination function. */ - _LIEF_EI(DT_SONAME) = 14, /**< String table offset of a shared objects name. */ - _LIEF_EI(DT_RPATH) = 15, /**< String table offset of library search path. */ - _LIEF_EI(DT_SYMBOLIC) = 16, /**< Changes symbol resolution algorithm. */ - _LIEF_EI(DT_REL) = 17, /**< Address of relocation table (Rel entries). */ - _LIEF_EI(DT_RELSZ) = 18, /**< Size of Rel relocation table. */ - _LIEF_EI(DT_RELENT) = 19, /**< Size of a Rel relocation entry. */ - _LIEF_EI(DT_PLTREL) = 20, /**< Type of relocation entry used for linking. */ - _LIEF_EI(DT_DEBUG) = 21, /**< Reserved for debugger. */ - _LIEF_EI(DT_TEXTREL) = 22, /**< Relocations exist for non-writable segments. */ - _LIEF_EI(DT_JMPREL) = 23, /**< Address of relocations associated with PLT. */ - _LIEF_EI(DT_BIND_NOW) = 24, /**< Process all relocations before execution. */ - _LIEF_EI(DT_INIT_ARRAY) = 25, /**< Pointer to array of initialization functions. */ - _LIEF_EI(DT_FINI_ARRAY) = 26, /**< Pointer to array of termination functions. */ - _LIEF_EI(DT_INIT_ARRAYSZ) = 27, /**< Size of DT_INIT_ARRAY. */ - _LIEF_EI(DT_FINI_ARRAYSZ) = 28, /**< Size of DT_FINI_ARRAY. */ - _LIEF_EI(DT_RUNPATH) = 29, /**< String table offset of lib search path. */ - _LIEF_EI(DT_FLAGS) = 30, /**< Flags. */ - _LIEF_EI(DT_ENCODING) = 32, /**< Values from here to DT_LOOS follow the rules for the interpretation of the d_un union. */ - - _LIEF_EI(DT_PREINIT_ARRAY) = 32, /**< Pointer to array of preinit functions. */ - _LIEF_EI(DT_PREINIT_ARRAYSZ) = 33, /**< Size of the DT_PREINIT_ARRAY array. */ - - _LIEF_EI(DT_LOOS) = 0x60000000, /**< Start of environment specific tags. */ - _LIEF_EI(DT_HIOS) = 0x6FFFFFFF, /**< End of environment specific tags. */ - _LIEF_EI(DT_LOPROC) = 0x70000000, /**< Start of processor specific tags. */ - _LIEF_EI(DT_HIPROC) = 0x7FFFFFFF, /**< End of processor specific tags. */ - - _LIEF_EI(DT_GNU_HASH) = 0x6FFFFEF5, /**< Reference to the GNU hash table. */ - _LIEF_EI(DT_RELACOUNT) = 0x6FFFFFF9, /**< ELF32_Rela count. */ - _LIEF_EI(DT_RELCOUNT) = 0x6FFFFFFA, /**< ELF32_Rel count. */ - - _LIEF_EI(DT_FLAGS_1) = 0x6FFFFFFB, /**< Flags_1. */ - _LIEF_EI(DT_VERSYM) = 0x6FFFFFF0, /**< The address of .gnu.version section. */ - _LIEF_EI(DT_VERDEF) = 0x6FFFFFFC, /**< The address of the version definition table. */ - _LIEF_EI(DT_VERDEFNUM) = 0x6FFFFFFD, /**< The number of entries in DT_VERDEF. */ - _LIEF_EI(DT_VERNEED) = 0x6FFFFFFE, /**< The address of the version Dependency table. */ - _LIEF_EI(DT_VERNEEDNUM) = 0x6FFFFFFF, /**< The number of entries in DT_VERNEED. */ - - /* Mips specific dynamic table entry tags. */ - _LIEF_EI(DT_MIPS_RLD_VERSION) = 0x70000001, /**< 32 bit version number for runtime linker interface. */ - _LIEF_EI(DT_MIPS_TIME_STAMP) = 0x70000002, /**< Time stamp. */ - _LIEF_EI(DT_MIPS_ICHECKSUM) = 0x70000003, /**< Checksum of external strings and common sizes. */ - _LIEF_EI(DT_MIPS_IVERSION) = 0x70000004, /**< Index of version string in string table. */ - _LIEF_EI(DT_MIPS_FLAGS) = 0x70000005, /**< 32 bits of flags. */ - _LIEF_EI(DT_MIPS_BASE_ADDRESS) = 0x70000006, /**< Base address of the segment. */ - _LIEF_EI(DT_MIPS_MSYM) = 0x70000007, /**< Address of .msym section. */ - _LIEF_EI(DT_MIPS_CONFLICT) = 0x70000008, /**< Address of .conflict section. */ - _LIEF_EI(DT_MIPS_LIBLIST) = 0x70000009, /**< Address of .liblist section. */ - _LIEF_EI(DT_MIPS_LOCAL_GOTNO) = 0x7000000a, /**< Number of local global offset table entries. */ - _LIEF_EI(DT_MIPS_CONFLICTNO) = 0x7000000b, /**< Number of entries in the .conflict section. */ - _LIEF_EI(DT_MIPS_LIBLISTNO) = 0x70000010, /**< Number of entries in the .liblist section. */ - _LIEF_EI(DT_MIPS_SYMTABNO) = 0x70000011, /**< Number of entries in the .dynsym section. */ - _LIEF_EI(DT_MIPS_UNREFEXTNO) = 0x70000012, /**< Index of first external dynamic symbol not referenced locally. */ - _LIEF_EI(DT_MIPS_GOTSYM) = 0x70000013, /**< Index of first dynamic symbol in global offset table. */ - _LIEF_EI(DT_MIPS_HIPAGENO) = 0x70000014, /**< Number of page table entries in global offset table. */ - _LIEF_EI(DT_MIPS_RLD_MAP) = 0x70000016, /**< Address of run time loader map, used for debugging. */ - _LIEF_EI(DT_MIPS_DELTA_CLASS) = 0x70000017, /**< Delta C++ class definition. */ - _LIEF_EI(DT_MIPS_DELTA_CLASS_NO) = 0x70000018, /**< Number of entries in DT_MIPS_DELTA_CLASS. */ - _LIEF_EI(DT_MIPS_DELTA_INSTANCE) = 0x70000019, /**< Delta C++ class instances. */ - _LIEF_EI(DT_MIPS_DELTA_INSTANCE_NO) = 0x7000001A, /**< Number of entries in DT_MIPS_DELTA_INSTANCE. */ - _LIEF_EI(DT_MIPS_DELTA_RELOC) = 0x7000001B, /**< Delta relocations. */ - _LIEF_EI(DT_MIPS_DELTA_RELOC_NO) = 0x7000001C, /**< Number of entries in DT_MIPS_DELTA_RELOC. */ - _LIEF_EI(DT_MIPS_DELTA_SYM) = 0x7000001D, /**< Delta symbols that Delta relocations refer to. */ - _LIEF_EI(DT_MIPS_DELTA_SYM_NO) = 0x7000001E, /**< Number of entries in DT_MIPS_DELTA_SYM. */ - _LIEF_EI(DT_MIPS_DELTA_CLASSSYM) = 0x70000020, /**< Delta symbols that hold class declarations. */ - _LIEF_EI(DT_MIPS_DELTA_CLASSSYM_NO) = 0x70000021, /**< Number of entries in DT_MIPS_DELTA_CLASSSYM. */ - _LIEF_EI(DT_MIPS_CXX_FLAGS) = 0x70000022, /**< Flags indicating information about C++ flavor. */ - _LIEF_EI(DT_MIPS_PIXIE_INIT) = 0x70000023, /**< Pixie information. */ - _LIEF_EI(DT_MIPS_SYMBOL_LIB) = 0x70000024, /**< Address of .MIPS.symlib */ - _LIEF_EI(DT_MIPS_LOCALPAGE_GOTIDX) = 0x70000025, /**< The GOT index of the first PTE for a segment */ - _LIEF_EI(DT_MIPS_LOCAL_GOTIDX) = 0x70000026, /**< The GOT index of the first PTE for a local symbol */ - _LIEF_EI(DT_MIPS_HIDDEN_GOTIDX) = 0x70000027, /**< The GOT index of the first PTE for a hidden symbol */ - _LIEF_EI(DT_MIPS_PROTECTED_GOTIDX) = 0x70000028, /**< The GOT index of the first PTE for a protected symbol */ - _LIEF_EI(DT_MIPS_OPTIONS) = 0x70000029, /**< Address of `.MIPS.options'. */ - _LIEF_EI(DT_MIPS_INTERFACE) = 0x7000002A, /**< Address of `.interface'. */ - _LIEF_EI(DT_MIPS_DYNSTR_ALIGN) = 0x7000002B, /**< Unknown. */ - _LIEF_EI(DT_MIPS_INTERFACE_SIZE) = 0x7000002C, /**< Size of the .interface section. */ - _LIEF_EI(DT_MIPS_RLD_TEXT_RESOLVE_ADDR) = 0x7000002D, /**< Size of rld_text_resolve function stored in the GOT. */ - _LIEF_EI(DT_MIPS_PERF_SUFFIX) = 0x7000002E, /**< Default suffix of DSO to be added by rld on dlopen() calls. */ - _LIEF_EI(DT_MIPS_COMPACT_SIZE) = 0x7000002F, /**< Size of compact relocation section (O32). */ - _LIEF_EI(DT_MIPS_GP_VALUE) = 0x70000030, /**< GP value for auxiliary GOTs. */ - _LIEF_EI(DT_MIPS_AUX_DYNAMIC) = 0x70000031, /**< Address of auxiliary .dynamic. */ - _LIEF_EI(DT_MIPS_PLTGOT) = 0x70000032, /**< Address of the base of the PLTGOT. */ - _LIEF_EI(DT_MIPS_RWPLT) = 0x70000034, /**< Points to the base of a writable PLT. */ - - /* Android specific dynamic table entry tags. */ - _LIEF_EI(DT_ANDROID_REL_OFFSET) = 0x6000000D, /**< The offset of packed relocation data (older version < M) (Android specific). */ - _LIEF_EI(DT_ANDROID_REL_SIZE) = 0x6000000E, /**< The size of packed relocation data in bytes (older version < M) (Android specific). */ - _LIEF_EI(DT_ANDROID_REL) = 0x6000000F, /**< The offset of packed relocation data (Android specific). */ - _LIEF_EI(DT_ANDROID_RELSZ) = 0x60000010, /**< The size of packed relocation data in bytes (Android specific). */ - _LIEF_EI(DT_ANDROID_RELA) = 0x60000011, /**< The offset of packed relocation data (Android specific). */ - _LIEF_EI(DT_ANDROID_RELASZ) = 0x60000012, /**< The size of packed relocation data in bytes (Android specific). */ - _LIEF_EI(DT_RELR) = 0x6FFFE000, /**< The offset of new relr relocation data (Android specific). */ - _LIEF_EI(DT_RELRSZ) = 0x6FFFE001, /**< The size of nre relr relocation data in bytes (Android specific). */ - _LIEF_EI(DT_RELRENT) = 0x6FFFE003, /**< The size of a new relr relocation entry (Android specific). */ - _LIEF_EI(DT_RELRCOUNT) = 0x6FFFE005 /**< Specifies the relative count of new relr relocation entries (Android specific). */ -}; - -/** DT_FLAGS and DT_FLAGS_1 values. */ -enum _LIEF_EN(DYNAMIC_FLAGS) { - _LIEF_EI(DF_ORIGIN) = 0x00000001, /**< The object may reference $ORIGIN. */ - _LIEF_EI(DF_SYMBOLIC) = 0x00000002, /**< Search the shared lib before searching the exe. */ - _LIEF_EI(DF_TEXTREL) = 0x00000004, /**< Relocations may modify a non-writable segment. */ - _LIEF_EI(DF_BIND_NOW) = 0x00000008, /**< Process all relocations on load. */ - _LIEF_EI(DF_STATIC_TLS) = 0x00000010, /**< Reject attempts to load dynamically. */ -}; - -enum _LIEF_EN(DYNAMIC_FLAGS_1) { - _LIEF_EI(DF_1_NOW) = 0x00000001, /**< Set RTLD_NOW for this object. */ - _LIEF_EI(DF_1_GLOBAL) = 0x00000002, /**< Set RTLD_GLOBAL for this object. */ - _LIEF_EI(DF_1_GROUP) = 0x00000004, /**< Set RTLD_GROUP for this object. */ - _LIEF_EI(DF_1_NODELETE) = 0x00000008, /**< Set RTLD_NODELETE for this object. */ - _LIEF_EI(DF_1_LOADFLTR) = 0x00000010, /**< Trigger filtee loading at runtime. */ - _LIEF_EI(DF_1_INITFIRST) = 0x00000020, /**< Set RTLD_INITFIRST for this object. */ - _LIEF_EI(DF_1_NOOPEN) = 0x00000040, /**< Set RTLD_NOOPEN for this object. */ - _LIEF_EI(DF_1_ORIGIN) = 0x00000080, /**< $ORIGIN must be handled. */ - _LIEF_EI(DF_1_DIRECT) = 0x00000100, /**< Direct binding enabled. */ - _LIEF_EI(DF_1_TRANS) = 0x00000200, - _LIEF_EI(DF_1_INTERPOSE) = 0x00000400, /**< Object is used to interpose. */ - _LIEF_EI(DF_1_NODEFLIB) = 0x00000800, /**< Ignore default lib search path. */ - _LIEF_EI(DF_1_NODUMP) = 0x00001000, /**< Object can't be dldump'ed. */ - _LIEF_EI(DF_1_CONFALT) = 0x00002000, /**< Configuration alternative created. */ - _LIEF_EI(DF_1_ENDFILTEE) = 0x00004000, /**< Filtee terminates filters search. */ - _LIEF_EI(DF_1_DISPRELDNE) = 0x00008000, /**< Disp reloc applied at build time. */ - _LIEF_EI(DF_1_DISPRELPND) = 0x00010000, /**< Disp reloc applied at run-time. */ - _LIEF_EI(DF_1_NODIRECT) = 0x00020000, /**< Object has no-direct binding. */ - _LIEF_EI(DF_1_IGNMULDEF) = 0x00040000, - _LIEF_EI(DF_1_NOKSYMS) = 0x00080000, - _LIEF_EI(DF_1_NOHDR) = 0x00100000, - _LIEF_EI(DF_1_EDITED) = 0x00200000, /**< Object is modified after built. */ - _LIEF_EI(DF_1_NORELOC) = 0x00400000, - _LIEF_EI(DF_1_SYMINTPOSE) = 0x00800000, /**< Object has individual interposers. */ - _LIEF_EI(DF_1_GLOBAUDIT) = 0x01000000, /**< Global auditing required. */ - _LIEF_EI(DF_1_SINGLETON) = 0x02000000, /**< Singleton symbols are used. */ - _LIEF_EI(DF_1_PIE) = 0x08000000 /**< Singleton symbols are used. */ -}; - -/* DT_MIPS_FLAGS values. */ -enum { - _LIEF_EI(RHF_NONE) = 0x00000000, /* No flags. */ - _LIEF_EI(RHF_QUICKSTART) = 0x00000001, /* Uses shortcut pointers. */ - _LIEF_EI(RHF_NOTPOT) = 0x00000002, /* Hash size is not a power of two. */ - _LIEF_EI(RHS_NO_LIBRARY_REPLACEMENT) = 0x00000004, /* Ignore LD_LIBRARY_PATH. */ - _LIEF_EI(RHF_NO_MOVE) = 0x00000008, /* DSO address may not be relocated. */ - _LIEF_EI(RHF_SGI_ONLY) = 0x00000010, /* SGI specific features. */ - _LIEF_EI(RHF_GUARANTEE_INIT) = 0x00000020, /* Guarantee that .init will finish */ - /* executing before any non-init */ - /* code in DSO is called. */ - _LIEF_EI(RHF_DELTA_C_PLUS_PLUS) = 0x00000040, /* Contains Delta C++ code. */ - _LIEF_EI(RHF_GUARANTEE_START_INIT) = 0x00000080, /* Guarantee that .init will start */ - /* executing before any non-init */ - /* code in DSO is called. */ - _LIEF_EI(RHF_PIXIE) = 0x00000100, /* Generated by pixie. */ - _LIEF_EI(RHF_DEFAULT_DELAY_LOAD) = 0x00000200, /* Delay-load DSO by default. */ - _LIEF_EI(RHF_REQUICKSTART) = 0x00000400, /* Object may be requickstarted */ - _LIEF_EI(RHF_REQUICKSTARTED) = 0x00000800, /* Object has been requickstarted */ - _LIEF_EI(RHF_CORD) = 0x00001000, /* Generated by cord. */ - _LIEF_EI(RHF_NO_UNRES_UNDEF) = 0x00002000, /* Object contains no unresolved */ - /* undef symbols. */ - _LIEF_EI(RHF_RLD_ORDER_SAFE) = 0x00004000 /* Symbol table is in a safe order. */ -}; - -/** ElfXX_VerDef structure version (GNU versioning) */ -enum { - _LIEF_EI(VER_DEF_NONE) = 0, - _LIEF_EI(VER_DEF_CURRENT) = 1 -}; - -/** VerDef Flags (ElfXX_VerDef::vd_flags) */ -enum { - _LIEF_EI(VER_FLG_BASE) = 0x1, - _LIEF_EI(VER_FLG_WEAK) = 0x2, - _LIEF_EI(VER_FLG_INFO) = 0x4 -}; - -/** Special constants for the version table. (SHT_GNU_versym/.gnu.version) */ -enum { - _LIEF_EI(VER_NDX_LOCAL) = 0, /**< Unversioned local symbol */ - _LIEF_EI(VER_NDX_GLOBAL) = 1, /**< Unversioned global symbol */ - _LIEF_EI(VERSYM_VERSION) = 0x7fff, /**< Version Index mask */ - _LIEF_EI(VERSYM_HIDDEN) = 0x8000 /**< Hidden bit (non-default version) */ -}; - -/** ElfXX_VerNeed structure version (GNU versioning) */ -enum { - _LIEF_EI(VER_NEED_NONE) = 0, - _LIEF_EI(VER_NEED_CURRENT) = 1 -}; - - -enum _LIEF_EN(AUX_TYPE) { - - _LIEF_EI(AT_NULL) = 0, /**< End of vector */ - _LIEF_EI(AT_IGNORE) = 1, /**< Entry should be ignored */ - _LIEF_EI(AT_EXECFD) = 2, /**< File descriptor of program */ - _LIEF_EI(AT_PHDR) = 3, /**< Program headers for program */ - _LIEF_EI(AT_PHENT) = 4, /**< Size of program header entry */ - _LIEF_EI(AT_PHNUM) = 5, /**< Number of program headers */ - _LIEF_EI(AT_PAGESZ) = 6, /**< System page size */ - _LIEF_EI(AT_BASE) = 7, /**< Base address of interpreter */ - _LIEF_EI(AT_FLAGS) = 8, /**< Flags */ - _LIEF_EI(AT_ENTRY) = 9, /**< Entry point of program */ - _LIEF_EI(AT_NOTELF) = 10, /**< Program is not ELF */ - _LIEF_EI(AT_UID) = 11, /**< Real uid */ - _LIEF_EI(AT_EUID) = 12, /**< Effective uid */ - _LIEF_EI(AT_GID) = 13, /**< Real gid */ - _LIEF_EI(AT_EGID) = 14, /**< Effective gid */ - _LIEF_EI(AT_CLKTCK) = 17, /**< Frequency of times() */ - - /* Some more special a_type values describing the hardware. */ - - _LIEF_EI(AT_PLATFORM) = 15, /**< String identifying platform. */ - _LIEF_EI(AT_HWCAP) = 16, /**< Machine dependent hints about processor capabilities. */ - - /* This entry gives some information about the FPU initialization - performed by the kernel. */ - - _LIEF_EI(AT_FPUCW) = 18, /**< Used FPU control word. */ - - /* Cache block sizes. */ - _LIEF_EI(AT_DCACHEBSIZE) = 19, /**< Data cache block size. */ - _LIEF_EI(AT_ICACHEBSIZE) = 20, /**< Instruction cache block size. */ - _LIEF_EI(AT_UCACHEBSIZE) = 21, /**< Unified cache block size. */ - - /* A special ignored value for PPC, used by the kernel to control the - interpretation of the AUXV. Must be > 16. */ - - _LIEF_EI(AT_IGNOREPPC) = 22, /**< Entry should be ignored. */ - _LIEF_EI(AT_SECURE) = 23, /**< Boolean, was exec setuid-like? */ - _LIEF_EI(AT_BASE_PLATFORM) = 24, /**< String identifying real platforms.*/ - _LIEF_EI(AT_RANDOM) = 25, /**< Address of 16 random bytes. */ - _LIEF_EI(AT_HWCAP2) = 26, /**< Extension of AT_HWCAP. */ - _LIEF_EI(AT_EXECFN) = 31, /**< Filename of executable. */ - - /* Pointer to the global system page used for system calls and other - nice things. */ - _LIEF_EI(AT_SYSINFO) = 32, - _LIEF_EI(AT_SYSINFO_EHDR) = 33, - - /* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains - log2 of line size; mask those to get cache size. */ - _LIEF_EI(AT_L1I_CACHESHAPE) = 34, - _LIEF_EI(AT_L1D_CACHESHAPE) = 35, - _LIEF_EI(AT_L2_CACHESHAPE) = 36, - _LIEF_EI(AT_L3_CACHESHAPE) = 37 -}; - -/** Methods that can be used by the LIEF::ELF::Parser - to count the number of dynamic symbols */ -enum _LIEF_EN(DYNSYM_COUNT_METHODS) { - _LIEF_EI(COUNT_AUTO) = 0, /**< Automatic detection */ - _LIEF_EI(COUNT_SECTION) = 1, /**< Count based on sections (not very reliable) */ - _LIEF_EI(COUNT_HASH) = 2, /**< Count based on hash table (reliable) */ - _LIEF_EI(COUNT_RELOCATIONS) = 3, /**< Count based on PLT/GOT relocations (very reliable but not accurate) */ -}; - -enum _LIEF_EN(NOTE_TYPES) { - _LIEF_EI(NT_UNKNOWN) = 0, - _LIEF_EI(NT_GNU_ABI_TAG) = 1, - _LIEF_EI(NT_GNU_HWCAP) = 2, - _LIEF_EI(NT_GNU_BUILD_ID) = 3, - _LIEF_EI(NT_GNU_GOLD_VERSION) = 4, - _LIEF_EI(NT_GNU_PROPERTY_TYPE_0) = 5, - _LIEF_EI(NT_GNU_BUILD_ATTRIBUTE_OPEN) = 0x100, - _LIEF_EI(NT_GNU_BUILD_ATTRIBUTE_FUNC) = 0x101, - _LIEF_EI(NT_CRASHPAD) = 0x4f464e49, -}; - -enum _LIEF_EN(NOTE_TYPES_CORE) { - _LIEF_EI(NT_CORE_UNKNOWN) = 0, - _LIEF_EI(NT_PRSTATUS) = 1, - _LIEF_EI(NT_PRFPREG) = 2, - _LIEF_EI(NT_PRPSINFO) = 3, - _LIEF_EI(NT_TASKSTRUCT) = 4, - _LIEF_EI(NT_AUXV) = 6, - _LIEF_EI(NT_SIGINFO) = 0x53494749, - _LIEF_EI(NT_FILE) = 0x46494c45, - _LIEF_EI(NT_PRXFPREG) = 0x46e62b7f, - - _LIEF_EI(NT_ARM_VFP) = 0x400, - _LIEF_EI(NT_ARM_TLS) = 0x401, - _LIEF_EI(NT_ARM_HW_BREAK) = 0x402, - _LIEF_EI(NT_ARM_HW_WATCH) = 0x403, - _LIEF_EI(NT_ARM_SYSTEM_CALL) = 0x404, - _LIEF_EI(NT_ARM_SVE) = 0x405, - - _LIEF_EI(NT_386_TLS) = 0x200, - _LIEF_EI(NT_386_IOPERM) = 0x201, - _LIEF_EI(NT_386_XSTATE) = 0x202, - -}; - - -enum _LIEF_EN(NOTE_ABIS) { - _LIEF_EI(ELF_NOTE_UNKNOWN) = ~(unsigned int)(0), - _LIEF_EI(ELF_NOTE_OS_LINUX) = 0, - _LIEF_EI(ELF_NOTE_OS_GNU) = 1, - _LIEF_EI(ELF_NOTE_OS_SOLARIS2) = 2, - _LIEF_EI(ELF_NOTE_OS_FREEBSD) = 3, - _LIEF_EI(ELF_NOTE_OS_NETBSD) = 4, - _LIEF_EI(ELF_NOTE_OS_SYLLABLE) = 5, -}; - -enum _LIEF_EN(RELOCATION_PURPOSES) { - _LIEF_EI(RELOC_PURPOSE_NONE) = 0, - _LIEF_EI(RELOC_PURPOSE_PLTGOT) = 1, - _LIEF_EI(RELOC_PURPOSE_DYNAMIC) = 2, - _LIEF_EI(RELOC_PURPOSE_OBJECT) = 3, -}; - diff --git a/include/LIEF/ELF/undef.h b/include/LIEF/ELF/undef.h index 7e55383c8d..a76eb1a83e 100644 --- a/include/LIEF/ELF/undef.h +++ b/include/LIEF/ELF/undef.h @@ -20,8 +20,6 @@ #pragma message("LIEF will disable #define enums. Please use LIEF_ELF_XXXX or LIEF::ELF::XXXX instead!") #endif - - #undef EI_MAG0 #undef EI_MAG1 #undef EI_MAG2 diff --git a/src/ELF/Binary.cpp b/src/ELF/Binary.cpp index 6893f1ec0f..1a37b88931 100644 --- a/src/ELF/Binary.cpp +++ b/src/ELF/Binary.cpp @@ -52,6 +52,7 @@ #include "LIEF/ELF/SymbolVersion.hpp" #include "LIEF/ELF/SymbolVersionDefinition.hpp" #include "LIEF/ELF/SymbolVersionRequirement.hpp" +#include "LIEF/ELF/SymbolVersionAuxRequirement.hpp" #include "LIEF/ELF/GnuHash.hpp" #include "LIEF/ELF/SysvHash.hpp" #include "LIEF/ELF/hash.hpp" @@ -67,7 +68,7 @@ namespace ELF { inline size_t get_relocation_sizeof(const Binary& bin, const Relocation& R) { - const bool is64 = (bin.type() == ELF_CLASS::ELFCLASS64); + const bool is64 = (bin.type() == Header::CLASS::ELF64); const bool is_rela = R.is_rela(); return is64 ? @@ -82,20 +83,8 @@ Binary::Binary() : } -Header& Binary::header() { - return const_cast(static_cast(this)->header()); -} - -const Header& Binary::header() const { - return header_; -} - -ELF_CLASS Binary::type() const { - return type_; -} - size_t Binary::hash(const std::string& name) { - if (type_ == ELF_CLASS::ELFCLASS32) { + if (type_ == Header::CLASS::ELF32) { return hash32(name.c_str()); } return hash64(name.c_str()); @@ -112,35 +101,10 @@ LIEF::Binary::sections_t Binary::get_abstract_sections() { return sections; } - -// Sections -// ======== - -Binary::it_sections Binary::sections() { - return sections_; -} - - -Binary::it_const_sections Binary::sections() const { - return sections_; -} - -// Segments -// ======== - -Binary::it_segments Binary::segments() { - return segments_; -} - -Binary::it_const_segments Binary::segments() const { - return segments_; -} - - LIEF::Binary::functions_t Binary::get_abstract_exported_functions() const { LIEF::Binary::functions_t result; for (const Symbol& symbol : exported_symbols()) { - if (symbol.type() == ELF_SYMBOL_TYPES::STT_FUNC) { + if (symbol.type() == Symbol::TYPE::FUNC) { result.emplace_back(symbol.name(), symbol.value(), Function::flags_list_t{Function::FLAGS::EXPORTED}); } } @@ -151,7 +115,7 @@ LIEF::Binary::functions_t Binary::get_abstract_exported_functions() const { LIEF::Binary::functions_t Binary::get_abstract_imported_functions() const { LIEF::Binary::functions_t result; for (const Symbol& symbol : imported_symbols()) { - if (symbol.type() == ELF_SYMBOL_TYPES::STT_FUNC) { + if (symbol.type() == Symbol::TYPE::FUNC) { result.emplace_back(symbol.name(), symbol.value(), Function::flags_list_t{Function::FLAGS::IMPORTED}); } } @@ -170,47 +134,13 @@ std::vector Binary::get_abstract_imported_libraries() const { } -// Dynamic Entries -// =============== - -Binary::it_dynamic_entries Binary::dynamic_entries() { - return dynamic_entries_; -} - -Binary::it_const_dynamic_entries Binary::dynamic_entries() const { - return dynamic_entries_; -} - DynamicEntry& Binary::add(const DynamicEntry& entry) { - - std::unique_ptr new_one; - - if (DynamicEntryLibrary::classof(&entry)) { - new_one = std::make_unique(*entry.as()); - } - else if (DynamicSharedObject::classof(&entry)) { - new_one = std::make_unique(*entry.as()); - } - else if (DynamicEntryRpath::classof(&entry)) { - new_one = std::make_unique(*entry.as()); - } - else if (DynamicEntryRunPath::classof(&entry)) { - new_one = std::make_unique(*entry.as()); - } - else if (DynamicEntryFlags::classof(&entry)) { - new_one = std::make_unique(*entry.as()); - } - else if (DynamicEntryArray::classof(&entry)) { - new_one = std::make_unique(*entry.as()); - } - else { - new_one = std::make_unique(entry); - } + std::unique_ptr new_one = entry.clone(); const auto it_new_place = std::find_if(std::begin(dynamic_entries_), std::end(dynamic_entries_), [&new_one] (const std::unique_ptr& e) { - return e->tag() == new_one->tag() || e->tag() == DYNAMIC_TAGS::DT_NULL; + return e->tag() == new_one->tag() || e->tag() == DynamicEntry::TAG::DT_NULL; }); auto* ptr = new_one.get(); @@ -221,7 +151,7 @@ DynamicEntry& Binary::add(const DynamicEntry& entry) { Note& Binary::add(const Note& note) { - notes_.push_back(std::make_unique(note)); + notes_.push_back(note.clone()); return *notes_.back(); } @@ -240,7 +170,7 @@ void Binary::remove(const DynamicEntry& entry) { } -void Binary::remove(DYNAMIC_TAGS tag) { +void Binary::remove(DynamicEntry::TAG tag) { for (auto it = std::begin(dynamic_entries_); it != std::end(dynamic_entries_);) { if ((*it)->tag() == tag) { it = dynamic_entries_.erase(it); @@ -330,41 +260,6 @@ void Binary::remove(Note::TYPE type) { -// Symbols -// ======= - -// Statics -// ------- - -Binary::it_static_symbols Binary::static_symbols() { - return static_symbols_; -} - -Binary::it_const_static_symbols Binary::static_symbols() const { - return static_symbols_; -} - -// Dynamics -// -------- - -Binary::it_dynamic_symbols Binary::dynamic_symbols() { - return dynamic_symbols_; -} - -Binary::it_const_dynamic_symbols Binary::dynamic_symbols() const { - return dynamic_symbols_; -} - - -Binary::it_symbols Binary::symbols() { - return static_dyn_symbols(); -} - -Binary::it_const_symbols Binary::symbols() const { - return static_dyn_symbols(); -} - - Symbol& Binary::export_symbol(const Symbol& symbol) { // Check if the symbol is in the dynamic symbol table @@ -389,19 +284,19 @@ Symbol& Binary::export_symbol(const Symbol& symbol) { size_t text_idx = std::distance(std::begin(sections_), it_text); - if (s->binding() != SYMBOL_BINDINGS::STB_WEAK || s->binding() != SYMBOL_BINDINGS::STB_GLOBAL) { - s->binding(SYMBOL_BINDINGS::STB_GLOBAL); + if (s->binding() != Symbol::BINDING::WEAK || s->binding() != Symbol::BINDING::GLOBAL) { + s->binding(Symbol::BINDING::GLOBAL); } - if (s->type() == ELF_SYMBOL_TYPES::STT_NOTYPE) { - s->type(ELF_SYMBOL_TYPES::STT_COMMON); + if (s->type() == Symbol::TYPE::NOTYPE) { + s->type(Symbol::TYPE::COMMON); } if (s->shndx() == 0) { s->shndx(text_idx); } - s->visibility(ELF_SYMBOL_VISIBILITY::STV_DEFAULT); + s->visibility(Symbol::VISIBILITY::DEFAULT); return *s; } @@ -425,9 +320,9 @@ Symbol& Binary::export_symbol(const std::string& symbol_name, uint64_t value) { // Create a new one Symbol newsym; newsym.name(symbol_name); - newsym.type(ELF_SYMBOL_TYPES::STT_COMMON); - newsym.binding(SYMBOL_BINDINGS::STB_GLOBAL); - newsym.visibility(ELF_SYMBOL_VISIBILITY::STV_DEFAULT); + newsym.type(Symbol::TYPE::COMMON); + newsym.binding(Symbol::BINDING::GLOBAL); + newsym.visibility(Symbol::VISIBILITY::DEFAULT); newsym.value(value); newsym.size(0x10); return export_symbol(newsym); @@ -445,9 +340,9 @@ Symbol& Binary::add_exported_function(uint64_t address, const std::string& name) // First: Check if a symbol with the given 'name' exists in the **dynamic** table Symbol* s = get_dynamic_symbol(funcname); if (s != nullptr) { - s->type(ELF_SYMBOL_TYPES::STT_FUNC); - s->binding(SYMBOL_BINDINGS::STB_GLOBAL); - s->visibility(ELF_SYMBOL_VISIBILITY::STV_DEFAULT); + s->type(Symbol::TYPE::FUNC); + s->binding(Symbol::BINDING::GLOBAL); + s->visibility(Symbol::VISIBILITY::DEFAULT); s->value(address); return export_symbol(*s); } @@ -455,9 +350,9 @@ Symbol& Binary::add_exported_function(uint64_t address, const std::string& name) // Second: Check if a symbol with the given 'name' exists in the **static** s = get_static_symbol(funcname); if (s != nullptr) { - s->type(ELF_SYMBOL_TYPES::STT_FUNC); - s->binding(SYMBOL_BINDINGS::STB_GLOBAL); - s->visibility(ELF_SYMBOL_VISIBILITY::STV_DEFAULT); + s->type(Symbol::TYPE::FUNC); + s->binding(Symbol::BINDING::GLOBAL); + s->visibility(Symbol::VISIBILITY::DEFAULT); s->value(address); return export_symbol(*s); } @@ -465,9 +360,9 @@ Symbol& Binary::add_exported_function(uint64_t address, const std::string& name) // Create a new Symbol Symbol funcsym; funcsym.name(funcname); - funcsym.type(ELF_SYMBOL_TYPES::STT_FUNC); - funcsym.binding(SYMBOL_BINDINGS::STB_GLOBAL); - funcsym.visibility(ELF_SYMBOL_VISIBILITY::STV_DEFAULT); + funcsym.type(Symbol::TYPE::FUNC); + funcsym.binding(Symbol::BINDING::GLOBAL); + funcsym.visibility(Symbol::VISIBILITY::DEFAULT); funcsym.value(address); funcsym.size(0x10); @@ -477,19 +372,23 @@ Symbol& Binary::add_exported_function(uint64_t address, const std::string& name) bool Binary::has_dynamic_symbol(const std::string& name) const { - const auto it_symbol = std::find_if(std::begin(dynamic_symbols_), std::end(dynamic_symbols_), - [&name] (const std::unique_ptr& s) { - return s->name() == name; - }); + const auto it_symbol = std::find_if( + std::begin(dynamic_symbols_), std::end(dynamic_symbols_), + [&name] (const std::unique_ptr& s) { + return s->name() == name; + } + ); return it_symbol != std::end(dynamic_symbols_); } const Symbol* Binary::get_dynamic_symbol(const std::string& name) const { - const auto it_symbol = std::find_if(std::begin(dynamic_symbols_), std::end(dynamic_symbols_), - [&name] (const std::unique_ptr& s) { - return s->name() == name; - }); + const auto it_symbol = std::find_if( + std::begin(dynamic_symbols_), std::end(dynamic_symbols_), + [&name] (const std::unique_ptr& s) { + return s->name() == name; + }); + if (it_symbol == std::end(dynamic_symbols_)) { return nullptr; } @@ -501,18 +400,20 @@ Symbol* Binary::get_dynamic_symbol(const std::string& name) { } bool Binary::has_static_symbol(const std::string& name) const { - const auto it_symbol = std::find_if(std::begin(static_symbols_), std::end(static_symbols_), - [&name] (const std::unique_ptr& s) { - return s->name() == name; - }); + const auto it_symbol = std::find_if( + std::begin(static_symbols_), std::end(static_symbols_), + [&name] (const std::unique_ptr& s) { + return s->name() == name; + }); return it_symbol != std::end(static_symbols_); } const Symbol* Binary::get_static_symbol(const std::string& name) const { - const auto it_symbol = std::find_if(std::begin(static_symbols_), std::end(static_symbols_), - [&name] (const std::unique_ptr& s) { - return s->name() == name; - }); + const auto it_symbol = std::find_if( + std::begin(static_symbols_), std::end(static_symbols_), + [&name] (const std::unique_ptr& s) { + return s->name() == name; + }); if (it_symbol == std::end(static_symbols_)) { return nullptr; } @@ -580,7 +481,6 @@ std::vector Binary::static_dyn_symbols() const { // -------- Binary::it_exported_symbols Binary::exported_symbols() { - return {static_dyn_symbols(), [] (const Symbol* symbol) { return symbol->is_exported(); }}; @@ -609,46 +509,11 @@ Binary::it_const_imported_symbols Binary::imported_symbols() const { }}; } - -// Symbol version -// -------------- - -Binary::it_symbols_version Binary::symbols_version() { - return symbol_version_table_; -} - -Binary::it_const_symbols_version Binary::symbols_version() const { - return symbol_version_table_; -} - -// Symbol version definition -// ------------------------- - -Binary::it_symbols_version_definition Binary::symbols_version_definition() { - return symbol_version_definition_; -} - -Binary::it_const_symbols_version_definition Binary::symbols_version_definition() const { - return symbol_version_definition_; -} - -// Symbol version requirement -// -------------------------- - -Binary::it_symbols_version_requirement Binary::symbols_version_requirement() { - return symbol_version_requirements_; -} - -Binary::it_const_symbols_version_requirement Binary::symbols_version_requirement() const { - return symbol_version_requirements_; -} - void Binary::remove_symbol(const std::string& name) { remove_static_symbol(name); remove_dynamic_symbol(name); } - void Binary::remove_static_symbol(const std::string& name) { Symbol* sym = get_static_symbol(name); if (sym == nullptr) { @@ -663,10 +528,12 @@ void Binary::remove_static_symbol(Symbol* symbol) { return; } - const auto it_symbol = std::find_if(std::begin(static_symbols_), std::end(static_symbols_), - [symbol] (const std::unique_ptr& sym) { - return *symbol == *sym; - }); + const auto it_symbol = std::find_if( + std::begin(static_symbols_), std::end(static_symbols_), + [symbol] (const std::unique_ptr& sym) { + return *symbol == *sym; + } + ); if (it_symbol == std::end(static_symbols_)) { LIEF_WARN("Can't find the static symbol '{}'. It won't be removed", symbol->name()); @@ -691,10 +558,13 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) { if (symbol == nullptr) { return; } - const auto it_symbol = std::find_if(std::begin(dynamic_symbols_), std::end(dynamic_symbols_), - [symbol] (const std::unique_ptr& sym) { - return *symbol == *sym; - }); + + const auto it_symbol = std::find_if( + std::begin(dynamic_symbols_), std::end(dynamic_symbols_), + [symbol] (const std::unique_ptr& sym) { + return *symbol == *sym; + } + ); if (it_symbol == std::end(dynamic_symbols_)) { LIEF_WARN("Can't find the dynamic symbol '{}'. It won't be removed", symbol->name()); @@ -704,7 +574,7 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) { // Update relocations auto it_relocation = std::find_if(std::begin(relocations_), std::end(relocations_), [symbol] (const std::unique_ptr& relocation) { - return relocation->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT && + return relocation->purpose() == Relocation::PURPOSE::PLTGOT && relocation->has_symbol() && relocation->symbol() == symbol; }); @@ -738,19 +608,19 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) { it_relocation = std::find_if(std::begin(relocations_), std::end(relocations_), [symbol] (const std::unique_ptr& relocation) { - return relocation->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC && + return relocation->purpose() == Relocation::PURPOSE::DYNAMIC && relocation->has_symbol() && relocation->symbol() == symbol; }); if (it_relocation != std::end(relocations_)) { const size_t rel_sizeof = get_relocation_sizeof(*this, **it_relocation); - if (auto* DT = get(DYNAMIC_TAGS::DT_RELASZ)) { + if (auto* DT = get(DynamicEntry::TAG::RELASZ)) { const uint64_t sizes = DT->value(); if (sizes >= rel_sizeof) { DT->value(sizes - rel_sizeof); } } - else if (auto* DT = get(DYNAMIC_TAGS::DT_RELSZ)) { + else if (auto* DT = get(DynamicEntry::TAG::RELSZ)) { const uint64_t sizes = DT->value(); if (sizes >= rel_sizeof) { DT->value(sizes - rel_sizeof); @@ -761,10 +631,12 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) { // Update symbol versions if (symbol->has_version()) { - const auto it = std::find_if(std::begin(symbol_version_table_), std::end(symbol_version_table_), - [symbol] (const std::unique_ptr& sv) { - return sv.get() == symbol->symbol_version_; - }); + const auto it = std::find_if( + std::begin(symbol_version_table_), std::end(symbol_version_table_), + [symbol] (const std::unique_ptr& sv) { + return sv.get() == symbol->symbol_version_; + } + ); if (it != std::end(symbol_version_table_)) { symbol_version_table_.erase(it); } @@ -782,21 +654,21 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) { Binary::it_dynamic_relocations Binary::dynamic_relocations() { return {relocations_, [] (const std::unique_ptr& reloc) { - return reloc->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC; + return reloc->purpose() == Relocation::PURPOSE::DYNAMIC; } }; } Binary::it_const_dynamic_relocations Binary::dynamic_relocations() const { return {relocations_, [] (const std::unique_ptr& reloc) { - return reloc->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC; + return reloc->purpose() == Relocation::PURPOSE::DYNAMIC; } }; } Relocation& Binary::add_dynamic_relocation(const Relocation& relocation) { auto relocation_ptr = std::make_unique(relocation); - relocation_ptr->purpose(RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC); + relocation_ptr->purpose(Relocation::PURPOSE::DYNAMIC); relocation_ptr->architecture_ = header().machine_type(); // Add symbol @@ -806,10 +678,11 @@ Relocation& Binary::add_dynamic_relocation(const Relocation& relocation) { if (inner_sym == nullptr) { inner_sym = &(add_dynamic_symbol(*associated_sym)); } - const auto it_sym = std::find_if(std::begin(dynamic_symbols_), std::end(dynamic_symbols_), - [inner_sym] (const std::unique_ptr& s) { - return s->name() == inner_sym->name(); - }); + const auto it_sym = std::find_if( + std::begin(dynamic_symbols_), std::end(dynamic_symbols_), + [inner_sym] (const std::unique_ptr& s) { + return s->name() == inner_sym->name(); + }); const size_t idx = std::distance(std::begin(dynamic_symbols_), it_sym); relocation_ptr->info(idx); relocation_ptr->symbol(inner_sym); @@ -817,8 +690,11 @@ Relocation& Binary::add_dynamic_relocation(const Relocation& relocation) { // Update the Dynamic Section (Thanks to @yd0b0N) bool is_rela = relocation.is_rela(); - DYNAMIC_TAGS tag_sz = is_rela ? DYNAMIC_TAGS::DT_RELASZ : DYNAMIC_TAGS::DT_RELSZ; - DYNAMIC_TAGS tag_ent = is_rela ? DYNAMIC_TAGS::DT_RELAENT : DYNAMIC_TAGS::DT_RELENT; + auto tag_sz = is_rela ? DynamicEntry::TAG::RELASZ : + DynamicEntry::TAG::RELSZ; + + auto tag_ent = is_rela ? DynamicEntry::TAG::RELAENT : + DynamicEntry::TAG::RELENT; DynamicEntry* dt_sz = get(tag_sz); DynamicEntry* dt_ent = get(tag_ent); @@ -833,7 +709,7 @@ Relocation& Binary::add_dynamic_relocation(const Relocation& relocation) { Relocation& Binary::add_pltgot_relocation(const Relocation& relocation) { auto relocation_ptr = std::make_unique(relocation); - relocation_ptr->purpose(RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT); + relocation_ptr->purpose(Relocation::PURPOSE::PLTGOT); relocation_ptr->architecture_ = header().machine_type(); // Add symbol @@ -843,10 +719,11 @@ Relocation& Binary::add_pltgot_relocation(const Relocation& relocation) { if (inner_sym == nullptr) { inner_sym = &(add_dynamic_symbol(*associated_sym)); } - const auto it_sym = std::find_if(std::begin(dynamic_symbols_), std::end(dynamic_symbols_), - [inner_sym] (const std::unique_ptr& s) { - return s->name() == inner_sym->name(); - }); + const auto it_sym = std::find_if( + std::begin(dynamic_symbols_), std::end(dynamic_symbols_), + [inner_sym] (const std::unique_ptr& s) { + return s->name() == inner_sym->name(); + }); const size_t idx = std::distance(std::begin(dynamic_symbols_), it_sym); relocation_ptr->info(idx); relocation_ptr->symbol(inner_sym); @@ -855,8 +732,8 @@ Relocation& Binary::add_pltgot_relocation(const Relocation& relocation) { // Update the Dynamic Section size_t reloc_size = get_relocation_sizeof(*this, relocation); - DynamicEntry* dt_sz = get(DYNAMIC_TAGS::DT_PLTRELSZ); - if (dt_sz != nullptr && has(DYNAMIC_TAGS::DT_JMPREL)) { + DynamicEntry* dt_sz = get(DynamicEntry::TAG::PLTRELSZ); + if (dt_sz != nullptr && has(DynamicEntry::TAG::JMPREL)) { dt_sz->value(dt_sz->value() + reloc_size); } @@ -877,7 +754,7 @@ Relocation* Binary::add_object_relocation(const Relocation& relocation, const Se auto relocation_ptr = std::make_unique(relocation); - relocation_ptr->purpose(RELOCATION_PURPOSES::RELOC_PURPOSE_OBJECT); + relocation_ptr->purpose(Relocation::PURPOSE::OBJECT); relocation_ptr->architecture_ = header().machine_type(); relocation_ptr->section_ = it_section->get(); relocations_.push_back(std::move(relocation_ptr)); @@ -888,14 +765,14 @@ Relocation* Binary::add_object_relocation(const Relocation& relocation, const Se // ------- Binary::it_pltgot_relocations Binary::pltgot_relocations() { return {relocations_, [] (const std::unique_ptr& reloc) { - return reloc->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT; + return reloc->purpose() == Relocation::PURPOSE::PLTGOT; } }; } Binary::it_const_pltgot_relocations Binary::pltgot_relocations() const { return {relocations_, [] (const std::unique_ptr& reloc) { - return reloc->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT; + return reloc->purpose() == Relocation::PURPOSE::PLTGOT; } }; } @@ -905,28 +782,18 @@ Binary::it_const_pltgot_relocations Binary::pltgot_relocations() const { // ------- Binary::it_object_relocations Binary::object_relocations() { return {relocations_, [] (const std::unique_ptr& reloc) { - return reloc->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_OBJECT; + return reloc->purpose() == Relocation::PURPOSE::OBJECT; } }; } Binary::it_const_object_relocations Binary::object_relocations() const { return {relocations_, [] (const std::unique_ptr& reloc) { - return reloc->purpose() == RELOCATION_PURPOSES::RELOC_PURPOSE_OBJECT; + return reloc->purpose() == Relocation::PURPOSE::OBJECT; } }; } -// All relocations -// --------------- -Binary::it_relocations Binary::relocations() { - return relocations_; -} - -Binary::it_const_relocations Binary::relocations() const { - return relocations_; -} - LIEF::Binary::relocations_t Binary::get_abstract_relocations() { LIEF::Binary::relocations_t relocations; relocations.reserve(relocations_.size()); @@ -965,10 +832,11 @@ Section* Binary::get_section(const std::string& name) { } const Section* Binary::get_section(const std::string& name) const { - const auto it_section = std::find_if(std::begin(sections_), std::end(sections_), - [&name] (const std::unique_ptr
& section) { - return section->name() == name; - }); + const auto it_section = std::find_if( + std::begin(sections_), std::end(sections_), + [&name] (const std::unique_ptr
& section) { + return section->name() == name; + }); if (it_section == std::end(sections_)) { return nullptr; @@ -976,16 +844,12 @@ const Section* Binary::get_section(const std::string& name) const { return it_section->get(); } -Section* Binary::text_section() { - return get_section(".text"); -} - - Section* Binary::dynamic_section() { - const auto it_dynamic_section = std::find_if(std::begin(sections_), std::end(sections_), - [] (const std::unique_ptr
& section) { - return section->type() == ELF_SECTION_TYPES::SHT_DYNAMIC; - }); + const auto it_dynamic_section = std::find_if( + std::begin(sections_), std::end(sections_), + [] (const std::unique_ptr
& section) { + return section->type() == Section::TYPE::DYNAMIC; + }); if (it_dynamic_section == std::end(sections_)) { return nullptr; @@ -996,10 +860,11 @@ Section* Binary::dynamic_section() { } Section* Binary::hash_section() { - const auto it_hash_section = std::find_if(std::begin(sections_), std::end(sections_), + const auto it_hash_section = std::find_if( + std::begin(sections_), std::end(sections_), [] (const std::unique_ptr
& section) { - return section->type() == ELF_SECTION_TYPES::SHT_HASH || - section->type() == ELF_SECTION_TYPES::SHT_GNU_HASH; + return section->type() == Section::TYPE::HASH || + section->type() == Section::TYPE::GNU_HASH; }); if (it_hash_section == std::end(sections_)) { @@ -1011,11 +876,11 @@ Section* Binary::hash_section() { } Section* Binary::static_symbols_section() { - const auto it_symtab_section = std::find_if(std::begin(sections_), std::end(sections_), - [] (const std::unique_ptr
& section) { - return section->type() == ELF_SECTION_TYPES::SHT_SYMTAB; - }); - + const auto it_symtab_section = std::find_if( + std::begin(sections_), std::end(sections_), + [] (const std::unique_ptr
& section) { + return section->type() == Section::TYPE::SYMTAB; + }); if (it_symtab_section == std::end(sections_)) { return nullptr; @@ -1027,7 +892,7 @@ Section* Binary::static_symbols_section() { uint64_t Binary::imagebase() const { auto imagebase = static_cast(-1); for (const std::unique_ptr& segment : segments_) { - if (segment != nullptr && segment->type() == SEGMENT_TYPES::PT_LOAD) { + if (segment != nullptr && segment->is_load()) { imagebase = std::min(imagebase, segment->virtual_address() - segment->file_offset()); } } @@ -1037,7 +902,7 @@ uint64_t Binary::imagebase() const { uint64_t Binary::virtual_size() const { uint64_t virtual_size = 0; for (const std::unique_ptr& segment : segments_) { - if (segment != nullptr && segment->type() == SEGMENT_TYPES::PT_LOAD) { + if (segment != nullptr && segment->is_load()) { virtual_size = std::max(virtual_size, segment->virtual_address() + segment->virtual_size()); } } @@ -1077,7 +942,7 @@ result Binary::get_function_address(const std::string& func_name, bool sname = symbol->name(); } return sname == func_name && - symbol->type() == ELF_SYMBOL_TYPES::STT_FUNC; + symbol->type() == Symbol::TYPE::FUNC; }); if (it_symbol == std::end(static_symbols_)) { @@ -1106,11 +971,13 @@ Section* Binary::add_frame_section(const Section& sec) { } bool Binary::is_pie() const { - const auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), - [] (const std::unique_ptr& entry) { - return entry->type() == SEGMENT_TYPES::PT_INTERP; - }); - if (header().file_type() != E_TYPE::ET_DYN) { + const auto it_segment = std::find_if( + std::begin(segments_), std::end(segments_), + [] (const std::unique_ptr& entry) { + return entry->is_interpreter(); + }); + + if (header().file_type() != Header::FILE_TYPE::DYN) { return false; } @@ -1134,9 +1001,9 @@ bool Binary::is_pie() const { */ - if (has(SEGMENT_TYPES::PT_DYNAMIC)) { - if (const auto* flag = static_cast(get(DYNAMIC_TAGS::DT_FLAGS_1))) { - return flag->has(DYNAMIC_FLAGS_1::DF_1_PIE); + if (has(Segment::TYPE::DYNAMIC)) { + if (const auto* flag = static_cast(get(DynamicEntry::TAG::FLAGS_1))) { + return flag->has(DynamicEntryFlags::FLAG::PIE); } } @@ -1145,11 +1012,11 @@ bool Binary::is_pie() const { bool Binary::has_nx() const { - if (const Segment* gnu_stack = get(SEGMENT_TYPES::PT_GNU_STACK)) { - return !gnu_stack->has(ELF_SEGMENT_FLAGS::PF_X); + if (const Segment* gnu_stack = get(Segment::TYPE::GNU_STACK)) { + return !gnu_stack->has(Segment::FLAGS::X); } - if (header().machine_type() == ARCH::EM_PPC64) { + if (header().machine_type() == ARCH::PPC64) { // The PPC64 ELF ABI has a non-executable stack by default. return true; } @@ -1161,8 +1028,10 @@ Segment* Binary::add(const Segment& segment, uint64_t base) { const uint64_t new_base = base == 0 ? next_virtual_address() : base; switch(header().file_type()) { - case E_TYPE::ET_EXEC: return add_segment(segment, new_base); - case E_TYPE::ET_DYN: return add_segment(segment, new_base); + case Header::FILE_TYPE::EXEC: + return add_segment(segment, new_base); + case Header::FILE_TYPE::DYN: + return add_segment(segment, new_base); default: { LIEF_WARN("Adding segment for {} is not implemented", to_string(header().file_type())); @@ -1174,8 +1043,12 @@ Segment* Binary::add(const Segment& segment, uint64_t base) { Segment* Binary::replace(const Segment& new_segment, const Segment& original_segment, uint64_t base) { - const auto it_original_segment = std::find_if(std::begin(segments_), std::end(segments_), - [&original_segment] (const std::unique_ptr& s) { return *s == original_segment; }); + const auto it_original_segment = std::find_if( + std::begin(segments_), std::end(segments_), + [&original_segment] (const std::unique_ptr& s) { + return *s == original_segment; + } + ); if (it_original_segment == std::end(segments_)) { LIEF_WARN("Unable to find the segment in the current binary"); @@ -1232,10 +1105,11 @@ Segment* Binary::replace(const Segment& new_segment, const Segment& original_seg new_segment_ptr->content(content); - const auto it_segment_phdr = std::find_if(std::begin(segments_), std::end(segments_), - [] (const std::unique_ptr& s) { - return s->type() == SEGMENT_TYPES::PT_PHDR; - }); + const auto it_segment_phdr = std::find_if( + std::begin(segments_), std::end(segments_), + [] (const std::unique_ptr& s) { + return s->is_phdr(); + }); if (it_segment_phdr != std::end(segments_)) { std::unique_ptr& phdr_segment = *it_segment_phdr; @@ -1260,10 +1134,11 @@ Segment* Binary::replace(const Segment& new_segment, const Segment& original_seg void Binary::remove(const Segment& segment) { - const auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), - [&segment] (const std::unique_ptr& s) { - return *s == segment; - }); + const auto it_segment = std::find_if( + std::begin(segments_), std::end(segments_), + [&segment] (const std::unique_ptr& s) { + return *s == segment; + }); if (it_segment == std::end(segments_)) { LIEF_ERR("Can't find the provided segment"); @@ -1283,13 +1158,11 @@ void Binary::remove(const Segment& segment) { Segment* Binary::extend(const Segment& segment, uint64_t size) { - const SEGMENT_TYPES type = segment.type(); + const Segment::TYPE type = segment.type(); switch (type) { - case SEGMENT_TYPES::PT_PHDR: - case SEGMENT_TYPES::PT_LOAD: - { - return extend_segment(segment, size); - } + case Segment::TYPE::PHDR: + case Segment::TYPE::LOAD: + return extend_segment(segment, size); default: { @@ -1301,10 +1174,12 @@ Segment* Binary::extend(const Segment& segment, uint64_t size) { Section* Binary::extend(const Section& section, uint64_t size) { - const auto it_section = std::find_if(std::begin(sections_), std::end(sections_), - [§ion] (const std::unique_ptr
& s) { - return *s == section; - }); + const auto it_section = std::find_if( + std::begin(sections_), std::end(sections_), + [§ion] (const std::unique_ptr
& s) { + return *s == section; + } + ); if (it_section == std::end(sections_)) { LIEF_WARN("Unable to find the section '{}' in the current binary", section.name()); @@ -1357,7 +1232,7 @@ Section* Binary::extend(const Section& section, uint64_t size) { shift_symbols(from_address, shift); shift_relocations(from_address, shift); - if (type() == ELF_CLASS::ELFCLASS32) { + if (type() == Header::CLASS::ELF32) { fix_got_entries(from_address, shift); } else { fix_got_entries(from_address, shift); @@ -1378,7 +1253,7 @@ Section* Binary::extend(const Section& section, uint64_t size) { void Binary::patch_address(uint64_t address, const std::vector& patch_value, LIEF::Binary::VA_TYPES) { // Object file does not have segments - if (header().file_type() == E_TYPE::ET_REL) { + if (header().file_type() == Header::FILE_TYPE::REL) { Section* section = section_from_offset(address); if (section == nullptr) { LIEF_ERR("Can't find a section associated with the virtual address 0x{:x}", address); @@ -1424,7 +1299,7 @@ void Binary::patch_address(uint64_t address, uint64_t patch_value, size_t size, } // Object file does not have segments - if (header().file_type() == E_TYPE::ET_REL) { + if (header().file_type() == Header::FILE_TYPE::REL) { Section* section = section_from_offset(address); if (section == nullptr) { LIEF_ERR("Can't find a section associated with the address 0x{:x}", address); @@ -1569,11 +1444,11 @@ const Segment* Binary::segment_from_virtual_address(uint64_t address) const { } -Segment* Binary::segment_from_virtual_address(SEGMENT_TYPES type, uint64_t address) { +Segment* Binary::segment_from_virtual_address(Segment::TYPE type, uint64_t address) { return const_cast(static_cast(this)->segment_from_virtual_address(type, address)); } -const Segment* Binary::segment_from_virtual_address(SEGMENT_TYPES type, uint64_t address) const { +const Segment* Binary::segment_from_virtual_address(Segment::TYPE type, uint64_t address) const { const auto it_segment = std::find_if(segments_.cbegin(), segments_.cend(), [address, type] (const std::unique_ptr& segment) { return segment->type() == type && @@ -1593,8 +1468,6 @@ Segment* Binary::segment_from_virtual_address(uint64_t address) { return const_cast(static_cast(this)->segment_from_virtual_address(address)); } - - const Segment* Binary::segment_from_offset(uint64_t offset) const { const auto it_segment = std::find_if(segments_.cbegin(), segments_.cend(), [&offset] (const std::unique_ptr& segment) { @@ -1647,7 +1520,7 @@ bool Binary::has_section_with_va(uint64_t va) const { void Binary::strip() { static_symbols_.clear(); - Section* symtab = get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* symtab = get(Section::TYPE::SYMTAB); if (symtab != nullptr) { remove(*symtab, /* clear */ true); } @@ -1679,7 +1552,7 @@ Symbol& Binary::add_dynamic_symbol(const Symbol& symbol, const SymbolVersion* ve result Binary::virtual_address_to_offset(uint64_t virtual_address) const { const auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), [virtual_address] (const std::unique_ptr& segment) { - return segment->type() == SEGMENT_TYPES::PT_LOAD && + return segment->is_load() && segment->virtual_address() <= virtual_address && virtual_address < (segment->virtual_address() + segment->virtual_size()); }); @@ -1698,7 +1571,7 @@ result Binary::virtual_address_to_offset(uint64_t virtual_address) con result Binary::offset_to_virtual_address(uint64_t offset, uint64_t slide) const { const auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), [offset] (const std::unique_ptr& segment) { - return segment->type() == SEGMENT_TYPES::PT_LOAD && + return segment->is_load() && segment->file_offset() <= offset && offset < (segment->file_offset() + segment->physical_size()); }); @@ -1719,10 +1592,11 @@ result Binary::offset_to_virtual_address(uint64_t offset, uint64_t sli bool Binary::has_interpreter() const { - const auto it_segment_interp = std::find_if(std::begin(segments_), std::end(segments_), - [] (const std::unique_ptr& segment) { - return segment->type() == SEGMENT_TYPES::PT_INTERP; - }); + const auto it_segment_interp = std::find_if( + std::begin(segments_), std::end(segments_), + [] (const std::unique_ptr& segment) { + return segment->is_interpreter(); + }); return it_segment_interp != std::end(segments_) && !interpreter_.empty(); } @@ -1762,15 +1636,10 @@ void Binary::write(std::ostream& os, Builder::config_t config) { builder.write(os); } -uint64_t Binary::entrypoint() const { - return header().entrypoint(); -} - - const Section* Binary::section_from_offset(uint64_t offset, bool skip_nobits) const { const auto it_section = std::find_if(sections_.cbegin(), sections_.cend(), [offset, skip_nobits] (const std::unique_ptr
& section) { - if (skip_nobits && section->type() == ELF_SECTION_TYPES::SHT_NOBITS) { + if (skip_nobits && section->type() == Section::TYPE::NOBITS) { return false; } return section->offset() <= offset && @@ -1792,7 +1661,7 @@ Section* Binary::section_from_offset(uint64_t offset, bool skip_nobits) { const Section* Binary::section_from_virtual_address(uint64_t address, bool skip_nobits) const { const auto it_section = std::find_if(sections_.cbegin(), sections_.cend(), [address, skip_nobits] (const std::unique_ptr
& section) { - if (skip_nobits && section->type() == ELF_SECTION_TYPES::SHT_NOBITS) { + if (skip_nobits && section->type() == Section::TYPE::NOBITS) { return false; } return section->virtual_address() != 0 && @@ -1811,7 +1680,10 @@ Section* Binary::section_from_virtual_address(uint64_t address, bool skip_nobits return const_cast(static_cast(this)->section_from_virtual_address(address, skip_nobits)); } -span Binary::get_content_from_virtual_address(uint64_t virtual_address, uint64_t size, Binary::VA_TYPES) const { +span +Binary::get_content_from_virtual_address(uint64_t virtual_address, + uint64_t size, Binary::VA_TYPES) const +{ const Segment* segment = segment_from_virtual_address(virtual_address); if (segment == nullptr) { return {}; @@ -1828,31 +1700,26 @@ span Binary::get_content_from_virtual_address(uint64_t virtual_ad } -const DynamicEntry* Binary::get(DYNAMIC_TAGS tag) const { - const auto it_entry = std::find_if(std::begin(dynamic_entries_), std::end(dynamic_entries_), - [tag] (const std::unique_ptr& entry) { - return entry->tag() == tag; - }); +const DynamicEntry* Binary::get(DynamicEntry::TAG tag) const { + const auto it_entry = std::find_if( + std::begin(dynamic_entries_), std::end(dynamic_entries_), + [tag] (const std::unique_ptr& entry) { + return entry->tag() == tag; + }); + if (it_entry == std::end(dynamic_entries_)) { return nullptr; } return it_entry->get(); } -DynamicEntry* Binary::get(DYNAMIC_TAGS tag) { - return const_cast(static_cast(this)->get(tag)); -} - - -bool Binary::has(DYNAMIC_TAGS tag) const { - return get(tag) != nullptr; -} +const Segment* Binary::get(Segment::TYPE type) const { + const auto it_segment = std::find_if( + std::begin(segments_), std::end(segments_), + [type] (const std::unique_ptr& segment) { + return segment->type() == type; + }); -const Segment* Binary::get(SEGMENT_TYPES type) const { - const auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), - [type] (const std::unique_ptr& segment) { - return segment->type() == type; - }); if (it_segment == std::end(segments_)) { return nullptr; } @@ -1861,15 +1728,16 @@ const Segment* Binary::get(SEGMENT_TYPES type) const { } -Segment* Binary::get(SEGMENT_TYPES type) { +Segment* Binary::get(Segment::TYPE type) { return const_cast(static_cast(this)->get(type)); } const Note* Binary::get(Note::TYPE type) const { - const auto it_note = std::find_if(std::begin(notes_), std::end(notes_), - [type] (const std::unique_ptr& note) { - return note->type() == type; - }); + const auto it_note = std::find_if( + std::begin(notes_), std::end(notes_), + [type] (const std::unique_ptr& note) { + return note->type() == type; + }); if (it_note == std::end(notes_)) { return nullptr; } @@ -1882,11 +1750,13 @@ Note* Binary::get(Note::TYPE type) { return const_cast(static_cast(this)->get(type)); } -const Section* Binary::get(ELF_SECTION_TYPES type) const { - const auto it_section = std::find_if(std::begin(sections_), std::end(sections_), - [type] (const std::unique_ptr
& section) { - return section->type() == type; - }); +const Section* Binary::get(Section::TYPE type) const { + const auto it_section = std::find_if( + std::begin(sections_), std::end(sections_), + [type] (const std::unique_ptr
& section) { + return section->type() == type; + }); + if (it_section == std::end(sections_)) { return nullptr; } @@ -1894,23 +1764,10 @@ const Section* Binary::get(ELF_SECTION_TYPES type) const { return it_section->get(); } - -Section* Binary::get(ELF_SECTION_TYPES type) { +Section* Binary::get(Section::TYPE type) { return const_cast(static_cast(this)->get(type)); } -bool Binary::has(SEGMENT_TYPES type) const { - return get(type) != nullptr; -} - -bool Binary::has(Note::TYPE type) const { - return get(type) != nullptr; -} - -bool Binary::has(ELF_SECTION_TYPES type) const { - return get(type) != nullptr; -} - void Binary::permute_dynamic_symbols(const std::vector& permutation) { std::set done; for (size_t i = 0; i < permutation.size(); ++i) { @@ -1941,7 +1798,7 @@ LIEF::Header Binary::get_abstract_header() const { header.modes(am.second); header.entrypoint(this->header().entrypoint()); - if (this->header().file_type() == E_TYPE::ET_DYN && has_interpreter()) { // PIE + if (this->header().file_type() == Header::FILE_TYPE::DYN && has_interpreter()) { // PIE header.object_type(OBJECT_TYPES::TYPE_EXECUTABLE); } else { header.object_type(this->header().abstract_object_type()); @@ -1954,51 +1811,19 @@ LIEF::Header Binary::get_abstract_header() const { bool Binary::has_notes() const { - const auto it_segment_note = std::find_if(std::begin(segments_), std::end(segments_), - [] (const std::unique_ptr& segment) { - return segment->type() == SEGMENT_TYPES::PT_NOTE; - }); + const auto it_segment_note = std::find_if( + std::begin(segments_), std::end(segments_), + [] (const std::unique_ptr& segment) { + return segment->type() == Segment::TYPE::NOTE; + }); return it_segment_note != std::end(segments_) && notes().size() > 0; } -Binary::it_const_notes Binary::notes() const { - return notes_; -} - -Binary::it_notes Binary::notes() { - return notes_; -} - void Binary::accept(LIEF::Visitor& visitor) const { visitor.visit(*this); } -bool Binary::use_gnu_hash() const { - return gnu_hash_ != nullptr && has(DYNAMIC_TAGS::DT_GNU_HASH); -} - - -const GnuHash* Binary::gnu_hash() const { - if (!use_gnu_hash()) { - return nullptr; - } - return gnu_hash_.get(); -} - - -bool Binary::use_sysv_hash() const { - return sysv_hash_ != nullptr && has(DYNAMIC_TAGS::DT_HASH); -} - -const SysvHash* Binary::sysv_hash() const { - if (!use_sysv_hash()) { - return nullptr; - } - return sysv_hash_.get(); -} - - void Binary::shift_sections(uint64_t from, uint64_t shift) { LIEF_DEBUG("[+] Shift Sections"); for (std::unique_ptr
& section : sections_) { @@ -2037,19 +1862,19 @@ void Binary::shift_dynamic_entries(uint64_t from, uint64_t shift) { for (std::unique_ptr& entry : dynamic_entries_) { LIEF_DEBUG("[BEFORE] {}", *entry); switch (entry->tag()) { - case DYNAMIC_TAGS::DT_PLTGOT: - case DYNAMIC_TAGS::DT_HASH: - case DYNAMIC_TAGS::DT_GNU_HASH: - case DYNAMIC_TAGS::DT_STRTAB: - case DYNAMIC_TAGS::DT_SYMTAB: - case DYNAMIC_TAGS::DT_RELA: - case DYNAMIC_TAGS::DT_REL: - case DYNAMIC_TAGS::DT_JMPREL: - case DYNAMIC_TAGS::DT_INIT: - case DYNAMIC_TAGS::DT_FINI: - case DYNAMIC_TAGS::DT_VERSYM: - case DYNAMIC_TAGS::DT_VERDEF: - case DYNAMIC_TAGS::DT_VERNEED: + case DynamicEntry::TAG::PLTGOT: + case DynamicEntry::TAG::HASH: + case DynamicEntry::TAG::GNU_HASH: + case DynamicEntry::TAG::STRTAB: + case DynamicEntry::TAG::SYMTAB: + case DynamicEntry::TAG::RELA: + case DynamicEntry::TAG::REL: + case DynamicEntry::TAG::JMPREL: + case DynamicEntry::TAG::INIT: + case DynamicEntry::TAG::FINI: + case DynamicEntry::TAG::VERSYM: + case DynamicEntry::TAG::VERDEF: + case DynamicEntry::TAG::VERNEED: { if (entry->value() >= from) { @@ -2058,15 +1883,15 @@ void Binary::shift_dynamic_entries(uint64_t from, uint64_t shift) { break; } - case DYNAMIC_TAGS::DT_INIT_ARRAY: - case DYNAMIC_TAGS::DT_FINI_ARRAY: - case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + case DynamicEntry::TAG::INIT_ARRAY: + case DynamicEntry::TAG::FINI_ARRAY: + case DynamicEntry::TAG::PREINIT_ARRAY: { DynamicEntryArray::array_t& array = entry->as()->array(); for (uint64_t& address : array) { if (address >= from) { - if ((type() == ELF_CLASS::ELFCLASS32 && static_cast(address) > 0) || - (type() == ELF_CLASS::ELFCLASS64 && static_cast(address) > 0)) + if ((type() == Header::CLASS::ELF32 && static_cast(address) > 0) || + (type() == Header::CLASS::ELF64 && static_cast(address) > 0)) { address += shift; } @@ -2100,52 +1925,51 @@ void Binary::shift_symbols(uint64_t from, uint64_t shift) { } } - void Binary::shift_relocations(uint64_t from, uint64_t shift) { const ARCH arch = header().machine_type(); LIEF_DEBUG("Shift relocations for {} by 0x{:x} from 0x{:x}", to_string(arch), shift, from); switch(arch) { - case ARCH::EM_ARM: + case ARCH::ARM: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } - case ARCH::EM_AARCH64: + case ARCH::AARCH64: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } - case ARCH::EM_X86_64: + case ARCH::X86_64: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } - case ARCH::EM_386: + case ARCH::I386: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } - case ARCH::EM_PPC: + case ARCH::PPC: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } /* - case ARCH::EM_PPC64: + case ARCH::PPC64: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } - case ARCH::EM_RISCV: + case ARCH::RISCV: { - patch_relocations(from, shift); + patch_relocations(from, shift); break; } */ @@ -2184,11 +2008,11 @@ uint64_t Binary::next_virtual_address() const { return std::max(segment->virtual_address() + segment->virtual_size(), address); }); - if (type() == ELF_CLASS::ELFCLASS32) { + if (type() == Header::CLASS::ELF32) { va = round(static_cast(va)); } - if (type() == ELF_CLASS::ELFCLASS64) { + if (type() == Header::CLASS::ELF64) { va = round(static_cast(va)); } @@ -2232,7 +2056,7 @@ bool Binary::has_library(const std::string& name) const { } -LIEF::Binary::functions_t Binary::tor_functions(DYNAMIC_TAGS tag) const { +LIEF::Binary::functions_t Binary::tor_functions(DynamicEntry::TAG tag) const { LIEF::Binary::functions_t functions; const DynamicEntry* entry = get(tag); if (entry == nullptr || !DynamicEntryArray::classof(entry)) { @@ -2256,7 +2080,7 @@ LIEF::Binary::functions_t Binary::tor_functions(DYNAMIC_TAGS tag) const { LIEF::Binary::functions_t Binary::ctor_functions() const { LIEF::Binary::functions_t functions; - LIEF::Binary::functions_t init = tor_functions(DYNAMIC_TAGS::DT_INIT_ARRAY); + LIEF::Binary::functions_t init = tor_functions(DynamicEntry::TAG::INIT_ARRAY); std::transform( std::make_move_iterator(std::begin(init)), std::make_move_iterator(std::end(init)), std::back_inserter(functions), @@ -2266,7 +2090,7 @@ LIEF::Binary::functions_t Binary::ctor_functions() const { return f; }); - LIEF::Binary::functions_t preinit = tor_functions(DYNAMIC_TAGS::DT_PREINIT_ARRAY); + LIEF::Binary::functions_t preinit = tor_functions(DynamicEntry::TAG::PREINIT_ARRAY); std::transform( std::make_move_iterator(std::begin(preinit)), std::make_move_iterator(std::end(preinit)), @@ -2277,7 +2101,7 @@ LIEF::Binary::functions_t Binary::ctor_functions() const { return f; }); - const DynamicEntry* dt_init = get(DYNAMIC_TAGS::DT_INIT); + const DynamicEntry* dt_init = get(DynamicEntry::TAG::INIT); if (dt_init != nullptr) { functions.emplace_back("__dt_init", dt_init->value(), Function::flags_list_t{Function::FLAGS::CONSTRUCTOR}); @@ -2290,7 +2114,7 @@ LIEF::Binary::functions_t Binary::dtor_functions() const { LIEF::Binary::functions_t functions; - LIEF::Binary::functions_t fini = tor_functions(DYNAMIC_TAGS::DT_FINI_ARRAY); + LIEF::Binary::functions_t fini = tor_functions(DynamicEntry::TAG::FINI_ARRAY); std::transform( std::make_move_iterator(std::begin(fini)), std::make_move_iterator(std::end(fini)), std::back_inserter(functions), @@ -2300,7 +2124,7 @@ LIEF::Binary::functions_t Binary::dtor_functions() const { return f; }); - const DynamicEntry* dt_fini = get(DYNAMIC_TAGS::DT_FINI); + const DynamicEntry* dt_fini = get(DynamicEntry::TAG::FINI); if (dt_fini != nullptr) { functions.emplace_back("__dt_fini", dt_fini->value(), Function::flags_list_t{Function::FLAGS::DESTRUCTOR}); @@ -2368,7 +2192,7 @@ LIEF::Binary::functions_t Binary::armexid_functions() const { return base + offset; }; - const Segment* exidx = get(SEGMENT_TYPES::PT_ARM_EXIDX); + const Segment* exidx = get(Segment::TYPE::ARM_EXIDX); if (exidx != nullptr) { span content = exidx->content(); const size_t nb_functions = content.size() / (2 * sizeof(uint32_t)); @@ -2391,7 +2215,7 @@ LIEF::Binary::functions_t Binary::armexid_functions() const { LIEF::Binary::functions_t Binary::eh_frame_functions() const { LIEF::Binary::functions_t functions; - const Segment* eh_frame_seg = get(SEGMENT_TYPES::PT_GNU_EH_FRAME); + const Segment* eh_frame_seg = get(Segment::TYPE::GNU_EH_FRAME); if (eh_frame_seg == nullptr) { return functions; } @@ -2407,14 +2231,14 @@ LIEF::Binary::functions_t Binary::eh_frame_functions() const { return functions; } - const Segment* load_segment = segment_from_virtual_address(SEGMENT_TYPES::PT_LOAD, eh_frame_addr); + const Segment* load_segment = segment_from_virtual_address(Segment::TYPE::LOAD, eh_frame_addr); if (load_segment == nullptr) { LIEF_ERR("Unable to find the LOAD segment associated with PT_GNU_EH_FRAME"); return functions; } - const bool is64 = (type() == ELF_CLASS::ELFCLASS64); + const bool is64 = (type() == Header::CLASS::ELF64); eh_frame_off = eh_frame_off - load_segment->file_offset(); SpanStream vs = load_segment->content(); @@ -2695,7 +2519,7 @@ LIEF::Binary::functions_t Binary::functions() const { LIEF::Binary::functions_t dtors = dtor_functions(); for (const Symbol& s : symbols()) { - if (s.type() == ELF_SYMBOL_TYPES::STT_FUNC && s.value() > 0) { + if (s.type() == Symbol::TYPE::FUNC && s.value() > 0) { Function f{s.name(), s.value()}; f.size(s.size()); functions_set.insert(f); @@ -2722,18 +2546,18 @@ uint64_t Binary::eof_offset() const { uint64_t last_offset_sections = 0; for (const std::unique_ptr
& section : sections_) { - if (section->type() != LIEF::ELF::ELF_SECTION_TYPES::SHT_NOBITS && !section->is_frame()) { + if (section->type() != Section::TYPE::NOBITS && !section->is_frame()) { last_offset_sections = std::max(section->file_offset() + section->size(), last_offset_sections); } } - const uint64_t section_header_size = type() == ELF_CLASS::ELFCLASS64 ? - sizeof(typename details::ELF64::Elf_Shdr) : - sizeof(typename details::ELF32::Elf_Shdr); + const uint64_t section_header_size = + type() == Header::CLASS::ELF64 ? sizeof(typename details::ELF64::Elf_Shdr) : + sizeof(typename details::ELF32::Elf_Shdr); - const uint64_t segment_header_size = type() == ELF_CLASS::ELFCLASS64 ? - sizeof(typename details::ELF64::Elf_Phdr) : - sizeof(typename details::ELF32::Elf_Phdr); + const uint64_t segment_header_size = + type() == Header::CLASS::ELF64 ? sizeof(typename details::ELF64::Elf_Phdr) : + sizeof(typename details::ELF32::Elf_Phdr); const uint64_t end_sht_table = header().section_headers_offset() + @@ -2793,7 +2617,7 @@ uint64_t Binary::relocate_phdr_table_auto() { } uint64_t offset = 0; - if (header_.file_type() == E_TYPE::ET_DYN) { + if (header_.file_type() == Header::FILE_TYPE::DYN) { offset = relocate_phdr_table_pie(); if (offset == 0) { LIEF_ERR("Can't relocated phdr table for this PIE binary"); @@ -2803,9 +2627,10 @@ uint64_t Binary::relocate_phdr_table_auto() { } /* This is typically static binaries */ - const bool is_valid_for_v3 = header_.file_type() == E_TYPE::ET_EXEC && - get(SEGMENT_TYPES::PT_PHDR) == nullptr && - get(SEGMENT_TYPES::PT_INTERP) == nullptr; + const bool is_valid_for_v3 = + header_.file_type() == Header::FILE_TYPE::EXEC && + get(Segment::TYPE::PHDR) == nullptr && + get(Segment::TYPE::INTERP) == nullptr; if (is_valid_for_v3) { LIEF_DEBUG("Try v3 relocator"); offset = relocate_phdr_table_v3(); @@ -2841,11 +2666,11 @@ uint64_t Binary::relocate_phdr_table_pie() { const uint64_t phdr_offset = header().program_headers_offset(); uint64_t phdr_size = 0; - if (type() == ELF_CLASS::ELFCLASS32) { + if (type() == Header::CLASS::ELF32) { phdr_size = sizeof(details::ELF32::Elf_Phdr); } - if (type() == ELF_CLASS::ELFCLASS64) { + if (type() == Header::CLASS::ELF64) { phdr_size = sizeof(details::ELF64::Elf_Phdr); } @@ -2862,7 +2687,7 @@ uint64_t Binary::relocate_phdr_table_pie() { * e.g: * const ARCH arch = header_.machine_type(); * uint64_t shift = align(phdr_size, 0x10); - * if (arch == ARCH::EM_AARCH64 || arch == ARCH::EM_ARM) { + * if (arch == ARCH::AARCH64 || arch == ARCH::ARM) { * shift = 0x1000; * phdr_reloc_info_.new_offset = phdr_offset; * phdr_reloc_info_.nb_segments = shift / phdr_size - header_.numberof_segments(); @@ -2900,7 +2725,7 @@ uint64_t Binary::relocate_phdr_table_pie() { shift_symbols(from, shift); shift_relocations(from, shift); - if (type() == ELF_CLASS::ELFCLASS32) { + if (type() == Header::CLASS::ELF32) { fix_got_entries(from, shift); } else { fix_got_entries(from, shift); @@ -2930,9 +2755,9 @@ uint64_t Binary::relocate_phdr_table_v3() { Header& header = this->header(); - const uint64_t phdr_size = type() == ELF_CLASS::ELFCLASS32 ? - sizeof(details::ELF32::Elf_Phdr) : - sizeof(details::ELF64::Elf_Phdr); + const uint64_t phdr_size = + type() == Header::CLASS::ELF32 ? sizeof(details::ELF32::Elf_Phdr) : + sizeof(details::ELF64::Elf_Phdr); const uint64_t last_offset = virtual_size(); @@ -2958,14 +2783,14 @@ uint64_t Binary::relocate_phdr_table_v3() { // Add a segment that wraps this new PHDR auto phdr_load_segment = std::make_unique(); - phdr_load_segment->type(SEGMENT_TYPES::PT_LOAD); + phdr_load_segment->type(Segment::TYPE::LOAD); phdr_load_segment->file_offset(phdr_reloc_info_.new_offset); phdr_load_segment->physical_size(new_segtbl_sz); phdr_load_segment->virtual_size(new_segtbl_sz); phdr_load_segment->virtual_address(imagebase() + phdr_reloc_info_.new_offset); phdr_load_segment->physical_address(phdr_load_segment->virtual_address()); phdr_load_segment->alignment(0x1000); - phdr_load_segment->add(ELF_SEGMENT_FLAGS::PF_R); + phdr_load_segment->add(Segment::FLAGS::R); phdr_load_segment->datahandler_ = datahandler_.get(); DataHandler::Node new_node{phdr_reloc_info_.new_offset, new_segtbl_sz, @@ -2975,7 +2800,7 @@ uint64_t Binary::relocate_phdr_table_v3() { const auto it_new_place = std::find_if( segments_.rbegin(), segments_.rend(), - [] (const auto& s) { return s->type() == SEGMENT_TYPES::PT_LOAD; }); + [] (const auto& s) { return s->is_load(); }); if (it_new_place == segments_.rend()) { segments_.push_back(std::move(phdr_load_segment)); @@ -3012,7 +2837,7 @@ uint64_t Binary::relocate_phdr_table_v2() { Header& header = this->header(); - const uint64_t phdr_size = type() == ELF_CLASS::ELFCLASS32 ? + const uint64_t phdr_size = type() == Header::CLASS::ELF32 ? sizeof(details::ELF32::Elf_Phdr) : sizeof(details::ELF64::Elf_Phdr); @@ -3021,7 +2846,7 @@ uint64_t Binary::relocate_phdr_table_v2() { Segment* bss_segment = nullptr; size_t bss_cnt = 0; for (std::unique_ptr& segment : segments_) { - if (segment->type() == SEGMENT_TYPES::PT_LOAD) { + if (segment->is_load()) { load_seg.push_back(segment.get()); if (segment->physical_size() < segment->virtual_size()) { bss_segment = segment.get(); @@ -3113,12 +2938,12 @@ uint64_t Binary::relocate_phdr_table_v2() { // Create a LOAD segment that wraps the new location of the PT_PHDR. auto new_segment_ptr = std::make_unique(); Segment* nsegment_addr = new_segment_ptr.get(); - nsegment_addr->type(SEGMENT_TYPES::PT_LOAD); + nsegment_addr->type(Segment::TYPE::LOAD); nsegment_addr->virtual_size(new_phdr_size); nsegment_addr->physical_size(new_phdr_size); nsegment_addr->virtual_address(imagebase() + phdr_reloc_info_.new_offset); nsegment_addr->physical_address(imagebase() + phdr_reloc_info_.new_offset); - nsegment_addr->flags(ELF_SEGMENT_FLAGS::PF_R); + nsegment_addr->flags(Segment::FLAGS::R); nsegment_addr->alignment(0x1000); nsegment_addr->file_offset(phdr_reloc_info_.new_offset); nsegment_addr->datahandler_ = datahandler_.get(); @@ -3144,7 +2969,7 @@ uint64_t Binary::relocate_phdr_table_v2() { const auto it_segment_phdr = std::find_if(std::begin(segments_), std::end(segments_), [] (const std::unique_ptr& s) { - return s->type() == SEGMENT_TYPES::PT_PHDR; + return s->is_phdr(); }); if (it_segment_phdr != std::end(segments_)) { @@ -3166,7 +2991,7 @@ uint64_t Binary::relocate_phdr_table_v2() { if (section->is_frame()) { continue; } - if (section->file_offset() >= from && section->type() != ELF_SECTION_TYPES::SHT_NOBITS) { + if (section->file_offset() >= from && section->type() != Section::TYPE::NOBITS) { LIEF_DEBUG("[BEFORE] {}", *section); section->file_offset(section->file_offset() + shift); if (section->virtual_address() > 0) { @@ -3193,18 +3018,18 @@ uint64_t Binary::relocate_phdr_table_v1() { Header& header = this->header(); - const uint64_t phdr_size = type() == ELF_CLASS::ELFCLASS32 ? + const uint64_t phdr_size = type() == Header::CLASS::ELF32 ? sizeof(details::ELF32::Elf_Phdr) : sizeof(details::ELF64::Elf_Phdr); const auto it_segment_phdr = std::find_if(std::begin(segments_), std::end(segments_), [] (const std::unique_ptr& s) { - return s->type() == SEGMENT_TYPES::PT_PHDR; + return s->is_phdr(); }); std::vector load_seg; for (std::unique_ptr& segment : segments_) { - if (segment->type() == SEGMENT_TYPES::PT_LOAD) { + if (segment->is_load()) { load_seg.push_back(segment.get()); } } @@ -3307,89 +3132,6 @@ uint64_t Binary::relocate_phdr_table_v1() { return phdr_reloc_info_.new_offset; } -// Operator+= -// ========== -Binary& Binary::operator+=(const DynamicEntry& entry) { - add(entry); - return *this; -} - -Binary& Binary::operator+=(const Section& section) { - add(section); - return *this; -} - -Binary& Binary::operator+=(const Segment& segment) { - add(segment); - return *this; -} - -Binary& Binary::operator+=(const Note& note) { - add(note); - return *this; -} - -// Operator -= -// =========== -Binary& Binary::operator-=(const DynamicEntry& entry) { - remove(entry); - return *this; -} - -Binary& Binary::operator-=(DYNAMIC_TAGS tag) { - remove(tag); - return *this; -} - - -Binary& Binary::operator-=(const Note& note) { - remove(note); - return *this; -} - -Binary& Binary::operator-=(Note::TYPE type) { - remove(type); - return *this; -} - -// Operator[] -// ========== -Segment* Binary::operator[](SEGMENT_TYPES type) { - return get(type); -} - -const Segment* Binary::operator[](SEGMENT_TYPES type) const { - return get(type); -} - -DynamicEntry* Binary::operator[](DYNAMIC_TAGS tag) { - return get(tag); -} - -const DynamicEntry* Binary::operator[](DYNAMIC_TAGS tag) const { - return get(tag); -} - -Note* Binary::operator[](Note::TYPE type) { - return get(type); -} - -const Note* Binary::operator[](Note::TYPE type) const { - return get(type); -} - -Section* Binary::operator[](ELF_SECTION_TYPES type) { - return get(type); -} - -const Section* Binary::operator[](ELF_SECTION_TYPES type) const { - return get(type); -} - - - - - std::ostream& Binary::print(std::ostream& os) const { os << "Header" << std::endl; diff --git a/src/ELF/Binary.tcc b/src/ELF/Binary.tcc index 05ca73ae68..e96054de74 100644 --- a/src/ELF/Binary.tcc +++ b/src/ELF/Binary.tcc @@ -41,7 +41,7 @@ namespace ELF { // ARM Relocations // =============== template<> -void Binary::patch_relocations(uint64_t from, uint64_t shift) { +void Binary::patch_relocations(uint64_t from, uint64_t shift) { for (Relocation& relocation : relocations()) { if (relocation.address() >= from) { @@ -49,13 +49,13 @@ void Binary::patch_relocations(uint64_t from, uint64_t shift) { relocation.address(relocation.address() + shift); } - const auto type = static_cast(relocation.type()); + const Relocation::TYPE type = relocation.type(); switch (type) { - case RELOC_ARM::R_ARM_JUMP_SLOT: - case RELOC_ARM::R_ARM_RELATIVE: - case RELOC_ARM::R_ARM_GLOB_DAT: - case RELOC_ARM::R_ARM_IRELATIVE: + case Relocation::TYPE::ARM_JUMP_SLOT: + case Relocation::TYPE::ARM_RELATIVE: + case Relocation::TYPE::ARM_GLOB_DAT: + case Relocation::TYPE::ARM_IRELATIVE: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); @@ -75,7 +75,7 @@ void Binary::patch_relocations(uint64_t from, uint64_t shift) { // AARCH64 Relocations // =================== template<> -void Binary::patch_relocations(uint64_t from, uint64_t shift) { +void Binary::patch_relocations(uint64_t from, uint64_t shift) { for (Relocation& relocation : relocations()) { if (relocation.address() >= from) { @@ -83,50 +83,49 @@ void Binary::patch_relocations(uint64_t from, uint64_t shift) relocation.address(relocation.address() + shift); } - const auto type = static_cast(relocation.type()); + const Relocation::TYPE type = relocation.type(); switch (type) { - case RELOC_AARCH64::R_AARCH64_JUMP_SLOT: - case RELOC_AARCH64::R_AARCH64_RELATIVE: - case RELOC_AARCH64::R_AARCH64_GLOB_DAT: - case RELOC_AARCH64::R_AARCH64_IRELATIVE: - case RELOC_AARCH64::R_AARCH64_ABS64: + case Relocation::TYPE::AARCH64_JUMP_SLOT: + case Relocation::TYPE::AARCH64_RELATIVE: + case Relocation::TYPE::AARCH64_GLOB_DAT: + case Relocation::TYPE::AARCH64_IRELATIVE: + case Relocation::TYPE::AARCH64_ABS64: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - case RELOC_AARCH64::R_AARCH64_ABS32: + case Relocation::TYPE::AARCH64_ABS32: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - case RELOC_AARCH64::R_AARCH64_ABS16: + case Relocation::TYPE::AARCH64_ABS16: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - - case RELOC_AARCH64::R_AARCH64_PREL64: + case Relocation::TYPE::AARCH64_PREL64: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - case RELOC_AARCH64::R_AARCH64_PREL32: + case Relocation::TYPE::AARCH64_PREL32: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - case RELOC_AARCH64::R_AARCH64_PREL16: + case Relocation::TYPE::AARCH64_PREL16: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); @@ -145,28 +144,28 @@ void Binary::patch_relocations(uint64_t from, uint64_t shift) // x86_32 Relocations // ================== template<> -void Binary::patch_relocations(uint64_t from, uint64_t shift) { +void Binary::patch_relocations(uint64_t from, uint64_t shift) { for (Relocation& relocation : relocations()) { if (relocation.address() >= from) { //shift_code(relocation.address(), shift, relocation.size() / 8); relocation.address(relocation.address() + shift); } - const auto type = static_cast(relocation.type()); + const Relocation::TYPE type = relocation.type(); switch (type) { - case RELOC_i386::R_386_RELATIVE: - case RELOC_i386::R_386_JUMP_SLOT: - case RELOC_i386::R_386_IRELATIVE: - case RELOC_i386::R_386_GLOB_DAT: - case RELOC_i386::R_386_32: + case Relocation::TYPE::X86_RELATIVE: + case Relocation::TYPE::X86_JUMP_SLOT: + case Relocation::TYPE::X86_IRELATIVE: + case Relocation::TYPE::X86_GLOB_DAT: + case Relocation::TYPE::X86_32: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - case RELOC_i386::R_386_TLS_DTPMOD32: - case RELOC_i386::R_386_TLS_DTPOFF32: + case Relocation::TYPE::X86_TLS_DTPMOD32: + case Relocation::TYPE::X86_TLS_DTPOFF32: { // Nothing to do for these relocations continue; @@ -184,27 +183,28 @@ void Binary::patch_relocations(uint64_t from, uint64_t shift) { // x86_64 Relocations // ================== template<> -void Binary::patch_relocations(uint64_t from, uint64_t shift) { +void Binary::patch_relocations(uint64_t from, uint64_t shift) { for (Relocation& relocation : relocations()) { if (relocation.address() >= from) { //shift_code(relocation.address(), shift, relocation.size() / 8); relocation.address(relocation.address() + shift); } - const auto type = static_cast(relocation.type()); + const Relocation::TYPE type = relocation.type(); + switch (type) { - case RELOC_x86_64::R_X86_64_RELATIVE: - case RELOC_x86_64::R_X86_64_IRELATIVE: - case RELOC_x86_64::R_X86_64_JUMP_SLOT: - case RELOC_x86_64::R_X86_64_GLOB_DAT: - case RELOC_x86_64::R_X86_64_64: + case Relocation::TYPE::X86_64_RELATIVE: + case Relocation::TYPE::X86_64_IRELATIVE: + case Relocation::TYPE::X86_64_JUMP_SLOT: + case Relocation::TYPE::X86_64_GLOB_DAT: + case Relocation::TYPE::X86_64_64: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); break; } - case RELOC_x86_64::R_X86_64_32: + case Relocation::TYPE::X86_64_32: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); @@ -224,16 +224,16 @@ void Binary::patch_relocations(uint64_t from, uint64_t shift) { // PPC_32 Relocations // ================== template<> -void Binary::patch_relocations(uint64_t from, uint64_t shift) { +void Binary::patch_relocations(uint64_t from, uint64_t shift) { for (Relocation& relocation : relocations()) { if (relocation.address() >= from) { relocation.address(relocation.address() + shift); } - const auto type = static_cast(relocation.type()); + const Relocation::TYPE type = relocation.type(); switch (type) { - case RELOC_POWERPC32::R_PPC_RELATIVE: + case Relocation::TYPE::PPC_RELATIVE: { LIEF_DEBUG("Patch addend of {}", relocation); patch_addend(relocation, from, shift); @@ -309,7 +309,7 @@ void Binary::patch_addend(Relocation& relocation, uint64_t from, uint64_t shift) // To do so, we would just need to extend the PT_LOAD segment associated // with the caving. template<> -Segment* Binary::add_segment(const Segment& segment, uint64_t base) { +Segment* Binary::add_segment(const Segment& segment, uint64_t base) { Header& header = this->header(); const uint64_t new_phdr_offset = relocate_phdr_table_auto(); @@ -393,7 +393,7 @@ Segment* Binary::add_segment(const Segment& segment, uint64_t b // ET_DYN (PIE/Libraries) // ======================= template<> -Segment* Binary::add_segment(const Segment& segment, uint64_t base) { +Segment* Binary::add_segment(const Segment& segment, uint64_t base) { const auto psize = static_cast(getpagesize()); /*const uint64_t new_phdr_offset = */ relocate_phdr_table_auto(); @@ -464,7 +464,7 @@ Segment* Binary::add_segment(const Segment& segment, uint64_t ba // Extend PT_LOAD // ======================= template<> -Segment* Binary::extend_segment(const Segment& segment, uint64_t size) { +Segment* Binary::extend_segment(const Segment& segment, uint64_t size) { const auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), [&segment] (const std::unique_ptr& s) { @@ -512,7 +512,7 @@ Segment* Binary::extend_segment(const Segment& segment, shift_symbols(from_address, shift); shift_relocations(from_address, shift); - if (type() == ELF_CLASS::ELFCLASS32) { + if (type() == Header::CLASS::ELF32) { fix_got_entries(from_address, shift); } else { fix_got_entries(from_address, shift); @@ -533,7 +533,7 @@ Section* Binary::add_section(const Section& section) { Segment new_segment; span content_ref = section.content(); new_segment.content({std::begin(content_ref), std::end(content_ref)}); - new_segment.type(SEGMENT_TYPES::PT_LOAD); + new_segment.type(Segment::TYPE::LOAD); new_segment.virtual_address(section.virtual_address()); new_segment.physical_address(section.virtual_address()); @@ -542,14 +542,14 @@ Section* Binary::add_section(const Section& section) { new_segment.file_offset(section.offset()); new_segment.alignment(section.alignment()); - new_segment.add(ELF_SEGMENT_FLAGS::PF_R); + new_segment.add(Segment::FLAGS::R); - if (section.has(ELF_SECTION_FLAGS::SHF_WRITE)) { - new_segment.add(ELF_SEGMENT_FLAGS::PF_W); + if (section.has(Section::FLAGS::WRITE)) { + new_segment.add(Segment::FLAGS::W); } - if (section.has(ELF_SECTION_FLAGS::SHF_EXECINSTR)) { - new_segment.add(ELF_SEGMENT_FLAGS::PF_X); + if (section.has(Section::FLAGS::EXECINSTR)) { + new_segment.add(Segment::FLAGS::X); } Segment* segment_added = add(new_segment); @@ -625,7 +625,7 @@ template void Binary::fix_got_entries(uint64_t from, uint64_t shift) { using ptr_t = typename ELF_T::Elf_Addr; - DynamicEntry* dt_pltgot = get(DYNAMIC_TAGS::DT_PLTGOT); + DynamicEntry* dt_pltgot = get(DynamicEntry::TAG::PLTGOT); if (dt_pltgot == nullptr) { return; } diff --git a/src/ELF/Builder.cpp b/src/ELF/Builder.cpp index 70a5fa611b..82e1c7a162 100644 --- a/src/ELF/Builder.cpp +++ b/src/ELF/Builder.cpp @@ -35,24 +35,23 @@ namespace LIEF { namespace ELF { - Builder::~Builder() = default; Builder::Builder(Binary& binary) : binary_{&binary}, layout_{nullptr} { - const E_TYPE type = binary.header().file_type(); + const Header::FILE_TYPE type = binary.header().file_type(); switch (type) { - case E_TYPE::ET_CORE: - case E_TYPE::ET_DYN: - case E_TYPE::ET_EXEC: + case Header::FILE_TYPE::CORE: + case Header::FILE_TYPE::DYN: + case Header::FILE_TYPE::EXEC: { layout_ = std::make_unique(binary); break; } - case E_TYPE::ET_REL: + case Header::FILE_TYPE::REL: { layout_ = std::make_unique(binary); break; @@ -87,16 +86,10 @@ bool Builder::should_swap() const { void Builder::build() { - if (binary_->type() == ELF_CLASS::ELFCLASS32) { - auto res = build(); - if (!res) { - LIEF_ERR("Builder failed"); - } - } else { - auto res = build(); - if (!res) { - LIEF_ERR("Builder failed"); - } + auto res = binary_->type() == Header::CLASS::ELF32 ? + build() : build(); + if (!res) { + LIEF_ERR("Builder failed"); } } @@ -124,8 +117,9 @@ uint32_t Builder::sort_dynamic_symbols() { const auto it_end = std::end(binary_->dynamic_symbols_); const auto it_first_non_local_symbol = - std::stable_partition(it_begin, it_end, [] (const std::unique_ptr& sym) { - return sym->binding() == SYMBOL_BINDINGS::STB_LOCAL; + std::stable_partition(it_begin, it_end, + [] (const std::unique_ptr& sym) { + return sym->is_local(); }); const uint32_t first_non_local_symbol_index = std::distance(it_begin, it_first_non_local_symbol); @@ -144,7 +138,7 @@ uint32_t Builder::sort_dynamic_symbols() { const auto it_first_exported_symbol = std::stable_partition( it_first_non_local_symbol, it_end, [] (const std::unique_ptr& sym) { - return sym->shndx() == static_cast(SYMBOL_SECTION_INDEX::SHN_UNDEF); + return sym->shndx() == Symbol::SECTION_INDEX::UNDEF; }); const uint32_t first_exported_symbol_index = std::distance(it_begin, it_first_exported_symbol); @@ -154,7 +148,7 @@ uint32_t Builder::sort_dynamic_symbols() { ok_error_t Builder::build_empty_symbol_gnuhash() { LIEF_DEBUG("Build empty GNU Hash"); - Section* gnu_hash_section = binary_->get(ELF_SECTION_TYPES::SHT_GNU_HASH); + Section* gnu_hash_section = binary_->get(Section::TYPE::GNU_HASH); if (gnu_hash_section == nullptr) { LIEF_ERR("Can't find section with type SHT_GNU_HASH"); @@ -188,7 +182,7 @@ ok_error_t Builder::build_empty_symbol_gnuhash() { ok_error_t Builder::update_note_section(const Note& note, std::set& notes) { - Segment* segment_note = binary_->get(SEGMENT_TYPES::PT_NOTE); + Segment* segment_note = binary_->get(Segment::TYPE::NOTE); if (segment_note == nullptr) { LIEF_ERR("Can't find the PT_NOTE segment"); return make_error_code(lief_errors::not_found); @@ -227,7 +221,7 @@ ok_error_t Builder::update_note_section(const Note& note, note_sec->virtual_address(segment_note->virtual_address() + note_offset); if (note.type() == Note::TYPE::GNU_PROPERTY_TYPE_0) { - if (Segment* seg = binary_->get(SEGMENT_TYPES::PT_GNU_PROPERTY)) { + if (Segment* seg = binary_->get(Segment::TYPE::GNU_PROPERTY)) { seg->file_offset(note_sec->offset()); seg->physical_size(note_sec->size()); seg->virtual_address(note_sec->virtual_address()); diff --git a/src/ELF/Builder.tcc b/src/ELF/Builder.tcc index b96d613b49..409d724955 100644 --- a/src/ELF/Builder.tcc +++ b/src/ELF/Builder.tcc @@ -60,14 +60,14 @@ namespace ELF { template ok_error_t Builder::build() { - const char* type = ((binary_->type_ == ELF_CLASS::ELFCLASS32) ? "ELF32" : "ELF64"); + const char* type = ((binary_->type_ == Header::CLASS::ELF32) ? "ELF32" : "ELF64"); LIEF_DEBUG("== Re-building {} ==", type); - const E_TYPE file_type = binary_->header().file_type(); + const Header::FILE_TYPE file_type = binary_->header().file_type(); switch (file_type) { - case E_TYPE::ET_DYN: - case E_TYPE::ET_EXEC: - case E_TYPE::ET_CORE: + case Header::FILE_TYPE::DYN: + case Header::FILE_TYPE::EXEC: + case Header::FILE_TYPE::CORE: { auto res = build_exe_lib(); if (!res) { @@ -78,7 +78,7 @@ ok_error_t Builder::build() { return ok(); } - case E_TYPE::ET_REL: + case Header::FILE_TYPE::REL: { auto res = build_relocatable(); if (!res) { @@ -105,7 +105,7 @@ ok_error_t Builder::build_exe_lib() { uint32_t new_symndx = sort_dynamic_symbols(); layout->set_dyn_sym_idx(new_symndx); - Segment* pt_interp = binary_->get(SEGMENT_TYPES::PT_INTERP); + Segment* pt_interp = binary_->get(Segment::TYPE::INTERP); if (config_.interpreter) { if (pt_interp != nullptr) { const size_t interpt_size = layout->interpreter_size(); @@ -125,11 +125,11 @@ ok_error_t Builder::build_exe_lib() { } } - if (binary_->has(SEGMENT_TYPES::PT_NOTE) && config_.notes) { + if (binary_->has(Segment::TYPE::NOTE) && config_.notes) { const size_t notes_size = layout->note_size(); std::vector note_segments; for (std::unique_ptr& seg : binary_->segments_) { - if (seg->type() == SEGMENT_TYPES::PT_NOTE) { + if (seg->type() == Segment::TYPE::NOTE) { note_segments.push_back(seg.get()); } } @@ -151,7 +151,7 @@ ok_error_t Builder::build_exe_lib() { } else { /*LIEF_DEBUG(".notes: -0x{:x} bytes", note_segment.physical_size() - notes_size);*/ } } - if (binary_->has(DYNAMIC_TAGS::DT_GNU_HASH) && config_.gnu_hash) { + if (binary_->has(DynamicEntry::TAG::GNU_HASH) && config_.gnu_hash) { const size_t needed_size = layout->symbol_gnu_hash_size(); const uint64_t osize = binary_->sizing_info_->gnu_hash; const bool should_relocate = needed_size > osize || config_.force_relocate; @@ -161,7 +161,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_GNU_HASH: -0x{:x} bytes", osize - needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_HASH) && config_.dt_hash) { + if (binary_->has(DynamicEntry::TAG::HASH) && config_.dt_hash) { const size_t needed_size = layout->symbol_sysv_hash_size(); const uint64_t osize = binary_->sizing_info_->hash; const bool should_relocate = needed_size > osize || config_.force_relocate; @@ -171,7 +171,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_HASH: -0x{:x} bytes", osize - needed_size); } } - if (binary_->has(SEGMENT_TYPES::PT_DYNAMIC) && config_.dynamic_section) { + if (binary_->has(Segment::TYPE::DYNAMIC) && config_.dynamic_section) { const size_t dynamic_needed_size = layout->dynamic_size(); const uint64_t osize = binary_->sizing_info_->dynamic; const bool should_relocate = dynamic_needed_size > osize || config_.force_relocate; @@ -181,7 +181,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("PT_DYNAMIC: -0x{:x} bytes", osize - dynamic_needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_RELA) || binary_->has(DYNAMIC_TAGS::DT_REL)) { + if (binary_->has(DynamicEntry::TAG::RELA) || binary_->has(DynamicEntry::TAG::REL)) { const size_t dyn_reloc_needed_size = layout->dynamic_relocations_size(); if (config_.rela) { const uint64_t osize = binary_->sizing_info_->rela; @@ -193,7 +193,7 @@ ok_error_t Builder::build_exe_lib() { } } - if (config_.jmprel && binary_->has(DYNAMIC_TAGS::DT_JMPREL)) { + if (config_.jmprel && binary_->has(DynamicEntry::TAG::JMPREL)) { const size_t plt_reloc_needed_size = layout->pltgot_relocations_size(); const uint64_t osize = binary_->sizing_info_->jmprel; const bool should_relocate = plt_reloc_needed_size > osize || config_.force_relocate; @@ -203,7 +203,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_JMPREL: -0x{:x} bytes", osize - plt_reloc_needed_size); } } - if (config_.dyn_str && binary_->has(DYNAMIC_TAGS::DT_STRTAB)) { + if (config_.dyn_str && binary_->has(DynamicEntry::TAG::STRTAB)) { const size_t needed_size = layout->dynstr_size(); const uint64_t osize = binary_->sizing_info_->dynstr; const bool should_relocate = needed_size > osize || config_.force_relocate; @@ -213,7 +213,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_STRTAB: -0x{:x} bytes", osize - needed_size); } } - if (config_.symtab && binary_->has(DYNAMIC_TAGS::DT_SYMTAB)) { + if (config_.symtab && binary_->has(DynamicEntry::TAG::SYMTAB)) { const size_t dynsym_needed_size = layout->dynsym_size(); const uint64_t osize = binary_->sizing_info_->dynsym; const bool should_relocate = dynsym_needed_size > osize || config_.force_relocate; @@ -223,10 +223,10 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_SYMTAB: -0x{:x} bytes", osize - dynsym_needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_INIT_ARRAY) && binary_->has(DYNAMIC_TAGS::DT_INIT_ARRAYSZ) && + if (binary_->has(DynamicEntry::TAG::INIT_ARRAY) && binary_->has(DynamicEntry::TAG::INIT_ARRAYSZ) && config_.init_array) { - const size_t needed_size = layout->dynamic_arraysize(DYNAMIC_TAGS::DT_INIT_ARRAY); + const size_t needed_size = layout->dynamic_arraysize(DynamicEntry::TAG::INIT_ARRAY); const uint64_t osize = binary_->sizing_info_->init_array; const bool should_relocate = needed_size > osize; if (should_relocate) { @@ -238,10 +238,10 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_INIT_ARRAY: -0x{:x} bytes", osize - needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_PREINIT_ARRAY) && binary_->has(DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ) && + if (binary_->has(DynamicEntry::TAG::PREINIT_ARRAY) && binary_->has(DynamicEntry::TAG::PREINIT_ARRAYSZ) && config_.preinit_array) { - const size_t needed_size = layout->dynamic_arraysize(DYNAMIC_TAGS::DT_PREINIT_ARRAY); + const size_t needed_size = layout->dynamic_arraysize(DynamicEntry::TAG::PREINIT_ARRAY); const uint64_t osize = binary_->sizing_info_->preinit_array; const bool should_relocate = needed_size > osize; if (should_relocate) { @@ -250,10 +250,10 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_PREINIT_ARRAY: -0x{:x} bytes", osize - needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_FINI_ARRAY) && binary_->has(DYNAMIC_TAGS::DT_FINI_ARRAYSZ) && + if (binary_->has(DynamicEntry::TAG::FINI_ARRAY) && binary_->has(DynamicEntry::TAG::FINI_ARRAYSZ) && config_.fini_array) { - const size_t needed_size = layout->dynamic_arraysize(DYNAMIC_TAGS::DT_FINI_ARRAY); + const size_t needed_size = layout->dynamic_arraysize(DynamicEntry::TAG::FINI_ARRAY); const uint64_t osize = binary_->sizing_info_->fini_array; const bool should_relocate = needed_size > osize; if (should_relocate) { @@ -265,7 +265,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_FINI_ARRAY: -0x{:x} bytes", osize - needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_VERSYM) && config_.sym_versym) { + if (binary_->has(DynamicEntry::TAG::VERSYM) && config_.sym_versym) { const size_t symver_needed_size = layout->symbol_version(); const uint64_t osize = binary_->sizing_info_->versym; const bool should_relocate = symver_needed_size > osize || config_.force_relocate; @@ -275,7 +275,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_VERSYM: -0x{:x} bytes", osize - symver_needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_VERDEF) && config_.sym_verdef) { + if (binary_->has(DynamicEntry::TAG::VERDEF) && config_.sym_verdef) { const size_t symvdef_needed_size = layout->symbol_vdef_size(); const uint64_t osize = binary_->sizing_info_->verdef; const bool should_relocate = symvdef_needed_size > osize || config_.force_relocate; @@ -285,7 +285,7 @@ ok_error_t Builder::build_exe_lib() { } else { LIEF_DEBUG("DT_VERDEF: -0x{:x} bytes", osize - symvdef_needed_size); } } - if (binary_->has(DYNAMIC_TAGS::DT_VERNEED) && config_.sym_verneed) { + if (binary_->has(DynamicEntry::TAG::VERNEED) && config_.sym_verneed) { const size_t symvreq_needed_size = layout->symbol_vreq_size(); const uint64_t osize = binary_->sizing_info_->verneed; const bool should_relocate = symvreq_needed_size > osize || config_.force_relocate; @@ -311,7 +311,7 @@ ok_error_t Builder::build_exe_lib() { } // Check if we should relocate or create the .strtab section - Section* sec_symtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* sec_symtab = binary_->get(Section::TYPE::SYMTAB); if (!layout->is_strtab_shared_shstrtab() && !binary_->static_symbols_.empty()) { // There is no .symtab section => create .strtab if (sec_symtab == nullptr) { @@ -371,36 +371,36 @@ ok_error_t Builder::build_exe_lib() { } if (config_.dyn_str) { - if (DynamicEntry* dt_strtab = binary_->get(DYNAMIC_TAGS::DT_STRTAB)) { + if (DynamicEntry* dt_strtab = binary_->get(DynamicEntry::TAG::STRTAB)) { binary_->patch_address(dt_strtab->value(), layout->raw_dynstr()); } } - if (config_.interpreter && binary_->has(SEGMENT_TYPES::PT_INTERP)) { + if (config_.interpreter && binary_->has(Segment::TYPE::INTERP)) { build_interpreter(); } - if (config_.notes && binary_->has(SEGMENT_TYPES::PT_NOTE)) { + if (config_.notes && binary_->has(Segment::TYPE::NOTE)) { build_notes(); } - if (config_.dynamic_section && binary_->has(SEGMENT_TYPES::PT_DYNAMIC)) { + if (config_.dynamic_section && binary_->has(Segment::TYPE::DYNAMIC)) { build_dynamic_section(); } - if (config_.symtab && binary_->has(DYNAMIC_TAGS::DT_SYMTAB)) { + if (config_.symtab && binary_->has(DynamicEntry::TAG::SYMTAB)) { build_dynamic_symbols(); } - if (config_.sym_versym && binary_->has(DYNAMIC_TAGS::DT_VERSYM)) { + if (config_.sym_versym && binary_->has(DynamicEntry::TAG::VERSYM)) { build_symbol_version(); } - if (config_.sym_verdef && binary_->has(DYNAMIC_TAGS::DT_VERDEF)) { + if (config_.sym_verdef && binary_->has(DynamicEntry::TAG::VERDEF)) { build_symbol_definition(); } - if (config_.sym_verneed && binary_->has(DYNAMIC_TAGS::DT_VERNEED)) { + if (config_.sym_verneed && binary_->has(DynamicEntry::TAG::VERNEED)) { build_symbol_requirement(); } @@ -412,7 +412,7 @@ ok_error_t Builder::build_exe_lib() { build_pltgot_relocations(); } - if (config_.static_symtab && binary_->has(ELF_SECTION_TYPES::SHT_SYMTAB)) { + if (config_.static_symtab && binary_->has(Section::TYPE::SYMTAB)) { build_static_symbols(); } @@ -458,8 +458,8 @@ ok_error_t Builder::process_object_relocations() { ObjectFileLayout::rel_sections_size_t& rel_sections_size = layout->rel_sections_size(); for (Section& sec : sections) { - const ELF_SECTION_TYPES type = sec.type(); - if (type != ELF_SECTION_TYPES::SHT_RELA && type != ELF_SECTION_TYPES::SHT_REL) { + const Section::TYPE type = sec.type(); + if (type != Section::TYPE::RELA && type != Section::TYPE::REL) { continue; } const size_t sh_info = sec.information(); @@ -523,7 +523,7 @@ ok_error_t Builder::build_relocatable() { } // Check the .symtab section - Section* symtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* symtab = binary_->get(Section::TYPE::SYMTAB); if (symtab != nullptr) { const size_t needed_size = layout->symtab_size(); if (needed_size > symtab->size() || config_.force_relocate) { @@ -536,7 +536,7 @@ ok_error_t Builder::build_relocatable() { // Check if we should relocate or create a .strtab section. // We assume that a .shstrtab is always prensent if (!layout->is_strtab_shared_shstrtab() && !binary_->static_symbols_.empty()) { - Section* sec_symtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* sec_symtab = binary_->get(Section::TYPE::SYMTAB); if (sec_symtab == nullptr) { LIEF_ERR("Object file without a symtab section is not supported. Please consider submitting an issue."); return make_error_code(lief_errors::not_supported); @@ -565,7 +565,7 @@ ok_error_t Builder::build_relocatable() { return make_error_code(lief_errors::build_error); } - if (binary_->has(ELF_SECTION_TYPES::SHT_SYMTAB)) { + if (binary_->has(Section::TYPE::SYMTAB)) { build_obj_symbols(); } @@ -654,7 +654,7 @@ ok_error_t Builder::build_sections() { // SHT_NOTBITS sections should not be considered. // Nevertheless, some (malformed or tricky) ELF binaries // might use this type to put content. - section->type() != ELF_SECTION_TYPES::SHT_NOBITS) { + section->type() != Section::TYPE::NOBITS) { span content = section->content(); LIEF_DEBUG("[Content] {:20}: 0x{:010x} - 0x{:010x} (0x{:x})", section->name(), section->file_offset(), @@ -725,7 +725,7 @@ ok_error_t Builder::build_segments() { pheaders.write_conv(phdr); } - Segment* phdr_segment = binary_->get(SEGMENT_TYPES::PT_PHDR); + Segment* phdr_segment = binary_->get(Segment::TYPE::PHDR); if (phdr_segment != nullptr) { phdr_segment->content(pheaders.raw()); } @@ -774,11 +774,7 @@ ok_error_t Builder::build_static_symbols() { std::stable_sort(std::begin(binary_->static_symbols_), std::end(binary_->static_symbols_), [](const std::unique_ptr& lhs, const std::unique_ptr& rhs) { - return lhs->binding() == SYMBOL_BINDINGS::STB_LOCAL && - ( - rhs->binding() == SYMBOL_BINDINGS::STB_GLOBAL || - rhs->binding() == SYMBOL_BINDINGS::STB_WEAK - ); + return lhs->is_local() && (rhs->is_global() || rhs->is_weak()); }); const auto it_first_exported_symbol = @@ -853,7 +849,7 @@ ok_error_t Builder::build_dynamic_section() { for (std::unique_ptr& entry : binary_->dynamic_entries_) { switch (entry->tag()) { - case DYNAMIC_TAGS::DT_NEEDED: + case DynamicEntry::TAG::NEEDED: { const std::string& name = entry->as()->name(); const auto& it = dynstr_map.find(name); @@ -865,7 +861,7 @@ ok_error_t Builder::build_dynamic_section() { break; } - case DYNAMIC_TAGS::DT_SONAME: + case DynamicEntry::TAG::SONAME: { const std::string& name = entry->as()->name(); const auto& it = dynstr_map.find(name); @@ -877,9 +873,9 @@ ok_error_t Builder::build_dynamic_section() { break; } - case DYNAMIC_TAGS::DT_RPATH: + case DynamicEntry::TAG::RPATH: { - const std::string& name = entry->as()->name(); + const std::string& name = entry->as()->rpath(); const auto& it = dynstr_map.find(name); if (it == std::end(dynstr_map)) { LIEF_ERR("Can't find string offset in .dynstr for {}", name); @@ -889,9 +885,9 @@ ok_error_t Builder::build_dynamic_section() { break; } - case DYNAMIC_TAGS::DT_RUNPATH: + case DynamicEntry::TAG::RUNPATH: { - const std::string& name = entry->as()->name(); + const std::string& name = entry->as()->runpath(); const auto& it = dynstr_map.find(name); if (it == std::end(dynstr_map)) { LIEF_ERR("Can't find string offset in .dynstr for {}", name); @@ -901,10 +897,10 @@ ok_error_t Builder::build_dynamic_section() { break; } - case DYNAMIC_TAGS::DT_INIT_ARRAY: + case DynamicEntry::TAG::INIT_ARRAY: { if (config_.init_array) { - DynamicEntry* dt_array_size = binary_->get(DYNAMIC_TAGS::DT_INIT_ARRAYSZ); + DynamicEntry* dt_array_size = binary_->get(DynamicEntry::TAG::INIT_ARRAYSZ); if (dt_array_size == nullptr) { LIEF_ERR("Can't find the DT_INIT_ARRAYSZ / .init_array"); break; @@ -923,10 +919,10 @@ ok_error_t Builder::build_dynamic_section() { break; } - case DYNAMIC_TAGS::DT_FINI_ARRAY: + case DynamicEntry::TAG::FINI_ARRAY: { if (config_.fini_array) { - DynamicEntry* dt_array_size = binary_->get(DYNAMIC_TAGS::DT_FINI_ARRAYSZ); + DynamicEntry* dt_array_size = binary_->get(DynamicEntry::TAG::FINI_ARRAYSZ); if (dt_array_size == nullptr) { LIEF_ERR("Can't find the DT_FINI_ARRAYSZ / .fini_array"); break; @@ -946,10 +942,10 @@ ok_error_t Builder::build_dynamic_section() { break; } - case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + case DynamicEntry::TAG::PREINIT_ARRAY: { if (config_.fini_array) { - DynamicEntry* dt_array_size = binary_->get(DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ); + DynamicEntry* dt_array_size = binary_->get(DynamicEntry::TAG::PREINIT_ARRAYSZ); if (dt_array_size == nullptr) { LIEF_ERR("Can't find the DT_PREINIT_ARRAYSZ / .preinit_array"); break; @@ -977,7 +973,7 @@ ok_error_t Builder::build_dynamic_section() { } Elf_Dyn dynhdr; - dynhdr.d_tag = static_cast(entry->tag()); + dynhdr.d_tag = static_cast(DynamicEntry::to_value(entry->tag())); dynhdr.d_un.d_val = static_cast(entry->value()); dynamic_table_raw.write_conv(dynhdr); @@ -993,7 +989,7 @@ ok_error_t Builder::build_dynamic_section() { } // Update the PT_DYNAMIC segment - if (Segment* dynamic_seg = binary_->get(SEGMENT_TYPES::PT_DYNAMIC)) { + if (Segment* dynamic_seg = binary_->get(Segment::TYPE::DYNAMIC)) { dynamic_seg->physical_size(raw.size()); dynamic_seg->virtual_size(raw.size()); dynamic_seg->content(std::move(raw)); @@ -1008,7 +1004,7 @@ ok_error_t Builder::build_dynamic_section() { template ok_error_t Builder::build_symbol_hash() { LIEF_DEBUG("== Build SYSV Hash =="); - DynamicEntry* dt_hash = binary_->get(DYNAMIC_TAGS::DT_HASH); + DynamicEntry* dt_hash = binary_->get(DynamicEntry::TAG::HASH); if (dt_hash == nullptr) { LIEF_ERR("Can't find the SYSV hash section"); @@ -1041,7 +1037,7 @@ ok_error_t Builder::build_symbol_hash() { uint32_t* chain = &new_hash_table_ptr[2 + nbucket]; uint32_t idx = 0; for (const std::unique_ptr& symbol : binary_->dynamic_symbols_) { - uint32_t hash = binary_->type_ == ELF_CLASS::ELFCLASS32 ? + uint32_t hash = binary_->type_ == Header::CLASS::ELF32 ? hash32(symbol->name().c_str()) : hash64(symbol->name().c_str()); @@ -1082,7 +1078,7 @@ ok_error_t Builder::build_hash_table() { LIEF_DEBUG("== Build hash table =="); bool has_error = false; - if (config_.dt_hash && binary_->has(DYNAMIC_TAGS::DT_HASH)) { + if (config_.dt_hash && binary_->has(DynamicEntry::TAG::HASH)) { if (!build_symbol_hash()) { LIEF_ERR("Building the new SYSV Hash section failed"); has_error = true; @@ -1090,7 +1086,7 @@ ok_error_t Builder::build_hash_table() { } if (config_.gnu_hash) { - if (const DynamicEntry* entry = binary_->get(DYNAMIC_TAGS::DT_GNU_HASH)) { + if (const DynamicEntry* entry = binary_->get(DynamicEntry::TAG::GNU_HASH)) { binary_->patch_address(entry->value(), static_cast(layout_.get())->raw_gnuhash()); } } @@ -1119,7 +1115,7 @@ ok_error_t Builder::build_obj_symbols() { } // Find the section associated with the address - Section* symbol_table_section = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* symbol_table_section = binary_->get(Section::TYPE::SYMTAB); if (symbol_table_section == nullptr) { LIEF_ERR("Can't find the .symtab section"); return make_error_code(lief_errors::file_format_error); @@ -1168,7 +1164,7 @@ ok_error_t Builder::build_dynamic_symbols() { // Find useful sections // ==================== - DynamicEntry* dt_symtab = binary_->get(DYNAMIC_TAGS::DT_SYMTAB); + DynamicEntry* dt_symtab = binary_->get(DynamicEntry::TAG::SYMTAB); if (dt_symtab == nullptr) { LIEF_ERR("Can't find the DT_SYMTAB entry"); return make_error_code(lief_errors::not_found); @@ -1256,10 +1252,10 @@ ok_error_t Builder::build_section_relocations() { Elf_Xword info = 0; if (std::is_same::value) { - info = (static_cast(symidx) << 8) | reloc->type(); + info = (static_cast(symidx) << 8) | Relocation::to_value(reloc->type()); } else { // NOTE: To suppress a warning we require a cast here, this path is not constexpr but only uses Elf64_Xword - info = (static_cast(symidx) << 32) | (reloc->type() & 0xffffffffL); + info = (static_cast(symidx) << 32) | (Relocation::to_value(reloc->type()) & 0xffffffffL); } if (is_rela) { @@ -1297,12 +1293,12 @@ ok_error_t Builder::build_dynamic_relocations() { Binary::it_dynamic_relocations dynamic_relocations = binary_->dynamic_relocations(); if (dynamic_relocations.empty()) { - if (auto* DT = binary_->get(DYNAMIC_TAGS::DT_REL)) { + if (auto* DT = binary_->get(DynamicEntry::TAG::REL)) { if (auto* sec = binary_->section_from_virtual_address(DT->value())) { sec->size(0); } } - if (auto* DT = binary_->get(DYNAMIC_TAGS::DT_RELA)) { + if (auto* DT = binary_->get(DynamicEntry::TAG::RELA)) { if (auto* sec = binary_->section_from_virtual_address(DT->value())) { sec->size(0); } @@ -1314,16 +1310,16 @@ ok_error_t Builder::build_dynamic_relocations() { DynamicEntry* dt_reloc = nullptr; DynamicEntry* dt_relocsz = nullptr; - DynamicEntry* dt_rela = binary_->get(DYNAMIC_TAGS::DT_RELA); + DynamicEntry* dt_rela = binary_->get(DynamicEntry::TAG::RELA); const bool is_rela = dt_rela != nullptr; if (dt_rela != nullptr) { dt_reloc = dt_rela; - dt_relocsz = binary_->get(DYNAMIC_TAGS::DT_RELASZ); + dt_relocsz = binary_->get(DynamicEntry::TAG::RELASZ); } else { // Fallback on relation type REL - dt_reloc = binary_->get(DYNAMIC_TAGS::DT_REL); - dt_relocsz = binary_->get(DYNAMIC_TAGS::DT_RELSZ); + dt_reloc = binary_->get(DynamicEntry::TAG::REL); + dt_relocsz = binary_->get(DynamicEntry::TAG::RELSZ); } @@ -1367,10 +1363,10 @@ ok_error_t Builder::build_dynamic_relocations() { Elf_Xword r_info = 0; if (std::is_same::value) { - r_info = (static_cast(info) << 8) | relocation.type(); + r_info = (static_cast(info) << 8) | Relocation::to_value(relocation.type()); } else { // NOTE: To suppress a warning we require a cast here, this path is not constexpr but only uses Elf64_Xword - r_info = (static_cast(info) << 32) | (relocation.type() & 0xffffffffL); + r_info = (static_cast(info) << 32) | (Relocation::to_value(relocation.type()) & 0xffffffffL); } @@ -1404,7 +1400,7 @@ ok_error_t Builder::build_pltgot_relocations() { Binary::it_pltgot_relocations pltgot_relocations = binary_->pltgot_relocations(); if (pltgot_relocations.empty()) { - if (auto* DT = binary_->get(DYNAMIC_TAGS::DT_JMPREL)) { + if (auto* DT = binary_->get(DynamicEntry::TAG::JMPREL)) { if (auto* sec = binary_->section_from_virtual_address(DT->value())) { sec->size(0); } @@ -1415,12 +1411,12 @@ ok_error_t Builder::build_pltgot_relocations() { LIEF_DEBUG("[+] Building .plt.got relocations"); bool is_rela = false; - DynamicEntry* dt_pltrel = binary_->get(DYNAMIC_TAGS::DT_PLTREL); + DynamicEntry* dt_pltrel = binary_->get(DynamicEntry::TAG::PLTREL); if (dt_pltrel != nullptr) { - is_rela = dt_pltrel->value() == static_cast(DYNAMIC_TAGS::DT_RELA); + is_rela = dt_pltrel->value() == static_cast(DynamicEntry::TAG::RELA); } - DynamicEntry* dt_jmprel = binary_->get(DYNAMIC_TAGS::DT_JMPREL); - DynamicEntry* dt_pltrelsz = binary_->get(DYNAMIC_TAGS::DT_PLTRELSZ); + DynamicEntry* dt_jmprel = binary_->get(DynamicEntry::TAG::JMPREL); + DynamicEntry* dt_pltrelsz = binary_->get(DynamicEntry::TAG::PLTRELSZ); if (dt_jmprel == nullptr) { LIEF_ERR("Unable to find the DT_JMPREL entry"); return make_error_code(lief_errors::not_found); @@ -1453,11 +1449,11 @@ ok_error_t Builder::build_pltgot_relocations() { } Elf_Xword info = 0; - if (std::is_same::value) { - info = (static_cast(idx) << 8) | relocation.type(); + if constexpr (std::is_same_v) { + info = (static_cast(idx) << 8) | Relocation::to_value(relocation.type()); } else { // NOTE: To suppress a warning we require a cast here, this path is not constexpr but only uses Elf64_Xword - info = (static_cast(idx) << 32) | (relocation.type() & 0xffffffffL); + info = (static_cast(idx) << 32) | (Relocation::to_value(relocation.type()) & 0xffffffffL); } if (is_rela) { @@ -1491,13 +1487,13 @@ ok_error_t Builder::build_symbol_requirement() { using Elf_Vernaux = typename ELF_T::Elf_Vernaux; LIEF_DEBUG("[+] Building symbol requirement"); - DynamicEntry* dt_verneed = binary_->get(DYNAMIC_TAGS::DT_VERNEED); + DynamicEntry* dt_verneed = binary_->get(DynamicEntry::TAG::VERNEED); if (dt_verneed == nullptr) { LIEF_ERR("Can't find DT_VERNEED"); return make_error_code(lief_errors::not_found); } - DynamicEntry* dt_verneednum = binary_->get(DYNAMIC_TAGS::DT_VERNEEDNUM); + DynamicEntry* dt_verneednum = binary_->get(DynamicEntry::TAG::VERNEEDNUM); if (dt_verneednum == nullptr) { LIEF_ERR("Can't find DT_VERNEEDNUM"); return make_error_code(lief_errors::not_found); @@ -1595,13 +1591,13 @@ ok_error_t Builder::build_symbol_definition() { using Elf_Verdaux = typename ELF_T::Elf_Verdaux; LIEF_DEBUG("[+] Building symbol definition"); - DynamicEntry* dt_verdef = binary_->get(DYNAMIC_TAGS::DT_VERDEF); + DynamicEntry* dt_verdef = binary_->get(DynamicEntry::TAG::VERDEF); if (dt_verdef == nullptr) { LIEF_ERR("Can't find DT_VERDEF"); return make_error_code(lief_errors::not_found); } - DynamicEntry* dt_verdefnum = binary_->get(DYNAMIC_TAGS::DT_VERDEFNUM); + DynamicEntry* dt_verdefnum = binary_->get(DynamicEntry::TAG::VERDEFNUM); if (dt_verdef == nullptr) { LIEF_ERR("Can't find DT_VERDEFNUM"); return make_error_code(lief_errors::not_found); @@ -1697,7 +1693,7 @@ ok_error_t Builder::build_interpreter() { } LIEF_DEBUG("[+] Building Interpreter"); const std::string& inter_str = binary_->interpreter(); - Segment* interp_segment = binary_->get(SEGMENT_TYPES::PT_INTERP); + Segment* interp_segment = binary_->get(Segment::TYPE::INTERP); if (interp_segment == nullptr) { LIEF_ERR("Can't find a PT_INTERP segment"); return make_error_code(lief_errors::not_found); @@ -1714,7 +1710,7 @@ ok_error_t Builder::build_notes() { } LIEF_DEBUG("== Building notes =="); - Segment* note_segment = binary_->get(SEGMENT_TYPES::PT_NOTE); + Segment* note_segment = binary_->get(Segment::TYPE::NOTE); if (note_segment == nullptr) { LIEF_ERR("Can't find the PT_NOTE segment"); return make_error_code(lief_errors::not_found); @@ -1724,7 +1720,7 @@ ok_error_t Builder::build_notes() { // Write the cached note note_segment->content(static_cast(layout_.get())->raw_notes()); - if (binary_->header().file_type() == E_TYPE::ET_CORE) { + if (binary_->header().file_type() == Header::FILE_TYPE::CORE) { return ok_t(); } @@ -1745,7 +1741,7 @@ ok_error_t Builder::build_symbol_version() { binary_->symbol_version_table_.size(), binary_->dynamic_symbols_.size()); } - DynamicEntry* dt_versym = binary_->get(DYNAMIC_TAGS::DT_VERSYM); + DynamicEntry* dt_versym = binary_->get(DynamicEntry::TAG::VERSYM); if (dt_versym == nullptr) { LIEF_ERR("Can't find DT_VERSYM entry"); return make_error_code(lief_errors::not_found); diff --git a/src/ELF/CMakeLists.txt b/src/ELF/CMakeLists.txt index 7c75e91dc2..e9f95e1f9b 100644 --- a/src/ELF/CMakeLists.txt +++ b/src/ELF/CMakeLists.txt @@ -20,8 +20,10 @@ target_sources(LIB_LIEF PRIVATE Note.cpp Parser.cpp Parser.tcc + ProcessorFlags.cpp Relocation.cpp RelocationSizes.cpp + RelocationStrings.cpp Section.cpp Segment.cpp Symbol.cpp diff --git a/src/ELF/DynamicEntry.cpp b/src/ELF/DynamicEntry.cpp index dd837d340a..c619225af0 100644 --- a/src/ELF/DynamicEntry.cpp +++ b/src/ELF/DynamicEntry.cpp @@ -13,82 +13,239 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include - #include "LIEF/Visitor.hpp" -#include "LIEF/ELF/hash.hpp" #include "LIEF/ELF/DynamicEntry.hpp" -#include "LIEF/ELF/EnumToString.hpp" #include "ELF/Structures.hpp" +#include + +#include "frozen.hpp" +#include "logging.hpp" + namespace LIEF { namespace ELF { -DynamicEntry::DynamicEntry() = default; +DynamicEntry::TAG DynamicEntry::from_value(uint64_t value, ARCH arch) { + static constexpr auto LOPROC = 0x70000000; + static constexpr auto HIPROC = 0x7FFFFFFF; -DynamicEntry& DynamicEntry::operator=(const DynamicEntry&) = default; + if (LOPROC <= value && value <= HIPROC) { + switch (arch) { + case ARCH::AARCH64: + return TAG(AARCH64_DISC + value); -DynamicEntry::DynamicEntry(const DynamicEntry&) = default; + case ARCH::MIPS_RS3_LE: + case ARCH::MIPS: + return TAG(MIPS_DISC + value); -DynamicEntry::~DynamicEntry() = default; + case ARCH::HEXAGON: + return TAG(HEXAGON_DISC + value); -DynamicEntry::DynamicEntry(const details::Elf64_Dyn& header) : - tag_{static_cast(header.d_tag)}, - value_{header.d_un.d_val} -{} + case ARCH::PPC: + return TAG(PPC_DISC + value); + case ARCH::PPC64: + return TAG(PPC64_DISC + value); -DynamicEntry::DynamicEntry(const details::Elf32_Dyn& header) : - tag_{static_cast(header.d_tag)}, - value_{header.d_un.d_val} -{} + case ARCH::RISCV: + return TAG(RISCV_DISC + value); + default: + LIEF_WARN("Dynamic tag: 0x{:04x} is not supported for the " + "current architecture", value); + return TAG::UNKNOWN; + } + } -DynamicEntry::DynamicEntry(DYNAMIC_TAGS tag, uint64_t value) : - tag_{tag}, - value_{value} -{} + return TAG(value); +} +uint64_t DynamicEntry::to_value(DynamicEntry::TAG tag) { + auto raw_value = static_cast(tag); + if (MIPS_DISC <= raw_value && raw_value < AARCH64_DISC) { + return raw_value - MIPS_DISC; + } -DYNAMIC_TAGS DynamicEntry::tag() const { - return tag_; -} + if (AARCH64_DISC <= raw_value && raw_value < HEXAGON_DISC) { + return raw_value - AARCH64_DISC; + } + if (HEXAGON_DISC <= raw_value && raw_value < PPC_DISC) { + return raw_value - HEXAGON_DISC; + } -uint64_t DynamicEntry::value() const { - return value_; -} + if (PPC_DISC <= raw_value && raw_value < PPC64_DISC) { + return raw_value - PPC_DISC; + } -void DynamicEntry::tag(DYNAMIC_TAGS tag) { - tag_ = tag; -} + if (PPC64_DISC <= raw_value && raw_value < RISCV_DISC) { + return raw_value - PPC64_DISC; + } + if (RISCV_DISC <= raw_value) { + return raw_value - RISCV_DISC; + } -void DynamicEntry::value(uint64_t value) { - value_ = value; + return raw_value; } +DynamicEntry::DynamicEntry(const details::Elf64_Dyn& header, ARCH arch) : + tag_{DynamicEntry::from_value(header.d_tag, arch)}, + value_{header.d_un.d_val} +{} + +DynamicEntry::DynamicEntry(const details::Elf32_Dyn& header, ARCH arch) : + tag_{DynamicEntry::from_value(header.d_tag, arch)}, + value_{header.d_un.d_val} +{} + void DynamicEntry::accept(Visitor& visitor) const { visitor.visit(*this); } - - - - - std::ostream& DynamicEntry::print(std::ostream& os) const { - os << std::hex; - os << std::left - << std::setw(20) << to_string(tag()) - << std::setw(10) << value(); + os << fmt::format("{:<20}: 0x{:06x} ", to_string(tag()), value()); return os; } - -std::ostream& operator<<(std::ostream& os, const DynamicEntry& entry) { - return entry.print(os); +const char* to_string(DynamicEntry::TAG tag) { + #define ENTRY(X) std::pair(DynamicEntry::TAG::X, #X) + STRING_MAP enums2str { + ENTRY(UNKNOWN), + ENTRY(DT_NULL), + ENTRY(NEEDED), + ENTRY(PLTRELSZ), + ENTRY(PLTGOT), + ENTRY(HASH), + ENTRY(STRTAB), + ENTRY(SYMTAB), + ENTRY(RELA), + ENTRY(RELASZ), + ENTRY(RELAENT), + ENTRY(STRSZ), + ENTRY(SYMENT), + ENTRY(INIT), + ENTRY(FINI), + ENTRY(SONAME), + ENTRY(RPATH), + ENTRY(SYMBOLIC), + ENTRY(REL), + ENTRY(RELSZ), + ENTRY(RELENT), + ENTRY(PLTREL), + ENTRY(DEBUG), + ENTRY(TEXTREL), + ENTRY(JMPREL), + ENTRY(BIND_NOW), + ENTRY(INIT_ARRAY), + ENTRY(FINI_ARRAY), + ENTRY(INIT_ARRAYSZ), + ENTRY(FINI_ARRAYSZ), + ENTRY(RUNPATH), + ENTRY(FLAGS), + ENTRY(PREINIT_ARRAY), + ENTRY(PREINIT_ARRAYSZ), + ENTRY(SYMTAB_SHNDX), + ENTRY(RELRSZ), + ENTRY(RELR), + ENTRY(RELRENT), + ENTRY(GNU_HASH), + ENTRY(RELACOUNT), + ENTRY(RELCOUNT), + ENTRY(FLAGS_1), + ENTRY(VERSYM), + ENTRY(VERDEF), + ENTRY(VERDEFNUM), + ENTRY(VERNEED), + ENTRY(VERNEEDNUM), + ENTRY(ANDROID_REL_OFFSET), + ENTRY(ANDROID_REL_SIZE), + ENTRY(ANDROID_REL), + ENTRY(ANDROID_RELSZ), + ENTRY(ANDROID_RELA), + ENTRY(ANDROID_RELASZ), + ENTRY(ANDROID_RELR), + ENTRY(ANDROID_RELRSZ), + ENTRY(ANDROID_RELRENT), + ENTRY(ANDROID_RELRCOUNT), + ENTRY(MIPS_RLD_VERSION), + ENTRY(MIPS_TIME_STAMP), + ENTRY(MIPS_ICHECKSUM), + ENTRY(MIPS_IVERSION), + ENTRY(MIPS_FLAGS), + ENTRY(MIPS_BASE_ADDRESS), + ENTRY(MIPS_MSYM), + ENTRY(MIPS_CONFLICT), + ENTRY(MIPS_LIBLIST), + ENTRY(MIPS_LOCAL_GOTNO), + ENTRY(MIPS_CONFLICTNO), + ENTRY(MIPS_LIBLISTNO), + ENTRY(MIPS_SYMTABNO), + ENTRY(MIPS_UNREFEXTNO), + ENTRY(MIPS_GOTSYM), + ENTRY(MIPS_HIPAGENO), + ENTRY(MIPS_RLD_MAP), + ENTRY(MIPS_DELTA_CLASS), + ENTRY(MIPS_DELTA_CLASS_NO), + ENTRY(MIPS_DELTA_INSTANCE), + ENTRY(MIPS_DELTA_INSTANCE_NO), + ENTRY(MIPS_DELTA_RELOC), + ENTRY(MIPS_DELTA_RELOC_NO), + ENTRY(MIPS_DELTA_SYM), + ENTRY(MIPS_DELTA_SYM_NO), + ENTRY(MIPS_DELTA_CLASSSYM), + ENTRY(MIPS_DELTA_CLASSSYM_NO), + ENTRY(MIPS_CXX_FLAGS), + ENTRY(MIPS_PIXIE_INIT), + ENTRY(MIPS_SYMBOL_LIB), + ENTRY(MIPS_LOCALPAGE_GOTIDX), + ENTRY(MIPS_LOCAL_GOTIDX), + ENTRY(MIPS_HIDDEN_GOTIDX), + ENTRY(MIPS_PROTECTED_GOTIDX), + ENTRY(MIPS_OPTIONS), + ENTRY(MIPS_INTERFACE), + ENTRY(MIPS_DYNSTR_ALIGN), + ENTRY(MIPS_INTERFACE_SIZE), + ENTRY(MIPS_RLD_TEXT_RESOLVE_ADDR), + ENTRY(MIPS_PERF_SUFFIX), + ENTRY(MIPS_COMPACT_SIZE), + ENTRY(MIPS_GP_VALUE), + ENTRY(MIPS_AUX_DYNAMIC), + ENTRY(MIPS_PLTGOT), + ENTRY(MIPS_RWPLT), + ENTRY(MIPS_RLD_MAP_REL), + ENTRY(MIPS_XHASH), + + ENTRY(AARCH64_BTI_PLT), + ENTRY(AARCH64_PAC_PLT), + ENTRY(AARCH64_VARIANT_PCS), + ENTRY(AARCH64_MEMTAG_MODE), + ENTRY(AARCH64_MEMTAG_HEAP), + ENTRY(AARCH64_MEMTAG_STACK), + ENTRY(AARCH64_MEMTAG_GLOBALS), + ENTRY(AARCH64_MEMTAG_GLOBALSSZ), + + ENTRY(HEXAGON_SYMSZ), + ENTRY(HEXAGON_VER), + ENTRY(HEXAGON_PLT), + + ENTRY(PPC_GOT), + ENTRY(PPC_OPT), + + ENTRY(PPC64_GLINK), + ENTRY(PPC64_OPT), + + ENTRY(RISCV_VARIANT_CC), + }; + #undef ENTRY + + if (auto it = enums2str.find(tag); it != enums2str.end()) { + return it->second; + } + + return "UNKNOWN"; } + } } diff --git a/src/ELF/DynamicEntryArray.cpp b/src/ELF/DynamicEntryArray.cpp index 38b3b8c1dd..7879640814 100644 --- a/src/ELF/DynamicEntryArray.cpp +++ b/src/ELF/DynamicEntryArray.cpp @@ -18,43 +18,9 @@ #include "logging.hpp" -#include -#include -#include -#include - namespace LIEF { namespace ELF { -DynamicEntryArray::DynamicEntryArray() = default; -DynamicEntryArray& DynamicEntryArray::operator=(const DynamicEntryArray&) = default; -DynamicEntryArray::DynamicEntryArray(const DynamicEntryArray&) = default; - - -DynamicEntryArray::DynamicEntryArray(DYNAMIC_TAGS tag, array_t array) : - DynamicEntry::DynamicEntry{tag, 0}, - array_{std::move(array)} -{} - - -DynamicEntryArray::array_t& DynamicEntryArray::array() { - return const_cast(static_cast(this)->array()); -} - - -const DynamicEntryArray::array_t& DynamicEntryArray::array() const { - return array_; -} - -void DynamicEntryArray::array(const DynamicEntryArray::array_t& array) { - array_ = array; -} - -DynamicEntryArray& DynamicEntryArray::append(uint64_t function) { - array_.push_back(function); - return *this; -} - DynamicEntryArray& DynamicEntryArray::remove(uint64_t function) { array_.erase(std::remove_if(std::begin(array_), std::end(array_), [function] (uint64_t v) { return v == function; }), @@ -76,21 +42,8 @@ DynamicEntryArray& DynamicEntryArray::insert(size_t pos, uint64_t function) { return *this; } - -size_t DynamicEntryArray::size() const { - return array_.size(); -} - -DynamicEntryArray& DynamicEntryArray::operator+=(uint64_t value) { - return append(value); -} - -DynamicEntryArray& DynamicEntryArray::operator-=(uint64_t value) { - return remove(value); -} - const uint64_t& DynamicEntryArray::operator[](size_t idx) const { - static uint64_t GARBAGE; + static uint64_t GARBAGE = 0; if (idx >= array_.size()) { LIEF_WARN("DynamicEntryArray[{}] is out-of-range", idx); return GARBAGE; @@ -106,34 +59,13 @@ void DynamicEntryArray::accept(Visitor& visitor) const { visitor.visit(*this); } -bool DynamicEntryArray::classof(const DynamicEntry* entry) { - const DYNAMIC_TAGS tag = entry->tag(); - return tag == DYNAMIC_TAGS::DT_INIT_ARRAY || - tag == DYNAMIC_TAGS::DT_FINI_ARRAY || - tag == DYNAMIC_TAGS::DT_PREINIT_ARRAY; -} - std::ostream& DynamicEntryArray::print(std::ostream& os) const { - const DynamicEntryArray::array_t& array = this->array(); + const array_t& array = this->array(); DynamicEntry::print(os); - os << std::hex - << std::left - << "[" - << std::accumulate(std::begin(array), std::end(array), std::string(), - [] (std::string& s, uint64_t x) { - std::stringstream ss; - ss << "0x" << std::hex << x; - return s.empty() ? ss.str() : s + ", " + ss.str(); - }) - << "]"; - - + os << '[' << fmt::format("0x{:04x}", fmt::join(array, ", ")) << ']'; return os; } - -DynamicEntryArray::~DynamicEntryArray() = default; - } } diff --git a/src/ELF/DynamicEntryFlags.cpp b/src/ELF/DynamicEntryFlags.cpp index 268a7822ab..54a39b0483 100644 --- a/src/ELF/DynamicEntryFlags.cpp +++ b/src/ELF/DynamicEntryFlags.cpp @@ -13,150 +13,202 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include #include "LIEF/Visitor.hpp" - #include "LIEF/ELF/DynamicEntryFlags.hpp" -#include "LIEF/ELF/EnumToString.hpp" -#include "ELF/Structures.hpp" + +#include "frozen.hpp" +#include "logging.hpp" +#include "fmt_formatter.hpp" + +FMT_FORMATTER(LIEF::ELF::DynamicEntryFlags::FLAG, LIEF::ELF::to_string); namespace LIEF { namespace ELF { -DynamicEntryFlags::DynamicEntryFlags() = default; -DynamicEntryFlags& DynamicEntryFlags::operator=(const DynamicEntryFlags&) = default; -DynamicEntryFlags::DynamicEntryFlags(const DynamicEntryFlags&) = default; +static constexpr auto DF_FLAGS = { + DynamicEntryFlags::FLAG::ORIGIN, DynamicEntryFlags::FLAG::SYMBOLIC, + DynamicEntryFlags::FLAG::TEXTREL, DynamicEntryFlags::FLAG::BIND_NOW, + DynamicEntryFlags::FLAG::STATIC_TLS, +}; + +static constexpr auto DF_FLAGS_1 = { + DynamicEntryFlags::FLAG::NOW, + DynamicEntryFlags::FLAG::GLOBAL, + DynamicEntryFlags::FLAG::GROUP, + DynamicEntryFlags::FLAG::NODELETE, + DynamicEntryFlags::FLAG::LOADFLTR, + DynamicEntryFlags::FLAG::INITFIRST, + DynamicEntryFlags::FLAG::NOOPEN, + DynamicEntryFlags::FLAG::HANDLE_ORIGIN, + DynamicEntryFlags::FLAG::DIRECT, + DynamicEntryFlags::FLAG::TRANS, + DynamicEntryFlags::FLAG::INTERPOSE, + DynamicEntryFlags::FLAG::NODEFLIB, + DynamicEntryFlags::FLAG::NODUMP, + DynamicEntryFlags::FLAG::CONFALT, + DynamicEntryFlags::FLAG::ENDFILTEE, + DynamicEntryFlags::FLAG::DISPRELDNE, + DynamicEntryFlags::FLAG::DISPRELPND, + DynamicEntryFlags::FLAG::NODIRECT, + DynamicEntryFlags::FLAG::IGNMULDEF, + DynamicEntryFlags::FLAG::NOKSYMS, + DynamicEntryFlags::FLAG::NOHDR, + DynamicEntryFlags::FLAG::EDITED, + DynamicEntryFlags::FLAG::NORELOC, + DynamicEntryFlags::FLAG::SYMINTPOSE, + DynamicEntryFlags::FLAG::GLOBAUDIT, + DynamicEntryFlags::FLAG::SINGLETON, + DynamicEntryFlags::FLAG::PIE, + DynamicEntryFlags::FLAG::KMOD, + DynamicEntryFlags::FLAG::WEAKFILTER, + DynamicEntryFlags::FLAG::NOCOMMON, +}; + +bool DynamicEntryFlags::has(DynamicEntryFlags::FLAG f) const { + if (tag() == DynamicEntry::TAG::FLAGS) { + auto raw = static_cast(f); + if (BASE <= raw) { + return false; + } + return (value() & raw) > 0; + } -bool DynamicEntryFlags::has(DYNAMIC_FLAGS f) const { - if (tag() != DYNAMIC_TAGS::DT_FLAGS) { - return false; + if (tag() == DynamicEntry::TAG::FLAGS_1) { + auto raw = static_cast(f); + if (raw < BASE) { + return false; + } + raw -= BASE; + return (value() & raw) > 0; } - return (static_cast(f) & value()) > 0; + return false; } -bool DynamicEntryFlags::has(DYNAMIC_FLAGS_1 f) const { - if (tag() != DYNAMIC_TAGS::DT_FLAGS_1) { - return false; - } - return (static_cast(f) & value()) > 0; -} - DynamicEntryFlags::flags_list_t DynamicEntryFlags::flags() const { - DynamicEntryFlags::flags_list_t flags; + flags_list_t flags; - - if (tag() == DYNAMIC_TAGS::DT_FLAGS) { - for (DYNAMIC_FLAGS f : details::dynamic_flags_array) { + if (tag() == DynamicEntry::TAG::FLAGS) { + for (DynamicEntryFlags::FLAG f : DF_FLAGS) { if (has(f)) { - flags.insert(static_cast(f)); + flags.push_back(f); } } + return flags; } - if (tag() == DYNAMIC_TAGS::DT_FLAGS_1) { - for (DYNAMIC_FLAGS_1 f : details::dynamic_flags_1_array) { + if (tag() == DynamicEntry::TAG::FLAGS_1) { + for (DynamicEntryFlags::FLAG f : DF_FLAGS_1) { if (has(f)) { - flags.insert(static_cast(f)); + flags.push_back(f); } } + return flags; } return flags; } -void DynamicEntryFlags::add(DYNAMIC_FLAGS f) { - if (tag() != DYNAMIC_TAGS::DT_FLAGS) { +void DynamicEntryFlags::add(DynamicEntryFlags::FLAG f) { + if (tag() == DynamicEntry::TAG::FLAGS) { + auto raw = static_cast(f); + if (BASE <= raw) { + return; + } + value(value() | raw); return; } - value(value() | static_cast(f)); -} - -void DynamicEntryFlags::add(DYNAMIC_FLAGS_1 f) { - if (tag() != DYNAMIC_TAGS::DT_FLAGS_1) { + if (tag() == DynamicEntry::TAG::FLAGS_1) { + auto raw = static_cast(f); + if (raw < BASE) { + return; + } + raw -= BASE; + value(value() | raw); return; } - - value(value() | static_cast(f)); + return; } -void DynamicEntryFlags::remove(DYNAMIC_FLAGS f) { - if (tag() != DYNAMIC_TAGS::DT_FLAGS) { - return; +void DynamicEntryFlags::remove(DynamicEntryFlags::FLAG f) { + if (tag() == DynamicEntry::TAG::FLAGS) { + auto raw = static_cast(f); + if (BASE <= raw) { + return; + } + value(value() & ~raw); } - value(value() & (~ static_cast(f))); -} - -void DynamicEntryFlags::remove(DYNAMIC_FLAGS_1 f) { - if (tag() != DYNAMIC_TAGS::DT_FLAGS_1) { - return; + if (tag() == DynamicEntry::TAG::FLAGS_1) { + auto raw = static_cast(f); + if (raw < BASE) { + return; + } + raw -= BASE; + value(value() & ~raw); } - - value(value() & (~ static_cast(f))); -} - - -DynamicEntryFlags& DynamicEntryFlags::operator+=(DYNAMIC_FLAGS f) { - add(f); - return *this; -} - -DynamicEntryFlags& DynamicEntryFlags::operator+=(DYNAMIC_FLAGS_1 f) { - add(f); - return *this; -} - -DynamicEntryFlags& DynamicEntryFlags::operator-=(DYNAMIC_FLAGS f) { - remove(f); - return *this; -} - -DynamicEntryFlags& DynamicEntryFlags::operator-=(DYNAMIC_FLAGS_1 f) { - remove(f); - return *this; } void DynamicEntryFlags::accept(Visitor& visitor) const { visitor.visit(*this); } -bool DynamicEntryFlags::classof(const DynamicEntry* entry) { - const DYNAMIC_TAGS tag = entry->tag(); - return tag == DYNAMIC_TAGS::DT_FLAGS_1 || - tag == DYNAMIC_TAGS::DT_FLAGS; -} - std::ostream& DynamicEntryFlags::print(std::ostream& os) const { DynamicEntry::print(os); + os << " " << fmt::to_string(flags()); + return os; +} - const flags_list_t& flags = this->flags(); - std::string flags_str; - - if (tag() == DYNAMIC_TAGS::DT_FLAGS) { - flags_str = std::accumulate(std::begin(flags), std::end(flags), std::string{}, - [] (const std::string& a, const uint32_t flag) { - auto f = static_cast(flag); - return a.empty() ? to_string(f) : a + " - " + to_string(f); - }); - } - - if (tag() == DYNAMIC_TAGS::DT_FLAGS_1) { - flags_str = std::accumulate(std::begin(flags), std::end(flags), std::string{}, - [] (const std::string& a, const uint32_t flag) { - auto f = static_cast(flag); - return a.empty() ? to_string(f) : a + " - " + to_string(f); - }); +const char* to_string(DynamicEntryFlags::FLAG flag) { + #define ENTRY(X) std::pair(DynamicEntryFlags::FLAG::X, #X) + STRING_MAP enums2str { + ENTRY(ORIGIN), + ENTRY(SYMBOLIC), + ENTRY(TEXTREL), + ENTRY(BIND_NOW), + ENTRY(STATIC_TLS), + ENTRY(NOW), + ENTRY(GLOBAL), + ENTRY(GROUP), + ENTRY(NODELETE), + ENTRY(LOADFLTR), + ENTRY(INITFIRST), + ENTRY(NOOPEN), + ENTRY(HANDLE_ORIGIN), + ENTRY(DIRECT), + ENTRY(TRANS), + ENTRY(INTERPOSE), + ENTRY(NODEFLIB), + ENTRY(NODUMP), + ENTRY(CONFALT), + ENTRY(ENDFILTEE), + ENTRY(DISPRELDNE), + ENTRY(DISPRELPND), + ENTRY(NODIRECT), + ENTRY(IGNMULDEF), + ENTRY(NOKSYMS), + ENTRY(NOHDR), + ENTRY(EDITED), + ENTRY(NORELOC), + ENTRY(SYMINTPOSE), + ENTRY(GLOBAUDIT), + ENTRY(SINGLETON), + ENTRY(PIE), + ENTRY(KMOD), + ENTRY(WEAKFILTER), + ENTRY(NOCOMMON), + }; + #undef ENTRY + if (auto it = enums2str.find(flag); it != enums2str.end()) { + return it->second; } - os << " " << flags_str; - - return os; + return "UNKNOWN"; } + } } diff --git a/src/ELF/DynamicEntryLibrary.cpp b/src/ELF/DynamicEntryLibrary.cpp index afdccd30fd..3b1a19544b 100644 --- a/src/ELF/DynamicEntryLibrary.cpp +++ b/src/ELF/DynamicEntryLibrary.cpp @@ -16,52 +16,21 @@ #include "LIEF/ELF/DynamicEntryLibrary.hpp" #include "LIEF/Visitor.hpp" -#include -#include +#include namespace LIEF { namespace ELF { -DynamicEntryLibrary& DynamicEntryLibrary::operator=(const DynamicEntryLibrary&) = default; -DynamicEntryLibrary::DynamicEntryLibrary(const DynamicEntryLibrary&) = default; - -DynamicEntryLibrary::DynamicEntryLibrary() : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_NEEDED, 0} -{} - -DynamicEntryLibrary::DynamicEntryLibrary(std::string name) : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_NEEDED, 0}, - libname_{std::move(name)} -{} - -const std::string& DynamicEntryLibrary::name() const { - return libname_; -} - - -void DynamicEntryLibrary::name(const std::string& name) { - libname_ = name; -} - - void DynamicEntryLibrary::accept(Visitor& visitor) const { visitor.visit(*this); } -bool DynamicEntryLibrary::classof(const DynamicEntry* entry) { - const DYNAMIC_TAGS tag = entry->tag(); - return tag == DYNAMIC_TAGS::DT_NEEDED; -} - std::ostream& DynamicEntryLibrary::print(std::ostream& os) const { - DynamicEntry::print(os); - os << std::hex - << std::left - << std::setw(10) << name(); + os << fmt::format("{:<10}", name()); return os; - } + } } diff --git a/src/ELF/DynamicEntryRpath.cpp b/src/ELF/DynamicEntryRpath.cpp index a93df3a724..fd6220d298 100644 --- a/src/ELF/DynamicEntryRpath.cpp +++ b/src/ELF/DynamicEntryRpath.cpp @@ -26,45 +26,6 @@ namespace LIEF { namespace ELF { -DynamicEntryRpath::DynamicEntryRpath() : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_RPATH, 0} -{} - -DynamicEntryRpath& DynamicEntryRpath::operator=(const DynamicEntryRpath&) = default; -DynamicEntryRpath::DynamicEntryRpath(const DynamicEntryRpath&) = default; - - -DynamicEntryRpath::DynamicEntryRpath(std::string rpath) : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_RPATH, 0}, - rpath_{std::move(rpath)} -{} - - -DynamicEntryRpath::DynamicEntryRpath(const std::vector& paths) : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_RPATH, 0} -{ - this->paths(paths); -} - -const std::string& DynamicEntryRpath::name() const { - return rpath_; -} - - -void DynamicEntryRpath::name(const std::string& name) { - rpath_ = name; -} - -const std::string& DynamicEntryRpath::rpath() const { - return name(); -} - - -void DynamicEntryRpath::rpath(const std::string& rpath) { - name(rpath); -} - - std::vector DynamicEntryRpath::paths() const { std::stringstream ss; ss.str(rpath()); @@ -117,33 +78,18 @@ DynamicEntryRpath& DynamicEntryRpath::insert(size_t pos, const std::string& path return *this; } -DynamicEntryRpath& DynamicEntryRpath::operator+=(const std::string& path) { - return append(path); -} - -DynamicEntryRpath& DynamicEntryRpath::operator-=(const std::string& path) { - return remove(path); -} void DynamicEntryRpath::accept(Visitor& visitor) const { visitor.visit(*this); } -bool DynamicEntryRpath::classof(const DynamicEntry* entry) { - const DYNAMIC_TAGS tag = entry->tag(); - return tag == DYNAMIC_TAGS::DT_RPATH; -} - std::ostream& DynamicEntryRpath::print(std::ostream& os) const { - DynamicEntry::print(os); - os << std::hex - << std::left - << std::setw(10) << rpath(); + os << fmt::format("{:<10}", rpath()); return os; - } + } } diff --git a/src/ELF/DynamicEntryRunPath.cpp b/src/ELF/DynamicEntryRunPath.cpp index 3555f95e00..f7330b574b 100644 --- a/src/ELF/DynamicEntryRunPath.cpp +++ b/src/ELF/DynamicEntryRunPath.cpp @@ -17,55 +17,12 @@ #include "LIEF/Visitor.hpp" #include "logging.hpp" -#include -#include #include #include -#include namespace LIEF { namespace ELF { - -DynamicEntryRunPath& DynamicEntryRunPath::operator=(const DynamicEntryRunPath&) = default; -DynamicEntryRunPath::DynamicEntryRunPath(const DynamicEntryRunPath&) = default; - -DynamicEntryRunPath::DynamicEntryRunPath() : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_RUNPATH, 0} -{} - -DynamicEntryRunPath::DynamicEntryRunPath(std::string runpath) : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_RUNPATH, 0}, - runpath_{std::move(runpath)} -{} - - -DynamicEntryRunPath::DynamicEntryRunPath(const std::vector& paths) : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_RUNPATH, 0} -{ - this->paths(paths); -} - - - -const std::string& DynamicEntryRunPath::name() const { - return runpath_; -} - - -void DynamicEntryRunPath::name(const std::string& name) { - runpath_ = name; -} - -const std::string& DynamicEntryRunPath::runpath() const { - return name(); -} - -void DynamicEntryRunPath::runpath(const std::string& runpath) { - name(runpath); -} - - std::vector DynamicEntryRunPath::paths() const { std::stringstream ss; ss.str(runpath()); @@ -119,28 +76,14 @@ DynamicEntryRunPath& DynamicEntryRunPath::insert(size_t pos, const std::string& return *this; } -DynamicEntryRunPath& DynamicEntryRunPath::operator+=(const std::string& path) { - return append(path); -} - -DynamicEntryRunPath& DynamicEntryRunPath::operator-=(const std::string& path) { - return remove(path); -} - void DynamicEntryRunPath::accept(Visitor& visitor) const { visitor.visit(*this); } -bool DynamicEntryRunPath::classof(const DynamicEntry* entry) { - const DYNAMIC_TAGS tag = entry->tag(); - return tag == DYNAMIC_TAGS::DT_RUNPATH; -} std::ostream& DynamicEntryRunPath::print(std::ostream& os) const { DynamicEntry::print(os); - os << std::hex - << std::left - << std::setw(10) << name(); + os << fmt::format("{:<10}", runpath()); return os; } } diff --git a/src/ELF/DynamicSharedObject.cpp b/src/ELF/DynamicSharedObject.cpp index 1a7e9aa2b8..24242924c3 100644 --- a/src/ELF/DynamicSharedObject.cpp +++ b/src/ELF/DynamicSharedObject.cpp @@ -16,52 +16,21 @@ #include "LIEF/ELF/DynamicSharedObject.hpp" #include "LIEF/Visitor.hpp" -#include -#include +#include namespace LIEF { namespace ELF { -DynamicSharedObject::DynamicSharedObject() : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_SONAME, 0} -{} - -DynamicSharedObject& DynamicSharedObject::operator=(const DynamicSharedObject&) = default; - -DynamicSharedObject::DynamicSharedObject(const DynamicSharedObject&) = default; - -DynamicSharedObject::DynamicSharedObject(std::string name) : - DynamicEntry::DynamicEntry{DYNAMIC_TAGS::DT_SONAME, 0}, - name_{std::move(name)} -{} - - -const std::string& DynamicSharedObject::name() const { - return name_; -} - - -void DynamicSharedObject::name(const std::string& name) { - name_ = name; -} void DynamicSharedObject::accept(Visitor& visitor) const { visitor.visit(*this); } -bool DynamicSharedObject::classof(const DynamicEntry* entry) { - const DYNAMIC_TAGS tag = entry->tag(); - return tag == DYNAMIC_TAGS::DT_SONAME; -} - - std::ostream& DynamicSharedObject::print(std::ostream& os) const { DynamicEntry::print(os); - os << std::hex - << std::left - << std::setw(10) << name(); + os << fmt::format("{:<10}", name()); return os; - } + } } diff --git a/src/ELF/EnumToString.cpp b/src/ELF/EnumToString.cpp index 1fc9fea9b2..613081ffbd 100644 --- a/src/ELF/EnumToString.cpp +++ b/src/ELF/EnumToString.cpp @@ -14,1519 +14,197 @@ * limitations under the License. */ #include "LIEF/ELF/EnumToString.hpp" -#include "LIEF/ELF/NoteDetails/core/CorePrStatus.hpp" #include "frozen.hpp" namespace LIEF { namespace ELF { -const char* to_string(SYMBOL_BINDINGS e) { - CONST_MAP(SYMBOL_BINDINGS, const char*, 4) enumStrings { - { SYMBOL_BINDINGS::STB_LOCAL, "LOCAL" }, - { SYMBOL_BINDINGS::STB_GLOBAL, "GLOBAL" }, - { SYMBOL_BINDINGS::STB_WEAK, "WEAK" }, - { SYMBOL_BINDINGS::STB_GNU_UNIQUE, "GNU_UNIQUE" }, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(E_TYPE e) { - CONST_MAP(E_TYPE, const char*, 7) enumStrings { - { E_TYPE::ET_NONE, "NONE" }, - { E_TYPE::ET_REL, "RELOCATABLE" }, - { E_TYPE::ET_EXEC, "EXECUTABLE" }, - { E_TYPE::ET_DYN, "DYNAMIC" }, - { E_TYPE::ET_CORE, "CORE" }, - { E_TYPE::ET_LOPROC, "LOPROC" }, - { E_TYPE::ET_HIPROC, "HIPROC" } - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(VERSION e) { - CONST_MAP(VERSION, const char*, 2) enumStrings { - { VERSION::EV_NONE, "NONE" }, - { VERSION::EV_CURRENT, "CURRENT" } - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - const char* to_string(ARCH e) { - CONST_MAP(ARCH, const char*, 178) enumStrings { - { ARCH::EM_NONE, "NONE" }, - { ARCH::EM_M32, "M32"}, - { ARCH::EM_SPARC, "SPARC"}, - { ARCH::EM_386, "i386"}, - { ARCH::EM_68K, "ARCH_68K"}, - { ARCH::EM_88K, "ARCH_88K"}, - { ARCH::EM_IAMCU, "IAMCU"}, - { ARCH::EM_860, "ARCH_860"}, - { ARCH::EM_MIPS, "MIPS"}, - { ARCH::EM_S370, "S370"}, - { ARCH::EM_MIPS_RS3_LE, "MIPS_RS3_LE"}, - { ARCH::EM_PARISC, "PARISC"}, - { ARCH::EM_VPP500, "VPP500"}, - { ARCH::EM_SPARC32PLUS, "SPARC32PLUS"}, - { ARCH::EM_960, "ARCH_960"}, - { ARCH::EM_PPC, "PPC"}, - { ARCH::EM_PPC64, "PPC64"}, - { ARCH::EM_S390, "S390"}, - { ARCH::EM_SPU, "SPU"}, - { ARCH::EM_V800, "V800"}, - { ARCH::EM_FR20, "FR20"}, - { ARCH::EM_RH32, "RH32"}, - { ARCH::EM_RCE, "RCE"}, - { ARCH::EM_ARM, "ARM"}, - { ARCH::EM_ALPHA, "ALPHA"}, - { ARCH::EM_SH, "SH"}, - { ARCH::EM_SPARCV9, "SPARCV9"}, - { ARCH::EM_TRICORE, "TRICORE"}, - { ARCH::EM_ARC, "ARC"}, - { ARCH::EM_H8_300, "H8_300"}, - { ARCH::EM_H8_300H, "H8_300H"}, - { ARCH::EM_H8S, "H8S"}, - { ARCH::EM_H8_500, "H8_500"}, - { ARCH::EM_IA_64, "IA_64"}, - { ARCH::EM_MIPS_X, "MIPS_X"}, - { ARCH::EM_COLDFIRE, "COLDFIRE"}, - { ARCH::EM_68HC12, "ARCH_68HC12"}, - { ARCH::EM_MMA, "MMA"}, - { ARCH::EM_PCP, "PCP"}, - { ARCH::EM_NCPU, "NCPU"}, - { ARCH::EM_NDR1, "NDR1"}, - { ARCH::EM_STARCORE, "STARCORE"}, - { ARCH::EM_ME16, "ME16"}, - { ARCH::EM_ST100, "ST100"}, - { ARCH::EM_TINYJ, "TINYJ"}, - { ARCH::EM_X86_64, "x86_64"}, - { ARCH::EM_PDSP, "PDSP"}, - { ARCH::EM_PDP10, "PDP10"}, - { ARCH::EM_PDP11, "PDP11"}, - { ARCH::EM_FX66, "FX66"}, - { ARCH::EM_ST9PLUS, "ST9PLUS"}, - { ARCH::EM_ST7, "ST7"}, - { ARCH::EM_68HC16, "ARCH_68HC16"}, - { ARCH::EM_68HC11, "ARCH_68HC11"}, - { ARCH::EM_68HC08, "ARCH_68HC08"}, - { ARCH::EM_68HC05, "ARCH_68HC05"}, - { ARCH::EM_SVX, "SVX"}, - { ARCH::EM_ST19, "ST19"}, - { ARCH::EM_VAX, "VAX"}, - { ARCH::EM_CRIS, "CRIS"}, - { ARCH::EM_JAVELIN, "JAVELIN"}, - { ARCH::EM_FIREPATH, "FIREPATH"}, - { ARCH::EM_ZSP, "ZSP"}, - { ARCH::EM_MMIX, "MMIX"}, - { ARCH::EM_HUANY, "HUANY"}, - { ARCH::EM_PRISM, "PRISM"}, - { ARCH::EM_AVR, "AVR"}, - { ARCH::EM_FR30, "FR30"}, - { ARCH::EM_D10V, "D10V"}, - { ARCH::EM_D30V, "D30V"}, - { ARCH::EM_V850, "V850"}, - { ARCH::EM_M32R, "M32R"}, - { ARCH::EM_MN10300, "MN10300"}, - { ARCH::EM_MN10200, "MN10200"}, - { ARCH::EM_PJ, "PJ"}, - { ARCH::EM_OPENRISC, "OPENRISC"}, - { ARCH::EM_ARC_COMPACT, "ARC_COMPACT"}, - { ARCH::EM_XTENSA, "XTENSA"}, - { ARCH::EM_VIDEOCORE, "VIDEOCORE"}, - { ARCH::EM_TMM_GPP, "TMM_GPP"}, - { ARCH::EM_NS32K, "NS32K"}, - { ARCH::EM_TPC, "TPC"}, - { ARCH::EM_SNP1K, "SNP1K"}, - { ARCH::EM_ST200, "ST200"}, - { ARCH::EM_IP2K, "IP2K"}, - { ARCH::EM_MAX, "MAX"}, - { ARCH::EM_CR, "CR"}, - { ARCH::EM_F2MC16, "F2MC16"}, - { ARCH::EM_MSP430, "MSP430"}, - { ARCH::EM_BLACKFIN, "BLACKFIN"}, - { ARCH::EM_SE_C33, "SE_C33"}, - { ARCH::EM_SEP, "SEP"}, - { ARCH::EM_ARCA, "ARCA"}, - { ARCH::EM_UNICORE, "UNICORE"}, - { ARCH::EM_EXCESS, "EXCESS"}, - { ARCH::EM_DXP, "DXP"}, - { ARCH::EM_ALTERA_NIOS2, "ALTERA_NIOS2"}, - { ARCH::EM_CRX, "CRX"}, - { ARCH::EM_XGATE, "XGATE"}, - { ARCH::EM_C166, "C166"}, - { ARCH::EM_M16C, "M16C"}, - { ARCH::EM_DSPIC30F, "DSPIC30F"}, - { ARCH::EM_CE, "CE"}, - { ARCH::EM_M32C, "M32C"}, - { ARCH::EM_TSK3000, "TSK3000"}, - { ARCH::EM_RS08, "RS08"}, - { ARCH::EM_SHARC, "SHARC"}, - { ARCH::EM_ECOG2, "ECOG2"}, - { ARCH::EM_SCORE7, "SCORE7"}, - { ARCH::EM_DSP24, "DSP24"}, - { ARCH::EM_VIDEOCORE3, "VIDEOCORE3"}, - { ARCH::EM_LATTICEMICO32, "LATTICEMICO32"}, - { ARCH::EM_SE_C17, "SE_C17"}, - { ARCH::EM_TI_C6000, "TI_C6000"}, - { ARCH::EM_TI_C2000, "TI_C2000"}, - { ARCH::EM_TI_C5500, "TI_C5500"}, - { ARCH::EM_MMDSP_PLUS, "MMDSP_PLUS"}, - { ARCH::EM_CYPRESS_M8C, "CYPRESS_M8C"}, - { ARCH::EM_R32C, "R32C"}, - { ARCH::EM_TRIMEDIA, "TRIMEDIA"}, - { ARCH::EM_HEXAGON, "HEXAGON"}, - { ARCH::EM_8051, "ARCH_8051"}, - { ARCH::EM_STXP7X, "STXP7X"}, - { ARCH::EM_NDS32, "NDS32"}, - { ARCH::EM_ECOG1, "ECOG1"}, - { ARCH::EM_ECOG1X, "ECOG1X"}, - { ARCH::EM_MAXQ30, "MAXQ30"}, - { ARCH::EM_XIMO16, "XIMO16"}, - { ARCH::EM_MANIK, "MANIK"}, - { ARCH::EM_CRAYNV2, "CRAYNV2"}, - { ARCH::EM_RX, "RX"}, - { ARCH::EM_METAG, "METAG"}, - { ARCH::EM_MCST_ELBRUS, "MCST_ELBRUS"}, - { ARCH::EM_ECOG16, "ECOG16"}, - { ARCH::EM_CR16, "CR16"}, - { ARCH::EM_ETPU, "ETPU"}, - { ARCH::EM_SLE9X, "SLE9X"}, - { ARCH::EM_L10M, "L10M"}, - { ARCH::EM_K10M, "K10M"}, - { ARCH::EM_AARCH64, "AARCH64"}, - { ARCH::EM_AVR32, "AVR32"}, - { ARCH::EM_STM8, "STM8"}, - { ARCH::EM_TILE64, "TILE64"}, - { ARCH::EM_TILEPRO, "TILEPRO"}, - { ARCH::EM_CUDA, "CUDA"}, - { ARCH::EM_TILEGX, "TILEGX"}, - { ARCH::EM_CLOUDSHIELD, "CLOUDSHIELD"}, - { ARCH::EM_COREA_1ST, "COREA_1ST"}, - { ARCH::EM_COREA_2ND, "COREA_2ND"}, - { ARCH::EM_ARC_COMPACT2, "ARC_COMPACT2"}, - { ARCH::EM_OPEN8, "OPEN8"}, - { ARCH::EM_RL78, "RL78"}, - { ARCH::EM_VIDEOCORE5, "VIDEOCORE5"}, - { ARCH::EM_78KOR, "ARCH_78KOR"}, - { ARCH::EM_56800EX, "ARCH_56800EX"}, - { ARCH::EM_BA1, "BA1"}, - { ARCH::EM_BA2, "BA2"}, - { ARCH::EM_XCORE, "XCORE"}, - { ARCH::EM_MCHP_PIC, "MCHP_PIC"}, - { ARCH::EM_INTEL205, "INTEL205"}, - { ARCH::EM_INTEL206, "INTEL206"}, - { ARCH::EM_INTEL207, "INTEL207"}, - { ARCH::EM_INTEL208, "INTEL208"}, - { ARCH::EM_INTEL209, "INTEL209"}, - { ARCH::EM_KM32, "KM32"}, - { ARCH::EM_KMX32, "KMX32"}, - { ARCH::EM_KMX16, "KMX16"}, - { ARCH::EM_KMX8, "KMX8"}, - { ARCH::EM_KVARC, "KVARC"}, - { ARCH::EM_CDP, "CDP"}, - { ARCH::EM_COGE, "COGE"}, - { ARCH::EM_COOL, "COOL"}, - { ARCH::EM_NORC, "NORC"}, - { ARCH::EM_CSR_KALIMBA, "CSR_KALIMBA"}, - { ARCH::EM_AMDGPU, "AMDGPU"}, - { ARCH::EM_RISCV, "RISCV"}, - { ARCH::EM_BPF, "BPF"}, - { ARCH::EM_LOONGARCH, "LOONGARCH"} - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(SEGMENT_TYPES e) { - CONST_MAP(SEGMENT_TYPES, const char*, 20) enumStrings { - { SEGMENT_TYPES::PT_NULL, "NULL" }, - { SEGMENT_TYPES::PT_LOAD, "LOAD" }, - { SEGMENT_TYPES::PT_DYNAMIC, "DYNAMIC" }, - { SEGMENT_TYPES::PT_INTERP, "INTERP" }, - { SEGMENT_TYPES::PT_NOTE, "NOTE" }, - { SEGMENT_TYPES::PT_SHLIB, "SHLIB" }, - { SEGMENT_TYPES::PT_PHDR, "PHDR" }, - { SEGMENT_TYPES::PT_TLS, "TLS" }, - { SEGMENT_TYPES::PT_LOOS, "LOOS" }, - { SEGMENT_TYPES::PT_HIOS, "HIOS" }, - { SEGMENT_TYPES::PT_LOPROC, "LOPROC" }, - { SEGMENT_TYPES::PT_HIPROC, "HIPROC" }, - { SEGMENT_TYPES::PT_GNU_EH_FRAME, "GNU_EH_FRAME" }, - //{ SEGMENT_TYPES::PT_SUNW_EH_FRAME, "SUNW_EH_FRAME" }, - { SEGMENT_TYPES::PT_SUNW_UNWIND, "SUNW_UNWIND" }, - { SEGMENT_TYPES::PT_GNU_STACK, "GNU_STACK" }, - { SEGMENT_TYPES::PT_GNU_PROPERTY, "GNU_PROPERTY" }, - { SEGMENT_TYPES::PT_GNU_RELRO, "GNU_RELRO" }, - { SEGMENT_TYPES::PT_ARM_ARCHEXT, "ARM_ARCHEXT" }, - { SEGMENT_TYPES::PT_ARM_EXIDX, "ARM_EXIDX" }, - { SEGMENT_TYPES::PT_ARM_UNWIND, "ARM_UNWIND" }, - //{ SEGMENT_TYPES::PT_MIPS_REGINFO, "MIPS_REGINFO" }, - //{ SEGMENT_TYPES::PT_MIPS_RTPROC, "MIPS_RTPROC" }, - //{ SEGMENT_TYPES::PT_MIPS_OPTIONS, "MIPS_OPTIONS" }, - //{ SEGMENT_TYPES::PT_MIPS_ABIFLAGS, "MIPS_ABIFLAGS" } - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(DYNAMIC_TAGS e) { - CONST_MAP(DYNAMIC_TAGS, const char*, 101) enumStrings { - { DYNAMIC_TAGS::DT_NULL, "NULL"}, - { DYNAMIC_TAGS::DT_NEEDED, "NEEDED"}, - { DYNAMIC_TAGS::DT_PLTRELSZ, "PLTRELSZ"}, - { DYNAMIC_TAGS::DT_PLTGOT, "PLTGOT"}, - { DYNAMIC_TAGS::DT_HASH, "HASH"}, - { DYNAMIC_TAGS::DT_STRTAB, "STRTAB"}, - { DYNAMIC_TAGS::DT_SYMTAB, "SYMTAB"}, - { DYNAMIC_TAGS::DT_RELA, "RELA"}, - { DYNAMIC_TAGS::DT_RELASZ, "RELASZ"}, - { DYNAMIC_TAGS::DT_RELAENT, "RELAENT"}, - { DYNAMIC_TAGS::DT_STRSZ, "STRSZ"}, - { DYNAMIC_TAGS::DT_SYMENT, "SYMENT"}, - { DYNAMIC_TAGS::DT_INIT, "INIT"}, - { DYNAMIC_TAGS::DT_FINI, "FINI"}, - { DYNAMIC_TAGS::DT_SONAME, "SONAME"}, - { DYNAMIC_TAGS::DT_RPATH, "RPATH"}, - { DYNAMIC_TAGS::DT_SYMBOLIC, "SYMBOLIC"}, - { DYNAMIC_TAGS::DT_REL, "REL"}, - { DYNAMIC_TAGS::DT_RELSZ, "RELSZ"}, - { DYNAMIC_TAGS::DT_RELENT, "RELENT"}, - { DYNAMIC_TAGS::DT_PLTREL, "PLTREL"}, - { DYNAMIC_TAGS::DT_DEBUG, "DEBUG"}, - { DYNAMIC_TAGS::DT_TEXTREL, "TEXTREL"}, - { DYNAMIC_TAGS::DT_JMPREL, "JMPREL"}, - { DYNAMIC_TAGS::DT_BIND_NOW, "BIND_NOW"}, - { DYNAMIC_TAGS::DT_INIT_ARRAY, "INIT_ARRAY"}, - { DYNAMIC_TAGS::DT_FINI_ARRAY, "FINI_ARRAY"}, - { DYNAMIC_TAGS::DT_INIT_ARRAYSZ, "INIT_ARRAYSZ"}, - { DYNAMIC_TAGS::DT_FINI_ARRAYSZ, "FINI_ARRAYSZ"}, - { DYNAMIC_TAGS::DT_RUNPATH, "RUNPATH"}, - { DYNAMIC_TAGS::DT_FLAGS, "FLAGS"}, - //{ DYNAMIC_TAGS::DT_ENCODING, "ENCODING"}, // SKIPED - { DYNAMIC_TAGS::DT_PREINIT_ARRAY, "PREINIT_ARRAY"}, - { DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ, "PREINIT_ARRAYSZ"}, - { DYNAMIC_TAGS::DT_GNU_HASH, "GNU_HASH"}, - { DYNAMIC_TAGS::DT_RELACOUNT, "RELACOUNT"}, - { DYNAMIC_TAGS::DT_RELCOUNT, "RELCOUNT"}, - { DYNAMIC_TAGS::DT_FLAGS_1, "FLAGS_1"}, - { DYNAMIC_TAGS::DT_VERSYM, "VERSYM"}, - { DYNAMIC_TAGS::DT_VERDEF, "VERDEF"}, - { DYNAMIC_TAGS::DT_VERDEFNUM, "VERDEFNUM"}, - { DYNAMIC_TAGS::DT_VERNEED, "VERNEED"}, - { DYNAMIC_TAGS::DT_VERNEEDNUM, "VERNEEDNUM"}, - { DYNAMIC_TAGS::DT_SYMTAB_SHNDX, "SYMTAB_SHNDX"}, - { DYNAMIC_TAGS::DT_RELRSZ, "RELRSZ"}, - { DYNAMIC_TAGS::DT_RELR, "RELR"}, - { DYNAMIC_TAGS::DT_RELRENT, "RELRENT"}, - { DYNAMIC_TAGS::DT_MIPS_RLD_VERSION, "MIPS_RLD_VERSION"}, - { DYNAMIC_TAGS::DT_MIPS_TIME_STAMP, "MIPS_TIME_STAMP"}, - { DYNAMIC_TAGS::DT_MIPS_ICHECKSUM, "MIPS_ICHECKSUM"}, - { DYNAMIC_TAGS::DT_MIPS_IVERSION, "MIPS_IVERSION"}, - { DYNAMIC_TAGS::DT_MIPS_FLAGS, "MIPS_FLAGS"}, - { DYNAMIC_TAGS::DT_MIPS_BASE_ADDRESS, "MIPS_BASE_ADDRESS"}, - { DYNAMIC_TAGS::DT_MIPS_MSYM, "MIPS_MSYM"}, - { DYNAMIC_TAGS::DT_MIPS_CONFLICT, "MIPS_CONFLICT"}, - { DYNAMIC_TAGS::DT_MIPS_LIBLIST, "MIPS_LIBLIST"}, - { DYNAMIC_TAGS::DT_MIPS_LOCAL_GOTNO, "MIPS_LOCAL_GOTNO"}, - { DYNAMIC_TAGS::DT_MIPS_CONFLICTNO, "MIPS_CONFLICTNO"}, - { DYNAMIC_TAGS::DT_MIPS_LIBLISTNO, "MIPS_LIBLISTNO"}, - { DYNAMIC_TAGS::DT_MIPS_SYMTABNO, "MIPS_SYMTABNO"}, - { DYNAMIC_TAGS::DT_MIPS_UNREFEXTNO, "MIPS_UNREFEXTNO"}, - { DYNAMIC_TAGS::DT_MIPS_GOTSYM, "MIPS_GOTSYM"}, - { DYNAMIC_TAGS::DT_MIPS_HIPAGENO, "MIPS_HIPAGENO"}, - { DYNAMIC_TAGS::DT_MIPS_RLD_MAP, "MIPS_RLD_MAP"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_CLASS, "MIPS_DELTA_CLASS"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_CLASS_NO, "MIPS_DELTA_CLASS_NO"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_INSTANCE, "MIPS_DELTA_INSTANCE"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_INSTANCE_NO, "MIPS_DELTA_INSTANCE_NO"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_RELOC, "MIPS_DELTA_RELOC"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_RELOC_NO, "MIPS_DELTA_RELOC_NO"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_SYM, "MIPS_DELTA_SYM"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_SYM_NO, "MIPS_DELTA_SYM_NO"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_CLASSSYM, "MIPS_DELTA_CLASSSYM"}, - { DYNAMIC_TAGS::DT_MIPS_DELTA_CLASSSYM_NO, "MIPS_DELTA_CLASSSYM_NO"}, - { DYNAMIC_TAGS::DT_MIPS_CXX_FLAGS, "MIPS_CXX_FLAGS"}, - { DYNAMIC_TAGS::DT_MIPS_PIXIE_INIT, "MIPS_PIXIE_INIT"}, - { DYNAMIC_TAGS::DT_MIPS_SYMBOL_LIB, "MIPS_SYMBOL_LIB"}, - { DYNAMIC_TAGS::DT_MIPS_LOCALPAGE_GOTIDX, "MIPS_LOCALPAGE_GOTIDX"}, - { DYNAMIC_TAGS::DT_MIPS_LOCAL_GOTIDX, "MIPS_LOCAL_GOTIDX"}, - { DYNAMIC_TAGS::DT_MIPS_HIDDEN_GOTIDX, "MIPS_HIDDEN_GOTIDX"}, - { DYNAMIC_TAGS::DT_MIPS_PROTECTED_GOTIDX, "MIPS_PROTECTED_GOTIDX"}, - { DYNAMIC_TAGS::DT_MIPS_OPTIONS, "MIPS_OPTIONS"}, - { DYNAMIC_TAGS::DT_MIPS_INTERFACE, "MIPS_INTERFACE"}, - { DYNAMIC_TAGS::DT_MIPS_DYNSTR_ALIGN, "MIPS_DYNSTR_ALIGN"}, - { DYNAMIC_TAGS::DT_MIPS_INTERFACE_SIZE, "MIPS_INTERFACE_SIZE"}, - { DYNAMIC_TAGS::DT_MIPS_RLD_TEXT_RESOLVE_ADDR, "MIPS_RLD_TEXT_RESOLVE_ADDR"}, - { DYNAMIC_TAGS::DT_MIPS_PERF_SUFFIX, "MIPS_PERF_SUFFIX"}, - { DYNAMIC_TAGS::DT_MIPS_COMPACT_SIZE, "MIPS_COMPACT_SIZE"}, - { DYNAMIC_TAGS::DT_MIPS_GP_VALUE, "MIPS_GP_VALUE"}, - { DYNAMIC_TAGS::DT_MIPS_AUX_DYNAMIC, "MIPS_AUX_DYNAMIC"}, - { DYNAMIC_TAGS::DT_MIPS_PLTGOT, "MIPS_PLTGOT"}, - { DYNAMIC_TAGS::DT_MIPS_RWPLT, "MIPS_RWPLT"}, - { DYNAMIC_TAGS::DT_ANDROID_REL_OFFSET, "ANDROID_REL_OFFSET"}, - { DYNAMIC_TAGS::DT_ANDROID_REL_SIZE, "ANDROID_REL_SIZE"}, - { DYNAMIC_TAGS::DT_ANDROID_REL, "ANDROID_REL"}, - { DYNAMIC_TAGS::DT_ANDROID_RELSZ, "ANDROID_RELSZ"}, - { DYNAMIC_TAGS::DT_ANDROID_RELA, "ANDROID_RELA"}, - { DYNAMIC_TAGS::DT_ANDROID_RELASZ, "ANDROID_RELASZ"}, - { DYNAMIC_TAGS::DT_ANDROID_RELR, "ANDROID_RELR"}, - { DYNAMIC_TAGS::DT_ANDROID_RELRSZ, "ANDROID_RELRSZ"}, - { DYNAMIC_TAGS::DT_ANDROID_RELRENT, "ANDROID_RELRENT"}, - { DYNAMIC_TAGS::DT_ANDROID_RELRCOUNT, "ANDROID_RELRCOUNT"} - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(ELF_SECTION_TYPES e) { - CONST_MAP(ELF_SECTION_TYPES, const char*, 39) enumStrings { - { ELF_SECTION_TYPES::SHT_NULL, "NULL"}, - { ELF_SECTION_TYPES::SHT_PROGBITS, "PROGBITS"}, - { ELF_SECTION_TYPES::SHT_SYMTAB, "SYMTAB"}, - { ELF_SECTION_TYPES::SHT_STRTAB, "STRTAB"}, - { ELF_SECTION_TYPES::SHT_RELA, "RELA"}, - { ELF_SECTION_TYPES::SHT_HASH, "HASH"}, - { ELF_SECTION_TYPES::SHT_DYNAMIC, "DYNAMIC"}, - { ELF_SECTION_TYPES::SHT_NOTE, "NOTE"}, - { ELF_SECTION_TYPES::SHT_NOBITS, "NOBITS"}, - { ELF_SECTION_TYPES::SHT_REL, "REL"}, - { ELF_SECTION_TYPES::SHT_SHLIB, "SHLIB"}, - { ELF_SECTION_TYPES::SHT_DYNSYM, "DYNSYM"}, - { ELF_SECTION_TYPES::SHT_INIT_ARRAY, "INIT_ARRAY"}, - { ELF_SECTION_TYPES::SHT_FINI_ARRAY, "FINI_ARRAY"}, - { ELF_SECTION_TYPES::SHT_PREINIT_ARRAY, "PREINIT_ARRAY"}, - { ELF_SECTION_TYPES::SHT_GROUP, "GROUP"}, - { ELF_SECTION_TYPES::SHT_SYMTAB_SHNDX, "SYMTAB_SHNDX"}, - { ELF_SECTION_TYPES::SHT_LOOS, "LOOS"}, - { ELF_SECTION_TYPES::SHT_ANDROID_REL, "ANDROID_REL"}, - { ELF_SECTION_TYPES::SHT_ANDROID_RELA, "ANDROID_RELA"}, - { ELF_SECTION_TYPES::SHT_LLVM_ADDRSIG, "LLVM_ADDRSIG"}, - { ELF_SECTION_TYPES::SHT_RELR, "RELR"}, - { ELF_SECTION_TYPES::SHT_GNU_ATTRIBUTES, "GNU_ATTRIBUTES"}, - { ELF_SECTION_TYPES::SHT_GNU_HASH, "GNU_HASH"}, - { ELF_SECTION_TYPES::SHT_GNU_verdef, "GNU_VERDEF"}, - { ELF_SECTION_TYPES::SHT_GNU_verneed, "GNU_VERNEED"}, - { ELF_SECTION_TYPES::SHT_GNU_versym, "GNU_VERSYM"}, - { ELF_SECTION_TYPES::SHT_HIOS, "HIOS"}, - { ELF_SECTION_TYPES::SHT_LOPROC, "LOPROC"}, - { ELF_SECTION_TYPES::SHT_ARM_EXIDX, "ARM_EXIDX"}, - { ELF_SECTION_TYPES::SHT_ARM_PREEMPTMAP, "ARM_PREEMPTMAP"}, - { ELF_SECTION_TYPES::SHT_ARM_ATTRIBUTES, "ARM_ATTRIBUTES"}, - { ELF_SECTION_TYPES::SHT_ARM_DEBUGOVERLAY, "ARM_DEBUGOVERLAY"}, - { ELF_SECTION_TYPES::SHT_ARM_OVERLAYSECTION, "ARM_OVERLAYSECTION"}, - { ELF_SECTION_TYPES::SHT_HEX_ORDERED, "HEX_ORDERED"}, - { ELF_SECTION_TYPES::SHT_X86_64_UNWIND, "X86_64_UNWIND"}, - //{ ELF_SECTION_TYPES::SHT_MIPS_REGINFO, "MIPS_REGINFO"}, - //{ ELF_SECTION_TYPES::SHT_MIPS_OPTIONS, "MIPS_OPTIONS"}, - //{ ELF_SECTION_TYPES::SHT_MIPS_ABIFLAGS, "MIPS_ABIFLAGS"}, - { ELF_SECTION_TYPES::SHT_HIPROC, "HIPROC"}, - { ELF_SECTION_TYPES::SHT_LOUSER, "LOUSER"}, - { ELF_SECTION_TYPES::SHT_HIUSER, "HIUSER"} - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(ELF_SECTION_FLAGS e) { - CONST_MAP(ELF_SECTION_FLAGS, const char*, 25) enumStrings { - { ELF_SECTION_FLAGS::SHF_NONE, "NONE"}, - { ELF_SECTION_FLAGS::SHF_WRITE, "WRITE"}, - { ELF_SECTION_FLAGS::SHF_ALLOC, "ALLOC"}, - { ELF_SECTION_FLAGS::SHF_EXECINSTR, "EXECINSTR"}, - { ELF_SECTION_FLAGS::SHF_MERGE, "MERGE"}, - { ELF_SECTION_FLAGS::SHF_STRINGS, "STRINGS"}, - { ELF_SECTION_FLAGS::SHF_INFO_LINK, "INFO_LINK"}, - { ELF_SECTION_FLAGS::SHF_LINK_ORDER, "LINK_ORDER"}, - { ELF_SECTION_FLAGS::SHF_OS_NONCONFORMING, "OS_NONCONFORMING"}, - { ELF_SECTION_FLAGS::SHF_GROUP, "GROUP"}, - { ELF_SECTION_FLAGS::SHF_TLS, "TLS"}, - { ELF_SECTION_FLAGS::SHF_EXCLUDE, "EXCLUDE"}, - { ELF_SECTION_FLAGS::XCORE_SHF_CP_SECTION, "XCORE_SHF_CP_SECTION"}, - { ELF_SECTION_FLAGS::XCORE_SHF_DP_SECTION, "XCORE_SHF_CP_SECTION"}, - { ELF_SECTION_FLAGS::SHF_MASKOS, "MASKOS"}, - { ELF_SECTION_FLAGS::SHF_MASKPROC, "MASKPROC"}, - { ELF_SECTION_FLAGS::SHF_HEX_GPREL, "HEX_GPREL"}, - { ELF_SECTION_FLAGS::SHF_MIPS_NODUPES, "MIPS_NODUPES"}, - { ELF_SECTION_FLAGS::SHF_MIPS_NAMES, "MIPS_NAMES"}, - { ELF_SECTION_FLAGS::SHF_MIPS_LOCAL, "MIPS_LOCAL"}, - { ELF_SECTION_FLAGS::SHF_MIPS_NOSTRIP, "MIPS_NOSTRIP"}, - { ELF_SECTION_FLAGS::SHF_MIPS_GPREL, "MIPS_GPREL"}, - { ELF_SECTION_FLAGS::SHF_MIPS_MERGE, "MIPS_MERGE"}, - { ELF_SECTION_FLAGS::SHF_MIPS_ADDR, "MIPS_ADDR"}, - { ELF_SECTION_FLAGS::SHF_MIPS_STRING, "MIPS_STRING"} - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(ELF_SYMBOL_TYPES e) { - CONST_MAP(ELF_SYMBOL_TYPES, const char*, 8) enumStrings { - { ELF_SYMBOL_TYPES::STT_NOTYPE, "NOTYPE"}, - { ELF_SYMBOL_TYPES::STT_OBJECT, "OBJECT"}, - { ELF_SYMBOL_TYPES::STT_FUNC, "FUNC"}, - { ELF_SYMBOL_TYPES::STT_SECTION, "SECTION"}, - { ELF_SYMBOL_TYPES::STT_FILE, "FILE"}, - { ELF_SYMBOL_TYPES::STT_COMMON, "COMMON"}, - { ELF_SYMBOL_TYPES::STT_TLS, "TLS"}, - { ELF_SYMBOL_TYPES::STT_GNU_IFUNC, "GNU_IFUNC"}, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(RELOC_x86_64 e) { - CONST_MAP(RELOC_x86_64, const char*, 43) enumStrings { - { RELOC_x86_64::R_X86_64_NONE, "NONE"}, - { RELOC_x86_64::R_X86_64_64, "R64"}, - { RELOC_x86_64::R_X86_64_PC32, "PC32"}, - { RELOC_x86_64::R_X86_64_GOT32, "GOT32"}, - { RELOC_x86_64::R_X86_64_PLT32, "PLT32"}, - { RELOC_x86_64::R_X86_64_COPY, "COPY"}, - { RELOC_x86_64::R_X86_64_GLOB_DAT, "GLOB_DAT"}, - { RELOC_x86_64::R_X86_64_JUMP_SLOT, "JUMP_SLOT"}, - { RELOC_x86_64::R_X86_64_RELATIVE, "RELATIVE"}, - { RELOC_x86_64::R_X86_64_GOTPCREL, "GOTPCREL"}, - { RELOC_x86_64::R_X86_64_32, "R32"}, - { RELOC_x86_64::R_X86_64_32S, "R32S"}, - { RELOC_x86_64::R_X86_64_16, "R16"}, - { RELOC_x86_64::R_X86_64_PC16, "PC16"}, - { RELOC_x86_64::R_X86_64_8, "R8"}, - { RELOC_x86_64::R_X86_64_PC8, "PC8"}, - { RELOC_x86_64::R_X86_64_DTPMOD64, "DTPMOD64"}, - { RELOC_x86_64::R_X86_64_DTPOFF64, "DTPOFF64"}, - { RELOC_x86_64::R_X86_64_TPOFF64, "TPOFF64"}, - { RELOC_x86_64::R_X86_64_TLSGD, "TLSGD"}, - { RELOC_x86_64::R_X86_64_TLSLD, "TLSLD"}, - { RELOC_x86_64::R_X86_64_DTPOFF32, "DTPOFF32"}, - { RELOC_x86_64::R_X86_64_GOTTPOFF, "GOTTPOFF"}, - { RELOC_x86_64::R_X86_64_TPOFF32, "TPOFF32"}, - { RELOC_x86_64::R_X86_64_PC64, "PC64"}, - { RELOC_x86_64::R_X86_64_GOTOFF64, "GOTOFF64"}, - { RELOC_x86_64::R_X86_64_GOTPC32, "GOTPC32"}, - { RELOC_x86_64::R_X86_64_GOT64, "GOT64"}, - { RELOC_x86_64::R_X86_64_GOTPCREL64, "GOTPCREL64"}, - { RELOC_x86_64::R_X86_64_GOTPC64, "GOTPC64"}, - { RELOC_x86_64::R_X86_64_GOTPLT64, "GOTPLT64"}, - { RELOC_x86_64::R_X86_64_PLTOFF64, "PLTOFF64"}, - { RELOC_x86_64::R_X86_64_SIZE32, "SIZE32"}, - { RELOC_x86_64::R_X86_64_SIZE64, "SIZE64"}, - { RELOC_x86_64::R_X86_64_GOTPC32_TLSDESC, "GOTPC32_TLSDESC"}, - { RELOC_x86_64::R_X86_64_TLSDESC_CALL, "TLSDESC_CALL"}, - { RELOC_x86_64::R_X86_64_TLSDESC, "TLSDESC"}, - { RELOC_x86_64::R_X86_64_IRELATIVE, "IRELATIVE"}, - { RELOC_x86_64::R_X86_64_RELATIVE64, "RELATIVE64"}, - { RELOC_x86_64::R_X86_64_PC32_BND, "PC32_BND"}, - { RELOC_x86_64::R_X86_64_PLT32_BND, "PLT32_BND"}, - { RELOC_x86_64::R_X86_64_GOTPCRELX, "GOTPCRELX"}, - { RELOC_x86_64::R_X86_64_REX_GOTPCRELX, "REX_GOTPCRELX"}, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOC_ARM e) { - CONST_MAP(RELOC_ARM, const char*, 138) enumStrings { - { RELOC_ARM::R_ARM_NONE, "NONE"}, - { RELOC_ARM::R_ARM_PC24, "PC24"}, - { RELOC_ARM::R_ARM_ABS32, "ABS32"}, - { RELOC_ARM::R_ARM_REL32, "REL32"}, - { RELOC_ARM::R_ARM_LDR_PC_G0, "LDR_PC_G0"}, - { RELOC_ARM::R_ARM_ABS16, "ABS16"}, - { RELOC_ARM::R_ARM_ABS12, "ABS12"}, - { RELOC_ARM::R_ARM_THM_ABS5, "THM_ABS5"}, - { RELOC_ARM::R_ARM_ABS8, "ABS8"}, - { RELOC_ARM::R_ARM_SBREL32, "SBREL32"}, - { RELOC_ARM::R_ARM_THM_CALL, "THM_CALL"}, - { RELOC_ARM::R_ARM_THM_PC8, "THM_PC8"}, - { RELOC_ARM::R_ARM_BREL_ADJ, "BREL_ADJ"}, - { RELOC_ARM::R_ARM_TLS_DESC, "TLS_DESC"}, - { RELOC_ARM::R_ARM_THM_SWI8, "THM_SWI8"}, - { RELOC_ARM::R_ARM_XPC25, "XPC25"}, - { RELOC_ARM::R_ARM_THM_XPC22, "THM_XPC22"}, - { RELOC_ARM::R_ARM_TLS_DTPMOD32, "TLS_DTPMOD32"}, - { RELOC_ARM::R_ARM_TLS_DTPOFF32, "TLS_DTPOFF32"}, - { RELOC_ARM::R_ARM_TLS_TPOFF32, "TLS_TPOFF32"}, - { RELOC_ARM::R_ARM_COPY, "COPY"}, - { RELOC_ARM::R_ARM_GLOB_DAT, "GLOB_DAT"}, - { RELOC_ARM::R_ARM_JUMP_SLOT, "JUMP_SLOT"}, - { RELOC_ARM::R_ARM_RELATIVE, "RELATIVE"}, - { RELOC_ARM::R_ARM_GOTOFF32, "GOTOFF32"}, - { RELOC_ARM::R_ARM_BASE_PREL, "BASE_PREL"}, - { RELOC_ARM::R_ARM_GOT_BREL, "GOT_BREL"}, - { RELOC_ARM::R_ARM_PLT32, "PLT32"}, - { RELOC_ARM::R_ARM_CALL, "CALL"}, - { RELOC_ARM::R_ARM_JUMP24, "JUMP24"}, - { RELOC_ARM::R_ARM_THM_JUMP24, "THM_JUMP24"}, - { RELOC_ARM::R_ARM_BASE_ABS, "BASE_ABS"}, - { RELOC_ARM::R_ARM_ALU_PCREL_7_0, "ALU_PCREL_7_0"}, - { RELOC_ARM::R_ARM_ALU_PCREL_15_8, "ALU_PCREL_15_8"}, - { RELOC_ARM::R_ARM_ALU_PCREL_23_15, "ALU_PCREL_23_15"}, - { RELOC_ARM::R_ARM_LDR_SBREL_11_0_NC, "LDR_SBREL_11_0_NC"}, - { RELOC_ARM::R_ARM_ALU_SBREL_19_12_NC, "ALU_SBREL_19_12_NC"}, - { RELOC_ARM::R_ARM_ALU_SBREL_27_20_CK, "ALU_SBREL_27_20_CK"}, - { RELOC_ARM::R_ARM_TARGET1, "TARGET1"}, - { RELOC_ARM::R_ARM_SBREL31, "SBREL31"}, - { RELOC_ARM::R_ARM_V4BX, "V4BX"}, - { RELOC_ARM::R_ARM_TARGET2, "TARGET2"}, - { RELOC_ARM::R_ARM_PREL31, "PREL31"}, - { RELOC_ARM::R_ARM_MOVW_ABS_NC, "MOVW_ABS_NC"}, - { RELOC_ARM::R_ARM_MOVT_ABS, "MOVT_ABS"}, - { RELOC_ARM::R_ARM_MOVW_PREL_NC, "MOVW_PREL_NC"}, - { RELOC_ARM::R_ARM_MOVT_PREL, "MOVT_PREL"}, - { RELOC_ARM::R_ARM_THM_MOVW_ABS_NC, "THM_MOVW_ABS_NC"}, - { RELOC_ARM::R_ARM_THM_MOVT_ABS, "THM_MOVT_ABS"}, - { RELOC_ARM::R_ARM_THM_MOVW_PREL_NC, "THM_MOVW_PREL_NC"}, - { RELOC_ARM::R_ARM_THM_MOVT_PREL, "THM_MOVT_PREL"}, - { RELOC_ARM::R_ARM_THM_JUMP19, "THM_JUMP19"}, - { RELOC_ARM::R_ARM_THM_JUMP6, "THM_JUMP6"}, - { RELOC_ARM::R_ARM_THM_ALU_PREL_11_0, "THM_ALU_PREL_11_0"}, - { RELOC_ARM::R_ARM_THM_PC12, "THM_PC12"}, - { RELOC_ARM::R_ARM_ABS32_NOI, "ABS32_NOI"}, - { RELOC_ARM::R_ARM_REL32_NOI, "REL32_NOI"}, - { RELOC_ARM::R_ARM_ALU_PC_G0_NC, "ALU_PC_G0_NC"}, - { RELOC_ARM::R_ARM_ALU_PC_G0, "ALU_PC_G0"}, - { RELOC_ARM::R_ARM_ALU_PC_G1_NC, "ALU_PC_G1_NC"}, - { RELOC_ARM::R_ARM_ALU_PC_G1, "ALU_PC_G1"}, - { RELOC_ARM::R_ARM_ALU_PC_G2, "ALU_PC_G2"}, - { RELOC_ARM::R_ARM_LDR_PC_G1, "LDR_PC_G1"}, - { RELOC_ARM::R_ARM_LDR_PC_G2, "LDR_PC_G2"}, - { RELOC_ARM::R_ARM_LDRS_PC_G0, "LDRS_PC_G0"}, - { RELOC_ARM::R_ARM_LDRS_PC_G1, "LDRS_PC_G1"}, - { RELOC_ARM::R_ARM_LDRS_PC_G2, "LDRS_PC_G2"}, - { RELOC_ARM::R_ARM_LDC_PC_G0, "LDC_PC_G0"}, - { RELOC_ARM::R_ARM_LDC_PC_G1, "LDC_PC_G1"}, - { RELOC_ARM::R_ARM_LDC_PC_G2, "LDC_PC_G2"}, - { RELOC_ARM::R_ARM_ALU_SB_G0_NC, "ALU_SB_G0_NC"}, - { RELOC_ARM::R_ARM_ALU_SB_G0, "ALU_SB_G0"}, - { RELOC_ARM::R_ARM_ALU_SB_G1_NC, "ALU_SB_G1_NC"}, - { RELOC_ARM::R_ARM_ALU_SB_G1, "ALU_SB_G1"}, - { RELOC_ARM::R_ARM_ALU_SB_G2, "ALU_SB_G2"}, - { RELOC_ARM::R_ARM_LDR_SB_G0, "LDR_SB_G0"}, - { RELOC_ARM::R_ARM_LDR_SB_G1, "LDR_SB_G1"}, - { RELOC_ARM::R_ARM_LDR_SB_G2, "LDR_SB_G2"}, - { RELOC_ARM::R_ARM_LDRS_SB_G0, "LDRS_SB_G0"}, - { RELOC_ARM::R_ARM_LDRS_SB_G1, "LDRS_SB_G1"}, - { RELOC_ARM::R_ARM_LDRS_SB_G2, "LDRS_SB_G2"}, - { RELOC_ARM::R_ARM_LDC_SB_G0, "LDC_SB_G0"}, - { RELOC_ARM::R_ARM_LDC_SB_G1, "LDC_SB_G1"}, - { RELOC_ARM::R_ARM_LDC_SB_G2, "LDC_SB_G2"}, - { RELOC_ARM::R_ARM_MOVW_BREL_NC, "MOVW_BREL_NC"}, - { RELOC_ARM::R_ARM_MOVT_BREL, "MOVT_BREL"}, - { RELOC_ARM::R_ARM_MOVW_BREL, "MOVW_BREL"}, - { RELOC_ARM::R_ARM_THM_MOVW_BREL_NC, "THM_MOVW_BREL_NC"}, - { RELOC_ARM::R_ARM_THM_MOVT_BREL, "THM_MOVT_BREL"}, - { RELOC_ARM::R_ARM_THM_MOVW_BREL, "THM_MOVW_BREL"}, - { RELOC_ARM::R_ARM_TLS_GOTDESC, "TLS_GOTDESC"}, - { RELOC_ARM::R_ARM_TLS_CALL, "TLS_CALL"}, - { RELOC_ARM::R_ARM_TLS_DESCSEQ, "TLS_DESCSEQ"}, - { RELOC_ARM::R_ARM_THM_TLS_CALL, "THM_TLS_CALL"}, - { RELOC_ARM::R_ARM_PLT32_ABS, "PLT32_ABS"}, - { RELOC_ARM::R_ARM_GOT_ABS, "GOT_ABS"}, - { RELOC_ARM::R_ARM_GOT_PREL, "GOT_PREL"}, - { RELOC_ARM::R_ARM_GOT_BREL12, "GOT_BREL12"}, - { RELOC_ARM::R_ARM_GOTOFF12, "GOTOFF12"}, - { RELOC_ARM::R_ARM_GOTRELAX, "GOTRELAX"}, - { RELOC_ARM::R_ARM_GNU_VTENTRY, "GNU_VTENTRY"}, - { RELOC_ARM::R_ARM_GNU_VTINHERIT, "GNU_VTINHERIT"}, - { RELOC_ARM::R_ARM_THM_JUMP11, "THM_JUMP11"}, - { RELOC_ARM::R_ARM_THM_JUMP8, "THM_JUMP8"}, - { RELOC_ARM::R_ARM_TLS_GD32, "TLS_GD32"}, - { RELOC_ARM::R_ARM_TLS_LDM32, "TLS_LDM32"}, - { RELOC_ARM::R_ARM_TLS_LDO32, "TLS_LDO32"}, - { RELOC_ARM::R_ARM_TLS_IE32, "TLS_IE32"}, - { RELOC_ARM::R_ARM_TLS_LE32, "TLS_LE32"}, - { RELOC_ARM::R_ARM_TLS_LDO12, "TLS_LDO12"}, - { RELOC_ARM::R_ARM_TLS_LE12, "TLS_LE12"}, - { RELOC_ARM::R_ARM_TLS_IE12GP, "TLS_IE12GP"}, - { RELOC_ARM::R_ARM_PRIVATE_0, "PRIVATE_0"}, - { RELOC_ARM::R_ARM_PRIVATE_1, "PRIVATE_1"}, - { RELOC_ARM::R_ARM_PRIVATE_2, "PRIVATE_2"}, - { RELOC_ARM::R_ARM_PRIVATE_3, "PRIVATE_3"}, - { RELOC_ARM::R_ARM_PRIVATE_4, "PRIVATE_4"}, - { RELOC_ARM::R_ARM_PRIVATE_5, "PRIVATE_5"}, - { RELOC_ARM::R_ARM_PRIVATE_6, "PRIVATE_6"}, - { RELOC_ARM::R_ARM_PRIVATE_7, "PRIVATE_7"}, - { RELOC_ARM::R_ARM_PRIVATE_8, "PRIVATE_8"}, - { RELOC_ARM::R_ARM_PRIVATE_9, "PRIVATE_9"}, - { RELOC_ARM::R_ARM_PRIVATE_10, "PRIVATE_10"}, - { RELOC_ARM::R_ARM_PRIVATE_11, "PRIVATE_11"}, - { RELOC_ARM::R_ARM_PRIVATE_12, "PRIVATE_12"}, - { RELOC_ARM::R_ARM_PRIVATE_13, "PRIVATE_13"}, - { RELOC_ARM::R_ARM_PRIVATE_14, "PRIVATE_14"}, - { RELOC_ARM::R_ARM_PRIVATE_15, "PRIVATE_15"}, - { RELOC_ARM::R_ARM_ME_TOO, "ME_TOO"}, - { RELOC_ARM::R_ARM_THM_TLS_DESCSEQ16, "THM_TLS_DESCSEQ16"}, - { RELOC_ARM::R_ARM_THM_TLS_DESCSEQ32, "THM_TLS_DESCSEQ32"}, - { RELOC_ARM::R_ARM_IRELATIVE, "IRELATIVE"}, - { RELOC_ARM::R_ARM_RXPC25, "RXPC25"}, - { RELOC_ARM::R_ARM_RSBREL32, "RSBREL32"}, - { RELOC_ARM::R_ARM_THM_RPC22, "THM_RPC22"}, - { RELOC_ARM::R_ARM_RREL32, "RREL32"}, - { RELOC_ARM::R_ARM_RPC24, "RPC24"}, - { RELOC_ARM::R_ARM_RBASE, "RBASE"}, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOC_AARCH64 e) { - CONST_MAP(RELOC_AARCH64, const char*, 123) enumStrings { - { RELOC_AARCH64::R_AARCH64_NONE, "NONE"}, - { RELOC_AARCH64::R_AARCH64_ABS64, "ABS64"}, - { RELOC_AARCH64::R_AARCH64_ABS32, "ABS32"}, - { RELOC_AARCH64::R_AARCH64_ABS16, "ABS16"}, - { RELOC_AARCH64::R_AARCH64_PREL64, "PREL64"}, - { RELOC_AARCH64::R_AARCH64_PREL32, "PREL32"}, - { RELOC_AARCH64::R_AARCH64_PREL16, "PREL16"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G0, "MOVW_UABS_G0"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G0_NC, "MOVW_UABS_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G1, "MOVW_UABS_G1"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G1_NC, "MOVW_UABS_G1_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G2, "MOVW_UABS_G2"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G2_NC, "MOVW_UABS_G2_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G3, "MOVW_UABS_G3"}, - { RELOC_AARCH64::R_AARCH64_MOVW_SABS_G0, "MOVW_SABS_G0"}, - { RELOC_AARCH64::R_AARCH64_MOVW_SABS_G1, "MOVW_SABS_G1"}, - { RELOC_AARCH64::R_AARCH64_MOVW_SABS_G2, "MOVW_SABS_G2"}, - { RELOC_AARCH64::R_AARCH64_LD_PREL_LO19, "LD_PREL_LO19"}, - { RELOC_AARCH64::R_AARCH64_ADR_PREL_LO21, "ADR_PREL_LO21"}, - { RELOC_AARCH64::R_AARCH64_ADR_PREL_PG_HI21, "ADR_PREL_PG_HI21"}, - { RELOC_AARCH64::R_AARCH64_ADR_PREL_PG_HI21_NC, "ADR_PREL_PG_HI21_NC"}, - { RELOC_AARCH64::R_AARCH64_ADD_ABS_LO12_NC, "ADD_ABS_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_LDST8_ABS_LO12_NC, "LDST8_ABS_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TSTBR14, "TSTBR14"}, - { RELOC_AARCH64::R_AARCH64_CONDBR19, "CONDBR19"}, - { RELOC_AARCH64::R_AARCH64_JUMP26, "JUMP26"}, - { RELOC_AARCH64::R_AARCH64_CALL26, "CALL26"}, - { RELOC_AARCH64::R_AARCH64_LDST16_ABS_LO12_NC, "LDST16_ABS_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_LDST32_ABS_LO12_NC, "LDST32_ABS_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_LDST64_ABS_LO12_NC, "LDST64_ABS_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G0, "MOVW_PREL_G0"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G0_NC, "MOVW_PREL_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G1, "MOVW_PREL_G1"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G1_NC, "MOVW_PREL_G1_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G2, "MOVW_PREL_G2"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G2_NC, "MOVW_PREL_G2_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G3, "MOVW_PREL_G3"}, - { RELOC_AARCH64::R_AARCH64_LDST128_ABS_LO12_NC, "LDST128_ABS_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G0, "MOVW_GOTOFF_G0"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G0_NC, "MOVW_GOTOFF_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G1, "MOVW_GOTOFF_G1"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G1_NC, "MOVW_GOTOFF_G1_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G2, "MOVW_GOTOFF_G2"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G2_NC, "MOVW_GOTOFF_G2_NC"}, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G3, "MOVW_GOTOFF_G3"}, - { RELOC_AARCH64::R_AARCH64_GOTREL64, "GOTREL64"}, - { RELOC_AARCH64::R_AARCH64_GOTREL32, "GOTREL32"}, - { RELOC_AARCH64::R_AARCH64_GOT_LD_PREL19, "GOT_LD_PREL19"}, - { RELOC_AARCH64::R_AARCH64_LD64_GOTOFF_LO15, "LD64_GOTOFF_LO15"}, - { RELOC_AARCH64::R_AARCH64_ADR_GOT_PAGE, "ADR_GOT_PAGE"}, - { RELOC_AARCH64::R_AARCH64_LD64_GOT_LO12_NC, "LD64_GOT_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_LD64_GOTPAGE_LO15, "LD64_GOTPAGE_LO15"}, - { RELOC_AARCH64::R_AARCH64_TLSGD_ADR_PREL21, "TLSGD_ADR_PREL21"}, - { RELOC_AARCH64::R_AARCH64_TLSGD_ADR_PAGE21, "TLSGD_ADR_PAGE21"}, - { RELOC_AARCH64::R_AARCH64_TLSGD_ADD_LO12_NC, "TLSGD_ADD_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSGD_MOVW_G1, "TLSGD_MOVW_G1"}, - { RELOC_AARCH64::R_AARCH64_TLSGD_MOVW_G0_NC, "TLSGD_MOVW_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADR_PREL21, "TLSLD_ADR_PREL21"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADR_PAGE21, "TLSLD_ADR_PAGE21"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_LO12_NC, "TLSLD_ADD_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_G1, "TLSLD_MOVW_G1"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_G0_NC, "TLSLD_MOVW_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LD_PREL19, "TLSLD_LD_PREL19"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G2, "TLSLD_MOVW_DTPREL_G2"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G1, "TLSLD_MOVW_DTPREL_G1"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC, "TLSLD_MOVW_DTPREL_G1_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G0, "TLSLD_MOVW_DTPREL_G0"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC, "TLSLD_MOVW_DTPREL_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_HI12, "TLSLD_ADD_DTPREL_HI12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_LO12, "TLSLD_ADD_DTPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC, "TLSLD_ADD_DTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST8_DTPREL_LO12, "TLSLD_LDST8_DTPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, "TLSLD_LDST8_DTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST16_DTPREL_LO12, "TLSLD_LDST16_DTPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, "TLSLD_LDST16_DTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST32_DTPREL_LO12, "TLSLD_LDST32_DTPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, "TLSLD_LDST32_DTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST64_DTPREL_LO12, "TLSLD_LDST64_DTPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, "TLSLD_LDST64_DTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSIE_MOVW_GOTTPREL_G1, "TLSIE_MOVW_GOTTPREL_G1"}, - { RELOC_AARCH64::R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, "TLSIE_MOVW_GOTTPREL_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, "TLSIE_ADR_GOTTPREL_PAGE21"}, - { RELOC_AARCH64::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, "TLSIE_LD64_GOTTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSIE_LD_GOTTPREL_PREL19, "TLSIE_LD_GOTTPREL_PREL19"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G2, "TLSLE_MOVW_TPREL_G2"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G1, "TLSLE_MOVW_TPREL_G1"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G1_NC, "TLSLE_MOVW_TPREL_G1_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G0, "TLSLE_MOVW_TPREL_G0"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC, "TLSLE_MOVW_TPREL_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_HI12, "TLSLE_ADD_TPREL_HI12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_LO12, "TLSLE_ADD_TPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC, "TLSLE_ADD_TPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST8_TPREL_LO12, "TLSLE_LDST8_TPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC, "TLSLE_LDST8_TPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST16_TPREL_LO12, "TLSLE_LDST16_TPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC, "TLSLE_LDST16_TPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST32_TPREL_LO12, "TLSLE_LDST32_TPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC, "TLSLE_LDST32_TPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST64_TPREL_LO12, "TLSLE_LDST64_TPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC, "TLSLE_LDST64_TPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_LD_PREL19, "TLSDESC_LD_PREL19"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADR_PREL21, "TLSDESC_ADR_PREL21"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADR_PAGE21, "TLSDESC_ADR_PAGE21"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_LD64_LO12_NC, "TLSDESC_LD64_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADD_LO12_NC, "TLSDESC_ADD_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_OFF_G1, "TLSDESC_OFF_G1"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_OFF_G0_NC, "TLSDESC_OFF_G0_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_LDR, "TLSDESC_LDR"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADD, "TLSDESC_ADD"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC_CALL, "TLSDESC_CALL"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST128_TPREL_LO12, "TLSLE_LDST128_TPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC, "TLSLE_LDST128_TPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST128_DTPREL_LO12, "TLSLD_LDST128_DTPREL_LO12"}, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC, "TLSLD_LDST128_DTPREL_LO12_NC"}, - { RELOC_AARCH64::R_AARCH64_COPY, "COPY"}, - { RELOC_AARCH64::R_AARCH64_GLOB_DAT, "GLOB_DAT"}, - { RELOC_AARCH64::R_AARCH64_JUMP_SLOT, "JUMP_SLOT"}, - { RELOC_AARCH64::R_AARCH64_RELATIVE, "RELATIVE"}, - { RELOC_AARCH64::R_AARCH64_TLS_DTPREL64, "TLS_DTPREL64"}, - { RELOC_AARCH64::R_AARCH64_TLS_DTPMOD64, "TLS_DTPMOD64"}, - { RELOC_AARCH64::R_AARCH64_TLS_TPREL64, "TLS_TPREL64"}, - { RELOC_AARCH64::R_AARCH64_TLSDESC, "TLSDESC"}, - { RELOC_AARCH64::R_AARCH64_IRELATIVE, "IRELATIVE"}, - - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(RELOC_i386 e) { - CONST_MAP(RELOC_i386, const char*, 41) enumStrings { - { RELOC_i386::R_386_NONE, "NONE"}, - { RELOC_i386::R_386_32, "R32"}, - { RELOC_i386::R_386_PC32, "PC32"}, - { RELOC_i386::R_386_GOT32, "GOT32"}, - { RELOC_i386::R_386_PLT32, "PLT32"}, - { RELOC_i386::R_386_COPY, "COPY"}, - { RELOC_i386::R_386_GLOB_DAT, "GLOB_DAT"}, - { RELOC_i386::R_386_JUMP_SLOT, "JUMP_SLOT"}, - { RELOC_i386::R_386_RELATIVE, "RELATIVE"}, - { RELOC_i386::R_386_GOTOFF, "GOTOFF"}, - { RELOC_i386::R_386_GOTPC, "GOTPC"}, - { RELOC_i386::R_386_32PLT, "R32PLT"}, - { RELOC_i386::R_386_TLS_TPOFF, "TLS_TPOFF"}, - { RELOC_i386::R_386_TLS_IE, "TLS_IE"}, - { RELOC_i386::R_386_TLS_GOTIE, "TLS_GOTIE"}, - { RELOC_i386::R_386_TLS_LE, "TLS_LE"}, - { RELOC_i386::R_386_TLS_GD, "TLS_GD"}, - { RELOC_i386::R_386_TLS_LDM, "TLS_LDM"}, - { RELOC_i386::R_386_16, "R16"}, - { RELOC_i386::R_386_PC16, "PC16"}, - { RELOC_i386::R_386_8, "R8"}, - { RELOC_i386::R_386_PC8, "PC8"}, - { RELOC_i386::R_386_TLS_GD_32, "TLS_GD_32"}, - { RELOC_i386::R_386_TLS_GD_PUSH, "TLS_GD_PUSH"}, - { RELOC_i386::R_386_TLS_GD_CALL, "TLS_GD_CALL"}, - { RELOC_i386::R_386_TLS_GD_POP, "TLS_GD_POP"}, - { RELOC_i386::R_386_TLS_LDM_32, "TLS_LDM_32"}, - { RELOC_i386::R_386_TLS_LDM_PUSH, "TLS_LDM_PUSH"}, - { RELOC_i386::R_386_TLS_LDM_CALL, "TLS_LDM_CALL"}, - { RELOC_i386::R_386_TLS_LDM_POP, "TLS_LDM_POP"}, - { RELOC_i386::R_386_TLS_LDO_32, "TLS_LDO_32"}, - { RELOC_i386::R_386_TLS_IE_32, "TLS_IE_32"}, - { RELOC_i386::R_386_TLS_LE_32, "TLS_LE_32"}, - { RELOC_i386::R_386_TLS_DTPMOD32, "TLS_DTPMOD32"}, - { RELOC_i386::R_386_TLS_DTPOFF32, "TLS_DTPOFF32"}, - { RELOC_i386::R_386_TLS_TPOFF32, "TLS_TPOFF32"}, - { RELOC_i386::R_386_TLS_GOTDESC, "TLS_GOTDESC"}, - { RELOC_i386::R_386_TLS_DESC_CALL, "TLS_DESC_CALL"}, - { RELOC_i386::R_386_TLS_DESC, "TLS_DESC"}, - { RELOC_i386::R_386_IRELATIVE, "IRELATIVE"}, - { RELOC_i386::R_386_NUM, "NUM"}, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOC_POWERPC32 e) { - CONST_MAP(RELOC_POWERPC32, const char*, 57) enumStrings { - { RELOC_POWERPC32::R_PPC_NONE, "NONE" }, - { RELOC_POWERPC32::R_PPC_ADDR32, "ADDR32" }, - { RELOC_POWERPC32::R_PPC_ADDR24, "ADDR24" }, - { RELOC_POWERPC32::R_PPC_ADDR16, "ADDR16" }, - { RELOC_POWERPC32::R_PPC_ADDR16_LO, "ADDR16_LO" }, - { RELOC_POWERPC32::R_PPC_ADDR16_HI, "ADDR16_HI" }, - { RELOC_POWERPC32::R_PPC_ADDR16_HA, "ADDR16_HA" }, - { RELOC_POWERPC32::R_PPC_ADDR14, "ADDR14" }, - { RELOC_POWERPC32::R_PPC_ADDR14_BRTAKEN, "ADDR14_BRTAKEN" }, - { RELOC_POWERPC32::R_PPC_ADDR14_BRNTAKEN, "ADDR14_BRNTAKEN" }, - { RELOC_POWERPC32::R_PPC_REL24, "REL24" }, - { RELOC_POWERPC32::R_PPC_REL14, "REL14" }, - { RELOC_POWERPC32::R_PPC_REL14_BRTAKEN, "REL14_BRTAKEN" }, - { RELOC_POWERPC32::R_PPC_REL14_BRNTAKEN, "REL14_BRNTAKEN" }, - { RELOC_POWERPC32::R_PPC_GOT16, "GOT16" }, - { RELOC_POWERPC32::R_PPC_GOT16_LO, "GOT16_LO" }, - { RELOC_POWERPC32::R_PPC_GOT16_HI, "GOT16_HI" }, - { RELOC_POWERPC32::R_PPC_GOT16_HA, "GOT16_HA" }, - { RELOC_POWERPC32::R_PPC_PLTREL24, "PLTREL24" }, - { RELOC_POWERPC32::R_PPC_JMP_SLOT, "JMP_SLOT" }, - { RELOC_POWERPC32::R_PPC_RELATIVE, "RELATIVE" }, - { RELOC_POWERPC32::R_PPC_LOCAL24PC, "LOCAL24PC" }, - { RELOC_POWERPC32::R_PPC_REL32, "REL32" }, - { RELOC_POWERPC32::R_PPC_TLS, "TLS" }, - { RELOC_POWERPC32::R_PPC_DTPMOD32, "DTPMOD32" }, - { RELOC_POWERPC32::R_PPC_TPREL16, "TPREL16" }, - { RELOC_POWERPC32::R_PPC_TPREL16_LO, "TPREL16_LO" }, - { RELOC_POWERPC32::R_PPC_TPREL16_HI, "TPREL16_HI" }, - { RELOC_POWERPC32::R_PPC_TPREL16_HA, "TPREL16_HA" }, - { RELOC_POWERPC32::R_PPC_TPREL32, "TPREL32" }, - { RELOC_POWERPC32::R_PPC_DTPREL16, "DTPREL16" }, - { RELOC_POWERPC32::R_PPC_DTPREL16_LO, "DTPREL16_LO" }, - { RELOC_POWERPC32::R_PPC_DTPREL16_HI, "DTPREL16_HI" }, - { RELOC_POWERPC32::R_PPC_DTPREL16_HA, "DTPREL16_HA" }, - { RELOC_POWERPC32::R_PPC_DTPREL32, "DTPREL32" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16, "GOT_TLSGD16" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16_LO, "GOT_TLSGD16_LO" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16_HI, "GOT_TLSGD16_HI" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16_HA, "GOT_TLSGD16_HA" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16, "GOT_TLSLD16" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16_LO, "GOT_TLSLD16_LO" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16_HI, "GOT_TLSLD16_HI" }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16_HA, "GOT_TLSLD16_HA" }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16, "GOT_TPREL16" }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16_LO, "GOT_TPREL16_LO" }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16_HI, "GOT_TPREL16_HI" }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16_HA, "GOT_TPREL16_HA" }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16, "GOT_DTPREL16" }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16_LO, "GOT_DTPREL16_LO" }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16_HI, "GOT_DTPREL16_HI" }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16_HA, "GOT_DTPREL16_HA" }, - { RELOC_POWERPC32::R_PPC_TLSGD, "TLSGD" }, - { RELOC_POWERPC32::R_PPC_TLSLD, "TLSLD" }, - { RELOC_POWERPC32::R_PPC_REL16, "REL16" }, - { RELOC_POWERPC32::R_PPC_REL16_LO, "REL16_LO" }, - { RELOC_POWERPC32::R_PPC_REL16_HI, "REL16_HI" }, - { RELOC_POWERPC32::R_PPC_REL16_HA, "REL16_HA" }, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOC_POWERPC64 e) { - CONST_MAP(RELOC_POWERPC64, const char*, 84) enumStrings { - { RELOC_POWERPC64::R_PPC64_NONE, "NONE" }, - { RELOC_POWERPC64::R_PPC64_ADDR32, "ADDR32" }, - { RELOC_POWERPC64::R_PPC64_ADDR24, "ADDR24" }, - { RELOC_POWERPC64::R_PPC64_ADDR16, "ADDR16" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_LO, "ADDR16_LO" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HI, "ADDR16_HI" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HA, "ADDR16_HA" }, - { RELOC_POWERPC64::R_PPC64_ADDR14, "ADDR14" }, - { RELOC_POWERPC64::R_PPC64_ADDR14_BRTAKEN, "ADDR14_BRTAKEN" }, - { RELOC_POWERPC64::R_PPC64_ADDR14_BRNTAKEN, "ADDR14_BRNTAKEN" }, - { RELOC_POWERPC64::R_PPC64_REL24, "REL24" }, - { RELOC_POWERPC64::R_PPC64_REL14, "REL14" }, - { RELOC_POWERPC64::R_PPC64_REL14_BRTAKEN, "REL14_BRTAKEN" }, - { RELOC_POWERPC64::R_PPC64_REL14_BRNTAKEN, "REL14_BRNTAKEN" }, - { RELOC_POWERPC64::R_PPC64_GOT16, "GOT16" }, - { RELOC_POWERPC64::R_PPC64_GOT16_LO, "GOT16_LO" }, - { RELOC_POWERPC64::R_PPC64_GOT16_HI, "GOT16_HI" }, - { RELOC_POWERPC64::R_PPC64_GOT16_HA, "GOT16_HA" }, - { RELOC_POWERPC64::R_PPC64_JMP_SLOT, "JMP_SLOT" }, - { RELOC_POWERPC64::R_PPC64_RELATIVE, "RELATIVE"}, - { RELOC_POWERPC64::R_PPC64_REL32, "REL32" }, - { RELOC_POWERPC64::R_PPC64_ADDR64, "ADDR64" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHER, "ADDR16_HIGHER" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHERA, "ADDR16_HIGHERA" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHEST, "ADDR16_HIGHEST" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHESTA, "ADDR16_HIGHESTA" }, - { RELOC_POWERPC64::R_PPC64_REL64, "REL64" }, - { RELOC_POWERPC64::R_PPC64_TOC16, "TOC16" }, - { RELOC_POWERPC64::R_PPC64_TOC16_LO, "TOC16_LO" }, - { RELOC_POWERPC64::R_PPC64_TOC16_HI, "TOC16_HI" }, - { RELOC_POWERPC64::R_PPC64_TOC16_HA, "TOC16_HA" }, - { RELOC_POWERPC64::R_PPC64_TOC, "TOC" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_DS, "ADDR16_DS" }, - { RELOC_POWERPC64::R_PPC64_ADDR16_LO_DS, "ADDR16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_GOT16_DS, "GOT16_DS" }, - { RELOC_POWERPC64::R_PPC64_GOT16_LO_DS, "GOT16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_TOC16_DS, "TOC16_DS" }, - { RELOC_POWERPC64::R_PPC64_TOC16_LO_DS, "TOC16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_TLS, "TLS" }, - { RELOC_POWERPC64::R_PPC64_DTPMOD64, "DTPMOD64" }, - { RELOC_POWERPC64::R_PPC64_TPREL16, "TPREL16" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_LO, "TPREL16_LO" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HI, "TPREL16_HI" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HA, "TPREL16_HA" }, - { RELOC_POWERPC64::R_PPC64_TPREL64, "TPREL64" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16, "DTPREL16" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_LO, "DTPREL16_LO" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HI, "DTPREL16_HI" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HA, "DTPREL16_HA" }, - { RELOC_POWERPC64::R_PPC64_DTPREL64, "DTPREL64" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16, "GOT_TLSGD16" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_LO, "GOT_TLSGD16_LO" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_HI, "GOT_TLSGD16_HI" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_HA, "GOT_TLSGD16_HA" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16, "GOT_TLSLD16" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_LO, "GOT_TLSLD16_LO" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_HI, "GOT_TLSLD16_HI" }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_HA, "GOT_TLSLD16_HA" }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_DS, "GOT_TPREL16_DS" }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_LO_DS, "GOT_TPREL16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_HI, "GOT_TPREL16_HI" }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_HA, "GOT_TPREL16_HA" }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_DS, "GOT_DTPREL16_DS" }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_LO_DS, "GOT_DTPREL16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_HI, "GOT_DTPREL16_HI" }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_HA, "GOT_DTPREL16_HA" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_DS, "TPREL16_DS" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_LO_DS, "TPREL16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHER, "TPREL16_HIGHER" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHERA, "TPREL16_HIGHERA" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHEST, "TPREL16_HIGHEST" }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHESTA, "TPREL16_HIGHESTA" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_DS, "DTPREL16_DS" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_LO_DS, "DTPREL16_LO_DS" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHER, "DTPREL16_HIGHER" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHERA, "DTPREL16_HIGHERA" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHEST, "DTPREL16_HIGHEST" }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHESTA, "DTPREL16_HIGHESTA" }, - { RELOC_POWERPC64::R_PPC64_TLSGD, "TLSGD" }, - { RELOC_POWERPC64::R_PPC64_TLSLD, "TLSLD" }, - { RELOC_POWERPC64::R_PPC64_REL16, "REL16" }, - { RELOC_POWERPC64::R_PPC64_REL16_LO, "REL16_LO" }, - { RELOC_POWERPC64::R_PPC64_REL16_HI, "REL16_HI" }, - { RELOC_POWERPC64::R_PPC64_REL16_HA, "REL16_HA" }, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOC_MIPS e) { - CONST_MAP(RELOC_MIPS, const char*, 112) enumStrings { - { RELOC_MIPS::R_MICROMIPS_26_S1, "MIRCRO_MIPS_26_S1" }, - { RELOC_MIPS::R_MICROMIPS_CALL16, "MIRCRO_MIPS_CALL16" }, - { RELOC_MIPS::R_MICROMIPS_CALL_HI16, "MIRCRO_MIPS_CALL_HI16" }, - { RELOC_MIPS::R_MICROMIPS_CALL_LO16, "MIRCRO_MIPS_CALL_LO16" }, - { RELOC_MIPS::R_MICROMIPS_GOT16, "MIRCRO_MIPS_GOT16" }, - { RELOC_MIPS::R_MICROMIPS_GOT_DISP, "MIRCRO_MIPS_GOT_DISP" }, - { RELOC_MIPS::R_MICROMIPS_GOT_HI16, "MIRCRO_MIPS_GOT_HI16" }, - { RELOC_MIPS::R_MICROMIPS_GOT_LO16, "MIRCRO_MIPS_GOT_LO16" }, - { RELOC_MIPS::R_MICROMIPS_GOT_OFST, "MIRCRO_MIPS_GOT_OFST" }, - { RELOC_MIPS::R_MICROMIPS_GOT_PAGE, "MIRCRO_MIPS_GOT_PAGE" }, - { RELOC_MIPS::R_MICROMIPS_GPREL16, "MIRCRO_MIPS_GPREL16" }, - { RELOC_MIPS::R_MICROMIPS_GPREL7_S2, "MIRCRO_MIPS_GPREL7_S2" }, - { RELOC_MIPS::R_MICROMIPS_HI0_LO16, "MIRCRO_MIPS_HI0_LO16" }, - { RELOC_MIPS::R_MICROMIPS_HI16, "MIRCRO_MIPS_HI16" }, - { RELOC_MIPS::R_MICROMIPS_HIGHER, "MIRCRO_MIPS_HIGHER" }, - { RELOC_MIPS::R_MICROMIPS_HIGHEST, "MIRCRO_MIPS_HIGHEST" }, - { RELOC_MIPS::R_MICROMIPS_JALR, "MIRCRO_MIPS_JALR" }, - { RELOC_MIPS::R_MICROMIPS_LITERAL, "MIRCRO_MIPS_LITERAL" }, - { RELOC_MIPS::R_MICROMIPS_LO16, "MIRCRO_MIPS_LO16" }, - { RELOC_MIPS::R_MICROMIPS_PC10_S1, "MIRCRO_MIPS_PC10_S1" }, - { RELOC_MIPS::R_MICROMIPS_PC16_S1, "MIRCRO_MIPS_PC16_S1" }, - { RELOC_MIPS::R_MICROMIPS_PC18_S3, "MIRCRO_MIPS_PC18_S3" }, - { RELOC_MIPS::R_MICROMIPS_PC19_S2, "MIRCRO_MIPS_PC19_S2" }, - { RELOC_MIPS::R_MICROMIPS_PC21_S2, "MIRCRO_MIPS_PC21_S2" }, - { RELOC_MIPS::R_MICROMIPS_PC23_S2, "MIRCRO_MIPS_PC23_S2" }, - { RELOC_MIPS::R_MICROMIPS_PC26_S2, "MIRCRO_MIPS_PC26_S2" }, - { RELOC_MIPS::R_MICROMIPS_PC7_S1, "MIRCRO_MIPS_PC7_S1" }, - { RELOC_MIPS::R_MICROMIPS_SCN_DISP, "MIRCRO_MIPS_SCN_DISP" }, - { RELOC_MIPS::R_MICROMIPS_SUB, "MIRCRO_MIPS_SUB" }, - { RELOC_MIPS::R_MICROMIPS_TLS_DTPREL_HI16, "MIRCRO_MIPS_TLS_DTPREL_HI16" }, - { RELOC_MIPS::R_MICROMIPS_TLS_DTPREL_LO16, "MIRCRO_MIPS_TLS_DTPREL_LO16" }, - { RELOC_MIPS::R_MICROMIPS_TLS_GD, "MIRCRO_MIPS_TLS_GD" }, - { RELOC_MIPS::R_MICROMIPS_TLS_GOTTPREL, "MIRCRO_MIPS_TLS_GOTTPREL" }, - { RELOC_MIPS::R_MICROMIPS_TLS_LDM, "MIRCRO_MIPS_TLS_LDM" }, - { RELOC_MIPS::R_MICROMIPS_TLS_TPREL_HI16, "MIRCRO_MIPS_TLS_TPREL_HI16" }, - { RELOC_MIPS::R_MICROMIPS_TLS_TPREL_LO16, "MIRCRO_MIPS_TLS_TPREL_LO16" }, - { RELOC_MIPS::R_MIPS_16, "MIPS16_16"}, - { RELOC_MIPS::R_MIPS16_26, "MIPS16_26" }, - { RELOC_MIPS::R_MIPS16_CALL16, "MIPS16_CALL16" }, - { RELOC_MIPS::R_MIPS16_GOT16, "MIPS16_GOT16" }, - { RELOC_MIPS::R_MIPS16_GPREL, "MIPS16_GPREL" }, - { RELOC_MIPS::R_MIPS16_HI16, "MIPS16_HI16" }, - { RELOC_MIPS::R_MIPS16_LO16, "MIPS16_LO16" }, - { RELOC_MIPS::R_MIPS16_TLS_DTPREL_HI16, "MIPS16_TLS_DTPREL_HI16" }, - { RELOC_MIPS::R_MIPS16_TLS_DTPREL_LO16, "MIPS16_TLS_DTPREL_LO16" }, - { RELOC_MIPS::R_MIPS16_TLS_GD, "MIPS16_TLS_GD" }, - { RELOC_MIPS::R_MIPS16_TLS_GOTTPREL, "MIPS16_TLS_GOTTPREL" }, - { RELOC_MIPS::R_MIPS16_TLS_LDM, "MIPS16_TLS_LDM" }, - { RELOC_MIPS::R_MIPS16_TLS_TPREL_HI16, "MIPS16_TLS_TPREL_HI16" }, - { RELOC_MIPS::R_MIPS16_TLS_TPREL_LO16, "MIPS16_TLS_TPREL_LO16" }, - { RELOC_MIPS::R_MIPS_26, "MIPS_26" }, - { RELOC_MIPS::R_MIPS_32, "MIPS_32" }, - { RELOC_MIPS::R_MIPS_64, "MIPS_64" }, - { RELOC_MIPS::R_MIPS_ADD_IMMEDIATE, "MIPS_ADD_IMMEDIATE" }, - { RELOC_MIPS::R_MIPS_CALL16, "MIPS_CALL16" }, - { RELOC_MIPS::R_MIPS_CALL_HI16, "MIPS_CALL_HI16" }, - { RELOC_MIPS::R_MIPS_CALL_LO16, "MIPS_CALL_LO16" }, - { RELOC_MIPS::R_MIPS_COPY, "MIPS_COPY" }, - { RELOC_MIPS::R_MIPS_DELETE, "MIPS_DELETE" }, - { RELOC_MIPS::R_MIPS_EH, "MIPS_EH" }, - { RELOC_MIPS::R_MIPS_GLOB_DAT, "MIPS_GLOB_DAT" }, - { RELOC_MIPS::R_MIPS_GOT16, "MIPS_GOT16" }, - { RELOC_MIPS::R_MIPS_GOT_DISP, "MIPS_GOT_DISP" }, - { RELOC_MIPS::R_MIPS_GOT_HI16, "MIPS_GOT_HI16" }, - { RELOC_MIPS::R_MIPS_GOT_LO16, "MIPS_GOT_LO16" }, - { RELOC_MIPS::R_MIPS_GOT_OFST, "MIPS_GOT_OFST" }, - { RELOC_MIPS::R_MIPS_GOT_PAGE, "MIPS_GOT_PAGE" }, - { RELOC_MIPS::R_MIPS_GPREL16, "MIPS_GPREL16" }, - { RELOC_MIPS::R_MIPS_GPREL32, "MIPS_GPREL32" }, - { RELOC_MIPS::R_MIPS_HI16, "MIPS_HI16" }, - { RELOC_MIPS::R_MIPS_HIGHER, "MIPS_HIGHER" }, - { RELOC_MIPS::R_MIPS_HIGHEST, "MIPS_HIGHEST" }, - { RELOC_MIPS::R_MIPS_INSERT_A, "MIPS_INSERT_A" }, - { RELOC_MIPS::R_MIPS_INSERT_B, "MIPS_INSERT_B" }, - { RELOC_MIPS::R_MIPS_JALR, "MIPS_JALR" }, - { RELOC_MIPS::R_MIPS_JUMP_SLOT, "MIPS_JUMP_SLOT" }, - { RELOC_MIPS::R_MIPS_LITERAL, "MIPS_LITERAL" }, - { RELOC_MIPS::R_MIPS_LO16, "MIPS_LO16" }, - { RELOC_MIPS::R_MIPS_NONE, "MIPS_NONE"}, - { RELOC_MIPS::R_MIPS_NUM, "MIPS_NUM" }, - { RELOC_MIPS::R_MIPS_PC16, "MIPS_PC16" }, - { RELOC_MIPS::R_MIPS_PC18_S3, "MIPS_PC18_S3" }, - { RELOC_MIPS::R_MIPS_PC19_S2, "MIPS_PC19_S2" }, - { RELOC_MIPS::R_MIPS_PC21_S2, "MIPS_PC21_S2" }, - { RELOC_MIPS::R_MIPS_PC26_S2, "MIPS_PC26_S2" }, - { RELOC_MIPS::R_MIPS_PC32, "MIPS_PC32" }, - { RELOC_MIPS::R_MIPS_PCHI16, "MIPS_PCHI16" }, - { RELOC_MIPS::R_MIPS_PCLO16, "MIPS_PCLO16" }, - { RELOC_MIPS::R_MIPS_PJUMP, "MIPS_PJUMP" }, - { RELOC_MIPS::R_MIPS_REL16, "MIPS_REL16" }, - { RELOC_MIPS::R_MIPS_REL32, "MIPS_REL32" }, - { RELOC_MIPS::R_MIPS_RELGOT, "MIPS_RELGOT" }, - { RELOC_MIPS::R_MIPS_SCN_DISP, "MIPS_SCN_DISP" }, - { RELOC_MIPS::R_MIPS_SHIFT5, "MIPS_SHIFT5" }, - { RELOC_MIPS::R_MIPS_SHIFT6, "MIPS_SHIFT6" }, - { RELOC_MIPS::R_MIPS_SUB, "MIPS_SUB" }, - { RELOC_MIPS::R_MIPS_TLS_DTPMOD32, "MIPS_TLS_DTPMOD32" }, - { RELOC_MIPS::R_MIPS_TLS_DTPMOD64, "MIPS_TLS_DTPMOD64" }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL32, "MIPS_TLS_DTPREL32" }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL64, "MIPS_TLS_DTPREL64" }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL_HI16, "MIPS_TLS_DTPREL_HI16" }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL_LO16, "MIPS_TLS_DTPREL_LO16" }, - { RELOC_MIPS::R_MIPS_TLS_GD, "MIPS_TLS_GD" }, - { RELOC_MIPS::R_MIPS_TLS_GOTTPREL, "MIPS_TLS_GOTTPREL" }, - { RELOC_MIPS::R_MIPS_TLS_LDM, "MIPS_TLS_LDM" }, - { RELOC_MIPS::R_MIPS_TLS_TPREL32, "MIPS_TLS_TPREL32" }, - { RELOC_MIPS::R_MIPS_TLS_TPREL64, "MIPS_TLS_TPREL64" }, - { RELOC_MIPS::R_MIPS_TLS_TPREL_HI16, "MIPS_TLS_TPREL_HI16" }, - { RELOC_MIPS::R_MIPS_TLS_TPREL_LO16, "MIPS_TLS_TPREL_LO16" }, - { RELOC_MIPS::R_MIPS_UNUSED1, "MIPS_UNUSED1" }, - { RELOC_MIPS::R_MIPS_UNUSED2, "MIPS_UNUSED2" }, - { RELOC_MIPS::R_MIPS_UNUSED3, "MIPS_UNUSED3" }, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOC_LOONGARCH e) { - CONST_MAP(RELOC_LOONGARCH, const char*, 89) enumStrings { - { RELOC_LOONGARCH::R_LARCH_NONE, "LARCH_NONE" }, - { RELOC_LOONGARCH::R_LARCH_32, "LARCH_32" }, - { RELOC_LOONGARCH::R_LARCH_64, "LARCH_64" }, - { RELOC_LOONGARCH::R_LARCH_RELATIVE, "LARCH_RELATIVE" }, - { RELOC_LOONGARCH::R_LARCH_COPY, "LARCH_COPY" }, - { RELOC_LOONGARCH::R_LARCH_JUMP_SLOT, "LARCH_JUMP_SLOT" }, - { RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD32, "LARCH_TLS_DTPMOD32" }, - { RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD64, "LARCH_TLS_DTPMOD64" }, - { RELOC_LOONGARCH::R_LARCH_TLS_DTPREL32, "LARCH_TLS_DTPREL32" }, - { RELOC_LOONGARCH::R_LARCH_TLS_DTPREL64, "LARCH_TLS_DTPREL64" }, - { RELOC_LOONGARCH::R_LARCH_TLS_TPREL32, "LARCH_TLS_TPREL32" }, - { RELOC_LOONGARCH::R_LARCH_TLS_TPREL64, "LARCH_TLS_TPREL64" }, - { RELOC_LOONGARCH::R_LARCH_IRELATIVE, "LARCH_IRELATIVE" }, - { RELOC_LOONGARCH::R_LARCH_MARK_LA, "LARCH_MARK_LA" }, - { RELOC_LOONGARCH::R_LARCH_MARK_PCREL, "LARCH_MARK_PCREL" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PCREL, "LARCH_SOP_PUSH_PCREL" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_ABSOLUTE, "LARCH_SOP_PUSH_ABSOLUTE" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_DUP, "LARCH_SOP_PUSH_DUP" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_GPREL, "LARCH_SOP_PUSH_GPREL" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_TPREL, "LARCH_SOP_PUSH_TLS_TPREL" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GOT, "LARCH_SOP_PUSH_TLS_GOT" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GD, "LARCH_SOP_PUSH_TLS_GD" }, - { RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PLT_PCREL, "LARCH_SOP_PUSH_PLT_PCREL" }, - { RELOC_LOONGARCH::R_LARCH_SOP_ASSERT, "LARCH_SOP_ASSERT" }, - { RELOC_LOONGARCH::R_LARCH_SOP_NOT, "LARCH_SOP_NOT" }, - { RELOC_LOONGARCH::R_LARCH_SOP_SUB, "LARCH_SOP_SUB" }, - { RELOC_LOONGARCH::R_LARCH_SOP_SL, "LARCH_SOP_SL" }, - { RELOC_LOONGARCH::R_LARCH_SOP_SR, "LARCH_SOP_SR" }, - { RELOC_LOONGARCH::R_LARCH_SOP_ADD, "LARCH_SOP_ADD" }, - { RELOC_LOONGARCH::R_LARCH_SOP_AND, "LARCH_SOP_AND" }, - { RELOC_LOONGARCH::R_LARCH_SOP_IF_ELSE, "LARCH_SOP_IF_ELSE" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_5, "LARCH_SOP_POP_32_S_10_5" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U_10_12, "LARCH_SOP_POP_32_U_10_12" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_12, "LARCH_SOP_POP_32_S_10_12" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16, "LARCH_SOP_POP_32_S_10_16" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16_S2, "LARCH_SOP_POP_32_S_10_16_S2" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_5_20, "LARCH_SOP_POP_32_S_5_20" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_5_10_16_S2, "LARCH_SOP_POP_32_S_0_5_10_16_S2" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_10_10_16_S2, "LARCH_SOP_POP_32_S_0_10_10_16_S2" }, - { RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U, "LARCH_SOP_POP_32_U" }, - { RELOC_LOONGARCH::R_LARCH_ADD8, "LARCH_ADD8" }, - { RELOC_LOONGARCH::R_LARCH_ADD16, "LARCH_ADD16" }, - { RELOC_LOONGARCH::R_LARCH_ADD24, "LARCH_ADD24" }, - { RELOC_LOONGARCH::R_LARCH_ADD32, "LARCH_ADD32" }, - { RELOC_LOONGARCH::R_LARCH_ADD64, "LARCH_ADD64" }, - { RELOC_LOONGARCH::R_LARCH_SUB8, "LARCH_SUB8" }, - { RELOC_LOONGARCH::R_LARCH_SUB16, "LARCH_SUB16" }, - { RELOC_LOONGARCH::R_LARCH_SUB24, "LARCH_SUB24" }, - { RELOC_LOONGARCH::R_LARCH_SUB32, "LARCH_SUB32" }, - { RELOC_LOONGARCH::R_LARCH_SUB64, "LARCH_SUB64" }, - { RELOC_LOONGARCH::R_LARCH_GNU_VTINHERIT, "LARCH_GNU_VTINHERIT" }, - { RELOC_LOONGARCH::R_LARCH_GNU_VTENTRY, "LARCH_GNU_VTENTRY" }, - { RELOC_LOONGARCH::R_LARCH_B16, "LARCH_B16" }, - { RELOC_LOONGARCH::R_LARCH_B21, "LARCH_B21" }, - { RELOC_LOONGARCH::R_LARCH_B26, "LARCH_B26" }, - { RELOC_LOONGARCH::R_LARCH_ABS_HI20, "LARCH_ABS_HI20" }, - { RELOC_LOONGARCH::R_LARCH_ABS_LO12, "LARCH_ABS_LO12" }, - { RELOC_LOONGARCH::R_LARCH_ABS64_LO20, "LARCH_ABS64_LO20" }, - { RELOC_LOONGARCH::R_LARCH_ABS64_HI12, "LARCH_ABS64_HI12" }, - { RELOC_LOONGARCH::R_LARCH_PCALA_HI20, "LARCH_PCALA_HI20" }, - { RELOC_LOONGARCH::R_LARCH_PCALA_LO12, "LARCH_PCALA_LO12" }, - { RELOC_LOONGARCH::R_LARCH_PCALA64_LO20, "LARCH_PCALA64_LO20" }, - { RELOC_LOONGARCH::R_LARCH_PCALA64_HI12, "LARCH_PCALA64_HI12" }, - { RELOC_LOONGARCH::R_LARCH_GOT_PC_HI20, "LARCH_GOT_PC_HI20" }, - { RELOC_LOONGARCH::R_LARCH_GOT_PC_LO12, "LARCH_GOT_PC_LO12" }, - { RELOC_LOONGARCH::R_LARCH_GOT64_PC_LO20, "LARCH_GOT64_PC_LO20" }, - { RELOC_LOONGARCH::R_LARCH_GOT64_PC_HI12, "LARCH_GOT64_PC_HI12" }, - { RELOC_LOONGARCH::R_LARCH_GOT_HI20, "LARCH_GOT_HI20" }, - { RELOC_LOONGARCH::R_LARCH_GOT_LO12, "LARCH_GOT_LO12" }, - { RELOC_LOONGARCH::R_LARCH_GOT64_LO20, "LARCH_GOT64_LO20" }, - { RELOC_LOONGARCH::R_LARCH_GOT64_HI12, "LARCH_GOT64_HI12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_LE_HI20, "LARCH_TLS_LE_HI20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_LE_LO12, "LARCH_TLS_LE_LO12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_LE64_LO20, "LARCH_TLS_LE64_LO20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_LE64_HI12, "LARCH_TLS_LE64_HI12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_HI20, "LARCH_TLS_IE_PC_HI20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_LO12, "LARCH_TLS_IE_PC_LO12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_LO20, "LARCH_TLS_IE64_PC_LO20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_HI12, "LARCH_TLS_IE64_PC_HI12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE_HI20, "LARCH_TLS_IE_HI20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE_LO12, "LARCH_TLS_IE_LO12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE64_LO20, "LARCH_TLS_IE64_LO20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_IE64_HI12, "LARCH_TLS_IE64_HI12" }, - { RELOC_LOONGARCH::R_LARCH_TLS_LD_PC_HI20, "LARCH_TLS_LD_PC_HI20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_LD_HI20, "LARCH_TLS_LD_HI20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_GD_PC_HI20, "LARCH_TLS_GD_PC_HI20" }, - { RELOC_LOONGARCH::R_LARCH_TLS_GD_HI20, "LARCH_TLS_GD_HI20" }, - { RELOC_LOONGARCH::R_LARCH_32_PCREL, "LARCH_32_PCREL" }, - { RELOC_LOONGARCH::R_LARCH_RELAX, "LARCH_RELAX" }, - }; - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(ELF_CLASS e) { - CONST_MAP(ELF_CLASS, const char*, 3) enumStrings { - { ELF_CLASS::ELFCLASSNONE, "NONE"}, - { ELF_CLASS::ELFCLASS32, "CLASS32"}, - { ELF_CLASS::ELFCLASS64, "CLASS64"}, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(ELF_DATA e) { - CONST_MAP(ELF_DATA, const char*, 3) enumStrings { - { ELF_DATA::ELFDATANONE, "NONE"}, - { ELF_DATA::ELFDATA2LSB, "LSB"}, - { ELF_DATA::ELFDATA2MSB, "MSB"}, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(OS_ABI e) { - CONST_MAP(OS_ABI, const char*, 23) enumStrings { - { OS_ABI::ELFOSABI_SYSTEMV, "SYSTEMV"}, - { OS_ABI::ELFOSABI_HPUX, "HPUX"}, - { OS_ABI::ELFOSABI_NETBSD, "NETBSD"}, - { OS_ABI::ELFOSABI_GNU, "GNU"}, - { OS_ABI::ELFOSABI_LINUX, "LINUX"}, - { OS_ABI::ELFOSABI_HURD, "HURD"}, - { OS_ABI::ELFOSABI_SOLARIS, "SOLARIS"}, - { OS_ABI::ELFOSABI_AIX, "AIX"}, - { OS_ABI::ELFOSABI_IRIX, "IRIX"}, - { OS_ABI::ELFOSABI_FREEBSD, "FREEBSD"}, - { OS_ABI::ELFOSABI_TRU64, "TRU64"}, - { OS_ABI::ELFOSABI_MODESTO, "MODESTO"}, - { OS_ABI::ELFOSABI_OPENBSD, "OPENBSD"}, - { OS_ABI::ELFOSABI_OPENVMS, "OPENVMS"}, - { OS_ABI::ELFOSABI_NSK, "NSK"}, - { OS_ABI::ELFOSABI_AROS, "AROS"}, - { OS_ABI::ELFOSABI_FENIXOS, "FENIXOS"}, - { OS_ABI::ELFOSABI_CLOUDABI, "CLOUDABI"}, - { OS_ABI::ELFOSABI_C6000_ELFABI, "C6000_ELFABI"}, - { OS_ABI::ELFOSABI_AMDGPU_HSA, "AMDGPU_HSA"}, - { OS_ABI::ELFOSABI_C6000_LINUX, "C6000_LINUX"}, - { OS_ABI::ELFOSABI_ARM, "ARM"}, - { OS_ABI::ELFOSABI_STANDALONE, "STANDALONE"}, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(DYNSYM_COUNT_METHODS e) { - CONST_MAP(DYNSYM_COUNT_METHODS, const char*, 4) enumStrings { - { DYNSYM_COUNT_METHODS::COUNT_AUTO, "AUTO"}, - { DYNSYM_COUNT_METHODS::COUNT_SECTION, "SECTION"}, - { DYNSYM_COUNT_METHODS::COUNT_HASH, "HASH"}, - { DYNSYM_COUNT_METHODS::COUNT_RELOCATIONS, "RELOCATIONS"}, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(RELOCATION_PURPOSES e) { - CONST_MAP(RELOCATION_PURPOSES, const char*, 4) enumStrings { - { RELOCATION_PURPOSES::RELOC_PURPOSE_NONE, "NONE"}, - { RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT, "PLTGOT"}, - { RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC, "DYNAMIC"}, - { RELOCATION_PURPOSES::RELOC_PURPOSE_OBJECT, "OBJECT"}, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(PPC64_EFLAGS e) { - CONST_MAP(PPC64_EFLAGS, const char*, 1) enumStrings { - { PPC64_EFLAGS::EF_PPC64_ABI, "ABI"}, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(ARM_EFLAGS e) { - CONST_MAP(ARM_EFLAGS, const char*, 8) enumStrings { - { ARM_EFLAGS::EF_ARM_SOFT_FLOAT, "SOFT_FLOAT" }, - { ARM_EFLAGS::EF_ARM_VFP_FLOAT, "VFP_FLOAT" }, - { ARM_EFLAGS::EF_ARM_EABI_UNKNOWN, "UNKNOWN" }, - { ARM_EFLAGS::EF_ARM_EABI_VER1, "EABI_VER1" }, - { ARM_EFLAGS::EF_ARM_EABI_VER2, "EABI_VER2" }, - { ARM_EFLAGS::EF_ARM_EABI_VER3, "EABI_VER3" }, - { ARM_EFLAGS::EF_ARM_EABI_VER4, "EABI_VER4" }, - { ARM_EFLAGS::EF_ARM_EABI_VER5, "EABI_VER5" }, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(MIPS_EFLAGS e) { - CONST_MAP(MIPS_EFLAGS, const char*, 43) enumStrings { - { MIPS_EFLAGS::EF_MIPS_NOREORDER, "NOREORDER" }, - { MIPS_EFLAGS::EF_MIPS_PIC, "PIC" }, - { MIPS_EFLAGS::EF_MIPS_CPIC, "CPIC" }, - { MIPS_EFLAGS::EF_MIPS_ABI2, "ABI2" }, - { MIPS_EFLAGS::EF_MIPS_32BITMODE, "_32BITMODE" }, - { MIPS_EFLAGS::EF_MIPS_FP64, "FP64" }, - { MIPS_EFLAGS::EF_MIPS_NAN2008, "NAN2008" }, - - { MIPS_EFLAGS::EF_MIPS_ABI_O32, "ABI_O32" }, - { MIPS_EFLAGS::EF_MIPS_ABI_O64, "ABI_O64" }, - { MIPS_EFLAGS::EF_MIPS_ABI_EABI32, "ABI_EABI32" }, - { MIPS_EFLAGS::EF_MIPS_ABI_EABI64, "ABI_EABI64" }, - - { MIPS_EFLAGS::EF_MIPS_MACH_3900, "MACH_3900" }, - { MIPS_EFLAGS::EF_MIPS_MACH_4010, "MACH_4010" }, - { MIPS_EFLAGS::EF_MIPS_MACH_4100, "MACH_4100" }, - { MIPS_EFLAGS::EF_MIPS_MACH_4650, "MACH_4650" }, - { MIPS_EFLAGS::EF_MIPS_MACH_4120, "MACH_4120" }, - { MIPS_EFLAGS::EF_MIPS_MACH_4111, "MACH_4111" }, - { MIPS_EFLAGS::EF_MIPS_MACH_SB1, "MACH_SB1" }, - { MIPS_EFLAGS::EF_MIPS_MACH_OCTEON, "MACH_OCTEON" }, - { MIPS_EFLAGS::EF_MIPS_MACH_XLR, "MACH_XLR" }, - { MIPS_EFLAGS::EF_MIPS_MACH_OCTEON2, "MACH_OCTEON2" }, - { MIPS_EFLAGS::EF_MIPS_MACH_OCTEON3, "MACH_OCTEON3" }, - { MIPS_EFLAGS::EF_MIPS_MACH_5400, "MACH_5400" }, - { MIPS_EFLAGS::EF_MIPS_MACH_5900, "MACH_5900" }, - { MIPS_EFLAGS::EF_MIPS_MACH_5500, "MACH_5500" }, - { MIPS_EFLAGS::EF_MIPS_MACH_9000, "MACH_9000" }, - { MIPS_EFLAGS::EF_MIPS_MACH_LS2E, "MACH_LS2E" }, - { MIPS_EFLAGS::EF_MIPS_MACH_LS2F, "MACH_LS2F" }, - { MIPS_EFLAGS::EF_MIPS_MACH_LS3A, "MACH_LS3A" }, - - { MIPS_EFLAGS::EF_MIPS_MICROMIPS, "MICROMIPS" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_ASE_M16, "ARCH_ASE_M16" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_ASE_MDMX, "ARCH_ASE_MDMX" }, - - { MIPS_EFLAGS::EF_MIPS_ARCH_1, "ARCH_1" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_2, "ARCH_2" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_3, "ARCH_3" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_4, "ARCH_4" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_5, "ARCH_5" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_32, "ARCH_32" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_64, "ARCH_64" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_32R2, "ARCH_32R2" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_64R2, "ARCH_64R2" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_32R6, "ARCH_32R6" }, - { MIPS_EFLAGS::EF_MIPS_ARCH_64R6, "ARCH_64R6" }, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(HEXAGON_EFLAGS e) { - CONST_MAP(HEXAGON_EFLAGS, const char*, 9) enumStrings { - { HEXAGON_EFLAGS::EF_HEXAGON_MACH_V2, "MACH_V2" }, - { HEXAGON_EFLAGS::EF_HEXAGON_MACH_V3, "MACH_V3" }, - { HEXAGON_EFLAGS::EF_HEXAGON_MACH_V4, "MACH_V4" }, - { HEXAGON_EFLAGS::EF_HEXAGON_MACH_V5, "MACH_V5" }, - - { HEXAGON_EFLAGS::EF_HEXAGON_ISA_MACH, "ISA_MACH" }, - - { HEXAGON_EFLAGS::EF_HEXAGON_ISA_V2, "ISA_V2" }, - { HEXAGON_EFLAGS::EF_HEXAGON_ISA_V3, "ISA_V3" }, - { HEXAGON_EFLAGS::EF_HEXAGON_ISA_V4, "ISA_V4" }, - { HEXAGON_EFLAGS::EF_HEXAGON_ISA_V5, "ISA_V5" }, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(LOONGARCH_EFLAGS e) { - CONST_MAP(LOONGARCH_EFLAGS, const char*, 3) enumStrings { - { LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SOFT_FLOAT, "ABI_SOFT_FLOAT" }, - { LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SINGLE_FLOAT, "ABI_SINGLE_FLOAT" }, - { LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_DOUBLE_FLOAT, "ABI_DOUBLE_FLOAT" }, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(IDENTITY e) { - CONST_MAP(IDENTITY, const char*, 11) enumStrings { - { IDENTITY::EI_MAG0, "MAG0" }, - { IDENTITY::EI_MAG1, "MAG1" }, - { IDENTITY::EI_MAG2, "MAG2" }, - { IDENTITY::EI_MAG3, "MAG3" }, - { IDENTITY::EI_CLASS, "CLASS" }, - { IDENTITY::EI_DATA, "DATA" }, - { IDENTITY::EI_VERSION, "VERSION" }, - { IDENTITY::EI_OSABI, "OSABI" }, - { IDENTITY::EI_ABIVERSION, "ABIVERSION" }, - { IDENTITY::EI_PAD, "PAD" }, - { IDENTITY::EI_NIDENT, "NIDENT" }, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(SYMBOL_SECTION_INDEX e) { - CONST_MAP(SYMBOL_SECTION_INDEX, const char*, 10) enumStrings { - { SYMBOL_SECTION_INDEX::SHN_UNDEF, "UNDEF" }, - { SYMBOL_SECTION_INDEX::SHN_LORESERVE, "LORESERVE" }, - { SYMBOL_SECTION_INDEX::SHN_LOPROC, "LOPROC" }, - { SYMBOL_SECTION_INDEX::SHN_HIPROC, "HIPROC" }, - { SYMBOL_SECTION_INDEX::SHN_LOOS, "LOOS" }, - { SYMBOL_SECTION_INDEX::SHN_HIOS, "HIOS" }, - { SYMBOL_SECTION_INDEX::SHN_ABS, "ABS" }, - { SYMBOL_SECTION_INDEX::SHN_COMMON, "COMMON" }, - { SYMBOL_SECTION_INDEX::SHN_XINDEX, "XINDEX" }, - { SYMBOL_SECTION_INDEX::SHN_HIRESERVE, "HIRESERVE" }, - }; - - const auto it = enumStrings.find(e); - return it == enumStrings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(DYNAMIC_FLAGS e) { - CONST_MAP(DYNAMIC_FLAGS, const char*, 5) enum_strings { - { DYNAMIC_FLAGS::DF_ORIGIN, "ORIGIN" }, - { DYNAMIC_FLAGS::DF_SYMBOLIC, "SYMBOLIC" }, - { DYNAMIC_FLAGS::DF_TEXTREL, "TEXTREL" }, - { DYNAMIC_FLAGS::DF_BIND_NOW, "BIND_NOW" }, - { DYNAMIC_FLAGS::DF_STATIC_TLS, "STATIC_TLS" }, - }; - - const auto it = enum_strings.find(e); - return it == enum_strings.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(DYNAMIC_FLAGS_1 e) { - CONST_MAP(DYNAMIC_FLAGS_1, const char*, 27) enum_strings_flags1 { - { DYNAMIC_FLAGS_1::DF_1_NOW, "NOW" }, - { DYNAMIC_FLAGS_1::DF_1_GLOBAL, "GLOBAL" }, - { DYNAMIC_FLAGS_1::DF_1_GROUP, "GROUP" }, - { DYNAMIC_FLAGS_1::DF_1_NODELETE, "NODELETE" }, - { DYNAMIC_FLAGS_1::DF_1_LOADFLTR, "LOADFLTR" }, - { DYNAMIC_FLAGS_1::DF_1_INITFIRST, "INITFIRST" }, - { DYNAMIC_FLAGS_1::DF_1_NOOPEN, "NOOPEN" }, - { DYNAMIC_FLAGS_1::DF_1_ORIGIN, "ORIGIN" }, - { DYNAMIC_FLAGS_1::DF_1_DIRECT, "DIRECT" }, - { DYNAMIC_FLAGS_1::DF_1_TRANS, "TRANS" }, - { DYNAMIC_FLAGS_1::DF_1_INTERPOSE, "INTERPOSE" }, - { DYNAMIC_FLAGS_1::DF_1_NODEFLIB, "NODEFLIB" }, - { DYNAMIC_FLAGS_1::DF_1_NODUMP, "NODUMP" }, - { DYNAMIC_FLAGS_1::DF_1_CONFALT, "CONFALT" }, - { DYNAMIC_FLAGS_1::DF_1_ENDFILTEE, "ENDFILTEE" }, - { DYNAMIC_FLAGS_1::DF_1_DISPRELDNE, "DISPRELDNE" }, - { DYNAMIC_FLAGS_1::DF_1_DISPRELPND, "DISPRELPND" }, - { DYNAMIC_FLAGS_1::DF_1_NODIRECT, "NODIRECT" }, - { DYNAMIC_FLAGS_1::DF_1_IGNMULDEF, "IGNMULDEF" }, - { DYNAMIC_FLAGS_1::DF_1_NOKSYMS, "NOKSYMS" }, - { DYNAMIC_FLAGS_1::DF_1_NOHDR, "NOHDR" }, - { DYNAMIC_FLAGS_1::DF_1_EDITED, "EDITED" }, - { DYNAMIC_FLAGS_1::DF_1_NORELOC, "NORELOC" }, - { DYNAMIC_FLAGS_1::DF_1_SYMINTPOSE, "SYMINTPOSE" }, - { DYNAMIC_FLAGS_1::DF_1_GLOBAUDIT, "GLOBAUDIT" }, - { DYNAMIC_FLAGS_1::DF_1_SINGLETON, "SINGLETON" }, - { DYNAMIC_FLAGS_1::DF_1_PIE, "PIE" }, - }; - - const auto it = enum_strings_flags1.find(e); - return it == enum_strings_flags1.end() ? "UNDEFINED" : it->second; -} - -const char* to_string(ELF_SEGMENT_FLAGS e) { - CONST_MAP(ELF_SEGMENT_FLAGS, const char*, 4) enum_strings { - { ELF_SEGMENT_FLAGS::PF_NONE, "NONE" }, - { ELF_SEGMENT_FLAGS::PF_X, "X" }, - { ELF_SEGMENT_FLAGS::PF_W, "W" }, - { ELF_SEGMENT_FLAGS::PF_R, "R" }, - }; - - const auto it = enum_strings.find(e); - return it == enum_strings.end() ? "UNDEFINED" : it->second; -} - - -const char* to_string(ELF_SYMBOL_VISIBILITY e) { - CONST_MAP(ELF_SYMBOL_VISIBILITY, const char*, 4) enum_strings { - { ELF_SYMBOL_VISIBILITY::STV_DEFAULT, "DEFAULT" }, - { ELF_SYMBOL_VISIBILITY::STV_HIDDEN, "HIDDEN" }, - { ELF_SYMBOL_VISIBILITY::STV_INTERNAL, "INTERNAL" }, - { ELF_SYMBOL_VISIBILITY::STV_PROTECTED, "PROTECTED" }, - }; - - const auto it = enum_strings.find(e); - return it == enum_strings.end() ? "UNDEFINED" : it->second; + #define ENTRY(X) std::pair(ARCH::X, #X) + STRING_MAP enums2str { + ENTRY(NONE), + ENTRY(M32), + ENTRY(SPARC), + ENTRY(I386), + ENTRY(M68K), + ENTRY(M88K), + ENTRY(IAMCU), + ENTRY(I860), + ENTRY(MIPS), + ENTRY(S370), + ENTRY(MIPS_RS3_LE), + ENTRY(PARISC), + ENTRY(VPP500), + ENTRY(SPARC32PLUS), + ENTRY(I60), + ENTRY(PPC), + ENTRY(PPC64), + ENTRY(S390), + ENTRY(SPU), + ENTRY(V800), + ENTRY(FR20), + ENTRY(RH32), + ENTRY(RCE), + ENTRY(ARM), + ENTRY(ALPHA), + ENTRY(SH), + ENTRY(SPARCV9), + ENTRY(TRICORE), + ENTRY(ARC), + ENTRY(H8_300), + ENTRY(H8_300H), + ENTRY(H8S), + ENTRY(H8_500), + ENTRY(IA_64), + ENTRY(MIPS_X), + ENTRY(COLDFIRE), + ENTRY(M68HC12), + ENTRY(MMA), + ENTRY(PCP), + ENTRY(NCPU), + ENTRY(NDR1), + ENTRY(STARCORE), + ENTRY(ME16), + ENTRY(ST100), + ENTRY(TINYJ), + ENTRY(X86_64), + ENTRY(PDSP), + ENTRY(PDP10), + ENTRY(PDP11), + ENTRY(FX66), + ENTRY(ST9PLUS), + ENTRY(ST7), + ENTRY(M68HC16), + ENTRY(M68HC11), + ENTRY(M68HC08), + ENTRY(M68HC05), + ENTRY(SVX), + ENTRY(ST19), + ENTRY(VAX), + ENTRY(CRIS), + ENTRY(JAVELIN), + ENTRY(FIREPATH), + ENTRY(ZSP), + ENTRY(MMIX), + ENTRY(HUANY), + ENTRY(PRISM), + ENTRY(AVR), + ENTRY(FR30), + ENTRY(D10V), + ENTRY(D30V), + ENTRY(V850), + ENTRY(M32R), + ENTRY(MN10300), + ENTRY(MN10200), + ENTRY(PJ), + ENTRY(OPENRISC), + ENTRY(ARC_COMPACT), + ENTRY(XTENSA), + ENTRY(VIDEOCORE), + ENTRY(TMM_GPP), + ENTRY(NS32K), + ENTRY(TPC), + ENTRY(SNP1K), + ENTRY(ST200), + ENTRY(IP2K), + ENTRY(MAX), + ENTRY(CR), + ENTRY(F2MC16), + ENTRY(MSP430), + ENTRY(BLACKFIN), + ENTRY(SE_C33), + ENTRY(SEP), + ENTRY(ARCA), + ENTRY(UNICORE), + ENTRY(EXCESS), + ENTRY(DXP), + ENTRY(ALTERA_NIOS2), + ENTRY(CRX), + ENTRY(XGATE), + ENTRY(C166), + ENTRY(M16C), + ENTRY(DSPIC30F), + ENTRY(CE), + ENTRY(M32C), + ENTRY(TSK3000), + ENTRY(RS08), + ENTRY(SHARC), + ENTRY(ECOG2), + ENTRY(SCORE7), + ENTRY(DSP24), + ENTRY(VIDEOCORE3), + ENTRY(LATTICEMICO32), + ENTRY(SE_C17), + ENTRY(TI_C6000), + ENTRY(TI_C2000), + ENTRY(TI_C5500), + ENTRY(MMDSP_PLUS), + ENTRY(CYPRESS_M8C), + ENTRY(R32C), + ENTRY(TRIMEDIA), + ENTRY(HEXAGON), + ENTRY(M8051), + ENTRY(STXP7X), + ENTRY(NDS32), + ENTRY(ECOG1), + ENTRY(ECOG1X), + ENTRY(MAXQ30), + ENTRY(XIMO16), + ENTRY(MANIK), + ENTRY(CRAYNV2), + ENTRY(RX), + ENTRY(METAG), + ENTRY(MCST_ELBRUS), + ENTRY(ECOG16), + ENTRY(CR16), + ENTRY(ETPU), + ENTRY(SLE9X), + ENTRY(L10M), + ENTRY(K10M), + ENTRY(AARCH64), + ENTRY(AVR32), + ENTRY(STM8), + ENTRY(TILE64), + ENTRY(TILEPRO), + ENTRY(CUDA), + ENTRY(TILEGX), + ENTRY(CLOUDSHIELD), + ENTRY(COREA_1ST), + ENTRY(COREA_2ND), + ENTRY(ARC_COMPACT2), + ENTRY(OPEN8), + ENTRY(RL78), + ENTRY(VIDEOCORE5), + ENTRY(M78KOR), + ENTRY(M56800EX), + ENTRY(BA1), + ENTRY(BA2), + ENTRY(XCORE), + ENTRY(MCHP_PIC), + ENTRY(INTEL205), + ENTRY(INTEL206), + ENTRY(INTEL207), + ENTRY(INTEL208), + ENTRY(INTEL209), + ENTRY(KM32), + ENTRY(KMX32), + ENTRY(KMX16), + ENTRY(KMX8), + ENTRY(KVARC), + ENTRY(CDP), + ENTRY(COGE), + ENTRY(COOL), + ENTRY(NORC), + ENTRY(CSR_KALIMBA), + ENTRY(AMDGPU), + ENTRY(RISCV), + ENTRY(BPF), + ENTRY(LOONGARCH), + }; + #undef ENTRY + + const auto it = enums2str.find(e); + return it == enums2str.end() ? "UNDEFINED" : it->second; } } // namespace ELF diff --git a/src/ELF/ExeLayout.hpp b/src/ELF/ExeLayout.hpp index ded16f2d09..b717a36701 100644 --- a/src/ELF/ExeLayout.hpp +++ b/src/ELF/ExeLayout.hpp @@ -103,30 +103,30 @@ class LIEF_LOCAL ExeLayout : public Layout { for (std::unique_ptr& entry : binary_->dynamic_entries_) { switch (entry->tag()) { - case DYNAMIC_TAGS::DT_NEEDED: + case DynamicEntry::TAG::NEEDED: { const std::string& name = entry->as()->name(); opt_list.push_back(name); break; } - case DYNAMIC_TAGS::DT_SONAME: + case DynamicEntry::TAG::SONAME: { const std::string& name = entry->as()->name(); opt_list.push_back(name); break; } - case DYNAMIC_TAGS::DT_RPATH: + case DynamicEntry::TAG::RPATH: { - const std::string& name = entry->as()->name(); + const std::string& name = entry->as()->rpath(); opt_list.push_back(name); break; } - case DYNAMIC_TAGS::DT_RUNPATH: + case DynamicEntry::TAG::RUNPATH: { - const std::string& name = entry->as()->name(); + const std::string& name = entry->as()->runpath(); opt_list.push_back(name); break; } @@ -185,7 +185,7 @@ class LIEF_LOCAL ExeLayout : public Layout { } template - size_t dynamic_arraysize(DYNAMIC_TAGS tag) { + size_t dynamic_arraysize(DynamicEntry::TAG tag) { using uint = typename ELF_T::uint; DynamicEntry* entry = binary_->get(tag); if (entry == nullptr || !DynamicEntryArray::classof(entry)) { @@ -396,7 +396,7 @@ class LIEF_LOCAL ExeLayout : public Layout { using Elf_Rel = typename ELF_T::Elf_Rel; const Binary::it_dynamic_relocations& dyn_relocs = binary_->dynamic_relocations(); - const size_t computed_size = binary_->has(DYNAMIC_TAGS::DT_RELA) ? + const size_t computed_size = binary_->has(DynamicEntry::TAG::RELA) ? dyn_relocs.size() * sizeof(Elf_Rela) : dyn_relocs.size() * sizeof(Elf_Rel); return computed_size; @@ -408,10 +408,12 @@ class LIEF_LOCAL ExeLayout : public Layout { using Elf_Rel = typename ELF_T::Elf_Rel; const Binary::it_pltgot_relocations& pltgot_relocs = binary_->pltgot_relocations(); - const DynamicEntry* dt_rela = binary_->get(DYNAMIC_TAGS::DT_PLTREL); + const DynamicEntry* dt_rela = binary_->get(DynamicEntry::TAG::PLTREL); + + const ARCH arch = binary_->header().machine_type(); const bool is_rela = dt_rela != nullptr && - dt_rela->value() == static_cast(DYNAMIC_TAGS::DT_RELA); + DynamicEntry::from_value(dt_rela->value(), arch) == DynamicEntry::TAG::RELA; if (is_rela) { return pltgot_relocs.size() * sizeof(Elf_Rela); @@ -556,11 +558,11 @@ class LIEF_LOCAL ExeLayout : public Layout { /* PT_INTERP segment (optional) * */ - if (interp_size_ > 0 && !binary_->has(SEGMENT_TYPES::PT_INTERP)) { + if (interp_size_ > 0 && !binary_->has(Segment::TYPE::INTERP)) { Segment interp_segment; interp_segment.alignment(0x8); - interp_segment.type(SEGMENT_TYPES::PT_INTERP); - interp_segment.add(ELF_SEGMENT_FLAGS::PF_R); + interp_segment.type(Segment::TYPE::INTERP); + interp_segment.add(Segment::FLAGS::R); interp_segment.content(std::vector(interp_size_)); if (Segment* interp = binary_->add(interp_segment)) { LIEF_DEBUG("Interp Segment: 0x{:x}:0x{:x}", interp->virtual_address(), interp->virtual_size()); @@ -607,8 +609,8 @@ class LIEF_LOCAL ExeLayout : public Layout { if (read_segment > 0) { Segment rsegment; rsegment.alignment(0x1000); - rsegment.type(SEGMENT_TYPES::PT_LOAD); - rsegment.add(ELF_SEGMENT_FLAGS::PF_R); + rsegment.type(Segment::TYPE::LOAD); + rsegment.add(Segment::FLAGS::R); rsegment.content(std::vector(read_segment)); new_rsegment = binary_->add(rsegment); if (new_rsegment != nullptr) { @@ -637,9 +639,8 @@ class LIEF_LOCAL ExeLayout : public Layout { Segment rwsegment; if (read_write_segment > 0) { rwsegment.alignment(0x1000); - rwsegment.type(SEGMENT_TYPES::PT_LOAD); - rwsegment.add(ELF_SEGMENT_FLAGS::PF_R); - rwsegment.add(ELF_SEGMENT_FLAGS::PF_W); + rwsegment.type(Segment::TYPE::LOAD); + rwsegment.add(Segment::FLAGS::R | Segment::FLAGS::W); rwsegment.content(std::vector(read_write_segment)); new_rwsegment = binary_->add(rwsegment); if (new_rwsegment != nullptr) { @@ -664,7 +665,7 @@ class LIEF_LOCAL ExeLayout : public Layout { std::unique_ptr
& string_names_section = binary_->sections_[hdr.section_name_table_idx()]; std::string sec_name = binary_->shstrtab_name(); binary_->remove(*string_names_section, /* clear */ true); - Section sec_str_section(sec_name, ELF_SECTION_TYPES::SHT_STRTAB); + Section sec_str_section(sec_name, Section::TYPE::STRTAB); sec_str_section.content(std::vector(raw_shstrtab_.size())); binary_->add(sec_str_section, /* loaded */ false); @@ -680,7 +681,7 @@ class LIEF_LOCAL ExeLayout : public Layout { uint64_t va_rw_base = new_rwsegment != nullptr ? new_rwsegment->virtual_address() : 0; if (interp_size_ > 0) { - Segment* pt_interp = binary_->get(SEGMENT_TYPES::PT_INTERP); + Segment* pt_interp = binary_->get(Segment::TYPE::INTERP); if (pt_interp == nullptr) { LIEF_ERR("Can't find the PT_INTERP segment."); return make_error_code(lief_errors::file_format_error); @@ -715,7 +716,7 @@ class LIEF_LOCAL ExeLayout : public Layout { } if (relocate_notes_) { - Segment* note_segment = binary_->get(SEGMENT_TYPES::PT_NOTE); + Segment* note_segment = binary_->get(Segment::TYPE::NOTE); if (note_segment == nullptr) { LIEF_ERR("Can't find the PT_NOTE segment"); return make_error_code(lief_errors::file_format_error); @@ -739,7 +740,7 @@ class LIEF_LOCAL ExeLayout : public Layout { if (dynamic_size_ > 0) { // Update .dynamic / PT_DYNAMIC // Update relocations associated with .init_array etc - Segment* dynamic_segment = binary_->get(SEGMENT_TYPES::PT_DYNAMIC); + Segment* dynamic_segment = binary_->get(Segment::TYPE::DYNAMIC); if (dynamic_segment == nullptr) { LIEF_ERR("Can't find the dynamic section/segment"); return make_error_code(lief_errors::file_format_error); @@ -770,7 +771,7 @@ class LIEF_LOCAL ExeLayout : public Layout { if (dynsym_size_ > 0) { // Update .dynsym / DT_SYMTAB - DynamicEntry* dt_symtab = binary_->get(DYNAMIC_TAGS::DT_SYMTAB); + DynamicEntry* dt_symtab = binary_->get(DynamicEntry::TAG::SYMTAB); if (dt_symtab == nullptr) { LIEF_ERR("Can't find DT_SYMTAB"); @@ -798,8 +799,8 @@ class LIEF_LOCAL ExeLayout : public Layout { if (relocate_dynstr_) { // Update .dynstr section, DT_SYMTAB, DT_STRSZ - DynamicEntry* dt_strtab = binary_->get(DYNAMIC_TAGS::DT_STRTAB); - DynamicEntry* dt_strsize = binary_->get(DYNAMIC_TAGS::DT_STRSZ); + DynamicEntry* dt_strtab = binary_->get(DynamicEntry::TAG::STRTAB); + DynamicEntry* dt_strsize = binary_->get(DynamicEntry::TAG::STRSZ); if (dt_strtab == nullptr || dt_strsize == nullptr) { LIEF_ERR("Can't find DT_STRTAB/DT_STRSZ"); @@ -828,7 +829,7 @@ class LIEF_LOCAL ExeLayout : public Layout { if (sver_size_ > 0) { - DynamicEntry* dt_versym = binary_->get(DYNAMIC_TAGS::DT_VERSYM); + DynamicEntry* dt_versym = binary_->get(DynamicEntry::TAG::VERSYM); if (dt_versym == nullptr) { LIEF_ERR("Can't find DT_VERSYM"); return make_error_code(lief_errors::file_format_error); @@ -854,7 +855,7 @@ class LIEF_LOCAL ExeLayout : public Layout { } if (sverd_size_ > 0) { - DynamicEntry* dt_verdef = binary_->get(DYNAMIC_TAGS::DT_VERDEF); + DynamicEntry* dt_verdef = binary_->get(DynamicEntry::TAG::VERDEF); if (dt_verdef == nullptr) { LIEF_ERR("Can't find DT_VERDEF"); @@ -881,7 +882,7 @@ class LIEF_LOCAL ExeLayout : public Layout { } if (sverr_size_ > 0) { - DynamicEntry* dt_verreq = binary_->get(DYNAMIC_TAGS::DT_VERNEED); + DynamicEntry* dt_verreq = binary_->get(DynamicEntry::TAG::VERNEED); if (dt_verreq == nullptr) { LIEF_ERR("Can't find DT_VERNEED"); @@ -913,12 +914,12 @@ class LIEF_LOCAL ExeLayout : public Layout { // - DT_RELSZ / DT_RELASZ // - .dyn.rel - DynamicEntry* dt_rela = binary_->get(DYNAMIC_TAGS::DT_RELA); + DynamicEntry* dt_rela = binary_->get(DynamicEntry::TAG::RELA); const bool is_rela = dt_rela != nullptr; - DynamicEntry* dt_reloc = is_rela ? dt_rela : binary_->get(DYNAMIC_TAGS::DT_REL); - DynamicEntry* dt_relocsz = is_rela ? binary_->get(DYNAMIC_TAGS::DT_RELASZ) : - binary_->get(DYNAMIC_TAGS::DT_RELSZ); + DynamicEntry* dt_reloc = is_rela ? dt_rela : binary_->get(DynamicEntry::TAG::REL); + DynamicEntry* dt_relocsz = is_rela ? binary_->get(DynamicEntry::TAG::RELASZ) : + binary_->get(DynamicEntry::TAG::RELSZ); if (dt_reloc == nullptr || dt_relocsz == nullptr) { LIEF_ERR("Can't find DT_REL(A) / DT_REL(A)SZ"); @@ -950,8 +951,8 @@ class LIEF_LOCAL ExeLayout : public Layout { // Update: // - DT_JMPREL / DT_PLTRELSZ // - .plt.rel - DynamicEntry* dt_reloc = binary_->get(DYNAMIC_TAGS::DT_JMPREL); - DynamicEntry* dt_relocsz = binary_->get(DYNAMIC_TAGS::DT_PLTRELSZ); + DynamicEntry* dt_reloc = binary_->get(DynamicEntry::TAG::JMPREL); + DynamicEntry* dt_relocsz = binary_->get(DynamicEntry::TAG::PLTRELSZ); if (dt_reloc == nullptr || dt_relocsz == nullptr) { LIEF_ERR("Can't find DT_JMPREL, DT_PLTRELSZ"); @@ -982,7 +983,7 @@ class LIEF_LOCAL ExeLayout : public Layout { if (relocate_gnu_hash_) { // Update .gnu.hash section / DT_GNU_HASH - DynamicEntry* dt_gnu_hash = binary_->get(DYNAMIC_TAGS::DT_GNU_HASH); + DynamicEntry* dt_gnu_hash = binary_->get(DynamicEntry::TAG::GNU_HASH); if (dt_gnu_hash == nullptr) { LIEF_ERR("Can't find DT_GNU_HASH"); @@ -1010,7 +1011,7 @@ class LIEF_LOCAL ExeLayout : public Layout { if (sysv_size_ > 0) { // Update .hash section / DT_HASH - DynamicEntry* dt_hash = binary_->get(DYNAMIC_TAGS::DT_HASH); + DynamicEntry* dt_hash = binary_->get(DynamicEntry::TAG::HASH); if (dt_hash == nullptr) { LIEF_ERR("Can't find DT_HASH"); @@ -1040,13 +1041,13 @@ class LIEF_LOCAL ExeLayout : public Layout { // RW-Segment // ==================================== if (init_size_ > 0) { // .init_array - DynamicEntry* raw_dt_init = binary_->get(DYNAMIC_TAGS::DT_INIT_ARRAY); + DynamicEntry* raw_dt_init = binary_->get(DynamicEntry::TAG::INIT_ARRAY); if (raw_dt_init == nullptr || !DynamicEntryArray::classof(raw_dt_init)) { LIEF_ERR("DT_INIT_ARRAY not found"); return make_error_code(lief_errors::file_format_error); } auto* dt_init_array = raw_dt_init->as(); - DynamicEntry* dt_init_arraysz = binary_->get(DYNAMIC_TAGS::DT_INIT_ARRAYSZ); + DynamicEntry* dt_init_arraysz = binary_->get(DynamicEntry::TAG::INIT_ARRAYSZ); if (dt_init_arraysz == nullptr) { LIEF_ERR("Can't find DT_INIT_ARRAYSZ"); @@ -1055,10 +1056,10 @@ class LIEF_LOCAL ExeLayout : public Layout { // Update relocation range - if (binary_->header().file_type() == E_TYPE::ET_DYN) { + if (binary_->header().file_type() == Header::FILE_TYPE::DYN) { LIEF_WARN("Relocating .init_array might not work on Linux."); const std::vector& array = dt_init_array->array(); - const size_t sizeof_p = binary_->type() == ELF_CLASS::ELFCLASS32 ? + const size_t sizeof_p = binary_->type() == Header::CLASS::ELF32 ? sizeof(uint32_t) : sizeof(uint64_t); // Since the values of the .init_array have moved elsewhere, @@ -1082,7 +1083,7 @@ class LIEF_LOCAL ExeLayout : public Layout { return make_error_code(lief_errors::build_error); } - if (Section* section = binary_->get(ELF_SECTION_TYPES::SHT_INIT_ARRAY)) { + if (Section* section = binary_->get(Section::TYPE::INIT_ARRAY)) { section->virtual_address(va_rw_base); section->size(init_size_); section->offset(offset_rw_base); @@ -1096,22 +1097,22 @@ class LIEF_LOCAL ExeLayout : public Layout { } if (preinit_size_ > 0) { // .preinit_array - DynamicEntry* raw_dt_preinit = binary_->get(DYNAMIC_TAGS::DT_PREINIT_ARRAY); + DynamicEntry* raw_dt_preinit = binary_->get(DynamicEntry::TAG::PREINIT_ARRAY); if (raw_dt_preinit == nullptr || !DynamicEntryArray::classof(raw_dt_preinit)) { LIEF_ERR("DT_PREINIT_ARRAY not found"); return make_error_code(lief_errors::file_format_error); } auto* dt_preinit_array = raw_dt_preinit->as(); - DynamicEntry* dt_preinit_arraysz = binary_->get(DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ); + DynamicEntry* dt_preinit_arraysz = binary_->get(DynamicEntry::TAG::PREINIT_ARRAYSZ); if (dt_preinit_array == nullptr) { LIEF_ERR("Can't find DT_PREINIT_ARRAYSZ"); return make_error_code(lief_errors::file_format_error); } - if (binary_->header().file_type() == E_TYPE::ET_DYN) { + if (binary_->header().file_type() == Header::FILE_TYPE::DYN) { const std::vector& array = dt_preinit_array->array(); - const size_t sizeof_p = binary_->type() == ELF_CLASS::ELFCLASS32 ? + const size_t sizeof_p = binary_->type() == Header::CLASS::ELF32 ? sizeof(uint32_t) : sizeof(uint64_t); LIEF_WARN("Relocating .preinit_array might not work on Linux."); @@ -1134,7 +1135,7 @@ class LIEF_LOCAL ExeLayout : public Layout { return make_error_code(lief_errors::build_error); } - if (Section* section = binary_->get(ELF_SECTION_TYPES::SHT_PREINIT_ARRAY)) { + if (Section* section = binary_->get(Section::TYPE::PREINIT_ARRAY)) { section->virtual_address(va_rw_base); section->size(preinit_size_); section->offset(offset_rw_base); @@ -1149,22 +1150,22 @@ class LIEF_LOCAL ExeLayout : public Layout { if (fini_size_ > 0) { // .fini_array - DynamicEntry* raw_dt_fini = binary_->get(DYNAMIC_TAGS::DT_FINI_ARRAY); + DynamicEntry* raw_dt_fini = binary_->get(DynamicEntry::TAG::FINI_ARRAY); if (raw_dt_fini == nullptr || !DynamicEntryArray::classof(raw_dt_fini)) { LIEF_ERR("DT_FINI_ARRAY not found"); return make_error_code(lief_errors::file_format_error); } auto* dt_fini_array = raw_dt_fini->as(); - DynamicEntry* dt_fini_arraysz = binary_->get(DYNAMIC_TAGS::DT_FINI_ARRAYSZ); + DynamicEntry* dt_fini_arraysz = binary_->get(DynamicEntry::TAG::FINI_ARRAYSZ); if (dt_fini_arraysz == nullptr) { LIEF_ERR("Can't find DT_FINI_ARRAYSZ"); return make_error_code(lief_errors::file_format_error); } - if (binary_->header().file_type() == E_TYPE::ET_DYN) { + if (binary_->header().file_type() == Header::FILE_TYPE::DYN) { const std::vector& array = dt_fini_array->array(); - const size_t sizeof_p = binary_->type() == ELF_CLASS::ELFCLASS32 ? + const size_t sizeof_p = binary_->type() == Header::CLASS::ELF32 ? sizeof(uint32_t) : sizeof(uint64_t); LIEF_WARN("Relocating .fini_array might not work on Linux."); @@ -1188,7 +1189,7 @@ class LIEF_LOCAL ExeLayout : public Layout { return make_error_code(lief_errors::build_error); } - if (Section* section = binary_->get(ELF_SECTION_TYPES::SHT_FINI_ARRAY)) { + if (Section* section = binary_->get(Section::TYPE::FINI_ARRAY)) { section->virtual_address(va_rw_base); section->size(fini_size_); section->offset(offset_rw_base); @@ -1217,7 +1218,7 @@ class LIEF_LOCAL ExeLayout : public Layout { } else { strtab_idx = binary_->sections().size(); } - Section strtab{".strtab", ELF_SECTION_TYPES::SHT_STRTAB}; + Section strtab{".strtab", Section::TYPE::STRTAB}; strtab.content(raw_strtab_); strtab.alignment(1); Section* new_strtab = binary_->add(strtab, /* loaded */ false); @@ -1230,7 +1231,7 @@ class LIEF_LOCAL ExeLayout : public Layout { LIEF_DEBUG("New .strtab section: #{:d} {} 0x{:x} (size: {:x})", strtab_idx, new_strtab->name(), new_strtab->file_offset(), new_strtab->size()); - Section* sec_symtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* sec_symtab = binary_->get(Section::TYPE::SYMTAB); if (sec_symtab != nullptr) { LIEF_DEBUG("Link section {} with the new .strtab (idx: #{:d})", sec_symtab->name(), strtab_idx); sec_symtab->link(strtab_idx); @@ -1247,7 +1248,7 @@ class LIEF_LOCAL ExeLayout : public Layout { if (symtab_size_ > 0) { LIEF_DEBUG("Relocate .symtab"); - Section* sec_symtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + Section* sec_symtab = binary_->get(Section::TYPE::SYMTAB); if (sec_symtab != nullptr) { if (strtab_idx == 0) { strtab_idx = sec_symtab->link(); @@ -1257,10 +1258,10 @@ class LIEF_LOCAL ExeLayout : public Layout { binary_->remove(*sec_symtab, /* clear */ true); } - Section symtab{".symtab", ELF_SECTION_TYPES::SHT_SYMTAB}; + Section symtab{".symtab", Section::TYPE::SYMTAB}; symtab.content(std::vector(symtab_size_)); - const size_t sizeof_sym = binary_->type() == ELF_CLASS::ELFCLASS32 ? + const size_t sizeof_sym = binary_->type() == Header::CLASS::ELF32 ? sizeof(details::Elf32_Sym) : sizeof(details::Elf64_Sym); symtab.entry_size(sizeof_sym); symtab.alignment(8); @@ -1275,7 +1276,7 @@ class LIEF_LOCAL ExeLayout : public Layout { } // Process note sections - if (const Segment* segment_note = binary_->get(SEGMENT_TYPES::PT_NOTE)) { + if (const Segment* segment_note = binary_->get(Segment::TYPE::NOTE)) { //using value_t = typename note_to_section_map_t::value_type; //const note_to_section_map_t& note_to_section_map = get_note_to_section(); for (const Note& note : binary_->notes()) { @@ -1302,8 +1303,8 @@ class LIEF_LOCAL ExeLayout : public Layout { } const size_t note_offset = it_offset->second; - Section section{sec_name, ELF_SECTION_TYPES::SHT_NOTE}; - section += ELF_SECTION_FLAGS::SHF_ALLOC; + Section section{sec_name, Section::TYPE::NOTE}; + section += Section::FLAGS::ALLOC; Section* section_added = binary_->add(section, /*loaded */ false); if (section_added == nullptr) { diff --git a/src/ELF/GnuHash.cpp b/src/ELF/GnuHash.cpp index 5ce2dfc9ab..61b570bcb9 100644 --- a/src/ELF/GnuHash.cpp +++ b/src/ELF/GnuHash.cpp @@ -26,15 +26,6 @@ namespace LIEF { namespace ELF { -GnuHash::GnuHash(GnuHash&&) = default; -GnuHash& GnuHash::operator=(GnuHash&&) = default; - -GnuHash& GnuHash::operator=(const GnuHash&) = default; -GnuHash::GnuHash(const GnuHash&) = default; -GnuHash::~GnuHash() = default; -GnuHash::GnuHash() = default; - - GnuHash::GnuHash(uint32_t symbol_idx, uint32_t shift2, std::vector bloom_filters, std::vector buckets, @@ -47,34 +38,6 @@ GnuHash::GnuHash(uint32_t symbol_idx, uint32_t shift2, {} -uint32_t GnuHash::nb_buckets() const { - return static_cast(buckets_.size()); -} - -uint32_t GnuHash::symbol_index() const { - return symbol_index_; -} - -uint32_t GnuHash::maskwords() const { - return bloom_filters_.size(); -} - -uint32_t GnuHash::shift2() const { - return shift2_; -} - -const std::vector& GnuHash::bloom_filters() const { - return bloom_filters_; -} - -const std::vector& GnuHash::buckets() const { - return buckets_; -} - -const std::vector& GnuHash::hash_values() const { - return hash_values_; -} - bool GnuHash::check_bloom_filter(uint32_t hash) const { const size_t C = c_; const uint32_t h1 = hash; @@ -88,11 +51,6 @@ bool GnuHash::check_bloom_filter(uint32_t hash) const { return ((filter >> b1) & (filter >> b2) & 1) != 0u; } - -bool GnuHash::check_bucket(uint32_t hash) const { - return buckets()[hash % nb_buckets()] > 0; -} - bool GnuHash::check(const std::string& symbol_name) const { uint32_t hash = dl_new_hash(symbol_name.c_str()); return check(hash); @@ -111,12 +69,10 @@ bool GnuHash::check(uint32_t hash) const { } - void GnuHash::accept(Visitor& visitor) const { visitor.visit(*this); } - std::ostream& operator<<(std::ostream& os, const GnuHash& gnuhash) { os << std::hex << std::left; diff --git a/src/ELF/Header.cpp b/src/ELF/Header.cpp index 6c05d8aa38..894d29c514 100644 --- a/src/ELF/Header.cpp +++ b/src/ELF/Header.cpp @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include #include #include #include #include "frozen.hpp" - #include "LIEF/ELF/hash.hpp" #include "LIEF/ELF/Header.hpp" @@ -33,52 +30,52 @@ namespace LIEF { namespace ELF { -Header& Header::operator=(const Header&) = default; -Header::Header(const Header&) = default; -Header::~Header() = default; - -Header::Header() : - file_type_{E_TYPE::ET_NONE}, - machine_type_{ARCH::EM_NONE}, - object_file_version_{VERSION::EV_NONE}, - entrypoint_(0), - program_headers_offset_(0), - section_headers_offset_(0), - processor_flags_(0), - header_size_(0), - program_header_size_(0), - numberof_segments_(0), - section_header_size_(0), - numberof_sections_(0), - section_string_table_idx_(0) -{} - - -Header::Header(const details::Elf32_Ehdr& header): - file_type_(static_cast(header.e_type)), - machine_type_(static_cast(header.e_machine)), - object_file_version_(static_cast(header.e_version)), - entrypoint_(header.e_entry), - program_headers_offset_(header.e_phoff), - section_headers_offset_(header.e_shoff), - processor_flags_(header.e_flags), - header_size_(header.e_ehsize), - program_header_size_(header.e_phentsize), - numberof_segments_(header.e_phnum), - section_header_size_(header.e_shentsize), - numberof_sections_(header.e_shnum), - section_string_table_idx_(header.e_shstrndx) -{ - std::copy( - reinterpret_cast(header.e_ident), - reinterpret_cast(header.e_ident) + static_cast(IDENTITY::EI_NIDENT), - std::begin(identity_)); -} - -Header::Header(const details::Elf64_Ehdr& header): - file_type_(static_cast(header.e_type)), - machine_type_(static_cast(header.e_machine)), - object_file_version_(static_cast(header.e_version)), +static constexpr uint64_t ARM_EABIMASK = 0xFF000000U; +static constexpr uint64_t MIPS_ABI_MASK = 0x0000f000U; +static constexpr uint64_t MIPS_MACH_MASK = 0x00ff0000U; +static constexpr uint64_t MIPS_ARCH_ASE_MASK = 0x0f000000U; +static constexpr uint64_t MIPS_ARCH_MASK = 0xf0000000U; + +static constexpr auto PFLAGS_LIST = { + PROCESSOR_FLAGS::ARM_EABI_UNKNOWN, PROCESSOR_FLAGS::ARM_SOFT_FLOAT, + PROCESSOR_FLAGS::ARM_VFP_FLOAT, PROCESSOR_FLAGS::ARM_EABI_VER1, + PROCESSOR_FLAGS::ARM_EABI_VER2, PROCESSOR_FLAGS::ARM_EABI_VER3, + PROCESSOR_FLAGS::ARM_EABI_VER4, PROCESSOR_FLAGS::ARM_EABI_VER5, + PROCESSOR_FLAGS::HEXAGON_MACH_V2, PROCESSOR_FLAGS::HEXAGON_MACH_V3, + PROCESSOR_FLAGS::HEXAGON_MACH_V4, PROCESSOR_FLAGS::HEXAGON_MACH_V5, + PROCESSOR_FLAGS::HEXAGON_ISA_V2, PROCESSOR_FLAGS::HEXAGON_ISA_V3, + PROCESSOR_FLAGS::HEXAGON_ISA_V4, PROCESSOR_FLAGS::HEXAGON_ISA_V5, + PROCESSOR_FLAGS::LOONGARCH_ABI_SOFT_FLOAT, PROCESSOR_FLAGS::LOONGARCH_ABI_SINGLE_FLOAT, + PROCESSOR_FLAGS::LOONGARCH_ABI_DOUBLE_FLOAT, PROCESSOR_FLAGS::MIPS_NOREORDER, + PROCESSOR_FLAGS::MIPS_PIC, PROCESSOR_FLAGS::MIPS_CPIC, + PROCESSOR_FLAGS::MIPS_ABI2, PROCESSOR_FLAGS::MIPS_32BITMODE, + PROCESSOR_FLAGS::MIPS_FP64, PROCESSOR_FLAGS::MIPS_NAN2008, + PROCESSOR_FLAGS::MIPS_ABI_O32, PROCESSOR_FLAGS::MIPS_ABI_O64, + PROCESSOR_FLAGS::MIPS_ABI_EABI32, PROCESSOR_FLAGS::MIPS_ABI_EABI64, + PROCESSOR_FLAGS::MIPS_MACH_3900, + PROCESSOR_FLAGS::MIPS_MACH_4010, PROCESSOR_FLAGS::MIPS_MACH_4100, + PROCESSOR_FLAGS::MIPS_MACH_4650, PROCESSOR_FLAGS::MIPS_MACH_4120, + PROCESSOR_FLAGS::MIPS_MACH_4111, PROCESSOR_FLAGS::MIPS_MACH_SB1, + PROCESSOR_FLAGS::MIPS_MACH_OCTEON, PROCESSOR_FLAGS::MIPS_MACH_XLR, + PROCESSOR_FLAGS::MIPS_MACH_OCTEON2, PROCESSOR_FLAGS::MIPS_MACH_OCTEON3, + PROCESSOR_FLAGS::MIPS_MACH_5400, PROCESSOR_FLAGS::MIPS_MACH_5900, + PROCESSOR_FLAGS::MIPS_MACH_5500, PROCESSOR_FLAGS::MIPS_MACH_9000, + PROCESSOR_FLAGS::MIPS_MACH_LS2E, PROCESSOR_FLAGS::MIPS_MACH_LS2F, + PROCESSOR_FLAGS::MIPS_MACH_LS3A, PROCESSOR_FLAGS::MIPS_MICROMIPS, + PROCESSOR_FLAGS::MIPS_ARCH_ASE_M16, PROCESSOR_FLAGS::MIPS_ARCH_ASE_MDMX, + PROCESSOR_FLAGS::MIPS_ARCH_1, PROCESSOR_FLAGS::MIPS_ARCH_2, + PROCESSOR_FLAGS::MIPS_ARCH_3, PROCESSOR_FLAGS::MIPS_ARCH_4, + PROCESSOR_FLAGS::MIPS_ARCH_5, PROCESSOR_FLAGS::MIPS_ARCH_32, + PROCESSOR_FLAGS::MIPS_ARCH_64, PROCESSOR_FLAGS::MIPS_ARCH_32R2, + PROCESSOR_FLAGS::MIPS_ARCH_64R2, PROCESSOR_FLAGS::MIPS_ARCH_32R6, + PROCESSOR_FLAGS::MIPS_ARCH_64R6, +}; + +template +Header::Header(const T& header): + file_type_(FILE_TYPE(header.e_type)), + machine_type_(ARCH(header.e_machine)), + object_file_version_(VERSION(header.e_version)), entrypoint_(header.e_entry), program_headers_offset_(header.e_phoff), section_headers_offset_(header.e_shoff), @@ -90,555 +87,312 @@ Header::Header(const details::Elf64_Ehdr& header): numberof_sections_(header.e_shnum), section_string_table_idx_(header.e_shstrndx) { - std::copy( - reinterpret_cast(header.e_ident), - reinterpret_cast(header.e_ident) + static_cast(IDENTITY::EI_NIDENT), - std::begin(identity_)); -} - - -E_TYPE Header::file_type() const { - return file_type_; + std::copy(std::begin(header.e_ident), std::end(header.e_ident), + std::begin(identity_)); } - -ARCH Header::machine_type() const { - return machine_type_; -} +template Header::Header(const details::Elf32_Ehdr& header); +template Header::Header(const details::Elf64_Ehdr& header); OBJECT_TYPES Header::abstract_object_type() const { - CONST_MAP(E_TYPE, OBJECT_TYPES, 3) obj_elf_to_lief { - {E_TYPE::ET_EXEC, OBJECT_TYPES::TYPE_EXECUTABLE}, - {E_TYPE::ET_DYN, OBJECT_TYPES::TYPE_LIBRARY}, - {E_TYPE::ET_REL, OBJECT_TYPES::TYPE_OBJECT}, - }; - const auto it = obj_elf_to_lief.find(file_type()); - if (it == std::end(obj_elf_to_lief)) { - LIEF_ERR("File type {} is not abstracted by LIEF", to_string(file_type())); - return OBJECT_TYPES::TYPE_NONE; + switch (file_type()) { + case FILE_TYPE::EXEC: + return OBJECT_TYPES::TYPE_EXECUTABLE; + case FILE_TYPE::DYN: + return OBJECT_TYPES::TYPE_LIBRARY; + case FILE_TYPE::REL: + return OBJECT_TYPES::TYPE_OBJECT; + case FILE_TYPE::CORE: + case FILE_TYPE::NONE: + return OBJECT_TYPES::TYPE_NONE; } - return it->second;; + return OBJECT_TYPES::TYPE_NONE; } - Header::abstract_architecture_t Header::abstract_architecture() const { - static std::unordered_map arch_elf_to_lief { - {ARCH::EM_NONE, {ARCH_NONE, {}}}, - {ARCH::EM_X86_64, {ARCH_X86, {MODE_64}}}, - {ARCH::EM_ARM, {ARCH_ARM, {MODE_32}}}, - {ARCH::EM_AARCH64, {ARCH_ARM64, {MODE_64}}}, - {ARCH::EM_386, {ARCH_X86, {MODE_32}}}, - {ARCH::EM_IA_64, {ARCH_INTEL, {MODE_64}}}, - {ARCH::EM_MIPS, {ARCH_MIPS, {MODE_32}}}, - {ARCH::EM_PPC, {ARCH_PPC, {MODE_32}}}, - {ARCH::EM_PPC64, {ARCH_PPC, {MODE_64}}}, - {ARCH::EM_RISCV, {ARCH_RISCV, {MODE_64}}}, - {ARCH::EM_LOONGARCH, {ARCH_LOONGARCH, {MODE_64}}}, - }; - - const auto it = arch_elf_to_lief.find(machine_type()); - if (it == std::end(arch_elf_to_lief)) { - LIEF_ERR("{} is not supported!", to_string(machine_type())); - return {}; + switch (machine_type()) { + case ARCH::X86_64: + return {ARCH_X86, {MODE_64}}; + case ARCH::ARM: + return {ARCH_ARM, {MODE_32}}; + case ARCH::AARCH64: + return {ARCH_ARM64, {MODE_64}}; + case ARCH::I386: + return {ARCH_X86, {MODE_32}}; + case ARCH::IA_64: + return {ARCH_INTEL, {MODE_64}}; + case ARCH::MIPS: + return {ARCH_MIPS, {MODE_32}}; + case ARCH::PPC: + return {ARCH_PPC, {MODE_32}}; + case ARCH::PPC64: + return {ARCH_PPC, {MODE_64}}; + case ARCH::RISCV: + return {ARCH_RISCV, {MODE_64}}; + case ARCH::LOONGARCH: + return {ARCH_LOONGARCH, {MODE_64}}; + case ARCH::NONE: + default: + return {ARCH_NONE, {}}; } - return it->second; + return {ARCH_NONE, {}}; } ENDIANNESS Header::abstract_endianness() const { - CONST_MAP(ELF_DATA, ENDIANNESS, 3) endi_elf_to_lief { - {ELF_DATA::ELFDATANONE, ENDIANNESS::ENDIAN_NONE}, - {ELF_DATA::ELFDATA2LSB, ENDIANNESS::ENDIAN_LITTLE}, - {ELF_DATA::ELFDATA2MSB, ENDIANNESS::ENDIAN_BIG}, - }; - const auto it = endi_elf_to_lief.find(identity_data()); - if (it == std::end(endi_elf_to_lief)) { - LIEF_ERR("This endianness can't be abstracted"); - return ENDIANNESS::ENDIAN_NONE; + switch (identity_data()) { + case ELF_DATA::LSB: return ENDIAN_LITTLE; + case ELF_DATA::MSB: return ENDIAN_BIG; + case ELF_DATA::NONE: return ENDIAN_NONE; } - return it->second; -} - - -VERSION Header::object_file_version() const { - return object_file_version_; + return ENDIAN_NONE; } - -uint64_t Header::entrypoint() const { - return entrypoint_; +void Header::identity(const std::string& identity) { + std::copy(std::begin(identity), std::end(identity), + std::begin(identity_)); } - -uint64_t Header::program_headers_offset() const { - return program_headers_offset_; +void Header::identity(const Header::identity_t& identity) { + std::copy(std::begin(identity), std::end(identity), + std::begin(identity_)); } - -uint64_t Header::section_headers_offset() const { - return section_headers_offset_; +void Header::accept(LIEF::Visitor& visitor) const { + visitor.visit(*this); } +bool Header::has(PROCESSOR_FLAGS flag) const { + const auto ID = uint64_t(flag) >> PFLAGS_BIT; + const ARCH arch = machine_type(); + uint32_t raw_flag = uint64_t(flag) & PFLAGS_MASK; -uint32_t Header::processor_flag() const { - return processor_flags_; -} + if (ID == PF_ARM_ID) { + if (arch != ARCH::ARM) { + return false; + } + switch (flag) { + case PROCESSOR_FLAGS::ARM_EABI_VER1: + case PROCESSOR_FLAGS::ARM_EABI_VER2: + case PROCESSOR_FLAGS::ARM_EABI_VER3: + case PROCESSOR_FLAGS::ARM_EABI_VER4: + case PROCESSOR_FLAGS::ARM_EABI_VER5: + return (processor_flag() & ARM_EABIMASK) == raw_flag; + default: + return (processor_flag() & raw_flag) != 0; + } -bool Header::has(ARM_EFLAGS f) const { - if (machine_type() != ARCH::EM_ARM) { return false; } - switch (f) { - case ARM_EFLAGS::EF_ARM_EABI_VER1: - case ARM_EFLAGS::EF_ARM_EABI_VER2: - case ARM_EFLAGS::EF_ARM_EABI_VER3: - case ARM_EFLAGS::EF_ARM_EABI_VER4: - case ARM_EFLAGS::EF_ARM_EABI_VER5: - { - return (processor_flag() & static_cast(ARM_EFLAGS::EF_ARM_EABIMASK)) == static_cast(f); - } - default: - { - return (processor_flag() & static_cast(f)) > 0; - } + if (ID == PF_HEX_ID) { + if (arch != ARCH::HEXAGON) { + return false; + } + return (processor_flag() & raw_flag) != 0; } -} - -Header::arm_flags_list_t Header::arm_flags_list() const { - arm_flags_list_t flags; - - std::copy_if(std::begin(details::arm_eflags_array), std::end(details::arm_eflags_array), - std::inserter(flags, std::begin(flags)), - [this] (ARM_EFLAGS f) { return has(f); }); - - return flags; -} - -bool Header::has(MIPS_EFLAGS f) const { - - auto fn = static_cast(f); - if (machine_type() != ARCH::EM_MIPS) { - return false; + if (ID == PF_LOONGARCH_ID) { + if (arch != ARCH::LOONGARCH) { + return false; + } + return (processor_flag() & raw_flag) != 0; } - if (machine_type() != ARCH::EM_MIPS_RS3_LE) { - return false; + if (ID == PF_MIPS_ID) { + if (arch != ARCH::MIPS && arch != ARCH::MIPS_RS3_LE && arch != ARCH::MIPS_X) { + return false; + } + + switch(flag) { + case PROCESSOR_FLAGS::MIPS_NOREORDER: + case PROCESSOR_FLAGS::MIPS_PIC: + case PROCESSOR_FLAGS::MIPS_CPIC: + case PROCESSOR_FLAGS::MIPS_ABI2: + case PROCESSOR_FLAGS::MIPS_32BITMODE: + case PROCESSOR_FLAGS::MIPS_FP64: + case PROCESSOR_FLAGS::MIPS_NAN2008: + return (processor_flag() & raw_flag) != 0; + + case PROCESSOR_FLAGS::MIPS_ABI_O32: + case PROCESSOR_FLAGS::MIPS_ABI_O64: + case PROCESSOR_FLAGS::MIPS_ABI_EABI32: + case PROCESSOR_FLAGS::MIPS_ABI_EABI64: + return (processor_flag() & MIPS_ABI_MASK) == (raw_flag & MIPS_ABI_MASK); + + case PROCESSOR_FLAGS::MIPS_MACH_3900: + case PROCESSOR_FLAGS::MIPS_MACH_4010: + case PROCESSOR_FLAGS::MIPS_MACH_4100: + case PROCESSOR_FLAGS::MIPS_MACH_4650: + case PROCESSOR_FLAGS::MIPS_MACH_4120: + case PROCESSOR_FLAGS::MIPS_MACH_4111: + case PROCESSOR_FLAGS::MIPS_MACH_SB1: + case PROCESSOR_FLAGS::MIPS_MACH_OCTEON: + case PROCESSOR_FLAGS::MIPS_MACH_XLR: + case PROCESSOR_FLAGS::MIPS_MACH_OCTEON2: + case PROCESSOR_FLAGS::MIPS_MACH_OCTEON3: + case PROCESSOR_FLAGS::MIPS_MACH_5400: + case PROCESSOR_FLAGS::MIPS_MACH_5900: + case PROCESSOR_FLAGS::MIPS_MACH_5500: + case PROCESSOR_FLAGS::MIPS_MACH_9000: + case PROCESSOR_FLAGS::MIPS_MACH_LS2E: + case PROCESSOR_FLAGS::MIPS_MACH_LS2F: + case PROCESSOR_FLAGS::MIPS_MACH_LS3A: + return (processor_flag() & MIPS_MACH_MASK) == (raw_flag & MIPS_MACH_MASK); + + case PROCESSOR_FLAGS::MIPS_MICROMIPS: + case PROCESSOR_FLAGS::MIPS_ARCH_ASE_M16: + case PROCESSOR_FLAGS::MIPS_ARCH_ASE_MDMX: + return (processor_flag() & MIPS_ARCH_ASE_MASK) == (raw_flag & MIPS_ARCH_ASE_MASK); + + case PROCESSOR_FLAGS::MIPS_ARCH_1: + case PROCESSOR_FLAGS::MIPS_ARCH_2: + case PROCESSOR_FLAGS::MIPS_ARCH_3: + case PROCESSOR_FLAGS::MIPS_ARCH_4: + case PROCESSOR_FLAGS::MIPS_ARCH_5: + case PROCESSOR_FLAGS::MIPS_ARCH_32: + case PROCESSOR_FLAGS::MIPS_ARCH_64: + case PROCESSOR_FLAGS::MIPS_ARCH_32R2: + case PROCESSOR_FLAGS::MIPS_ARCH_64R2: + case PROCESSOR_FLAGS::MIPS_ARCH_32R6: + case PROCESSOR_FLAGS::MIPS_ARCH_64R6: + return (processor_flag() & MIPS_ARCH_MASK) == raw_flag; + + default: + return (processor_flag() & raw_flag) != 0; + } } - if (machine_type() != ARCH::EM_MIPS_X) { + if (ID != 0) { + LIEF_WARN("Architecture {} is not yet supported for this flag", + to_string(arch)); return false; } - switch(f) { - case MIPS_EFLAGS::EF_MIPS_NOREORDER: - case MIPS_EFLAGS::EF_MIPS_PIC: - case MIPS_EFLAGS::EF_MIPS_CPIC: - case MIPS_EFLAGS::EF_MIPS_ABI2: - case MIPS_EFLAGS::EF_MIPS_32BITMODE: - case MIPS_EFLAGS::EF_MIPS_FP64: - case MIPS_EFLAGS::EF_MIPS_NAN2008: - { - return (processor_flag() & fn) > 0; - } - - case MIPS_EFLAGS::EF_MIPS_ABI_O32: - case MIPS_EFLAGS::EF_MIPS_ABI_O64: - case MIPS_EFLAGS::EF_MIPS_ABI_EABI32: - case MIPS_EFLAGS::EF_MIPS_ABI_EABI64: - { - return ((processor_flag() & static_cast(MIPS_EFLAGS::EF_MIPS_ABI)) & fn) > 0; - } - - case MIPS_EFLAGS::EF_MIPS_MACH_3900: - case MIPS_EFLAGS::EF_MIPS_MACH_4010: - case MIPS_EFLAGS::EF_MIPS_MACH_4100: - case MIPS_EFLAGS::EF_MIPS_MACH_4650: - case MIPS_EFLAGS::EF_MIPS_MACH_4120: - case MIPS_EFLAGS::EF_MIPS_MACH_4111: - case MIPS_EFLAGS::EF_MIPS_MACH_SB1: - case MIPS_EFLAGS::EF_MIPS_MACH_OCTEON: - case MIPS_EFLAGS::EF_MIPS_MACH_XLR: - case MIPS_EFLAGS::EF_MIPS_MACH_OCTEON2: - case MIPS_EFLAGS::EF_MIPS_MACH_OCTEON3: - case MIPS_EFLAGS::EF_MIPS_MACH_5400: - case MIPS_EFLAGS::EF_MIPS_MACH_5900: - case MIPS_EFLAGS::EF_MIPS_MACH_5500: - case MIPS_EFLAGS::EF_MIPS_MACH_9000: - case MIPS_EFLAGS::EF_MIPS_MACH_LS2E: - case MIPS_EFLAGS::EF_MIPS_MACH_LS2F: - case MIPS_EFLAGS::EF_MIPS_MACH_LS3A: - { - return ((processor_flag() & static_cast(MIPS_EFLAGS::EF_MIPS_MACH)) & fn) > 0; - } - - - case MIPS_EFLAGS::EF_MIPS_MICROMIPS: - case MIPS_EFLAGS::EF_MIPS_ARCH_ASE_M16: - case MIPS_EFLAGS::EF_MIPS_ARCH_ASE_MDMX: - { - return ((processor_flag() & static_cast(MIPS_EFLAGS::EF_MIPS_ARCH_ASE)) & fn) > 0; - } - - case MIPS_EFLAGS::EF_MIPS_ARCH_1: - case MIPS_EFLAGS::EF_MIPS_ARCH_2: - case MIPS_EFLAGS::EF_MIPS_ARCH_3: - case MIPS_EFLAGS::EF_MIPS_ARCH_4: - case MIPS_EFLAGS::EF_MIPS_ARCH_5: - case MIPS_EFLAGS::EF_MIPS_ARCH_32: - case MIPS_EFLAGS::EF_MIPS_ARCH_64: - case MIPS_EFLAGS::EF_MIPS_ARCH_32R2: - case MIPS_EFLAGS::EF_MIPS_ARCH_64R2: - case MIPS_EFLAGS::EF_MIPS_ARCH_32R6: - case MIPS_EFLAGS::EF_MIPS_ARCH_64R6: - { - return (processor_flag() & static_cast(MIPS_EFLAGS::EF_MIPS_ARCH)) == fn; - } - - default: - { - return (processor_flag() & fn) > 0; - } - } - - - return (processor_flag() & fn) > 0; + return false; } -Header::mips_flags_list_t Header::mips_flags_list() const { - mips_flags_list_t flags; +std::vector Header::flags_list() const { + std::vector flags; - std::copy_if( - std::begin(details::mips_eflags_array), - std::end(details::mips_eflags_array), - std::inserter(flags, std::begin(flags)), - [this] (MIPS_EFLAGS f) { return has(f); }); + std::copy_if(std::begin(PFLAGS_LIST), std::end(PFLAGS_LIST), + std::back_inserter(flags), + [this] (PROCESSOR_FLAGS f) { return this->has(f); } + ); return flags; - -} - - -bool Header::has(PPC64_EFLAGS f) const { - if (machine_type() != ARCH::EM_PPC64) { - return false; - } - - return (processor_flag() & static_cast(f)) > 0; } -Header::ppc64_flags_list_t Header::ppc64_flags_list() const { - ppc64_flags_list_t flags; - - std::copy_if( - std::begin(details::ppc64_eflags_array), - std::end(details::ppc64_eflags_array), - std::inserter(flags, std::begin(flags)), - [this] (PPC64_EFLAGS f) { return has(f); }); - - return flags; +std::ostream& operator<<(std::ostream& os, const Header& hdr) { + static constexpr auto PADDING = 35; + const std::vector flags = hdr.flags_list(); + std::vector flags_str; + flags_str.reserve(flags.size()); + + std::transform(flags.begin(), flags.end(), std::back_inserter(flags_str), + [] (PROCESSOR_FLAGS f) { return to_string(f); } + ); + + os << "FLIST: " << flags_str.size() << '\n'; + + os << "ELF Header:\n" + << fmt::format("{:<{}} {:02x}\n", "Magic:", PADDING, fmt::join(hdr.identity(), " ")) + << fmt::format("{:<{}} {}\n", "Class:", PADDING, to_string(hdr.identity_class())) + << fmt::format("{:<{}} {}\n", "Data:", PADDING, to_string(hdr.identity_data())) + << fmt::format("{:<{}} {}\n", "Version:", PADDING, to_string(hdr.identity_version())) + << fmt::format("{:<{}} {}\n", "OS/ABI:", PADDING, to_string(hdr.identity_os_abi())) + << fmt::format("{:<{}} {}\n", "ABI Version:", PADDING, hdr.identity_abi_version()) + << fmt::format("{:<{}} {}\n", "Type:", PADDING, to_string(hdr.file_type())) + << fmt::format("{:<{}} {}\n", "Machine:", PADDING, to_string(hdr.machine_type())) + << fmt::format("{:<{}} {}\n", "Version:", PADDING, to_string(hdr.object_file_version())) + << fmt::format("{:<{}} 0x{:08x}\n", "Entry point address:", PADDING, hdr.entrypoint()) + << fmt::format("{:<{}} {} (bytes into file)\n", "Start of program headers:", PADDING, hdr.program_headers_offset()) + << fmt::format("{:<{}} {} (bytes into file)\n", "Start of section headers:", PADDING, hdr.section_headers_offset()) + << fmt::format("{:<{}} 0x{:x} {}\n", "Flags:", PADDING, hdr.processor_flag(), fmt::to_string(fmt::join(flags_str, ", "))) + << fmt::format("{:<{}} {} (bytes)\n", "Size of this header:", PADDING, hdr.header_size()) + << fmt::format("{:<{}} {} (bytes)\n", "Size of program headers:", PADDING, hdr.program_header_size()) + << fmt::format("{:<{}} {}\n", "Number of program headers:", PADDING, hdr.numberof_segments()) + << fmt::format("{:<{}} {} (bytes)\n", "Size of section headers:", PADDING, hdr.section_header_size()) + << fmt::format("{:<{}} {}\n", "Number of section headers:", PADDING, hdr.numberof_sections()) + << fmt::format("{:<{}} {}\n", "Section header string table index:", PADDING, hdr.section_name_table_idx()) + ; + return os; } - -bool Header::has(HEXAGON_EFLAGS f) const { - if (machine_type() != ARCH::EM_HEXAGON) { - return false; +const char* to_string(Header::FILE_TYPE e) { + switch (e) { + case Header::FILE_TYPE::NONE: return "NONE"; + case Header::FILE_TYPE::REL: return "REL"; + case Header::FILE_TYPE::EXEC: return "EXEC"; + case Header::FILE_TYPE::DYN: return "DYN"; + case Header::FILE_TYPE::CORE: return "CORE"; } - - return (processor_flag() & static_cast(f)) > 0; -} - -Header::hexagon_flags_list_t Header::hexagon_flags_list() const { - hexagon_flags_list_t flags; - - std::copy_if( - std::begin(details::hexagon_eflags_array), - std::end(details::hexagon_eflags_array), - std::inserter(flags, std::begin(flags)), - [this] (HEXAGON_EFLAGS f) { return has(f); }); - - return flags; - + return "UNKNOWN"; } -bool Header::has(LOONGARCH_EFLAGS f) const { - if (machine_type() != ARCH::EM_LOONGARCH) { - return false; +const char* to_string(Header::VERSION e) { + switch (e) { + case Header::VERSION::NONE: return "NONE"; + case Header::VERSION::CURRENT: return "CURRENT"; } - - return (processor_flag() & static_cast(f)) > 0; -} - -Header::loongarch_flags_list_t Header::loongarch_flags_list() const { - loongarch_flags_list_t flags; - - std::copy_if( - std::begin(details::loongarch_eflags_array), - std::end(details::loongarch_eflags_array), - std::inserter(flags, std::begin(flags)), - [this] (LOONGARCH_EFLAGS f) { return has(f); }); - - return flags; - -} - -uint32_t Header::header_size() const { - return header_size_; -} - - -uint32_t Header::program_header_size() const { - return program_header_size_; -} - - -uint32_t Header::numberof_segments() const { - return numberof_segments_; -} - -uint32_t Header::section_header_size() const { - return section_header_size_; -} - -uint32_t Header::numberof_sections() const { - return numberof_sections_; -} - - -uint32_t Header::section_name_table_idx() const { - return section_string_table_idx_; -} - - -const Header::identity_t& Header::identity() const { - return identity_; -} - -Header::identity_t& Header::identity() { - return const_cast(static_cast(this)->identity()); -} - -ELF_CLASS Header::identity_class() const { - return static_cast(identity_[static_cast(IDENTITY::EI_CLASS)]); -} - -ELF_DATA Header::identity_data() const { - return static_cast(identity_[static_cast(IDENTITY::EI_DATA)]); -} - -VERSION Header::identity_version() const { - return static_cast(identity_[static_cast(IDENTITY::EI_VERSION)]); -} - -OS_ABI Header::identity_os_abi() const { - return static_cast(identity_[static_cast(IDENTITY::EI_OSABI)]); -} - -uint32_t Header::identity_abi_version() const { - return static_cast(identity_[static_cast(IDENTITY::EI_ABIVERSION)]); -} - -void Header::file_type(E_TYPE type) { - file_type_ = type; -} - - -void Header::machine_type(ARCH machineType) { - machine_type_ = machineType; + return "UNKNOWN"; } - -void Header::object_file_version(VERSION version) { - object_file_version_ = version; -} - - -void Header::entrypoint(uint64_t entryPoint) { - entrypoint_ = entryPoint; -} - - -void Header::program_headers_offset(uint64_t programHeaderOffset) { - program_headers_offset_ = programHeaderOffset; -} - - -void Header::section_headers_offset(uint64_t sectionHeaderOffset) { - section_headers_offset_ = sectionHeaderOffset; -} - - -void Header::processor_flag(uint32_t processorFlag) { - processor_flags_ = processorFlag; -} - - -void Header::header_size(uint32_t headerSize) { - header_size_ = headerSize; -} - - -void Header::program_header_size(uint32_t programHeaderSize) { - program_header_size_ = programHeaderSize; -} - - -void Header::numberof_segments(uint32_t n) { - numberof_segments_ = n; -} - - -void Header::section_header_size(uint32_t sizeOfSectionHeaderEntries) { - section_header_size_ = sizeOfSectionHeaderEntries; -} - - -void Header::numberof_sections(uint32_t n) { - numberof_sections_ = n; -} - - -void Header::section_name_table_idx(uint32_t sectionNameStringTableIdx) { - section_string_table_idx_ = sectionNameStringTableIdx; -} - - -void Header::identity(const std::string& identity) { - std::copy( - std::begin(identity), - std::end(identity), - std::begin(identity_)); -} - -void Header::identity(const Header::identity_t& identity) { - std::copy( - std::begin(identity), - std::end(identity), - std::begin(identity_)); -} - -void Header::identity_class(ELF_CLASS i_class) { - identity_[static_cast(IDENTITY::EI_CLASS)] = static_cast(i_class); -} - -void Header::identity_data(ELF_DATA data) { - identity_[static_cast(IDENTITY::EI_DATA)] = static_cast(data); -} - -void Header::identity_version(VERSION version) { - identity_[static_cast(IDENTITY::EI_VERSION)] = static_cast(version); -} - -void Header::identity_os_abi(OS_ABI osabi) { - identity_[static_cast(IDENTITY::EI_OSABI)] = static_cast(osabi); -} - -void Header::identity_abi_version(uint32_t version) { - identity_[static_cast(IDENTITY::EI_ABIVERSION)] = static_cast(version); -} - - -void Header::accept(LIEF::Visitor& visitor) const { - visitor.visit(*this); -} - - - - - -std::ostream& operator<<(std::ostream& os, const Header& hdr) -{ - const Header::identity_t& identity = const_cast(&hdr)->identity(); - std::stringstream ss; - ss << std::hex; - ss << static_cast(identity[static_cast(IDENTITY::EI_MAG0)]) << " "; - ss << static_cast(identity[static_cast(IDENTITY::EI_MAG1)]) << " "; - ss << static_cast(identity[static_cast(IDENTITY::EI_MAG2)]) << " "; - ss << static_cast(identity[static_cast(IDENTITY::EI_MAG3)]) << " "; - const std::string& ident_magic = ss.str(); - - std::string processor_flags_str; - - if (hdr.machine_type() == ARCH::EM_ARM) { - const Header::arm_flags_list_t& flags = hdr.arm_flags_list(); - processor_flags_str = std::accumulate( - std::begin(flags), - std::end(flags), std::string{}, - [] (const std::string& a, ARM_EFLAGS b) { - return a.empty() ? to_string(b) : a + " " + to_string(b); - }); +const char* to_string(Header::CLASS e) { + switch (e) { + case Header::CLASS::NONE: return "NONE"; + case Header::CLASS::ELF32: return "ELF32"; + case Header::CLASS::ELF64: return "ELF64"; } + return "UNKNOWN"; +} - - if (hdr.machine_type() == ARCH::EM_PPC64) { - const Header::ppc64_flags_list_t& flags = hdr.ppc64_flags_list(); - processor_flags_str = std::accumulate( - std::begin(flags), - std::end(flags), std::string{}, - [] (const std::string& a, PPC64_EFLAGS b) { - return a.empty() ? to_string(b) : a + " " + to_string(b); - }); - } - - if (hdr.machine_type() == ARCH::EM_HEXAGON) { - const Header::hexagon_flags_list_t& flags = hdr.hexagon_flags_list(); - processor_flags_str = std::accumulate( - std::begin(flags), - std::end(flags), std::string{}, - [] (const std::string& a, HEXAGON_EFLAGS b) { - return a.empty() ? to_string(b) : a + " " + to_string(b); - }); - } - - - if (hdr.machine_type() == ARCH::EM_MIPS || - hdr.machine_type() == ARCH::EM_MIPS_RS3_LE || - hdr.machine_type() == ARCH::EM_MIPS_X) - { - const Header::mips_flags_list_t& flags = hdr.mips_flags_list(); - processor_flags_str = std::accumulate( - std::begin(flags), - std::end(flags), std::string{}, - [] (const std::string& a, MIPS_EFLAGS b) { - return a.empty() ? to_string(b) : a + " " + to_string(b); - }); +const char* to_string(Header::ELF_DATA e) { + switch (e) { + case Header::ELF_DATA::NONE: return "NONE"; + case Header::ELF_DATA::LSB: return "LSB"; + case Header::ELF_DATA::MSB: return "MSB"; } + return "UNKNOWN"; +} + +const char* to_string(Header::OS_ABI e) { + #define ENTRY(X) std::pair(Header::OS_ABI::X, #X) + STRING_MAP enums2str { + ENTRY(SYSTEMV), + ENTRY(HPUX), + ENTRY(NETBSD), + ENTRY(GNU), + ENTRY(LINUX), + ENTRY(HURD), + ENTRY(SOLARIS), + ENTRY(AIX), + ENTRY(IRIX), + ENTRY(FREEBSD), + ENTRY(TRU64), + ENTRY(MODESTO), + ENTRY(OPENBSD), + ENTRY(OPENVMS), + ENTRY(NSK), + ENTRY(AROS), + ENTRY(FENIXOS), + ENTRY(CLOUDABI), + ENTRY(C6000_ELFABI), + ENTRY(AMDGPU_HSA), + ENTRY(C6000_LINUX), + ENTRY(ARM), + ENTRY(STANDALONE), + }; + #undef ENTRY - if (hdr.machine_type() == ARCH::EM_LOONGARCH) { - const Header::loongarch_flags_list_t& flags = hdr.loongarch_flags_list(); - processor_flags_str = std::accumulate( - std::begin(flags), - std::end(flags), std::string{}, - [] (const std::string& a, LOONGARCH_EFLAGS b) { - return a.empty() ? to_string(b) : a + " " + to_string(b); - }); + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; } + return "UNKNOWN"; +} - os << std::hex << std::left; - os << std::setw(33) << std::setfill(' ') << "Magic:" << ident_magic << std::endl; - os << std::setw(33) << std::setfill(' ') << "Class:" << to_string(hdr.identity_class()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "Endianness:" << to_string(hdr.identity_data()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "Version:" << to_string(hdr.identity_version()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "OS/ABI:" << to_string(hdr.identity_os_abi()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "ABI Version:" << std::dec << hdr.identity_abi_version() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Machine type:" << to_string(hdr.machine_type()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "File type:" << to_string(hdr.file_type()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "Object file version:" << to_string(hdr.object_file_version()) << std::endl; - os << std::setw(33) << std::setfill(' ') << "Entry Point:" << std::hex << "0x" << hdr.entrypoint() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Program header offset:" << std::hex << "0x" << hdr.program_headers_offset() << std::endl << std::dec; - os << std::setw(33) << std::setfill(' ') << "Section header offset:" << hdr.section_headers_offset() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Processor Flag:" << hdr.processor_flag() << " " << processor_flags_str << std::endl; - os << std::setw(33) << std::setfill(' ') << "Header size:" << hdr.header_size() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Size of program header:" << hdr.program_header_size() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Number of program header:" << hdr.numberof_segments() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Size of section header:" << hdr.section_header_size() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Number of section headers:" << hdr.numberof_sections() << std::endl; - os << std::setw(33) << std::setfill(' ') << "Section Name Table idx:" << hdr.section_name_table_idx() << std::endl; - return os; -} } } diff --git a/src/ELF/Layout.cpp b/src/ELF/Layout.cpp index 5b9777d291..213035b6c5 100644 --- a/src/ELF/Layout.cpp +++ b/src/ELF/Layout.cpp @@ -22,18 +22,13 @@ namespace LIEF { namespace ELF { -Layout::Layout(Binary& bin) : - binary_{&bin} -{} - -Layout::~Layout() = default; bool Layout::is_strtab_shared_shstrtab() const { // Check if the .strtab is shared with the .shstrtab const size_t shstrtab_idx = binary_->header().section_name_table_idx(); size_t strtab_idx = 0; - const Section* symtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB); + const Section* symtab = binary_->get(Section::TYPE::SYMTAB); if (symtab == nullptr) { return false; } @@ -98,10 +93,10 @@ size_t Layout::section_shstr_size() { }); if (!binary_->static_symbols_.empty()) { - if (binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB) == nullptr) { + if (binary_->get(Section::TYPE::SYMTAB) == nullptr) { sec_names.emplace_back(".symtab"); } - if (binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB) == nullptr) { + if (binary_->get(Section::TYPE::SYMTAB) == nullptr) { sec_names.emplace_back(".strtab"); } } @@ -131,8 +126,5 @@ size_t Layout::section_shstr_size() { return raw_shstrtab_.size(); } - - - } } diff --git a/src/ELF/Layout.hpp b/src/ELF/Layout.hpp index bdab9c1bda..5520db8930 100644 --- a/src/ELF/Layout.hpp +++ b/src/ELF/Layout.hpp @@ -26,7 +26,9 @@ class Section; class Binary; class Layout { public: - Layout(Binary& bin); + Layout(Binary& bin) : + binary_(&bin) + {} virtual const std::unordered_map& shstr_map() const { return shstr_name_map_; @@ -56,7 +58,7 @@ class Layout { size_t section_strtab_size(); size_t section_shstr_size(); - virtual ~Layout(); + virtual ~Layout() = default; Layout() = delete; protected: diff --git a/src/ELF/Note.cpp b/src/ELF/Note.cpp index e40132b508..2022dcbc1e 100644 --- a/src/ELF/Note.cpp +++ b/src/ELF/Note.cpp @@ -294,12 +294,12 @@ result Note::type_owner(Note::TYPE type) { } -result Note::convert_type(E_TYPE ftype, uint32_t type, +result Note::convert_type(Header::FILE_TYPE ftype, uint32_t type, const std::string& name) { std::string norm_name = strip_zero(name); - if (ftype == E_TYPE::ET_CORE) { + if (ftype == Header::FILE_TYPE::CORE) { if (norm_name == NT_CORE_NAME) { if (auto it = CORE_TYPES.find(type); it != CORE_TYPES.end()) { return it->second; @@ -363,7 +363,7 @@ result Note::convert_type(E_TYPE ftype, uint32_t type, } std::unique_ptr -Note::create(BinaryStream& stream, E_TYPE ftype, ARCH arch, ELF_CLASS cls) { +Note::create(BinaryStream& stream, Header::FILE_TYPE ftype, ARCH arch, Header::CLASS cls) { static constexpr uint32_t MAX_NOTE_DESCRIPTION = 1_MB; const size_t pos = stream.pos(); auto res_namesz = stream.read_conv(); @@ -429,7 +429,7 @@ Note::create(BinaryStream& stream, E_TYPE ftype, ARCH arch, ELF_CLASS cls) { std::unique_ptr Note::create(const std::string& name, Note::TYPE ntype, Note::description_t description, - ARCH arch, ELF_CLASS cls) + ARCH arch, Header::CLASS cls) { std::string owner; auto res_owner = type_owner(ntype); @@ -465,12 +465,12 @@ Note::create(const std::string& name, Note::TYPE ntype, Note::description_t desc switch (ntype) { case Note::TYPE::CORE_PRSTATUS: { - if (cls != ELF_CLASS::ELFCLASS32 && cls != ELF_CLASS::ELFCLASS64) { + if (cls != Header::CLASS::ELF32 && cls != Header::CLASS::ELF64) { LIEF_WARN("CORE_PRSTATUS requires a valid ELF class"); return nullptr; } - if (arch == ARCH::EM_NONE) { + if (arch == ARCH::NONE) { LIEF_WARN("CORE_PRSTATUS requires a valid architecture"); return nullptr; } @@ -480,12 +480,12 @@ Note::create(const std::string& name, Note::TYPE ntype, Note::description_t desc } case Note::TYPE::CORE_PRPSINFO: { - if (cls != ELF_CLASS::ELFCLASS32 && cls != ELF_CLASS::ELFCLASS64) { + if (cls != Header::CLASS::ELF32 && cls != Header::CLASS::ELF64) { LIEF_WARN("CORE_PRPSINFO requires a valid ELF class"); return nullptr; } - if (arch == ARCH::EM_NONE) { + if (arch == ARCH::NONE) { LIEF_WARN("CORE_PRPSINFO requires a valid architecture"); return nullptr; } @@ -495,12 +495,12 @@ Note::create(const std::string& name, Note::TYPE ntype, Note::description_t desc } case Note::TYPE::CORE_FILE: { - if (cls != ELF_CLASS::ELFCLASS32 && cls != ELF_CLASS::ELFCLASS64) { + if (cls != Header::CLASS::ELF32 && cls != Header::CLASS::ELF64) { LIEF_WARN("CORE_FILE requires a valid ELF class"); return nullptr; } - if (arch == ARCH::EM_NONE) { + if (arch == ARCH::NONE) { LIEF_WARN("CORE_FILE requires a valid architecture"); return nullptr; } @@ -510,12 +510,12 @@ Note::create(const std::string& name, Note::TYPE ntype, Note::description_t desc } case Note::TYPE::CORE_AUXV: { - if (cls != ELF_CLASS::ELFCLASS32 && cls != ELF_CLASS::ELFCLASS64) { + if (cls != Header::CLASS::ELF32 && cls != Header::CLASS::ELF64) { LIEF_WARN("CORE_AUXV requires a valid ELF class"); return nullptr; } - if (arch == ARCH::EM_NONE) { + if (arch == ARCH::NONE) { LIEF_WARN("CORE_AUXV requires a valid architecture"); return nullptr; } @@ -531,12 +531,12 @@ Note::create(const std::string& name, Note::TYPE ntype, Note::description_t desc } case Note::TYPE::GNU_PROPERTY_TYPE_0: { - if (cls != ELF_CLASS::ELFCLASS32 && cls != ELF_CLASS::ELFCLASS64) { + if (cls != Header::CLASS::ELF32 && cls != Header::CLASS::ELF64) { LIEF_WARN("GNU_PROPERTY_TYPE_0 requires a valid ELF class"); return nullptr; } - if (arch == ARCH::EM_NONE) { + if (arch == ARCH::NONE) { LIEF_WARN("GNU_PROPERTY_TYPE_0 requires a valid architecture"); return nullptr; } @@ -564,7 +564,7 @@ Note::create(const std::string& name, Note::TYPE ntype, Note::description_t desc std::unique_ptr Note::create(const std::string& name, uint32_t type, Note::description_t description, - E_TYPE ftype, ARCH arch, ELF_CLASS cls) + Header::FILE_TYPE ftype, ARCH arch, Header::CLASS cls) { auto conv = Note::convert_type(ftype, type, name); if (!conv) { diff --git a/src/ELF/NoteDetails/NoteGnuProperty.cpp b/src/ELF/NoteDetails/NoteGnuProperty.cpp index 1499ea2ab2..faf8af231a 100644 --- a/src/ELF/NoteDetails/NoteGnuProperty.cpp +++ b/src/ELF/NoteDetails/NoteGnuProperty.cpp @@ -64,9 +64,9 @@ parse_property(ARCH arch, SpanStream& stream) { SpanStream content = std::move(*res_content); const uint32_t type = *res_type; if (GNU_PROPERTY_LOPROC <= type && type <= GNU_PROPERTY_HIPROC) { - if (arch == ARCH::EM_X86_64 || - arch == ARCH::EM_IAMCU || - arch == ARCH::EM_386) + if (arch == ARCH::X86_64 || + arch == ARCH::IAMCU || + arch == ARCH::I386) { switch (type) { case GNU_PROPERTY_X86_ISA_1_USED: @@ -84,7 +84,7 @@ parse_property(ARCH arch, SpanStream& stream) { } } - if (arch == ARCH::EM_AARCH64) { + if (arch == ARCH::AARCH64) { if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { return AArch64Feature::create(content); } @@ -136,8 +136,8 @@ NoteGnuProperty::properties_t NoteGnuProperty::properties() const { LIEF_WARN("Can't create stream"); return {}; } - const bool is64 = arch_ == ARCH::EM_IA_64 || arch_ == ARCH::EM_AARCH64 || - arch_ == ARCH::EM_LOONGARCH || arch_ == ARCH::EM_X86_64; + const bool is64 = arch_ == ARCH::IA_64 || arch_ == ARCH::AARCH64 || + arch_ == ARCH::LOONGARCH || arch_ == ARCH::X86_64; properties_t props; diff --git a/src/ELF/NoteDetails/core/CoreAuxv.cpp b/src/ELF/NoteDetails/core/CoreAuxv.cpp index 163deeeeac..444dad6d88 100644 --- a/src/ELF/NoteDetails/core/CoreAuxv.cpp +++ b/src/ELF/NoteDetails/core/CoreAuxv.cpp @@ -106,13 +106,13 @@ inline bool write_impl(Note::description_t& description, result CoreAuxv::get(TYPE type) const { - return class_ == ELF_CLASS::ELFCLASS32 ? + return class_ == Header::CLASS::ELF32 ? get_impl(type, description_) : get_impl(type, description_); } std::map CoreAuxv::values() const { - return class_ == ELF_CLASS::ELFCLASS32 ? + return class_ == Header::CLASS::ELF32 ? get_values_impl(description_) : get_values_impl(description_); } @@ -125,7 +125,7 @@ bool CoreAuxv::set(TYPE type, uint64_t value) { } bool CoreAuxv::set(std::map values) { - return class_ == ELF_CLASS::ELFCLASS32 ? + return class_ == Header::CLASS::ELF32 ? write_impl(description_, values) : write_impl(description_, values); } diff --git a/src/ELF/NoteDetails/core/CoreFile.cpp b/src/ELF/NoteDetails/core/CoreFile.cpp index ef4d5b604f..860a2e9a5a 100644 --- a/src/ELF/NoteDetails/core/CoreFile.cpp +++ b/src/ELF/NoteDetails/core/CoreFile.cpp @@ -96,21 +96,21 @@ void CoreFile::write_files() { ios.move(description_); } -CoreFile::CoreFile(ARCH arch, ELF_CLASS cls, std::string name, +CoreFile::CoreFile(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, Note::description_t description) : Note(std::move(name), Note::TYPE::CORE_FILE, type, std::move(description)), arch_(arch), class_(cls) { - class_ == ELF_CLASS::ELFCLASS32 ? read_files() : - read_files(); + class_ == Header::CLASS::ELF32 ? read_files() : + read_files(); } void CoreFile::files(const CoreFile::files_t& files) { files_ = files; - class_ == ELF_CLASS::ELFCLASS32 ? write_files() : - write_files(); + class_ == Header::CLASS::ELF32 ? write_files() : + write_files(); } diff --git a/src/ELF/NoteDetails/core/CorePrPsInfo.cpp b/src/ELF/NoteDetails/core/CorePrPsInfo.cpp index 62499133a9..3ccd7b13fd 100644 --- a/src/ELF/NoteDetails/core/CorePrPsInfo.cpp +++ b/src/ELF/NoteDetails/core/CorePrPsInfo.cpp @@ -98,14 +98,14 @@ write_info_impl(Note::description_t& description, result CorePrPsInfo::info() const { - return class_ == ELF_CLASS::ELFCLASS32 ? + return class_ == Header::CLASS::ELF32 ? get_info_impl(description_) : get_info_impl(description_); } void CorePrPsInfo::info(const info_t& info) { - class_ == ELF_CLASS::ELFCLASS32 ? + class_ == Header::CLASS::ELF32 ? write_info_impl(description_, info) : write_info_impl(description_, info); } diff --git a/src/ELF/NoteDetails/core/CorePrStatus.cpp b/src/ELF/NoteDetails/core/CorePrStatus.cpp index e6aaca7cfd..071c5df925 100644 --- a/src/ELF/NoteDetails/core/CorePrStatus.cpp +++ b/src/ELF/NoteDetails/core/CorePrStatus.cpp @@ -114,29 +114,29 @@ inline Note::description_t write_status_impl(const CorePrStatus::pr_status_t& st template inline result get_reg_impl(REG_T reg, const Note::description_t& description, - ELF_CLASS cls, ARCH arch) + Header::CLASS cls, ARCH arch) { if constexpr (std::is_same_v) { - if (arch != ARCH::EM_386) { + if (arch != ARCH::I386) { return make_error_code(lief_errors::not_found); } } else if constexpr (std::is_same_v) { - if (arch != ARCH::EM_X86_64) { + if (arch != ARCH::X86_64) { return make_error_code(lief_errors::not_found); } } else if constexpr (std::is_same_v) { - if (arch != ARCH::EM_ARM) { + if (arch != ARCH::ARM) { return make_error_code(lief_errors::not_found); } } else if constexpr (std::is_same_v) { - if (arch != ARCH::EM_AARCH64) { + if (arch != ARCH::AARCH64) { return make_error_code(lief_errors::not_found); } } @@ -155,7 +155,7 @@ get_reg_impl(REG_T reg, const Note::description_t& description, return make_error_code(lief_errors::not_found); } - if (cls == ELF_CLASS::ELFCLASS32) { + if (cls == Header::CLASS::ELF32) { stream->increment_pos(sizeof(details::ELF32::Elf_Prstatus)); stream->increment_pos(pos * sizeof(uint32_t)); auto value = stream->read(); @@ -165,7 +165,7 @@ get_reg_impl(REG_T reg, const Note::description_t& description, return *value; } - if (cls == ELF_CLASS::ELFCLASS64) { + if (cls == Header::CLASS::ELF64) { stream->increment_pos(sizeof(details::ELF64::Elf_Prstatus)); stream->increment_pos(pos * sizeof(uint64_t)); auto value = stream->read(); @@ -181,29 +181,29 @@ get_reg_impl(REG_T reg, const Note::description_t& description, template inline ok_error_t set_reg_impl(REG_T reg, uint64_t value, Note::description_t& description, - ELF_CLASS cls, ARCH arch) + Header::CLASS cls, ARCH arch) { if constexpr (std::is_same_v) { - if (arch != ARCH::EM_386) { + if (arch != ARCH::I386) { return make_error_code(lief_errors::not_found); } } else if constexpr (std::is_same_v) { - if (arch != ARCH::EM_X86_64) { + if (arch != ARCH::X86_64) { return make_error_code(lief_errors::not_found); } } else if constexpr (std::is_same_v) { - if (arch != ARCH::EM_ARM) { + if (arch != ARCH::ARM) { return make_error_code(lief_errors::not_found); } } else if constexpr (std::is_same_v) { - if (arch != ARCH::EM_AARCH64) { + if (arch != ARCH::AARCH64) { return make_error_code(lief_errors::not_found); } } @@ -221,14 +221,14 @@ set_reg_impl(REG_T reg, uint64_t value, Note::description_t& description, vector_iostream os; os.write(description); - if (cls == ELF_CLASS::ELFCLASS32) { + if (cls == Header::CLASS::ELF32) { offset += sizeof(details::ELF32::Elf_Prstatus) + pos * sizeof(uint32_t); os.seekp(offset); os.write(value); return ok(); } - if (cls == ELF_CLASS::ELFCLASS64) { + if (cls == Header::CLASS::ELF64) { offset += sizeof(details::ELF64::Elf_Prstatus) + pos * sizeof(uint64_t); os.seekp(offset); os.write(value); @@ -242,7 +242,7 @@ set_reg_impl(REG_T reg, uint64_t value, Note::description_t& description, std::vector CorePrStatus::register_values() const { std::vector values; switch (arch_) { - case ARCH::EM_X86_64: + case ARCH::X86_64: { using Reg = Registers::X86_64; const auto count = static_cast(Reg::_COUNT); @@ -256,7 +256,7 @@ std::vector CorePrStatus::register_values() const { } return values; } - case ARCH::EM_386: + case ARCH::I386: { using Reg = Registers::X86; const auto count = static_cast(Reg::_COUNT); @@ -270,7 +270,7 @@ std::vector CorePrStatus::register_values() const { } return values; } - case ARCH::EM_ARM: + case ARCH::ARM: { using Reg = Registers::ARM; const auto count = static_cast(Reg::_COUNT); @@ -284,7 +284,7 @@ std::vector CorePrStatus::register_values() const { } return values; } - case ARCH::EM_AARCH64: + case ARCH::AARCH64: { using Reg = Registers::AARCH64; const auto count = static_cast(Reg::_COUNT); @@ -303,14 +303,14 @@ std::vector CorePrStatus::register_values() const { } CorePrStatus::pr_status_t CorePrStatus::status() const { - if (class_ == ELF_CLASS::ELFCLASS32) { + if (class_ == Header::CLASS::ELF32) { return get_status_impl(description_); } return get_status_impl(description_); } void CorePrStatus::status(const pr_status_t& status) { - Note::description_t description = class_ == ELF_CLASS::ELFCLASS32 ? + Note::description_t description = class_ == Header::CLASS::ELF32 ? write_status_impl(status) : write_status_impl(status); @@ -360,30 +360,30 @@ ok_error_t CorePrStatus::set(Registers::AARCH64 reg, uint64_t value) { result CorePrStatus::pc() const { switch (arch_) { - case ARCH::EM_AARCH64: return get(Registers::AARCH64::PC); - case ARCH::EM_ARM: return get(Registers::ARM::R15); - case ARCH::EM_386: return get(Registers::X86::EIP); - case ARCH::EM_X86_64: return get(Registers::X86_64::RIP); + case ARCH::AARCH64: return get(Registers::AARCH64::PC); + case ARCH::ARM: return get(Registers::ARM::R15); + case ARCH::I386: return get(Registers::X86::EIP); + case ARCH::X86_64: return get(Registers::X86_64::RIP); default: return make_error_code(lief_errors::not_supported); } } result CorePrStatus::sp() const { switch (arch_) { - case ARCH::EM_AARCH64: return get(Registers::AARCH64::X31); - case ARCH::EM_ARM: return get(Registers::ARM::R13); - case ARCH::EM_386: return get(Registers::X86::ESP); - case ARCH::EM_X86_64: return get(Registers::X86_64::RSP); + case ARCH::AARCH64: return get(Registers::AARCH64::X31); + case ARCH::ARM: return get(Registers::ARM::R13); + case ARCH::I386: return get(Registers::X86::ESP); + case ARCH::X86_64: return get(Registers::X86_64::RSP); default: return make_error_code(lief_errors::not_supported); } } result CorePrStatus::return_value() const { switch (arch_) { - case ARCH::EM_AARCH64: return get(Registers::AARCH64::X0); - case ARCH::EM_ARM: return get(Registers::ARM::R0); - case ARCH::EM_386: return get(Registers::X86::EAX); - case ARCH::EM_X86_64: return get(Registers::X86_64::RAX); + case ARCH::AARCH64: return get(Registers::AARCH64::X0); + case ARCH::ARM: return get(Registers::ARM::R0); + case ARCH::I386: return get(Registers::X86::EAX); + case ARCH::X86_64: return get(Registers::X86_64::RAX); default: return make_error_code(lief_errors::not_supported); } } @@ -413,13 +413,13 @@ void CorePrStatus::dump(std::ostream& os) const { status.cursig, status.reserved); const std::vector& reg_vals = register_values(); switch (architecture()) { - case ARCH::EM_ARM: + case ARCH::ARM: dump_impl(os, reg_vals); break; - case ARCH::EM_AARCH64: + case ARCH::AARCH64: dump_impl(os, reg_vals); break; - case ARCH::EM_386: + case ARCH::I386: dump_impl(os, reg_vals); break; - case ARCH::EM_X86_64: + case ARCH::X86_64: dump_impl(os, reg_vals); break; default: dump_impl(os, reg_vals); break; diff --git a/src/ELF/ObjectFileLayout.hpp b/src/ELF/ObjectFileLayout.hpp index 3057c20420..2880da0c93 100644 --- a/src/ELF/ObjectFileLayout.hpp +++ b/src/ELF/ObjectFileLayout.hpp @@ -63,7 +63,7 @@ class LIEF_LOCAL ObjectFileLayout : public Layout { uint64_t last_offset_sections = 0; for (std::unique_ptr
& section : binary_->sections_) { - if (section->type() == LIEF::ELF::ELF_SECTION_TYPES::SHT_NOBITS) { + if (section->type() == Section::TYPE::NOBITS) { continue; } last_offset_sections = std::max(section->file_offset() + section->size(), diff --git a/src/ELF/Parser.cpp b/src/ELF/Parser.cpp index f13842c7d0..5d61fa931a 100644 --- a/src/ELF/Parser.cpp +++ b/src/ELF/Parser.cpp @@ -38,9 +38,6 @@ namespace LIEF { namespace ELF { -Parser::~Parser() = default; -Parser::Parser() = default; - Parser::Parser(const std::vector& data, ParserConfig conf) : stream_{std::make_unique(data)}, binary_{new Binary{}}, @@ -62,78 +59,74 @@ Parser::Parser(const std::string& file, ParserConfig conf) : } } -ELF_DATA determine_elf_endianess(ARCH machine) { +Header::ELF_DATA determine_elf_endianess(ARCH machine) { switch (machine) { /* Architectures that are known to be big-endian only */ - case ARCH::EM_H8_300: - case ARCH::EM_SPARC: - case ARCH::EM_SPARCV9: - case ARCH::EM_S390: - case ARCH::EM_68K: - case ARCH::EM_OPENRISC: - { - return ELF_DATA::ELFDATA2MSB; - } + case ARCH::H8_300: + case ARCH::SPARC: + case ARCH::SPARCV9: + case ARCH::S390: + case ARCH::M68K: + case ARCH::OPENRISC: + return Header::ELF_DATA::MSB; + /* Architectures that are known to be little-endian only */ - case ARCH::EM_HEXAGON: - case ARCH::EM_ALPHA: - case ARCH::EM_ALTERA_NIOS2: - case ARCH::EM_CRIS: - case ARCH::EM_386: // x86 - case ARCH::EM_X86_64: - case ARCH::EM_IA_64: - case ARCH::EM_LOONGARCH: - { - return ELF_DATA::ELFDATA2LSB; - } + case ARCH::HEXAGON: + case ARCH::ALPHA: + case ARCH::ALTERA_NIOS2: + case ARCH::CRIS: + case ARCH::I386: // x86 + case ARCH::X86_64: + case ARCH::IA_64: + case ARCH::LOONGARCH: + return Header::ELF_DATA::LSB; + default: - { - return ELF_DATA::ELFDATANONE; - } + return Header::ELF_DATA::NONE; } } /* * Get the endianess of the current architecture */ -constexpr ELF_DATA get_endianess() { +constexpr Header::ELF_DATA get_endianess() { #ifdef __BYTE_ORDER__ #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - return ELF_DATA::ELFDATA2LSB; + return Header::ELF_DATA::LSB; #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - return ELF_DATA::ELFDATA2MSB; + return Header::ELF_DATA::MSB; #endif #endif /* If there are no __BYTE_ORDER__ we take the (arbitrary) decision that we are * on a little endian architecture. */ - return ELF_DATA::ELFDATA2LSB; + return Header::ELF_DATA::LSB; } -constexpr ELF_DATA invert_endianess(ELF_DATA endian) { - if (endian == ELF_DATA::ELFDATA2MSB) { - return ELF_DATA::ELFDATA2LSB; +constexpr Header::ELF_DATA invert_endianess(Header::ELF_DATA endian) { + if (endian == Header::ELF_DATA::MSB) { + return Header::ELF_DATA::LSB; } - if (endian == ELF_DATA::ELFDATA2LSB) { - return ELF_DATA::ELFDATA2MSB; + if (endian == Header::ELF_DATA::LSB) { + return Header::ELF_DATA::MSB; } - return ELF_DATA::ELFDATANONE; + return Header::ELF_DATA::NONE; } -ELF_DATA determine_elf_endianess(BinaryStream& stream) { +Header::ELF_DATA determine_elf_endianess(BinaryStream& stream) { static const std::set BOTH_ENDIANESS = { - ARCH::EM_AARCH64, ARCH::EM_ARM, ARCH::EM_SH, ARCH::EM_XTENSA, - ARCH::EM_ARC, ARCH::EM_MIPS, ARCH::EM_PPC, ARCH::EM_PPC64, + ARCH::AARCH64, ARCH::ARM, ARCH::SH, ARCH::XTENSA, + ARCH::ARC, ARCH::MIPS, ARCH::PPC, ARCH::PPC64, }; - ELF_DATA from_ei_data = ELF_DATA::ELFDATANONE; + Header::ELF_DATA from_ei_data = Header::ELF_DATA::NONE; /* ELF_DATA from_e_machine = ELF_DATA::ELFDATANONE; */ // First, check EI_CLASS if (auto res = stream.peek()) { auto ident = *res; - uint32_t ei_data = ident[static_cast(IDENTITY::EI_DATA)]; - const auto data = static_cast(ei_data); - if (data == ELF_DATA::ELFDATA2LSB || data == ELF_DATA::ELFDATA2MSB) { + uint32_t ei_data = ident[Header::EI_DATA]; + const auto data = static_cast(ei_data); + if (data == Header::ELF_DATA::LSB || data == Header::ELF_DATA::MSB) { from_ei_data = data; } } @@ -150,8 +143,8 @@ ELF_DATA determine_elf_endianess(BinaryStream& stream) { constexpr size_t e_machine_off = offsetof(details::Elf32_Ehdr, e_machine); { // Read Machine type with both endianess - ARCH machine = ARCH::EM_NONE; // e_machine value without endian swap enabled - ARCH machine_swap = ARCH::EM_NONE; // e_machine value with endian swap enabled + ARCH machine = ARCH::NONE; // e_machine value without endian swap enabled + ARCH machine_swap = ARCH::NONE; // e_machine value with endian swap enabled const bool is_swap = stream.should_swap(); stream.set_endian_swap(false); if (auto res = stream.peek_conv(e_machine_off)) { @@ -166,14 +159,14 @@ ELF_DATA determine_elf_endianess(BinaryStream& stream) { LIEF_DEBUG("Machine '{}'", to_string(machine)); LIEF_DEBUG("Machine Swap'{}'", to_string(machine_swap)); - const ELF_DATA endian = determine_elf_endianess(machine); - const ELF_DATA endian_swap = determine_elf_endianess(machine_swap); + const Header::ELF_DATA endian = determine_elf_endianess(machine); + const Header::ELF_DATA endian_swap = determine_elf_endianess(machine_swap); - if (endian != ELF_DATA::ELFDATANONE) { + if (endian != Header::ELF_DATA::NONE) { return endian; } - if (endian_swap != ELF_DATA::ELFDATANONE) { + if (endian_swap != Header::ELF_DATA::NONE) { return endian_swap; } @@ -189,12 +182,12 @@ ELF_DATA determine_elf_endianess(BinaryStream& stream) { } bool Parser::should_swap() const { - const ELF_DATA binary_endian = determine_elf_endianess(*stream_); - const ELF_DATA current_endian = get_endianess(); + const Header::ELF_DATA binary_endian = determine_elf_endianess(*stream_); + const Header::ELF_DATA current_endian = get_endianess(); LIEF_DEBUG("LIEF Endianness: '{}'", to_string(current_endian)); LIEF_DEBUG("Binary Endianness: '{}'", to_string(binary_endian)); - if (binary_endian != ELF_DATA::ELFDATANONE && - current_endian != ELF_DATA::ELFDATANONE) + if (binary_endian != Header::ELF_DATA::NONE && + current_endian != Header::ELF_DATA::NONE) { return binary_endian != current_endian; } @@ -203,24 +196,24 @@ bool Parser::should_swap() const { -ELF_CLASS determine_elf_class(BinaryStream& stream) { - auto from_ei_class = ELF_CLASS::ELFCLASSNONE; - auto from_e_machine = ELF_CLASS::ELFCLASSNONE; - auto file_type = E_TYPE::ET_NONE; +Header::CLASS determine_elf_class(BinaryStream& stream) { + auto from_ei_class = Header::CLASS::NONE; + auto from_e_machine = Header::CLASS::NONE; + auto file_type = Header::FILE_TYPE::NONE; // First, check EI_CLASS if (auto res = stream.peek()) { auto ident = *res; - uint32_t ei_class = ident[static_cast(IDENTITY::EI_CLASS)]; - const auto typed = static_cast(ei_class); - if (typed == ELF_CLASS::ELFCLASS32 || typed == ELF_CLASS::ELFCLASS64) { + uint32_t ei_class = ident[Header::EI_CLASS]; + const auto typed = Header::CLASS(ei_class); + if (typed == Header::CLASS::ELF32 || typed == Header::CLASS::ELF64) { from_ei_class = typed; } } constexpr size_t e_type_off = offsetof(details::Elf32_Ehdr, e_type); if (auto res = stream.peek(e_type_off)) { - file_type = static_cast(*res); + file_type = Header::FILE_TYPE(*res); } // Try to determine the size based on Elf_Ehdr.e_machine @@ -236,37 +229,37 @@ ELF_CLASS determine_elf_class(BinaryStream& stream) { if (auto res = stream.peek_conv(e_machine_off)) { const auto machine = static_cast(*res); switch (machine) { - case ARCH::EM_AARCH64: - case ARCH::EM_X86_64: - case ARCH::EM_PPC64: - case ARCH::EM_SPARCV9: - case ARCH::EM_IA_64: + case ARCH::AARCH64: + case ARCH::X86_64: + case ARCH::PPC64: + case ARCH::SPARCV9: + case ARCH::IA_64: { - from_e_machine = ELF_CLASS::ELFCLASS64; + from_e_machine = Header::CLASS::ELF64; break; } - case ARCH::EM_386: - case ARCH::EM_ARM: - case ARCH::EM_PPC: + case ARCH::I386: + case ARCH::ARM: + case ARCH::PPC: { - from_e_machine = ELF_CLASS::ELFCLASS32; + from_e_machine = Header::CLASS::ELF32; break; } default: { - from_e_machine = ELF_CLASS::ELFCLASSNONE; + from_e_machine = Header::CLASS::NONE; break; } } } - if (from_e_machine != ELF_CLASS::ELFCLASSNONE && - from_ei_class != ELF_CLASS::ELFCLASSNONE) + if (from_e_machine != Header::CLASS::NONE && + from_ei_class != Header::CLASS::NONE) { if (from_e_machine == from_ei_class) { return from_ei_class; } - if (file_type == E_TYPE::ET_REL) { + if (file_type == Header::FILE_TYPE::REL) { return from_ei_class; } @@ -277,7 +270,7 @@ ELF_CLASS determine_elf_class(BinaryStream& stream) { // this value that is used by the kernel. return from_e_machine; } - if (from_e_machine != ELF_CLASS::ELFCLASSNONE) { + if (from_e_machine != Header::CLASS::NONE) { return from_e_machine; } return from_ei_class; @@ -285,7 +278,6 @@ ELF_CLASS determine_elf_class(BinaryStream& stream) { ok_error_t Parser::init() { - if (stream_ == nullptr) { LIEF_ERR("Stream not properly initialized"); return make_error_code(lief_errors::parsing_error); @@ -309,15 +301,14 @@ ok_error_t Parser::init() { stream_->set_endian_swap(should_swap()); binary_->type_ = determine_elf_class(*stream_); - type_ = binary_->type_; - switch (type_) { - case ELF_CLASS::ELFCLASS32: return parse_binary(); - case ELF_CLASS::ELFCLASS64: return parse_binary(); - case ELF_CLASS::ELFCLASSNONE: - default: + switch (binary_->type_) { + case Header::CLASS::ELF32: return parse_binary(); + case Header::CLASS::ELF64: return parse_binary(); + case Header::CLASS::NONE: { - LIEF_ERR("Can't determine the ELF class ({})", static_cast(type_)); + LIEF_ERR("Can't determine the ELF class ({})", + static_cast(binary_->type_)); return make_error_code(lief_errors::corrupted); } } @@ -378,7 +369,7 @@ ok_error_t Parser::parse_symbol_version(uint64_t symbol_version_offset) { result Parser::get_dynamic_string_table_from_segments() const { - Segment* dyn_segment = binary_->get(SEGMENT_TYPES::PT_DYNAMIC); + Segment* dyn_segment = binary_->get(Segment::TYPE::DYNAMIC); if (dyn_segment == nullptr) { return 0; } @@ -388,7 +379,9 @@ result Parser::get_dynamic_string_table_from_segments() const { stream_->setpos(offset); - if (binary_->type_ == ELF_CLASS::ELFCLASS32) { + const ARCH arch = binary_->header().machine_type(); + + if (binary_->type_ == Header::CLASS::ELF32) { size_t nb_entries = size / sizeof(details::Elf32_Dyn); for (size_t i = 0; i < nb_entries; ++i) { @@ -399,7 +392,7 @@ result Parser::get_dynamic_string_table_from_segments() const { } auto dt = *res; - if (static_cast(dt.d_tag) == DYNAMIC_TAGS::DT_STRTAB) { + if (DynamicEntry::from_value(dt.d_tag, arch) == DynamicEntry::TAG::STRTAB) { return binary_->virtual_address_to_offset(dt.d_un.d_val); } } @@ -414,7 +407,7 @@ result Parser::get_dynamic_string_table_from_segments() const { } const auto dt = *res; - if (static_cast(dt.d_tag) == DYNAMIC_TAGS::DT_STRTAB) { + if (DynamicEntry::from_value(dt.d_tag, arch) == DynamicEntry::TAG::STRTAB) { return binary_->virtual_address_to_offset(dt.d_un.d_val); } } @@ -428,7 +421,7 @@ uint64_t Parser::get_dynamic_string_table_from_sections() const { std::begin(binary_->sections_), std::end(binary_->sections_), [] (const std::unique_ptr
& section) { return section->name() == ".dynstr" && - section->type() == ELF_SECTION_TYPES::SHT_STRTAB; + section->type() == Section::TYPE::STRTAB; }); @@ -635,8 +628,8 @@ bool Parser::check_section_in_segment(const Section& section, const Segment& seg ok_error_t Parser::link_symbol_section(Symbol& sym) { const uint16_t sec_idx = sym.section_idx(); - if (sec_idx == static_cast(SYMBOL_SECTION_INDEX::SHN_ABS) || - sec_idx == static_cast(SYMBOL_SECTION_INDEX::SHN_UNDEF)) { + if (sec_idx == Symbol::SECTION_INDEX::ABS || + sec_idx == Symbol::SECTION_INDEX::UNDEF) { // Nothing to bind return ok(); } @@ -650,7 +643,5 @@ ok_error_t Parser::link_symbol_section(Symbol& sym) { return ok(); } - - } } diff --git a/src/ELF/Parser.tcc b/src/ELF/Parser.tcc index 089be17b99..3b51e89ce3 100644 --- a/src/ELF/Parser.tcc +++ b/src/ELF/Parser.tcc @@ -75,7 +75,7 @@ ok_error_t Parser::parse_binary() { if (binary_->header_.program_headers_offset() > 0) { parse_segments(); } else { - if (binary_->header().file_type() != E_TYPE::ET_REL) { + if (binary_->header().file_type() != Header::FILE_TYPE::REL) { LIEF_WARN("Binary doesn't have a program header"); } } @@ -84,7 +84,7 @@ ok_error_t Parser::parse_binary() { // ====================== // Find the dynamic Segment - if (const Segment* seg_dyn = binary_->get(SEGMENT_TYPES::PT_DYNAMIC)) { + if (const Segment* seg_dyn = binary_->get(Segment::TYPE::DYNAMIC)) { const Elf_Off offset = seg_dyn->file_offset(); const Elf_Off size = seg_dyn->physical_size(); @@ -96,8 +96,8 @@ ok_error_t Parser::parse_binary() { // Parse dynamic symbols // ===================== { - DynamicEntry* dt_symtab = binary_->get(DYNAMIC_TAGS::DT_SYMTAB); - DynamicEntry* dt_syment = binary_->get(DYNAMIC_TAGS::DT_SYMENT); + DynamicEntry* dt_symtab = binary_->get(DynamicEntry::TAG::SYMTAB); + DynamicEntry* dt_syment = binary_->get(DynamicEntry::TAG::SYMENT); if (dt_symtab != nullptr && dt_syment != nullptr && config_.parse_dyn_symbols) { const uint64_t virtual_address = dt_symtab->value(); @@ -115,8 +115,8 @@ ok_error_t Parser::parse_binary() { // RELA // ---- { - DynamicEntry* dt_rela = binary_->get(DYNAMIC_TAGS::DT_RELA); - DynamicEntry* dt_relasz = binary_->get(DYNAMIC_TAGS::DT_RELASZ); + DynamicEntry* dt_rela = binary_->get(DynamicEntry::TAG::RELA); + DynamicEntry* dt_relasz = binary_->get(DynamicEntry::TAG::RELASZ); if (dt_rela != nullptr && dt_relasz != nullptr && config_.parse_relocations) { const uint64_t virtual_address = dt_rela->value(); @@ -134,8 +134,8 @@ ok_error_t Parser::parse_binary() { // REL // --- { - DynamicEntry* dt_rel = binary_->get(DYNAMIC_TAGS::DT_REL); - DynamicEntry* dt_relsz = binary_->get(DYNAMIC_TAGS::DT_RELSZ); + DynamicEntry* dt_rel = binary_->get(DynamicEntry::TAG::REL); + DynamicEntry* dt_relsz = binary_->get(DynamicEntry::TAG::RELSZ); if (dt_rel != nullptr && dt_relsz != nullptr && config_.parse_relocations) { const uint64_t virtual_address = dt_rel->value(); @@ -152,27 +152,27 @@ ok_error_t Parser::parse_binary() { // Parse PLT/GOT Relocations // ========================== { - DynamicEntry* dt_jmprel = binary_->get(DYNAMIC_TAGS::DT_JMPREL); - DynamicEntry* dt_pltrelsz = binary_->get(DYNAMIC_TAGS::DT_PLTRELSZ); + DynamicEntry* dt_jmprel = binary_->get(DynamicEntry::TAG::JMPREL); + DynamicEntry* dt_pltrelsz = binary_->get(DynamicEntry::TAG::PLTRELSZ); if (dt_jmprel != nullptr && dt_pltrelsz != nullptr && config_.parse_relocations) { const uint64_t virtual_address = dt_jmprel->value(); const uint64_t size = dt_pltrelsz->value(); - DynamicEntry* dt_pltrel = binary_->get(DYNAMIC_TAGS::DT_PLTREL); - DYNAMIC_TAGS type; + DynamicEntry* dt_pltrel = binary_->get(DynamicEntry::TAG::PLTREL); + DynamicEntry::TAG type; if (dt_pltrel != nullptr) { - type = static_cast(dt_pltrel->value()); + type = DynamicEntry::from_value(dt_pltrel->value(), binary_->header().machine_type()); } else { // Try to guess: We assume that on ELF64 -> DT_RELA and on ELF32 -> DT_REL - if (std::is_same::value) { - type = DYNAMIC_TAGS::DT_RELA; + if constexpr (std::is_same_v) { + type = DynamicEntry::TAG::RELA; } else { - type = DYNAMIC_TAGS::DT_REL; + type = DynamicEntry::TAG::REL; } } if (auto res = binary_->virtual_address_to_offset(virtual_address)) { - type == DYNAMIC_TAGS::DT_RELA ? + type == DynamicEntry::TAG::RELA ? parse_pltgot_relocations(*res, size) : parse_pltgot_relocations(*res, size); binary_->sizing_info_->jmprel = size; @@ -185,7 +185,7 @@ ok_error_t Parser::parse_binary() { // Parse Symbol Version // ==================== if (config_.parse_symbol_versions && config_.parse_dyn_symbols) { - if (DynamicEntry* dt_versym = binary_->get(DYNAMIC_TAGS::DT_VERSYM)) { + if (DynamicEntry* dt_versym = binary_->get(DynamicEntry::TAG::VERSYM)) { const uint64_t virtual_address = dt_versym->value(); if (auto res = binary_->virtual_address_to_offset(virtual_address)) { parse_symbol_version(*res); @@ -200,8 +200,8 @@ ok_error_t Parser::parse_binary() { // Parse Symbol Version Requirement // ================================ if (config_.parse_symbol_versions) { - DynamicEntry* dt_verneed = binary_->get(DYNAMIC_TAGS::DT_VERNEED); - DynamicEntry* dt_verneed_num = binary_->get(DYNAMIC_TAGS::DT_VERNEEDNUM); + DynamicEntry* dt_verneed = binary_->get(DynamicEntry::TAG::VERNEED); + DynamicEntry* dt_verneed_num = binary_->get(DynamicEntry::TAG::VERNEEDNUM); if (dt_verneed != nullptr && dt_verneed_num != nullptr) { const uint64_t virtual_address = dt_verneed->value(); @@ -219,8 +219,8 @@ ok_error_t Parser::parse_binary() { // Parse Symbol Version Definition // =============================== if (config_.parse_symbol_versions) { - DynamicEntry* dt_verdef = binary_->get(DYNAMIC_TAGS::DT_VERDEF); - DynamicEntry* dt_verdef_num = binary_->get(DYNAMIC_TAGS::DT_VERDEFNUM); + DynamicEntry* dt_verdef = binary_->get(DynamicEntry::TAG::VERDEF); + DynamicEntry* dt_verdef_num = binary_->get(DynamicEntry::TAG::VERDEFNUM); if (dt_verdef != nullptr && dt_verdef_num != nullptr) { const uint64_t virtual_address = dt_verdef->value(); const auto size = static_cast(dt_verdef_num->value()); @@ -236,7 +236,7 @@ ok_error_t Parser::parse_binary() { // Parse static symbols // ==================== - if (const Section* sec_symbtab = binary_->get(ELF_SECTION_TYPES::SHT_SYMTAB)) { + if (const Section* sec_symbtab = binary_->get(Section::TYPE::SYMTAB)) { auto nb_entries = static_cast((sec_symbtab->size() / sizeof(typename ELF_T::Elf_Sym))); nb_entries = std::min(nb_entries, Parser::NB_MAX_SYMBOLS); @@ -256,7 +256,7 @@ ok_error_t Parser::parse_binary() { // Parse Symbols's hash // ==================== - if (DynamicEntry* dt_hash = binary_->get(DYNAMIC_TAGS::DT_HASH)) { + if (DynamicEntry* dt_hash = binary_->get(DynamicEntry::TAG::HASH)) { if (auto res = binary_->virtual_address_to_offset(dt_hash->value())) { parse_symbol_sysv_hash(*res); } else { @@ -265,7 +265,7 @@ ok_error_t Parser::parse_binary() { } - if (DynamicEntry* dt_gnu_hash = binary_->get(DYNAMIC_TAGS::DT_GNU_HASH)) { + if (DynamicEntry* dt_gnu_hash = binary_->get(DynamicEntry::TAG::GNU_HASH)) { if (auto res = binary_->virtual_address_to_offset(dt_gnu_hash->value())) { parse_symbol_gnu_hash(*res); } else { @@ -277,7 +277,7 @@ ok_error_t Parser::parse_binary() { // Parse Note segment // ================== for (const Segment& segment : binary_->segments()) { - if (segment.type() != SEGMENT_TYPES::PT_NOTE) { + if (segment.type() != Segment::TYPE::NOTE) { continue; } parse_notes(segment.file_offset(), segment.physical_size()); @@ -286,7 +286,7 @@ ok_error_t Parser::parse_binary() { // Parse Note Sections // =================== for (const Section& section : binary_->sections()) { - if (section.type() != ELF_SECTION_TYPES::SHT_NOTE) { + if (section.type() != Section::TYPE::NOTE) { continue; } LIEF_DEBUG("Notes from section: {}", section.name()); @@ -301,13 +301,13 @@ ok_error_t Parser::parse_binary() { if (config_.parse_relocations) { bool skip_allocated_sections = !binary_->relocations_.empty(); for (const Section& section : binary_->sections()) { - if (skip_allocated_sections && section.has(ELF_SECTION_FLAGS::SHF_ALLOC)){ + if (skip_allocated_sections && section.has(Section::FLAGS::ALLOC)){ continue; } - if (section.type() == ELF_SECTION_TYPES::SHT_REL) { + if (section.type() == Section::TYPE::REL) { parse_section_relocations(section); } - else if (section.type() == ELF_SECTION_TYPES::SHT_RELA) { + else if (section.type() == Section::TYPE::RELA) { parse_section_relocations(section); } } @@ -340,7 +340,7 @@ ok_error_t Parser::parse_header() { } if (auto res = stream_->read_conv()) { - binary_->header_.file_type_ = static_cast(*res); + binary_->header_.file_type_ = Header::FILE_TYPE(*res); } else { LIEF_ERR("Can't parse Elf_Ehdr.e_type"); return make_error_code(lief_errors::read_error); @@ -354,7 +354,7 @@ ok_error_t Parser::parse_header() { } if (auto res = stream_->read_conv()) { - binary_->header_.object_file_version_ = static_cast(*res); + binary_->header_.object_file_version_ = Header::VERSION(*res); } else { LIEF_ERR("Can't parse Elf_Ehdr.e_version"); return make_error_code(lief_errors::read_error); @@ -439,29 +439,29 @@ ok_error_t Parser::parse_header() { template -result Parser::get_numberof_dynamic_symbols(DYNSYM_COUNT_METHODS mtd) const { +result Parser::get_numberof_dynamic_symbols(ParserConfig::DYNSYM_COUNT mtd) const { switch(mtd) { - case DYNSYM_COUNT_METHODS::COUNT_HASH: return nb_dynsym_hash(); - case DYNSYM_COUNT_METHODS::COUNT_SECTION: return nb_dynsym_section(); - case DYNSYM_COUNT_METHODS::COUNT_RELOCATIONS: return nb_dynsym_relocations(); + case ParserConfig::DYNSYM_COUNT::HASH: return nb_dynsym_hash(); + case ParserConfig::DYNSYM_COUNT::SECTION: return nb_dynsym_section(); + case ParserConfig::DYNSYM_COUNT::RELOCATIONS: return nb_dynsym_relocations(); - case DYNSYM_COUNT_METHODS::COUNT_AUTO: + case ParserConfig::DYNSYM_COUNT::AUTO: default: { uint32_t nb_reloc = 0; uint32_t nb_section = 0; uint32_t nb_hash = 0; - if (auto res = get_numberof_dynamic_symbols(DYNSYM_COUNT_METHODS::COUNT_RELOCATIONS)) { + if (auto res = get_numberof_dynamic_symbols(ParserConfig::DYNSYM_COUNT::RELOCATIONS)) { nb_reloc = *res; } - if (auto res = get_numberof_dynamic_symbols(DYNSYM_COUNT_METHODS::COUNT_SECTION)) { + if (auto res = get_numberof_dynamic_symbols(ParserConfig::DYNSYM_COUNT::SECTION)) { nb_section = *res; } - if (auto res = get_numberof_dynamic_symbols(DYNSYM_COUNT_METHODS::COUNT_HASH)) { + if (auto res = get_numberof_dynamic_symbols(ParserConfig::DYNSYM_COUNT::HASH)) { nb_hash = *res; } @@ -508,8 +508,8 @@ result Parser::nb_dynsym_relocations() const { // RELA // ---- - DynamicEntry* dt_rela = binary_->get(DYNAMIC_TAGS::DT_RELA); - DynamicEntry* dt_relasz = binary_->get(DYNAMIC_TAGS::DT_RELASZ); + DynamicEntry* dt_rela = binary_->get(DynamicEntry::TAG::RELA); + DynamicEntry* dt_relasz = binary_->get(DynamicEntry::TAG::RELASZ); if (dt_rela != nullptr && dt_relasz != nullptr) { const uint64_t virtual_address = dt_rela->value(); const uint64_t size = dt_relasz->value(); @@ -521,8 +521,8 @@ result Parser::nb_dynsym_relocations() const { // REL // --- - DynamicEntry* dt_rel = binary_->get(DYNAMIC_TAGS::DT_REL); - DynamicEntry* dt_relsz = binary_->get(DYNAMIC_TAGS::DT_RELSZ); + DynamicEntry* dt_rel = binary_->get(DynamicEntry::TAG::REL); + DynamicEntry* dt_relsz = binary_->get(DynamicEntry::TAG::RELSZ); if (dt_rel != nullptr && dt_relsz != nullptr) { const uint64_t virtual_address = dt_rel->value(); @@ -535,25 +535,25 @@ result Parser::nb_dynsym_relocations() const { // Parse PLT/GOT Relocations // ========================== - DynamicEntry* dt_jmprel = binary_->get(DYNAMIC_TAGS::DT_JMPREL); - DynamicEntry* dt_pltrelsz = binary_->get(DYNAMIC_TAGS::DT_PLTRELSZ); + DynamicEntry* dt_jmprel = binary_->get(DynamicEntry::TAG::JMPREL); + DynamicEntry* dt_pltrelsz = binary_->get(DynamicEntry::TAG::PLTRELSZ); if (dt_jmprel != nullptr && dt_pltrelsz != nullptr) { const uint64_t virtual_address = dt_jmprel->value(); const uint64_t size = dt_pltrelsz->value(); - DynamicEntry* dt_pltrel = binary_->get(DYNAMIC_TAGS::DT_PLTREL); - DYNAMIC_TAGS type; + DynamicEntry* dt_pltrel = binary_->get(DynamicEntry::TAG::PLTREL); + DynamicEntry::TAG type; if (dt_pltrel != nullptr) { - type = static_cast(dt_pltrel->value()); + type = DynamicEntry::from_value(dt_pltrel->value(), binary_->header().machine_type()); } else { // Try to guess: We assume that on ELF64 -> DT_RELA and on ELF32 -> DT_REL - if (std::is_same::value) { - type = DYNAMIC_TAGS::DT_RELA; + if constexpr (std::is_same_v) { + type = DynamicEntry::TAG::RELA; } else { - type = DYNAMIC_TAGS::DT_REL; + type = DynamicEntry::TAG::REL; } } if (auto res = binary_->virtual_address_to_offset(virtual_address)) { - if (type == DYNAMIC_TAGS::DT_RELA) { + if (type == DynamicEntry::TAG::RELA) { nb_symbols = std::max(nb_symbols, max_relocation_index(*res, size)); } else { nb_symbols = std::max(nb_symbols, max_relocation_index(*res, size)); @@ -591,7 +591,7 @@ template result Parser::nb_dynsym_section() const { using Elf_Sym = typename ELF_T::Elf_Sym; using Elf_Off = typename ELF_T::Elf_Off; - Section* dynsym_sec = binary_->get(ELF_SECTION_TYPES::SHT_DYNSYM); + Section* dynsym_sec = binary_->get(Section::TYPE::DYNSYM); if (dynsym_sec == nullptr) { return 0; @@ -605,11 +605,11 @@ result Parser::nb_dynsym_section() const { template result Parser::nb_dynsym_hash() const { - if (binary_->has(DYNAMIC_TAGS::DT_HASH)) { + if (binary_->has(DynamicEntry::TAG::HASH)) { return nb_dynsym_sysv_hash(); } - if (binary_->has(DYNAMIC_TAGS::DT_GNU_HASH)) { + if (binary_->has(DynamicEntry::TAG::GNU_HASH)) { return nb_dynsym_gnu_hash(); } @@ -621,7 +621,7 @@ template result Parser::nb_dynsym_sysv_hash() const { using Elf_Off = typename ELF_T::Elf_Off; - const DynamicEntry* dyn_hash = binary_->get(DYNAMIC_TAGS::DT_HASH); + const DynamicEntry* dyn_hash = binary_->get(DynamicEntry::TAG::HASH); if (dyn_hash == nullptr) { LIEF_ERR("Can't find DT_GNU_HASH"); return make_error_code(lief_errors::not_found); @@ -648,7 +648,7 @@ result Parser::nb_dynsym_gnu_hash() const { using uint__ = typename ELF_T::uint; using Elf_Off = typename ELF_T::Elf_Off; - const DynamicEntry* dyn_hash = binary_->get(DYNAMIC_TAGS::DT_GNU_HASH); + const DynamicEntry* dyn_hash = binary_->get(DynamicEntry::TAG::GNU_HASH); if (dyn_hash == nullptr) { LIEF_ERR("Can't find DT_GNU_HASH"); return make_error_code(lief_errors::not_found); @@ -742,6 +742,7 @@ ok_error_t Parser::parse_sections() { stream_->setpos(shdr_offset); std::unordered_map sections_names; DataHandler::Handler& handler = *binary_->datahandler_; + const ARCH arch = binary_->header().machine_type(); for (size_t i = 0; i < numberof_sections; ++i) { LIEF_DEBUG(" Elf_Shdr#{:02d}.offset: 0x{:x} ", i, stream_->pos()); const auto shdr = stream_->read_conv(); @@ -750,7 +751,7 @@ ok_error_t Parser::parse_sections() { break; } - auto section = std::make_unique
(*shdr); + auto section = std::unique_ptr
(new Section(*shdr, arch)); section->datahandler_ = binary_->datahandler_.get(); const uint64_t section_start = section->file_offset(); @@ -758,7 +759,7 @@ ok_error_t Parser::parse_sections() { bool access_content = true; if (section_start > stream_->size() || section_end > stream_->size()) { access_content = false; - if (section->type() != ELF_SECTION_TYPES::SHT_NOBITS) { + if (section->type() != Section::TYPE::NOBITS) { LIEF_WARN("Can't access the content of section #{}", i); } } @@ -773,13 +774,13 @@ ok_error_t Parser::parse_sections() { int64_t read_size = section->size(); if (static_cast(read_size) < 0 ) { LIEF_WARN("Section #{} is {} bytes large. Only the first {} bytes will be taken into account", - i, read_size, Parser::MAX_SECTION_SIZE); - read_size = Parser::MAX_SECTION_SIZE; + i, read_size, Section::MAX_SECTION_SIZE); + read_size = Section::MAX_SECTION_SIZE; } - if (read_size > Parser::MAX_SECTION_SIZE) { + if (read_size > Section::MAX_SECTION_SIZE) { LIEF_WARN("Section #{} is {} bytes large. Only the first {} bytes will be taken into account", - i, read_size, Parser::MAX_SECTION_SIZE); - read_size = Parser::MAX_SECTION_SIZE; + i, read_size, Section::MAX_SECTION_SIZE); + read_size = Section::MAX_SECTION_SIZE; } handler.create(section->file_offset(), read_size, @@ -800,7 +801,7 @@ ok_error_t Parser::parse_sections() { if (stream_->type() != BinaryStream::STREAM_TYPE::ELF_DATA_HANDLER) { std::vector sec_content; if (!stream_->peek_data(sec_content, offset_to_content, read_size)) { - if (section->type() != ELF_SECTION_TYPES::SHT_NOBITS) { + if (section->type() != Section::TYPE::NOBITS) { LIEF_WARN(" Unable to get content of section #{:d}", i); } } else { @@ -851,6 +852,8 @@ ok_error_t Parser::parse_segments() { stream_->setpos(segment_headers_offset); + const ARCH arch = binary_->header().machine_type(); + for (size_t i = 0; i < nbof_segments; ++i) { const auto elf_phdr = stream_->read_conv(); if (!elf_phdr) { @@ -858,7 +861,7 @@ ok_error_t Parser::parse_segments() { break; } - auto segment = std::make_unique(*elf_phdr); + auto segment = std::unique_ptr(new Segment(*elf_phdr, arch)); segment->datahandler_ = binary_->datahandler_.get(); if (0 < segment->physical_size() && segment->physical_size() < Parser::MAX_SEGMENT_SIZE) { @@ -903,7 +906,7 @@ ok_error_t Parser::parse_segments() { } } - if (segment->type() == SEGMENT_TYPES::PT_INTERP) { + if (segment->is_interpreter()) { auto interpreter = stream_->peek_string_at(offset_to_content, read_size); if (!interpreter) { LIEF_ERR("Can't read the interpreter string"); @@ -956,9 +959,8 @@ ok_error_t Parser::parse_dynamic_relocations(uint64_t relocations_offset, uint64 if (!raw_reloc) { break; } - auto reloc = std::make_unique(std::move(*raw_reloc)); - reloc->purpose(RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC); - reloc->architecture_ = arch; + auto reloc = std::make_unique( + std::move(*raw_reloc), Relocation::PURPOSE::DYNAMIC, arch); const auto idx = static_cast(raw_reloc->r_info >> shift); if (config_.parse_dyn_symbols) { @@ -974,8 +976,6 @@ ok_error_t Parser::parse_dynamic_relocations(uint64_t relocations_offset, uint64 return ok(); } // build_dynamic_reclocations - - template ok_error_t Parser::parse_static_symbols(uint64_t offset, uint32_t nb_symbols, const Section& string_section) { @@ -987,13 +987,13 @@ ok_error_t Parser::parse_static_symbols(uint64_t offset, uint32_t nb_symbols, binary_->static_symbols_.reserve(nb_reserved); stream_->setpos(offset); + const ARCH arch = binary_->header().machine_type(); for (uint32_t i = 0; i < nb_symbols; ++i) { const auto raw_sym = stream_->read_conv(); if (!raw_sym) { break; } - auto symbol = std::make_unique(std::move(*raw_sym), - binary_->header().machine_type()); + auto symbol = std::unique_ptr(new Symbol(std::move(*raw_sym), arch)); const auto name_offset = string_section.file_offset() + raw_sym->st_name; auto symbol_name = stream_->peek_string_at(name_offset); @@ -1047,8 +1047,8 @@ ok_error_t Parser::parse_dynamic_symbols(uint64_t offset) { LIEF_DEBUG("Break on symbol #{:d}", i); break; } - auto symbol = std::make_unique(std::move(*symbol_header), - binary_->header().machine_type()); + auto symbol = std::unique_ptr(new Symbol(std::move(*symbol_header), + binary_->header().machine_type())); if (symbol_header->st_name > 0) { auto name = stream_->peek_string_at(string_offset + symbol_header->st_name); @@ -1066,7 +1066,7 @@ ok_error_t Parser::parse_dynamic_symbols(uint64_t offset) { binary_->dynamic_symbols_.push_back(std::move(symbol)); } binary_->sizing_info_->dynsym = binary_->dynamic_symbols_.size() * sizeof(Elf_Sym); - if (const auto* dt_strsz = binary_->get(DYNAMIC_TAGS::DT_STRSZ)) { + if (const auto* dt_strsz = binary_->get(DynamicEntry::TAG::STRSZ)) { binary_->sizing_info_->dynstr = dt_strsz->value(); } return ok(); @@ -1100,10 +1100,12 @@ ok_error_t Parser::parse_dynamic_entries(uint64_t offset, uint64_t size) { std::unique_ptr dynamic_entry; - switch (static_cast(entry.d_tag)) { - case DYNAMIC_TAGS::DT_NEEDED : + const ARCH arch = binary_->header().machine_type(); + + switch (DynamicEntry::from_value(entry.d_tag, arch)) { + case DynamicEntry::TAG::NEEDED : { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); auto library_name = stream_->peek_string_at(dynamic_string_offset + dynamic_entry->value()); if (!library_name) { LIEF_ERR("Can't read library name for DT_NEEDED entry"); @@ -1113,9 +1115,9 @@ ok_error_t Parser::parse_dynamic_entries(uint64_t offset, uint64_t size) { break; } - case DYNAMIC_TAGS::DT_SONAME : + case DynamicEntry::TAG::SONAME : { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); auto sharename = stream_->peek_string_at(dynamic_string_offset + dynamic_entry->value()); if (!sharename) { LIEF_ERR("Can't read library name for DT_SONAME entry"); @@ -1125,74 +1127,74 @@ ok_error_t Parser::parse_dynamic_entries(uint64_t offset, uint64_t size) { break; } - case DYNAMIC_TAGS::DT_RPATH: + case DynamicEntry::TAG::RPATH: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); auto name = stream_->peek_string_at(dynamic_string_offset + dynamic_entry->value()); if (!name) { LIEF_ERR("Can't read rpath string value for DT_RPATH"); break; } - dynamic_entry->as()->name(std::move(*name)); + dynamic_entry->as()->rpath(std::move(*name)); break; } - case DYNAMIC_TAGS::DT_RUNPATH: + case DynamicEntry::TAG::RUNPATH: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); auto name = stream_->peek_string_at(dynamic_string_offset + dynamic_entry->value()); if (!name) { LIEF_ERR("Can't read runpath string value for DT_RUNPATH"); break; } - dynamic_entry->as()->name(std::move(*name)); + dynamic_entry->as()->runpath(std::move(*name)); break; } - case DYNAMIC_TAGS::DT_FLAGS_1: - case DYNAMIC_TAGS::DT_FLAGS: + case DynamicEntry::TAG::FLAGS_1: + case DynamicEntry::TAG::FLAGS: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); break; } - case DYNAMIC_TAGS::DT_SYMTAB: - case DYNAMIC_TAGS::DT_SYMENT: - case DYNAMIC_TAGS::DT_RELA: - case DYNAMIC_TAGS::DT_RELASZ: - case DYNAMIC_TAGS::DT_REL: - case DYNAMIC_TAGS::DT_RELSZ: - case DYNAMIC_TAGS::DT_JMPREL: - case DYNAMIC_TAGS::DT_PLTRELSZ: - case DYNAMIC_TAGS::DT_PLTREL: - case DYNAMIC_TAGS::DT_VERSYM: - case DYNAMIC_TAGS::DT_VERNEED: - case DYNAMIC_TAGS::DT_VERNEEDNUM: - case DYNAMIC_TAGS::DT_VERDEF: - case DYNAMIC_TAGS::DT_VERDEFNUM: + case DynamicEntry::TAG::SYMTAB: + case DynamicEntry::TAG::SYMENT: + case DynamicEntry::TAG::RELA: + case DynamicEntry::TAG::RELASZ: + case DynamicEntry::TAG::REL: + case DynamicEntry::TAG::RELSZ: + case DynamicEntry::TAG::JMPREL: + case DynamicEntry::TAG::PLTRELSZ: + case DynamicEntry::TAG::PLTREL: + case DynamicEntry::TAG::VERSYM: + case DynamicEntry::TAG::VERNEED: + case DynamicEntry::TAG::VERNEEDNUM: + case DynamicEntry::TAG::VERDEF: + case DynamicEntry::TAG::VERDEFNUM: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); break; } - case DYNAMIC_TAGS::DT_FINI_ARRAY: - case DYNAMIC_TAGS::DT_INIT_ARRAY: - case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + case DynamicEntry::TAG::FINI_ARRAY: + case DynamicEntry::TAG::INIT_ARRAY: + case DynamicEntry::TAG::PREINIT_ARRAY: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); break; } - case DYNAMIC_TAGS::DT_NULL: + case DynamicEntry::TAG::DT_NULL: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); end_of_dynamic = true; break; } default: { - dynamic_entry = std::make_unique(entry); + dynamic_entry = std::make_unique(entry, arch); } } @@ -1209,8 +1211,8 @@ ok_error_t Parser::parse_dynamic_entries(uint64_t offset, uint64_t size) { // Check for INIT array // ==================== - if (DynamicEntry* dt_init_array = binary_->get(DYNAMIC_TAGS::DT_INIT_ARRAY)) { - if (DynamicEntry* dt_init_arraysz = binary_->get(DYNAMIC_TAGS::DT_INIT_ARRAYSZ)) { + if (DynamicEntry* dt_init_array = binary_->get(DynamicEntry::TAG::INIT_ARRAY)) { + if (DynamicEntry* dt_init_arraysz = binary_->get(DynamicEntry::TAG::INIT_ARRAYSZ)) { binary_->sizing_info_->init_array = dt_init_arraysz->value(); std::vector& array = dt_init_array->as()->array(); const auto nb_functions = static_cast(dt_init_arraysz->value() / sizeof(uint__)); @@ -1232,8 +1234,8 @@ ok_error_t Parser::parse_dynamic_entries(uint64_t offset, uint64_t size) { // Check for FINI array // ==================== - if (DynamicEntry* dt_fini_array = binary_->get(DYNAMIC_TAGS::DT_FINI_ARRAY)) { - if (DynamicEntry* dt_fini_arraysz = binary_->get(DYNAMIC_TAGS::DT_FINI_ARRAYSZ)) { + if (DynamicEntry* dt_fini_array = binary_->get(DynamicEntry::TAG::FINI_ARRAY)) { + if (DynamicEntry* dt_fini_arraysz = binary_->get(DynamicEntry::TAG::FINI_ARRAYSZ)) { binary_->sizing_info_->fini_array = dt_fini_arraysz->value(); std::vector& array = dt_fini_array->as()->array(); @@ -1256,8 +1258,8 @@ ok_error_t Parser::parse_dynamic_entries(uint64_t offset, uint64_t size) { // Check for PREINIT array // ======================= - if (DynamicEntry* dt_preini_array = binary_->get(DYNAMIC_TAGS::DT_PREINIT_ARRAY)) { - if (DynamicEntry* dt_preinit_arraysz = binary_->get(DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ)) { + if (DynamicEntry* dt_preini_array = binary_->get(DynamicEntry::TAG::PREINIT_ARRAY)) { + if (DynamicEntry* dt_preinit_arraysz = binary_->get(DynamicEntry::TAG::PREINIT_ARRAYSZ)) { binary_->sizing_info_->preinit_array = dt_preinit_arraysz->value(); std::vector& array = dt_preini_array->as()->array(); @@ -1306,9 +1308,9 @@ ok_error_t Parser::parse_pltgot_relocations(uint64_t offset, uint64_t size) { if (!rel_hdr) { break; } - auto reloc = std::make_unique(*rel_hdr); - reloc->architecture_ = arch; - reloc->purpose(RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT); + + auto reloc = std::make_unique( + std::move(*rel_hdr), Relocation::PURPOSE::PLTGOT, arch); const auto idx = static_cast(rel_hdr->r_info >> shift); if (config_.parse_dyn_symbols && @@ -1395,24 +1397,24 @@ ok_error_t Parser::parse_section_relocations(const Section& section) { break; } - auto reloc = std::make_unique(*rel_hdr); - reloc->architecture_ = binary_->header_.machine_type(); + auto reloc = std::make_unique( + *rel_hdr, Relocation::PURPOSE::NONE, binary_->header_.machine_type()); reloc->section_ = applies_to; reloc->symbol_table_ = symbol_table; - if (binary_->header().file_type() == ELF::E_TYPE::ET_REL && + if (binary_->header().file_type() == Header::FILE_TYPE::REL && binary_->segments().size() == 0) { - reloc->purpose(RELOCATION_PURPOSES::RELOC_PURPOSE_OBJECT); + reloc->purpose(Relocation::PURPOSE::OBJECT); } const auto idx = static_cast(rel_hdr->r_info >> shift); const bool is_from_dynsym = idx > 0 && idx < binary_->dynamic_symbols_.size() && (symbol_table == nullptr || - symbol_table->type() == ELF_SECTION_TYPES::SHT_DYNSYM); + symbol_table->type() == Section::TYPE::DYNSYM); const bool is_from_symtab = idx < binary_->static_symbols_.size() && (symbol_table == nullptr || - symbol_table->type() == ELF_SECTION_TYPES::SHT_SYMTAB); + symbol_table->type() == Section::TYPE::SYMTAB); if (is_from_dynsym) { reloc->symbol_ = binary_->dynamic_symbols_[idx].get(); } else if (is_from_symtab) { @@ -1426,7 +1428,6 @@ ok_error_t Parser::parse_section_relocations(const Section& section) { return ok(); } - template ok_error_t Parser::parse_symbol_version_requirement(uint64_t offset, uint32_t nb_entries) { using Elf_Verneed = typename ELF_T::Elf_Verneed; diff --git a/src/ELF/ProcessorFlags.cpp b/src/ELF/ProcessorFlags.cpp new file mode 100644 index 0000000000..0eb9bf32ba --- /dev/null +++ b/src/ELF/ProcessorFlags.cpp @@ -0,0 +1,95 @@ +/* Copyright 2017 - 2023 R. Thomas + * Copyright 2017 - 2023 Quarkslab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "LIEF/ELF/ProcessorFlags.hpp" +#include "frozen.hpp" + +namespace LIEF { +namespace ELF { +const char* to_string(PROCESSOR_FLAGS flag) { + #define ENTRY(X) std::pair(PROCESSOR_FLAGS::X, #X) + STRING_MAP enums2str { + ENTRY(ARM_EABI_UNKNOWN), + ENTRY(ARM_SOFT_FLOAT), + ENTRY(ARM_VFP_FLOAT), + ENTRY(ARM_EABI_VER1), + ENTRY(ARM_EABI_VER2), + ENTRY(ARM_EABI_VER3), + ENTRY(ARM_EABI_VER4), + ENTRY(ARM_EABI_VER5), + ENTRY(HEXAGON_MACH_V2), + ENTRY(HEXAGON_MACH_V3), + ENTRY(HEXAGON_MACH_V4), + ENTRY(HEXAGON_MACH_V5), + ENTRY(HEXAGON_ISA_V2), + ENTRY(HEXAGON_ISA_V3), + ENTRY(HEXAGON_ISA_V4), + ENTRY(HEXAGON_ISA_V5), + ENTRY(LOONGARCH_ABI_SOFT_FLOAT), + ENTRY(LOONGARCH_ABI_SINGLE_FLOAT), + ENTRY(LOONGARCH_ABI_DOUBLE_FLOAT), + ENTRY(MIPS_NOREORDER), + ENTRY(MIPS_PIC), + ENTRY(MIPS_CPIC), + ENTRY(MIPS_ABI2), + ENTRY(MIPS_32BITMODE), + ENTRY(MIPS_FP64), + ENTRY(MIPS_NAN2008), + ENTRY(MIPS_ABI_O32), + ENTRY(MIPS_ABI_O64), + ENTRY(MIPS_ABI_EABI32), + ENTRY(MIPS_ABI_EABI64), + ENTRY(MIPS_MACH_3900), + ENTRY(MIPS_MACH_4010), + ENTRY(MIPS_MACH_4100), + ENTRY(MIPS_MACH_4650), + ENTRY(MIPS_MACH_4120), + ENTRY(MIPS_MACH_4111), + ENTRY(MIPS_MACH_SB1), + ENTRY(MIPS_MACH_OCTEON), + ENTRY(MIPS_MACH_XLR), + ENTRY(MIPS_MACH_OCTEON2), + ENTRY(MIPS_MACH_OCTEON3), + ENTRY(MIPS_MACH_5400), + ENTRY(MIPS_MACH_5900), + ENTRY(MIPS_MACH_5500), + ENTRY(MIPS_MACH_9000), + ENTRY(MIPS_MACH_LS2E), + ENTRY(MIPS_MACH_LS2F), + ENTRY(MIPS_MACH_LS3A), + ENTRY(MIPS_MICROMIPS), + ENTRY(MIPS_ARCH_ASE_M16), + ENTRY(MIPS_ARCH_ASE_MDMX), + ENTRY(MIPS_ARCH_1), + ENTRY(MIPS_ARCH_2), + ENTRY(MIPS_ARCH_3), + ENTRY(MIPS_ARCH_4), + ENTRY(MIPS_ARCH_5), + ENTRY(MIPS_ARCH_32), + ENTRY(MIPS_ARCH_64), + ENTRY(MIPS_ARCH_32R2), + ENTRY(MIPS_ARCH_64R2), + ENTRY(MIPS_ARCH_32R6), + ENTRY(MIPS_ARCH_64R6), + }; + #undef ENTRY + + if (auto it = enums2str.find(flag); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} +} +} diff --git a/src/ELF/Relocation.cpp b/src/ELF/Relocation.cpp index 20b5ebd916..24b5cee460 100644 --- a/src/ELF/Relocation.cpp +++ b/src/ELF/Relocation.cpp @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include - #include "LIEF/ELF/hash.hpp" #include "LIEF/ELF/Relocation.hpp" #include "LIEF/ELF/EnumToString.hpp" #include "LIEF/ELF/Symbol.hpp" -#include "LIEF/ELF/RelocationSizes.hpp" #include "ELF/Structures.hpp" #include "logging.hpp" @@ -29,8 +26,36 @@ namespace LIEF { namespace ELF { -Relocation::~Relocation() = default; -Relocation::Relocation() = default; +int32_t get_reloc_size(Relocation::TYPE type); + +Relocation::TYPE Relocation::type_from(uint32_t value, ARCH arch) { + switch (arch) { + case ARCH::X86_64: + return TYPE(value | R_X64); + case ARCH::I386: + return TYPE(value | R_X86); + case ARCH::ARM: + return TYPE(value | R_ARM); + case ARCH::HEXAGON: + return TYPE(value | R_HEXAGON); + case ARCH::LOONGARCH: + return TYPE(value | R_LARCH); + case ARCH::MIPS: + return TYPE(value | R_MIPS); + case ARCH::PPC: + return TYPE(value | R_PPC); + case ARCH::PPC64: + return TYPE(value | R_PPC64); + case ARCH::SPARC: + return TYPE(value | R_SPARC); + default: + { + LIEF_ERR("LIEF does not support relocation for '{}'", to_string(arch)); + return TYPE::UNKNOWN; + } + } + return TYPE::UNKNOWN; +} Relocation::Relocation(const Relocation& other) : LIEF::Relocation{other}, @@ -40,56 +65,84 @@ Relocation::Relocation(const Relocation& other) : architecture_{other.architecture_} {} - -Relocation::Relocation(ARCH arch) { - architecture_ = arch; -} - - Relocation& Relocation::operator=(Relocation other) { swap(other); return *this; } -Relocation::Relocation(const details::Elf32_Rel& header) : +template +Relocation::Relocation(const T& header, PURPOSE purpose, ARCH arch) : LIEF::Relocation{header.r_offset, 0}, - type_{static_cast(header.r_info & 0xff)}, - info_{static_cast(header.r_info >> 8)} -{} - - -Relocation::Relocation(const details::Elf32_Rela& header) : - LIEF::Relocation{header.r_offset, 0}, - type_{static_cast(header.r_info & 0xff)}, - addend_{header.r_addend}, - isRela_{true}, - info_{static_cast(header.r_info >> 8)} -{} - - -Relocation::Relocation(const details::Elf64_Rel& header) : - LIEF::Relocation{header.r_offset, 0}, - type_{static_cast(header.r_info & 0xffffffff)}, - info_{static_cast(header.r_info >> 32)} -{} - + architecture_{arch}, + purpose_{purpose} +{ + if constexpr (std::is_same_v || + std::is_same_v) + { + type_ = type_from(header.r_info & 0xff, arch); + info_ = static_cast(header.r_info >> 8); + } -Relocation::Relocation(const details::Elf64_Rela& header) : - LIEF::Relocation{header.r_offset, 0}, - type_{static_cast(header.r_info & 0xffffffff)}, - addend_{header.r_addend}, - isRela_{true}, - info_{static_cast(header.r_info >> 32)} -{} + if constexpr (std::is_same_v || + std::is_same_v) + { + type_ = type_from(header.r_info & 0xffffffff, arch); + info_ = static_cast(header.r_info >> 32); + } + if constexpr (std::is_same_v || + std::is_same_v) + { + isRela_ = true; + addend_ = header.r_addend; + } +} -Relocation::Relocation(uint64_t address, uint32_t type, int64_t addend, bool isRela) : - LIEF::Relocation{address, 0}, - type_{type}, - addend_{addend}, - isRela_{isRela} -{} +Relocation::Relocation(uint64_t address, TYPE type, bool is_rela) : + LIEF::Relocation(address, 0), + type_(type), + isRela_(is_rela) +{ + if (type != TYPE::UNKNOWN) { + auto raw_type = static_cast(type); + const uint64_t ID = (raw_type >> Relocation::R_BIT) << Relocation::R_BIT; + if (ID == Relocation::R_X64) { + architecture_ = ARCH::X86_64; + } + else if (ID == Relocation::R_AARCH64) { + architecture_ = ARCH::AARCH64; + } + else if (ID == Relocation::R_ARM) { + architecture_ = ARCH::ARM; + } + else if (ID == Relocation::R_HEXAGON) { + architecture_ = ARCH::HEXAGON; + } + else if (ID == Relocation::R_X86) { + architecture_ = ARCH::I386; + } + else if (ID == Relocation::R_LARCH) { + architecture_ = ARCH::LOONGARCH; + } + else if (ID == Relocation::R_MIPS) { + architecture_ = ARCH::MIPS; + } + else if (ID == Relocation::R_PPC) { + architecture_ = ARCH::PPC; + } + else if (ID == Relocation::R_PPC64) { + architecture_ = ARCH::PPC64; + } + else if (ID == Relocation::R_SPARC) { + architecture_ = ARCH::SPARC; + } + } +} +template Relocation::Relocation(const details::Elf32_Rel&, PURPOSE, ARCH); +template Relocation::Relocation(const details::Elf32_Rela&, PURPOSE, ARCH); +template Relocation::Relocation(const details::Elf64_Rel&, PURPOSE, ARCH); +template Relocation::Relocation(const details::Elf64_Rela&, PURPOSE, ARCH); void Relocation::swap(Relocation& other) { std::swap(address_, other.address_); @@ -103,287 +156,27 @@ void Relocation::swap(Relocation& other) { std::swap(info_, other.info_); } -int64_t Relocation::addend() const { - return addend_; -} - - -uint32_t Relocation::type() const { - return type_; -} - - -const Symbol* Relocation::symbol() const { - return symbol_; -} - -Symbol* Relocation::symbol() { - return const_cast(static_cast(this)->symbol()); -} - -const Section* Relocation::section() const { - return section_; -} - -Section* Relocation::section() { - return const_cast(static_cast(this)->section()); -} - -const Section* Relocation::symbol_table() const { - return symbol_table_; -} - -Section* Relocation::symbol_table() { - return const_cast(static_cast(this)->symbol_table()); -} - -bool Relocation::is_rela() const { - return isRela_; -} - - -bool Relocation::is_rel() const { - return !isRela_; -} - - -ARCH Relocation::architecture() const { - return architecture_; -} - - -RELOCATION_PURPOSES Relocation::purpose() const { - return purpose_; -} - - -bool Relocation::has_symbol() const { - return symbol_ != nullptr; -} - -bool Relocation::has_section() const { - return section_ != nullptr; -} - -uint32_t Relocation::info() const { - return info_; -} - size_t Relocation::size() const { - - switch (architecture()) { - case ARCH::EM_X86_64: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - case ARCH::EM_386: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - case ARCH::EM_ARM: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - case ARCH::EM_AARCH64: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - case ARCH::EM_MIPS: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - - case ARCH::EM_PPC: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - case ARCH::EM_PPC64: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - case ARCH::EM_LOONGARCH: - { - const auto rtype = static_cast(type()); - const int32_t size = get_reloc_size(rtype); - if (size < 0) { - LIEF_ERR("{} - {}", to_string(architecture()), to_string(rtype)); - return SIZE_MAX; - } - return size; - } - - default: - { - LIEF_ERR("Architecture {} not implemented", to_string(architecture())); - return SIZE_MAX; - } - } - -} - - -void Relocation::addend(int64_t addend) { - addend_ = addend; -} - - -void Relocation::type(uint32_t type) { - type_ = type; -} - -void Relocation::info(uint32_t v) { - info_ = v; -} - -void Relocation::symbol(Symbol* sym) { - symbol_ = sym; -} - -void Relocation::section(Section* section) { - section_ = section; -} - - -void Relocation::purpose(RELOCATION_PURPOSES purpose) { - purpose_ = purpose; + return get_reloc_size(type_); } void Relocation::accept(Visitor& visitor) const { visitor.visit(*this); } - - - - std::ostream& operator<<(std::ostream& os, const Relocation& entry) { std::string symbol_name; - os << std::hex; - os << std::left; - const Symbol* symbol = entry.symbol(); - if (symbol != nullptr) { + if (const Symbol* symbol = entry.symbol()) { symbol_name = symbol->demangled_name(); if (symbol_name.empty()) { symbol_name = symbol->name(); } } - std::string relocation_type; - switch (entry.architecture()) { - case ARCH::EM_X86_64: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_386: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_ARM: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_AARCH64: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_MIPS: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_PPC: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_PPC64: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - case ARCH::EM_LOONGARCH: - { - relocation_type = to_string(static_cast(entry.type())); - break; - } - - default: - { - relocation_type = std::to_string(entry.type()); - } - } - - - - os << std::setw(10) << entry.address() - << std::setw(10) << relocation_type - << std::setw(4) << std::dec << entry.size() - << std::setw(10) << std::hex << entry.addend() - << std::setw(10) << std::hex << entry.info() - << std::setw(10) << to_string(entry.purpose()) - << std::setw(10) << symbol_name; - + os << fmt::format("0x{:06x} {} ({}) 0x{:04x} 0x{:02x} {}", + entry.address(), to_string(entry.type()), + entry.size(), entry.addend(), entry.info(), symbol_name); return os; } } diff --git a/src/ELF/RelocationSizes.cpp b/src/ELF/RelocationSizes.cpp index d017fcc18d..c9763cb0ae 100644 --- a/src/ELF/RelocationSizes.cpp +++ b/src/ELF/RelocationSizes.cpp @@ -14,380 +14,381 @@ * limitations under the License. */ -#include "LIEF/ELF/RelocationSizes.hpp" +#include "LIEF/ELF/Relocation.hpp" #include "frozen.hpp" namespace LIEF { namespace ELF { -int32_t get_reloc_size(RELOC_x86_64 R) { - CONST_MAP(RELOC_x86_64, uint32_t, 43) SIZES { - {RELOC_x86_64::R_X86_64_NONE, 0 }, - {RELOC_x86_64::R_X86_64_64, 64 }, - {RELOC_x86_64::R_X86_64_PC32, 32 }, - {RELOC_x86_64::R_X86_64_GOT32, 32 }, - {RELOC_x86_64::R_X86_64_PLT32, 32 }, - {RELOC_x86_64::R_X86_64_COPY, 32 }, - {RELOC_x86_64::R_X86_64_GLOB_DAT, 64 }, - {RELOC_x86_64::R_X86_64_JUMP_SLOT, 64 }, - {RELOC_x86_64::R_X86_64_RELATIVE, 64 }, - {RELOC_x86_64::R_X86_64_GOTPCREL, 32 }, - {RELOC_x86_64::R_X86_64_32, 32 }, - {RELOC_x86_64::R_X86_64_32S, 32 }, - {RELOC_x86_64::R_X86_64_16, 16 }, - {RELOC_x86_64::R_X86_64_PC16, 16 }, - {RELOC_x86_64::R_X86_64_8, 8 }, - {RELOC_x86_64::R_X86_64_PC8, 8 }, - {RELOC_x86_64::R_X86_64_DTPMOD64, 64 }, - {RELOC_x86_64::R_X86_64_DTPOFF64, 64 }, - {RELOC_x86_64::R_X86_64_TPOFF64, 64 }, - {RELOC_x86_64::R_X86_64_TLSGD, 32 }, - {RELOC_x86_64::R_X86_64_TLSLD, 32 }, - {RELOC_x86_64::R_X86_64_DTPOFF32, 32 }, - {RELOC_x86_64::R_X86_64_GOTTPOFF, 32 }, - {RELOC_x86_64::R_X86_64_TPOFF32, 32 }, - {RELOC_x86_64::R_X86_64_PC64, 64 }, - {RELOC_x86_64::R_X86_64_GOTOFF64, 64 }, - {RELOC_x86_64::R_X86_64_GOTPC32, 32 }, - {RELOC_x86_64::R_X86_64_GOT64, 64 }, - {RELOC_x86_64::R_X86_64_GOTPCREL64, 64 }, - {RELOC_x86_64::R_X86_64_GOTPC64, 64 }, - {RELOC_x86_64::R_X86_64_GOTPLT64, 64 }, - {RELOC_x86_64::R_X86_64_PLTOFF64, 64 }, - {RELOC_x86_64::R_X86_64_SIZE32, 32 }, - {RELOC_x86_64::R_X86_64_SIZE64, 64 }, - {RELOC_x86_64::R_X86_64_GOTPC32_TLSDESC, 32 }, - {RELOC_x86_64::R_X86_64_TLSDESC_CALL, 0 }, - {RELOC_x86_64::R_X86_64_TLSDESC, 64 }, - {RELOC_x86_64::R_X86_64_IRELATIVE, 64 }, - {RELOC_x86_64::R_X86_64_RELATIVE64, 64 }, - {RELOC_x86_64::R_X86_64_PC32_BND, 32 }, - {RELOC_x86_64::R_X86_64_PLT32_BND, 32 }, - {RELOC_x86_64::R_X86_64_GOTPCRELX, 32 }, - {RELOC_x86_64::R_X86_64_REX_GOTPCRELX, 32 }, + +int32_t get_R_X64(Relocation::TYPE type) { + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::X86_64_NONE, 0), + std::pair(Relocation::TYPE::X86_64_64, 64), + std::pair(Relocation::TYPE::X86_64_PC32, 32), + std::pair(Relocation::TYPE::X86_64_GOT32, 32), + std::pair(Relocation::TYPE::X86_64_PLT32, 32), + std::pair(Relocation::TYPE::X86_64_COPY, 32), + std::pair(Relocation::TYPE::X86_64_GLOB_DAT, 64), + std::pair(Relocation::TYPE::X86_64_JUMP_SLOT, 64), + std::pair(Relocation::TYPE::X86_64_RELATIVE, 64), + std::pair(Relocation::TYPE::X86_64_GOTPCREL, 32), + std::pair(Relocation::TYPE::X86_64_32, 32), + std::pair(Relocation::TYPE::X86_64_32S, 32), + std::pair(Relocation::TYPE::X86_64_16, 16), + std::pair(Relocation::TYPE::X86_64_PC16, 16), + std::pair(Relocation::TYPE::X86_64_8, 8), + std::pair(Relocation::TYPE::X86_64_PC8, 8), + std::pair(Relocation::TYPE::X86_64_DTPMOD64, 64), + std::pair(Relocation::TYPE::X86_64_DTPOFF64, 64), + std::pair(Relocation::TYPE::X86_64_TPOFF64, 64), + std::pair(Relocation::TYPE::X86_64_TLSGD, 32), + std::pair(Relocation::TYPE::X86_64_TLSLD, 32), + std::pair(Relocation::TYPE::X86_64_DTPOFF32, 32), + std::pair(Relocation::TYPE::X86_64_GOTTPOFF, 32), + std::pair(Relocation::TYPE::X86_64_TPOFF32, 32), + std::pair(Relocation::TYPE::X86_64_PC64, 64), + std::pair(Relocation::TYPE::X86_64_GOTOFF64, 64), + std::pair(Relocation::TYPE::X86_64_GOTPC32, 32), + std::pair(Relocation::TYPE::X86_64_GOT64, 64), + std::pair(Relocation::TYPE::X86_64_GOTPCREL64, 64), + std::pair(Relocation::TYPE::X86_64_GOTPC64, 64), + std::pair(Relocation::TYPE::X86_64_GOTPLT64, 64), + std::pair(Relocation::TYPE::X86_64_PLTOFF64, 64), + std::pair(Relocation::TYPE::X86_64_SIZE32, 32), + std::pair(Relocation::TYPE::X86_64_SIZE64, 64), + std::pair(Relocation::TYPE::X86_64_GOTPC32_TLSDESC, 32), + std::pair(Relocation::TYPE::X86_64_TLSDESC_CALL, 0), + std::pair(Relocation::TYPE::X86_64_TLSDESC, 64), + std::pair(Relocation::TYPE::X86_64_IRELATIVE, 64), + std::pair(Relocation::TYPE::X86_64_RELATIVE64, 64), + std::pair(Relocation::TYPE::X86_64_PC32_BND, 32), + std::pair(Relocation::TYPE::X86_64_PLT32_BND, 32), + std::pair(Relocation::TYPE::X86_64_GOTPCRELX, 32), + std::pair(Relocation::TYPE::X86_64_REX_GOTPCRELX, 32), }; - const auto it = SIZES.find(R); + const auto it = SIZES.find(type); return it == SIZES.end() ? -1 : it->second; } -int32_t get_reloc_size(RELOC_i386 R) { - CONST_MAP(RELOC_i386, uint32_t, 40) SIZES { - {RELOC_i386::R_386_NONE, 0 }, - {RELOC_i386::R_386_32, 32 }, - {RELOC_i386::R_386_PC32, 32 }, - {RELOC_i386::R_386_GOT32, 32 }, - {RELOC_i386::R_386_PLT32, 32 }, - {RELOC_i386::R_386_COPY, 32 }, - {RELOC_i386::R_386_GLOB_DAT, 32 }, - {RELOC_i386::R_386_JUMP_SLOT, 32 }, - {RELOC_i386::R_386_RELATIVE, 32 }, - {RELOC_i386::R_386_GOTOFF, 32 }, - {RELOC_i386::R_386_GOTPC, 32 }, - {RELOC_i386::R_386_32PLT, 32 }, - {RELOC_i386::R_386_TLS_TPOFF, 32 }, - {RELOC_i386::R_386_TLS_IE, 32 }, - {RELOC_i386::R_386_TLS_GOTIE, 32 }, - {RELOC_i386::R_386_TLS_LE, 32 }, - {RELOC_i386::R_386_TLS_GD, 32 }, - {RELOC_i386::R_386_TLS_LDM, 32 }, - {RELOC_i386::R_386_16, 16 }, - {RELOC_i386::R_386_PC16, 16 }, - {RELOC_i386::R_386_8, 8 }, - {RELOC_i386::R_386_PC8, 8 }, - {RELOC_i386::R_386_TLS_GD_32, 32 }, - {RELOC_i386::R_386_TLS_GD_PUSH, 32 }, - {RELOC_i386::R_386_TLS_GD_CALL, 32 }, - {RELOC_i386::R_386_TLS_GD_POP, 32 }, - {RELOC_i386::R_386_TLS_LDM_32, 32 }, - {RELOC_i386::R_386_TLS_LDM_PUSH, 32 }, - {RELOC_i386::R_386_TLS_LDM_CALL, 0 }, - {RELOC_i386::R_386_TLS_LDM_POP, 32 }, - {RELOC_i386::R_386_TLS_LDO_32, 32 }, - {RELOC_i386::R_386_TLS_IE_32, 32 }, - {RELOC_i386::R_386_TLS_LE_32, 32 }, - {RELOC_i386::R_386_TLS_DTPMOD32, 32 }, - {RELOC_i386::R_386_TLS_DTPOFF32, 32 }, - {RELOC_i386::R_386_TLS_TPOFF32, 32 }, - {RELOC_i386::R_386_TLS_GOTDESC, 32 }, - {RELOC_i386::R_386_TLS_DESC_CALL, 32 }, - {RELOC_i386::R_386_TLS_DESC, 32 }, - {RELOC_i386::R_386_IRELATIVE, 32 }, +int32_t get_R_X86(Relocation::TYPE R) { + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::X86_NONE, 0), + std::pair(Relocation::TYPE::X86_32, 32), + std::pair(Relocation::TYPE::X86_PC32, 32), + std::pair(Relocation::TYPE::X86_GOT32, 32), + std::pair(Relocation::TYPE::X86_PLT32, 32), + std::pair(Relocation::TYPE::X86_COPY, 32), + std::pair(Relocation::TYPE::X86_GLOB_DAT, 32), + std::pair(Relocation::TYPE::X86_JUMP_SLOT, 32), + std::pair(Relocation::TYPE::X86_RELATIVE, 32), + std::pair(Relocation::TYPE::X86_GOTOFF, 32), + std::pair(Relocation::TYPE::X86_GOTPC, 32), + std::pair(Relocation::TYPE::X86_32PLT, 32), + std::pair(Relocation::TYPE::X86_TLS_TPOFF, 32), + std::pair(Relocation::TYPE::X86_TLS_IE, 32), + std::pair(Relocation::TYPE::X86_TLS_GOTIE, 32), + std::pair(Relocation::TYPE::X86_TLS_LE, 32), + std::pair(Relocation::TYPE::X86_TLS_GD, 32), + std::pair(Relocation::TYPE::X86_TLS_LDM, 32), + std::pair(Relocation::TYPE::X86_16, 16), + std::pair(Relocation::TYPE::X86_PC16, 16), + std::pair(Relocation::TYPE::X86_8, 8), + std::pair(Relocation::TYPE::X86_PC8, 8), + std::pair(Relocation::TYPE::X86_TLS_GD_32, 32), + std::pair(Relocation::TYPE::X86_TLS_GD_PUSH, 32), + std::pair(Relocation::TYPE::X86_TLS_GD_CALL, 32), + std::pair(Relocation::TYPE::X86_TLS_GD_POP, 32), + std::pair(Relocation::TYPE::X86_TLS_LDM_32, 32), + std::pair(Relocation::TYPE::X86_TLS_LDM_PUSH, 32), + std::pair(Relocation::TYPE::X86_TLS_LDM_CALL, 0), + std::pair(Relocation::TYPE::X86_TLS_LDM_POP, 32), + std::pair(Relocation::TYPE::X86_TLS_LDO_32, 32), + std::pair(Relocation::TYPE::X86_TLS_IE_32, 32), + std::pair(Relocation::TYPE::X86_TLS_LE_32, 32), + std::pair(Relocation::TYPE::X86_TLS_DTPMOD32, 32), + std::pair(Relocation::TYPE::X86_TLS_DTPOFF32, 32), + std::pair(Relocation::TYPE::X86_TLS_TPOFF32, 32), + std::pair(Relocation::TYPE::X86_TLS_GOTDESC, 32), + std::pair(Relocation::TYPE::X86_TLS_DESC_CALL, 32), + std::pair(Relocation::TYPE::X86_TLS_DESC, 32), + std::pair(Relocation::TYPE::X86_IRELATIVE, 32), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; } -int32_t get_reloc_size(RELOC_ARM R) { +int32_t get_R_ARM(Relocation::TYPE R) { // From https://github.com/gittup/binutils/blob/gittup/bfd/elf32-arm.c#L75 - CONST_MAP(RELOC_ARM, uint32_t, 138) SIZES { - {RELOC_ARM::R_ARM_NONE, 0 }, - {RELOC_ARM::R_ARM_PC24, 24 }, - {RELOC_ARM::R_ARM_ABS32, 32 }, - {RELOC_ARM::R_ARM_REL32, 32 }, - {RELOC_ARM::R_ARM_LDR_PC_G0, 32 }, - {RELOC_ARM::R_ARM_ABS16, 16 }, - {RELOC_ARM::R_ARM_ABS12, 12 }, - {RELOC_ARM::R_ARM_THM_ABS5, 5 }, - {RELOC_ARM::R_ARM_ABS8, 8 }, - {RELOC_ARM::R_ARM_SBREL32, 32 }, - {RELOC_ARM::R_ARM_THM_CALL, 25 }, - {RELOC_ARM::R_ARM_THM_PC8, 8 }, - {RELOC_ARM::R_ARM_BREL_ADJ, 32 }, - {RELOC_ARM::R_ARM_TLS_DESC, 0 }, - {RELOC_ARM::R_ARM_THM_SWI8, 0 }, - {RELOC_ARM::R_ARM_XPC25, 25 }, - {RELOC_ARM::R_ARM_THM_XPC22, 22 }, - {RELOC_ARM::R_ARM_TLS_DTPMOD32, 32 }, - {RELOC_ARM::R_ARM_TLS_DTPOFF32, 32 }, - {RELOC_ARM::R_ARM_TLS_TPOFF32, 32 }, - {RELOC_ARM::R_ARM_COPY, 32 }, - {RELOC_ARM::R_ARM_GLOB_DAT, 32 }, - {RELOC_ARM::R_ARM_JUMP_SLOT, 32 }, - {RELOC_ARM::R_ARM_RELATIVE, 32 }, - {RELOC_ARM::R_ARM_GOTOFF32, 32 }, - {RELOC_ARM::R_ARM_BASE_PREL, 32 }, - {RELOC_ARM::R_ARM_GOT_BREL, 32 }, - {RELOC_ARM::R_ARM_PLT32, 24 }, - {RELOC_ARM::R_ARM_CALL, 24 }, - {RELOC_ARM::R_ARM_JUMP24, 24 }, - {RELOC_ARM::R_ARM_THM_JUMP24, 24 }, - {RELOC_ARM::R_ARM_BASE_ABS, 21 }, - {RELOC_ARM::R_ARM_ALU_PCREL_7_0, 12 }, - {RELOC_ARM::R_ARM_ALU_PCREL_15_8, 12 }, - {RELOC_ARM::R_ARM_ALU_PCREL_23_15, 12 }, - {RELOC_ARM::R_ARM_LDR_SBREL_11_0_NC, 12 }, - {RELOC_ARM::R_ARM_ALU_SBREL_19_12_NC, 8 }, - {RELOC_ARM::R_ARM_ALU_SBREL_27_20_CK, 8 }, - {RELOC_ARM::R_ARM_TARGET1, 32 }, - {RELOC_ARM::R_ARM_SBREL31, 32 }, - {RELOC_ARM::R_ARM_V4BX, 32 }, - {RELOC_ARM::R_ARM_TARGET2, 32 }, - {RELOC_ARM::R_ARM_PREL31, 31 }, - {RELOC_ARM::R_ARM_MOVW_ABS_NC, 16 }, - {RELOC_ARM::R_ARM_MOVT_ABS, 16 }, - {RELOC_ARM::R_ARM_MOVW_PREL_NC, 16 }, - {RELOC_ARM::R_ARM_MOVT_PREL, 16 }, - {RELOC_ARM::R_ARM_THM_MOVW_ABS_NC, 16 }, - {RELOC_ARM::R_ARM_THM_MOVT_ABS, 16 }, - {RELOC_ARM::R_ARM_THM_MOVW_PREL_NC, 16 }, - {RELOC_ARM::R_ARM_THM_MOVT_PREL, 16 }, - {RELOC_ARM::R_ARM_THM_JUMP19, 19 }, - {RELOC_ARM::R_ARM_THM_JUMP6, 6 }, - {RELOC_ARM::R_ARM_THM_ALU_PREL_11_0, 13 }, - {RELOC_ARM::R_ARM_THM_PC12, 13 }, - {RELOC_ARM::R_ARM_ABS32_NOI, 32 }, - {RELOC_ARM::R_ARM_REL32_NOI, 32 }, - {RELOC_ARM::R_ARM_ALU_PC_G0_NC, 32 }, - {RELOC_ARM::R_ARM_ALU_PC_G0, 32 }, - {RELOC_ARM::R_ARM_ALU_PC_G1_NC, 32 }, - {RELOC_ARM::R_ARM_ALU_PC_G1, 32 }, - {RELOC_ARM::R_ARM_ALU_PC_G2, 32 }, - {RELOC_ARM::R_ARM_LDR_PC_G1, 32 }, - {RELOC_ARM::R_ARM_LDR_PC_G2, 32 }, - {RELOC_ARM::R_ARM_LDRS_PC_G0, 32 }, - {RELOC_ARM::R_ARM_LDRS_PC_G1, 32 }, - {RELOC_ARM::R_ARM_LDRS_PC_G2, 32 }, - {RELOC_ARM::R_ARM_LDC_PC_G0, 32 }, - {RELOC_ARM::R_ARM_LDC_PC_G1, 32 }, - {RELOC_ARM::R_ARM_LDC_PC_G2, 32 }, - {RELOC_ARM::R_ARM_ALU_SB_G0_NC, 32 }, - {RELOC_ARM::R_ARM_ALU_SB_G0, 32 }, - {RELOC_ARM::R_ARM_ALU_SB_G1_NC, 32 }, - {RELOC_ARM::R_ARM_ALU_SB_G1, 32 }, - {RELOC_ARM::R_ARM_ALU_SB_G2, 32 }, - {RELOC_ARM::R_ARM_LDR_SB_G0, 32 }, - {RELOC_ARM::R_ARM_LDR_SB_G1, 32 }, - {RELOC_ARM::R_ARM_LDR_SB_G2, 32 }, - {RELOC_ARM::R_ARM_LDRS_SB_G0, 32 }, - {RELOC_ARM::R_ARM_LDRS_SB_G1, 32 }, - {RELOC_ARM::R_ARM_LDRS_SB_G2, 32 }, - {RELOC_ARM::R_ARM_LDC_SB_G0, 32 }, - {RELOC_ARM::R_ARM_LDC_SB_G1, 32 }, - {RELOC_ARM::R_ARM_LDC_SB_G2, 32 }, - {RELOC_ARM::R_ARM_MOVW_BREL_NC, 16 }, - {RELOC_ARM::R_ARM_MOVT_BREL, 16 }, - {RELOC_ARM::R_ARM_MOVW_BREL, 16 }, - {RELOC_ARM::R_ARM_THM_MOVW_BREL_NC, 16 }, - {RELOC_ARM::R_ARM_THM_MOVT_BREL, 16 }, - {RELOC_ARM::R_ARM_THM_MOVW_BREL, 16 }, - {RELOC_ARM::R_ARM_TLS_GOTDESC, 0 }, - {RELOC_ARM::R_ARM_TLS_CALL, 0 }, - {RELOC_ARM::R_ARM_TLS_DESCSEQ, 0 }, - {RELOC_ARM::R_ARM_THM_TLS_CALL, 0 }, - {RELOC_ARM::R_ARM_PLT32_ABS, 32 }, - {RELOC_ARM::R_ARM_GOT_ABS, 32 }, - {RELOC_ARM::R_ARM_GOT_PREL, 32 }, - {RELOC_ARM::R_ARM_GOT_BREL12, 12 }, - {RELOC_ARM::R_ARM_GOTOFF12, 12 }, - {RELOC_ARM::R_ARM_GOTRELAX, 12 }, - {RELOC_ARM::R_ARM_GNU_VTENTRY, 0 }, - {RELOC_ARM::R_ARM_GNU_VTINHERIT, 0 }, - {RELOC_ARM::R_ARM_THM_JUMP11, 11 }, - {RELOC_ARM::R_ARM_THM_JUMP8, 8 }, - {RELOC_ARM::R_ARM_TLS_GD32, 32 }, - {RELOC_ARM::R_ARM_TLS_LDM32, 32 }, - {RELOC_ARM::R_ARM_TLS_LDO32, 32 }, - {RELOC_ARM::R_ARM_TLS_IE32, 32 }, - {RELOC_ARM::R_ARM_TLS_LE32, 32 }, - {RELOC_ARM::R_ARM_TLS_LDO12, 12 }, - {RELOC_ARM::R_ARM_TLS_LE12, 12 }, - {RELOC_ARM::R_ARM_TLS_IE12GP, 12 }, - {RELOC_ARM::R_ARM_PRIVATE_0, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_1, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_2, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_3, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_4, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_5, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_6, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_7, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_8, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_9, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_10, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_11, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_12, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_13, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_14, 0 }, - {RELOC_ARM::R_ARM_PRIVATE_15, 0 }, - {RELOC_ARM::R_ARM_ME_TOO, 0 }, - {RELOC_ARM::R_ARM_THM_TLS_DESCSEQ16, 0 }, - {RELOC_ARM::R_ARM_THM_TLS_DESCSEQ32, 0 }, - {RELOC_ARM::R_ARM_IRELATIVE, 0 }, - {RELOC_ARM::R_ARM_RXPC25, 25 }, - {RELOC_ARM::R_ARM_RSBREL32, 32 }, - {RELOC_ARM::R_ARM_THM_RPC22, 22 }, - {RELOC_ARM::R_ARM_RREL32, 32 }, - {RELOC_ARM::R_ARM_RPC24, 24 }, - {RELOC_ARM::R_ARM_RBASE, 0 }, + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::ARM_NONE, 0), + std::pair(Relocation::TYPE::ARM_PC24, 24), + std::pair(Relocation::TYPE::ARM_ABS32, 32), + std::pair(Relocation::TYPE::ARM_REL32, 32), + std::pair(Relocation::TYPE::ARM_LDR_PC_G0, 32), + std::pair(Relocation::TYPE::ARM_ABS16, 16), + std::pair(Relocation::TYPE::ARM_ABS12, 12), + std::pair(Relocation::TYPE::ARM_THM_ABS5, 5), + std::pair(Relocation::TYPE::ARM_ABS8, 8), + std::pair(Relocation::TYPE::ARM_SBREL32, 32), + std::pair(Relocation::TYPE::ARM_THM_CALL, 25), + std::pair(Relocation::TYPE::ARM_THM_PC8, 8), + std::pair(Relocation::TYPE::ARM_BREL_ADJ, 32), + std::pair(Relocation::TYPE::ARM_TLS_DESC, 0), + std::pair(Relocation::TYPE::ARM_THM_SWI8, 0), + std::pair(Relocation::TYPE::ARM_XPC25, 25), + std::pair(Relocation::TYPE::ARM_THM_XPC22, 22), + std::pair(Relocation::TYPE::ARM_TLS_DTPMOD32, 32), + std::pair(Relocation::TYPE::ARM_TLS_DTPOFF32, 32), + std::pair(Relocation::TYPE::ARM_TLS_TPOFF32, 32), + std::pair(Relocation::TYPE::ARM_COPY, 32), + std::pair(Relocation::TYPE::ARM_GLOB_DAT, 32), + std::pair(Relocation::TYPE::ARM_JUMP_SLOT, 32), + std::pair(Relocation::TYPE::ARM_RELATIVE, 32), + std::pair(Relocation::TYPE::ARM_GOTOFF32, 32), + std::pair(Relocation::TYPE::ARM_BASE_PREL, 32), + std::pair(Relocation::TYPE::ARM_GOT_BREL, 32), + std::pair(Relocation::TYPE::ARM_PLT32, 24), + std::pair(Relocation::TYPE::ARM_CALL, 24), + std::pair(Relocation::TYPE::ARM_JUMP24, 24), + std::pair(Relocation::TYPE::ARM_THM_JUMP24, 24), + std::pair(Relocation::TYPE::ARM_BASE_ABS, 21), + std::pair(Relocation::TYPE::ARM_ALU_PCREL_7_0, 12), + std::pair(Relocation::TYPE::ARM_ALU_PCREL_15_8, 12), + std::pair(Relocation::TYPE::ARM_ALU_PCREL_23_15, 12), + std::pair(Relocation::TYPE::ARM_LDR_SBREL_11_0_NC, 12), + std::pair(Relocation::TYPE::ARM_ALU_SBREL_19_12_NC, 8), + std::pair(Relocation::TYPE::ARM_ALU_SBREL_27_20_CK, 8), + std::pair(Relocation::TYPE::ARM_TARGET1, 32), + std::pair(Relocation::TYPE::ARM_SBREL31, 32), + std::pair(Relocation::TYPE::ARM_V4BX, 32), + std::pair(Relocation::TYPE::ARM_TARGET2, 32), + std::pair(Relocation::TYPE::ARM_PREL31, 31), + std::pair(Relocation::TYPE::ARM_MOVW_ABS_NC, 16), + std::pair(Relocation::TYPE::ARM_MOVT_ABS, 16), + std::pair(Relocation::TYPE::ARM_MOVW_PREL_NC, 16), + std::pair(Relocation::TYPE::ARM_MOVT_PREL, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVW_ABS_NC, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVT_ABS, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVW_PREL_NC, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVT_PREL, 16), + std::pair(Relocation::TYPE::ARM_THM_JUMP19, 19), + std::pair(Relocation::TYPE::ARM_THM_JUMP6, 6), + std::pair(Relocation::TYPE::ARM_THM_ALU_PREL_11_0, 13), + std::pair(Relocation::TYPE::ARM_THM_PC12, 13), + std::pair(Relocation::TYPE::ARM_ABS32_NOI, 32), + std::pair(Relocation::TYPE::ARM_REL32_NOI, 32), + std::pair(Relocation::TYPE::ARM_ALU_PC_G0_NC, 32), + std::pair(Relocation::TYPE::ARM_ALU_PC_G0, 32), + std::pair(Relocation::TYPE::ARM_ALU_PC_G1_NC, 32), + std::pair(Relocation::TYPE::ARM_ALU_PC_G1, 32), + std::pair(Relocation::TYPE::ARM_ALU_PC_G2, 32), + std::pair(Relocation::TYPE::ARM_LDR_PC_G1, 32), + std::pair(Relocation::TYPE::ARM_LDR_PC_G2, 32), + std::pair(Relocation::TYPE::ARM_LDRS_PC_G0, 32), + std::pair(Relocation::TYPE::ARM_LDRS_PC_G1, 32), + std::pair(Relocation::TYPE::ARM_LDRS_PC_G2, 32), + std::pair(Relocation::TYPE::ARM_LDC_PC_G0, 32), + std::pair(Relocation::TYPE::ARM_LDC_PC_G1, 32), + std::pair(Relocation::TYPE::ARM_LDC_PC_G2, 32), + std::pair(Relocation::TYPE::ARM_ALU_SB_G0_NC, 32), + std::pair(Relocation::TYPE::ARM_ALU_SB_G0, 32), + std::pair(Relocation::TYPE::ARM_ALU_SB_G1_NC, 32), + std::pair(Relocation::TYPE::ARM_ALU_SB_G1, 32), + std::pair(Relocation::TYPE::ARM_ALU_SB_G2, 32), + std::pair(Relocation::TYPE::ARM_LDR_SB_G0, 32), + std::pair(Relocation::TYPE::ARM_LDR_SB_G1, 32), + std::pair(Relocation::TYPE::ARM_LDR_SB_G2, 32), + std::pair(Relocation::TYPE::ARM_LDRS_SB_G0, 32), + std::pair(Relocation::TYPE::ARM_LDRS_SB_G1, 32), + std::pair(Relocation::TYPE::ARM_LDRS_SB_G2, 32), + std::pair(Relocation::TYPE::ARM_LDC_SB_G0, 32), + std::pair(Relocation::TYPE::ARM_LDC_SB_G1, 32), + std::pair(Relocation::TYPE::ARM_LDC_SB_G2, 32), + std::pair(Relocation::TYPE::ARM_MOVW_BREL_NC, 16), + std::pair(Relocation::TYPE::ARM_MOVT_BREL, 16), + std::pair(Relocation::TYPE::ARM_MOVW_BREL, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVW_BREL_NC, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVT_BREL, 16), + std::pair(Relocation::TYPE::ARM_THM_MOVW_BREL, 16), + std::pair(Relocation::TYPE::ARM_TLS_GOTDESC, 0), + std::pair(Relocation::TYPE::ARM_TLS_CALL, 0), + std::pair(Relocation::TYPE::ARM_TLS_DESCSEQ, 0), + std::pair(Relocation::TYPE::ARM_THM_TLS_CALL, 0), + std::pair(Relocation::TYPE::ARM_PLT32_ABS, 32), + std::pair(Relocation::TYPE::ARM_GOT_ABS, 32), + std::pair(Relocation::TYPE::ARM_GOT_PREL, 32), + std::pair(Relocation::TYPE::ARM_GOT_BREL12, 12), + std::pair(Relocation::TYPE::ARM_GOTOFF12, 12), + std::pair(Relocation::TYPE::ARM_GOTRELAX, 12), + std::pair(Relocation::TYPE::ARM_GNU_VTENTRY, 0), + std::pair(Relocation::TYPE::ARM_GNU_VTINHERIT, 0), + std::pair(Relocation::TYPE::ARM_THM_JUMP11, 11), + std::pair(Relocation::TYPE::ARM_THM_JUMP8, 8), + std::pair(Relocation::TYPE::ARM_TLS_GD32, 32), + std::pair(Relocation::TYPE::ARM_TLS_LDM32, 32), + std::pair(Relocation::TYPE::ARM_TLS_LDO32, 32), + std::pair(Relocation::TYPE::ARM_TLS_IE32, 32), + std::pair(Relocation::TYPE::ARM_TLS_LE32, 32), + std::pair(Relocation::TYPE::ARM_TLS_LDO12, 12), + std::pair(Relocation::TYPE::ARM_TLS_LE12, 12), + std::pair(Relocation::TYPE::ARM_TLS_IE12GP, 12), + std::pair(Relocation::TYPE::ARM_PRIVATE_0, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_1, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_2, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_3, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_4, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_5, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_6, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_7, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_8, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_9, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_10, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_11, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_12, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_13, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_14, 0), + std::pair(Relocation::TYPE::ARM_PRIVATE_15, 0), + std::pair(Relocation::TYPE::ARM_ME_TOO, 0), + std::pair(Relocation::TYPE::ARM_THM_TLS_DESCSEQ16, 0), + std::pair(Relocation::TYPE::ARM_THM_TLS_DESCSEQ32, 0), + std::pair(Relocation::TYPE::ARM_IRELATIVE, 0), + std::pair(Relocation::TYPE::ARM_RXPC25, 25), + std::pair(Relocation::TYPE::ARM_RSBREL32, 32), + std::pair(Relocation::TYPE::ARM_THM_RPC22, 22), + std::pair(Relocation::TYPE::ARM_RREL32, 32), + std::pair(Relocation::TYPE::ARM_RPC24, 24), + std::pair(Relocation::TYPE::ARM_RBASE, 0), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; } -int32_t get_reloc_size(RELOC_AARCH64 R) { - CONST_MAP(RELOC_AARCH64, uint32_t, 123) SIZES { - { RELOC_AARCH64::R_AARCH64_NONE, 0 }, - { RELOC_AARCH64::R_AARCH64_ABS64, 64 }, - { RELOC_AARCH64::R_AARCH64_ABS32, 32 }, - { RELOC_AARCH64::R_AARCH64_ABS16, 16 }, - { RELOC_AARCH64::R_AARCH64_PREL64, 64 }, - { RELOC_AARCH64::R_AARCH64_PREL32, 32 }, - { RELOC_AARCH64::R_AARCH64_PREL16, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G0, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G1_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G2, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G2_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_UABS_G3, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_SABS_G0, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_SABS_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_SABS_G2, 16 }, - { RELOC_AARCH64::R_AARCH64_LD_PREL_LO19, 19 }, - { RELOC_AARCH64::R_AARCH64_ADR_PREL_LO21, 21 }, - { RELOC_AARCH64::R_AARCH64_ADR_PREL_PG_HI21, 21 }, - { RELOC_AARCH64::R_AARCH64_ADR_PREL_PG_HI21_NC, 21 }, - { RELOC_AARCH64::R_AARCH64_ADD_ABS_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_LDST8_ABS_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TSTBR14, 14 }, - { RELOC_AARCH64::R_AARCH64_CONDBR19, 19 }, - { RELOC_AARCH64::R_AARCH64_JUMP26, 26 }, - { RELOC_AARCH64::R_AARCH64_CALL26, 26 }, - { RELOC_AARCH64::R_AARCH64_LDST16_ABS_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_LDST32_ABS_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_LDST64_ABS_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G0, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G1_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G2, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G2_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_PREL_G3, 16 }, - { RELOC_AARCH64::R_AARCH64_LDST128_ABS_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G0, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G1_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G2, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G2_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_MOVW_GOTOFF_G3, 16 }, - { RELOC_AARCH64::R_AARCH64_GOTREL64, 64 }, - { RELOC_AARCH64::R_AARCH64_GOTREL32, 64 }, - { RELOC_AARCH64::R_AARCH64_GOT_LD_PREL19, 19 }, - { RELOC_AARCH64::R_AARCH64_LD64_GOTOFF_LO15, 15 }, - { RELOC_AARCH64::R_AARCH64_ADR_GOT_PAGE, 21 }, - { RELOC_AARCH64::R_AARCH64_LD64_GOT_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_LD64_GOTPAGE_LO15, 15 }, - { RELOC_AARCH64::R_AARCH64_TLSGD_ADR_PREL21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSGD_ADR_PAGE21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSGD_ADD_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSGD_MOVW_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSGD_MOVW_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADR_PREL21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADR_PAGE21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_LO12_NC, 0 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_G1, 0 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_G0_NC, 0 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LD_PREL19, 19 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G2, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G0, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_HI12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST8_DTPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST16_DTPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST32_DTPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST64_DTPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSIE_MOVW_GOTTPREL_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSIE_LD_GOTTPREL_PREL19, 19 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G2, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G1, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G1_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G0, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_MOVW_TPREL_G0_NC, 16 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_HI12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_ADD_TPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST8_TPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST16_TPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST32_TPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST64_TPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_LD_PREL19, 19 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADR_PREL21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADR_PAGE21, 21 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_LD64_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADD_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_OFF_G1, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_OFF_G0_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_LDR, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_ADD, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC_CALL, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST128_TPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST128_DTPREL_LO12, 12 }, - { RELOC_AARCH64::R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC, 12 }, - { RELOC_AARCH64::R_AARCH64_COPY, 64 }, - { RELOC_AARCH64::R_AARCH64_GLOB_DAT, 64 }, - { RELOC_AARCH64::R_AARCH64_JUMP_SLOT, 64 }, - { RELOC_AARCH64::R_AARCH64_RELATIVE, 64 }, - { RELOC_AARCH64::R_AARCH64_TLS_DTPREL64, 64 }, - { RELOC_AARCH64::R_AARCH64_TLS_DTPMOD64, 64 }, - { RELOC_AARCH64::R_AARCH64_TLS_TPREL64, 64 }, - { RELOC_AARCH64::R_AARCH64_TLSDESC, 64 }, - { RELOC_AARCH64::R_AARCH64_IRELATIVE, 64 }, +int32_t get_R_AARCH64(Relocation::TYPE R) { + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::AARCH64_NONE, 0 ), + std::pair(Relocation::TYPE::AARCH64_ABS64, 64 ), + std::pair(Relocation::TYPE::AARCH64_ABS32, 32 ), + std::pair(Relocation::TYPE::AARCH64_ABS16, 16 ), + std::pair(Relocation::TYPE::AARCH64_PREL64, 64 ), + std::pair(Relocation::TYPE::AARCH64_PREL32, 32 ), + std::pair(Relocation::TYPE::AARCH64_PREL16, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G0, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G1_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G2, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G2_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_UABS_G3, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_SABS_G0, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_SABS_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_SABS_G2, 16 ), + std::pair(Relocation::TYPE::AARCH64_LD_PREL_LO19, 19 ), + std::pair(Relocation::TYPE::AARCH64_ADR_PREL_LO21, 21 ), + std::pair(Relocation::TYPE::AARCH64_ADR_PREL_PG_HI21, 21 ), + std::pair(Relocation::TYPE::AARCH64_ADR_PREL_PG_HI21_NC, 21 ), + std::pair(Relocation::TYPE::AARCH64_ADD_ABS_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_LDST8_ABS_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TSTBR14, 14 ), + std::pair(Relocation::TYPE::AARCH64_CONDBR19, 19 ), + std::pair(Relocation::TYPE::AARCH64_JUMP26, 26 ), + std::pair(Relocation::TYPE::AARCH64_CALL26, 26 ), + std::pair(Relocation::TYPE::AARCH64_LDST16_ABS_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_LDST32_ABS_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_LDST64_ABS_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G0, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G1_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G2, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G2_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_PREL_G3, 16 ), + std::pair(Relocation::TYPE::AARCH64_LDST128_ABS_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G0, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G1_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G2, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G2_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_MOVW_GOTOFF_G3, 16 ), + std::pair(Relocation::TYPE::AARCH64_GOTREL64, 64 ), + std::pair(Relocation::TYPE::AARCH64_GOTREL32, 64 ), + std::pair(Relocation::TYPE::AARCH64_GOT_LD_PREL19, 19 ), + std::pair(Relocation::TYPE::AARCH64_LD64_GOTOFF_LO15, 15 ), + std::pair(Relocation::TYPE::AARCH64_ADR_GOT_PAGE, 21 ), + std::pair(Relocation::TYPE::AARCH64_LD64_GOT_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_LD64_GOTPAGE_LO15, 15 ), + std::pair(Relocation::TYPE::AARCH64_TLSGD_ADR_PREL21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSGD_ADR_PAGE21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSGD_ADD_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSGD_MOVW_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSGD_MOVW_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_ADR_PREL21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_ADR_PAGE21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_ADD_LO12_NC, 0 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_G1, 0 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_G0_NC, 0 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LD_PREL19, 19 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_DTPREL_G2, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_DTPREL_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_DTPREL_G1_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_DTPREL_G0, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_MOVW_DTPREL_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_ADD_DTPREL_HI12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_ADD_DTPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_ADD_DTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST8_DTPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST16_DTPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST32_DTPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST64_DTPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSIE_MOVW_GOTTPREL_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSIE_LD_GOTTPREL_PREL19, 19 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_MOVW_TPREL_G2, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_MOVW_TPREL_G1, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_MOVW_TPREL_G1_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_MOVW_TPREL_G0, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_MOVW_TPREL_G0_NC, 16 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_ADD_TPREL_HI12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_ADD_TPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_ADD_TPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST8_TPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST8_TPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST16_TPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST16_TPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST32_TPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST32_TPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST64_TPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST64_TPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_LD_PREL19, 19 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_ADR_PREL21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_ADR_PAGE21, 21 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_LD64_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_ADD_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_OFF_G1, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_OFF_G0_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_LDR, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_ADD, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC_CALL, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST128_TPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLE_LDST128_TPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST128_DTPREL_LO12, 12 ), + std::pair(Relocation::TYPE::AARCH64_TLSLD_LDST128_DTPREL_LO12_NC, 12 ), + std::pair(Relocation::TYPE::AARCH64_COPY, 64 ), + std::pair(Relocation::TYPE::AARCH64_GLOB_DAT, 64 ), + std::pair(Relocation::TYPE::AARCH64_JUMP_SLOT, 64 ), + std::pair(Relocation::TYPE::AARCH64_RELATIVE, 64 ), + std::pair(Relocation::TYPE::AARCH64_TLS_DTPREL64, 64 ), + std::pair(Relocation::TYPE::AARCH64_TLS_DTPMOD64, 64 ), + std::pair(Relocation::TYPE::AARCH64_TLS_TPREL64, 64 ), + std::pair(Relocation::TYPE::AARCH64_TLSDESC, 64 ), + std::pair(Relocation::TYPE::AARCH64_IRELATIVE, 64 ), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; @@ -395,377 +396,409 @@ int32_t get_reloc_size(RELOC_AARCH64 R) { -int32_t get_reloc_size(RELOC_POWERPC32 R) { - CONST_MAP(RELOC_POWERPC32, uint32_t, 57) SIZES { - { RELOC_POWERPC32::R_PPC_NONE, 0 }, - { RELOC_POWERPC32::R_PPC_ADDR32, 32 }, - { RELOC_POWERPC32::R_PPC_ADDR24, 32 }, - { RELOC_POWERPC32::R_PPC_ADDR16, 16 }, - { RELOC_POWERPC32::R_PPC_ADDR16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_ADDR16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_ADDR16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_ADDR14, 32 }, - { RELOC_POWERPC32::R_PPC_ADDR14_BRTAKEN, 32 }, - { RELOC_POWERPC32::R_PPC_ADDR14_BRNTAKEN, 32 }, - { RELOC_POWERPC32::R_PPC_REL24, 32 }, - { RELOC_POWERPC32::R_PPC_REL14, 32 }, - { RELOC_POWERPC32::R_PPC_REL14_BRTAKEN, 32 }, - { RELOC_POWERPC32::R_PPC_REL14_BRNTAKEN, 32 }, - { RELOC_POWERPC32::R_PPC_GOT16, 16 }, - { RELOC_POWERPC32::R_PPC_GOT16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_GOT16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_GOT16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_PLTREL24, 32 }, - { RELOC_POWERPC32::R_PPC_JMP_SLOT, 0 }, - { RELOC_POWERPC32::R_PPC_RELATIVE, 32 }, - { RELOC_POWERPC32::R_PPC_LOCAL24PC, 32 }, - { RELOC_POWERPC32::R_PPC_REL32, 32 }, - { RELOC_POWERPC32::R_PPC_TLS, 32 }, - { RELOC_POWERPC32::R_PPC_DTPMOD32, 32 }, - { RELOC_POWERPC32::R_PPC_TPREL16, 16 }, - { RELOC_POWERPC32::R_PPC_TPREL16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_TPREL16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_TPREL16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_TPREL32, 32 }, - { RELOC_POWERPC32::R_PPC_DTPREL16, 16 }, - { RELOC_POWERPC32::R_PPC_DTPREL16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_DTPREL16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_DTPREL16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_DTPREL32, 32 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSGD16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TLSLD16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_TPREL16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_GOT_DTPREL16_HA, 16 }, - { RELOC_POWERPC32::R_PPC_TLSGD, 32 }, - { RELOC_POWERPC32::R_PPC_TLSLD, 32 }, - { RELOC_POWERPC32::R_PPC_REL16, 16 }, - { RELOC_POWERPC32::R_PPC_REL16_LO, 16 }, - { RELOC_POWERPC32::R_PPC_REL16_HI, 16 }, - { RELOC_POWERPC32::R_PPC_REL16_HA, 16 }, +int32_t get_R_PPC(Relocation::TYPE R) { + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::PPC_NONE, 0 ), + std::pair(Relocation::TYPE::PPC_ADDR32, 32 ), + std::pair(Relocation::TYPE::PPC_ADDR24, 32 ), + std::pair(Relocation::TYPE::PPC_ADDR16, 16 ), + std::pair(Relocation::TYPE::PPC_ADDR16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_ADDR16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_ADDR16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_ADDR14, 32 ), + std::pair(Relocation::TYPE::PPC_ADDR14_BRTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC_ADDR14_BRNTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC_REL24, 32 ), + std::pair(Relocation::TYPE::PPC_REL14, 32 ), + std::pair(Relocation::TYPE::PPC_REL14_BRTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC_REL14_BRNTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC_GOT16, 16 ), + std::pair(Relocation::TYPE::PPC_GOT16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_GOT16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_GOT16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_PLTREL24, 32 ), + std::pair(Relocation::TYPE::PPC_JMP_SLOT, 0 ), + std::pair(Relocation::TYPE::PPC_RELATIVE, 32 ), + std::pair(Relocation::TYPE::PPC_LOCAL24PC, 32 ), + std::pair(Relocation::TYPE::PPC_REL32, 32 ), + std::pair(Relocation::TYPE::PPC_TLS, 32 ), + std::pair(Relocation::TYPE::PPC_DTPMOD32, 32 ), + std::pair(Relocation::TYPE::PPC_TPREL16, 16 ), + std::pair(Relocation::TYPE::PPC_TPREL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_TPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_TPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_TPREL32, 32 ), + std::pair(Relocation::TYPE::PPC_DTPREL16, 16 ), + std::pair(Relocation::TYPE::PPC_DTPREL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_DTPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_DTPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_DTPREL32, 32 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSGD16, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSGD16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSGD16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSGD16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSLD16, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSLD16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSLD16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TLSLD16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TPREL16, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TPREL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_TPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_DTPREL16, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_DTPREL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_DTPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_GOT_DTPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC_TLSGD, 32 ), + std::pair(Relocation::TYPE::PPC_TLSLD, 32 ), + std::pair(Relocation::TYPE::PPC_REL16, 16 ), + std::pair(Relocation::TYPE::PPC_REL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC_REL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC_REL16_HA, 16 ), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; } -int32_t get_reloc_size(RELOC_POWERPC64 R) { - CONST_MAP(RELOC_POWERPC64, uint32_t, 84) SIZES { - { RELOC_POWERPC64::R_PPC64_NONE, 0 }, - { RELOC_POWERPC64::R_PPC64_ADDR32, 32 }, - { RELOC_POWERPC64::R_PPC64_ADDR24, 32 }, - { RELOC_POWERPC64::R_PPC64_ADDR16, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR14, 32 }, - { RELOC_POWERPC64::R_PPC64_ADDR14_BRTAKEN, 32 }, - { RELOC_POWERPC64::R_PPC64_ADDR14_BRNTAKEN, 32 }, - { RELOC_POWERPC64::R_PPC64_REL24, 32 }, - { RELOC_POWERPC64::R_PPC64_REL14, 32 }, - { RELOC_POWERPC64::R_PPC64_REL14_BRTAKEN, 32 }, - { RELOC_POWERPC64::R_PPC64_REL14_BRNTAKEN, 32 }, - { RELOC_POWERPC64::R_PPC64_GOT16, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_JMP_SLOT, 64 }, - { RELOC_POWERPC64::R_PPC64_RELATIVE, 64 }, - { RELOC_POWERPC64::R_PPC64_REL32, 32 }, - { RELOC_POWERPC64::R_PPC64_ADDR64, 64 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHER, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHERA, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHEST, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_HIGHESTA, 16 }, - { RELOC_POWERPC64::R_PPC64_REL64, 64 }, - { RELOC_POWERPC64::R_PPC64_TOC16, 16 }, - { RELOC_POWERPC64::R_PPC64_TOC16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_TOC16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_TOC16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_TOC, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_ADDR16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_TOC16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_TOC16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_TLS, 0 }, - { RELOC_POWERPC64::R_PPC64_DTPMOD64, 64 }, - { RELOC_POWERPC64::R_PPC64_TPREL16, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL64, 64 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL64, 64 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSGD16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TLSLD16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_TPREL16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_GOT_DTPREL16_HA, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHER, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHERA, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHEST, 16 }, - { RELOC_POWERPC64::R_PPC64_TPREL16_HIGHESTA, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_LO_DS, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHER, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHERA, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHEST, 16 }, - { RELOC_POWERPC64::R_PPC64_DTPREL16_HIGHESTA, 16 }, - { RELOC_POWERPC64::R_PPC64_TLSGD, 64 }, - { RELOC_POWERPC64::R_PPC64_TLSLD, 64 }, - { RELOC_POWERPC64::R_PPC64_REL16, 16 }, - { RELOC_POWERPC64::R_PPC64_REL16_LO, 16 }, - { RELOC_POWERPC64::R_PPC64_REL16_HI, 16 }, - { RELOC_POWERPC64::R_PPC64_REL16_HA, 16 }, +int32_t get_R_PPC64(Relocation::TYPE R) { + CONST_MAP_ALT SIZES { + + std::pair(Relocation::TYPE::PPC64_NONE, 0 ), + std::pair(Relocation::TYPE::PPC64_ADDR32, 32 ), + std::pair(Relocation::TYPE::PPC64_ADDR24, 32 ), + std::pair(Relocation::TYPE::PPC64_ADDR16, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR14, 32 ), + std::pair(Relocation::TYPE::PPC64_ADDR14_BRTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC64_ADDR14_BRNTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC64_REL24, 32 ), + std::pair(Relocation::TYPE::PPC64_REL14, 32 ), + std::pair(Relocation::TYPE::PPC64_REL14_BRTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC64_REL14_BRNTAKEN, 32 ), + std::pair(Relocation::TYPE::PPC64_GOT16, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_JMP_SLOT, 64 ), + std::pair(Relocation::TYPE::PPC64_RELATIVE, 64 ), + std::pair(Relocation::TYPE::PPC64_REL32, 32 ), + std::pair(Relocation::TYPE::PPC64_ADDR64, 64 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_HIGHER, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_HIGHERA, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_HIGHEST, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_HIGHESTA, 16 ), + std::pair(Relocation::TYPE::PPC64_REL64, 64 ), + std::pair(Relocation::TYPE::PPC64_TOC16, 16 ), + std::pair(Relocation::TYPE::PPC64_TOC16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_TOC16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_TOC16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_TOC, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_ADDR16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_TOC16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_TOC16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_TLS, 0 ), + std::pair(Relocation::TYPE::PPC64_DTPMOD64, 64 ), + std::pair(Relocation::TYPE::PPC64_TPREL16, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL64, 64 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL64, 64 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSGD16, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSGD16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSGD16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSGD16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSLD16, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSLD16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSLD16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TLSLD16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TPREL16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TPREL16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_TPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_DTPREL16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_DTPREL16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_DTPREL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_GOT_DTPREL16_HA, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_HIGHER, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_HIGHERA, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_HIGHEST, 16 ), + std::pair(Relocation::TYPE::PPC64_TPREL16_HIGHESTA, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_LO_DS, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_HIGHER, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_HIGHERA, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_HIGHEST, 16 ), + std::pair(Relocation::TYPE::PPC64_DTPREL16_HIGHESTA, 16 ), + std::pair(Relocation::TYPE::PPC64_TLSGD, 64 ), + std::pair(Relocation::TYPE::PPC64_TLSLD, 64 ), + std::pair(Relocation::TYPE::PPC64_REL16, 16 ), + std::pair(Relocation::TYPE::PPC64_REL16_LO, 16 ), + std::pair(Relocation::TYPE::PPC64_REL16_HI, 16 ), + std::pair(Relocation::TYPE::PPC64_REL16_HA, 16 ), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; } -int32_t get_reloc_size(RELOC_MIPS R) { - CONST_MAP(RELOC_MIPS, uint32_t, 112) SIZES { - { RELOC_MIPS::R_MICROMIPS_26_S1, 26 }, - { RELOC_MIPS::R_MICROMIPS_CALL16, 16 }, - { RELOC_MIPS::R_MICROMIPS_CALL_HI16, 16 }, - { RELOC_MIPS::R_MICROMIPS_CALL_LO16, 16 }, - { RELOC_MIPS::R_MICROMIPS_GOT16, 16 }, - { RELOC_MIPS::R_MICROMIPS_GOT_DISP, 16 }, - { RELOC_MIPS::R_MICROMIPS_GOT_HI16, 16 }, - { RELOC_MIPS::R_MICROMIPS_GOT_LO16, 16 }, - { RELOC_MIPS::R_MICROMIPS_GOT_OFST, 16 }, - { RELOC_MIPS::R_MICROMIPS_GOT_PAGE, 16 }, - { RELOC_MIPS::R_MICROMIPS_GPREL16, 16 }, - { RELOC_MIPS::R_MICROMIPS_GPREL7_S2, 7 }, - { RELOC_MIPS::R_MICROMIPS_HI0_LO16, 16 }, - { RELOC_MIPS::R_MICROMIPS_HI16, 16 }, - { RELOC_MIPS::R_MICROMIPS_HIGHER, 16 }, - { RELOC_MIPS::R_MICROMIPS_HIGHEST, 16 }, - { RELOC_MIPS::R_MICROMIPS_JALR, 32 }, - { RELOC_MIPS::R_MICROMIPS_LITERAL, 16 }, - { RELOC_MIPS::R_MICROMIPS_LO16, 16 }, - { RELOC_MIPS::R_MICROMIPS_PC10_S1, 10 }, - { RELOC_MIPS::R_MICROMIPS_PC16_S1, 16 }, - { RELOC_MIPS::R_MICROMIPS_PC18_S3, 18 }, - { RELOC_MIPS::R_MICROMIPS_PC19_S2, 19 }, - { RELOC_MIPS::R_MICROMIPS_PC21_S2, 21 }, - { RELOC_MIPS::R_MICROMIPS_PC23_S2, 23 }, - { RELOC_MIPS::R_MICROMIPS_PC26_S2, 26 }, - { RELOC_MIPS::R_MICROMIPS_PC7_S1, 7 }, - { RELOC_MIPS::R_MICROMIPS_SCN_DISP, 32 }, - { RELOC_MIPS::R_MICROMIPS_SUB, 64 }, - { RELOC_MIPS::R_MICROMIPS_TLS_DTPREL_HI16, 16 }, - { RELOC_MIPS::R_MICROMIPS_TLS_DTPREL_LO16, 16 }, - { RELOC_MIPS::R_MICROMIPS_TLS_GD, 16 }, - { RELOC_MIPS::R_MICROMIPS_TLS_GOTTPREL, 16 }, - { RELOC_MIPS::R_MICROMIPS_TLS_LDM, 16 }, - { RELOC_MIPS::R_MICROMIPS_TLS_TPREL_HI16, 16 }, - { RELOC_MIPS::R_MICROMIPS_TLS_TPREL_LO16, 16 }, - { RELOC_MIPS::R_MIPS_16, 16 }, - { RELOC_MIPS::R_MIPS16_26, 26 }, - { RELOC_MIPS::R_MIPS16_CALL16, 16 }, - { RELOC_MIPS::R_MIPS16_GOT16, 16 }, - { RELOC_MIPS::R_MIPS16_GPREL, 16 }, - { RELOC_MIPS::R_MIPS16_HI16, 16 }, - { RELOC_MIPS::R_MIPS16_LO16, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_DTPREL_HI16, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_DTPREL_LO16, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_GD, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_GOTTPREL, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_LDM, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_TPREL_HI16, 16 }, - { RELOC_MIPS::R_MIPS16_TLS_TPREL_LO16, 16 }, - { RELOC_MIPS::R_MIPS_ADD_IMMEDIATE, 0 }, - { RELOC_MIPS::R_MIPS_26, 26 }, - { RELOC_MIPS::R_MIPS_32, 32 }, - { RELOC_MIPS::R_MIPS_64, 64 }, - { RELOC_MIPS::R_MIPS_CALL16, 16 }, - { RELOC_MIPS::R_MIPS_CALL_HI16, 16 }, - { RELOC_MIPS::R_MIPS_CALL_LO16, 16 }, - { RELOC_MIPS::R_MIPS_COPY, 0 }, - { RELOC_MIPS::R_MIPS_DELETE, 32 }, - { RELOC_MIPS::R_MIPS_EH, 32 }, - { RELOC_MIPS::R_MIPS_GLOB_DAT, 32 }, - { RELOC_MIPS::R_MIPS_GOT16, 16 }, - { RELOC_MIPS::R_MIPS_GOT_DISP, 16 }, - { RELOC_MIPS::R_MIPS_GOT_HI16, 16 }, - { RELOC_MIPS::R_MIPS_GOT_LO16, 16 }, - { RELOC_MIPS::R_MIPS_GOT_OFST, 16 }, - { RELOC_MIPS::R_MIPS_GOT_PAGE, 16 }, - { RELOC_MIPS::R_MIPS_GPREL16, 16 }, - { RELOC_MIPS::R_MIPS_GPREL32, 32 }, - { RELOC_MIPS::R_MIPS_HI16, 16 }, - { RELOC_MIPS::R_MIPS_HIGHER, 16 }, - { RELOC_MIPS::R_MIPS_HIGHEST, 16 }, - { RELOC_MIPS::R_MIPS_INSERT_A, 32 }, - { RELOC_MIPS::R_MIPS_INSERT_B, 32 }, - { RELOC_MIPS::R_MIPS_JALR, 32 }, - { RELOC_MIPS::R_MIPS_JUMP_SLOT, 64 }, - { RELOC_MIPS::R_MIPS_LITERAL, 16 }, - { RELOC_MIPS::R_MIPS_LO16, 16 }, - { RELOC_MIPS::R_MIPS_NONE, 0 }, - { RELOC_MIPS::R_MIPS_NUM, 0 }, - { RELOC_MIPS::R_MIPS_PC16, 16 }, - { RELOC_MIPS::R_MIPS_PC18_S3, 18 }, - { RELOC_MIPS::R_MIPS_PC19_S2, 19 }, - { RELOC_MIPS::R_MIPS_PC21_S2, 21 }, - { RELOC_MIPS::R_MIPS_PC26_S2, 26 }, - { RELOC_MIPS::R_MIPS_PC32, 32 }, - { RELOC_MIPS::R_MIPS_PCHI16, 16 }, - { RELOC_MIPS::R_MIPS_PCLO16, 16 }, - { RELOC_MIPS::R_MIPS_PJUMP, 0 }, - { RELOC_MIPS::R_MIPS_REL16, 16 }, - { RELOC_MIPS::R_MIPS_REL32, 32 }, - { RELOC_MIPS::R_MIPS_RELGOT, 32 }, - { RELOC_MIPS::R_MIPS_SCN_DISP, 32 }, - { RELOC_MIPS::R_MIPS_SHIFT5, 5 }, - { RELOC_MIPS::R_MIPS_SHIFT6, 6 }, - { RELOC_MIPS::R_MIPS_SUB, 64 }, - { RELOC_MIPS::R_MIPS_TLS_DTPMOD32, 32 }, - { RELOC_MIPS::R_MIPS_TLS_DTPMOD64, 64 }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL32, 32 }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL64, 64 }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL_HI16, 16 }, - { RELOC_MIPS::R_MIPS_TLS_DTPREL_LO16, 16 }, - { RELOC_MIPS::R_MIPS_TLS_GD, 16 }, - { RELOC_MIPS::R_MIPS_TLS_GOTTPREL, 16 }, - { RELOC_MIPS::R_MIPS_TLS_LDM, 16 }, - { RELOC_MIPS::R_MIPS_TLS_TPREL64, 32 }, - { RELOC_MIPS::R_MIPS_TLS_TPREL64, 64 }, - { RELOC_MIPS::R_MIPS_TLS_TPREL_HI16, 16 }, - { RELOC_MIPS::R_MIPS_TLS_TPREL_LO16, 16 }, - { RELOC_MIPS::R_MIPS_UNUSED1, 0 }, - { RELOC_MIPS::R_MIPS_UNUSED2, 0 }, - { RELOC_MIPS::R_MIPS_UNUSED3, 0 }, +int32_t get_R_MIPS(Relocation::TYPE R) { + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::MICROMIPS_26_S1, 26 ), + std::pair(Relocation::TYPE::MICROMIPS_CALL16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_CALL_HI16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_CALL_LO16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GOT16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GOT_DISP, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GOT_HI16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GOT_LO16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GOT_OFST, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GOT_PAGE, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GPREL16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_GPREL7_S2, 7 ), + std::pair(Relocation::TYPE::MICROMIPS_HI0_LO16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_HI16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_HIGHER, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_HIGHEST, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_JALR, 32 ), + std::pair(Relocation::TYPE::MICROMIPS_LITERAL, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_LO16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_PC10_S1, 10 ), + std::pair(Relocation::TYPE::MICROMIPS_PC16_S1, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_PC18_S3, 18 ), + std::pair(Relocation::TYPE::MICROMIPS_PC19_S2, 19 ), + std::pair(Relocation::TYPE::MICROMIPS_PC21_S2, 21 ), + std::pair(Relocation::TYPE::MICROMIPS_PC23_S2, 23 ), + std::pair(Relocation::TYPE::MICROMIPS_PC26_S2, 26 ), + std::pair(Relocation::TYPE::MICROMIPS_PC7_S1, 7 ), + std::pair(Relocation::TYPE::MICROMIPS_SCN_DISP, 32 ), + std::pair(Relocation::TYPE::MICROMIPS_SUB, 64 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_DTPREL_HI16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_DTPREL_LO16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_GD, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_GOTTPREL, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_LDM, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_TPREL_HI16, 16 ), + std::pair(Relocation::TYPE::MICROMIPS_TLS_TPREL_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_16, 16 ), + std::pair(Relocation::TYPE::MIPS16_26, 26 ), + std::pair(Relocation::TYPE::MIPS16_CALL16, 16 ), + std::pair(Relocation::TYPE::MIPS16_GOT16, 16 ), + std::pair(Relocation::TYPE::MIPS16_GPREL, 16 ), + std::pair(Relocation::TYPE::MIPS16_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS16_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_DTPREL_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_DTPREL_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_GD, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_GOTTPREL, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_LDM, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_TPREL_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS16_TLS_TPREL_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_ADD_IMMEDIATE, 0 ), + std::pair(Relocation::TYPE::MIPS_26, 26 ), + std::pair(Relocation::TYPE::MIPS_32, 32 ), + std::pair(Relocation::TYPE::MIPS_64, 64 ), + std::pair(Relocation::TYPE::MIPS_CALL16, 16 ), + std::pair(Relocation::TYPE::MIPS_CALL_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS_CALL_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_COPY, 0 ), + std::pair(Relocation::TYPE::MIPS_DELETE, 32 ), + std::pair(Relocation::TYPE::MIPS_EH, 32 ), + std::pair(Relocation::TYPE::MIPS_GLOB_DAT, 32 ), + std::pair(Relocation::TYPE::MIPS_GOT16, 16 ), + std::pair(Relocation::TYPE::MIPS_GOT_DISP, 16 ), + std::pair(Relocation::TYPE::MIPS_GOT_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS_GOT_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_GOT_OFST, 16 ), + std::pair(Relocation::TYPE::MIPS_GOT_PAGE, 16 ), + std::pair(Relocation::TYPE::MIPS_GPREL16, 16 ), + std::pair(Relocation::TYPE::MIPS_GPREL32, 32 ), + std::pair(Relocation::TYPE::MIPS_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS_HIGHER, 16 ), + std::pair(Relocation::TYPE::MIPS_HIGHEST, 16 ), + std::pair(Relocation::TYPE::MIPS_INSERT_A, 32 ), + std::pair(Relocation::TYPE::MIPS_INSERT_B, 32 ), + std::pair(Relocation::TYPE::MIPS_JALR, 32 ), + std::pair(Relocation::TYPE::MIPS_JUMP_SLOT, 64 ), + std::pair(Relocation::TYPE::MIPS_LITERAL, 16 ), + std::pair(Relocation::TYPE::MIPS_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_NONE, 0 ), + std::pair(Relocation::TYPE::MIPS_NUM, 0 ), + std::pair(Relocation::TYPE::MIPS_PC16, 16 ), + std::pair(Relocation::TYPE::MIPS_PC18_S3, 18 ), + std::pair(Relocation::TYPE::MIPS_PC19_S2, 19 ), + std::pair(Relocation::TYPE::MIPS_PC21_S2, 21 ), + std::pair(Relocation::TYPE::MIPS_PC26_S2, 26 ), + std::pair(Relocation::TYPE::MIPS_PC32, 32 ), + std::pair(Relocation::TYPE::MIPS_PCHI16, 16 ), + std::pair(Relocation::TYPE::MIPS_PCLO16, 16 ), + std::pair(Relocation::TYPE::MIPS_PJUMP, 0 ), + std::pair(Relocation::TYPE::MIPS_REL16, 16 ), + std::pair(Relocation::TYPE::MIPS_REL32, 32 ), + std::pair(Relocation::TYPE::MIPS_RELGOT, 32 ), + std::pair(Relocation::TYPE::MIPS_SCN_DISP, 32 ), + std::pair(Relocation::TYPE::MIPS_SHIFT5, 5 ), + std::pair(Relocation::TYPE::MIPS_SHIFT6, 6 ), + std::pair(Relocation::TYPE::MIPS_SUB, 64 ), + std::pair(Relocation::TYPE::MIPS_TLS_DTPMOD32, 32 ), + std::pair(Relocation::TYPE::MIPS_TLS_DTPMOD64, 64 ), + std::pair(Relocation::TYPE::MIPS_TLS_DTPREL32, 32 ), + std::pair(Relocation::TYPE::MIPS_TLS_DTPREL64, 64 ), + std::pair(Relocation::TYPE::MIPS_TLS_DTPREL_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS_TLS_DTPREL_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_TLS_GD, 16 ), + std::pair(Relocation::TYPE::MIPS_TLS_GOTTPREL, 16 ), + std::pair(Relocation::TYPE::MIPS_TLS_LDM, 16 ), + std::pair(Relocation::TYPE::MIPS_TLS_TPREL64, 32 ), + std::pair(Relocation::TYPE::MIPS_TLS_TPREL64, 64 ), + std::pair(Relocation::TYPE::MIPS_TLS_TPREL_HI16, 16 ), + std::pair(Relocation::TYPE::MIPS_TLS_TPREL_LO16, 16 ), + std::pair(Relocation::TYPE::MIPS_UNUSED1, 0 ), + std::pair(Relocation::TYPE::MIPS_UNUSED2, 0 ), + std::pair(Relocation::TYPE::MIPS_UNUSED3, 0 ), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; } -int32_t get_reloc_size(RELOC_LOONGARCH R) { - CONST_MAP(RELOC_LOONGARCH, uint32_t, 89) SIZES { - {RELOC_LOONGARCH::R_LARCH_NONE, 0}, - {RELOC_LOONGARCH::R_LARCH_32, 32}, - {RELOC_LOONGARCH::R_LARCH_64, 64}, - {RELOC_LOONGARCH::R_LARCH_RELATIVE, 32}, - {RELOC_LOONGARCH::R_LARCH_COPY, 0}, - {RELOC_LOONGARCH::R_LARCH_JUMP_SLOT, 64}, - {RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD32, 32}, - {RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD64, 64}, - {RELOC_LOONGARCH::R_LARCH_TLS_DTPREL32, 32}, - {RELOC_LOONGARCH::R_LARCH_TLS_DTPREL64, 64}, - {RELOC_LOONGARCH::R_LARCH_TLS_TPREL32, 32}, - {RELOC_LOONGARCH::R_LARCH_TLS_TPREL64, 64}, - {RELOC_LOONGARCH::R_LARCH_IRELATIVE, 32}, - {RELOC_LOONGARCH::R_LARCH_MARK_LA, 0}, - {RELOC_LOONGARCH::R_LARCH_MARK_PCREL, 0}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PCREL, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_ABSOLUTE, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_DUP, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_GPREL, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_TPREL, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GOT, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GD, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PLT_PCREL, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_ASSERT, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_NOT, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_SUB, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_SL, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_SR, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_ADD, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_AND, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_IF_ELSE, 32}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_5, 5}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U_10_12, 12}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_12, 12}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16, 16}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16_S2, 16}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_5_20, 20}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_5_10_16_S2, 21}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_10_10_16_S2, 26}, - {RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U, 32}, - {RELOC_LOONGARCH::R_LARCH_ADD8, 8}, - {RELOC_LOONGARCH::R_LARCH_ADD16, 16}, - {RELOC_LOONGARCH::R_LARCH_ADD24, 24}, - {RELOC_LOONGARCH::R_LARCH_ADD32, 32}, - {RELOC_LOONGARCH::R_LARCH_ADD64, 64}, - {RELOC_LOONGARCH::R_LARCH_SUB8, 8}, - {RELOC_LOONGARCH::R_LARCH_SUB16, 16}, - {RELOC_LOONGARCH::R_LARCH_SUB24, 24}, - {RELOC_LOONGARCH::R_LARCH_SUB32, 32}, - {RELOC_LOONGARCH::R_LARCH_SUB64, 64}, - {RELOC_LOONGARCH::R_LARCH_GNU_VTINHERIT, 0}, - {RELOC_LOONGARCH::R_LARCH_GNU_VTENTRY, 0}, - {RELOC_LOONGARCH::R_LARCH_B16, 16}, - {RELOC_LOONGARCH::R_LARCH_B21, 21}, - {RELOC_LOONGARCH::R_LARCH_B26, 26}, - {RELOC_LOONGARCH::R_LARCH_ABS_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_ABS_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_ABS64_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_ABS64_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_PCALA_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_PCALA_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_PCALA64_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_PCALA64_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_GOT_PC_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_GOT_PC_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_GOT64_PC_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_GOT64_PC_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_GOT_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_GOT_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_GOT64_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_GOT64_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_LE_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_LE_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_LE64_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_LE64_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE_LO12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE64_LO20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_IE64_HI12, 12}, - {RELOC_LOONGARCH::R_LARCH_TLS_LD_PC_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_LD_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_GD_PC_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_TLS_GD_HI20, 20}, - {RELOC_LOONGARCH::R_LARCH_32_PCREL, 32}, - {RELOC_LOONGARCH::R_LARCH_RELAX, 0}, +int32_t get_R_LARCH(Relocation::TYPE R) { + CONST_MAP_ALT SIZES { + std::pair(Relocation::TYPE::LARCH_NONE, 0), + std::pair(Relocation::TYPE::LARCH_32, 32), + std::pair(Relocation::TYPE::LARCH_64, 64), + std::pair(Relocation::TYPE::LARCH_RELATIVE, 32), + std::pair(Relocation::TYPE::LARCH_COPY, 0), + std::pair(Relocation::TYPE::LARCH_JUMP_SLOT, 64), + std::pair(Relocation::TYPE::LARCH_TLS_DTPMOD32, 32), + std::pair(Relocation::TYPE::LARCH_TLS_DTPMOD64, 64), + std::pair(Relocation::TYPE::LARCH_TLS_DTPREL32, 32), + std::pair(Relocation::TYPE::LARCH_TLS_DTPREL64, 64), + std::pair(Relocation::TYPE::LARCH_TLS_TPREL32, 32), + std::pair(Relocation::TYPE::LARCH_TLS_TPREL64, 64), + std::pair(Relocation::TYPE::LARCH_IRELATIVE, 32), + std::pair(Relocation::TYPE::LARCH_MARK_LA, 0), + std::pair(Relocation::TYPE::LARCH_MARK_PCREL, 0), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_PCREL, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_ABSOLUTE, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_DUP, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_GPREL, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_TLS_TPREL, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_TLS_GOT, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_TLS_GD, 32), + std::pair(Relocation::TYPE::LARCH_SOP_PUSH_PLT_PCREL, 32), + std::pair(Relocation::TYPE::LARCH_SOP_ASSERT, 32), + std::pair(Relocation::TYPE::LARCH_SOP_NOT, 32), + std::pair(Relocation::TYPE::LARCH_SOP_SUB, 32), + std::pair(Relocation::TYPE::LARCH_SOP_SL, 32), + std::pair(Relocation::TYPE::LARCH_SOP_SR, 32), + std::pair(Relocation::TYPE::LARCH_SOP_ADD, 32), + std::pair(Relocation::TYPE::LARCH_SOP_AND, 32), + std::pair(Relocation::TYPE::LARCH_SOP_IF_ELSE, 32), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_10_5, 5), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_U_10_12, 12), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_10_12, 12), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_10_16, 16), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_10_16_S2, 16), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_5_20, 20), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_0_5_10_16_S2, 21), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_S_0_10_10_16_S2, 26), + std::pair(Relocation::TYPE::LARCH_SOP_POP_32_U, 32), + std::pair(Relocation::TYPE::LARCH_ADD8, 8), + std::pair(Relocation::TYPE::LARCH_ADD16, 16), + std::pair(Relocation::TYPE::LARCH_ADD24, 24), + std::pair(Relocation::TYPE::LARCH_ADD32, 32), + std::pair(Relocation::TYPE::LARCH_ADD64, 64), + std::pair(Relocation::TYPE::LARCH_SUB8, 8), + std::pair(Relocation::TYPE::LARCH_SUB16, 16), + std::pair(Relocation::TYPE::LARCH_SUB24, 24), + std::pair(Relocation::TYPE::LARCH_SUB32, 32), + std::pair(Relocation::TYPE::LARCH_SUB64, 64), + std::pair(Relocation::TYPE::LARCH_GNU_VTINHERIT, 0), + std::pair(Relocation::TYPE::LARCH_GNU_VTENTRY, 0), + std::pair(Relocation::TYPE::LARCH_B16, 16), + std::pair(Relocation::TYPE::LARCH_B21, 21), + std::pair(Relocation::TYPE::LARCH_B26, 26), + std::pair(Relocation::TYPE::LARCH_ABS_HI20, 20), + std::pair(Relocation::TYPE::LARCH_ABS_LO12, 12), + std::pair(Relocation::TYPE::LARCH_ABS64_LO20, 20), + std::pair(Relocation::TYPE::LARCH_ABS64_HI12, 12), + std::pair(Relocation::TYPE::LARCH_PCALA_HI20, 20), + std::pair(Relocation::TYPE::LARCH_PCALA_LO12, 12), + std::pair(Relocation::TYPE::LARCH_PCALA64_LO20, 20), + std::pair(Relocation::TYPE::LARCH_PCALA64_HI12, 12), + std::pair(Relocation::TYPE::LARCH_GOT_PC_HI20, 20), + std::pair(Relocation::TYPE::LARCH_GOT_PC_LO12, 12), + std::pair(Relocation::TYPE::LARCH_GOT64_PC_LO20, 20), + std::pair(Relocation::TYPE::LARCH_GOT64_PC_HI12, 12), + std::pair(Relocation::TYPE::LARCH_GOT_HI20, 20), + std::pair(Relocation::TYPE::LARCH_GOT_LO12, 12), + std::pair(Relocation::TYPE::LARCH_GOT64_LO20, 20), + std::pair(Relocation::TYPE::LARCH_GOT64_HI12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_LE_HI20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_LE_LO12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_LE64_LO20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_LE64_HI12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_IE_PC_HI20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_IE_PC_LO12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_IE64_PC_LO20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_IE64_PC_HI12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_IE_HI20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_IE_LO12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_IE64_LO20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_IE64_HI12, 12), + std::pair(Relocation::TYPE::LARCH_TLS_LD_PC_HI20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_LD_HI20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_GD_PC_HI20, 20), + std::pair(Relocation::TYPE::LARCH_TLS_GD_HI20, 20), + std::pair(Relocation::TYPE::LARCH_32_PCREL, 32), + std::pair(Relocation::TYPE::LARCH_RELAX, 0), }; const auto it = SIZES.find(R); return it == SIZES.end() ? -1 : it->second; } +int32_t get_reloc_size(Relocation::TYPE type) { + auto raw_type = static_cast(type); + const uint64_t ID = (raw_type >> Relocation::R_BIT) << Relocation::R_BIT; + + if (ID == Relocation::R_X64) { + return get_R_X64(type); + } + if (ID == Relocation::R_X86) { + return get_R_X86(type); + } + if (ID == Relocation::R_AARCH64) { + return get_R_AARCH64(type); + } + if (ID == Relocation::R_ARM) { + return get_R_ARM(type); + } + if (ID == Relocation::R_LARCH) { + return get_R_LARCH(type); + } + if (ID == Relocation::R_MIPS) { + return get_R_MIPS(type); + } + if (ID == Relocation::R_PPC) { + return get_R_PPC(type); + } + if (ID == Relocation::R_PPC64) { + return get_R_PPC64(type); + } + return -1; +} + } } diff --git a/src/ELF/RelocationStrings.cpp b/src/ELF/RelocationStrings.cpp new file mode 100644 index 0000000000..78713d8fbf --- /dev/null +++ b/src/ELF/RelocationStrings.cpp @@ -0,0 +1,215 @@ +/* Copyright 2017 - 2023 R. Thomas + * Copyright 2017 - 2023 Quarkslab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "LIEF/ELF/Relocation.hpp" +#include "frozen.hpp" +#include "logging.hpp" + +#define ELF_RELOC(X, _) std::pair(Relocation::TYPE::X, #X), + +namespace LIEF { +namespace ELF { +template +const char* to_string(Relocation::TYPE type); + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/x86_64.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/AArch64.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/ARM.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + #define ENTRY(X) std::pair(Relocation::TYPE::X, #X) + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/Hexagon.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + #define ENTRY(X) std::pair(Relocation::TYPE::X, #X) + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/i386.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/LoongArch.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/Mips.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/PowerPC.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/PowerPC64.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/Sparc.def" + }; + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +template<> +const char* to_string(Relocation::TYPE type) { + #define ENTRY(X) std::pair(Relocation::TYPE::X, #X) + STRING_MAP enums2str { + #include "LIEF/ELF/Relocations/SystemZ.def" + }; + #undef ENTRY + + if (auto it = enums2str.find(type); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +const char* to_string(Relocation::TYPE type) { + auto raw_type = static_cast(type); + + const uint64_t ID = (raw_type >> Relocation::R_BIT) << Relocation::R_BIT; + + if (ID == Relocation::R_X64) { + return to_string(type); + } + + if (ID == Relocation::R_AARCH64) { + return to_string(type); + } + + if (ID == Relocation::R_ARM) { + return to_string(type); + } + + if (ID == Relocation::R_HEXAGON) { + return to_string(type); + } + + if (ID == Relocation::R_X86) { + return to_string(type); + } + + if (ID == Relocation::R_LARCH) { + return to_string(type); + } + + if (ID == Relocation::R_MIPS) { + return to_string(type); + } + + if (ID == Relocation::R_PPC) { + return to_string(type); + } + + if (ID == Relocation::R_PPC64) { + return to_string(type); + } + + if (ID == Relocation::R_SPARC) { + return to_string(type); + } + + if (ID == Relocation::R_SYSZ) { + return to_string(type); + } + + return "UNKNOWN"; +} +} +} diff --git a/src/ELF/Section.cpp b/src/ELF/Section.cpp index b9842607f9..735494e96a 100644 --- a/src/ELF/Section.cpp +++ b/src/ELF/Section.cpp @@ -18,42 +18,77 @@ #include #include -#include "LIEF/ELF/Parser.hpp" - #include "logging.hpp" +#include "frozen.hpp" +#include "fmt_formatter.hpp" -#include "LIEF/ELF/hash.hpp" - -#include "LIEF/ELF/EnumToString.hpp" +#include "LIEF/Visitor.hpp" #include "LIEF/ELF/Section.hpp" #include "LIEF/ELF/Segment.hpp" +#include "LIEF/ELF/EnumToString.hpp" + #include "ELF/DataHandler/Handler.hpp" #include "ELF/Structures.hpp" +FMT_FORMATTER(LIEF::ELF::Section::FLAGS, LIEF::ELF::to_string); +FMT_FORMATTER(LIEF::ELF::Section::TYPE, LIEF::ELF::to_string); + namespace LIEF { namespace ELF { -Section::~Section() = default; -Section::Section() = default; - -Section::Section(const details::Elf64_Shdr& header) : - type_{static_cast(header.sh_type)}, - flags_{header.sh_flags}, - original_size_{header.sh_size}, - link_{header.sh_link}, - info_{header.sh_info}, - address_align_{header.sh_addralign}, - entry_size_{header.sh_entsize} -{ - virtual_address_ = header.sh_addr; - offset_ = header.sh_offset; - size_ = header.sh_size; +static constexpr uint64_t SHF_MASKPROC = 0xf0000000; +static constexpr uint64_t SHT_LOPROC = 0x70000000; +static constexpr uint64_t SHT_HIPROC = 0x7fffffff; + +static constexpr auto ARRAY_FLAGS = { + Section::FLAGS::NONE, Section::FLAGS::WRITE, + Section::FLAGS::ALLOC, Section::FLAGS::EXECINSTR, + Section::FLAGS::MERGE, Section::FLAGS::STRINGS, + Section::FLAGS::INFO_LINK, Section::FLAGS::LINK_ORDER, + Section::FLAGS::OS_NONCONFORMING, Section::FLAGS::GROUP, + Section::FLAGS::TLS, Section::FLAGS::COMPRESSED, + Section::FLAGS::GNU_RETAIN, Section::FLAGS::EXCLUDE, + Section::FLAGS::XCORE_SHF_DP_SECTION, Section::FLAGS::XCORE_SHF_CP_SECTION, + Section::FLAGS::X86_64_LARGE, Section::FLAGS::HEX_GPREL, + Section::FLAGS::MIPS_NODUPES, Section::FLAGS::MIPS_NAMES, + Section::FLAGS::MIPS_LOCAL, Section::FLAGS::MIPS_NOSTRIP, + Section::FLAGS::MIPS_GPREL, Section::FLAGS::MIPS_MERGE, + Section::FLAGS::MIPS_ADDR, Section::FLAGS::MIPS_STRING, + Section::FLAGS::ARM_PURECODE, +}; + +Section::TYPE Section::type_from(uint32_t value, ARCH arch) { + if (SHT_LOPROC <= value && value <= SHT_HIPROC) { + switch (arch) { + case ARCH::ARM: + return TYPE(value + (uint64_t(TYPE::_ARM_ID_) << uint8_t(TYPE::_ID_SHIFT_))); + + case ARCH::HEXAGON: + return TYPE(value + (uint64_t(TYPE::_HEX_ID_) << uint8_t(TYPE::_ID_SHIFT_))); + + case ARCH::X86_64: + return TYPE(value + (uint64_t(TYPE::_X86_64_ID_) << uint8_t(TYPE::_ID_SHIFT_))); + + case ARCH::MIPS: + return TYPE(value + (uint64_t(TYPE::_MIPS_ID_) << uint8_t(TYPE::_ID_SHIFT_))); + + default: + { + LIEF_ERR("Arch-specific section: 0x{:08x} is not recognized for {}", + value, to_string(arch)); + return TYPE::SHT_NULL; + } + } + } + return TYPE(value); } -Section::Section(const details::Elf32_Shdr& header) : - type_{static_cast(header.sh_type)}, +template +Section::Section(const T& header, ARCH arch) : + arch_{arch}, + type_{type_from(header.sh_type, arch)}, flags_{header.sh_flags}, original_size_{header.sh_size}, link_{header.sh_link}, @@ -66,20 +101,8 @@ Section::Section(const details::Elf32_Shdr& header) : size_ = header.sh_size; } -Section::Section(const std::string& name, ELF_SECTION_TYPES type) : - LIEF::Section{name}, - type_{type} -{} - - -Section::Section(const uint8_t *data, ELF_CLASS type) -{ - if (type == ELF_CLASS::ELFCLASS32) { - *this = {*reinterpret_cast(data)}; - } else if (type == ELF_CLASS::ELFCLASS64) { - *this = {*reinterpret_cast(data)}; - } -} +template Section::Section(const details::Elf32_Shdr& header, ARCH); +template Section::Section(const details::Elf64_Shdr& header, ARCH); Section& Section::operator=(Section other) { swap(other); @@ -88,6 +111,7 @@ Section& Section::operator=(Section other) { Section::Section(const Section& other) : LIEF::Section{other}, + arch_{other.arch_}, type_{other.type_}, flags_{other.flags_}, original_size_{other.original_size_}, @@ -97,16 +121,15 @@ Section::Section(const Section& other) : entry_size_{other.entry_size_}, is_frame_{other.is_frame_}, content_c_{other.content_c_} -{ -} +{} void Section::swap(Section& other) { - std::swap(name_, other.name_); std::swap(virtual_address_, other.virtual_address_); std::swap(offset_, other.offset_); std::swap(size_, other.size_); + std::swap(arch_, other.arch_); std::swap(type_, other.type_); std::swap(flags_, other.flags_); std::swap(original_size_, other.original_size_); @@ -120,20 +143,6 @@ void Section::swap(Section& other) { std::swap(content_c_, other.content_c_); } - -ELF_SECTION_TYPES Section::type() const { - return type_; -} - -uint64_t Section::flags() const { - return flags_; -} - -bool Section::has(ELF_SECTION_FLAGS flag) const { - return (flags() & static_cast(flag)) != 0; -} - - bool Section::has(const Segment& segment) const { auto it_segment = std::find_if(std::begin(segments_), std::end(segments_), [&segment] (Segment* s) { @@ -142,42 +151,15 @@ bool Section::has(const Segment& segment) const { return it_segment != std::end(segments_); } -uint64_t Section::file_offset() const { - return offset(); -} - -uint64_t Section::original_size() const { - return original_size_; -} - -uint64_t Section::information() const { - return info_; -} - -uint64_t Section::entry_size() const { - return entry_size_; -} - -uint64_t Section::alignment() const { - return address_align_; -} - -uint64_t Section::size() const { - return size_; -} - -uint64_t Section::offset() const { - return offset_; -} - void Section::size(uint64_t size) { if (datahandler_ != nullptr && !is_frame()) { if (auto node = datahandler_->get(file_offset(), this->size(), DataHandler::Node::SECTION)) { node->get().size(size); } else { - if (type() != ELF_SECTION_TYPES::SHT_NOBITS) { + if (type() != TYPE::NOBITS) { LIEF_ERR("Node not found. Can't resize the section {}", name()); + std::abort(); } } } @@ -190,7 +172,7 @@ void Section::offset(uint64_t offset) { if (auto node = datahandler_->get(file_offset(), size(), DataHandler::Node::SECTION)) { node->get().offset(offset); } else { - if (type() != ELF_SECTION_TYPES::SHT_NOBITS) { + if (type() != TYPE::NOBITS) { LIEF_WARN("Node not found. Can't change the offset of the section {}", name()); } } @@ -207,13 +189,13 @@ span Section::content() const { return content_c_; } - if (size() > Parser::MAX_SECTION_SIZE) { + if (size() > MAX_SECTION_SIZE) { return {}; } auto res = datahandler_->get(offset(), size(), DataHandler::Node::SECTION); if (!res) { - if (type() != ELF_SECTION_TYPES::SHT_NOBITS) { + if (type() != TYPE::NOBITS) { LIEF_WARN("Section '{}' does not have content", name()); } return {}; @@ -224,16 +206,11 @@ span Section::content() const { return {ptr, ptr + node.size()}; } -uint32_t Section::link() const { - return link_; -} - -std::set Section::flags_list() const { - std::set flags; - std::copy_if(std::begin(details::section_flags_array), std::end(details::section_flags_array), - std::inserter(flags, std::begin(flags)), - [this] (ELF_SECTION_FLAGS f) { return has(f); }); - +std::vector Section::flags_list() const { + std::vector flags; + std::copy_if(std::begin(ARRAY_FLAGS), std::end(ARRAY_FLAGS), + std::back_inserter(flags), + [this] (FLAGS f) { return has(f); }); return flags; } @@ -242,7 +219,7 @@ void Section::content(const std::vector& data) { return; } - if (!data.empty() && type() == ELF_SECTION_TYPES::SHT_NOBITS) { + if (!data.empty() && type() == TYPE::NOBITS) { LIEF_INFO("You inserted 0x{:x} bytes in section '{}' which has SHT_NOBITS type", data.size(), name()); } @@ -286,7 +263,7 @@ void Section::content(std::vector&& data) { if (is_frame()) { return; } - if (!data.empty() && type() == ELF_SECTION_TYPES::SHT_NOBITS) { + if (!data.empty() && type() == TYPE::NOBITS) { LIEF_INFO("You inserted 0x{:x} bytes in section '{}' which has SHT_NOBITS type", data.size(), name()); } @@ -322,56 +299,51 @@ void Section::content(std::vector&& data) { std::begin(binary_content) + node.offset()); } -void Section::type(ELF_SECTION_TYPES type) { - type_ = type; -} - -void Section::flags(uint64_t flags) { - flags_ = flags; -} +bool Section::has(Section::FLAGS flag) const { + if ((flags_ & SHF_MASKPROC) == 0) { + return (flags_ & (static_cast(flag) & FLAG_MASK)) != 0; + } -void Section::add(ELF_SECTION_FLAGS flag) { - flags(flags() | static_cast(flag)); -} + uint64_t raw_flag = static_cast(flag); + size_t id = raw_flag >> uint8_t(FLAGS::_ID_SHIFT_); -void Section::remove(ELF_SECTION_FLAGS flag) { - flags(flags() & (~ static_cast(flag))); -} + if (id > 0 && arch_ == ARCH::NONE) { + LIEF_WARN("Missing architecture. Can't determine whether the flag is present"); + return false; + } -void Section::clear_flags() { - flags(0); -} + if (id == uint8_t(FLAGS::_XCORE_ID_) && arch_ != ARCH::XCORE) { + return false; + } -void Section::file_offset(uint64_t offset) { - this->offset(offset); -} + if (id == uint8_t(FLAGS::_X86_64_ID_) && arch_ != ARCH::X86_64) { + return false; + } -void Section::link(uint32_t link) { - link_ = link; -} + if (id == uint8_t(FLAGS::_HEX_ID_) && arch_ != ARCH::HEXAGON) { + return false; + } -void Section::information(uint32_t info) { - info_ = info; -} + if (id == uint8_t(FLAGS::_MIPS_ID_) && arch_ != ARCH::MIPS) { + return false; + } -void Section::alignment(uint64_t alignment) { - address_align_ = alignment; -} + if (id == uint8_t(FLAGS::_ARM_ID_) && arch_ != ARCH::ARM) { + return false; + } -void Section::entry_size(uint64_t entry_size) { - entry_size_ = entry_size; + return (flags_ & (static_cast(flag) & FLAG_MASK)) != 0; } - -Section::it_segments Section::segments() { - return segments_; +void Section::add(Section::FLAGS flag) { + flags(flags() | (static_cast(flag) & FLAG_MASK)); } -Section::it_const_segments Section::segments() const { - return segments_; +void Section::remove(Section::FLAGS flag) { + const auto raw_flag = static_cast(flag) & FLAG_MASK; + flags(flags() & (~ raw_flag)); } - Section& Section::clear(uint8_t value) { if (is_frame()) { return *this; @@ -391,28 +363,12 @@ Section& Section::clear(uint8_t value) { std::fill_n(std::begin(binary_content) + node.offset(), size(), value); return *this; - } void Section::accept(Visitor& visitor) const { visitor.visit(*this); } - -Section& Section::operator+=(ELF_SECTION_FLAGS c) { - add(c); - return *this; -} - -Section& Section::operator-=(ELF_SECTION_FLAGS c) { - remove(c); - return *this; -} - - - - - span Section::writable_content() { if (is_frame()) { return {}; @@ -421,34 +377,108 @@ span Section::writable_content() { return {const_cast(ref.data()), ref.size()}; } - std::ostream& operator<<(std::ostream& os, const Section& section) { const auto& flags = section.flags_list(); - std::string flags_str = std::accumulate( - std::begin(flags), std::end(flags), std::string{}, - [] (const std::string& a, ELF_SECTION_FLAGS b) { - return a.empty() ? to_string(b) : a + " " + to_string(b); - }); - - Section::it_const_segments segments = section.segments(); - std::string segments_str = std::accumulate( - std::begin(segments), std::end(segments), std::string{}, - [] (const std::string& a, const Segment& segment) { - return a.empty() ? to_string(segment.type()) : a + " " + to_string(segment.type()); - }); - - os << std::hex; - os << std::left - << std::setw(20) << section.name() - << std::setw(15) << to_string(section.type()) - << std::setw(10) << section.virtual_address() - << std::setw(10) << section.size() - << std::setw(10) << section.file_offset() - << std::setw(10) << section.entropy() - << std::setw(30) << flags_str - << std::setw(15) << segments_str; + + os << fmt::format("{} ({}) 0x{:08x}/0x{:08x} 0x{:04x} {} {}", + section.name(), section.type(), section.virtual_address(), + section.file_offset(), section.size(), + section.entropy(), fmt::to_string(flags)); return os; } + + +const char* to_string(Section::TYPE e) { + #define ENTRY(X) std::pair(Section::TYPE::X, #X) + STRING_MAP enums2str { + ENTRY(SHT_NULL), + ENTRY(PROGBITS), + ENTRY(SYMTAB), + ENTRY(STRTAB), + ENTRY(RELA), + ENTRY(HASH), + ENTRY(DYNAMIC), + ENTRY(NOTE), + ENTRY(NOBITS), + ENTRY(REL), + ENTRY(SHLIB), + ENTRY(DYNSYM), + ENTRY(INIT_ARRAY), + ENTRY(FINI_ARRAY), + ENTRY(PREINIT_ARRAY), + ENTRY(GROUP), + ENTRY(SYMTAB_SHNDX), + ENTRY(RELR), + + ENTRY(ANDROID_REL), + ENTRY(ANDROID_RELA), + ENTRY(LLVM_ADDRSIG), + ENTRY(ANDROID_RELR), + ENTRY(GNU_ATTRIBUTES), + ENTRY(GNU_HASH), + ENTRY(GNU_VERDEF), + ENTRY(GNU_VERNEED), + ENTRY(GNU_VERSYM), + + ENTRY(ARM_EXIDX), + ENTRY(ARM_PREEMPTMAP), + ENTRY(ARM_ATTRIBUTES), + ENTRY(ARM_DEBUGOVERLAY), + ENTRY(ARM_OVERLAYSECTION), + ENTRY(HEX_ORDERED), + ENTRY(X86_64_UNWIND), + ENTRY(MIPS_REGINFO), + ENTRY(MIPS_OPTIONS), + ENTRY(MIPS_ABIFLAGS), + }; + #undef ENTRY + + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +const char* to_string(Section::FLAGS e) { + #define ENTRY(X) std::pair(Section::FLAGS::X, #X) + STRING_MAP enums2str { + ENTRY(NONE), + ENTRY(WRITE), + ENTRY(ALLOC), + ENTRY(EXECINSTR), + ENTRY(MERGE), + ENTRY(STRINGS), + ENTRY(INFO_LINK), + ENTRY(LINK_ORDER), + ENTRY(OS_NONCONFORMING), + ENTRY(GROUP), + ENTRY(TLS), + ENTRY(COMPRESSED), + ENTRY(GNU_RETAIN), + ENTRY(EXCLUDE), + ENTRY(XCORE_SHF_DP_SECTION), + ENTRY(XCORE_SHF_CP_SECTION), + ENTRY(X86_64_LARGE), + ENTRY(HEX_GPREL), + + ENTRY(MIPS_NODUPES), + ENTRY(MIPS_NAMES), + ENTRY(MIPS_LOCAL), + ENTRY(MIPS_NOSTRIP), + ENTRY(MIPS_GPREL), + ENTRY(MIPS_MERGE), + ENTRY(MIPS_ADDR), + ENTRY(MIPS_STRING), + ENTRY(ARM_PURECODE), + }; + #undef ENTRY + + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + } } diff --git a/src/ELF/Segment.cpp b/src/ELF/Segment.cpp index 140b67c856..0cece477c3 100644 --- a/src/ELF/Segment.cpp +++ b/src/ELF/Segment.cpp @@ -18,8 +18,7 @@ #include #include "logging.hpp" - - +#include "frozen.hpp" #include "LIEF/ELF/hash.hpp" @@ -30,19 +29,46 @@ #include "ELF/DataHandler/Handler.hpp" #include "ELF/Structures.hpp" - namespace LIEF { namespace ELF { -Segment::Segment() = default; -Segment::~Segment() = default; +static constexpr auto PT_LOPROC = 0x70000000; +static constexpr auto PT_HIPROC = 0x7fffffff; + +Segment::TYPE Segment::type_from(uint64_t value, ARCH arch) { + if (PT_LOPROC <= value && value <= PT_HIPROC) { + if (arch == ARCH::NONE) { + LIEF_WARN("Segment type 0x{:08x} requires to know the architecture", value); + return TYPE::UNKNOWN; + } + switch (arch) { + case ARCH::ARM: + return TYPE(value | PT_ARM); + + case ARCH::AARCH64: + return TYPE(value | PT_AARCH64); + + case ARCH::MIPS: + return TYPE(value | PT_MIPS); -Segment& Segment::operator=(Segment&&) = default; -Segment::Segment(Segment&&) = default; + case ARCH::RISCV: + return TYPE(value | PT_RISCV); + + default: + { + LIEF_WARN("Segment type 0x{:08x} is unknown for the architecture {}", + value, to_string(arch)); + return TYPE::UNKNOWN; + } + } + } + return TYPE(value); +} Segment::Segment(const Segment& other) : Object{other}, type_{other.type_}, + arch_{other.arch_}, flags_{other.flags_}, file_offset_{other.file_offset_}, virtual_address_{other.virtual_address_}, @@ -54,9 +80,11 @@ Segment::Segment(const Segment& other) : content_c_{other.content_c_} {} -Segment::Segment(const details::Elf64_Phdr& header) : - type_{static_cast(header.p_type)}, - flags_{static_cast(header.p_flags)}, +template +Segment::Segment(const T& header, ARCH arch) : + type_{type_from(header.p_type, arch)}, + arch_(arch), + flags_{header.p_flags}, file_offset_{header.p_offset}, virtual_address_{header.p_vaddr}, physical_address_{header.p_paddr}, @@ -66,20 +94,12 @@ Segment::Segment(const details::Elf64_Phdr& header) : handler_size_{header.p_filesz} {} -Segment::Segment(const details::Elf32_Phdr& header) : - type_{static_cast(header.p_type)}, - flags_{static_cast(header.p_flags)}, - file_offset_{header.p_offset}, - virtual_address_{header.p_vaddr}, - physical_address_{header.p_paddr}, - size_{header.p_filesz}, - virtual_size_{header.p_memsz}, - alignment_{header.p_align}, - handler_size_{header.p_filesz} -{} +template Segment::Segment(const details::Elf32_Phdr& header, ARCH); +template Segment::Segment(const details::Elf64_Phdr& header, ARCH); void Segment::swap(Segment& other) { std::swap(type_, other.type_); + std::swap(arch_, other.arch_); std::swap(flags_, other.flags_); std::swap(file_offset_, other.file_offset_); std::swap(virtual_address_, other.virtual_address_); @@ -93,25 +113,13 @@ void Segment::swap(Segment& other) { std::swap(content_c_, other.content_c_); } - Segment& Segment::operator=(Segment other) { swap(other); return *this; } - result Segment::from_raw(const uint8_t* ptr, size_t size) { - if (size != sizeof(details::Elf32_Phdr) && - size != sizeof(details::Elf64_Phdr)) - { - LIEF_ERR("The size of the provided data does not match a valid header size"); - return make_error_code(lief_errors::corrupted); - } - return Segment::from_raw(std::vector{ptr, ptr + size}); -} -result Segment::from_raw(const std::vector& raw) { - const size_t size = raw.size(); if (size != sizeof(details::Elf32_Phdr) && size != sizeof(details::Elf64_Phdr)) { @@ -120,55 +128,16 @@ result Segment::from_raw(const std::vector& raw) { } if (size == sizeof(details::Elf32_Phdr)) { - return Segment(*reinterpret_cast(raw.data())); + return Segment(*reinterpret_cast(ptr)); } if (size == sizeof(details::Elf64_Phdr)) { - return Segment(*reinterpret_cast(raw.data())); + return Segment(*reinterpret_cast(ptr)); } return make_error_code(lief_errors::not_implemented); } -SEGMENT_TYPES Segment::type() const { - return type_; -} - - -ELF_SEGMENT_FLAGS Segment::flags() const { - return flags_; -} - - -uint64_t Segment::file_offset() const { - return file_offset_; -} - - -uint64_t Segment::virtual_address() const { - return virtual_address_; -} - - -uint64_t Segment::physical_address() const { - return physical_address_; -} - - -uint64_t Segment::physical_size() const { - return size_; -} - - -uint64_t Segment::virtual_size() const { - return virtual_size_; -} - - -uint64_t Segment::alignment() const { - return alignment_; -} - span Segment::content() const { if (datahandler_ == nullptr) { LIEF_DEBUG("Get content of segment {}@0x{:x} from cache", @@ -224,7 +193,8 @@ size_t Segment::get_content_size() const { return node.size(); } -template T Segment::get_content_value(size_t offset) const { +template +T Segment::get_content_value(size_t offset) const { T ret; if (datahandler_ == nullptr) { LIEF_DEBUG("Get content of segment {}@0x{:x} from cache", @@ -249,7 +219,8 @@ template unsigned int Segment::get_content_value(size_t offset) co template unsigned long Segment::get_content_value(size_t offset) const; template unsigned long long Segment::get_content_value(size_t offset) const; -template void Segment::set_content_value(size_t offset, T value) { +template +void Segment::set_content_value(size_t offset, T value) { if (datahandler_ == nullptr) { LIEF_DEBUG("Set content of segment {}@0x{:x}:0x{:x} in cache (0x{:x} bytes)", to_string(type()), virtual_address(), offset, sizeof(T)); @@ -282,20 +253,6 @@ template void Segment::set_content_value(size_t offset, unsigned i template void Segment::set_content_value(size_t offset, unsigned long value); template void Segment::set_content_value(size_t offset, unsigned long long value); -Segment::it_const_sections Segment::sections() const { - return sections_; -} - - -Segment::it_sections Segment::sections() { - return sections_; -} - -bool Segment::has(ELF_SEGMENT_FLAGS flag) const { - return ((flags() & flag) != ELF_SEGMENT_FLAGS::PF_NONE); -} - - bool Segment::has(const Section& section) const { auto it_section = std::find_if(std::begin(sections_), std::end(sections_), [§ion] (const Section* s) { @@ -304,7 +261,6 @@ bool Segment::has(const Section& section) const { return it_section != std::end(sections_); } - bool Segment::has(const std::string& name) const { auto it_section = std::find_if(std::begin(sections_), std::end(sections_), [&name] (const Section* s) { @@ -313,27 +269,14 @@ bool Segment::has(const std::string& name) const { return it_section != std::end(sections_); } - -void Segment::flags(ELF_SEGMENT_FLAGS flags) { - flags_ = flags; -} - - -void Segment::add(ELF_SEGMENT_FLAGS flag) { +void Segment::add(Segment::FLAGS flag) { flags(flags() | flag); } - -void Segment::remove(ELF_SEGMENT_FLAGS flag) { +void Segment::remove(Segment::FLAGS flag) { flags(flags() & ~flag); } - -void Segment::clear_flags() { - flags_ = ELF_SEGMENT_FLAGS::PF_NONE; -} - - void Segment::file_offset(uint64_t file_offset) { if (datahandler_ != nullptr) { auto res = datahandler_->get(this->file_offset(), handler_size(), DataHandler::Node::SEGMENT); @@ -347,17 +290,6 @@ void Segment::file_offset(uint64_t file_offset) { file_offset_ = file_offset; } - -void Segment::virtual_address(uint64_t virtual_address) { - virtual_address_ = virtual_address; -} - - -void Segment::physical_address(uint64_t physical_address) { - physical_address_ = physical_address; -} - - void Segment::physical_size(uint64_t physical_size) { if (datahandler_ != nullptr) { auto node = datahandler_->get(file_offset(), handler_size(), DataHandler::Node::SEGMENT); @@ -371,20 +303,6 @@ void Segment::physical_size(uint64_t physical_size) { size_ = physical_size; } - -void Segment::virtual_size(uint64_t virtual_size) { - virtual_size_ = virtual_size; -} - - -void Segment::alignment(uint64_t alignment) { - alignment_ = alignment; -} - -void Segment::type(SEGMENT_TYPES type) { - type_ = type; -} - void Segment::content(std::vector content) { if (datahandler_ == nullptr) { LIEF_DEBUG("Set content of segment {}@0x{:x} in cache (0x{:x} bytes)", @@ -422,20 +340,6 @@ void Segment::accept(Visitor& visitor) const { visitor.visit(*this); } - -Segment& Segment::operator+=(ELF_SEGMENT_FLAGS flag) { - add(flag); - return *this; -} - -Segment& Segment::operator-=(ELF_SEGMENT_FLAGS flag) { - remove(flag); - return *this; -} - - - - span Segment::writable_content() { span ref = static_cast(this)->content(); return {const_cast(ref.data()), ref.size()}; @@ -448,42 +352,70 @@ uint64_t Segment::handler_size() const { return physical_size(); } -std::ostream& operator<<(std::ostream& os, const ELF::Segment& segment) { - - +std::ostream& operator<<(std::ostream& os, const Segment& segment) { std::string flags = "---"; - if (segment.has(ELF_SEGMENT_FLAGS::PF_R)) { + if (segment.has(Segment::FLAGS::R)) { flags[0] = 'r'; } - if (segment.has(ELF_SEGMENT_FLAGS::PF_W)) { + if (segment.has(Segment::FLAGS::W)) { flags[1] = 'w'; } - if (segment.has(ELF_SEGMENT_FLAGS::PF_X)) { + if (segment.has(Segment::FLAGS::X)) { flags[2] = 'x'; } - os << std::hex; - os << std::left - << std::setw(18) << to_string(segment.type()) - << std::setw(10) << flags - << std::setw(10) << segment.file_offset() - << std::setw(10) << segment.virtual_address() - << std::setw(10) << segment.physical_address() - << std::setw(10) << segment.physical_size() - << std::setw(10) << segment.virtual_size() - << std::setw(10) << segment.alignment() - << std::endl; - - if (!segment.sections().empty()) { - os << "Sections in this segment :" << std::endl; - for (const Section& section : segment.sections()) { - os << " " << section.name() << std::endl; - } - } + os << fmt::format("{} 0x{:08x}/0x{:06x} 0x{:06x} 0x{:04x}/0x{:04x} {} {}", + to_string(segment.type()), segment.virtual_address(), + segment.file_offset(), segment.physical_address(), + segment.physical_size(), segment.virtual_size(), + segment.alignment(), flags); return os; } + +const char* to_string(Segment::TYPE e) { + #define ENTRY(X) std::pair(Segment::TYPE::X, #X) + STRING_MAP enums2str { + ENTRY(PT_NULL), + ENTRY(LOAD), + ENTRY(DYNAMIC), + ENTRY(INTERP), + ENTRY(NOTE), + ENTRY(SHLIB), + ENTRY(PHDR), + ENTRY(TLS), + ENTRY(GNU_EH_FRAME), + ENTRY(GNU_STACK), + ENTRY(GNU_PROPERTY), + ENTRY(GNU_RELRO), + ENTRY(ARM_ARCHEXT), + ENTRY(ARM_EXIDX), + ENTRY(ARM_UNWIND), + ENTRY(AARCH64_MEMTAG_MTE), + ENTRY(MIPS_REGINFO), + ENTRY(MIPS_RTPROC), + ENTRY(MIPS_OPTIONS), + ENTRY(MIPS_ABIFLAGS), + ENTRY(RISCV_ATTRIBUTES), + }; + #undef ENTRY + + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + +const char* to_string(Segment::FLAGS e) { + switch (e) { + case Segment::FLAGS::NONE: return "NONE"; + case Segment::FLAGS::R: return "R"; + case Segment::FLAGS::W: return "W"; + case Segment::FLAGS::X: return "X"; + } + return "UNKNOWN"; +} } } diff --git a/src/ELF/Structures.hpp b/src/ELF/Structures.hpp index ff73ba6539..b292d7b670 100644 --- a/src/ELF/Structures.hpp +++ b/src/ELF/Structures.hpp @@ -27,136 +27,6 @@ namespace details { #include "structures.inc" -static const ELF_SECTION_FLAGS section_flags_array[] = { - ELF_SECTION_FLAGS::SHF_NONE, ELF_SECTION_FLAGS::SHF_WRITE, ELF_SECTION_FLAGS::SHF_ALLOC, ELF_SECTION_FLAGS::SHF_EXECINSTR, - ELF_SECTION_FLAGS::SHF_MERGE, ELF_SECTION_FLAGS::SHF_STRINGS, ELF_SECTION_FLAGS::SHF_INFO_LINK, - ELF_SECTION_FLAGS::SHF_LINK_ORDER, ELF_SECTION_FLAGS::SHF_OS_NONCONFORMING, ELF_SECTION_FLAGS::SHF_GROUP, - ELF_SECTION_FLAGS::SHF_TLS, ELF_SECTION_FLAGS::SHF_EXCLUDE, ELF_SECTION_FLAGS::XCORE_SHF_CP_SECTION, - ELF_SECTION_FLAGS::XCORE_SHF_DP_SECTION, ELF_SECTION_FLAGS::SHF_MASKOS, ELF_SECTION_FLAGS::SHF_MASKPROC, - ELF_SECTION_FLAGS::SHF_HEX_GPREL, ELF_SECTION_FLAGS::SHF_MIPS_NODUPES, ELF_SECTION_FLAGS::SHF_MIPS_NAMES, - ELF_SECTION_FLAGS::SHF_MIPS_LOCAL, ELF_SECTION_FLAGS::SHF_MIPS_NOSTRIP, ELF_SECTION_FLAGS::SHF_MIPS_GPREL, - ELF_SECTION_FLAGS::SHF_MIPS_MERGE, ELF_SECTION_FLAGS::SHF_MIPS_ADDR, ELF_SECTION_FLAGS::SHF_MIPS_STRING -}; - - -static const ARM_EFLAGS arm_eflags_array[] = { - ARM_EFLAGS::EF_ARM_SOFT_FLOAT, - ARM_EFLAGS::EF_ARM_VFP_FLOAT, - ARM_EFLAGS::EF_ARM_EABI_UNKNOWN, - ARM_EFLAGS::EF_ARM_EABI_VER1, - ARM_EFLAGS::EF_ARM_EABI_VER2, - ARM_EFLAGS::EF_ARM_EABI_VER3, - ARM_EFLAGS::EF_ARM_EABI_VER4, - ARM_EFLAGS::EF_ARM_EABI_VER5, -}; - -static const PPC64_EFLAGS ppc64_eflags_array[] = { - PPC64_EFLAGS::EF_PPC64_ABI, -}; - -static const MIPS_EFLAGS mips_eflags_array[] = { - MIPS_EFLAGS::EF_MIPS_NOREORDER, - MIPS_EFLAGS::EF_MIPS_PIC, - MIPS_EFLAGS::EF_MIPS_CPIC, - MIPS_EFLAGS::EF_MIPS_ABI2, - MIPS_EFLAGS::EF_MIPS_32BITMODE, - MIPS_EFLAGS::EF_MIPS_FP64, - MIPS_EFLAGS::EF_MIPS_NAN2008, - MIPS_EFLAGS::EF_MIPS_ABI_O32, - MIPS_EFLAGS::EF_MIPS_ABI_O64, - MIPS_EFLAGS::EF_MIPS_ABI_EABI32, - MIPS_EFLAGS::EF_MIPS_ABI_EABI64, - MIPS_EFLAGS::EF_MIPS_MACH_3900, - MIPS_EFLAGS::EF_MIPS_MACH_4010, - MIPS_EFLAGS::EF_MIPS_MACH_4100, - MIPS_EFLAGS::EF_MIPS_MACH_4650, - MIPS_EFLAGS::EF_MIPS_MACH_4120, - MIPS_EFLAGS::EF_MIPS_MACH_4111, - MIPS_EFLAGS::EF_MIPS_MACH_SB1, - MIPS_EFLAGS::EF_MIPS_MACH_OCTEON, - MIPS_EFLAGS::EF_MIPS_MACH_XLR, - MIPS_EFLAGS::EF_MIPS_MACH_OCTEON2, - MIPS_EFLAGS::EF_MIPS_MACH_OCTEON3, - MIPS_EFLAGS::EF_MIPS_MACH_5400, - MIPS_EFLAGS::EF_MIPS_MACH_5900, - MIPS_EFLAGS::EF_MIPS_MACH_5500, - MIPS_EFLAGS::EF_MIPS_MACH_9000, - MIPS_EFLAGS::EF_MIPS_MACH_LS2E, - MIPS_EFLAGS::EF_MIPS_MACH_LS2F, - MIPS_EFLAGS::EF_MIPS_MACH_LS3A, - MIPS_EFLAGS::EF_MIPS_MICROMIPS, - MIPS_EFLAGS::EF_MIPS_ARCH_ASE_M16, - MIPS_EFLAGS::EF_MIPS_ARCH_ASE_MDMX, - MIPS_EFLAGS::EF_MIPS_ARCH_1, - MIPS_EFLAGS::EF_MIPS_ARCH_2, - MIPS_EFLAGS::EF_MIPS_ARCH_3, - MIPS_EFLAGS::EF_MIPS_ARCH_4, - MIPS_EFLAGS::EF_MIPS_ARCH_5, - MIPS_EFLAGS::EF_MIPS_ARCH_32, - MIPS_EFLAGS::EF_MIPS_ARCH_64, - MIPS_EFLAGS::EF_MIPS_ARCH_32R2, - MIPS_EFLAGS::EF_MIPS_ARCH_64R2, - MIPS_EFLAGS::EF_MIPS_ARCH_32R6, - MIPS_EFLAGS::EF_MIPS_ARCH_64R6, -}; - -static const HEXAGON_EFLAGS hexagon_eflags_array[] = { - HEXAGON_EFLAGS::EF_HEXAGON_MACH_V2, - HEXAGON_EFLAGS::EF_HEXAGON_MACH_V3, - HEXAGON_EFLAGS::EF_HEXAGON_MACH_V4, - HEXAGON_EFLAGS::EF_HEXAGON_MACH_V5, - HEXAGON_EFLAGS::EF_HEXAGON_ISA_MACH, - HEXAGON_EFLAGS::EF_HEXAGON_ISA_V2, - HEXAGON_EFLAGS::EF_HEXAGON_ISA_V3, - HEXAGON_EFLAGS::EF_HEXAGON_ISA_V4, - HEXAGON_EFLAGS::EF_HEXAGON_ISA_V5, -}; - -static const LOONGARCH_EFLAGS loongarch_eflags_array[] = { - LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SOFT_FLOAT, - LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SINGLE_FLOAT, - LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_DOUBLE_FLOAT, -}; - -static const DYNAMIC_FLAGS dynamic_flags_array[] = { - DYNAMIC_FLAGS::DF_ORIGIN, - DYNAMIC_FLAGS::DF_SYMBOLIC, - DYNAMIC_FLAGS::DF_TEXTREL, - DYNAMIC_FLAGS::DF_BIND_NOW, - DYNAMIC_FLAGS::DF_STATIC_TLS, -}; - - -static const DYNAMIC_FLAGS_1 dynamic_flags_1_array[] = { - DYNAMIC_FLAGS_1::DF_1_NOW, - DYNAMIC_FLAGS_1::DF_1_GLOBAL, - DYNAMIC_FLAGS_1::DF_1_GROUP, - DYNAMIC_FLAGS_1::DF_1_NODELETE, - DYNAMIC_FLAGS_1::DF_1_LOADFLTR, - DYNAMIC_FLAGS_1::DF_1_INITFIRST, - DYNAMIC_FLAGS_1::DF_1_NOOPEN, - DYNAMIC_FLAGS_1::DF_1_ORIGIN, - DYNAMIC_FLAGS_1::DF_1_DIRECT, - DYNAMIC_FLAGS_1::DF_1_TRANS, - DYNAMIC_FLAGS_1::DF_1_INTERPOSE, - DYNAMIC_FLAGS_1::DF_1_NODEFLIB, - DYNAMIC_FLAGS_1::DF_1_NODUMP, - DYNAMIC_FLAGS_1::DF_1_CONFALT, - DYNAMIC_FLAGS_1::DF_1_ENDFILTEE, - DYNAMIC_FLAGS_1::DF_1_DISPRELDNE, - DYNAMIC_FLAGS_1::DF_1_DISPRELPND, - DYNAMIC_FLAGS_1::DF_1_NODIRECT, - DYNAMIC_FLAGS_1::DF_1_IGNMULDEF, - DYNAMIC_FLAGS_1::DF_1_NOKSYMS, - DYNAMIC_FLAGS_1::DF_1_NOHDR, - DYNAMIC_FLAGS_1::DF_1_EDITED, - DYNAMIC_FLAGS_1::DF_1_NORELOC, - DYNAMIC_FLAGS_1::DF_1_SYMINTPOSE, - DYNAMIC_FLAGS_1::DF_1_GLOBAUDIT, - DYNAMIC_FLAGS_1::DF_1_SINGLETON, - DYNAMIC_FLAGS_1::DF_1_PIE, -}; - struct Elf64_Prpsinfo { char pr_state; diff --git a/src/ELF/Symbol.cpp b/src/ELF/Symbol.cpp index 70e463263a..9192b2bda3 100644 --- a/src/ELF/Symbol.cpp +++ b/src/ELF/Symbol.cpp @@ -13,29 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include #ifdef __unix__ #include #endif - - -#include "LIEF/ELF/hash.hpp" - #include "LIEF/ELF/Symbol.hpp" -#include "LIEF/ELF/EnumToString.hpp" #include "LIEF/ELF/SymbolVersion.hpp" - +#include "LIEF/Visitor.hpp" #include "ELF/Structures.hpp" +#include "frozen.hpp" +#include + + namespace LIEF { namespace ELF { -Symbol::Symbol() = default; -Symbol::~Symbol() = default; - Symbol& Symbol::operator=(Symbol other) { swap(other); return *this; @@ -61,20 +56,10 @@ void Symbol::swap(Symbol& other) { std::swap(arch_, other.arch_); } -Symbol::Symbol(const details::Elf32_Sym& header, ARCH arch) : - type_{static_cast(header.st_info & 0x0f)}, - binding_{static_cast(header.st_info >> 4)}, - other_{header.st_other}, - shndx_{header.st_shndx}, - arch_{arch} -{ - value_ = header.st_value; - size_ = header.st_size; -} - -Symbol::Symbol(const details::Elf64_Sym& header, ARCH arch) : - type_{static_cast(header.st_info & 0x0f)}, - binding_{static_cast(header.st_info >> 4)}, +template +Symbol::Symbol(const T& header, ARCH arch) : + type_{type_from(header.st_info & 0x0f, arch)}, + binding_{binding_from(header.st_info >> 4, arch)}, other_{header.st_other}, shndx_{header.st_shndx}, arch_{arch} @@ -83,92 +68,21 @@ Symbol::Symbol(const details::Elf64_Sym& header, ARCH arch) : size_ = header.st_size; } +template Symbol::Symbol(const details::Elf32_Sym& header, ARCH); +template Symbol::Symbol(const details::Elf64_Sym& header, ARCH); -Symbol::Symbol(std::string name, ELF_SYMBOL_TYPES type, SYMBOL_BINDINGS binding, - uint8_t other, uint16_t shndx, - uint64_t value, uint64_t size) : - LIEF::Symbol{std::move(name), value, size}, - type_{type}, - binding_{binding}, - other_{other}, - shndx_{shndx} -{} - - -ELF_SYMBOL_TYPES Symbol::type() const { - return type_; -} - -SYMBOL_BINDINGS Symbol::binding() const { - return binding_; -} uint8_t Symbol::information() const { - return static_cast((static_cast(binding_) << 4) | (static_cast(type_) & 0x0f)); -} - -uint8_t Symbol::other() const { - return other_; + return static_cast( + (static_cast(binding_) << 4) | (static_cast(type_) & 0x0f) + ); } -uint16_t Symbol::section_idx() const { - return shndx(); -} - -Section* Symbol::section() { - return section_; -} - -uint16_t Symbol::shndx() const { - return shndx_; -} - - -ELF_SYMBOL_VISIBILITY Symbol::visibility() const { - return static_cast(other_); -} - - -bool Symbol::has_version() const { - return symbol_version_ != nullptr; -} - - -const SymbolVersion* Symbol::symbol_version() const { - return symbol_version_; -} - -SymbolVersion* Symbol::symbol_version() { - return const_cast(static_cast(this)->symbol_version()); -} - -void Symbol::type(ELF_SYMBOL_TYPES type) { - type_ = type; -} - -void Symbol::binding(SYMBOL_BINDINGS binding) { - binding_ = binding; -} - -void Symbol::other(uint8_t other) { - other_ = other; -} - -void Symbol::shndx(uint16_t idx) { - shndx_ = idx; -} - -void Symbol::visibility(ELF_SYMBOL_VISIBILITY visibility) { - other_ = static_cast(visibility); -} - - void Symbol::information(uint8_t info) { - binding_ = static_cast(info >> 4); - type_ = static_cast(info & 0x0f); + binding_ = binding_from(info >> 4, arch_); + type_ = type_from(info & 0x0f, arch_); } - std::string Symbol::demangled_name() const { #if defined(__unix__) int status; @@ -188,39 +102,39 @@ std::string Symbol::demangled_name() const { } bool Symbol::is_exported() const { - bool is_exported = shndx() != static_cast(SYMBOL_SECTION_INDEX::SHN_UNDEF); + bool is_exported = shndx() != SECTION_INDEX::UNDEF; // An export must have an address is_exported = is_exported && (value() != 0 || (value() == 0 && size() > 0)); // An export must be bind to GLOBAL or WEAK - is_exported = is_exported && (binding() == SYMBOL_BINDINGS::STB_GLOBAL || - binding() == SYMBOL_BINDINGS::STB_WEAK); + is_exported = is_exported && (binding() == BINDING::GLOBAL || + binding() == BINDING::WEAK); // An export must have one of theses types: - is_exported = is_exported && (type() == ELF_SYMBOL_TYPES::STT_FUNC || - type() == ELF_SYMBOL_TYPES::STT_GNU_IFUNC || - type() == ELF_SYMBOL_TYPES::STT_OBJECT); + is_exported = is_exported && (type() == TYPE::FUNC || + type() == TYPE::GNU_IFUNC || + type() == TYPE::OBJECT); return is_exported; } void Symbol::set_exported(bool flag) { if (flag) { shndx(1); - binding(SYMBOL_BINDINGS::STB_GLOBAL); + binding(BINDING::GLOBAL); } else { - shndx(SYMBOL_SECTION_INDEX::SHN_UNDEF); - binding(SYMBOL_BINDINGS::STB_LOCAL); + shndx(SECTION_INDEX::UNDEF); + binding(BINDING::LOCAL); } } bool Symbol::is_imported() const { // An import must not be defined in a section - bool is_imported = shndx() == static_cast(SYMBOL_SECTION_INDEX::SHN_UNDEF); + bool is_imported = shndx() == SECTION_INDEX::UNDEF; - const bool is_mips = arch_ == ARCH::EM_MIPS || arch_ == ARCH::EM_MIPS_X || - arch_ == ARCH::EM_MIPS_RS3_LE; - const bool is_ppc = arch_ == ARCH::EM_PPC || arch_ == ARCH::EM_PPC64; + const bool is_mips = arch_ == ARCH::MIPS || arch_ == ARCH::MIPS_X || + arch_ == ARCH::MIPS_RS3_LE; + const bool is_ppc = arch_ == ARCH::PPC || arch_ == ARCH::PPC64; // An import must not have an address (except for some architectures like Mips/PPC) if (!is_mips && !is_ppc) { @@ -231,19 +145,19 @@ bool Symbol::is_imported() const { is_imported = is_imported && !name().empty(); // It must have a GLOBAL or WEAK bind - is_imported = is_imported && (binding() == SYMBOL_BINDINGS::STB_GLOBAL || - binding() == SYMBOL_BINDINGS::STB_WEAK); + is_imported = is_imported && (binding() == BINDING::GLOBAL || + binding() == BINDING::WEAK); // It must be a FUNC or an OBJECT - is_imported = is_imported && (type() == ELF_SYMBOL_TYPES::STT_FUNC || - type() == ELF_SYMBOL_TYPES::STT_GNU_IFUNC || - type() == ELF_SYMBOL_TYPES::STT_OBJECT); + is_imported = is_imported && (type() == TYPE::FUNC || + type() == TYPE::GNU_IFUNC || + type() == TYPE::OBJECT); return is_imported; } void Symbol::set_imported(bool flag) { if (flag) { - shndx(SYMBOL_SECTION_INDEX::SHN_UNDEF); + shndx(SECTION_INDEX::UNDEF); } else { shndx(1); } @@ -254,25 +168,70 @@ void Symbol::accept(Visitor& visitor) const { } std::ostream& operator<<(std::ostream& os, const Symbol& entry) { - std::string name = entry.demangled_name(); if (name.empty()) { name = entry.name(); } - os << std::hex; - os << std::left - << std::setw(30) << name - << std::setw(10) << to_string(entry.type()) - << std::setw(10) << to_string(entry.binding()) - << std::setw(10) << entry.value() - << std::setw(10) << entry.size(); + os << fmt::format("{} ({}/{}): 0x{:06x} (0x{:02x})", + name, to_string(entry.type()), to_string(entry.binding()), + entry.value(), entry.size()); - if (entry.has_version()) { - os << std::setw(10) << *entry.symbol_version(); + if (const SymbolVersion* version = entry.symbol_version()) { + os << *version; } - return os; } + +const char* to_string(Symbol::BINDING e) { + #define ENTRY(X) std::pair(Symbol::BINDING::X, #X) + STRING_MAP enums2str { + ENTRY(LOCAL), + ENTRY(GLOBAL), + ENTRY(WEAK), + ENTRY(GNU_UNIQUE), + }; + #undef ENTRY + + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} +const char* to_string(Symbol::TYPE e) { + #define ENTRY(X) std::pair(Symbol::TYPE::X, #X) + STRING_MAP enums2str { + ENTRY(NOTYPE), + ENTRY(OBJECT), + ENTRY(FUNC), + ENTRY(SECTION), + ENTRY(FILE), + ENTRY(COMMON), + ENTRY(TLS), + ENTRY(GNU_IFUNC), + }; + #undef ENTRY + + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} +const char* to_string(Symbol::VISIBILITY e) { + #define ENTRY(X) std::pair(Symbol::VISIBILITY::X, #X) + STRING_MAP enums2str { + ENTRY(DEFAULT), + ENTRY(INTERNAL), + ENTRY(HIDDEN), + ENTRY(PROTECTED), + }; + #undef ENTRY + + if (auto it = enums2str.find(e); it != enums2str.end()) { + return it->second; + } + return "UNKNOWN"; +} + } } diff --git a/src/ELF/SymbolVersion.cpp b/src/ELF/SymbolVersion.cpp index 8e7ffebbe1..79cbd19c03 100644 --- a/src/ELF/SymbolVersion.cpp +++ b/src/ELF/SymbolVersion.cpp @@ -22,58 +22,15 @@ namespace LIEF { namespace ELF { -SymbolVersion::SymbolVersion() = default; -SymbolVersion::~SymbolVersion() = default; - -SymbolVersion& SymbolVersion::operator=(const SymbolVersion&) = default; - -SymbolVersion::SymbolVersion(const SymbolVersion&) = default; - -SymbolVersion::SymbolVersion(uint16_t value) : - value_{value} -{} - - -SymbolVersion SymbolVersion::local() { - return SymbolVersion{0}; -} - -SymbolVersion SymbolVersion::global() { - return SymbolVersion{1}; -} - -uint16_t SymbolVersion::value() const { - return value_; -} - - -bool SymbolVersion::has_auxiliary_version() const { - return symbol_aux_ != nullptr; -} - -const SymbolVersionAux* SymbolVersion::symbol_version_auxiliary() const { - return symbol_aux_; -} - -SymbolVersionAux* SymbolVersion::symbol_version_auxiliary() { - return const_cast(static_cast(this)->symbol_version_auxiliary()); -} - void SymbolVersion::symbol_version_auxiliary(SymbolVersionAuxRequirement& svauxr) { symbol_aux_ = &svauxr; value_ = svauxr.other(); } -void SymbolVersion::value(uint16_t value) { - value_ = value; -} - void SymbolVersion::accept(Visitor& visitor) const { visitor.visit(*this); } - - std::ostream& operator<<(std::ostream& os, const ELF::SymbolVersion& symv) { if (symv.has_auxiliary_version()) { os << symv.symbol_version_auxiliary()->name() << "(" << symv.value() << ")"; diff --git a/src/ELF/SymbolVersionAux.cpp b/src/ELF/SymbolVersionAux.cpp index 1b8e37f227..86d56f0590 100644 --- a/src/ELF/SymbolVersionAux.cpp +++ b/src/ELF/SymbolVersionAux.cpp @@ -22,35 +22,9 @@ namespace LIEF { namespace ELF { -SymbolVersionAux::~SymbolVersionAux() = default; -SymbolVersionAux& SymbolVersionAux::operator=(const SymbolVersionAux&) = default; -SymbolVersionAux::SymbolVersionAux(const SymbolVersionAux&) = default; - -SymbolVersionAux::SymbolVersionAux() = default; - -SymbolVersionAux::SymbolVersionAux(std::string name) : - name_{std::move(name)} -{} - -const std::string& SymbolVersionAux::name() const { - return name_; -} - -void SymbolVersionAux::name(const std::string& name) { - name_ = name; -} - void SymbolVersionAux::accept(Visitor& visitor) const { visitor.visit(*this); } - - - - -std::ostream& operator<<(std::ostream& os, const SymbolVersionAux& symAux) { - os << symAux.name(); - return os; -} } } diff --git a/src/ELF/SymbolVersionAuxRequirement.cpp b/src/ELF/SymbolVersionAuxRequirement.cpp index 6b04af6843..3ea01b0371 100644 --- a/src/ELF/SymbolVersionAuxRequirement.cpp +++ b/src/ELF/SymbolVersionAuxRequirement.cpp @@ -21,13 +21,6 @@ namespace LIEF { namespace ELF { -SymbolVersionAuxRequirement::SymbolVersionAuxRequirement() = default; - -SymbolVersionAuxRequirement::~SymbolVersionAuxRequirement() = default; -SymbolVersionAuxRequirement& SymbolVersionAuxRequirement::operator=(const SymbolVersionAuxRequirement&) = default; -SymbolVersionAuxRequirement::SymbolVersionAuxRequirement(const SymbolVersionAuxRequirement&) = default; - - SymbolVersionAuxRequirement::SymbolVersionAuxRequirement(const details::Elf64_Vernaux& header) : hash_{header.vna_hash}, flags_{header.vna_flags}, @@ -41,47 +34,10 @@ SymbolVersionAuxRequirement::SymbolVersionAuxRequirement(const details::Elf32_Ve other_{header.vna_other} {} - -uint32_t SymbolVersionAuxRequirement::hash() const { - return hash_; -} - - -uint16_t SymbolVersionAuxRequirement::flags() const { - return flags_; -} - - -uint16_t SymbolVersionAuxRequirement::other() const { - return other_; -} - - -void SymbolVersionAuxRequirement::hash(uint32_t hash) { - hash_ = hash; -} - - -void SymbolVersionAuxRequirement::flags(uint16_t flags) { - flags_ = flags; -} - - -void SymbolVersionAuxRequirement::other(uint16_t other) { - other_ = other; -} - void SymbolVersionAuxRequirement::accept(Visitor& visitor) const { visitor.visit(*this); } - - - -std::ostream& operator<<(std::ostream& os, const SymbolVersionAuxRequirement& symAux) { - os << symAux.name(); - return os; -} } } diff --git a/src/ELF/SymbolVersionDefinition.cpp b/src/ELF/SymbolVersionDefinition.cpp index 14f3df61e2..f5f68f6ac2 100644 --- a/src/ELF/SymbolVersionDefinition.cpp +++ b/src/ELF/SymbolVersionDefinition.cpp @@ -26,7 +26,6 @@ namespace LIEF { namespace ELF { -SymbolVersionDefinition::SymbolVersionDefinition() = default; SymbolVersionDefinition::~SymbolVersionDefinition() = default; SymbolVersionDefinition::SymbolVersionDefinition(const details::Elf64_Verdef& header) : @@ -62,8 +61,6 @@ SymbolVersionDefinition& SymbolVersionDefinition::operator=(SymbolVersionDefinit return *this; } - - void SymbolVersionDefinition::swap(SymbolVersionDefinition& other) { std::swap(version_, other.version_); std::swap(flags_, other.flags_); @@ -72,51 +69,10 @@ void SymbolVersionDefinition::swap(SymbolVersionDefinition& other) { std::swap(symbol_version_aux_, other.symbol_version_aux_); } - -uint16_t SymbolVersionDefinition::version() const { - return version_; -} - -uint16_t SymbolVersionDefinition::flags() const { - return flags_; -} - -uint16_t SymbolVersionDefinition::ndx() const { - return ndx_; -} - -uint32_t SymbolVersionDefinition::hash() const { - return hash_; -} - -SymbolVersionDefinition::it_version_aux SymbolVersionDefinition::symbols_aux() { - return symbol_version_aux_; -} - -SymbolVersionDefinition::it_const_version_aux SymbolVersionDefinition::symbols_aux() const { - return symbol_version_aux_; - -} - -void SymbolVersionDefinition::version(uint16_t version) { - version_ = version; -} - -void SymbolVersionDefinition::flags(uint16_t flags) { - flags_ = flags; -} - -void SymbolVersionDefinition::hash(uint32_t hash) { - hash_ = hash; -} - void SymbolVersionDefinition::accept(Visitor& visitor) const { visitor.visit(*this); } - - - std::ostream& operator<<(std::ostream& os, const SymbolVersionDefinition& sym) { os << std::hex << std::left; os << std::setw(10) << sym.version(); diff --git a/src/ELF/SymbolVersionRequirement.cpp b/src/ELF/SymbolVersionRequirement.cpp index 1b35a4e9f1..0a3109197e 100644 --- a/src/ELF/SymbolVersionRequirement.cpp +++ b/src/ELF/SymbolVersionRequirement.cpp @@ -23,10 +23,6 @@ namespace LIEF { namespace ELF { -SymbolVersionRequirement::SymbolVersionRequirement() = default; -SymbolVersionRequirement::~SymbolVersionRequirement() = default; - - SymbolVersionRequirement::SymbolVersionRequirement(const details::Elf64_Verneed& header) : version_{header.vn_version} {} @@ -35,7 +31,6 @@ SymbolVersionRequirement::SymbolVersionRequirement(const details::Elf32_Verneed& version_{header.vn_version} {} - SymbolVersionRequirement::SymbolVersionRequirement(const SymbolVersionRequirement& other) : Object{other}, version_{other.version_}, @@ -47,7 +42,6 @@ SymbolVersionRequirement::SymbolVersionRequirement(const SymbolVersionRequiremen } } - SymbolVersionRequirement& SymbolVersionRequirement::operator=(SymbolVersionRequirement other) { swap(other); return *this; @@ -60,40 +54,6 @@ void SymbolVersionRequirement::swap(SymbolVersionRequirement& other) { } -uint16_t SymbolVersionRequirement::version() const { - return version_; -} - - -uint32_t SymbolVersionRequirement::cnt() const { - return static_cast(aux_requirements_.size()); -} - - -SymbolVersionRequirement::it_aux_requirement SymbolVersionRequirement::auxiliary_symbols() { - return aux_requirements_; -} - - -SymbolVersionRequirement::it_const_aux_requirement SymbolVersionRequirement::auxiliary_symbols() const { - return aux_requirements_; -} - - -const std::string& SymbolVersionRequirement::name() const { - return name_; -} - - -void SymbolVersionRequirement::version(uint16_t version) { - version_ = version; -} - - -void SymbolVersionRequirement::name(const std::string& name) { - name_ = name; -} - SymbolVersionAuxRequirement& SymbolVersionRequirement::add_aux_requirement(const SymbolVersionAuxRequirement& aux_requirement) { aux_requirements_.push_back(std::make_unique(aux_requirement)); return *aux_requirements_.back(); @@ -103,14 +63,5 @@ void SymbolVersionRequirement::accept(Visitor& visitor) const { visitor.visit(*this); } - - - - -std::ostream& operator<<(std::ostream& os, const SymbolVersionRequirement& symr) { - os << symr.version() << " " << symr.name(); - - return os; -} } } diff --git a/src/ELF/SysvHash.cpp b/src/ELF/SysvHash.cpp index 68325c4727..7657d1ce3b 100644 --- a/src/ELF/SysvHash.cpp +++ b/src/ELF/SysvHash.cpp @@ -23,38 +23,11 @@ namespace LIEF { namespace ELF { -SysvHash& SysvHash::operator=(const SysvHash&) = default; -SysvHash::SysvHash(const SysvHash&) = default; -SysvHash::~SysvHash() = default; -SysvHash::SysvHash() = default; -SysvHash& SysvHash::operator=(SysvHash&&) = default; -SysvHash::SysvHash(SysvHash&&) = default; - - -uint32_t SysvHash::nbucket() const { - return static_cast(buckets_.size()); -} - -uint32_t SysvHash::nchain() const { - return static_cast(chains_.size()); -} - -const std::vector& SysvHash::buckets() const { - return buckets_; -} - -const std::vector& SysvHash::chains() const { - return chains_; -} - - - void SysvHash::accept(Visitor& visitor) const { visitor.visit(*this); } - std::ostream& operator<<(std::ostream& os, const SysvHash& sysvhash) { os << std::hex << std::left; diff --git a/src/ELF/json.cpp b/src/ELF/json.cpp index fbebd933f4..6c7ee2501f 100644 --- a/src/ELF/json.cpp +++ b/src/ELF/json.cpp @@ -183,7 +183,7 @@ void JsonVisitor::visit(const Header& header) { void JsonVisitor::visit(const Section& section) { std::vector flags; - for (ELF_SECTION_FLAGS f : section.flags_list()) { + for (Section::FLAGS f : section.flags_list()) { flags.emplace_back(to_string(f)); } @@ -261,23 +261,13 @@ void JsonVisitor::visit(const DynamicEntryFlags& entry) { std::vector flags_str; flags_str.reserve(flags.size()); - if (entry.tag() == DYNAMIC_TAGS::DT_FLAGS) { - std::transform( - std::begin(flags), std::end(flags), - std::back_inserter(flags_str), - [] (uint32_t f) { - return to_string(static_cast(f)); - }); - } + std::transform( + std::begin(flags), std::end(flags), + std::back_inserter(flags_str), + [] (DynamicEntryFlags::FLAG f) { + return to_string(f); + }); - if (entry.tag() == DYNAMIC_TAGS::DT_FLAGS_1) { - std::transform( - std::begin(flags), std::end(flags), - std::back_inserter(flags_str), - [] (uint32_t f) { - return to_string(static_cast(f)); - }); - } node_["flags"] = flags_str; } @@ -315,10 +305,7 @@ void JsonVisitor::visit(const Relocation& relocation) { section_name = reloc_sec->name(); } - - if (relocation.architecture() == ARCH::EM_X86_64) { - relocation_type = to_string(static_cast(relocation.type())); - } + relocation_type = to_string(relocation.type()); node_["symbol_name"] = symbol_name; node_["address"] = relocation.address(); @@ -332,7 +319,6 @@ void JsonVisitor::visit(const SymbolVersion& sv) { if (sv.has_auxiliary_version()) { node_["symbol_version_auxiliary"] = sv.symbol_version_auxiliary()->name(); } - } void JsonVisitor::visit(const SymbolVersionRequirement& svr) { @@ -457,28 +443,28 @@ void JsonVisitor::visit(const CorePrStatus& pstatus) { if (!reg_vals.empty()) { json regs; switch (pstatus.architecture()) { - case ARCH::EM_386: + case ARCH::I386: { for (size_t i = 0; i < reg_vals.size(); ++i) { regs[to_string(CorePrStatus::Registers::X86(i))] = reg_vals[i]; } break; } - case ARCH::EM_X86_64: + case ARCH::X86_64: { for (size_t i = 0; i < reg_vals.size(); ++i) { regs[to_string(CorePrStatus::Registers::X86_64(i))] = reg_vals[i]; } break; } - case ARCH::EM_ARM: + case ARCH::ARM: { for (size_t i = 0; i < reg_vals.size(); ++i) { regs[to_string(CorePrStatus::Registers::ARM(i))] = reg_vals[i]; } break; } - case ARCH::EM_AARCH64: + case ARCH::AARCH64: { for (size_t i = 0; i < reg_vals.size(); ++i) { regs[to_string(CorePrStatus::Registers::AARCH64(i))] = reg_vals[i]; diff --git a/src/ELF/utils.cpp b/src/ELF/utils.cpp index 90589ee37d..16840c0926 100644 --- a/src/ELF/utils.cpp +++ b/src/ELF/utils.cpp @@ -88,13 +88,5 @@ uint32_t dl_new_hash(const char* name) { return h & 0xffffffff; } - - } // namespace ELF } // namespace LIEF - - - - - - diff --git a/src/OAT/Parser.cpp b/src/OAT/Parser.cpp index 43f8321c51..d2b06d4ae3 100644 --- a/src/OAT/Parser.cpp +++ b/src/OAT/Parser.cpp @@ -82,7 +82,7 @@ std::unique_ptr Parser::parse(std::vector data) { Parser::Parser(std::vector data) { stream_ = std::make_unique(std::move(data)); binary_ = std::unique_ptr(new Binary{}); - config_.count_mtd = ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO; + config_.count_mtd = ELF::ParserConfig::DYNSYM_COUNT::AUTO; } Parser::Parser(const std::string& file) { @@ -90,7 +90,7 @@ Parser::Parser(const std::string& file) { stream_ = std::make_unique(std::move(*s)); } binary_ = std::unique_ptr(new Binary{}); - config_.count_mtd = ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO; + config_.count_mtd = ELF::ParserConfig::DYNSYM_COUNT::AUTO; } diff --git a/tests/elf/check_bin_examples.py b/tests/elf/check_bin_examples.py index 3fbeed607f..18d88a581b 100644 --- a/tests/elf/check_bin_examples.py +++ b/tests/elf/check_bin_examples.py @@ -16,37 +16,37 @@ assert BUILD_DIR is not None -BUILD_DIR = Path(BUILD_DIR) +BUILD_DIR_PATH = Path(BUILD_DIR) def test_elf_reader_c(): - target = BUILD_DIR / "examples" / "c" / "elf_reader" + target = BUILD_DIR_PATH / "examples" / "c" / "elf_reader" for sample in elf_samples: check_call([target, sample]) def test_elf_reader_cpp(): - target = BUILD_DIR / "examples" / "cpp" / "elf_reader" + target = BUILD_DIR_PATH / "examples" / "cpp" / "elf_reader" for sample in elf_samples: check_call([target, sample]) def test_abstract_reader(): - target = BUILD_DIR / "examples" / "cpp" / "abstract_reader" + target = BUILD_DIR_PATH / "examples" / "cpp" / "abstract_reader" for sample in elf_samples: check_call([target, sample]) def test_elf_strip(tmp_path: Path): out = tmp_path / "out.bin" - target = BUILD_DIR / "examples" / "cpp" / "elf_strip" + target = BUILD_DIR_PATH / "examples" / "cpp" / "elf_strip" for sample in elf_samples: check_call([target, sample, out]) def test_elf_add_section(tmp_path: Path): out = tmp_path / "out.bin" - target = BUILD_DIR / "examples" / "cpp" / "elf_add_section" + target = BUILD_DIR_PATH / "examples" / "cpp" / "elf_add_section" for sample in elf_samples: check_call([target, sample, out]) def test_elf_symbols(tmp_path: Path): out = tmp_path / "out.bin" - target = BUILD_DIR / "examples" / "cpp" / "elf_add_section" + target = BUILD_DIR_PATH / "examples" / "cpp" / "elf_add_section" for sample in elf_samples: check_call([target, sample, out]) diff --git a/tests/elf/test_466.py b/tests/elf/test_466.py index 6d773a05f0..9dfadb4ca2 100644 --- a/tests/elf/test_466.py +++ b/tests/elf/test_466.py @@ -19,13 +19,15 @@ def test_freebl(tmp_path): output_ls = tmp / "ls.new" output_libfreebl3 = tmp / "libfreebl3.so" - libfreebl3 = lief.parse(libfreebl3_path) - ls = lief.parse("/usr/bin/ls") + libfreebl3 = lief.ELF.parse(libfreebl3_path) + ls: lief.ELF.Binary = lief.ELF.parse("/usr/bin/ls") if ls is None: - ls = lief.parse("/bin/ls") + ls = lief.ELF.parse("/bin/ls") - if lief.ELF.DYNAMIC_TAGS.FLAGS_1 in ls and ls[lief.ELF.DYNAMIC_TAGS.FLAGS_1].has(lief.ELF.DYNAMIC_FLAGS_1.PIE): - ls[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE) + if lief.ELF.DynamicEntry.TAG.FLAGS_1 in ls: + flags_1: lief.ELF.DynamicEntryFlags = ls[lief.ELF.DynamicEntry.TAG.FLAGS_1] + if flags_1.has(lief.ELF.DynamicEntryFlags.FLAG.PIE): + flags_1.remove(lief.ELF.DynamicEntryFlags.FLAG.PIE) ls.add_library("libfreebl3.so") diff --git a/tests/elf/test_808.py b/tests/elf/test_808.py index 60206906f8..726f772aa8 100755 --- a/tests/elf/test_808.py +++ b/tests/elf/test_808.py @@ -5,6 +5,6 @@ def test_core_offset_0(): file = get_sample('ELF/ELF_Core_issue_808.core') - core = lief.parse(file) + core = lief.ELF.parse(file) assert len(core.notes) == 7 diff --git a/tests/elf/test_add_content.py b/tests/elf/test_add_content.py index 7e19beec23..2305505b9b 100644 --- a/tests/elf/test_add_content.py +++ b/tests/elf/test_add_content.py @@ -23,7 +23,7 @@ assert STUB_FILE is not None -STUB = lief.parse((CURRENT_DIRECTORY / STUB_FILE).as_posix()) +STUB = lief.ELF.parse((CURRENT_DIRECTORY / STUB_FILE).as_posix()) COMPILER = get_compiler() @@ -93,21 +93,22 @@ def test_simple(tmp_path: Path): libadd_so = compile_libadd(tmp_path) binadd_bin = compile_binadd(tmp_path) - libadd = lief.parse(libadd_so.as_posix()) + libadd = lief.ELF.parse(libadd_so.as_posix()) for _ in range(10): segment = libadd.add(STUB.segments[0]) segment.alignment = 0x1000 new_ep = (STUB.header.entrypoint - STUB.segments[0].virtual_address) + segment.virtual_address - if libadd.has(lief.ELF.DYNAMIC_TAGS.INIT_ARRAY): - init_array = libadd.get(lief.ELF.DYNAMIC_TAGS.INIT_ARRAY) + if libadd.has(lief.ELF.DynamicEntry.TAG.INIT_ARRAY): + init_array = libadd.get(lief.ELF.DynamicEntry.TAG.INIT_ARRAY) + assert isinstance(init_array, lief.ELF.DynamicEntryArray) callbacks = init_array.array callbacks[0] = new_ep init_array.array = callbacks - if libadd.has(lief.ELF.DYNAMIC_TAGS.INIT): - init = libadd.get(lief.ELF.DYNAMIC_TAGS.INIT) + if libadd.has(lief.ELF.DynamicEntry.TAG.INIT): + init = libadd.get(lief.ELF.DynamicEntry.TAG.INIT) init.value = new_ep libadd.write(libadd_so.as_posix()) @@ -120,7 +121,7 @@ def test_simple(tmp_path: Path): "env": {"LD_LIBRARY_PATH": tmp_path.as_posix()}, } - with Popen([binadd_bin, '1', '2'], **popen_args) as P: + with Popen([binadd_bin, '1', '2'], **popen_args) as P: # type: ignore stdout = P.stdout.read().decode("utf8") print(stdout) assert re.search(r'LIEF is Working', stdout) is not None diff --git a/tests/elf/test_add_section.py b/tests/elf/test_add_section.py index bf1932f275..2dd9755a54 100644 --- a/tests/elf/test_add_section.py +++ b/tests/elf/test_add_section.py @@ -19,7 +19,7 @@ elif is_aarch64(): STUB_FILE = "hello_lief_aarch64.bin" -STUB = lief.parse((CWD / STUB_FILE).as_posix()) +STUB = lief.ELF.parse((CWD / STUB_FILE).as_posix()) is_updated_linux = pytest.mark.skipif(not (is_linux() and is_x86_64() and has_recent_glibc()), reason="needs a recent system") @@ -28,11 +28,11 @@ def test_simple(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin') output = tmp_path / "ls.section" - ls = lief.parse(sample_path) + ls = lief.ELF.parse(sample_path) for i in range(10): - section = lief.ELF.Section(f".test.{i}", lief.ELF.SECTION_TYPES.PROGBITS) - section += lief.ELF.SECTION_FLAGS.EXECINSTR - section += lief.ELF.SECTION_FLAGS.WRITE + section = lief.ELF.Section(f".test.{i}", lief.ELF.Section.TYPE.PROGBITS) + section += lief.ELF.Section.FLAGS.EXECINSTR + section += lief.ELF.Section.FLAGS.WRITE section.content = STUB.segments[0].content # First LOAD segment which holds payload if i % 2 == 0: section = ls.add(section, loaded=True) @@ -56,12 +56,12 @@ def test_gcc(tmp_path): sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin') output = tmp_path / "gcc.section" - gcc = lief.parse(sample_path) + gcc = lief.ELF.parse(sample_path) for i in range(10): - section = lief.ELF.Section(f".test.{i}", lief.ELF.SECTION_TYPES.PROGBITS) - section.type = lief.ELF.SECTION_TYPES.PROGBITS - section += lief.ELF.SECTION_FLAGS.EXECINSTR - section += lief.ELF.SECTION_FLAGS.WRITE + section = lief.ELF.Section(f".test.{i}", lief.ELF.Section.TYPE.PROGBITS) + section.type = lief.ELF.Section.TYPE.PROGBITS + section += lief.ELF.Section.FLAGS.EXECINSTR + section += lief.ELF.Section.FLAGS.WRITE section.content = STUB.segments[0].content # First LOAD segment which holds payload if i % 2 == 0: diff --git a/tests/elf/test_add_segment.py b/tests/elf/test_add_segment.py index 6a55771d7c..d5fadb05d0 100644 --- a/tests/elf/test_add_segment.py +++ b/tests/elf/test_add_segment.py @@ -23,10 +23,10 @@ @is_updated_linux def test_simple(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin') - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) output = tmp_path / "ls.segment" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) for _ in range(4): segment = stub.segments[0] original_va = segment.virtual_address @@ -48,10 +48,10 @@ def test_simple(tmp_path: Path): @is_updated_linux def test_gcc(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin') - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) output = tmp_path / "gcc.segment" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) segment = stub.segments[0] original_va = segment.virtual_address segment.virtual_address = 0 @@ -72,10 +72,10 @@ def test_gcc(tmp_path: Path): @is_linux_x64 def test_static(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_static-binary.bin') - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) output = tmp_path / "static.segment" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) segment = stub.segments[0] original_va = segment.virtual_address segment.virtual_address = 0 @@ -111,12 +111,12 @@ def test_add_segment(tmp_path: Path, binpath): stub = None if is_x86_64(): - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) elif is_aarch64(): - stub = lief.parse((CWD / "hello_lief_aarch64.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief_aarch64.bin").as_posix()) - name = target.name - target = lief.parse(target.as_posix()) + name = target.name + elf = lief.ELF.parse(target.as_posix()) output = tmp_path / f"{name}.segment" for _ in range(6): stub_segment = stub.segments[0] @@ -126,11 +126,11 @@ def test_add_segment(tmp_path: Path, binpath): segment.alignment = stub_segment.alignment segment.flags = stub_segment.flags - new_segment = target.add(segment) + new_segment = elf.add(segment) new_ep = (stub.header.entrypoint - stub.imagebase - stub_segment.file_offset) + new_segment.virtual_address - target.header.entrypoint = new_ep - target.write(output.as_posix()) + elf.header.entrypoint = new_ep + elf.write(output.as_posix()) st = os.stat(output) os.chmod(output, st.st_mode | stat.S_IEXEC) diff --git a/tests/elf/test_architectures.py b/tests/elf/test_architectures.py index 31c37c45c2..a4894433e3 100644 --- a/tests/elf/test_architectures.py +++ b/tests/elf/test_architectures.py @@ -2,47 +2,47 @@ from utils import get_sample def test_s390(): - s390 = lief.parse(get_sample("ELF/elf_reader.s390.elf")) + s390 = lief.ELF.parse(get_sample("ELF/elf_reader.s390.elf")) assert len(s390.segments) == 10 assert len(s390.sections) == 32 assert len(s390.dynamic_symbols) == 278 assert len(s390.dynamic_entries) == 27 def test_xtensa(): - xtensa = lief.parse(get_sample("ELF/elf_reader.xtensa.elf")) + xtensa = lief.ELF.parse(get_sample("ELF/elf_reader.xtensa.elf")) assert len(xtensa.segments) == 10 assert len(xtensa.sections) == 30 assert len(xtensa.dynamic_symbols) == 247 assert len(xtensa.dynamic_entries) == 25 def test_mips(): - mips = lief.parse(get_sample("ELF/elf_reader.mips.elf")) + mips = lief.ELF.parse(get_sample("ELF/elf_reader.mips.elf")) assert len(mips.segments) == 12 assert len(mips.sections) == 39 assert len(mips.dynamic_symbols) == 450 assert len(mips.dynamic_entries) == 36 def test_riscv64(): - riscv64 = lief.parse(get_sample("ELF/elf_reader.riscv64.elf")) + riscv64 = lief.ELF.parse(get_sample("ELF/elf_reader.riscv64.elf")) assert len(riscv64.segments) == 10 assert len(riscv64.sections) == 30 assert len(riscv64.dynamic_symbols) == 439 assert len(riscv64.dynamic_entries) == 29 def test_riscv32(): - riscv32 = lief.parse(get_sample("ELF/elf_reader.riscv32.elf")) + riscv32 = lief.ELF.parse(get_sample("ELF/elf_reader.riscv32.elf")) assert len(riscv32.segments) == 10 assert len(riscv32.sections) == 30 assert len(riscv32.dynamic_symbols) == 445 assert len(riscv32.dynamic_entries) == 29 def test_ppc64le(): - ppc64le = lief.parse(get_sample("ELF/elf_reader.ppc64le.elf")) + ppc64le = lief.ELF.parse(get_sample("ELF/elf_reader.ppc64le.elf")) assert len(ppc64le.segments) == 10 assert len(ppc64le.sections) == 32 assert len(ppc64le.dynamic_symbols) == 246 assert len(ppc64le.dynamic_entries) == 29 def test_hexagon(): - hexagon = lief.parse(get_sample("ELF/modem.hexagon.elf")) + hexagon = lief.ELF.parse(get_sample("ELF/modem.hexagon.elf")) assert len(hexagon.segments) == 7 diff --git a/tests/elf/test_bin2lib.py b/tests/elf/test_bin2lib.py index 50d14219c1..0aa5d3ad47 100644 --- a/tests/elf/test_bin2lib.py +++ b/tests/elf/test_bin2lib.py @@ -89,12 +89,15 @@ def run_cmd(cmd): return CommandResult(stdout, stderr, p.returncode) def modif_1(libadd: lief.ELF.Binary, output: Path): - libadd_hidden = libadd.get_symbol("add_hidden") - libadd_hidden.binding = lief.ELF.SYMBOL_BINDINGS.GLOBAL - libadd_hidden.visibility = lief.ELF.SYMBOL_VISIBILITY.DEFAULT - libadd_hidden = libadd.add_dynamic_symbol(libadd_hidden, lief.ELF.SymbolVersion.global_) - if lief.ELF.DYNAMIC_TAGS.FLAGS_1 in libadd and libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].has(lief.ELF.DYNAMIC_FLAGS_1.PIE): - libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE) + libadd_hidden: lief.ELF.Symbol = libadd.get_symbol("add_hidden") + libadd_hidden.binding = lief.ELF.Symbol.BINDING.GLOBAL + libadd_hidden.visibility = lief.ELF.Symbol.VISIBILITY.DEFAULT + libadd_hidden = libadd.add_dynamic_symbol(libadd_hidden, lief.ELF.SymbolVersion.global_) # type: ignore + + if lief.ELF.DynamicEntry.TAG.FLAGS_1 in libadd: + flags_1: lief.ELF.DynamicEntryFlags = libadd[lief.ELF.DynamicEntry.TAG.FLAGS_1] + if flags_1.has(lief.ELF.DynamicEntryFlags.FLAG.PIE): + flags_1.remove(lief.ELF.DynamicEntryFlags.FLAG.PIE) print(libadd_hidden) @@ -104,17 +107,23 @@ def modif_1(libadd: lief.ELF.Binary, output: Path): def modif_2(libadd: lief.ELF.Binary, output: Path): libadd.export_symbol("add_hidden") - if lief.ELF.DYNAMIC_TAGS.FLAGS_1 in libadd and libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].has(lief.ELF.DYNAMIC_FLAGS_1.PIE): - libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE) + if lief.ELF.DynamicEntry.TAG.FLAGS_1 in libadd: + flags_1: lief.ELF.DynamicEntryFlags = libadd[lief.ELF.DynamicEntry.TAG.FLAGS_1] + if flags_1.has(lief.ELF.DynamicEntryFlags.FLAG.PIE): + flags_1.remove(lief.ELF.DynamicEntryFlags.FLAG.PIE) libadd.write(output.as_posix()) def modif_3(libadd: lief.ELF.Binary, output: Path): add_hidden_static = libadd.get_static_symbol("add_hidden") + assert isinstance(add_hidden_static.name, str) libadd.add_exported_function(add_hidden_static.value, add_hidden_static.name) - if lief.ELF.DYNAMIC_TAGS.FLAGS_1 in libadd and libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].has(lief.ELF.DYNAMIC_FLAGS_1.PIE): - libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE) + if lief.ELF.DynamicEntry.TAG.FLAGS_1 in libadd: + flags_1: lief.ELF.DynamicEntryFlags = libadd[lief.ELF.DynamicEntry.TAG.FLAGS_1] + if flags_1.has(lief.ELF.DynamicEntryFlags.FLAG.PIE): + flags_1.remove(lief.ELF.DynamicEntryFlags.FLAG.PIE) + libadd.write(output.as_posix()) @@ -150,7 +159,7 @@ def test_libadd(tmp_path: Path, modifier): output=libadd_so, input=libadd_src)) assert r - libadd = lief.parse(libadd_so.as_posix()) + libadd = lief.ELF.parse(libadd_so.as_posix()) modifier(libadd, libadd2_so) lib_directory = libadd2_so.parent diff --git a/tests/elf/test_binary_size.py b/tests/elf/test_binary_size.py index 78982ca2f6..f00764dd41 100644 --- a/tests/elf/test_binary_size.py +++ b/tests/elf/test_binary_size.py @@ -10,7 +10,7 @@ def test_builder_size(): ] for file in FILES: infile = pathlib.Path(get_sample(file)) - target = lief.parse(infile.as_posix()) + target = lief.ELF.parse(infile.as_posix()) print(infile) builder = lief.ELF.Builder(target) diff --git a/tests/elf/test_bss.py b/tests/elf/test_bss.py index 9731ffd305..b002b992ee 100644 --- a/tests/elf/test_bss.py +++ b/tests/elf/test_bss.py @@ -17,7 +17,7 @@ def test_issue_671(tmp_path: Path): cf. https://github.com/lief-project/LIEF/issues/671 """ binary_name = "nopie_bss_671.elf" - target: lief.ELF.Binary = lief.parse(get_sample(f"ELF/{binary_name}")) + target = lief.ELF.parse(get_sample(f"ELF/{binary_name}")) for s in filter(lambda e: e.exported, target.static_symbols): target.add_dynamic_symbol(s) @@ -26,10 +26,10 @@ def test_issue_671(tmp_path: Path): target.write(output.as_posix()) # Make sure that the PHDR has been relocated at the end: - built = lief.parse(output.as_posix()) - assert built[lief.ELF.SEGMENT_TYPES.PHDR].file_offset == 0x3000 - assert built[lief.ELF.SEGMENT_TYPES.PHDR].physical_size == 0x1f8 - assert built[lief.ELF.SEGMENT_TYPES.PHDR].virtual_address == 0x403000 + built = lief.ELF.parse(output.as_posix()) + assert built[lief.ELF.Segment.TYPE.PHDR].file_offset == 0x3000 + assert built[lief.ELF.Segment.TYPE.PHDR].physical_size == 0x1f8 + assert built[lief.ELF.Segment.TYPE.PHDR].virtual_address == 0x403000 if is_linux() and is_x86_64(): st = os.stat(output) @@ -46,7 +46,7 @@ def test_all(tmp_path: Path): pytest.skip("requires a 64-bits platform") binary_name = "544ca2035a9c15e7756ed8d8067d860bd3157e4eeaa39b4ee932458eebe2434b.elf" - target: lief.ELF.Binary = lief.parse(get_sample(f"ELF/{binary_name}")) + target: lief.ELF.Binary = lief.ELF.parse(get_sample(f"ELF/{binary_name}")) bss = target.get_section(".bss") assert bss.virtual_address == 0x65a3e0 @@ -57,7 +57,7 @@ def test_all(tmp_path: Path): target.add_library("libcap.so.2") # Add segment new_segment = lief.ELF.Segment() - new_segment.type = lief.ELF.SEGMENT_TYPES.LOAD + new_segment.type = lief.ELF.Segment.TYPE.LOAD new_segment.content = [0xCC] * 0x50 target.add(new_segment) @@ -74,5 +74,5 @@ def test_all(tmp_path: Path): assert len(stdout) > 0 # Check that the written binary contains our modifications - new: lief.ELF.Binary = lief.parse(output.as_posix()) + new: lief.ELF.Binary = lief.ELF.parse(output.as_posix()) assert new.get_library("libcap.so.2").name == "libcap.so.2" diff --git a/tests/elf/test_builder.py b/tests/elf/test_builder.py index f11cb5b09b..64ac6a0f72 100644 --- a/tests/elf/test_builder.py +++ b/tests/elf/test_builder.py @@ -63,7 +63,7 @@ def test_force_relocate(tmp_path): if not file.exists(): print(f"{file} does not exist. Skipping ...", file=sys.stderr) continue - elf: lief.ELF.Binary = lief.parse(file.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(file.as_posix()) fsize = file.stat().st_size builder = lief.ELF.Builder(elf) @@ -103,16 +103,16 @@ def test_symtab(tmp_path): tmp = pathlib.Path(tmp_path) out_path = tmp / TARGET.name - elf: lief.ELF.Binary = lief.parse(TARGET.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(TARGET.as_posix()) fsize = TARGET.stat().st_size for i in range(NB_SYMBOLS): sym = lief.ELF.Symbol() sym.name = "test_sym_{:03}".format(i) sym.value = 0x1000 + i - sym.type = lief.ELF.SYMBOL_TYPES.FUNC - sym.binding = lief.ELF.SYMBOL_BINDINGS.LOCAL - sym.visibility = lief.ELF.SYMBOL_VISIBILITY.DEFAULT + sym.type = lief.ELF.Symbol.TYPE.FUNC + sym.binding = lief.ELF.Symbol.BINDING.LOCAL + sym.visibility = lief.ELF.Symbol.VISIBILITY.DEFAULT elf.add_static_symbol(sym) elf.write(out_path.as_posix()) @@ -129,7 +129,7 @@ def test_symtab(tmp_path): assert normalize(OUTPUT) == normalize(stdout) - out = lief.parse(out_path.as_posix()) + out = lief.ELF.parse(out_path.as_posix()) sym_names = [s.name for s in out.static_symbols] assert "test_sym_029" in sym_names @@ -139,7 +139,7 @@ def test_add_interpreter(tmp_path): tmp = pathlib.Path(tmp_path) out_path = tmp / TARGET.name - elf: lief.ELF.Binary = lief.parse(TARGET.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(TARGET.as_posix()) fsize = TARGET.stat().st_size elf.interpreter = "/lib64/ld-linux-x86-64.so.2" @@ -164,7 +164,7 @@ def test_change_interpreter(tmp_path): tmp = pathlib.Path(tmp_path) out_path = tmp / TARGET.name - elf: lief.ELF.Binary = lief.parse(TARGET.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(TARGET.as_posix()) fsize = TARGET.stat().st_size elf.interpreter = "/lib64/ld-linux-x86-64.so.2" @@ -190,7 +190,7 @@ def test_rust_files(tmp_path): tmp = pathlib.Path(tmp_path) out_path = tmp / TARGET.name - elf: lief.ELF.Binary = lief.parse(TARGET.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(TARGET.as_posix()) fsize = TARGET.stat().st_size builder = lief.ELF.Builder(elf) @@ -221,7 +221,7 @@ def test_go_files(tmp_path): tmp = pathlib.Path(tmp_path) out_path = tmp / TARGET.name - elf: lief.ELF.Binary = lief.parse(TARGET.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(TARGET.as_posix()) fsize = TARGET.stat().st_size builder = lief.ELF.Builder(elf) diff --git a/tests/elf/test_core.py b/tests/elf/test_core.py index 2560fdf0a5..259470e4b0 100644 --- a/tests/elf/test_core.py +++ b/tests/elf/test_core.py @@ -7,7 +7,7 @@ lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO) def test_core_arm(): - core: lief.ELF.Binary = lief.parse(get_sample('ELF/ELF32_ARM_core_hello.core')) + core: lief.ELF.Binary = lief.ELF.parse(get_sample('ELF/ELF32_ARM_core_hello.core')) notes = core.notes @@ -145,7 +145,7 @@ def test_core_arm(): def test_core_arm64(): - core = lief.parse(get_sample('ELF/ELF64_AArch64_core_hello.core')) + core = lief.ELF.parse(get_sample('ELF/ELF64_AArch64_core_hello.core')) notes = core.notes @@ -245,6 +245,8 @@ def test_core_arm64(): siginfo = notes[3] assert siginfo.type == lief.ELF.Note.TYPE.CORE_SIGINFO + assert isinstance(siginfo, lief.ELF.CoreSigInfo) + assert siginfo.signo == 5 assert siginfo.sigcode == 0 assert siginfo.sigerrno == 1 @@ -254,6 +256,7 @@ def test_core_arm64(): auxv: lief.ELF.CoreAuxv = notes[4] assert auxv.type == lief.ELF.Note.TYPE.CORE_AUXV + assert isinstance(auxv, lief.ELF.CoreAuxv) # Check details values = auxv.values @@ -283,6 +286,8 @@ def test_core_arm64(): assert note.type == lief.ELF.Note.TYPE.CORE_FILE + assert isinstance(note, lief.ELF.CoreFile) + files = note.files assert len(files) == len(note) assert 22 == len(files) @@ -299,18 +304,22 @@ def test_core_arm64(): assert last.path == "/system/bin/linker64" def test_core_write(tmp_path: Path): - core = lief.parse(get_sample('ELF/ELF64_x86-64_core_hello.core')) + core = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_core_hello.core')) note = core.notes[1] + + assert isinstance(note, lief.ELF.CorePrStatus) assert note.type == lief.ELF.Note.TYPE.CORE_PRSTATUS note[lief.ELF.CorePrStatus.Registers.X86_64.RIP] = 0xBADC0DE note = core.notes[5] + assert isinstance(note, lief.ELF.CoreAuxv) assert note.type == lief.ELF.Note.TYPE.CORE_AUXV note[lief.ELF.CoreAuxv.TYPE.ENTRY] = 0xBADC0DE note = core.notes[4] + assert isinstance(note, lief.ELF.CoreSigInfo) assert note.type == lief.ELF.Note.TYPE.CORE_SIGINFO orig_siginfo_len = len(note.description) note.sigerrno = 0xCC @@ -322,20 +331,23 @@ def test_core_write(tmp_path: Path): # Cannot re-open a file on Windows, so handle it by hand core.write(output.as_posix(), config) - core_new = lief.parse(output.as_posix()) + core_new = lief.ELF.parse(output.as_posix()) assert core_new is not None note = core_new.notes[1] assert note.type == lief.ELF.Note.TYPE.CORE_PRSTATUS - + assert isinstance(note, lief.ELF.CorePrStatus) assert note[lief.ELF.CorePrStatus.Registers.X86_64.RIP] == 0xBADC0DE note = core_new.notes[5] + assert isinstance(note, lief.ELF.CoreAuxv) assert note.type == lief.ELF.Note.TYPE.CORE_AUXV assert note[lief.ELF.CoreAuxv.TYPE.ENTRY] == 0xBADC0DE note = core_new.notes[4] + + assert isinstance(note, lief.ELF.CoreSigInfo) assert note.type == lief.ELF.Note.TYPE.CORE_SIGINFO assert len(note.description) == orig_siginfo_len diff --git a/tests/elf/test_corrupted.py b/tests/elf/test_corrupted.py index 1389b5fd9d..34d5ff7098 100644 --- a/tests/elf/test_corrupted.py +++ b/tests/elf/test_corrupted.py @@ -1,7 +1,7 @@ import lief from utils import get_sample -TARGET = lief.parse(get_sample('ELF/ELF32_x86_library_libshellx.so')) +TARGET = lief.ELF.parse(get_sample('ELF/ELF32_x86_library_libshellx.so')) def test_symbols(): symbols = [sym for idx, sym in enumerate(TARGET.dynamic_symbols) if idx == 0 or len(sym.name) > 0] diff --git a/tests/elf/test_dynamic.py b/tests/elf/test_dynamic.py index 98795302c7..ff8eac198c 100644 --- a/tests/elf/test_dynamic.py +++ b/tests/elf/test_dynamic.py @@ -89,7 +89,7 @@ def test_add_dynamic_symbols(tmp_path: Path, style): compile_libadd(libadd_so, libadd_c, [link_opt]) compile_binadd(binadd_bin, binadd_c, [link_opt]) - libadd = lief.parse(libadd_so.as_posix()) + libadd = lief.ELF.parse(libadd_so.as_posix()) dynamic_symbols = list(libadd.dynamic_symbols) for sym in dynamic_symbols: @@ -107,13 +107,13 @@ def test_add_dynamic_symbols(tmp_path: Path, style): 'env' : {"LD_LIBRARY_PATH": tmp_path.as_posix()} } - with Popen([binadd_bin, '1', '2'], **opt) as P: + with Popen([binadd_bin, '1', '2'], **opt) as P: # type: ignore stdout = P.stdout.read().decode("utf8") P.communicate() assert P.returncode == 0 assert "From myLIb, a + b = 3" in stdout - libadd = lief.parse(libadd_so.as_posix()) + libadd = lief.ELF.parse(libadd_so.as_posix()) dynamic_section = libadd.get_section(".dynsym") # TODO: Size of libadd.dynamic_symbols is larger than dynamic_symbols_size. dynamic_symbols_size = int(dynamic_section.size / dynamic_section.entry_size) @@ -122,10 +122,10 @@ def test_add_dynamic_symbols(tmp_path: Path, style): first_not_null_symbol_index = dynamic_section.information first_exported_symbol_index = next(i for i, sym in enumerate(dynamic_symbols) if sym.shndx != 0) - assert all(map(lambda sym: sym.shndx == 0 and sym.binding == lief.ELF.SYMBOL_BINDINGS.LOCAL, + assert all(map(lambda sym: sym.shndx == 0 and sym.binding == lief.ELF.Symbol.BINDING.LOCAL, dynamic_symbols[:first_not_null_symbol_index])) - assert (all(map(lambda sym: sym.shndx == 0 and sym.binding != lief.ELF.SYMBOL_BINDINGS.LOCAL, + assert (all(map(lambda sym: sym.shndx == 0 and sym.binding != lief.ELF.Symbol.BINDING.LOCAL, dynamic_symbols[first_not_null_symbol_index:first_exported_symbol_index]))) assert (all(map(lambda sym: sym.shndx != 0, dynamic_symbols[first_exported_symbol_index:]))) @@ -144,7 +144,7 @@ def test_remove_library(tmp_path: Path): compile_libadd(libadd_so, libadd_c, []) compile_binadd(binadd_bin, binadd_c, []) - binadd = lief.parse(binadd_bin.as_posix()) + binadd = lief.ELF.parse(binadd_bin.as_posix()) libadd_needed = binadd.get_library("libadd.so") binadd -= libadd_needed @@ -165,10 +165,10 @@ def test_remove_tag(tmp_path: Path): compile_libadd(libadd_so, libadd_c, []) compile_binadd(binadd_bin, binadd_c, []) - binadd = lief.parse(binadd_bin.as_posix()) + binadd = lief.ELF.parse(binadd_bin.as_posix()) - binadd -= lief.ELF.DYNAMIC_TAGS.NEEDED - assert all(e.tag != lief.ELF.DYNAMIC_TAGS.NEEDED for e in binadd.dynamic_entries) + binadd -= lief.ELF.DynamicEntry.TAG.NEEDED + assert all(e.tag != lief.ELF.DynamicEntry.TAG.NEEDED for e in binadd.dynamic_entries) @pytest.mark.skipif(not is_linux(), reason="requires Linux") def test_runpath_api(tmp_path: Path): @@ -184,7 +184,7 @@ def test_runpath_api(tmp_path: Path): compile_libadd(libadd_so, libadd_c, []) compile_binadd(binadd_bin, binadd_c, []) - binadd = lief.parse(binadd_bin.as_posix()) + binadd = lief.ELF.parse(binadd_bin.as_posix()) rpath = lief.ELF.DynamicEntryRunPath() rpath = binadd.add(rpath) @@ -223,21 +223,22 @@ def test_change_libname(tmp_path: Path): compile_libadd(libadd_so, libadd_c, []) compile_binadd(binadd_bin, binadd_c, []) - libadd = lief.parse(libadd_so.as_posix()) - binadd = lief.parse(binadd_bin.as_posix()) + libadd = lief.ELF.parse(libadd_so.as_posix()) + binadd = lief.ELF.parse(binadd_bin.as_posix()) new_name = "libwhichhasalongverylongname.so" - assert lief.ELF.DYNAMIC_TAGS.SONAME in libadd - - libadd[lief.ELF.DYNAMIC_TAGS.SONAME].name = new_name + assert lief.ELF.DynamicEntry.TAG.SONAME in libadd + soname_entry: lief.ELF.DynamicEntryLibrary = libadd[lief.ELF.DynamicEntry.TAG.SONAME] + soname_entry.name = new_name libfoo_path = tmp_path / new_name libadd.write(libfoo_path.as_posix()) - libfoo = lief.parse(libfoo_path.as_posix()) + libfoo = lief.ELF.parse(libfoo_path.as_posix()) - new_so_name = libfoo[lief.ELF.DYNAMIC_TAGS.SONAME] + new_so_name = libfoo[lief.ELF.DynamicEntry.TAG.SONAME] + assert isinstance(new_so_name, lief.ELF.DynamicSharedObject) # Check builder did the job right assert new_so_name.name == new_name diff --git a/tests/elf/test_elf.py b/tests/elf/test_elf.py index 184419c88f..08490defc9 100644 --- a/tests/elf/test_elf.py +++ b/tests/elf/test_elf.py @@ -17,33 +17,32 @@ def test_rpath(): - etterlog = lief.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) + etterlog = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) dynamic_entries = etterlog.dynamic_entries - rpath = [e for e in dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH] + rpath = [e for e in dynamic_entries if e.tag == lief.ELF.DynamicEntry.TAG.RPATH] assert len(rpath) == 1 - rpath = rpath.pop() - - assert rpath.name == "/usr/lib" - assert rpath.rpath == rpath.name + last = rpath.pop() + assert isinstance(last, lief.ELF.DynamicEntryRpath) + assert last.rpath == "/usr/lib" def test_runpath(): - etterlog = lief.parse(get_sample('ELF/ELF64_x86-64_binary_systemd-resolve.bin')) + etterlog = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_systemd-resolve.bin')) dynamic_entries = etterlog.dynamic_entries - runpath = [e for e in dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RUNPATH] + runpath = [e for e in dynamic_entries if e.tag == lief.ELF.DynamicEntry.TAG.RUNPATH] assert len(runpath) == 1 - runpath = runpath.pop() - - assert runpath.name == "/usr/lib/systemd" + last = runpath.pop() + assert isinstance(last, lief.ELF.DynamicEntryRunPath) + assert last.runpath == "/usr/lib/systemd" def test_gnuhash(): - ls = lief.parse(get_sample('ELF/ELF64_x86-64_binary_ls.bin')) + ls = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_ls.bin')) gnu_hash = ls.gnu_hash assert gnu_hash.nb_buckets == 33 @@ -73,7 +72,7 @@ def test_gnuhash(): #for s in list(ls.dynamic_symbols)[gnu_hash.symbol_index:]: # print(gnu_hash.check(s.name), s.name) - assert all(gnu_hash.check(x.name) for x in list(ls.dynamic_symbols)[gnu_hash.symbol_index:]) + assert all(gnu_hash.check(x.name) for x in list(ls.dynamic_symbols)[gnu_hash.symbol_index:]) # type: ignore assert not gnu_hash.check("foofdsfdsfds") assert not gnu_hash.check("fazertrvkdfsrezklqpfjeopqdi") @@ -83,7 +82,7 @@ def test_gnuhash(): ]) def test_permutation(tmp_path: Path, sample: str): - binary = lief.parse(get_sample(sample)) + binary = lief.ELF.parse(get_sample(sample)) dynamic_symbols = binary.dynamic_symbols permutation = list(range(1, len(dynamic_symbols))) @@ -110,7 +109,7 @@ def test_permutation(tmp_path: Path, sample: str): assert P.returncode == 0 def test_notes(): - systemd_resolve = lief.parse(get_sample('ELF/ELF64_x86-64_binary_systemd-resolve.bin')) + systemd_resolve = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_systemd-resolve.bin')) notes = systemd_resolve.notes assert len(notes) == 3 @@ -140,7 +139,7 @@ def test_notes(): assert "".join(map(chr, n3.description)) == "gold 1.12\x00\x00\x00" def test_symbols_access(): - hello = lief.parse(get_sample('ELF/ELF64_x86-64_binary_hello-gdb.bin')) + hello = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_hello-gdb.bin')) symbols = hello.symbols dynamic_symbols = hello.dynamic_symbols @@ -150,81 +149,84 @@ def test_symbols_access(): assert all(s in symbols for s in static_symbols) def test_strings(): - hello = lief.parse(get_sample('ELF/ELF64_x86-64_binary_all.bin')) + hello = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_all.bin')) assert len(hello.strings) > 0 assert "add_1" in hello.strings def test_relocation_size(): - aarch64_toybox = lief.parse(get_sample('ELF/ELF64_AARCH64_piebinary_toybox.pie')) - arm_ls = lief.parse(get_sample('ELF/ELF32_ARM_binary_ls.bin')) - x86_ls = lief.parse(get_sample('ELF/ELF32_x86_binary_ls.bin')) - x86_64_ls = lief.parse(get_sample('ELF/ELF64_x86-64_binary_ld.bin')) + aarch64_toybox = lief.ELF.parse(get_sample('ELF/ELF64_AARCH64_piebinary_toybox.pie')) + arm_ls = lief.ELF.parse(get_sample('ELF/ELF32_ARM_binary_ls.bin')) + x86_ls = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_ls.bin')) + x86_64_ls = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_ld.bin')) for r in itertools.chain(aarch64_toybox.dynamic_relocations, aarch64_toybox.pltgot_relocations): - if r.type == lief.ELF.RELOCATION_AARCH64.RELATIVE: + if r.type == lief.ELF.Relocation.TYPE.AARCH64_RELATIVE: assert r.size == 64 - if r.type == lief.ELF.RELOCATION_AARCH64.GLOB_DAT: + if r.type == lief.ELF.Relocation.TYPE.AARCH64_GLOB_DAT: assert r.size == 64 - if r.type == lief.ELF.RELOCATION_AARCH64.JUMP_SLOT: + if r.type == lief.ELF.Relocation.TYPE.AARCH64_JUMP_SLOT: assert r.size == 64 for r in itertools.chain(arm_ls.dynamic_relocations, arm_ls.pltgot_relocations): - if r.type == lief.ELF.RELOCATION_ARM.RELATIVE: + if r.type == lief.ELF.Relocation.TYPE.ARM_RELATIVE: assert r.size == 32 - if r.type == lief.ELF.RELOCATION_ARM.GLOB_DAT: + if r.type == lief.ELF.Relocation.TYPE.ARM_GLOB_DAT: assert r.size == 32 - if r.type == lief.ELF.RELOCATION_ARM.ABS32: + if r.type == lief.ELF.Relocation.TYPE.ARM_ABS32: assert r.size == 32 - if r.type == lief.ELF.RELOCATION_ARM.JUMP_SLOT: + if r.type == lief.ELF.Relocation.TYPE.ARM_JUMP_SLOT: assert r.size == 32 for r in itertools.chain(x86_ls.dynamic_relocations, x86_ls.pltgot_relocations): - if r.type == lief.ELF.RELOCATION_i386.GLOB_DAT: + if r.type == lief.ELF.Relocation.TYPE.X86_GLOB_DAT: assert r.size == 32 - if r.type == lief.ELF.RELOCATION_i386.COPY: + if r.type == lief.ELF.Relocation.TYPE.X86_COPY: assert r.size == 32 - if r.type == lief.ELF.RELOCATION_i386.JUMP_SLOT: + if r.type == lief.ELF.Relocation.TYPE.X86_JUMP_SLOT: assert r.size == 32 for r in itertools.chain(x86_64_ls.dynamic_relocations, x86_64_ls.pltgot_relocations): - if r.type == lief.ELF.RELOCATION_X86_64.GLOB_DAT: + if r.type == lief.ELF.Relocation.TYPE.X86_64_GLOB_DAT: assert r.size == 64 - if r.type == lief.ELF.RELOCATION_X86_64.COPY: + if r.type == lief.ELF.Relocation.TYPE.X86_64_COPY: assert r.size == 32 - if r.type == lief.ELF.RELOCATION_X86_64.JUMP_SLOT: + if r.type == lief.ELF.Relocation.TYPE.X86_64_JUMP_SLOT: assert r.size == 64 def test_sectionless(): sample = "ELF/ELF64_x86-64_binary_rvs.bin" - rvs = lief.parse(get_sample(sample)) + rvs = lief.ELF.parse(get_sample(sample)) dynsym = list(rvs.dynamic_symbols) assert len(dynsym) == 10 def test_dynamic_flags(): sample = "ELF/ELF32_ARM_binary_ls.bin" - ls = lief.parse(get_sample(sample)) - d_flags = ls.get(lief.ELF.DYNAMIC_TAGS.FLAGS) - d_flags_1 = ls.get(lief.ELF.DYNAMIC_TAGS.FLAGS_1) + ls = lief.ELF.parse(get_sample(sample)) + d_flags = ls.get(lief.ELF.DynamicEntry.TAG.FLAGS) + d_flags_1 = ls.get(lief.ELF.DynamicEntry.TAG.FLAGS_1) + + assert isinstance(d_flags, lief.ELF.DynamicEntryFlags) + assert isinstance(d_flags_1, lief.ELF.DynamicEntryFlags) - assert lief.ELF.DYNAMIC_FLAGS.BIND_NOW in d_flags - assert lief.ELF.DYNAMIC_FLAGS_1.NOW in d_flags_1 + assert lief.ELF.DynamicEntryFlags.FLAG.BIND_NOW in d_flags + assert lief.ELF.DynamicEntryFlags.FLAG.NOW in d_flags_1 def test_unwind_arm(): sample = "ELF/ELF32_ARM_binary_ls.bin" - ls = lief.parse(get_sample(sample)) + ls = lief.ELF.parse(get_sample(sample)) functions = sorted(ls.functions, key=lambda f: f.address) @@ -241,7 +243,7 @@ def test_unwind_arm(): def test_unwind_x86(): sample = "ELF/ELF64_x86-64_binary_ld.bin" - ld = lief.parse(get_sample(sample)) + ld = lief.ELF.parse(get_sample(sample)) functions = sorted(ld.functions, key=lambda f: f.address) @@ -261,7 +263,7 @@ def test_unwind_x86(): def test_misc(): sample = "ELF/ELF64_x86-64_binary_ld.bin" - ld = lief.parse(get_sample(sample)) + ld = lief.ELF.parse(get_sample(sample)) text = ld.get_section(".text") @@ -283,6 +285,6 @@ def test_misc(): .replace(" ", " ") \ .replace(" ", " ").strip() hexdigits = raw.split(" ") - raw = bytes(int(c, 16) for c in hexdigits) + raw_bytes = bytes(int(c, 16) for c in hexdigits) - assert isinstance(lief.ELF.Segment.from_raw(raw), lief.ELF.Segment) + assert isinstance(lief.ELF.Segment.from_raw(raw_bytes), lief.ELF.Segment) diff --git a/tests/elf/test_elf_config.py b/tests/elf/test_elf_config.py index 323e162866..0d81404d5b 100644 --- a/tests/elf/test_elf_config.py +++ b/tests/elf/test_elf_config.py @@ -9,7 +9,7 @@ def test_config_1(): config.parse_static_symbols = False config.parse_symbol_versions = False config.parse_notes = False - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.SECTION + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION fpath = get_sample("ELF/ELF64_AARCH64_piebinary_linker64.pie") elf = lief.ELF.parse(fpath, config) @@ -30,7 +30,7 @@ def test_config_2(): config.parse_static_symbols = False config.parse_symbol_versions = False config.parse_notes = False - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.SECTION + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION fpath = get_sample("ELF/ELF64_x86-64_binary_ld.bin") elf = lief.ELF.parse(fpath, config) @@ -50,7 +50,7 @@ def test_config_3(): config.parse_static_symbols = True config.parse_symbol_versions = False config.parse_notes = False - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.SECTION + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION fpath = get_sample("ELF/ELF64_x86-64_binary_hello-c-debug.bin") elf = lief.ELF.parse(fpath, config) @@ -67,7 +67,7 @@ def test_config_no_overlay(): config.parse_overlay = False fpath = get_sample("ELF/batch-x86-64/test.dart.bin") - assert len(lief.parse(fpath).overlay) > 0 + assert len(lief.ELF.parse(fpath).overlay) > 0 elf = lief.ELF.parse(fpath) assert elf.has_overlay elf = lief.ELF.parse(fpath, config) diff --git a/tests/elf/test_empty_gnu_hash.py b/tests/elf/test_empty_gnu_hash.py index dc53203c8b..62624a591a 100644 --- a/tests/elf/test_empty_gnu_hash.py +++ b/tests/elf/test_empty_gnu_hash.py @@ -20,8 +20,9 @@ def test_gnu_hash(tmpdir): target_path = get_sample('ELF/ELF64_x86-64_binary_empty-gnu-hash.bin') output = os.path.join(tmpdir, "libnoempty.so") - binary = lief.parse(target_path) - binary[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE) + binary = lief.ELF.parse(target_path) + entry_flag: lief.ELF.DynamicEntryFlags = binary[lief.ELF.DynamicEntry.TAG.FLAGS_1] + entry_flag.remove(lief.ELF.DynamicEntryFlags.FLAG.PIE) for name, addr in SYMBOLS.items(): binary.add_exported_function(addr, name) diff --git a/tests/elf/test_equality.py b/tests/elf/test_equality.py index 22f0d91a4f..7efc001289 100644 --- a/tests/elf/test_equality.py +++ b/tests/elf/test_equality.py @@ -11,10 +11,10 @@ ]) def test_equal(tmp_path: Path, elf): infile = get_sample(elf) - inelf = lief.parse(infile) + inelf = lief.ELF.parse(infile) output = tmp_path / Path(infile).name inelf.write(output.as_posix()) - newelf = lief.parse(output.as_posix()) + newelf = lief.ELF.parse(output.as_posix()) assert inelf.header == newelf.header diff --git a/tests/elf/test_hash.py b/tests/elf/test_hash.py index adf2a1fb0f..c07e7a726b 100644 --- a/tests/elf/test_hash.py +++ b/tests/elf/test_hash.py @@ -87,8 +87,8 @@ def test_simple(tmp_path: Path, flag: str): libadd_so = compile_libadd(tmp_path, flag) binadd_bin = compile_binadd(tmp_path, flag) - libadd = lief.parse(libadd_so.as_posix()) - binadd = lief.parse(binadd_bin.as_posix()) + libadd = lief.ELF.parse(libadd_so.as_posix()) + binadd = lief.ELF.parse(binadd_bin.as_posix()) libadd_dynsym = libadd.dynamic_symbols binadd_dynsym = binadd.dynamic_symbols @@ -106,7 +106,10 @@ def test_simple(tmp_path: Path, flag: str): # change library name in the binary for entry in binadd.dynamic_entries: - if entry.tag == lief.ELF.DYNAMIC_TAGS.NEEDED and entry.name == "libadd.so": + if (entry.tag == lief.ELF.DynamicEntry.TAG.NEEDED and + isinstance(entry, lief.ELF.DynamicEntryLibrary) and + entry.name == "libadd.so" + ): entry.name = "libabc.so" libadd_modified = tmp_path / "libabc.so" @@ -126,7 +129,7 @@ def test_simple(tmp_path: Path, flag: str): "stderr": subprocess.STDOUT, "env": {"LD_LIBRARY_PATH": tmp_path.as_posix()}, } - with Popen([binadd_bin, '1', '2'], **popen_args) as P: + with Popen([binadd_bin, '1', '2'], **popen_args) as P: # type: ignore stdout = P.stdout.read().decode("utf8") print(stdout) assert "From myLIb, a + b = 3" in stdout diff --git a/tests/elf/test_i872.py b/tests/elf/test_i872.py index d0459ab493..433a1945f3 100644 --- a/tests/elf/test_i872.py +++ b/tests/elf/test_i872.py @@ -13,13 +13,13 @@ def test_issue_872(tmp_path): tmp = pathlib.Path(tmp_path) - elf: lief.ELF.Binary = lief.parse(get_sample('ELF/i872_risv.elf')) + elf: lief.ELF.Binary = lief.ELF.parse(get_sample('ELF/i872_risv.elf')) payload_sec = elf.get_section(".payload") offset = payload_sec.offset new_section = lief.ELF.Section(".new_section") new_section.virtual_address = 0xa0000000 - new_section.add(lief.ELF.SECTION_FLAGS.ALLOC) + new_section.add(lief.ELF.Section.FLAGS.ALLOC) new_section.size = 0x1000 new_section.content = [0xa5] * 0x1000 elf.add(new_section) @@ -51,7 +51,7 @@ def test_static_musl(tmp_path, mode): elf.relocate_phdr_table(mode) segment = lief.ELF.Segment() - segment.type = lief.ELF.SEGMENT_TYPES.LOAD + segment.type = lief.ELF.Segment.TYPE.LOAD segment.content = [0xcc for _ in range(0x2000)] elf.add(segment) @@ -65,7 +65,7 @@ def test_static_musl(tmp_path, mode): "universal_newlines": True } - with Popen([outpath.as_posix()], **popen_args) as proc: + with Popen([outpath.as_posix()], **popen_args) as proc: # type: ignore stdout = proc.stdout.read() assert "Hello World" in stdout, f"Error: {stdout}" @@ -82,7 +82,7 @@ def test_static_musl_bss(tmp_path, mode): elf.relocate_phdr_table(mode) segment = lief.ELF.Segment() - segment.type = lief.ELF.SEGMENT_TYPES.LOAD + segment.type = lief.ELF.Segment.TYPE.LOAD segment.content = [0xcc for _ in range(0x2000)] elf.add(segment) @@ -96,7 +96,7 @@ def test_static_musl_bss(tmp_path, mode): "universal_newlines": True } - with Popen([outpath.as_posix()], **popen_args) as proc: + with Popen([outpath.as_posix()], **popen_args) as proc: # type: ignore stdout = proc.stdout.read() assert "Hello World" in stdout, f"Error: {stdout}" @@ -112,7 +112,7 @@ def test_static(tmp_path, mode): elf.relocate_phdr_table(mode) segment = lief.ELF.Segment() - segment.type = lief.ELF.SEGMENT_TYPES.LOAD + segment.type = lief.ELF.Segment.TYPE.LOAD segment.content = [0xcc for _ in range(0x2000)] elf.add(segment) @@ -126,7 +126,7 @@ def test_static(tmp_path, mode): "universal_newlines": True } - with Popen([outpath.as_posix()], **popen_args) as proc: + with Popen([outpath.as_posix()], **popen_args) as proc: # type: ignore stdout = proc.stdout.read() assert "Hello World" in stdout, f"Error: {stdout}" @@ -143,7 +143,7 @@ def test_static_bss(tmp_path, mode): elf.relocate_phdr_table(mode) segment = lief.ELF.Segment() - segment.type = lief.ELF.SEGMENT_TYPES.LOAD + segment.type = lief.ELF.Segment.TYPE.LOAD segment.content = [0xcc for _ in range(0x2000)] elf.add(segment) @@ -157,7 +157,7 @@ def test_static_bss(tmp_path, mode): "universal_newlines": True } - with Popen([outpath.as_posix()], **popen_args) as proc: + with Popen([outpath.as_posix()], **popen_args) as proc: # type: ignore stdout = proc.stdout.read() assert "Hello World" in stdout, f"Error: {stdout}" @@ -173,7 +173,7 @@ def test_docker_init(tmp_path, mode): elf.relocate_phdr_table(mode) segment = lief.ELF.Segment() - segment.type = lief.ELF.SEGMENT_TYPES.LOAD + segment.type = lief.ELF.Segment.TYPE.LOAD segment.content = [0xcc for _ in range(0x2000)] elf.add(segment) @@ -187,6 +187,6 @@ def test_docker_init(tmp_path, mode): "universal_newlines": True } - with Popen([outpath.as_posix(), "--version"], **popen_args) as proc: + with Popen([outpath.as_posix(), "--version"], **popen_args) as proc: # type: ignore stdout = proc.stdout.read() assert "tini version 0.19.0" in stdout, f"Error: {stdout}" diff --git a/tests/elf/test_issues.py b/tests/elf/test_issues.py index da1eeed2dd..1f243e66f9 100755 --- a/tests/elf/test_issues.py +++ b/tests/elf/test_issues.py @@ -7,7 +7,7 @@ from utils import get_sample def test_issue_863(tmp_path: Path): - elf = lief.parse(get_sample('ELF/issue_863.elf')) + elf = lief.ELF.parse(get_sample('ELF/issue_863.elf')) assert elf.sysv_hash.nchain == 7 @@ -16,7 +16,7 @@ def test_issue_863(tmp_path: Path): out = tmp_path / "issue_863.modified" elf.write(out.as_posix()) - new = lief.parse(out.as_posix()) + new = lief.ELF.parse(out.as_posix()) assert new.sysv_hash.nchain == 6 def test_pr_968(): diff --git a/tests/elf/test_loongarch.py b/tests/elf/test_loongarch.py index 59dd755421..543608d0e6 100644 --- a/tests/elf/test_loongarch.py +++ b/tests/elf/test_loongarch.py @@ -8,4 +8,4 @@ def test_loongarch(): relocation = elf.relocations[0] assert relocation.size == 26 - assert relocation.type == int(lief.ELF.RELOCATION_LOONGARCH.LARCH_B26) + assert relocation.type == int(lief.ELF.Relocation.TYPE.LARCH_B26) diff --git a/tests/elf/test_modify_relocations.py b/tests/elf/test_modify_relocations.py index 6a82359d32..d4682cf330 100644 --- a/tests/elf/test_modify_relocations.py +++ b/tests/elf/test_modify_relocations.py @@ -17,9 +17,9 @@ def test_simple(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin') output = tmp_path / "ls.relocation" - ls = lief.parse(sample_path) + ls = lief.ELF.parse(sample_path) - relocation = lief.ELF.Relocation(0x61D370, type=lief.ELF.RELOCATION_X86_64.JUMP_SLOT, is_rela=True) + relocation = lief.ELF.Relocation(0x61D370, type=lief.ELF.Relocation.TYPE.X86_64_JUMP_SLOT, is_rela=True) symbol = lief.ELF.Symbol() symbol.name = "printf123" @@ -43,9 +43,9 @@ def test_all(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_all.bin') output = tmp_path / "all.relocation" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) - relocation = lief.ELF.Relocation(0x201028, type=lief.ELF.RELOCATION_X86_64.JUMP_SLOT, is_rela=True) + relocation = lief.ELF.Relocation(0x201028, type=lief.ELF.Relocation.TYPE.X86_64_JUMP_SLOT, is_rela=True) symbol = lief.ELF.Symbol() symbol.name = "printf123" @@ -69,9 +69,9 @@ def test_all32(tmp_path: Path): sample_path = get_sample('ELF/ELF32_x86_binary_all.bin') output = tmp_path / "all32.relocation" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) - relocation = lief.ELF.Relocation(0x2018, type=lief.ELF.RELOCATION_i386.JUMP_SLOT, is_rela=False) + relocation = lief.ELF.Relocation(0x2018, type=lief.ELF.Relocation.TYPE.X86_JUMP_SLOT, is_rela=False) symbol = lief.ELF.Symbol() symbol.name = "printf123" @@ -81,5 +81,5 @@ def test_all32(tmp_path: Path): target.write(output.as_posix()) - new = lief.parse(output.as_posix()) + new = lief.ELF.parse(output.as_posix()) assert new.has_symbol("printf123") diff --git a/tests/elf/test_notes.py b/tests/elf/test_notes.py index 51448d4fbb..7c7687a5ee 100644 --- a/tests/elf/test_notes.py +++ b/tests/elf/test_notes.py @@ -12,7 +12,7 @@ config.notes = True; def test_change_note(tmp_path: Path): - etterlog = lief.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) + etterlog = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) build_id = etterlog[lief.ELF.Note.TYPE.GNU_BUILD_ID] new_desc = [i & 0xFF for i in range(500)] @@ -20,12 +20,12 @@ def test_change_note(tmp_path: Path): output = tmp_path / "etterlog" etterlog.write(output.as_posix(), config) - etterlog_updated = lief.parse(output.as_posix()) + etterlog_updated = lief.ELF.parse(output.as_posix()) assert etterlog[lief.ELF.Note.TYPE.GNU_BUILD_ID] == etterlog_updated[lief.ELF.Note.TYPE.GNU_BUILD_ID] def test_remove_note(tmp_path: Path): - etterlog = lief.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) + etterlog = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) output = tmp_path / "etterlog" print(output) @@ -34,11 +34,11 @@ def test_remove_note(tmp_path: Path): etterlog -= build_id etterlog.write(output.as_posix(), config) - etterlog_updated = lief.parse(output.as_posix()) + etterlog_updated = lief.ELF.parse(output.as_posix()) assert lief.ELF.Note.TYPE.GNU_BUILD_ID not in etterlog_updated def test_add_note(tmp_path: Path): - etterlog = lief.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) + etterlog = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_etterlog.bin')) output = tmp_path / "etterlog" note = lief.ELF.Note.create("Foo", lief.ELF.Note.TYPE.GNU_GOLD_VERSION, [1, 2]) @@ -46,7 +46,7 @@ def test_add_note(tmp_path: Path): etterlog.write(output.as_posix(), config) - etterlog_updated = lief.parse(output.as_posix()) + etterlog_updated = lief.ELF.parse(output.as_posix()) assert lief.ELF.Note.TYPE.GNU_GOLD_VERSION in etterlog_updated @@ -59,7 +59,7 @@ def test_add_note(tmp_path: Path): def test_android_note(tmp_path: Path): - ndkr16 = lief.parse(get_sample('ELF/ELF64_AArch64_piebinary_ndkr16.bin')) + ndkr16 = lief.ELF.parse(get_sample('ELF/ELF64_AArch64_piebinary_ndkr16.bin')) output = tmp_path / "etterlog" note: lief.ELF.AndroidIdent = ndkr16.get(lief.ELF.Note.TYPE.ANDROID_IDENT) @@ -79,7 +79,7 @@ def test_android_note(tmp_path: Path): ndkr16.write(output.as_posix(), config) - ndkr15 = lief.parse(output.as_posix()) + ndkr15 = lief.ELF.parse(output.as_posix()) note = ndkr15.get(lief.ELF.Note.TYPE.ANDROID_IDENT) @@ -89,13 +89,13 @@ def test_android_note(tmp_path: Path): def test_issue_816(tmp_path: Path): - elf = lief.parse(get_sample('ELF/elf_notes_issue_816.bin')) + elf = lief.ELF.parse(get_sample('ELF/elf_notes_issue_816.bin')) output = tmp_path / "elf_notes_issue_816" assert len(elf.notes) == 40 elf.write(output.as_posix(), config) - new = lief.parse(output.as_posix()) + new = lief.ELF.parse(output.as_posix()) assert len(new.notes) == 40 def test_crashpad(): @@ -108,13 +108,14 @@ def test_note_aarch64_features(): GNU_PROPERTY_AARCH64_FEATURE_1_AND = "040000001000000005000000474e5500000000c0040000000100000000000000" note: lief.ELF.NoteGnuProperty = lief.ELF.Note.create(raw=bytes.fromhex(GNU_PROPERTY_AARCH64_FEATURE_1_AND), - file_type=lief.ELF.E_TYPE.NONE, arch=lief.ELF.ARCH.AARCH64, - cls=lief.ELF.ELF_CLASS.CLASS64) + file_type=lief.ELF.Header.FILE_TYPE.NONE, arch=lief.ELF.ARCH.AARCH64, + cls=lief.ELF.Header.CLASS.ELF64) assert len(note.properties) == 1 assert note.find(lief.ELF.NoteGnuProperty.Property.TYPE.AARCH64_FEATURES) is not None assert note.find(lief.ELF.NoteGnuProperty.Property.TYPE.GENERIC) is None + assert isinstance(note.properties[0], lief.ELF.AArch64Feature) - assert note.properties[0].features == [lief._lief.ELF.AArch64Feature.FEATURE.BTI] + assert note.properties[0].features == [lief.ELF.AArch64Feature.FEATURE.BTI] assert note.properties[0].type == lief.ELF.NoteGnuProperty.Property.TYPE.AARCH64_FEATURES assert str(note.properties[0]) print(note.properties[0]) @@ -123,20 +124,20 @@ def test_note_aarch64_features(): def test_note_x86_isa(): GNU_PROPERTY_X86_ISA_1_NEEDED = "040000001800000005000000474e5500028000c00400000001000000020001c00400000000000000" note: lief.ELF.NoteGnuProperty = lief.ELF.Note.create(raw=bytes.fromhex(GNU_PROPERTY_X86_ISA_1_NEEDED), - file_type=lief.ELF.E_TYPE.NONE, arch=lief.ELF.ARCH.x86_64, - cls=lief.ELF.ELF_CLASS.CLASS64) + file_type=lief.ELF.Header.FILE_TYPE.NONE, arch=lief.ELF.ARCH.X86_64, + cls=lief.ELF.Header.CLASS.ELF64) assert len(note.properties) == 2 assert isinstance(note.properties[0], lief.ELF.X86ISA) assert note.properties[0].values == [(lief.ELF.X86ISA.FLAG.NEEDED, lief.ELF.X86ISA.ISA.BASELINE)] - assert note.properties[0].type == lief._lief.ELF.NoteGnuProperty.Property.TYPE.X86_ISA + assert note.properties[0].type == lief.ELF.NoteGnuProperty.Property.TYPE.X86_ISA assert str(note.properties[0]) print(note) GNU_PROPERTY_X86_ISA_1_NEEDED = "040000001800000005000000474e5500020001c0040000000a000000028000c00400000003000000040000001800000005000000474e5500020001c004000000a0000000028000c00400000030000000" note: lief.ELF.NoteGnuProperty = lief.ELF.Note.create(raw=bytes.fromhex(GNU_PROPERTY_X86_ISA_1_NEEDED), - file_type=lief.ELF.E_TYPE.NONE, arch=lief.ELF.ARCH.x86_64, - cls=lief.ELF.ELF_CLASS.CLASS64) + file_type=lief.ELF.Header.FILE_TYPE.NONE, arch=lief.ELF.ARCH.X86_64, + cls=lief.ELF.Header.CLASS.ELF64) assert len(note.properties) == 1 assert isinstance(note.properties[0], lief.ELF.X86ISA) @@ -144,14 +145,14 @@ def test_note_x86_isa(): (lief.ELF.X86ISA.FLAG.USED, lief.ELF.X86ISA.ISA.V2), (lief.ELF.X86ISA.FLAG.USED, lief.ELF.X86ISA.ISA.V4), ] - assert note.properties[0].type == lief._lief.ELF.NoteGnuProperty.Property.TYPE.X86_ISA + assert note.properties[0].type == lief.ELF.NoteGnuProperty.Property.TYPE.X86_ISA assert str(note.properties[0]) print(note) GNU_PROPERTY_X86_ISA_1_NEEDED = "040000001800000005000000474e5500000001c0040000000a000000008000c00400000003000000040000001800000005000000474e5500000001c004000000a0000000008000c00400000030000000" note: lief.ELF.NoteGnuProperty = lief.ELF.Note.create(raw=bytes.fromhex(GNU_PROPERTY_X86_ISA_1_NEEDED), - file_type=lief.ELF.E_TYPE.NONE, arch=lief.ELF.ARCH.x86_64, - cls=lief.ELF.ELF_CLASS.CLASS64) + file_type=lief.ELF.Header.FILE_TYPE.NONE, arch=lief.ELF.ARCH.X86_64, + cls=lief.ELF.Header.CLASS.ELF64) assert len(note.properties) == 1 assert isinstance(note.properties[0], lief.ELF.X86ISA) @@ -165,8 +166,8 @@ def test_note_x86_isa(): def test_note_properties(): GNU_PROPERTY_C = "040000004800000005000000474e5500010000000800000000111100000000000200000000000000020001c0040000001110000000000000028000c0040000001110000000000000020000c0040000000100000000000000" note: lief.ELF.NoteGnuProperty = lief.ELF.Note.create(raw=bytes.fromhex(GNU_PROPERTY_C), - file_type=lief.ELF.E_TYPE.NONE, arch=lief.ELF.ARCH.x86_64, - cls=lief.ELF.ELF_CLASS.CLASS64) + file_type=lief.ELF.Header.FILE_TYPE.NONE, arch=lief.ELF.ARCH.X86_64, + cls=lief.ELF.Header.CLASS.ELF64) assert len(note.properties) == 5 assert str(note) diff --git a/tests/elf/test_object_files.py b/tests/elf/test_object_files.py index e8eaa7648e..9df1c3f530 100644 --- a/tests/elf/test_object_files.py +++ b/tests/elf/test_object_files.py @@ -66,7 +66,7 @@ def test_force_relocate(tmp_path): if not file.exists(): print(f"{file} does not exist. Skipping ...", file=sys.stderr) continue - elf: lief.ELF.Binary = lief.parse(file.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(file.as_posix()) builder = lief.ELF.Builder(elf) builder.config.force_relocate = True @@ -88,7 +88,7 @@ def test_object_files_section(tmp_path): if not file.exists(): print(f"{file} does not exist. Skipping ...", file=sys.stderr) continue - elf: lief.ELF.Binary = lief.parse(file.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(file.as_posix()) elf.get_section(".symtab").name = ".foooooootab" @@ -110,13 +110,13 @@ def test_object_files_symbols(tmp_path): if not file.exists(): print(f"{file} does not exist. Skipping ...", file=sys.stderr) continue - elf: lief.ELF.Binary = lief.parse(file.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(file.as_posix()) sym = lief.ELF.Symbol() sym.name = "LIEF_CUSTOM_SYMBOL" - sym.type = lief.ELF.SYMBOL_TYPES.NOTYPE - sym.visibility = lief.ELF.SYMBOL_VISIBILITY.DEFAULT - sym.binding = lief.ELF.SYMBOL_BINDINGS.GLOBAL # TODO(romain): it fails if the symbol is "local" + sym.type = lief.ELF.Symbol.TYPE.NOTYPE + sym.visibility = lief.ELF.Symbol.VISIBILITY.DEFAULT + sym.binding = lief.ELF.Symbol.BINDING.GLOBAL # TODO(romain): it fails if the symbol is "local" # cf. binutils-2.35.1/bfd/elflink.c:4602 sym.value = 0xdeadc0de elf.add_static_symbol(sym) @@ -144,14 +144,14 @@ def test_relocations(tmp_path): if not file.exists(): print(f"{file} does not exist. Skipping ...", file=sys.stderr) continue - elf: lief.ELF.Binary = lief.parse(file.as_posix()) + elf: lief.ELF.Binary = lief.ELF.parse(file.as_posix()) # Add a relocation that do "nothing" - rel = lief.ELF.Relocation(lief.ELF.ARCH.x86_64) + rel = lief.ELF.Relocation(lief.ELF.ARCH.X86_64) rel.addend = 123 rel.address = 0x123 - rel.type = lief.ELF.RELOCATION_X86_64.NONE - rel.purpose = lief.ELF.RELOCATION_PURPOSES.OBJECT + rel.type = lief.ELF.Relocation.TYPE.X86_64_NONE + rel.purpose = lief.ELF.Relocation.PURPOSE.OBJECT elf.add_object_relocation(rel, elf.get_section(".text")) builder = lief.ELF.Builder(elf) diff --git a/tests/elf/test_parser.py b/tests/elf/test_parser.py index bfda877a08..4aa3d1db4a 100644 --- a/tests/elf/test_parser.py +++ b/tests/elf/test_parser.py @@ -4,11 +4,11 @@ def test_symbol_count(): config = lief.ELF.ParserConfig() - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.HASH + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.HASH gcc1 = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_gcc.bin'), config) - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.SECTION + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION gcc2 = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_gcc.bin'), config) - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.RELOCATIONS + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.RELOCATIONS gcc3 = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_gcc.bin'), config) assert len(gcc1.symbols) == 158 @@ -21,26 +21,26 @@ def test_issue_922(): assert len(auto.symbols) == 14757 config = lief.ELF.ParserConfig() - config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.SECTION + config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION section = lief.ELF.parse(libcrypto_path, config) assert len(section.symbols) == 14757 assert section.virtual_address_to_offset(1000000000000) == lief.lief_errors.conversion_error def test_tiny(): - tiny = lief.parse(get_sample('ELF/ELF32_x86_binary_tiny01.bin')) + tiny = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_tiny01.bin')) assert len(tiny.segments) == 1 segment = tiny.segments[0] - assert segment.type == lief.ELF.SEGMENT_TYPES.LOAD + assert segment.type == lief.ELF.Segment.TYPE.LOAD assert segment.file_offset == 0 assert segment.virtual_address == 0x8048000 assert segment.physical_size == 0x5a assert segment.virtual_size == 0x5a - assert int(segment.flags) == lief.ELF.SEGMENT_FLAGS.R | lief.ELF.SEGMENT_FLAGS.X + assert int(segment.flags) == lief.ELF.Segment.FLAGS.R | lief.ELF.Segment.FLAGS.X def test_tiny_aarch64(): - tiny = lief.parse(get_sample('ELF/tiny_aarch64.elf')) + tiny = lief.ELF.parse(get_sample('ELF/tiny_aarch64.elf')) assert len(tiny.segments) == 1 assert tiny.segments[0].virtual_address == 0x100000000 @@ -51,7 +51,7 @@ def test_tiny_aarch64(): assert lief.hash(tiny.segments[0].content) == 2547808573126369212 def test_relocations(): - bin_with_relocs = lief.parse(get_sample('ELF/ELF64_x86-64_hello-with-relocs.bin')) + bin_with_relocs = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_hello-with-relocs.bin')) relocations = bin_with_relocs.relocations assert len(relocations) == 37 # check relocation from .rela.text @@ -67,7 +67,7 @@ def test_corrupted_identity(): to determine the ELFCLASS and the endianness cf. https://tmpout.sh/2/3.html """ - target = lief.parse(get_sample('ELF/hello_ei_data.elf')) + target = lief.ELF.parse(get_sample('ELF/hello_ei_data.elf')) assert len(target.segments) == 10 @@ -82,7 +82,7 @@ def test_issue_845(): """ https://github.com/lief-project/LIEF/issues/845 """ - target = lief.parse(get_sample('ELF/issue_845.elf')) + target = lief.ELF.parse(get_sample('ELF/issue_845.elf')) assert len(target.segments) > 1 assert len(target.segments[1].content) == 0 @@ -90,7 +90,7 @@ def test_issue_897(): """ Issue #897 / PR: #898 """ - target = lief.parse(get_sample('ELF/test_897.elf')) + target = lief.ELF.parse(get_sample('ELF/test_897.elf')) rel1 = target.get_relocation(0x1b39) assert rel1.symbol.name == "__init_array_start" assert rel1.symbol_table.name == ".symtab" @@ -101,9 +101,9 @@ def test_issue_897(): def test_issue_954(): target = lief.ELF.parse(get_sample('ELF/main.relr.elf')) - assert target.get(lief.ELF.DYNAMIC_TAGS.RELA) is not None - assert target.get(lief.ELF.DYNAMIC_TAGS.RELRSZ) is not None - assert target.get(lief.ELF.DYNAMIC_TAGS.RELRENT) is not None + assert target.get(lief.ELF.DynamicEntry.TAG.RELA) is not None + assert target.get(lief.ELF.DynamicEntry.TAG.RELRSZ) is not None + assert target.get(lief.ELF.DynamicEntry.TAG.RELRENT) is not None def test_issue_958(): target = lief.ELF.parse(get_sample('ELF/issue_958.elf')) @@ -111,21 +111,21 @@ def test_issue_958(): def test_issue_959(): target = lief.ELF.parse(get_sample('ELF/mbedtls_selftest.elf64')) - sym = target.get_symbol("mbedtls_hmac_drbg_random") - assert sym.shndx > 0 - assert sym.section is not None - assert sym.section.name == ".text" + sym_1: lief.ELF.Symbol = target.get_symbol("mbedtls_hmac_drbg_random") + assert sym_1.shndx > 0 + assert sym_1.section is not None + assert sym_1.section.name == ".text" - sym = target.get_symbol("stderr") - assert sym.shndx > 0 - assert sym.section is not None - assert sym.section.name == ".bss" + sym_2: lief.ELF.Symbol = target.get_symbol("stderr") + assert sym_2.shndx > 0 + assert sym_2.section is not None + assert sym_2.section.name == ".bss" def test_io(): class Wrong: pass wrong_io = Wrong() - assert lief.ELF.parse(wrong_io) is None + assert lief.ELF.parse(wrong_io) is None # type: ignore with open(get_sample('ELF/test_897.elf'), "rb") as f: assert lief.ELF.parse(f) is not None diff --git a/tests/elf/test_parser_simple.py b/tests/elf/test_parser_simple.py index bca0688cb8..d9c5982833 100644 --- a/tests/elf/test_parser_simple.py +++ b/tests/elf/test_parser_simple.py @@ -1,7 +1,7 @@ import lief from utils import get_sample -TARGET = lief.parse(get_sample('ELF/ELF32_x86_binary_all.bin')) +TARGET = lief.ELF.parse(get_sample('ELF/ELF32_x86_binary_all.bin')) def test_header(): assert TARGET.interpreter == "/lib/ld-linux.so.2" @@ -14,13 +14,13 @@ def test_sections(): text_section = TARGET.get_section(".text") - assert text_section.type == lief.ELF.SECTION_TYPES.PROGBITS + assert text_section.type == lief.ELF.Section.TYPE.PROGBITS assert text_section.offset == 0x6D0 assert text_section.virtual_address == 0x6D0 assert text_section.size == 0x271 assert text_section.alignment == 16 - assert lief.ELF.SECTION_FLAGS.ALLOC in text_section - assert lief.ELF.SECTION_FLAGS.EXECINSTR in text_section + assert lief.ELF.Section.FLAGS.ALLOC in text_section + assert lief.ELF.Section.FLAGS.EXECINSTR in text_section def test_segments(): segments = TARGET.segments @@ -29,27 +29,30 @@ def test_segments(): LOAD_0 = segments[2] LOAD_1 = segments[3] - assert LOAD_0.type == lief.ELF.SEGMENT_TYPES.LOAD + assert LOAD_0.type == lief.ELF.Segment.TYPE.LOAD assert LOAD_0.file_offset == 0 assert LOAD_0.virtual_address == 0 assert LOAD_0.physical_size == 0x00b34 assert LOAD_0.virtual_size == 0x00b34 - assert int(LOAD_0.flags) == lief.ELF.SEGMENT_FLAGS.R | lief.ELF.SEGMENT_FLAGS.X + assert int(LOAD_0.flags) == lief.ELF.Segment.FLAGS.R | lief.ELF.Segment.FLAGS.X - assert LOAD_1.type == lief.ELF.SEGMENT_TYPES.LOAD + assert LOAD_1.type == lief.ELF.Segment.TYPE.LOAD assert LOAD_1.file_offset == 0x000ed8 assert LOAD_1.virtual_address == 0x00001ed8 assert LOAD_1.physical_address == 0x00001ed8 assert LOAD_1.physical_size == 0x00148 assert LOAD_1.virtual_size == 0x0014c - assert int(LOAD_1.flags) == lief.ELF.SEGMENT_FLAGS.R | lief.ELF.SEGMENT_FLAGS.W + assert int(LOAD_1.flags) == lief.ELF.Segment.FLAGS.R | lief.ELF.Segment.FLAGS.W def test_dynamic(): entries = TARGET.dynamic_entries assert len(entries) == 28 - assert entries[0].name == "libc.so.6" - assert entries[3].array == [2208, 1782] - assert TARGET[lief.ELF.DYNAMIC_TAGS.FLAGS_1].value == 0x8000000 + lib_entry: lief.ELF.DynamicEntryLibrary = entries[0] + assert lib_entry.name == "libc.so.6" + + array_entry: lief.ELF.DynamicEntryArray = entries[3] + assert array_entry.array == [2208, 1782] + assert TARGET[lief.ELF.DynamicEntry.TAG.FLAGS_1].value == 0x8000000 def test_relocations(): dynamic_relocations = TARGET.dynamic_relocations @@ -105,6 +108,7 @@ def test_notes(): notes = TARGET.notes assert len(notes) == 2 + assert isinstance(notes[0], lief.ELF.NoteAbi) assert notes[0].abi == lief.ELF.NoteAbi.ABI.LINUX assert list(notes[0].description) == [0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0] assert notes[0].name == "GNU" @@ -115,7 +119,7 @@ def test_symbols_sections(): """ Related to this issue: https://github.com/lief-project/LIEF/issues/841 """ - elf = lief.parse(get_sample('ELF/ELF64_x86-64_binary_all.bin')) + elf = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_all.bin')) main = elf.get_static_symbol("main") assert main.section is not None assert main.section.name == ".text" diff --git a/tests/elf/test_remove_section.py b/tests/elf/test_remove_section.py index e00218b9c8..4bc3f7930c 100644 --- a/tests/elf/test_remove_section.py +++ b/tests/elf/test_remove_section.py @@ -16,7 +16,7 @@ def test_simple(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin') output = tmp_path / "ls.section" - ls = lief.parse(sample_path) + ls = lief.ELF.parse(sample_path) ls.remove_section(".text", clear=False) ls.write(output.as_posix()) diff --git a/tests/elf/test_replace_segment.py b/tests/elf/test_replace_segment.py index bb56680ff2..0e6bf680ee 100644 --- a/tests/elf/test_replace_segment.py +++ b/tests/elf/test_replace_segment.py @@ -20,19 +20,19 @@ def test_simple(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin') - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) output = tmp_path / "ls.replace_segment" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) - if not lief.ELF.SEGMENT_TYPES.NOTE in target: + if not lief.ELF.Segment.TYPE.NOTE in target: print("Note not found!", file=sys.stderr) return segment = stub.segments[0] original_va = segment.virtual_address segment.virtual_address = 0 - segment = target.replace(segment, target[lief.ELF.SEGMENT_TYPES.NOTE]) + segment = target.replace(segment, target[lief.ELF.Segment.TYPE.NOTE]) new_ep = (stub.header.entrypoint - original_va) + segment.virtual_address target.header.entrypoint = new_ep @@ -49,18 +49,18 @@ def test_simple(tmp_path: Path): def test_gcc(tmp_path: Path): sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin') - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) output = tmp_path / "gcc.replace_segment" - target = lief.parse(sample_path) + target = lief.ELF.parse(sample_path) - if not lief.ELF.SEGMENT_TYPES.NOTE in target: + if not lief.ELF.Segment.TYPE.NOTE in target: print("Note not found!", file=sys.stderr) return segment = stub.segments[0] original_va = segment.virtual_address segment.virtual_address = 0 - segment = target.replace(segment, target[lief.ELF.SEGMENT_TYPES.NOTE]) + segment = target.replace(segment, target[lief.ELF.Segment.TYPE.NOTE]) new_ep = (stub.header.entrypoint - original_va) + segment.virtual_address target.header.entrypoint = new_ep @@ -80,21 +80,21 @@ def test_gcc(tmp_path: Path): def test_ssh(tmp_path: Path): stub = None if is_x86_64(): - stub = lief.parse((CWD / "hello_lief.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief.bin").as_posix()) elif is_aarch64(): - stub = lief.parse((CWD / "hello_lief_aarch64.bin").as_posix()) + stub = lief.ELF.parse((CWD / "hello_lief_aarch64.bin").as_posix()) output = tmp_path / "ssh.replace_segment" - target = lief.parse("/usr/bin/ssh") + target = lief.ELF.parse("/usr/bin/ssh") - if not lief.ELF.SEGMENT_TYPES.NOTE in target: + if not lief.ELF.Segment.TYPE.NOTE in target: print("Note not found!", file=sys.stderr) return segment = stub.segments[0] original_va = segment.virtual_address segment.virtual_address = 0 - segment = target.replace(segment, target[lief.ELF.SEGMENT_TYPES.NOTE]) + segment = target.replace(segment, target[lief.ELF.Segment.TYPE.NOTE]) new_ep = (stub.header.entrypoint - original_va) + segment.virtual_address target.header.entrypoint = new_ep diff --git a/tests/elf/test_section_frame.py b/tests/elf/test_section_frame.py index 7bb3e3f360..f8119baf6d 100644 --- a/tests/elf/test_section_frame.py +++ b/tests/elf/test_section_frame.py @@ -9,7 +9,7 @@ lief.logging.set_level(lief.logging.LOGGING_LEVEL.DEBUG) def test_frame(tmp_path): - elf = lief.parse(get_sample("ELF/mbedtls_selftest.elf64")) + elf = lief.ELF.parse(get_sample("ELF/mbedtls_selftest.elf64")) assert len(elf.dynamic_entries) == 26 @@ -18,20 +18,20 @@ def test_frame(tmp_path): continue section.as_frame() - section.type = lief.ELF.SECTION_TYPES.ARM_EXIDX + section.type = lief.ELF.Section.TYPE.ARM_EXIDX section.virtual_address = 0xdeadc0de section.offset = 0xdeadc0de section.size = 0xdeadc0de - name = list(section.name) + name: list[str] = list(section.name) # type: ignore shuffle(name) section.name = "".join(name) - elf.add_library(elf.libraries[0]) + elf.add_library(elf.libraries[0]) # type: ignore out = pathlib.Path(tmp_path) / "mbedtls_selftest.elf64" elf.write(out.as_posix()) - new = lief.parse(out.as_posix()) + new = lief.ELF.parse(out.as_posix()) out.chmod(out.stat().st_mode | stat.S_IEXEC) assert len(new.dynamic_entries) == 27 # Make sure our modifications has been committed @@ -40,7 +40,7 @@ def test_frame(tmp_path): assert isinstance(subprocess.run(out.as_posix(), check=True), subprocess.CompletedProcess) def test_sectionless(tmp_path): - elf: lief.ELF.Binary = lief.parse(get_sample("ELF/mbedtls_selftest.elf64")) + elf: lief.ELF.Binary = lief.ELF.parse(get_sample("ELF/mbedtls_selftest.elf64")) assert len(elf.dynamic_symbols) == 40 @@ -52,17 +52,17 @@ def test_sectionless(tmp_path): out = pathlib.Path(tmp_path) / "mbedtls_selftest.sectionless" elf.write(out.as_posix()) - sectionless = lief.parse(out.as_posix()) + sectionless = lief.ELF.parse(out.as_posix()) out = pathlib.Path(tmp_path) / "mbedtls_selftest.sectionless.built" assert len(sectionless.dynamic_symbols) == 40 - sectionless.add_library(sectionless.libraries[0]) + sectionless.add_library(sectionless.libraries[0]) # type: ignore sectionless.write(out.as_posix()) out.chmod(out.stat().st_mode | stat.S_IEXEC) - new = lief.parse(out.as_posix()) + new = lief.ELF.parse(out.as_posix()) assert len(new.dynamic_entries) == 27 # Make sure our modifications has been committed if is_linux(): diff --git a/tests/elf/test_sectionless.py b/tests/elf/test_sectionless.py index b9aba1de1e..ed47ce627d 100644 --- a/tests/elf/test_sectionless.py +++ b/tests/elf/test_sectionless.py @@ -2,7 +2,7 @@ from utils import get_sample config = lief.ELF.ParserConfig() -config.count_mtd = lief.ELF.DYNSYM_COUNT_METHODS.HASH +config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.HASH TARGET = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_rvs.bin'), config) diff --git a/tests/elf/test_static.py b/tests/elf/test_static.py index ab7870602b..ed05d30233 100644 --- a/tests/elf/test_static.py +++ b/tests/elf/test_static.py @@ -67,11 +67,11 @@ def test_write_object(tmp_path: Path): compile_obj(binadd_o, binadd_c) - binadd = lief.parse(binadd_o.as_posix()) + binadd = lief.ELF.parse(binadd_o.as_posix()) init_obj = [str(o).strip() for o in binadd.object_relocations] binadd.write(newfile_o.as_posix()) - binadd = lief.parse(newfile_o.as_posix()) + binadd = lief.ELF.parse(newfile_o.as_posix()) new_obj = [str(o).strip() for o in binadd.object_relocations] assert len(init_obj) == len(new_obj) @@ -93,12 +93,12 @@ def test_update_addend_object(tmp_path: Path): binadd_c.write_text(BINADD_C) compile_obj(binadd_o, binadd_c) - binadd = lief.parse(binadd_o.as_posix()) + binadd = lief.ELF.parse(binadd_o.as_posix()) reloc = next(o for o in binadd.object_relocations if o.symbol.name == "add") reloc.addend = 0xABCD binadd.write(newfile_o.as_posix()) - binadd = lief.parse(newfile_o.as_posix()) + binadd = lief.ELF.parse(newfile_o.as_posix()) reloc = next(o for o in binadd.object_relocations if o.symbol.name == "add") assert reloc.addend == 0xABCD diff --git a/tests/elf/test_str_hash.py b/tests/elf/test_str_hash.py index a6baa5fab3..7fabfceb45 100644 --- a/tests/elf/test_str_hash.py +++ b/tests/elf/test_str_hash.py @@ -23,29 +23,29 @@ def test_hash(): assert hello_c_debug.gnu_hash is not None assert hash(hello_c_debug.gnu_hash) > 0 - assert empty_gnu_hash[lief.ELF.DYNAMIC_TAGS.FLAGS_1] is not None - assert hash(empty_gnu_hash[lief.ELF.DYNAMIC_TAGS.FLAGS_1]) > 0 + assert empty_gnu_hash[lief.ELF.DynamicEntry.TAG.FLAGS_1] is not None + assert hash(empty_gnu_hash[lief.ELF.DynamicEntry.TAG.FLAGS_1]) > 0 - assert arm_ls[lief.ELF.DYNAMIC_TAGS.FLAGS] is not None - assert hash(arm_ls[lief.ELF.DYNAMIC_TAGS.FLAGS]) > 0 + assert arm_ls[lief.ELF.DynamicEntry.TAG.FLAGS] is not None + assert hash(arm_ls[lief.ELF.DynamicEntry.TAG.FLAGS]) > 0 - assert libfreebl3[lief.ELF.DYNAMIC_TAGS.SONAME] is not None - assert hash(libfreebl3[lief.ELF.DYNAMIC_TAGS.SONAME]) > 0 + assert libfreebl3[lief.ELF.DynamicEntry.TAG.SONAME] is not None + assert hash(libfreebl3[lief.ELF.DynamicEntry.TAG.SONAME]) > 0 - assert hello_c_debug[lief.ELF.DYNAMIC_TAGS.GNU_HASH] is not None - assert hash(hello_c_debug[lief.ELF.DYNAMIC_TAGS.GNU_HASH]) > 0 + assert hello_c_debug[lief.ELF.DynamicEntry.TAG.GNU_HASH] is not None + assert hash(hello_c_debug[lief.ELF.DynamicEntry.TAG.GNU_HASH]) > 0 - assert hello_c_debug[lief.ELF.DYNAMIC_TAGS.INIT_ARRAY] is not None - assert hash(hello_c_debug[lief.ELF.DYNAMIC_TAGS.INIT_ARRAY]) > 0 + assert hello_c_debug[lief.ELF.DynamicEntry.TAG.INIT_ARRAY] is not None + assert hash(hello_c_debug[lief.ELF.DynamicEntry.TAG.INIT_ARRAY]) > 0 - assert hello_c_debug[lief.ELF.DYNAMIC_TAGS.NEEDED] is not None - assert hash(hello_c_debug[lief.ELF.DYNAMIC_TAGS.NEEDED]) > 0 + assert hello_c_debug[lief.ELF.DynamicEntry.TAG.NEEDED] is not None + assert hash(hello_c_debug[lief.ELF.DynamicEntry.TAG.NEEDED]) > 0 - assert etterlog[lief.ELF.DYNAMIC_TAGS.RPATH] is not None - assert hash(etterlog[lief.ELF.DYNAMIC_TAGS.RPATH]) > 0 + assert etterlog[lief.ELF.DynamicEntry.TAG.RPATH] is not None + assert hash(etterlog[lief.ELF.DynamicEntry.TAG.RPATH]) > 0 - assert resolve[lief.ELF.DYNAMIC_TAGS.RUNPATH] is not None - assert hash(resolve[lief.ELF.DYNAMIC_TAGS.RUNPATH]) > 0 + assert resolve[lief.ELF.DynamicEntry.TAG.RUNPATH] is not None + assert hash(resolve[lief.ELF.DynamicEntry.TAG.RUNPATH]) > 0 assert hash(resolve.header) > 0 assert hash(etterlog.notes[0]) > 0 @@ -80,30 +80,30 @@ def test_str(capsys): assert hello_c_debug.gnu_hash is not None print(hello_c_debug.gnu_hash) - assert empty_gnu_hash[lief.ELF.DYNAMIC_TAGS.FLAGS_1] is not None - print(empty_gnu_hash[lief.ELF.DYNAMIC_TAGS.FLAGS_1]) + assert empty_gnu_hash[lief.ELF.DynamicEntry.TAG.FLAGS_1] is not None + print(empty_gnu_hash[lief.ELF.DynamicEntry.TAG.FLAGS_1]) - assert arm_ls[lief.ELF.DYNAMIC_TAGS.FLAGS] is not None - print(arm_ls[lief.ELF.DYNAMIC_TAGS.FLAGS]) + assert arm_ls[lief.ELF.DynamicEntry.TAG.FLAGS] is not None + print(arm_ls[lief.ELF.DynamicEntry.TAG.FLAGS]) - assert libfreebl3[lief.ELF.DYNAMIC_TAGS.SONAME] is not None - print(libfreebl3[lief.ELF.DYNAMIC_TAGS.SONAME]) + assert libfreebl3[lief.ELF.DynamicEntry.TAG.SONAME] is not None + print(libfreebl3[lief.ELF.DynamicEntry.TAG.SONAME]) - assert hello_c_debug[lief.ELF.DYNAMIC_TAGS.GNU_HASH] is not None - print(hello_c_debug[lief.ELF.DYNAMIC_TAGS.GNU_HASH]) + assert hello_c_debug[lief.ELF.DynamicEntry.TAG.GNU_HASH] is not None + print(hello_c_debug[lief.ELF.DynamicEntry.TAG.GNU_HASH]) - assert hello_c_debug[lief.ELF.DYNAMIC_TAGS.INIT_ARRAY] is not None - print(hello_c_debug[lief.ELF.DYNAMIC_TAGS.INIT_ARRAY]) + assert hello_c_debug[lief.ELF.DynamicEntry.TAG.INIT_ARRAY] is not None + print(hello_c_debug[lief.ELF.DynamicEntry.TAG.INIT_ARRAY]) - assert hello_c_debug[lief.ELF.DYNAMIC_TAGS.NEEDED] is not None - print(hello_c_debug[lief.ELF.DYNAMIC_TAGS.NEEDED]) + assert hello_c_debug[lief.ELF.DynamicEntry.TAG.NEEDED] is not None + print(hello_c_debug[lief.ELF.DynamicEntry.TAG.NEEDED]) - assert etterlog[lief.ELF.DYNAMIC_TAGS.RPATH] is not None - print(etterlog[lief.ELF.DYNAMIC_TAGS.RPATH]) + assert etterlog[lief.ELF.DynamicEntry.TAG.RPATH] is not None + print(etterlog[lief.ELF.DynamicEntry.TAG.RPATH]) - assert resolve[lief.ELF.DYNAMIC_TAGS.RUNPATH] is not None - print(resolve[lief.ELF.DYNAMIC_TAGS.RUNPATH]) + assert resolve[lief.ELF.DynamicEntry.TAG.RUNPATH] is not None + print(resolve[lief.ELF.DynamicEntry.TAG.RUNPATH]) print(resolve.header) print(etterlog.notes[0])