ROSE 2.15.0
Loading...
Searching...
No Matches
BinaryAnalysis/ByteCode/Analysis.h
1#ifndef ROSE_BinaryAnalysis_ByteCode_Analysis_H
2#define ROSE_BinaryAnalysis_ByteCode_Analysis_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
8#include <Rose/Progress.h>
9
11
12namespace Rose {
13namespace BinaryAnalysis {
14namespace ByteCode {
15
16namespace P2 = Partitioner2;
17
18using BasicBlockPtr = P2::BasicBlockPtr;
19using PartitionerPtr = P2::PartitionerPtr;
20using InstructionMap = std::map<Address, SgAsmInstruction*>;
21
22// Forward references
23class Class;
24class Namespace;
25
26using ClassPtr = Sawyer::SharedPointer<Class>;
27using NamespacePtr = Sawyer::SharedPointer<Namespace>;
28
34 public Sawyer::SharedFromThis<Field> {
35 public:
38
39 virtual ~Field();
40
41public:
42 virtual std::string name() const = 0;
43
44protected:
45 Field();
46};
47
54 public Sawyer::SharedFromThis<Method> {
55 public:
58
59 virtual ~Method();
60
61 public:
62 const std::string& name() const;
63 Address address() const;
64
66 void finalize();
67
68 virtual bool isStatic() const = 0;
69 virtual bool isSystemReserved(const std::string &name) const = 0;
70
71 virtual const SgAsmInstructionList* instructions() const = 0;
72 virtual void decode(const Disassembler::BasePtr&) const = 0;
73
74 virtual std::string descriptor() const = 0;
75
76 /* Annotate the AST (.e.g., add comments to instructions) */
77 virtual void annotate() = 0;
78
79 /* Set of instruction branch targets */
80 std::set<Address> targets() const;
81
82 /* Accessors to the declaring class for this method */
83 Class* declaringClass() const;
84 void declaringClass(Class *declaringClass);
85
86 /* Retrieve the instruction at the given address */
87 SgAsmInstruction* instructionAt(Address va) const;
88
89 // Methods associated with basic blocks (Rose::BinaryAnalysis::Partitioner2)
90 //
91 const std::vector<BasicBlockPtr>& blocks() const;
92 void append(BasicBlockPtr bb);
93
94 Method() = delete;
95
96 protected:
97 Method(std::string name, Address va);
98
99 private:
100 std::string name_;
101
102 protected:
103 Address address_ = 0;
104
105 private:
106 Class* class_ = nullptr; // non-owning pointer to the declaring class
107 P2::FunctionPtr function_;
108 std::vector<BasicBlockPtr> blocks_;
109 InstructionMap instructionMap_;
110};
111
117 public Sawyer::SharedFromThis<Class> {
118 public:
121
122 virtual ~Interface();
123
124 virtual std::string name() const = 0;
125
126 protected:
127 Interface();
128};
129
135 public Sawyer::SharedFromThis<Attribute> {
136public:
139
140 virtual ~Attribute();
141
142 virtual std::string name() const = 0;
143
144 protected:
145 Attribute();
146};
147
153 public Sawyer::SharedFromThis<Class> {
154 public:
157 using NamespacePtr = Sawyer::SharedPointer<Namespace>; // forward declaration
158
159 virtual ~Class();
160
162 // Dynamic pointer cast. No-op since this is the base class
163 // static Class promote(const Class&);
164
165 const std::string& name() const;
166 const std::string& baseClassName() const;
167 Address address() const;
168
169 virtual std::string typeSeparator() const = 0;
170 virtual const std::vector<std::string>& strings();
171
172 const std::vector<Field::Ptr>& fields() const;
173 const std::vector<Method::Ptr>& methods() const;
174 const std::vector<Attribute::Ptr>& attributes() const;
175 const std::vector<Interface::Ptr>& interfaces() const;
176
178 void finalize();
179
180 virtual void partition(const PartitionerPtr &partitioner, std::map<std::string,Address> &discoveredFunctions,
181 const Progress::Ptr &progress = Progress::Ptr());
182 virtual void digraph() const;
183 virtual void dump() = 0;
184
185 Class() = delete;
186
187 private:
188 std::string name_;
189 Address address_ = 0; // Base virtual address assigned to this loaded class file
190 NamespacePtr namespace_;
191
192 protected:
193 Class(std::string name, Address va, NamespacePtr ns);
194
195 std::string baseClassName_;
196
197 std::vector<Field::Ptr> fields_;
198 std::vector<Method::Ptr> methods_;
199 std::vector<Attribute::Ptr> attributes_;
200 std::vector<Interface::Ptr> interfaces_;
201 std::vector<std::string> strings_;
202};
203
209 public Sawyer::SharedFromThis<Namespace> {
210 public:
213
214 virtual ~Namespace();
215
217 static Ptr instance();
218
219 virtual std::string name() const;
220 virtual void partition(const PartitionerPtr &partitioner,
221 std::map<std::string,Address> &discoveredFunctions);
222
223 void append(Class::Ptr ptr);
224
225 const std::vector<ByteCode::Class::Ptr>& classes() const;
226
227 protected:
228 Namespace();
229 std::vector<ByteCode::Class::Ptr> classes_;
230};
231
237 public Sawyer::SharedFromThis<Container> {
238 public:
241
242 virtual ~Container();
243
244 /* A unique (per container) virtual address for system/library functions */
245 static Address nextSystemReservedVa();
246
247 public:
248 virtual std::string name() const = 0;
249 virtual bool isSystemReserved(const std::string &name) const = 0;
250 virtual void partition(const PartitionerPtr &partitioner);
251
252 const std::vector<Namespace::Ptr>& namespaces() const;
253
254 protected:
255 Container();
256 std::vector<Namespace::Ptr> namespaces_;
257
258 private:
259 static Address nextSystemReservedVa_;
260};
261
262} // namespace
263} // namespace
264} // namespace
265
266#endif
267#endif
void finalize()
Complete initialization of the class once partitioning is done.
void finalize()
Complete initialization of the method once decoding is done.
static Ptr instance()
Allocating constructor.
Creates SharedPointer from this.
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
List of SgAsmInstruction nodes.
Base class for machine instructions.
Sawyer::SharedPointer< Partitioner > PartitionerPtr
Shared-ownership pointer for Partitioner.
Sawyer::SharedPointer< BasicBlock > BasicBlockPtr
Shared-ownersip pointer for BasicBlock.
Map< Address, SgAsmInstruction * > InstructionMap
Mapping from instruction addresses to instructions.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.