File indexing completed on 2024-05-12 05:43:30

0001 /*
0002     Copyright (C) 2013-2014 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef ELFSYMBOLTABLESECTION_H
0019 #define ELFSYMBOLTABLESECTION_H
0020 
0021 #include "elfarraysection.h"
0022 #include "elfsymboltableentry.h"
0023 
0024 #include <vector>
0025 
0026 /** Represents a symbol table sections (.symtab or .dynsym). */
0027 class ElfSymbolTableSection : public ElfSection
0028 {
0029 public:
0030     explicit ElfSymbolTableSection(ElfFile* file, ElfSectionHeader *shdr);
0031     ~ElfSymbolTableSection();
0032 
0033     /** Number of exported entries. */
0034     int exportCount() const;
0035 
0036     /** Number of undefined symbols, i.e. symbols needed to be provided from other libraries. */
0037     int importCount() const;
0038 
0039     /** Returns the symbol table at @p index. */
0040     ElfSymbolTableEntry* entry(uint32_t index) const;
0041 
0042     /** Finds the first symbol table entry with the given value.
0043      *  @return @c 0 if there is no matching entry.
0044      */
0045     ElfSymbolTableEntry* entryWithValue(uint64_t value) const;
0046 
0047     /** Similar as the above, but looks for entries containing @p value rather than matching it exactly .*/
0048     ElfSymbolTableEntry* entryContainingValue(uint64_t value) const;
0049 
0050 private:
0051     // entries in order of occurrence
0052     std::vector<ElfSymbolTableEntry> m_entries;
0053     // entry pointers in order of their virtual address, for fast reverse lookup
0054     std::vector<ElfSymbolTableEntry*> m_entriesByValue;
0055 };
0056 
0057 #endif // ELFSYMBOLTABLESECTION_H