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 "elfgnusymbolversionrequirementssection.h" 0019 #include "elfgnusymbolversionrequirement.h" 0020 #include "elfgnusymbolversionrequirementauxiliaryentry.h" 0021 #include "elfdynamicsection.h" 0022 #include "elffile.h" 0023 0024 ElfGNUSymbolVersionRequirementsSection::ElfGNUSymbolVersionRequirementsSection(ElfFile* file, ElfSectionHeader* shdr) : 0025 ElfSection(file, shdr) 0026 { 0027 } 0028 0029 ElfGNUSymbolVersionRequirementsSection::~ElfGNUSymbolVersionRequirementsSection() 0030 { 0031 qDeleteAll(m_versionRequirements); 0032 } 0033 0034 uint32_t ElfGNUSymbolVersionRequirementsSection::entryCount() const 0035 { 0036 return m_versionRequirements.size(); 0037 } 0038 0039 ElfGNUSymbolVersionRequirement* ElfGNUSymbolVersionRequirementsSection::requirement(uint32_t index) const 0040 { 0041 return m_versionRequirements.at(index); 0042 } 0043 0044 ElfGNUSymbolVersionRequirementAuxiliaryEntry* ElfGNUSymbolVersionRequirementsSection::requirementForVersionIndex(uint16_t index) const 0045 { 0046 for (uint32_t i = 0; i < entryCount(); ++i) { 0047 auto req = m_versionRequirements.at(i); 0048 for (uint16_t j = 0; j < req->auxiliarySize(); ++j) { 0049 auto reqAux = req->auxiliaryEntry(j); 0050 if ((reqAux->other() & 0x7FFF) == (index & 0x7FFF)) 0051 return reqAux; 0052 } 0053 } 0054 return nullptr; 0055 } 0056 0057 void ElfGNUSymbolVersionRequirementsSection::parse() 0058 { 0059 // TODO parse until nextOffset() is 0 might be an alternative, removes dependency on dynamicSection() being available here 0060 const auto verNeedNum = file()->dynamicSection()->entryWithTag(DT_VERNEEDNUM); 0061 if (!verNeedNum) 0062 return; 0063 0064 uint32_t offset = 0; 0065 m_versionRequirements.reserve(verNeedNum->value()); 0066 for (uint i = 0; i < verNeedNum->value(); ++i) { 0067 const auto entry = new ElfGNUSymbolVersionRequirement(this, offset); 0068 m_versionRequirements.push_back(entry); 0069 offset += entry->nextOffset(); 0070 } 0071 }