1 /* 2 Copyright (C) 2013-2014 Volker Krause <vkrause@kde.org> 3 4 This program is free software; you can redistribute it and/or modify it 5 under the terms of the GNU Library General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or (at your 7 option) any later version. 8 9 This program is distributed in the hope that it will be useful, but WITHOUT 10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 12 License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef DISASSEMBLER_H 19 #define DISASSEMBLER_H 20 21 #include <cstdint> 22 23 class QString; 24 25 class ElfFile; 26 class ElfPltEntry; 27 class ElfSection; 28 class ElfSymbolTableEntry; 29 class ElfGotEntry; 30 31 class DwarfLine; 32 33 class Disassembler 34 { 35 public: 36 Disassembler(); 37 Disassembler(const Disassembler&) = delete; 38 virtual ~Disassembler(); 39 40 Disassembler& operator=(const Disassembler&) = delete; 41 42 QString disassemble(ElfSymbolTableEntry *entry); 43 QString disassemble(ElfSection *section); 44 QString disassemble(ElfPltEntry *entry); 45 46 // internal 47 ElfFile* file() const; 48 uint64_t baseAddress() const; 49 void printAddress(uint64_t addr, QString *s) const; 50 51 /** Pretty-print symbol name, override for adding navigation links etc. */ 52 virtual QString printSymbol(ElfSymbolTableEntry *entry) const; 53 /** ditto, for .got entries. */ 54 virtual QString printGotEntry(ElfGotEntry *entry) const; 55 /** ditto, for .plt entries. */ 56 virtual QString printPltEntry(ElfPltEntry *entry) const; 57 58 private: 59 QString disassemble(const unsigned char* data, uint64_t size); 60 QString disassembleBinutils(const unsigned char* data, uint64_t size); 61 QString disassembleCapstone(const unsigned char* data, uint64_t size); 62 63 DwarfLine lineForAddress(uint64_t addr) const; 64 QString printSourceLine(DwarfLine line) const; 65 66 ElfFile *m_file = nullptr; 67 uint64_t m_baseAddress = 0; 68 }; 69 70 #endif // DISASSEMBLER_H 71