| 12 | { |
| 13 | public: |
| 14 | classfile(char *data, std::size_t size) : membuffer(data, size) |
| 15 | { |
| 16 | valid = false; |
| 17 | is_synthetic = false; |
| 18 | read_be(magic); |
| 19 | if (magic != 0xCAFEBABE) |
| 20 | throw new classfile_exception(); |
| 21 | read_be(minor_version); |
| 22 | read_be(major_version); |
| 23 | constants.load(*this); |
| 24 | read_be(access_flags); |
| 25 | read_be(this_class); |
| 26 | read_be(super_class); |
| 27 | |
| 28 | // Interfaces |
| 29 | uint16_t iface_count = 0; |
| 30 | read_be(iface_count); |
| 31 | while (iface_count) |
| 32 | { |
| 33 | uint16_t iface; |
| 34 | read_be(iface); |
| 35 | interfaces.push_back(iface); |
| 36 | iface_count--; |
| 37 | } |
| 38 | |
| 39 | // Fields |
| 40 | // read fields (and attributes from inside fields) (and possible inner classes. yay for |
| 41 | // recursion!) |
| 42 | // for now though, we will ignore all attributes |
| 43 | /* |
| 44 | * field_info |
| 45 | * { |
| 46 | * u2 access_flags; |
| 47 | * u2 name_index; |
| 48 | * u2 descriptor_index; |
| 49 | * u2 attributes_count; |
| 50 | * attribute_info attributes[attributes_count]; |
| 51 | * } |
| 52 | */ |
| 53 | uint16_t field_count = 0; |
| 54 | read_be(field_count); |
| 55 | while (field_count) |
| 56 | { |
| 57 | // skip field stuff |
| 58 | skip(6); |
| 59 | // and skip field attributes |
| 60 | uint16_t attr_count = 0; |
| 61 | read_be(attr_count); |
| 62 | while (attr_count) |
| 63 | { |
| 64 | skip(2); |
| 65 | uint32_t attr_length = 0; |
| 66 | read_be(attr_length); |
| 67 | skip(attr_length); |
| 68 | attr_count--; |
| 69 | } |
| 70 | field_count--; |
| 71 | } |