-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathElfDisassembler.h
78 lines (64 loc) · 2.24 KB
/
ElfDisassembler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//===------------------------------------------------------------*- C++ -*-===//
//
// This file is distributed under the MIT License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Copyright (c) 2015 Technical University of Kaiserslautern.
#pragma once
#include "binutils/elf/elf++.hh"
#include <capstone/capstone.h>
namespace disasm {
/**
* ElfDisassembler
*/
class ElfDisassembler {
public:
/**
* Construct a Elf Disassembler that is initially not valid. Calling
* methods other than valid on this results in undefined behavior.
*/
ElfDisassembler();
/**
* Prepares input file for disassembly.
* Precondition: file is a valid ELF file.
*/
ElfDisassembler(const elf::elf& elf_file);
virtual ~ElfDisassembler() = default;
ElfDisassembler(const ElfDisassembler &src) = delete;
ElfDisassembler &operator=(const ElfDisassembler &src) = delete;
ElfDisassembler(ElfDisassembler &&src) = default;
bool valid() const { return m_valid; }
void disassembleCodeUsingSymbols() const;
void disassembleCodeUsingLinearSweep() const;
const elf::section & findSectionbyName(std::string sec_name) const;
void print_string_hex(unsigned char *str, size_t len) const;
bool isSymbolTableAvailable();
void disassembleSectionUsingSymbols(const elf::section &sec) const;
void disassembleSectionUsingLinearSweep(const elf::section &sec) const;
private:
bool isBranch(const cs_insn *inst) const;
bool isDirectBranch(const cs_insn *inst) const;
void prettyPrintInst(const csh& handle, cs_insn* inst) const;
void initializeCapstone(csh *handle) const;
std::vector<size_t>
getCodeSymbolsForSection(const elf::section &sec) const;
private:
bool m_valid;
const elf::elf* m_elf_file;
struct CapstoneConfig final{
public:
CapstoneConfig():
arch_type{CS_ARCH_TRICORE},
mode{(cs_mode)0},
details{true}{
}
CapstoneConfig(const CapstoneConfig& src) = default;
CapstoneConfig &operator=(const CapstoneConfig& src) = default;
cs_arch arch_type;
cs_mode mode;
bool details;
};
CapstoneConfig m_config;
};
}