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

0001 /*
0002     Copyright (C) 2015 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 #include "elfpltentry.h"
0019 #include "elfpltsection.h"
0020 #include "elfgotsection.h"
0021 #include "elffile.h"
0022 #include "elfheader.h"
0023 
0024 #include <elf.h>
0025 
0026 ElfPltEntry::ElfPltEntry(const ElfPltEntry&) = default;
0027 
0028 ElfPltEntry::ElfPltEntry(ElfPltSection* section, uint64_t index) :
0029     m_section(section),
0030     m_index(index)
0031 {
0032 }
0033 
0034 ElfPltEntry& ElfPltEntry::operator=(const ElfPltEntry&) = default;
0035 
0036 ElfPltSection* ElfPltEntry::section() const
0037 {
0038     return m_section;
0039 }
0040 
0041 uint64_t ElfPltEntry::index() const
0042 {
0043     return m_index;
0044 }
0045 
0046 const uchar* ElfPltEntry::rawData() const
0047 {
0048     return m_section->rawData() + m_section->header()->entrySize() * m_index;
0049 }
0050 
0051 uint64_t ElfPltEntry::size() const
0052 {
0053     return m_section->header()->entrySize();
0054 }
0055 
0056 ElfGotEntry* ElfPltEntry::gotEntry() const
0057 {
0058     if (!m_index)
0059         return nullptr;
0060 
0061     // see i386/x86_64 psABI documentation for content of the first entry
0062     // for AArch64 this is experimentally determined
0063     if (m_section->file()->header()->machine() == EM_AARCH64) {
0064         return m_section->gotSection()->entry(m_index + 1);
0065     } else {
0066         return m_section->gotSection()->entry(m_index + 2);
0067     }
0068 }