ROSE  0.11.145.0
Rose/BinaryAnalysis/ByteCode/Jvm.h
1 #ifndef ROSE_BinaryAnalysis_ByteCode_Jvm_H
2 #define ROSE_BinaryAnalysis_ByteCode_Jvm_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/ByteCode/Analysis.h>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 namespace ByteCode {
11 
12 class JvmCode : public Code {
13 public:
14  virtual const uint8_t* bytes() const {
15  return bytes_;
16  }
17  virtual const size_t size() const {
18  return size_;
19  }
20  rose_addr_t const offset() const {
21  return offset_;
22  }
23  void bytes(const uint8_t* buf) {
24  bytes_ = buf;
25  }
26  void size(size_t sz) {
27  size_ = sz;
28  }
29  void offset(rose_addr_t off) {
30  offset_ = off;
31  }
32 
33  explicit JvmCode(uint8_t* bytes, size_t size, rose_addr_t offset)
34  : bytes_{bytes}, size_{size}, offset_{offset} {
35  }
36 
37 private:
38  const uint8_t* bytes_;
39  size_t size_;
40  rose_addr_t offset_;
41 };
42 
43 class JvmField : public Field {
44 public:
45  virtual const std::string name() const;
46 
47  JvmField() = delete;
48  explicit JvmField(SgAsmJvmFileHeader* jfh, SgAsmJvmField* field)
49  : jfh_{jfh}, sgField_{field} {
50  }
51 
52 private:
53  SgAsmJvmFileHeader* jfh_;
54  SgAsmJvmField* sgField_;
55 };
56 
57 class JvmMethod : public Method {
58 public:
59  virtual const std::string name() const override;
60  virtual const Code & code() const override;
61  virtual const void decode(const Disassembler::BasePtr &disassembler) const override;
62  virtual const SgAsmInstructionList* instructions() const override;
63 
64  virtual void annotate() override;
65 
66  JvmMethod() = delete;
67  explicit JvmMethod(SgAsmJvmFileHeader*, SgAsmJvmMethod*, rose_addr_t);
68 
69 private:
70  SgAsmJvmFileHeader* jfh_;
71  SgAsmJvmMethod* sgMethod_;
72  JvmCode code_;
73 };
74 
75 class JvmInterface : public Interface {
76 public:
77  virtual const std::string name() const;
78  const uint16_t index() const {return index_;}
79 
80  JvmInterface() = delete;
81  explicit JvmInterface(SgAsmJvmFileHeader* jfh, uint16_t index)
82  : jfh_{jfh}, index_{index} {
83  }
84 
85 private:
86  SgAsmJvmFileHeader* jfh_;
87  uint16_t index_;
88 };
89 
90 class JvmAttribute : public Attribute {
91 public:
92  virtual const std::string name() const;
93  const uint16_t index() const {return index_;}
94 
95  JvmAttribute() = delete;
96  explicit JvmAttribute(SgAsmJvmFileHeader* jfh, uint16_t index)
97  : jfh_{jfh}, index_{index} {
98  }
99 
100 private:
101  SgAsmJvmFileHeader* jfh_;
102  uint16_t index_;
103 };
104 
105 class JvmClass : public Class {
106 public:
107  virtual const std::string name() const;
108  virtual const std::string super_name() const;
109  virtual const std::vector<std::string> &strings();
110  virtual const std::vector<const Interface*> &interfaces() const {
111  return interfaces_;
112  }
113  virtual const std::vector<const Field*> &fields() const {
114  return fields_;
115  }
116  virtual const std::vector<const Method*> &methods() const {
117  return methods_;
118  }
119  virtual const std::vector<const Attribute*> &attributes() const {
120  return attributes_;
121  }
122 
123  SgAsmJvmConstantPool* constant_pool() {
124  return jfh_->get_constant_pool();
125  }
126  virtual void dump();
127 
128  static std::string name(uint16_t, const SgAsmJvmConstantPool*);
129 
130  JvmClass() = delete;
131  explicit JvmClass(SgAsmJvmFileHeader* jfh);
132 
133 private:
134  SgAsmJvmFileHeader* jfh_;
135  std::vector<const Field*> fields_;
136  std::vector<const Method*> methods_;
137  std::vector<const Attribute*> attributes_;
138  std::vector<const Interface*> interfaces_;
139  std::vector<std::string> strings_;
140 };
141 
142 
143 } // namespace
144 } // namespace
145 } // namespace
146 
147 #endif
148 #endif
Represents an JVM constant pool.
Main namespace for the ROSE library.
Represents the file header of an JVM binary container.
SgAsmJvmConstantPool *const & get_constant_pool() const
Property: Constant pool.
List of SgAsmInstruction nodes.