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