summaryrefslogtreecommitdiffstats
path: root/depends/classparser/src/classfile.h
diff options
context:
space:
mode:
authorSky <git@bunnies.cc>2013-11-06 17:02:23 +0000
committerSky <git@bunnies.cc>2013-11-06 17:02:23 +0000
commit7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a (patch)
tree2753d1ee11dad2cf1c4ce1e8a28ead92214f2f1c /depends/classparser/src/classfile.h
parentdc3b0fcb2b74aeede37b08216b203cab284f7fce (diff)
parentbba4ed5ab2c98c3d60a141d6a089a49716753615 (diff)
downloadMultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar
MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar.gz
MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar.lz
MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.tar.xz
MultiMC-7ddc2b6a89e1b57be1eaa44aa8018ff8af765c7a.zip
Merge branch 'develop'
Diffstat (limited to 'depends/classparser/src/classfile.h')
-rw-r--r--depends/classparser/src/classfile.h269
1 files changed, 136 insertions, 133 deletions
diff --git a/depends/classparser/src/classfile.h b/depends/classparser/src/classfile.h
index 33207e99..a5e7ee50 100644
--- a/depends/classparser/src/classfile.h
+++ b/depends/classparser/src/classfile.h
@@ -5,149 +5,152 @@
#include <map>
namespace java
{
- /**
- * Class representing a Java .class file
- */
- class classfile : public util::membuffer
+/**
+ * Class representing a Java .class file
+ */
+class classfile : public util::membuffer
+{
+public:
+ classfile(char *data, std::size_t size) : membuffer(data, size)
{
- public:
- classfile(char * data, std::size_t size) : membuffer(data, size)
+ valid = false;
+ is_synthetic = false;
+ read_be(magic);
+ if (magic != 0xCAFEBABE)
+ throw new classfile_exception();
+ read_be(minor_version);
+ read_be(major_version);
+ constants.load(*this);
+ read_be(access_flags);
+ read_be(this_class);
+ read_be(super_class);
+
+ // Interfaces
+ uint16_t iface_count = 0;
+ read_be(iface_count);
+ while (iface_count)
{
- valid = false;
- is_synthetic = false;
- read_be(magic);
- if(magic != 0xCAFEBABE)
- throw new classfile_exception();
- read_be(minor_version);
- read_be(major_version);
- constants.load(*this);
- read_be(access_flags);
- read_be(this_class);
- read_be(super_class);
-
- // Interfaces
- uint16_t iface_count = 0;
- read_be(iface_count);
- while (iface_count)
- {
- uint16_t iface;
- read_be(iface);
- interfaces.push_back(iface);
- iface_count --;
- }
-
- // Fields
- // read fields (and attributes from inside fields) (and possible inner classes. yay for recursion!)
- // for now though, we will ignore all attributes
- /*
- * field_info
- * {
- * u2 access_flags;
- * u2 name_index;
- * u2 descriptor_index;
- * u2 attributes_count;
- * attribute_info attributes[attributes_count];
- * }
- */
- uint16_t field_count = 0;
- read_be(field_count);
- while (field_count)
- {
- // skip field stuff
- skip(6);
- // and skip field attributes
- uint16_t attr_count = 0;
- read_be(attr_count);
- while(attr_count)
- {
- skip(2);
- uint32_t attr_length = 0;
- read_be(attr_length);
- skip(attr_length);
- attr_count --;
- }
- field_count --;
- }
+ uint16_t iface;
+ read_be(iface);
+ interfaces.push_back(iface);
+ iface_count--;
+ }
- // class methods
- /*
- * method_info
- * {
- * u2 access_flags;
- * u2 name_index;
- * u2 descriptor_index;
- * u2 attributes_count;
- * attribute_info attributes[attributes_count];
- * }
- */
- uint16_t method_count = 0;
- read_be(method_count);
- while( method_count )
+ // Fields
+ // read fields (and attributes from inside fields) (and possible inner classes. yay for
+ // recursion!)
+ // for now though, we will ignore all attributes
+ /*
+ * field_info
+ * {
+ * u2 access_flags;
+ * u2 name_index;
+ * u2 descriptor_index;
+ * u2 attributes_count;
+ * attribute_info attributes[attributes_count];
+ * }
+ */
+ uint16_t field_count = 0;
+ read_be(field_count);
+ while (field_count)
+ {
+ // skip field stuff
+ skip(6);
+ // and skip field attributes
+ uint16_t attr_count = 0;
+ read_be(attr_count);
+ while (attr_count)
{
- skip(6);
- // and skip method attributes
- uint16_t attr_count = 0;
- read_be(attr_count);
- while(attr_count)
- {
- skip(2);
- uint32_t attr_length = 0;
- read_be(attr_length);
- skip(attr_length);
- attr_count --;
- }
- method_count --;
+ skip(2);
+ uint32_t attr_length = 0;
+ read_be(attr_length);
+ skip(attr_length);
+ attr_count--;
}
+ field_count--;
+ }
- // class attributes
- // there are many kinds of attributes. this is just the generic wrapper structure.
- // type is decided by attribute name. extensions to the standard are *possible*
- // class annotations are one kind of a attribute (one per class)
- /*
- * attribute_info
- * {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u1 info[attribute_length];
- * }
- */
- uint16_t class_attr_count = 0;
- read_be(class_attr_count);
- while(class_attr_count)
+ // class methods
+ /*
+ * method_info
+ * {
+ * u2 access_flags;
+ * u2 name_index;
+ * u2 descriptor_index;
+ * u2 attributes_count;
+ * attribute_info attributes[attributes_count];
+ * }
+ */
+ uint16_t method_count = 0;
+ read_be(method_count);
+ while (method_count)
+ {
+ skip(6);
+ // and skip method attributes
+ uint16_t attr_count = 0;
+ read_be(attr_count);
+ while (attr_count)
{
- uint16_t name_idx = 0;
- read_be(name_idx);
+ skip(2);
uint32_t attr_length = 0;
read_be(attr_length);
-
- auto name = constants[name_idx];
- if(name.str_data == "RuntimeVisibleAnnotations")
+ skip(attr_length);
+ attr_count--;
+ }
+ method_count--;
+ }
+
+ // class attributes
+ // there are many kinds of attributes. this is just the generic wrapper structure.
+ // type is decided by attribute name. extensions to the standard are *possible*
+ // class annotations are one kind of a attribute (one per class)
+ /*
+ * attribute_info
+ * {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u1 info[attribute_length];
+ * }
+ */
+ uint16_t class_attr_count = 0;
+ read_be(class_attr_count);
+ while (class_attr_count)
+ {
+ uint16_t name_idx = 0;
+ read_be(name_idx);
+ uint32_t attr_length = 0;
+ read_be(attr_length);
+
+ auto name = constants[name_idx];
+ if (name.str_data == "RuntimeVisibleAnnotations")
+ {
+ uint16_t num_annotations = 0;
+ read_be(num_annotations);
+ while (num_annotations)
{
- uint16_t num_annotations = 0;
- read_be(num_annotations);
- while (num_annotations)
- {
- visible_class_annotations.push_back(annotation::read(*this, constants));
- num_annotations --;
- }
+ visible_class_annotations.push_back(annotation::read(*this, constants));
+ num_annotations--;
}
- else skip(attr_length);
- class_attr_count --;
}
- valid = true;
- };
- bool valid;
- bool is_synthetic;
- uint32_t magic;
- uint16_t minor_version;
- uint16_t major_version;
- constant_pool constants;
- uint16_t access_flags;
- uint16_t this_class;
- uint16_t super_class;
- // interfaces this class implements ? must be. investigate.
- std::vector<uint16_t> interfaces;
- // FIXME: doesn't free up memory on delete
- java::annotation_table visible_class_annotations;
- };
+ else
+ skip(attr_length);
+ class_attr_count--;
+ }
+ valid = true;
+ }
+ ;
+ bool valid;
+ bool is_synthetic;
+ uint32_t magic;
+ uint16_t minor_version;
+ uint16_t major_version;
+ constant_pool constants;
+ uint16_t access_flags;
+ uint16_t this_class;
+ uint16_t super_class;
+ // interfaces this class implements ? must be. investigate.
+ std::vector<uint16_t> interfaces;
+ // FIXME: doesn't free up memory on delete
+ java::annotation_table visible_class_annotations;
+};
} \ No newline at end of file