paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | """ |
paul@0 | 4 | Java class file decoder. Specification found at the following URL: |
paul@0 | 5 | http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html |
paul@0 | 6 | """ |
paul@0 | 7 | |
paul@0 | 8 | import struct |
paul@0 | 9 | |
paul@1 | 10 | # Utility functions. |
paul@1 | 11 | |
paul@1 | 12 | def u1(data): |
paul@1 | 13 | return struct.unpack(">B", data[0:1])[0] |
paul@1 | 14 | |
paul@1 | 15 | def u2(data): |
paul@1 | 16 | return struct.unpack(">H", data[0:2])[0] |
paul@1 | 17 | |
paul@1 | 18 | def u4(data): |
paul@1 | 19 | return struct.unpack(">L", data[0:4])[0] |
paul@1 | 20 | |
paul@2 | 21 | # Useful mix-ins. |
paul@2 | 22 | |
paul@2 | 23 | class NameUtils: |
paul@2 | 24 | def get_name(self): |
paul@2 | 25 | if self.name_index != 0: |
paul@2 | 26 | return unicode(self.class_file.constants[self.name_index - 1]) |
paul@2 | 27 | else: |
paul@2 | 28 | # Some name indexes are zero to indicate special conditions. |
paul@2 | 29 | return None |
paul@2 | 30 | |
paul@0 | 31 | # Constant information. |
paul@1 | 32 | # Objects of these classes are not directly aware of the class they reside in. |
paul@0 | 33 | |
paul@2 | 34 | class ClassInfo(NameUtils): |
paul@2 | 35 | def init(self, data, class_file): |
paul@2 | 36 | self.class_file = class_file |
paul@1 | 37 | self.name_index = u2(data[0:2]) |
paul@0 | 38 | return data[2:] |
paul@0 | 39 | |
paul@0 | 40 | class RefInfo: |
paul@2 | 41 | def init(self, data, class_file): |
paul@2 | 42 | self.class_file = class_file |
paul@1 | 43 | self.class_index = u2(data[0:2]) |
paul@1 | 44 | self.name_and_type_index = u2(data[2:4]) |
paul@0 | 45 | return data[4:] |
paul@0 | 46 | |
paul@0 | 47 | class FieldRefInfo(RefInfo): |
paul@0 | 48 | pass |
paul@0 | 49 | |
paul@0 | 50 | class MethodRefInfo(RefInfo): |
paul@0 | 51 | pass |
paul@0 | 52 | |
paul@0 | 53 | class InterfaceMethodRefInfo(RefInfo): |
paul@0 | 54 | pass |
paul@0 | 55 | |
paul@2 | 56 | class NameAndTypeInfo(NameUtils): |
paul@2 | 57 | def init(self, data, class_file): |
paul@2 | 58 | self.class_file = class_file |
paul@1 | 59 | self.name_index = u2(data[0:2]) |
paul@1 | 60 | self.descriptor_index = u2(data[2:4]) |
paul@0 | 61 | return data[4:] |
paul@0 | 62 | |
paul@0 | 63 | class Utf8Info: |
paul@2 | 64 | def init(self, data, class_file): |
paul@2 | 65 | self.class_file = class_file |
paul@1 | 66 | self.length = u2(data[0:2]) |
paul@0 | 67 | self.bytes = data[2:2+self.length] |
paul@0 | 68 | return data[2+self.length:] |
paul@0 | 69 | |
paul@0 | 70 | def __str__(self): |
paul@0 | 71 | return self.bytes |
paul@0 | 72 | |
paul@0 | 73 | def __unicode__(self): |
paul@0 | 74 | return unicode(self.bytes, "utf-8") |
paul@0 | 75 | |
paul@0 | 76 | class StringInfo: |
paul@2 | 77 | def init(self, data, class_file): |
paul@2 | 78 | self.class_file = class_file |
paul@1 | 79 | self.string_index = u2(data[0:2]) |
paul@0 | 80 | return data[2:] |
paul@0 | 81 | |
paul@0 | 82 | class SmallNumInfo: |
paul@2 | 83 | def init(self, data, class_file): |
paul@2 | 84 | self.class_file = class_file |
paul@1 | 85 | self.bytes = u4(data[0:4]) |
paul@0 | 86 | return data[4:] |
paul@0 | 87 | |
paul@0 | 88 | class IntegerInfo(SmallNumInfo): |
paul@0 | 89 | pass |
paul@0 | 90 | |
paul@0 | 91 | class FloatInfo(SmallNumInfo): |
paul@0 | 92 | pass |
paul@0 | 93 | |
paul@0 | 94 | class LargeNumInfo: |
paul@2 | 95 | def init(self, data, class_file): |
paul@2 | 96 | self.class_file = class_file |
paul@1 | 97 | self.high_bytes = u4(data[0:4]) |
paul@1 | 98 | self.low_bytes = u4(data[4:8]) |
paul@0 | 99 | return data[8:] |
paul@0 | 100 | |
paul@0 | 101 | class LongInfo(LargeNumInfo): |
paul@0 | 102 | pass |
paul@0 | 103 | |
paul@0 | 104 | class DoubleInfo(LargeNumInfo): |
paul@0 | 105 | pass |
paul@0 | 106 | |
paul@0 | 107 | # Other information. |
paul@1 | 108 | # Objects of these classes are generally aware of the class they reside in. |
paul@0 | 109 | |
paul@2 | 110 | class ItemInfo(NameUtils): |
paul@0 | 111 | def init(self, data, class_file): |
paul@0 | 112 | self.class_file = class_file |
paul@1 | 113 | self.access_flags = u2(data[0:2]) |
paul@1 | 114 | self.name_index = u2(data[2:4]) |
paul@1 | 115 | self.descriptor_index = u2(data[4:6]) |
paul@0 | 116 | self.attributes, data = self.class_file._get_attributes(data[6:]) |
paul@0 | 117 | return data |
paul@0 | 118 | |
paul@0 | 119 | # Symbol parsing. |
paul@0 | 120 | |
paul@0 | 121 | def _get_method_descriptor(self, s): |
paul@0 | 122 | assert s[0] == "(" |
paul@0 | 123 | params = [] |
paul@0 | 124 | s = s[1:] |
paul@0 | 125 | while s[0] != ")": |
paul@0 | 126 | parameter_descriptor, s = self._get_parameter_descriptor(s) |
paul@0 | 127 | params.append(parameter_descriptor) |
paul@0 | 128 | if s[1] != "V": |
paul@0 | 129 | return_type, s = self._get_field_type(s[1:]) |
paul@0 | 130 | else: |
paul@0 | 131 | return_type, s = None, s[1:] |
paul@0 | 132 | return params, return_type |
paul@0 | 133 | |
paul@0 | 134 | def _get_parameter_descriptor(self, s): |
paul@0 | 135 | return self._get_field_type(s) |
paul@0 | 136 | |
paul@0 | 137 | def _get_field_descriptor(self, s): |
paul@0 | 138 | return self._get_field_type(s) |
paul@0 | 139 | |
paul@0 | 140 | def _get_component_type(self, s): |
paul@0 | 141 | return self._get_field_type(s) |
paul@0 | 142 | |
paul@0 | 143 | def _get_field_type(self, s): |
paul@0 | 144 | base_type, s = self._get_base_type(s) |
paul@0 | 145 | object_type = None |
paul@0 | 146 | array_type = None |
paul@0 | 147 | if base_type == "L": |
paul@0 | 148 | object_type, s = self._get_object_type(s) |
paul@0 | 149 | elif base_type == "[": |
paul@0 | 150 | array_type, s = self._get_array_type(s) |
paul@0 | 151 | return (base_type, object_type, array_type), s |
paul@0 | 152 | |
paul@0 | 153 | def _get_base_type(self, s): |
paul@0 | 154 | if len(s) > 0: |
paul@0 | 155 | return s[0], s[1:] |
paul@0 | 156 | else: |
paul@0 | 157 | return None, s |
paul@0 | 158 | |
paul@0 | 159 | def _get_object_type(self, s): |
paul@0 | 160 | if len(s) > 0: |
paul@0 | 161 | s_end = s.find(";") |
paul@0 | 162 | assert s_end != -1 |
paul@0 | 163 | return s[:s_end], s[s_end+1:] |
paul@0 | 164 | else: |
paul@0 | 165 | return None, s |
paul@0 | 166 | |
paul@0 | 167 | def _get_array_type(self, s): |
paul@0 | 168 | if len(s) > 0: |
paul@3 | 169 | return self._get_component_type(s) |
paul@0 | 170 | else: |
paul@0 | 171 | return None, s |
paul@0 | 172 | |
paul@0 | 173 | class FieldInfo(ItemInfo): |
paul@0 | 174 | def get_descriptor(self): |
paul@0 | 175 | return self._get_field_descriptor(unicode(self.class_file.constants[self.descriptor_index - 1])) |
paul@0 | 176 | |
paul@0 | 177 | class MethodInfo(ItemInfo): |
paul@0 | 178 | def get_descriptor(self): |
paul@0 | 179 | return self._get_method_descriptor(unicode(self.class_file.constants[self.descriptor_index - 1])) |
paul@0 | 180 | |
paul@0 | 181 | class AttributeInfo: |
paul@0 | 182 | def init(self, data, class_file): |
paul@1 | 183 | self.attribute_length = u4(data[0:4]) |
paul@0 | 184 | self.info = data[4:4+self.attribute_length] |
paul@0 | 185 | return data[4+self.attribute_length:] |
paul@0 | 186 | |
paul@0 | 187 | # NOTE: Decode the different attribute formats. |
paul@0 | 188 | |
paul@2 | 189 | class SourceFileAttributeInfo(AttributeInfo, NameUtils): |
paul@2 | 190 | def init(self, data, class_file): |
paul@2 | 191 | self.class_file = class_file |
paul@2 | 192 | self.attribute_length = u4(data[0:4]) |
paul@2 | 193 | # Permit the NameUtils mix-in. |
paul@2 | 194 | self.name_index = self.sourcefile_index = u2(data[4:6]) |
paul@0 | 195 | |
paul@0 | 196 | class ConstantValueAttributeInfo(AttributeInfo): |
paul@0 | 197 | def init(self, data, class_file): |
paul@1 | 198 | self.attribute_length = u4(data[0:4]) |
paul@1 | 199 | self.constant_value_index = u2(data[4:6]) |
paul@0 | 200 | assert 4+self.attribute_length == 6 |
paul@0 | 201 | return data[4+self.attribute_length:] |
paul@0 | 202 | |
paul@0 | 203 | class CodeAttributeInfo(AttributeInfo): |
paul@0 | 204 | def init(self, data, class_file): |
paul@0 | 205 | self.class_file = class_file |
paul@1 | 206 | self.attribute_length = u4(data[0:4]) |
paul@1 | 207 | self.max_stack = u2(data[4:6]) |
paul@1 | 208 | self.max_locals = u2(data[6:8]) |
paul@1 | 209 | self.code_length = u4(data[8:12]) |
paul@0 | 210 | end_of_code = 12+self.code_length |
paul@0 | 211 | self.code = data[12:end_of_code] |
paul@1 | 212 | self.exception_table_length = u2(data[end_of_code:end_of_code+2]) |
paul@0 | 213 | self.exception_table = [] |
paul@0 | 214 | data = data[end_of_code + 2:] |
paul@0 | 215 | for i in range(0, self.exception_table_length): |
paul@0 | 216 | exception = ExceptionInfo() |
paul@0 | 217 | data = exception.init(data) |
paul@2 | 218 | self.exception_table.append(exception) |
paul@0 | 219 | self.attributes, data = self.class_file._get_attributes(data) |
paul@0 | 220 | return data |
paul@0 | 221 | |
paul@0 | 222 | class ExceptionsAttributeInfo(AttributeInfo): |
paul@1 | 223 | def init(self, data, class_file): |
paul@1 | 224 | self.class_file = class_file |
paul@1 | 225 | self.attribute_length = u4(data[0:4]) |
paul@1 | 226 | self.number_of_exceptions = u2(data[4:6]) |
paul@1 | 227 | self.exception_index_table = [] |
paul@1 | 228 | index = 6 |
paul@1 | 229 | for i in range(0, self.number_of_exceptions): |
paul@1 | 230 | self.exception_index_table.append(u2(data[index:index+2])) |
paul@1 | 231 | index += 2 |
paul@1 | 232 | return data[index:] |
paul@1 | 233 | |
paul@1 | 234 | def get_exception(self, i): |
paul@1 | 235 | exception_index = self.exception_index_table[i] |
paul@1 | 236 | return self.class_file.constants[exception_index - 1] |
paul@0 | 237 | |
paul@0 | 238 | class InnerClassesAttributeInfo(AttributeInfo): |
paul@2 | 239 | def init(self, data, class_file): |
paul@2 | 240 | self.class_file = class_file |
paul@2 | 241 | self.attribute_length = u4(data[0:4]) |
paul@2 | 242 | self.number_of_classes = u2(data[4:6]) |
paul@2 | 243 | self.classes = [] |
paul@2 | 244 | data = data[6:] |
paul@2 | 245 | for i in range(0, self.number_of_classes): |
paul@2 | 246 | inner_class = InnerClassInfo() |
paul@2 | 247 | data = inner_class.init(data, self.class_file) |
paul@2 | 248 | self.classes.append(inner_class) |
paul@2 | 249 | return data |
paul@0 | 250 | |
paul@0 | 251 | class SyntheticAttributeInfo(AttributeInfo): |
paul@0 | 252 | pass |
paul@0 | 253 | |
paul@0 | 254 | class LineNumberAttributeInfo(AttributeInfo): |
paul@2 | 255 | def init(self, data, class_file): |
paul@2 | 256 | self.class_file = class_file |
paul@2 | 257 | self.attribute_length = u4(data[0:4]) |
paul@2 | 258 | self.line_number_table_length = u2(data[4:6]) |
paul@2 | 259 | self.line_number_table = [] |
paul@2 | 260 | data = data[6:] |
paul@2 | 261 | for i in range(0, self.line_number_table_length): |
paul@2 | 262 | line_number = LineNumberInfo() |
paul@2 | 263 | data = line_number.init(data) |
paul@2 | 264 | self.line_number_table.append(line_number) |
paul@2 | 265 | return data |
paul@0 | 266 | |
paul@0 | 267 | class LocalVariableAttributeInfo(AttributeInfo): |
paul@2 | 268 | def init(self, data, class_file): |
paul@2 | 269 | self.class_file = class_file |
paul@2 | 270 | self.attribute_length = u4(data[0:4]) |
paul@2 | 271 | self.local_variable_table_length = u2(data[4:6]) |
paul@2 | 272 | self.local_variable_table = [] |
paul@2 | 273 | data = data[6:] |
paul@2 | 274 | for i in range(0, self.local_variable_table_length): |
paul@2 | 275 | local_variable = LocalVariableInfo() |
paul@2 | 276 | data = local_variable.init(data) |
paul@2 | 277 | self.local_variable_table.append(local_variable) |
paul@2 | 278 | return data |
paul@0 | 279 | |
paul@0 | 280 | class DeprecatedAttributeInfo(AttributeInfo): |
paul@0 | 281 | pass |
paul@0 | 282 | |
paul@2 | 283 | # Child classes of the attribute information classes. |
paul@2 | 284 | |
paul@0 | 285 | class ExceptionInfo: |
paul@0 | 286 | def init(self, data): |
paul@1 | 287 | self.start_pc = u2(data[0:2]) |
paul@1 | 288 | self.end_pc = u2(data[2:4]) |
paul@1 | 289 | self.handler_pc = u2(data[4:6]) |
paul@1 | 290 | self.catch_type = u2(data[6:8]) |
paul@0 | 291 | return data[8:] |
paul@0 | 292 | |
paul@2 | 293 | class InnerClassInfo(NameUtils): |
paul@2 | 294 | def init(self, data, class_file): |
paul@2 | 295 | self.class_file = class_file |
paul@2 | 296 | self.inner_class_info_index = u2(data[0:2]) |
paul@2 | 297 | self.outer_class_info_index = u2(data[2:4]) |
paul@2 | 298 | # Permit the NameUtils mix-in. |
paul@2 | 299 | self.name_index = self.inner_name_index = u2(data[4:6]) |
paul@2 | 300 | self.inner_class_access_flags = u2(data[6:8]) |
paul@2 | 301 | return data[8:] |
paul@2 | 302 | |
paul@2 | 303 | class LineNumberInfo: |
paul@2 | 304 | def init(self, data): |
paul@2 | 305 | self.start_pc = u2(data[0:2]) |
paul@2 | 306 | self.line_number = u2(data[2:4]) |
paul@2 | 307 | return data[4:] |
paul@2 | 308 | |
paul@2 | 309 | class LocalVariableInfo(NameUtils): |
paul@2 | 310 | def init(self, data, class_file): |
paul@2 | 311 | self.class_file = class_file |
paul@2 | 312 | self.start_pc = u2(data[0:2]) |
paul@2 | 313 | self.length = u2(data[2:4]) |
paul@2 | 314 | self.name_index = u2(data[4:6]) |
paul@2 | 315 | self.descriptor_index = u2(data[6:8]) |
paul@2 | 316 | self.index = u2(data[8:10]) |
paul@2 | 317 | return data[10:] |
paul@2 | 318 | |
paul@2 | 319 | def get_descriptor(self): |
paul@2 | 320 | return self._get_field_descriptor(unicode(self.class_file.constants[self.descriptor_index - 1])) |
paul@2 | 321 | |
paul@2 | 322 | # Exceptions. |
paul@2 | 323 | |
paul@0 | 324 | class UnknownTag(Exception): |
paul@0 | 325 | pass |
paul@0 | 326 | |
paul@0 | 327 | class UnknownAttribute(Exception): |
paul@0 | 328 | pass |
paul@0 | 329 | |
paul@0 | 330 | # Abstractions for the main structures. |
paul@0 | 331 | |
paul@0 | 332 | class ClassFile: |
paul@0 | 333 | |
paul@0 | 334 | "A class representing a Java class file." |
paul@0 | 335 | |
paul@0 | 336 | def __init__(self, s): |
paul@0 | 337 | |
paul@0 | 338 | """ |
paul@0 | 339 | Process the given string 's', populating the object with the class |
paul@0 | 340 | file's details. |
paul@0 | 341 | """ |
paul@0 | 342 | |
paul@0 | 343 | self.constants, s = self._get_constants(s[8:]) |
paul@0 | 344 | self.access_flags, s = self._get_access_flags(s) |
paul@0 | 345 | self.this_class, s = self._get_this_class(s) |
paul@0 | 346 | self.super_class, s = self._get_super_class(s) |
paul@0 | 347 | self.interfaces, s = self._get_interfaces(s) |
paul@0 | 348 | self.fields, s = self._get_fields(s) |
paul@0 | 349 | self.methods, s = self._get_methods(s) |
paul@0 | 350 | self.attributes, s = self._get_attributes(s) |
paul@0 | 351 | |
paul@0 | 352 | def _decode_const(self, s): |
paul@1 | 353 | tag = u1(s[0:1]) |
paul@0 | 354 | if tag == 1: |
paul@0 | 355 | const = Utf8Info() |
paul@0 | 356 | elif tag == 3: |
paul@0 | 357 | const = IntegerInfo() |
paul@0 | 358 | elif tag == 4: |
paul@0 | 359 | const = FloatInfo() |
paul@0 | 360 | elif tag == 5: |
paul@0 | 361 | const = LongInfo() |
paul@0 | 362 | elif tag == 6: |
paul@0 | 363 | const = DoubleInfo() |
paul@0 | 364 | elif tag == 7: |
paul@0 | 365 | const = ClassInfo() |
paul@0 | 366 | elif tag == 8: |
paul@0 | 367 | const = StringInfo() |
paul@0 | 368 | elif tag == 9: |
paul@0 | 369 | const = FieldRefInfo() |
paul@0 | 370 | elif tag == 10: |
paul@0 | 371 | const = MethodRefInfo() |
paul@0 | 372 | elif tag == 11: |
paul@0 | 373 | const = InterfaceMethodRefInfo() |
paul@0 | 374 | elif tag == 12: |
paul@0 | 375 | const = NameAndTypeInfo() |
paul@0 | 376 | else: |
paul@0 | 377 | raise UnknownTag, tag |
paul@2 | 378 | |
paul@2 | 379 | # Initialise the constant object. |
paul@2 | 380 | |
paul@2 | 381 | s = const.init(s[1:], self) |
paul@0 | 382 | return const, s |
paul@0 | 383 | |
paul@0 | 384 | def _get_constants_from_table(self, count, s): |
paul@0 | 385 | l = [] |
paul@0 | 386 | # Have to skip certain entries specially. |
paul@0 | 387 | i = 1 |
paul@0 | 388 | while i < count: |
paul@0 | 389 | c, s = self._decode_const(s) |
paul@0 | 390 | l.append(c) |
paul@0 | 391 | # Add a blank entry after "large" entries. |
paul@0 | 392 | if isinstance(c, LargeNumInfo): |
paul@0 | 393 | l.append(None) |
paul@0 | 394 | i += 1 |
paul@0 | 395 | i += 1 |
paul@0 | 396 | return l, s |
paul@0 | 397 | |
paul@0 | 398 | def _get_items_from_table(self, cls, number, s): |
paul@0 | 399 | l = [] |
paul@0 | 400 | for i in range(0, number): |
paul@0 | 401 | f = cls() |
paul@0 | 402 | s = f.init(s, self) |
paul@0 | 403 | l.append(f) |
paul@0 | 404 | return l, s |
paul@0 | 405 | |
paul@0 | 406 | def _get_methods_from_table(self, number, s): |
paul@0 | 407 | return self._get_items_from_table(MethodInfo, number, s) |
paul@0 | 408 | |
paul@0 | 409 | def _get_fields_from_table(self, number, s): |
paul@0 | 410 | return self._get_items_from_table(FieldInfo, number, s) |
paul@0 | 411 | |
paul@0 | 412 | def _get_attribute_from_table(self, s): |
paul@1 | 413 | attribute_name_index = u2(s[0:2]) |
paul@0 | 414 | constant_name = self.constants[attribute_name_index - 1].bytes |
paul@0 | 415 | if constant_name == "SourceFile": |
paul@0 | 416 | attribute = SourceFileAttributeInfo() |
paul@0 | 417 | elif constant_name == "ConstantValue": |
paul@0 | 418 | attribute = ConstantValueAttributeInfo() |
paul@0 | 419 | elif constant_name == "Code": |
paul@0 | 420 | attribute = CodeAttributeInfo() |
paul@0 | 421 | elif constant_name == "Exceptions": |
paul@0 | 422 | attribute = ExceptionsAttributeInfo() |
paul@0 | 423 | elif constant_name == "InnerClasses": |
paul@0 | 424 | attribute = InnerClassesAttributeInfo() |
paul@0 | 425 | elif constant_name == "Synthetic": |
paul@0 | 426 | attribute = SyntheticAttributeInfo() |
paul@0 | 427 | elif constant_name == "LineNumberTable": |
paul@0 | 428 | attribute = LineNumberAttributeInfo() |
paul@0 | 429 | elif constant_name == "LocalVariableTable": |
paul@0 | 430 | attribute = LocalVariableAttributeInfo() |
paul@0 | 431 | elif constant_name == "Deprecated": |
paul@0 | 432 | attribute = DeprecatedAttributeInfo() |
paul@0 | 433 | else: |
paul@0 | 434 | raise UnknownAttribute, constant_name |
paul@0 | 435 | s = attribute.init(s[2:], self) |
paul@0 | 436 | return attribute, s |
paul@0 | 437 | |
paul@0 | 438 | def _get_attributes_from_table(self, number, s): |
paul@0 | 439 | attributes = [] |
paul@0 | 440 | for i in range(0, number): |
paul@0 | 441 | attribute, s = self._get_attribute_from_table(s) |
paul@0 | 442 | attributes.append(attribute) |
paul@0 | 443 | return attributes, s |
paul@0 | 444 | |
paul@0 | 445 | def _get_constants(self, s): |
paul@1 | 446 | count = u2(s[0:2]) |
paul@0 | 447 | return self._get_constants_from_table(count, s[2:]) |
paul@0 | 448 | |
paul@0 | 449 | def _get_access_flags(self, s): |
paul@1 | 450 | return u2(s[0:2]), s[2:] |
paul@0 | 451 | |
paul@0 | 452 | def _get_this_class(self, s): |
paul@1 | 453 | index = u2(s[0:2]) |
paul@0 | 454 | return self.constants[index - 1], s[2:] |
paul@0 | 455 | |
paul@0 | 456 | _get_super_class = _get_this_class |
paul@0 | 457 | |
paul@0 | 458 | def _get_interfaces(self, s): |
paul@0 | 459 | interfaces = [] |
paul@1 | 460 | number = u2(s[0:2]) |
paul@0 | 461 | s = s[2:] |
paul@0 | 462 | for i in range(0, number): |
paul@1 | 463 | index = u2(s[0:2]) |
paul@0 | 464 | interfaces.append(self.constants[index - 1]) |
paul@0 | 465 | s = s[2:] |
paul@0 | 466 | return interfaces, s |
paul@0 | 467 | |
paul@0 | 468 | def _get_fields(self, s): |
paul@1 | 469 | number = u2(s[0:2]) |
paul@0 | 470 | return self._get_fields_from_table(number, s[2:]) |
paul@0 | 471 | |
paul@0 | 472 | def _get_attributes(self, s): |
paul@1 | 473 | number = u2(s[0:2]) |
paul@0 | 474 | return self._get_attributes_from_table(number, s[2:]) |
paul@0 | 475 | |
paul@0 | 476 | def _get_methods(self, s): |
paul@1 | 477 | number = u2(s[0:2]) |
paul@0 | 478 | return self._get_methods_from_table(number, s[2:]) |
paul@0 | 479 | |
paul@0 | 480 | if __name__ == "__main__": |
paul@0 | 481 | import sys |
paul@0 | 482 | f = open(sys.argv[1]) |
paul@0 | 483 | c = ClassFile(f.read()) |
paul@0 | 484 | |
paul@0 | 485 | # vim: tabstop=4 expandtab shiftwidth=4 |