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 ELFSECTION_H
0019 #define ELFSECTION_H
0020 
0021 #include "elfsectionheader.h"
0022 
0023 #include <QMetaType>
0024 
0025 #include <cstdint>
0026 
0027 class ElfFile;
0028 
0029 /** Base class for all ELF sections. */
0030 class ElfSection
0031 {
0032 public:
0033     explicit ElfSection(ElfFile *file, ElfSectionHeader *shdr);
0034     ElfSection(const ElfSection &other) = delete;
0035     virtual ~ElfSection();
0036     ElfSection& operator=(const ElfSection &other) = delete;
0037 
0038     template <typename T>
0039     inline T* linkedSection() const
0040     {
0041         return dynamic_cast<T*>(m_linkedSection);
0042     }
0043     void setLinkedSection(ElfSection* linkedSection);
0044 
0045     /** Size of the section. */
0046     uint64_t size() const;
0047     /** Access to the raw data of the section. */
0048     unsigned char* rawData() const;
0049 
0050     /** The file this section belongs to. */
0051     ElfFile* file() const;
0052     /** Returns the corresponding section header. */
0053     ElfSectionHeader* header() const;
0054 
0055 protected:
0056     ElfFile *m_file;
0057     ElfSectionHeader *m_sectionHeader;
0058     ElfSection *m_linkedSection;
0059 };
0060 
0061 Q_DECLARE_METATYPE(ElfSection*)
0062 
0063 #endif // ELFSECTION_H