ROSE 0.11.145.192
frontend/BinaryFormats/Jvm.h
1#ifndef Jvm_H
2#define Jvm_H
3#ifdef ROSE_ENABLE_BINARY_ANALYSIS
4
5#include <Rose/BinaryAnalysis/ByteOrder.h>
6
7namespace Jvm {
8
13template <typename T>
14size_t read_bytes(const SgAsmJvmConstantPool* pool, char* &bytes, T &length)
15{
16 SgAsmGenericHeader* header{pool->get_header()};
17 rose_addr_t offset{header->get_offset()};
18
19 /* read length of the array */
20 size_t count = header->readContent(offset, &length, sizeof(length));
21 if (count != sizeof(length)) {
22 //throw FormatError("Error reading JVM bytes array length");
23 ROSE_ASSERT(false && "Error reading JVM bytes array length");
24 }
26 offset += count;
27 header->set_offset(offset);
28
29 /* allocate memory for array */
30 bytes = new char[length];
31
32 /* read array */
33 count = header->readContent(offset, bytes, length);
34 if (count != length) {
35 //throw FormatError("Error reading JVM bytes array");
36 ROSE_ASSERT(false && "Error reading JVM bytes array");
37 }
38 offset += count;
39 header->set_offset(offset);
40
41 return count;
42}
43
44template <typename T>
45size_t read_value(const SgAsmJvmConstantPool* pool, T &value, bool advanceOffset=true)
46{
47 SgAsmGenericHeader* header{pool->get_header()};
48 rose_addr_t offset{header->get_offset()};
49
50 size_t count = header->readContent(offset, &value, sizeof(T));
51 if (count != sizeof(T)) {
52 //throw FormatError("Error reading JVM value");
53 ROSE_ASSERT(false && "Error reading JVM value");
54 }
56 if (advanceOffset) header->set_offset(offset + count);
57 return count;
58}
59
60template <typename T>
61void writeValue(std::ostream& os, T value)
62{
64 os.write(reinterpret_cast<const char*>(&value), sizeof value);
65}
66
67} // namespace Jvm
68
69#endif
70#endif
Base class for container file headers.
SgAsmGenericHeader *const & get_header() const
Property: File header that owns this section.
Represents an JVM constant pool.
void hostToBe(const Source &src, Destination *dst, typename std::enable_if< std::is_integral< Source >::value &&std::is_integral< Destination >::value >::type *=nullptr)
Convert host order to big-endian.
Definition ByteOrder.h:93
std::enable_if< std::is_integral< T >::value, T >::type beToHost(const T &x)
Convert a big-endian integer to host order.
Definition ByteOrder.h:51