ROSE 0.11.145.147
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
10
11namespace Rose {
12namespace BinaryAnalysis {
13namespace ByteCode {
14
15using BasicBlockPtr = Partitioner2::BasicBlockPtr;
16using PartitionerPtr = Partitioner2::PartitionerPtr;
17
18// Forward references
19class Class;
20class Namespace;
21
22class Code {
23public:
24 virtual const uint8_t* bytes() const = 0;
25 virtual size_t size() const = 0;
26 virtual rose_addr_t offset() const = 0;
27
28protected:
29 Code() {}
30};
31
32class Field {
33public:
34 virtual std::string name() const = 0;
35protected:
36 Field() {}
37};
38
39class Method {
40public:
41 virtual std::string name() const = 0;
42 virtual bool isSystemReserved(const std::string &name) const = 0;
43
44 virtual const Code & code() const = 0;
45 virtual const SgAsmInstructionList* instructions() const = 0;
46 virtual void decode(const Disassembler::BasePtr&) const = 0;
47
48 /* Annotate the AST (.e.g., add comments to instructions) */
49 virtual void annotate() = 0;
50
51 /* Set of instruction branch targets */
52 std::set<rose_addr_t> targets() const;
53
54 // Methods associated with basic blocks (Rose::BinaryAnalysis::Partitioner2)
55 //
56 const std::vector<BasicBlockPtr>& blocks() const;
57 void append(BasicBlockPtr bb);
58
59 Method() = delete;
60
61protected:
62 Method(rose_addr_t);
63 ~Method();
64 rose_addr_t classAddr_;
66 std::vector<BasicBlockPtr> blocks_;
67};
68
69class Interface {
70public:
71 virtual std::string name() const = 0;
72protected:
73 Interface() {}
74};
75
76class Attribute {
77public:
78 virtual std::string name() const = 0;
79protected:
80 Attribute() {}
81};
82
83class Class {
84public:
85 virtual std::string name() const = 0;
86 virtual std::string super_name() const = 0;
87 virtual std::string typeSeparator() const = 0;
88 virtual const std::vector<const Field*> &fields() const = 0;
89 virtual const std::vector<const Method*> &methods() const = 0;
90 virtual const std::vector<const Attribute*> &attributes() const = 0;
91 virtual const std::vector<const Interface*> &interfaces() const = 0;
92 virtual const std::vector<std::string> &strings() = 0;
93 virtual void partition(const PartitionerPtr &, std::map<std::string,rose_addr_t> &) const;
94 virtual void digraph() const;
95 virtual void dump() = 0;
96
97 rose_addr_t address() const {return address_;}
98
99 Class() = delete;
100
101protected:
102 rose_addr_t address_;
103 std::shared_ptr<Namespace> namespace_;
104 Class(std::shared_ptr<Namespace> ns, rose_addr_t va) : address_{va}, namespace_{ns} {}
105};
106
108public:
109 virtual std::string name() const = 0;
110 virtual void partition(const PartitionerPtr &partitioner, std::map<std::string,rose_addr_t> &) const;
111
112 void append(std::shared_ptr<Class> ptr) {
113 classes_.push_back(ptr);
114 }
115 const std::vector<std::shared_ptr<Class>> &classes() const {
116 return classes_;
117 }
118
119protected:
120 Namespace() {}
121 std::vector<std::shared_ptr<Class>> classes_;
122};
123
125public:
126 virtual std::string name() const = 0;
127 virtual bool isSystemReserved(const std::string &name) const = 0;
128 virtual void partition(const PartitionerPtr &partitioner) const;
129
130 const std::vector<std::shared_ptr<Namespace>> &namespaces() const {return namespaces_;}
131
132 /* A unique (per container) virtual address for system/library functions */
133 static rose_addr_t nextSystemReservedVa();
134
135protected:
136 Container() {}
137 std::vector<std::shared_ptr<Namespace>> namespaces_;
138
139private:
140 static rose_addr_t nextSystemReservedVa_;
141};
142
143} // namespace
144} // namespace
145} // namespace
146
147#endif
148#endif
List of SgAsmInstruction nodes.
Sawyer::SharedPointer< Partitioner > PartitionerPtr
Shared-ownership pointer for Partitioner.
Sawyer::SharedPointer< BasicBlock > BasicBlockPtr
Shared-ownersip pointer for BasicBlock.
The ROSE library.