ROSE  0.11.131.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;
60  virtual const Code & code() const;
61  virtual const void decode(const Disassembler::BasePtr &disassembler) const;
62  virtual const SgAsmInstructionList* instructions() const;
63 
64  JvmMethod() = delete;
66 
67 private:
68  SgAsmJvmFileHeader* jfh_;
69  SgAsmJvmMethod* sgMethod_;
70  JvmCode code_;
71 };
72 
73 class JvmInterface : public Interface {
74 public:
75  virtual const std::string name() const;
76  const uint16_t index() const {return index_;}
77 
78  JvmInterface() = delete;
79  explicit JvmInterface(SgAsmJvmFileHeader* jfh, uint16_t index)
80  : jfh_{jfh}, index_{index} {
81  }
82 
83 private:
84  SgAsmJvmFileHeader* jfh_;
85  uint16_t index_;
86 };
87 
88 class JvmAttribute : public Attribute {
89 public:
90  virtual const std::string name() const;
91  const uint16_t index() const {return index_;}
92 
93  JvmAttribute() = delete;
94  explicit JvmAttribute(SgAsmJvmFileHeader* jfh, uint16_t index)
95  : jfh_{jfh}, index_{index} {
96  }
97 
98 private:
99  SgAsmJvmFileHeader* jfh_;
100  uint16_t index_;
101 };
102 
103 class JvmClass : public Class {
104 public:
105  virtual const std::string name() const;
106  virtual const std::string super_name() const;
107  virtual const std::vector<std::string> &strings();
108  virtual const std::vector<const Interface*> &interfaces() const {
109  return interfaces_;
110  }
111  virtual const std::vector<const Field*> &fields() const {
112  return fields_;
113  }
114  virtual const std::vector<const Method*> &methods() const {
115  return methods_;
116  }
117  virtual const std::vector<const Attribute*> &attributes() const {
118  return attributes_;
119  }
120 
121  SgAsmJvmConstantPool* constant_pool() {
122  return jfh_->get_constant_pool();
123  }
124 
125  JvmClass() = delete;
126  explicit JvmClass(SgAsmJvmFileHeader* jfh);
127 
128 private:
129  SgAsmJvmFileHeader* jfh_;
130  std::vector<const Field*> fields_;
131  std::vector<const Method*> methods_;
132  std::vector<const Attribute*> attributes_;
133  std::vector<const Interface*> interfaces_;
134  std::vector<std::string> strings_;
135 };
136 
137 
138 } // namespace
139 } // namespace
140 } // namespace
141 
142 #endif
143 #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.