Projects STRLCPY LIEF Commits cddd8dd0
🤬
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Binary.cpp
    skipped 51 lines
    52 52   init_c_sections(c_binary, binary);
    53 53   init_c_segments(c_binary, binary);
    54 54   init_c_dynamic_symbols(c_binary, binary);
    55  - init_c_static_symbols(c_binary, binary);
     55 + init_c_symtab_symbols(c_binary, binary);
    56 56   init_c_dynamic_entries(c_binary, binary);
    57 57   
    58 58   
    skipped 44 lines
    103 103   destroy_sections(binary);
    104 104   destroy_segments(binary);
    105 105   destroy_dynamic_symbols(binary);
    106  - destroy_static_symbols(binary);
     106 + destroy_symtab_symbols(binary);
    107 107   destroy_dynamic_entries(binary);
    108 108   
    109 109   if (binary->interpreter != nullptr) {
    skipped 9 lines
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Symbol.cpp
    skipped 42 lines
    43 43  }
    44 44   
    45 45   
    46  -void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary) {
    47  - Binary::it_static_symbols static_symb = binary->static_symbols();
     46 +void init_c_symtab_symbols(Elf_Binary_t* c_binary, Binary* binary) {
     47 + Binary::it_symtab_symbols static_symb = binary->symtab_symbols();
    48 48   
    49  - c_binary->static_symbols = static_cast<Elf_Symbol_t**>(
     49 + c_binary->symtab_symbols = static_cast<Elf_Symbol_t**>(
    50 50   malloc((static_symb.size() + 1) * sizeof(Elf_Symbol_t**)));
    51 51   
    52 52   for (size_t i = 0; i < static_symb.size(); ++i) {
    53 53   Symbol& b_sym = static_symb[i];
    54  - c_binary->static_symbols[i] = static_cast<Elf_Symbol_t*>(malloc(sizeof(Elf_Symbol_t)));
    55  - c_binary->static_symbols[i]->name = b_sym.name().c_str();
    56  - c_binary->static_symbols[i]->type = static_cast<uint32_t>(b_sym.type());
    57  - c_binary->static_symbols[i]->binding = static_cast<uint32_t>(b_sym.binding());
    58  - c_binary->static_symbols[i]->other = b_sym.other();
    59  - c_binary->static_symbols[i]->shndx = b_sym.shndx();
    60  - c_binary->static_symbols[i]->value = b_sym.value();
    61  - c_binary->static_symbols[i]->size = b_sym.size();
    62  - c_binary->static_symbols[i]->information = b_sym.information();
    63  - c_binary->static_symbols[i]->is_exported = b_sym.is_exported();
    64  - c_binary->static_symbols[i]->is_imported = b_sym.is_imported();
     54 + c_binary->symtab_symbols[i] = static_cast<Elf_Symbol_t*>(malloc(sizeof(Elf_Symbol_t)));
     55 + c_binary->symtab_symbols[i]->name = b_sym.name().c_str();
     56 + c_binary->symtab_symbols[i]->type = static_cast<uint32_t>(b_sym.type());
     57 + c_binary->symtab_symbols[i]->binding = static_cast<uint32_t>(b_sym.binding());
     58 + c_binary->symtab_symbols[i]->other = b_sym.other();
     59 + c_binary->symtab_symbols[i]->shndx = b_sym.shndx();
     60 + c_binary->symtab_symbols[i]->value = b_sym.value();
     61 + c_binary->symtab_symbols[i]->size = b_sym.size();
     62 + c_binary->symtab_symbols[i]->information = b_sym.information();
     63 + c_binary->symtab_symbols[i]->is_exported = b_sym.is_exported();
     64 + c_binary->symtab_symbols[i]->is_imported = b_sym.is_imported();
    65 65   }
    66  - c_binary->static_symbols[static_symb.size()] = nullptr;
     66 + c_binary->symtab_symbols[static_symb.size()] = nullptr;
    67 67   
    68 68  }
    69 69   
    skipped 8 lines
    78 78  }
    79 79   
    80 80   
    81  -void destroy_static_symbols(Elf_Binary_t* c_binary) {
    82  - Elf_Symbol_t **static_symbols = c_binary->static_symbols;
    83  - for (size_t idx = 0; static_symbols[idx] != nullptr; ++idx) {
    84  - free(static_symbols[idx]);
     81 +void destroy_symtab_symbols(Elf_Binary_t* c_binary) {
     82 + Elf_Symbol_t **symtab_symbols = c_binary->symtab_symbols;
     83 + for (size_t idx = 0; symtab_symbols[idx] != nullptr; ++idx) {
     84 + free(symtab_symbols[idx]);
    85 85   }
    86  - free(c_binary->static_symbols);
     86 + free(c_binary->symtab_symbols);
    87 87  }
    88 88   
    89 89  }
    skipped 4 lines
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Symbol.hpp
    skipped 25 lines
    26 26  namespace ELF {
    27 27   
    28 28  void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary);
    29  -void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary);
     29 +void init_c_symtab_symbols(Elf_Binary_t* c_binary, Binary* binary);
    30 30   
    31 31  void destroy_dynamic_symbols(Elf_Binary_t* c_binary);
    32  -void destroy_static_symbols(Elf_Binary_t* c_binary);
     32 +void destroy_symtab_symbols(Elf_Binary_t* c_binary);
    33 33   
    34 34  }
    35 35  }
    skipped 3 lines
  • ■ ■ ■ ■
    api/c/include/LIEF/ELF/Binary.h
    skipped 42 lines
    43 43   Elf_Segment_t **segments;
    44 44   Elf_DynamicEntry_t **dynamic_entries;
    45 45   Elf_Symbol_t **dynamic_symbols;
    46  - Elf_Symbol_t **static_symbols;
     46 + Elf_Symbol_t **symtab_symbols;
    47 47  };
    48 48   
    49 49  typedef struct Elf_Binary_t Elf_Binary_t;
    skipped 15 lines
  • ■ ■ ■ ■ ■ ■
    api/python/examples/elf_reader.py
    skipped 239 lines
    240 240   
    241 241   
    242 242  @exceptions_handler(Exception)
    243  -def print_static_symbols(binary, args):
    244  - print("== Static symbols ==\n")
    245  - print_symbols(binary.static_symbols, args.no_trunc)
     243 +def print_symtab_symbols(binary, args):
     244 + print("== Symtab symbols ==\n")
     245 + print_symbols(binary.symtab_symbols, args.no_trunc)
    246 246   
    247 247  @exceptions_handler(Exception)
    248 248  def print_relocations(binary, relocations):
    skipped 248 lines
    497 497   action='store_true', dest='show_dynamic_symbols',
    498 498   help='Display the dynamic symbols')
    499 499   
    500  - parser.add_argument('--static-symbols', '--ssyms',
    501  - action='store_true', dest='show_static_symbols',
    502  - help='Display the static symbols')
     500 + parser.add_argument('--symtab-symbols', '--ssyms',
     501 + action='store_true', dest='show_symtab_symbols',
     502 + help='Display the symtab symbols')
    503 503   
    504 504   parser.add_argument('-r', '--relocs',
    505 505   action='store_true', dest='show_relocs',
    skipped 102 lines
    608 608   if (args.show_symbols or args.show_all or args.show_dynamic_symbols) and len(binary.dynamic_symbols) > 0:
    609 609   print_dynamic_symbols(binary, args)
    610 610   
    611  - if (args.show_symbols or args.show_all or args.show_static_symbols) and len(binary.static_symbols) > 0:
    612  - print_static_symbols(binary, args)
     611 + if (args.show_symbols or args.show_all or args.show_symtab_symbols) and len(binary.symtab_symbols) > 0:
     612 + print_symtab_symbols(binary, args)
    613 613   
    614 614   if args.show_relocs or args.show_all:
    615 615   print_all_relocations(binary)
    skipped 31 lines
  • ■ ■ ■ ■ ■ ■
    api/python/examples/elf_symbol_obfuscation.py
    skipped 1 lines
    2 2  # -*- coding: utf-8 -*-
    3 3   
    4 4   
    5  -# In this example, we replace all statics symbols in the .symtab
     5 +# In this example, we replace all symtab symbols in the .symtab
    6 6  # with a random name.
    7 7  #
    8 8  # Example:
    skipped 30 lines
    39 39   
    40 40  def randomize(binary, output):
    41 41   
    42  - symbols = binary.static_symbols
     42 + symbols = binary.symtab_symbols
    43 43   if len(symbols) == 0:
    44 44   print("No symbols")
    45 45   return
    skipped 18 lines
  • ■ ■ ■ ■ ■ ■
    api/python/examples/elf_unstrip.py
    skipped 4 lines
    5 5  # -----------
    6 6  # In this example, we assume that we found
    7 7  # the ``main`` function at address 0x402A00
    8  -# and we add a static symbol to the binary
     8 +# and we add a symtab symbol to the binary
    9 9  # so that we can do:
    10 10  #
    11 11  # (gdb) break main
    skipped 31 lines
    43 43   symbol.binding = ELF.Symbol.BINDING.LOCAL
    44 44   symbol.size = 0
    45 45   symbol.shndx = 0
    46  - symbol = binary.add_static_symbol(symbol)
     46 + symbol = binary.add_symtab_symbol(symbol)
    47 47   
    48 48   symbol = ELF.Symbol()
    49 49   symbol.name = "main"
    skipped 1 lines
    51 51   symbol.value = 0x402A00
    52 52   symbol.binding = ELF.Symbol.BINDING.LOCAL
    53 53   symbol.shndx = 14
    54  - symbol = binary.add_static_symbol(symbol)
     54 + symbol = binary.add_symtab_symbol(symbol)
    55 55   
    56 56   print(symbol)
    57 57   
    skipped 5 lines
  • api/python/lief/ELF.pyi
    Diff is too large to be displayed.
  • ■ ■ ■ ■ ■ ■
    api/python/src/ELF/objects/pyBinary.cpp
    skipped 70 lines
    71 71   init_ref_iterator<Binary::it_pltgot_relocations>(bin, "it_filter_relocation");
    72 72   init_ref_iterator<Binary::it_relocations>(bin, "it_relocations");
    73 73   
    74  - init_ref_iterator<Binary::it_symbols>(bin, "it_dyn_static_symbols");
    75  - init_ref_iterator<Binary::it_dynamic_symbols>(bin, "it_symbols"); // For it_dynamic_symbols / it_static_symbols
     74 + init_ref_iterator<Binary::it_symbols>(bin, "it_dyn_symtab_symbols");
     75 + init_ref_iterator<Binary::it_dynamic_symbols>(bin, "it_symbols"); // For it_dynamic_symbols / it_symtab_symbols
    76 76   init_ref_iterator<Binary::it_exported_symbols>(bin, "it_filter_symbols"); // For it_imported_symbols
    77 77   
    78 78   nb::enum_<Binary::PHDR_RELOC>(bin, "PHDR_RELOC", R"delim(
    skipped 56 lines
    135 135   "dynamic_entry",
    136 136   nb::rv_policy::reference_internal)
    137 137   
    138  - .def_prop_ro("static_symbols",
    139  - nb::overload_cast<>(&Binary::static_symbols),
     138 + .def_prop_ro("symtab_symbols",
     139 + nb::overload_cast<>(&Binary::symtab_symbols),
    140 140   "Return an iterator to static " RST_CLASS_REF(lief.ELF.Symbol) ""_doc,
    141 141   nb::keep_alive<0, 1>())
    142 142   
    skipped 281 lines
    424 424   "section_name"_a,
    425 425   nb::rv_policy::reference_internal)
    426 426   
    427  - .def("add_static_symbol",
    428  - &Binary::add_static_symbol,
     427 + .def("add_symtab_symbol",
     428 + &Binary::add_symtab_symbol,
    429 429   "Add a **static** " RST_CLASS_REF(lief.ELF.Symbol) " to the binary"_doc,
    430 430   "symbol"_a,
    431 431   nb::rv_policy::reference_internal)
    skipped 171 lines
    603 603   "symbol_name"_a,
    604 604   nb::rv_policy::reference_internal)
    605 605   
    606  - .def("has_static_symbol",
    607  - &Binary::has_static_symbol,
     606 + .def("has_symtab_symbol",
     607 + &Binary::has_symtab_symbol,
    608 608   "Check if the symbol with the given ``name`` exists in the **static** symbol table"_doc,
    609 609   "symbol_name"_a)
    610 610   
    611  - .def("get_static_symbol",
    612  - nb::overload_cast<const std::string&>(&Binary::get_static_symbol),
     611 + .def("get_symtab_symbol",
     612 + nb::overload_cast<const std::string&>(&Binary::get_symtab_symbol),
    613 613   R"delim(
    614 614   Get the **static** symbol from the given ``name``.
    615 615   
    skipped 25 lines
    641 641   "Basically this function looks for strings in the ``.roadata`` section"_doc,
    642 642   nb::rv_policy::move)
    643 643   
    644  - .def("remove_static_symbol",
    645  - nb::overload_cast<Symbol*>(&Binary::remove_static_symbol),
     644 + .def("remove_symtab_symbol",
     645 + nb::overload_cast<Symbol*>(&Binary::remove_symtab_symbol),
    646 646   "Remove the given " RST_CLASS_REF(lief.ELF.Symbol) " from the ``.symtab`` section"_doc)
    647 647   
    648 648   .def("remove_dynamic_symbol",
    skipped 132 lines
  • ■ ■ ■ ■
    api/python/src/ELF/objects/pyParserConfig.cpp
    skipped 39 lines
    40 40   "Whether relocations (including plt-like relocations) should be parsed."_doc)
    41 41   .def_rw("parse_dyn_symbols", &ParserConfig::parse_dyn_symbols,
    42 42   "Whether dynamic symbols (those from `.dynsym`) should be parsed"_doc)
    43  - .def_rw("parse_static_symbols", &ParserConfig::parse_static_symbols,
     43 + .def_rw("parse_symtab_symbols", &ParserConfig::parse_symtab_symbols,
    44 44   "Whether debug symbols (those from `.symtab`) should be parsed"_doc)
    45 45   .def_rw("parse_symbol_versions", &ParserConfig::parse_symbol_versions,
    46 46   "Whether versioning symbols should be parsed"_doc)
    skipped 23 lines
  • ■ ■ ■ ■ ■ ■
    doc/sphinx/changelog.rst
    skipped 4 lines
    5 5  -------------------------
    6 6   
    7 7  :ELF:
     8 + * The ``static_symbols`` API functions has been renamed in ``symtab_symbols``.
     9 + 
     10 + LIEF was naming symbols located in the ``.symtab`` sections as **static
     11 + symbols** in opposition to the ``.dynsym`` symbols. This naming can be
     12 + confusing since the concept of **static symbol** in a program is well
     13 + defined (i.e. ``static bool my_var``) and not applicable in this case.
     14 + 
     15 + **Therefore, the ``xxx_static_symbols`` API is has been renamed
     16 + ``xxx_symtab_symbol``.**
     17 + 
    8 18   * Re-scope ``DYNAMIC_TAGS`` into :class:`lief.ELF.DynamicEntry.TAG`
    9 19   * Re-scope ``E_TYPE`` into :class:`lief.ELF.Header.FILE_TYPE`
    10 20   * Re-scope ``VERSION`` into :class:`lief.ELF.Header.VERSION`
    skipped 1378 lines
  • ■ ■ ■ ■ ■ ■
    examples/c/elf_reader.c
    skipped 109 lines
    110 110   );
    111 111   }
    112 112   
    113  - /* Static symbols */
    114  - fprintf(stdout, "Static symbols:\n");
    115  - Elf_Symbol_t** static_symbols = elf_binary->static_symbols;
    116  - for (i = 0; static_symbols[i] != NULL; ++i) {
    117  - Elf_Symbol_t* symbol = static_symbols[i];
     113 + /* symtab symbols */
     114 + fprintf(stdout, "symtab symbols:\n");
     115 + Elf_Symbol_t** symtab_symbols = elf_binary->symtab_symbols;
     116 + for (i = 0; symtab_symbols[i] != NULL; ++i) {
     117 + Elf_Symbol_t* symbol = symtab_symbols[i];
    118 118   
    119 119   const char* import_export = "";
    120 120   
    skipped 185 lines
  • ■ ■ ■ ■ ■ ■
    examples/cpp/elf_reader.cpp
    skipped 59 lines
    60 60   std::cout << entry << '\n';
    61 61   }
    62 62   
    63  - auto static_symbols = binary->static_symbols();
    64  - if (static_symbols.size() > 0) {
    65  - std::cout << "== Static symbols ==" << '\n';
    66  - for (const Symbol& symbol : static_symbols) {
     63 + auto symtab_symbols = binary->symtab_symbols();
     64 + if (symtab_symbols.size() > 0) {
     65 + std::cout << "== .symtab (debug) symbols ==" << '\n';
     66 + for (const Symbol& symbol : symtab_symbols) {
    67 67   std::cout << symbol << '\n';
    68 68   }
    69 69   }
    skipped 72 lines
  • ■ ■ ■ ■ ■ ■
    include/LIEF/ELF/Binary.hpp
    skipped 156 lines
    157 157   using it_const_dynamic_symbols = const_ref_iterator<const symbols_t&, const Symbol*>;
    158 158   
    159 159   //! Iterator which outputs the static/debug Symbol& object
    160  - using it_static_symbols = ref_iterator<symbols_t&, Symbol*>;
     160 + using it_symtab_symbols = ref_iterator<symbols_t&, Symbol*>;
    161 161   
    162 162   //! Iterator which outputs the static/debug const Symbol& object
    163  - using it_const_static_symbols = const_ref_iterator<const symbols_t&, const Symbol*>;
     163 + using it_const_symtab_symbols = const_ref_iterator<const symbols_t&, const Symbol*>;
    164 164   
    165 165   //! Iterator which outputs static and dynamic Symbol& object
    166 166   using it_symbols = ref_iterator<std::vector<Symbol*>>;
    skipped 162 lines
    329 329   it_imported_symbols imported_symbols();
    330 330   it_const_imported_symbols imported_symbols() const;
    331 331   
    332  - //! Return statics symbols.
    333  - it_static_symbols static_symbols() {
    334  - return static_symbols_;
     332 + //! Return the debug symbols from the `.symtab` section.
     333 + it_symtab_symbols symtab_symbols() {
     334 + return symtab_symbols_;
    335 335   }
    336 336   
    337  - it_const_static_symbols static_symbols() const {
    338  - return static_symbols_;
     337 + it_const_symtab_symbols symtab_symbols() const {
     338 + return symtab_symbols_;
    339 339   }
    340 340   
    341 341   //! Return the symbol versions
    skipped 134 lines
    476 476   //! can't be found, it returns a nullptr
    477 477   Section* hash_section();
    478 478   
    479  - //! Return section which holds static symbols. If the section
     479 + //! Return section which holds the symtab symbols. If the section
    480 480   //! can't be found, it returns a nullptr
    481  - Section* static_symbols_section();
     481 + Section* symtab_symbols_section();
    482 482   
    483 483   //! Return program image base. For instance ``0x40000``
    484 484   //!
    skipped 19 lines
    504 504   
    505 505   //! Return an iterator on both static and dynamic symbols
    506 506   it_symbols symbols() {
    507  - return static_dyn_symbols();
     507 + return symtab_dyn_symbols();
    508 508   }
    509 509   
    510 510   it_const_symbols symbols() const {
    511  - return static_dyn_symbols();
     511 + return symtab_dyn_symbols();
    512 512   }
    513 513   
    514 514   //! Export the given symbol and create it if it doesn't exist
    skipped 11 lines
    526 526   
    527 527   Symbol* get_dynamic_symbol(const std::string& name);
    528 528   
    529  - //! Check if the symbol with the given ``name`` exists in the static symbol table
    530  - bool has_static_symbol(const std::string& name) const;
     529 + //! Check if the symbol with the given ``name`` exists in the symtab symbol table
     530 + bool has_symtab_symbol(const std::string& name) const {
     531 + return get_symtab_symbol(name) != nullptr;
     532 + }
    531 533   
    532  - //! Get the static symbol from the given name
     534 + //! Get the symtab symbol from the given name
    533 535   //! Return a nullptr if it can't be found
    534  - const Symbol* get_static_symbol(const std::string& name) const;
     536 + const Symbol* get_symtab_symbol(const std::string& name) const;
    535 537   
    536  - Symbol* get_static_symbol(const std::string& name);
     538 + Symbol* get_symtab_symbol(const std::string& name);
    537 539   
    538 540   //! Return list of the strings used by the ELF binary.
    539 541   //!
    skipped 2 lines
    542 544   
    543 545   //! Remove symbols with the given name in both:
    544 546   //! * dynamic symbols
    545  - //! * static symbols
     547 + //! * symtab symbols
    546 548   //!
    547  - //! @see remove_static_symbol, remove_dynamic_symbol
     549 + //! @see remove_symtab_symbol, remove_dynamic_symbol
    548 550   void remove_symbol(const std::string& name);
    549 551   
    550  - //! Remove static symbols with the given name
    551  - void remove_static_symbol(const std::string& name);
    552  - void remove_static_symbol(Symbol* symbol);
     552 + //! Remove symtabl symbols with the given name
     553 + void remove_symtab_symbol(const std::string& name);
     554 + void remove_symtab_symbol(Symbol* symbol);
    553 555   
    554 556   //! Remove dynamic symbols with the given name
    555 557   void remove_dynamic_symbol(const std::string& name);
    skipped 27 lines
    583 585   
    584 586   Section* extend(const Section& section, uint64_t size);
    585 587   
    586  - //! Add a static symbol
    587  - Symbol& add_static_symbol(const Symbol& symbol);
     588 + //! Add a symtab symbol
     589 + Symbol& add_symtab_symbol(const Symbol& symbol);
    588 590   
    589 591   //! Add a dynamic symbol with the associated SymbolVersion
    590 592   Symbol& add_dynamic_symbol(const Symbol& symbol, const SymbolVersion* version = nullptr);
    skipped 67 lines
    658 660   //! @param[in] address New address
    659 661   void patch_pltgot(const std::string& symbol_name, uint64_t address);
    660 662   
    661  - //! Strip the binary by removing static symbols
     663 + //! Strip the binary by removing symtab symbols
    662 664   void strip();
    663 665   
    664 666   //! Remove a binary's section.
    skipped 320 lines
    985 987   
    986 988   template<bool LOADED>
    987 989   Section* add_section(const Section& section);
    988  - std::vector<Symbol*> static_dyn_symbols() const;
     990 + std::vector<Symbol*> symtab_dyn_symbols() const;
    989 991   
    990 992   std::string shstrtab_name() const;
    991 993   Section* add_frame_section(const Section& sec);
    skipped 6 lines
    998 1000   segments_t segments_;
    999 1001   dynamic_entries_t dynamic_entries_;
    1000 1002   symbols_t dynamic_symbols_;
    1001  - symbols_t static_symbols_;
     1003 + symbols_t symtab_symbols_;
    1002 1004   relocations_t relocations_;
    1003 1005   symbols_version_t symbol_version_table_;
    1004 1006   symbols_version_requirement_t symbol_version_requirements_;
    skipped 16 lines
  • ■ ■ ■ ■
    include/LIEF/ELF/Builder.hpp
    skipped 122 lines
    123 123   ok_error_t build_segments();
    124 124   
    125 125   template<typename ELF_T>
    126  - ok_error_t build_static_symbols();
     126 + ok_error_t build_symtab_symbols();
    127 127   
    128 128   template<typename ELF_T>
    129 129   ok_error_t build_dynamic();
    skipped 69 lines
  • ■ ■ ■ ■ ■ ■
    include/LIEF/ELF/Parser.hpp
    skipped 160 lines
    161 161   template<typename ELF_T>
    162 162   ok_error_t parse_dynamic_symbols(uint64_t offset);
    163 163   
    164  - //! Parse static Symbol
     164 + //! Parse symtab Symbol
    165 165   //!
    166 166   //! Parser find Symbols offset by using the file offset attribute of the
    167 167   //! ELF_SECTION_TYPES::SHT_SYMTAB Section.
    skipped 2 lines
    170 170   //!
    171 171   //! The section containing symbols name is found with the `link` attribute.
    172 172   template<typename ELF_T>
    173  - ok_error_t parse_static_symbols(uint64_t offset, uint32_t nb_symbols,
     173 + ok_error_t parse_symtab_symbols(uint64_t offset, uint32_t nb_symbols,
    174 174   const Section& string_section);
    175 175   
    176 176   //! Parse Dynamic relocations
    skipped 84 lines
  • ■ ■ ■ ■
    include/LIEF/ELF/ParserConfig.hpp
    skipped 40 lines
    41 41   
    42 42   bool parse_relocations = true; ///< Whether relocations (including plt-like relocations) should be parsed.
    43 43   bool parse_dyn_symbols = true; ///< Whether dynamic symbols (those from `.dynsym`) should be parsed
    44  - bool parse_static_symbols = true; ///< Whether debug symbols (those from `.symtab`) should be parsed
     44 + bool parse_symtab_symbols = true; ///< Whether debug symbols (those from `.symtab`) should be parsed
    45 45   bool parse_symbol_versions = true; ///< Whether versioning symbols should be parsed
    46 46   bool parse_notes = true; ///< Whether ELF notes information should be parsed
    47 47   bool parse_overlay = true; ///< Whether the overlay data should be parsed
    skipped 9 lines
  • ■ ■ ■ ■ ■ ■
    src/ELF/Binary.cpp
    skipped 308 lines
    309 309   return export_symbol(*s);
    310 310   }
    311 311   
    312  - s = get_static_symbol(symbol_name);
     312 + s = get_symtab_symbol(symbol_name);
    313 313   if (s != nullptr) {
    314 314   if (value > 0) {
    315 315   s->value(value);
    skipped 32 lines
    348 348   }
    349 349   
    350 350   // Second: Check if a symbol with the given 'name' exists in the **static**
    351  - s = get_static_symbol(funcname);
     351 + s = get_symtab_symbol(funcname);
    352 352   if (s != nullptr) {
    353 353   s->type(Symbol::TYPE::FUNC);
    354 354   s->binding(Symbol::BINDING::GLOBAL);
    skipped 44 lines
    399 399   return const_cast<Symbol*>(static_cast<const Binary*>(this)->get_dynamic_symbol(name));
    400 400  }
    401 401   
    402  -bool Binary::has_static_symbol(const std::string& name) const {
    403  - const auto it_symbol = std::find_if(
    404  - std::begin(static_symbols_), std::end(static_symbols_),
    405  - [&name] (const std::unique_ptr<Symbol>& s) {
    406  - return s->name() == name;
    407  - });
    408  - return it_symbol != std::end(static_symbols_);
    409  -}
    410  - 
    411  -const Symbol* Binary::get_static_symbol(const std::string& name) const {
     402 +const Symbol* Binary::get_symtab_symbol(const std::string& name) const {
    412 403   const auto it_symbol = std::find_if(
    413  - std::begin(static_symbols_), std::end(static_symbols_),
     404 + std::begin(symtab_symbols_), std::end(symtab_symbols_),
    414 405   [&name] (const std::unique_ptr<Symbol>& s) {
    415 406   return s->name() == name;
    416 407   });
    417  - if (it_symbol == std::end(static_symbols_)) {
     408 + if (it_symbol == std::end(symtab_symbols_)) {
    418 409   return nullptr;
    419 410   }
    420 411   return it_symbol->get();
    skipped 38 lines
    459 450   return list;
    460 451  }
    461 452   
    462  -Symbol* Binary::get_static_symbol(const std::string& name) {
    463  - return const_cast<Symbol*>(static_cast<const Binary*>(this)->get_static_symbol(name));
     453 +Symbol* Binary::get_symtab_symbol(const std::string& name) {
     454 + return const_cast<Symbol*>(static_cast<const Binary*>(this)->get_symtab_symbol(name));
    464 455  }
    465 456   
    466 457   
    467  -std::vector<Symbol*> Binary::static_dyn_symbols() const {
     458 +std::vector<Symbol*> Binary::symtab_dyn_symbols() const {
    468 459   std::vector<Symbol*> symbols;
    469  - symbols.reserve(static_symbols_.size() + dynamic_symbols_.size());
     460 + symbols.reserve(symtab_symbols_.size() + dynamic_symbols_.size());
    470 461   for (const std::unique_ptr<Symbol>& s : dynamic_symbols_) {
    471 462   symbols.push_back(s.get());
    472 463   }
    473 464   
    474  - for (const std::unique_ptr<Symbol>& s : static_symbols_) {
     465 + for (const std::unique_ptr<Symbol>& s : symtab_symbols_) {
    475 466   symbols.push_back(s.get());
    476 467   }
    477 468   return symbols;
    skipped 3 lines
    481 472  // --------
    482 473   
    483 474  Binary::it_exported_symbols Binary::exported_symbols() {
    484  - return {static_dyn_symbols(), [] (const Symbol* symbol) {
     475 + return {symtab_dyn_symbols(), [] (const Symbol* symbol) {
    485 476   return symbol->is_exported();
    486 477   }};
    487 478  }
    488 479   
    489 480  Binary::it_const_exported_symbols Binary::exported_symbols() const {
    490  - return {static_dyn_symbols(), [] (const Symbol* symbol) {
     481 + return {symtab_dyn_symbols(), [] (const Symbol* symbol) {
    491 482   return symbol->is_exported();
    492 483   }};
    493 484  }
    skipped 4 lines
    498 489  // --------
    499 490   
    500 491  Binary::it_imported_symbols Binary::imported_symbols() {
    501  - return {static_dyn_symbols(), [] (const Symbol* symbol) {
     492 + return {symtab_dyn_symbols(), [] (const Symbol* symbol) {
    502 493   return symbol->is_imported();
    503 494   }};
    504 495  }
    505 496   
    506 497  Binary::it_const_imported_symbols Binary::imported_symbols() const {
    507  - return {static_dyn_symbols(), [] (const Symbol* symbol) {
     498 + return {symtab_dyn_symbols(), [] (const Symbol* symbol) {
    508 499   return symbol->is_imported();
    509 500   }};
    510 501  }
    511 502   
    512 503  void Binary::remove_symbol(const std::string& name) {
    513  - remove_static_symbol(name);
     504 + remove_symtab_symbol(name);
    514 505   remove_dynamic_symbol(name);
    515 506  }
    516 507   
    517  -void Binary::remove_static_symbol(const std::string& name) {
    518  - Symbol* sym = get_static_symbol(name);
     508 +void Binary::remove_symtab_symbol(const std::string& name) {
     509 + Symbol* sym = get_symtab_symbol(name);
    519 510   if (sym == nullptr) {
    520  - LIEF_WARN("Can't find the static symbol '{}'. It won't be removed", name);
     511 + LIEF_WARN("Can't find the symtab symbol '{}'. It won't be removed", name);
    521 512   return;
    522 513   }
    523  - remove_static_symbol(sym);
     514 + remove_symtab_symbol(sym);
    524 515  }
    525 516   
    526  -void Binary::remove_static_symbol(Symbol* symbol) {
     517 +void Binary::remove_symtab_symbol(Symbol* symbol) {
    527 518   if (symbol == nullptr) {
    528 519   return;
    529 520   }
    530 521   
    531 522   const auto it_symbol = std::find_if(
    532  - std::begin(static_symbols_), std::end(static_symbols_),
     523 + std::begin(symtab_symbols_), std::end(symtab_symbols_),
    533 524   [symbol] (const std::unique_ptr<Symbol>& sym) {
    534 525   return *symbol == *sym;
    535 526   }
    536 527   );
    537 528   
    538  - if (it_symbol == std::end(static_symbols_)) {
    539  - LIEF_WARN("Can't find the static symbol '{}'. It won't be removed", symbol->name());
     529 + if (it_symbol == std::end(symtab_symbols_)) {
     530 + LIEF_WARN("Can't find the symtab symbol '{}'. It won't be removed", symbol->name());
    540 531   return;
    541 532   }
    542 533   
    543  - static_symbols_.erase(it_symbol);
     534 + symtab_symbols_.erase(it_symbol);
    544 535  }
    545  - 
    546  - 
    547 536   
    548 537  void Binary::remove_dynamic_symbol(const std::string& name) {
    549 538   Symbol* sym = get_dynamic_symbol(name);
    skipped 259 lines
    809 798   
    810 799  LIEF::Binary::symbols_t Binary::get_abstract_symbols() {
    811 800   LIEF::Binary::symbols_t symbols;
    812  - symbols.reserve(dynamic_symbols_.size() + static_symbols_.size());
     801 + symbols.reserve(dynamic_symbols_.size() + symtab_symbols_.size());
    813 802   std::transform(std::begin(dynamic_symbols_), std::end(dynamic_symbols_),
    814 803   std::back_inserter(symbols),
    815 804   [] (std::unique_ptr<Symbol>& s) {
    816 805   return s.get();
    817 806   });
    818 807   
    819  - std::transform(std::begin(static_symbols_), std::end(static_symbols_),
     808 + std::transform(std::begin(symtab_symbols_), std::end(symtab_symbols_),
    820 809   std::back_inserter(symbols),
    821 810   [] (std::unique_ptr<Symbol>& s) {
    822 811   return s.get();
    skipped 52 lines
    875 864   
    876 865  }
    877 866   
    878  -Section* Binary::static_symbols_section() {
     867 +Section* Binary::symtab_symbols_section() {
    879 868   const auto it_symtab_section = std::find_if(
    880 869   std::begin(sections_), std::end(sections_),
    881 870   [] (const std::unique_ptr<Section>& section) {
    skipped 49 lines
    931 920  }
    932 921   
    933 922  result<uint64_t> Binary::get_function_address(const std::string& func_name, bool demangled) const {
    934  - const auto it_symbol = std::find_if(std::begin(static_symbols_), std::end(static_symbols_),
     923 + const auto it_symbol = std::find_if(std::begin(symtab_symbols_), std::end(symtab_symbols_),
    935 924   [&func_name, demangled] (const std::unique_ptr<Symbol>& symbol) {
    936 925   std::string sname;
    937 926   if (demangled) {
    skipped 7 lines
    945 934   symbol->type() == Symbol::TYPE::FUNC;
    946 935   });
    947 936   
    948  - if (it_symbol == std::end(static_symbols_)) {
     937 + if (it_symbol == std::end(symtab_symbols_)) {
    949 938   return make_error_code(lief_errors::not_found);
    950 939   }
    951 940   
    skipped 567 lines
    1519 1508  }
    1520 1509   
    1521 1510  void Binary::strip() {
    1522  - static_symbols_.clear();
     1511 + symtab_symbols_.clear();
    1523 1512   Section* symtab = get(Section::TYPE::SYMTAB);
    1524 1513   if (symtab != nullptr) {
    1525 1514   remove(*symtab, /* clear */ true);
    skipped 1 lines
    1527 1516  }
    1528 1517   
    1529 1518   
    1530  -Symbol& Binary::add_static_symbol(const Symbol& symbol) {
    1531  - static_symbols_.push_back(std::make_unique<Symbol>(symbol));
    1532  - return *static_symbols_.back();
     1519 +Symbol& Binary::add_symtab_symbol(const Symbol& symbol) {
     1520 + symtab_symbols_.push_back(std::make_unique<Symbol>(symbol));
     1521 + return *symtab_symbols_.back();
    1533 1522  }
    1534 1523   
    1535 1524   
    skipped 1642 lines
    3178 3167   os << std::endl;
    3179 3168   
    3180 3169   
    3181  - os << "Static symbols" << std::endl;
     3170 + os << "Symtab symbols" << std::endl;
    3182 3171   os << "==============" << std::endl;
    3183 3172   
    3184  - for (const Symbol& symbol : static_symbols()) {
     3173 + for (const Symbol& symbol : symtab_symbols()) {
    3185 3174   os << symbol << std::endl;
    3186 3175   }
    3187 3176   
    skipped 96 lines
  • ■ ■ ■ ■ ■ ■
    src/ELF/Builder.tcc
    skipped 311 lines
    312 312   
    313 313   // Check if we should relocate or create the .strtab section
    314 314   Section* sec_symtab = binary_->get(Section::TYPE::SYMTAB);
    315  - if (!layout->is_strtab_shared_shstrtab() && !binary_->static_symbols_.empty()) {
     315 + if (!layout->is_strtab_shared_shstrtab() && !binary_->symtab_symbols_.empty()) {
    316 316   // There is no .symtab section => create .strtab
    317 317   if (sec_symtab == nullptr) {
    318 318   // Required since it writes the .strtab content in cache
    skipped 28 lines
    347 347   layout->relocate_symtab(needed_size);
    348 348   }
    349 349   }
    350  - else if (!binary_->static_symbols_.empty()) {
     350 + else if (!binary_->symtab_symbols_.empty()) {
    351 351   // In this case the binary was stripped but the user
    352 352   // added symbols => We have to craft a new section that will contain the symtab
    353 353   LIEF_DEBUG("Need to create a new .symtab section");
    skipped 59 lines
    413 413   }
    414 414   
    415 415   if (config_.static_symtab && binary_->has(Section::TYPE::SYMTAB)) {
    416  - build_static_symbols<ELF_T>();
     416 + build_symtab_symbols<ELF_T>();
    417 417   }
    418 418   
    419 419   // Build sections
    skipped 115 lines
    535 535   
    536 536   // Check if we should relocate or create a .strtab section.
    537 537   // We assume that a .shstrtab is always prensent
    538  - if (!layout->is_strtab_shared_shstrtab() && !binary_->static_symbols_.empty()) {
     538 + if (!layout->is_strtab_shared_shstrtab() && !binary_->symtab_symbols_.empty()) {
    539 539   Section* sec_symtab = binary_->get(Section::TYPE::SYMTAB);
    540 540   if (sec_symtab == nullptr) {
    541 541   LIEF_ERR("Object file without a symtab section is not supported. Please consider submitting an issue.");
    skipped 212 lines
    754 754  }
    755 755   
    756 756  template<typename ELF_T>
    757  -ok_error_t Builder::build_static_symbols() {
     757 +ok_error_t Builder::build_symtab_symbols() {
    758 758   using Elf_Half = typename ELF_T::Elf_Half;
    759 759   using Elf_Word = typename ELF_T::Elf_Word;
    760 760   using Elf_Addr = typename ELF_T::Elf_Addr;
    skipped 3 lines
    764 764   
    765 765   auto* layout = static_cast<ExeLayout*>(layout_.get());
    766 766   
    767  - LIEF_DEBUG("== Build static symbols ==");
    768  - Section* symbol_section = binary_->static_symbols_section();
     767 + LIEF_DEBUG("== Build symtabl symbols ==");
     768 + Section* symbol_section = binary_->symtab_symbols_section();
    769 769   if (symbol_section == nullptr) {
    770 770   LIEF_ERR("Can't find the .symtab section");
    771 771   return make_error_code(lief_errors::file_format_error);
    772 772   }
    773 773   LIEF_DEBUG(".symtab section: '{}'", symbol_section->name());
    774 774   
    775  - std::stable_sort(std::begin(binary_->static_symbols_), std::end(binary_->static_symbols_),
     775 + std::stable_sort(std::begin(binary_->symtab_symbols_), std::end(binary_->symtab_symbols_),
    776 776   [](const std::unique_ptr<Symbol>& lhs, const std::unique_ptr<Symbol>& rhs) {
    777 777   return lhs->is_local() && (rhs->is_global() || rhs->is_weak());
    778 778   });
    779 779   
    780 780   const auto it_first_exported_symbol =
    781  - std::find_if(std::begin(binary_->static_symbols_), std::end(binary_->static_symbols_),
     781 + std::find_if(std::begin(binary_->symtab_symbols_), std::end(binary_->symtab_symbols_),
    782 782   [](const std::unique_ptr<Symbol>& sym) {
    783 783   return sym->is_exported();
    784 784   });
    785 785   
    786 786   const auto first_exported_symbol_index =
    787  - static_cast<uint32_t>(std::distance(std::begin(binary_->static_symbols_), it_first_exported_symbol));
     787 + static_cast<uint32_t>(std::distance(std::begin(binary_->symtab_symbols_), it_first_exported_symbol));
    788 788   
    789 789   if (first_exported_symbol_index != symbol_section->information()) {
    790 790   LIEF_INFO("information of .symtab section changes from {:d} to {:d}",
    skipped 18 lines
    809 809   str_map = &layout->strtab_map();
    810 810   }
    811 811   
    812  - for (const std::unique_ptr<Symbol>& symbol : binary_->static_symbols_) {
     812 + for (const std::unique_ptr<Symbol>& symbol : binary_->symtab_symbols_) {
    813 813   const std::string& name = symbol->name();
    814 814   
    815 815   Elf_Off offset_name = 0;
    816 816   const auto it = str_map->find(name);
    817 817   if (it == std::end(*str_map)) {
    818  - LIEF_ERR("Can't find string offset for static symbol name '{}'", name);
     818 + LIEF_ERR("Can't find string offset for symtab symbol name '{}'", name);
    819 819   } else {
    820 820   offset_name = it->second;
    821 821   }
    skipped 301 lines
    1123 1123   
    1124 1124   // Build symbols
    1125 1125   vector_iostream symbol_table_raw(should_swap());
    1126  - for (const std::unique_ptr<Symbol>& symbol : binary_->static_symbols_) {
     1126 + for (const std::unique_ptr<Symbol>& symbol : binary_->symtab_symbols_) {
    1127 1127   const std::string& name = symbol->name();
    1128 1128   const auto offset_it = str_map->find(name);
    1129 1129   if (offset_it == std::end(*str_map)) {
    skipped 108 lines
    1238 1238   uint32_t symidx = 0;
    1239 1239   const Symbol* sym = reloc->symbol();
    1240 1240   if (sym != nullptr) {
    1241  - const auto it_sym = std::find_if(std::begin(binary_->static_symbols_), std::end(binary_->static_symbols_),
     1241 + const auto it_sym = std::find_if(std::begin(binary_->symtab_symbols_), std::end(binary_->symtab_symbols_),
    1242 1242   [sym] (const std::unique_ptr<Symbol>& s) {
    1243 1243   return s.get() == sym;
    1244 1244   });
    1245  - if (it_sym == std::end(binary_->static_symbols_)) {
     1245 + if (it_sym == std::end(binary_->symtab_symbols_)) {
    1246 1246   LIEF_WARN("Can find the relocation's symbol '{}'", sym->name());
    1247 1247   continue;
    1248 1248   }
    1249 1249   
    1250  - symidx = static_cast<uint32_t>(std::distance(std::begin(binary_->static_symbols_), it_sym));
     1250 + symidx = static_cast<uint32_t>(std::distance(std::begin(binary_->symtab_symbols_), it_sym));
    1251 1251   }
    1252 1252   
    1253 1253   Elf_Xword info = 0;
    skipped 533 lines
  • ■ ■ ■ ■ ■ ■
    src/ELF/ExeLayout.hpp
    skipped 180 lines
    181 181   template<class ELF_T>
    182 182   size_t static_sym_size() {
    183 183   using Elf_Sym = typename ELF_T::Elf_Sym;
    184  - return binary_->static_symbols_.size() * sizeof(Elf_Sym);
     184 + return binary_->symtab_symbols_.size() * sizeof(Elf_Sym);
    185 185   }
    186 186   
    187 187   template<class ELF_T>
    skipped 1056 lines
    1244 1244   }
    1245 1245   LIEF_DEBUG("strtab_idx: {:d}", strtab_idx);
    1246 1246   // Sections that are not associated with segments (mostly debug information)
    1247  - // currently we only handle the static symbol table: .symtab
     1247 + // currently we only handle the symtab symbol table: .symtab
    1248 1248   if (symtab_size_ > 0) {
    1249 1249   LIEF_DEBUG("Relocate .symtab");
    1250 1250   
    skipped 135 lines
  • ■ ■ ■ ■ ■ ■
    src/ELF/Layout.cpp
    skipped 57 lines
    58 58   
    59 59   size_t offset_counter = raw_strtab.tellp();
    60 60   
    61  - if (binary_->static_symbols_.empty()) {
     61 + if (binary_->symtab_symbols_.empty()) {
    62 62   return 0;
    63 63   }
    64 64   
    65  - std::vector<std::string> symstr_opt = optimize(binary_->static_symbols_,
     65 + std::vector<std::string> symstr_opt = optimize(binary_->symtab_symbols_,
    66 66   [] (const std::unique_ptr<Symbol>& sym) { return sym->name(); },
    67 67   offset_counter, &strtab_name_map_);
    68 68   
    skipped 23 lines
    92 92   return s->name();
    93 93   });
    94 94   
    95  - if (!binary_->static_symbols_.empty()) {
     95 + if (!binary_->symtab_symbols_.empty()) {
    96 96   if (binary_->get(Section::TYPE::SYMTAB) == nullptr) {
    97 97   sec_names.emplace_back(".symtab");
    98 98   }
    skipped 12 lines
    111 111   }
    112 112   
    113 113   // Check if the .shstrtab and the .strtab are shared (optimization used by clang)
    114  - // in this case, include the static symbol names
    115  - if (!binary_->static_symbols_.empty() && is_strtab_shared_shstrtab()) {
     114 + // in this case, include the symtab symbol names
     115 + if (!binary_->symtab_symbols_.empty() && is_strtab_shared_shstrtab()) {
    116 116   offset_counter = raw_shstrtab.tellp();
    117  - std::vector<std::string> symstr_opt = optimize(binary_->static_symbols_,
     117 + std::vector<std::string> symstr_opt = optimize(binary_->symtab_symbols_,
    118 118   [] (const std::unique_ptr<Symbol>& sym) { return sym->name(); },
    119 119   offset_counter, &shstr_name_map_);
    120 120   for (const std::string& name : symstr_opt) {
    skipped 11 lines
  • ■ ■ ■ ■
    src/ELF/ObjectFileLayout.hpp
    skipped 101 lines
    102 102   template<class ELF_T>
    103 103   size_t symtab_size() {
    104 104   using Elf_Sym = typename ELF_T::Elf_Sym;
    105  - return binary_->static_symbols_.size() * sizeof(Elf_Sym);
     105 + return binary_->symtab_symbols_.size() * sizeof(Elf_Sym);
    106 106   }
    107 107   
    108 108   inline relocations_map_t& relocation_map() {
    skipped 27 lines
  • ■ ■ ■ ■ ■ ■
    src/ELF/Parser.tcc
    skipped 232 lines
    233 233   }
    234 234   }
    235 235   
    236  - 
    237  - // Parse static symbols
    238  - // ====================
    239 236   if (const Section* sec_symbtab = binary_->get(Section::TYPE::SYMTAB)) {
    240 237   auto nb_entries = static_cast<uint32_t>((sec_symbtab->size() / sizeof(typename ELF_T::Elf_Sym)));
    241 238   nb_entries = std::min(nb_entries, Parser::NB_MAX_SYMBOLS);
    skipped 1 lines
    243 240   if (sec_symbtab->link() == 0 || sec_symbtab->link() >= binary_->sections_.size()) {
    244 241   LIEF_WARN("section->link() is not valid !");
    245 242   } else {
    246  - if (config_.parse_static_symbols) {
     243 + if (config_.parse_symtab_symbols) {
    247 244   // We should have:
    248 245   // nb_entries == section->information())
    249 246   // but lots of compiler not respect this rule
    250  - parse_static_symbols<ELF_T>(sec_symbtab->file_offset(), nb_entries,
     247 + parse_symtab_symbols<ELF_T>(sec_symbtab->file_offset(), nb_entries,
    251 248   *binary_->sections_[sec_symbtab->link()]);
    252 249   }
    253 250   }
    skipped 723 lines
    977 974  } // build_dynamic_reclocations
    978 975   
    979 976  template<typename ELF_T>
    980  -ok_error_t Parser::parse_static_symbols(uint64_t offset, uint32_t nb_symbols,
     977 +ok_error_t Parser::parse_symtab_symbols(uint64_t offset, uint32_t nb_symbols,
    981 978   const Section& string_section) {
    982 979   using Elf_Sym = typename ELF_T::Elf_Sym;
    983 980   static constexpr size_t MAX_RESERVED_SYMBOLS = 10000;
    984  - LIEF_DEBUG("== Parsing static symbols ==");
     981 + LIEF_DEBUG("== Parsing symtab symbols ==");
    985 982   
    986 983   size_t nb_reserved = std::min<size_t>(nb_symbols, MAX_RESERVED_SYMBOLS);
    987  - binary_->static_symbols_.reserve(nb_reserved);
     984 + binary_->symtab_symbols_.reserve(nb_reserved);
    988 985   
    989 986   stream_->setpos(offset);
    990 987   const ARCH arch = binary_->header().machine_type();
    skipped 3 lines
    994 991   break;
    995 992   }
    996 993   auto symbol = std::unique_ptr<Symbol>(new Symbol(std::move(*raw_sym), arch));
    997  - 
    998 994   const auto name_offset = string_section.file_offset() + raw_sym->st_name;
    999  - auto symbol_name = stream_->peek_string_at(name_offset);
    1000  - if (symbol_name) {
     995 + 
     996 + if (auto symbol_name = stream_->peek_string_at(name_offset)) {
    1001 997   symbol->name(std::move(*symbol_name));
    1002 998   } else {
    1003 999   LIEF_ERR("Can't read the symbol's name for symbol #{}", i);
    1004 1000   }
    1005 1001   link_symbol_section(*symbol);
    1006  - binary_->static_symbols_.push_back(std::move(symbol));
     1002 + binary_->symtab_symbols_.push_back(std::move(symbol));
    1007 1003   }
    1008 1004   return ok();
    1009  -} // build_static_symbols
    1010  - 
     1005 +}
    1011 1006   
    1012 1007  template<typename ELF_T>
    1013 1008  ok_error_t Parser::parse_dynamic_symbols(uint64_t offset) {
    skipped 398 lines
    1412 1407   (symbol_table == nullptr ||
    1413 1408   symbol_table->type() == Section::TYPE::DYNSYM);
    1414 1409   
    1415  - const bool is_from_symtab = idx < binary_->static_symbols_.size() &&
     1410 + const bool is_from_symtab = idx < binary_->symtab_symbols_.size() &&
    1416 1411   (symbol_table == nullptr ||
    1417 1412   symbol_table->type() == Section::TYPE::SYMTAB);
    1418 1413   if (is_from_dynsym) {
    1419 1414   reloc->symbol_ = binary_->dynamic_symbols_[idx].get();
    1420 1415   } else if (is_from_symtab) {
    1421  - reloc->symbol_ = binary_->static_symbols_[idx].get();
     1416 + reloc->symbol_ = binary_->symtab_symbols_[idx].get();
    1422 1417   }
    1423 1418   
    1424 1419   if (reloc_hash.insert(reloc.get()).second) {
    skipped 275 lines
  • ■ ■ ■ ■
    src/ELF/hash.cpp
    skipped 61 lines
    62 62   process(std::begin(binary.segments()), std::end(binary.segments()));
    63 63   process(std::begin(binary.dynamic_entries()), std::end(binary.dynamic_entries()));
    64 64   process(std::begin(binary.dynamic_symbols()), std::end(binary.dynamic_symbols()));
    65  - process(std::begin(binary.static_symbols()), std::end(binary.static_symbols()));
     65 + process(std::begin(binary.symtab_symbols()), std::end(binary.symtab_symbols()));
    66 66   process(std::begin(binary.relocations()), std::end(binary.relocations()));
    67 67   process(std::begin(binary.notes()), std::end(binary.notes()));
    68 68   
    skipped 226 lines
  • ■ ■ ■ ■ ■ ■
    src/ELF/json.cpp
    skipped 57 lines
    58 58   }
    59 59   
    60 60   
    61  - // Static symbols
    62  - std::vector<json> static_symbols;
    63  - for (const Symbol& symbol : binary.static_symbols()) {
     61 + // Symtab symbols
     62 + std::vector<json> symtab_symbols;
     63 + for (const Symbol& symbol : binary.symtab_symbols()) {
    64 64   JsonVisitor visitor;
    65 65   visitor(symbol);
    66  - static_symbols.emplace_back(visitor.get());
     66 + symtab_symbols.emplace_back(visitor.get());
    67 67   }
    68 68   
    69 69   
    skipped 64 lines
    134 134   node_["segments"] = segments;
    135 135   node_["dynamic_entries"] = dynamic_entries;
    136 136   node_["dynamic_symbols"] = dynamic_symbols;
    137  - node_["static_symbols"] = static_symbols;
     137 + node_["symtab_symbols"] = symtab_symbols;
    138 138   node_["dynamic_relocations"] = dynamic_relocations;
    139 139   node_["pltgot_relocations"] = pltgot_relocations;
    140 140   node_["symbols_version"] = symbols_version;
    skipped 412 lines
  • ■ ■ ■ ■
    tests/elf/test_bin2lib.py
    skipped 114 lines
    115 115   libadd.write(output.as_posix())
    116 116   
    117 117  def modif_3(libadd: lief.ELF.Binary, output: Path):
    118  - add_hidden_static = libadd.get_static_symbol("add_hidden")
     118 + add_hidden_static = libadd.get_symtab_symbol("add_hidden")
    119 119   assert isinstance(add_hidden_static.name, str)
    120 120   libadd.add_exported_function(add_hidden_static.value, add_hidden_static.name)
    121 121   
    skipped 66 lines
  • ■ ■ ■ ■
    tests/elf/test_bss.py
    skipped 18 lines
    19 19   binary_name = "nopie_bss_671.elf"
    20 20   target = lief.ELF.parse(get_sample(f"ELF/{binary_name}"))
    21 21   
    22  - for s in filter(lambda e: e.exported, target.static_symbols):
     22 + for s in filter(lambda e: e.exported, target.symtab_symbols):
    23 23   target.add_dynamic_symbol(s)
    24 24   
    25 25   output = tmp_path / binary_name
    skipped 54 lines
  • ■ ■ ■ ■ ■ ■
    tests/elf/test_builder.py
    skipped 112 lines
    113 113   sym.type = lief.ELF.Symbol.TYPE.FUNC
    114 114   sym.binding = lief.ELF.Symbol.BINDING.LOCAL
    115 115   sym.visibility = lief.ELF.Symbol.VISIBILITY.DEFAULT
    116  - elf.add_static_symbol(sym)
     116 + elf.add_symtab_symbol(sym)
    117 117   elf.write(out_path.as_posix())
    118 118   
    119 119   print(f"File written in {out_path}")
    skipped 10 lines
    130 130   
    131 131   
    132 132   out = lief.ELF.parse(out_path.as_posix())
    133  - sym_names = [s.name for s in out.static_symbols]
     133 + sym_names = [s.name for s in out.symtab_symbols]
    134 134   assert "test_sym_029" in sym_names
    135 135   
    136 136  @pytest.mark.skipif(not is_linux() or glibc_too_old, reason="not linux or glibc too old")
    skipped 125 lines
  • ■ ■ ■ ■ ■ ■
    tests/elf/test_elf.py
    skipped 142 lines
    143 143   
    144 144   symbols = hello.symbols
    145 145   dynamic_symbols = hello.dynamic_symbols
    146  - static_symbols = hello.static_symbols
     146 + symtab_symbols = hello.symtab_symbols
    147 147   
    148 148   assert all(s in symbols for s in dynamic_symbols)
    149  - assert all(s in symbols for s in static_symbols)
     149 + assert all(s in symbols for s in symtab_symbols)
    150 150   
    151 151  def test_strings():
    152 152   hello = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_all.bin'))
    skipped 139 lines
  • ■ ■ ■ ■ ■ ■
    tests/elf/test_elf_config.py
    skipped 5 lines
    6 6   
    7 7   config.parse_relocations = False
    8 8   config.parse_dyn_symbols = False
    9  - config.parse_static_symbols = False
     9 + config.parse_symtab_symbols = False
    10 10   config.parse_symbol_versions = False
    11 11   config.parse_notes = False
    12 12   config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION
    skipped 4 lines
    17 17   assert len(elf.relocations) == 0
    18 18   assert len(elf.symbols) == 0
    19 19   assert len(elf.dynamic_symbols) == 0
    20  - assert len(elf.static_symbols) == 0
     20 + assert len(elf.symtab_symbols) == 0
    21 21   assert len(elf.symbols_version) == 0
    22 22   assert len(elf.notes) == 0
    23 23   
    skipped 3 lines
    27 27   
    28 28   config.parse_relocations = True
    29 29   config.parse_dyn_symbols = False
    30  - config.parse_static_symbols = False
     30 + config.parse_symtab_symbols = False
    31 31   config.parse_symbol_versions = False
    32 32   config.parse_notes = False
    33 33   config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION
    skipped 4 lines
    38 38   assert len(elf.relocations) > 0
    39 39   assert len(elf.symbols) == 0
    40 40   assert len(elf.dynamic_symbols) == 0
    41  - assert len(elf.static_symbols) == 0
     41 + assert len(elf.symtab_symbols) == 0
    42 42   assert len(elf.symbols_version) == 0
    43 43   assert len(elf.notes) == 0
    44 44   
    skipped 2 lines
    47 47   
    48 48   config.parse_relocations = False
    49 49   config.parse_dyn_symbols = False
    50  - config.parse_static_symbols = True
     50 + config.parse_symtab_symbols = True
    51 51   config.parse_symbol_versions = False
    52 52   config.parse_notes = False
    53 53   config.count_mtd = lief.ELF.ParserConfig.DYNSYM_COUNT.SECTION
    skipped 4 lines
    58 58   assert len(elf.relocations) == 0
    59 59   assert len(elf.symbols) > 0
    60 60   assert len(elf.dynamic_symbols) == 0
    61  - assert len(elf.static_symbols) > 0
     61 + assert len(elf.symtab_symbols) > 0
    62 62   assert len(elf.symbols_version) == 0
    63 63   assert len(elf.notes) == 0
    64 64   
    skipped 11 lines
  • ■ ■ ■ ■ ■ ■
    tests/elf/test_object_files.py
    skipped 118 lines
    119 119   sym.binding = lief.ELF.Symbol.BINDING.GLOBAL # TODO(romain): it fails if the symbol is "local"
    120 120   # cf. binutils-2.35.1/bfd/elflink.c:4602
    121 121   sym.value = 0xdeadc0de
    122  - elf.add_static_symbol(sym)
     122 + elf.add_symtab_symbol(sym)
    123 123   
    124 124   # Modify an existing one
    125  - file_sym = elf.get_static_symbol("test.cpp")
     125 + file_sym = elf.get_symtab_symbol("test.cpp")
    126 126   file_sym.name = "/tmp/foobar.cpp"
    127 127   
    128 128   builder = lief.ELF.Builder(elf)
    skipped 37 lines
  • ■ ■ ■ ■ ■ ■
    tests/elf/test_parser_simple.py
    skipped 70 lines
    71 71   
    72 72  def test_symbols():
    73 73   dynamic_symbols = TARGET.dynamic_symbols
    74  - static_symbols = TARGET.static_symbols
     74 + symtab_symbols = TARGET.symtab_symbols
    75 75   
    76 76   assert len(dynamic_symbols) == 27
    77  - assert len(static_symbols) == 78
     77 + assert len(symtab_symbols) == 78
    78 78   
    79 79   first = TARGET.get_dynamic_symbol("first")
    80 80   assert first.value == 0x000008a9
    81 81   assert first.symbol_version.value == 0x8002
    82 82   assert first.symbol_version.symbol_version_auxiliary.name == "LIBSIMPLE_1.0"
    83 83   
    84  - dtor = TARGET.get_static_symbol("__cxa_finalize@@GLIBC_2.1.3")
     84 + dtor = TARGET.get_symtab_symbol("__cxa_finalize@@GLIBC_2.1.3")
    85 85   assert dtor.value == 00000000
    86 86   
    87 87   symbol_version_definition = TARGET.symbols_version_definition
    skipped 32 lines
    120 120   Related to this issue: https://github.com/lief-project/LIEF/issues/841
    121 121   """
    122 122   elf = lief.ELF.parse(get_sample('ELF/ELF64_x86-64_binary_all.bin'))
    123  - main = elf.get_static_symbol("main")
     123 + main = elf.get_symtab_symbol("main")
    124 124   assert main.section is not None
    125 125   assert main.section.name == ".text"
    126 126   
    127  - assert elf.get_static_symbol("__gmon_start__").section is None
    128  - assert elf.get_static_symbol("_fini").section.name == ".fini"
     127 + assert elf.get_symtab_symbol("__gmon_start__").section is None
     128 + assert elf.get_symtab_symbol("_fini").section.name == ".fini"
    129 129   
Please wait...
Page is in error, reload to recover