# HG changeset patch # User Paul Boddie # Date 1100875502 -3600 # Node ID aec972e2534be0d5cb521d11930d32aed61d7139 # Parent 6dda8e27def2ada01438722fd71cac2d80a21dfc Fixed long and double constant handling. Added/fixed get_value methods to/for various constant types. diff -r 6dda8e27def2 -r aec972e2534b classfile.py --- a/classfile.py Fri Nov 19 15:43:43 2004 +0100 +++ b/classfile.py Fri Nov 19 15:45:02 2004 +0100 @@ -15,6 +15,9 @@ def u2(data): return struct.unpack(">H", data[0:2])[0] +def s2(data): + return struct.unpack(">h", data[0:2])[0] + def u4(data): return struct.unpack(">L", data[0:4])[0] @@ -223,12 +226,24 @@ def __unicode__(self): return unicode(self.bytes, "utf-8") + def get_value(self): + return str(self) + class StringInfo: def init(self, data, class_file): self.class_file = class_file self.string_index = u2(data[0:2]) return data[2:] + def __str__(self): + return str(self.class_file.constants[self.string_index - 1]) + + def __unicode__(self): + return unicode(self.class_file.constants[self.string_index - 1]) + + def get_value(self): + return str(self) + class SmallNumInfo: def init(self, data, class_file): self.class_file = class_file @@ -246,8 +261,8 @@ class LargeNumInfo: def init(self, data, class_file): self.class_file = class_file - self.high_bytes = u4(data[0:4]) - self.low_bytes = u4(data[4:8]) + self.high_bytes = data[0:4] + self.low_bytes = data[4:8] return data[8:] class LongInfo(LargeNumInfo): @@ -292,6 +307,7 @@ self.attribute_length = u4(data[0:4]) # Permit the NameUtils mix-in. self.name_index = self.sourcefile_index = u2(data[4:6]) + return data[6:] class ConstantValueAttributeInfo(AttributeInfo): def init(self, data, class_file):