ROSE  0.11.123.0
frontend/BinaryFormats/Jvm.h
1 #ifndef Jvm_H
2 #define Jvm_H
3 
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 namespace Jvm {
7 
12 template <typename T>
13 size_t read_bytes(const SgAsmJvmConstantPool* pool, char* &bytes, T &length)
14 {
15  SgAsmGenericHeader* header{pool->get_header()};
16  rose_addr_t offset{header->get_offset()};
17 
18  /* read length of the array */
19  size_t count = header->read_content(offset, &length, sizeof(length));
20  if (count != sizeof(length)) {
21  //throw FormatError("Error reading JVM bytes array length");
22  ROSE_ASSERT(false && "Error reading JVM bytes array length");
23  }
24  length = ByteOrder::be_to_host(length);
25  offset += count;
26  header->set_offset(offset);
27 
28  /* allocate memory for array */
29  bytes = new char[length];
30 
31  /* read array */
32  count = header->read_content(offset, bytes, length);
33  if (count != length) {
34  //throw FormatError("Error reading JVM bytes array");
35  ROSE_ASSERT(false && "Error reading JVM bytes array");
36  }
37  offset += count;
38  header->set_offset(offset);
39 
40  return count;
41 }
42 
43 template <typename T>
44 size_t read_value(const SgAsmJvmConstantPool* pool, T &value, bool advance_offset=true)
45 {
46  SgAsmGenericHeader* header{pool->get_header()};
47  rose_addr_t offset{header->get_offset()};
48 
49  size_t count = header->read_content(offset, &value, sizeof(T));
50  if (count != sizeof(T)) {
51  //throw FormatError("Error reading JVM value");
52  ROSE_ASSERT(false && "Error reading JVM value");
53  }
54  value = ByteOrder::be_to_host(value);
55  if (advance_offset) header->set_offset(offset + count);
56  return count;
57 }
58 
59 } // namespace Jvm
60 
61 #endif
62 #endif
Represents an JVM constant pool.
SgAsmGenericHeader * get_header() const
Property: File header that owns this section.
Base class for container file headers.