retdec
jump_targets.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_BIN2LLVMIR_OPTIMIZATIONS_DECODER_JUMP_TARGETS_H
8 #define RETDEC_BIN2LLVMIR_OPTIMIZATIONS_DECODER_JUMP_TARGETS_H
9 
10 #include <optional>
11 #include <set>
12 
16 #include "retdec/common/address.h"
17 
18 namespace retdec {
19 namespace bin2llvmir {
20 
21 class Config;
22 
27 {
28  public:
33  enum class eType
34  {
35  // Jump targets discovered in control flow changing instructions.
41  // Jump targets from various other sources.
42  CONFIG,
45  IMPORT,
46  DEBUG,
47  SYMBOL,
48  EXPORT,
50  VTABLE,
51  LEFTOVER,
52  // Default jump target.
53  UNKNOWN,
54  };
55 
56  public:
57  JumpTarget();
58  JumpTarget(
60  eType t,
61  cs_mode m,
63  std::optional<std::size_t> sz = std::nullopt);
64 
65  bool operator<(const JumpTarget& o) const;
66 
68  bool hasSize() const;
69  std::optional<std::size_t> getSize() const;
70  eType getType() const;
72  cs_mode getMode() const;
73  void setMode(cs_mode m) const;
74 
75  friend std::ostream& operator<<(std::ostream &out, const JumpTarget& jt);
76 
77  private:
78  // This address will be tried to be decoded.
81  std::optional<std::size_t> _size;
82  // The type of jump target - determined by its source.
87  mutable cs_mode _mode = CS_MODE_BIG_ENDIAN;
88 
89  public:
90  static Config* config;
91 };
92 
97 {
98  public:
99  auto begin();
100  auto end();
101 
102  bool empty();
103  std::size_t size() const;
104  void clear();
105  const JumpTarget& top();
106  void pop();
107 
108  const JumpTarget* push(
111  cs_mode m,
113  std::optional<std::size_t> sz = std::nullopt);
114 
115  friend std::ostream& operator<<(std::ostream &out, const JumpTargets& jts);
116 
117  public:
118  std::set<JumpTarget> _data;
119 
120  public:
121  static Config* config;
122 };
123 
124 } // namespace bin2llvmir
125 } // namespace retdec
126 
127 #endif
x86 specialization of translator's abstract public interface.
Common public interface for translators converting bytes to LLVM IR.
Definition: config.h:24
Definition: jump_targets.h:27
friend std::ostream & operator<<(std::ostream &out, const JumpTarget &jt)
Definition: jump_targets.cpp:102
eType _type
Definition: jump_targets.h:83
eType getType() const
Definition: jump_targets.cpp:82
eType
Definition: jump_targets.h:34
static Config * config
Definition: jump_targets.h:90
std::optional< std::size_t > _size
Definition: jump_targets.h:81
bool operator<(const JumpTarget &o) const
Definition: jump_targets.cpp:48
JumpTarget()
Definition: jump_targets.cpp:23
bool hasSize() const
Definition: jump_targets.cpp:72
retdec::common::Address getAddress() const
Definition: jump_targets.cpp:67
cs_mode getMode() const
Definition: jump_targets.cpp:92
cs_mode _mode
Disassembler mode that should be used for this jump target.
Definition: jump_targets.h:87
retdec::common::Address getFromAddress() const
Definition: jump_targets.cpp:87
retdec::common::Address _address
Definition: jump_targets.h:79
std::optional< std::size_t > getSize() const
Definition: jump_targets.cpp:77
void setMode(cs_mode m) const
Definition: jump_targets.cpp:97
retdec::common::Address _fromAddress
Address from which this jump target was created.
Definition: jump_targets.h:85
Definition: jump_targets.h:97
friend std::ostream & operator<<(std::ostream &out, const JumpTargets &jts)
Definition: jump_targets.cpp:258
static Config * config
Definition: jump_targets.h:121
const JumpTarget & top()
Definition: jump_targets.cpp:238
const JumpTarget * push(retdec::common::Address a, JumpTarget::eType t, cs_mode m, retdec::common::Address f, std::optional< std::size_t > sz=std::nullopt)
Definition: jump_targets.cpp:183
std::size_t size() const
Definition: jump_targets.cpp:223
bool empty()
Definition: jump_targets.cpp:233
auto begin()
Definition: jump_targets.cpp:248
auto end()
Definition: jump_targets.cpp:253
void pop()
Definition: jump_targets.cpp:243
void clear()
Definition: jump_targets.cpp:228
std::set< JumpTarget > _data
Definition: jump_targets.h:118
Definition: address.h:21
Address, address pair and other derived class representation.
Decode input binary into LLVM IR.
The frontend-end part of the decompiler.
Definition: archive_wrapper.h:19