@@ -155,7 +155,8 @@ def __init__(self, stream=None):
155155 self .TC_CLASS : self .do_class ,
156156 self .TC_BLOCKDATA : self .do_blockdata ,
157157 self .TC_REFERENCE : self .do_reference ,
158- self .TC_ENUM : self .do_enum
158+ self .TC_ENUM : self .do_enum ,
159+ self .TC_ENDBLOCKDATA : self .do_null , # note that we are reusing of do_null
159160 }
160161 self .current_object = None
161162 self .reference_counter = 0
@@ -165,7 +166,7 @@ def __init__(self, stream=None):
165166
166167 def readObject (self ):
167168 try :
168- res = self ._read_and_exec_opcode (ident = 0 ) # TODO: add expects
169+ opcode , res = self ._read_and_exec_opcode (ident = 0 ) # TODO: add expects
169170
170171 position_bak = self .object_stream .tell ()
171172 the_rest = self .object_stream .read ()
@@ -194,7 +195,7 @@ def _read_and_exec_opcode(self, ident=0, expect=None):
194195 handler = self .opmap .get (opid )
195196 if not handler :
196197 raise RuntimeError ("Unknown OpCode in the stream: 0x%x" % opid )
197- return handler (ident = ident )
198+ return ( opid , handler (ident = ident ) )
198199
199200 def _readStruct (self , unpack ):
200201 length = struct .calcsize (unpack )
@@ -246,14 +247,14 @@ def do_classdesc(self, parent=None, ident=0):
246247 field_type = self ._convert_char_to_type (typecode )
247248
248249 if field_type == self .TYPE_ARRAY :
249- field_type = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
250+ opcode , field_type = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
250251 assert type (field_type ) is str
251252# if field_type is not None:
252253# field_type = "array of " + field_type
253254# else:
254255# field_type = "array of None"
255256 elif field_type == self .TYPE_OBJECT :
256- field_type = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
257+ opcode , field_type = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
257258 assert type (field_type ) is str
258259
259260 log_debug ("FieldName: 0x%X" % typecode + " " + str (field_name ) + " " + str (field_type ), ident )
@@ -271,7 +272,7 @@ def do_classdesc(self, parent=None, ident=0):
271272 if opid != self .TC_ENDBLOCKDATA :
272273 raise NotImplementedError ("classAnnotation isn't implemented yet" )
273274 # superClassDesc
274- superclassdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
275+ opcode , superclassdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
275276 log_debug (str (superclassdesc ), ident )
276277 clazz .superclass = superclassdesc
277278
@@ -289,7 +290,7 @@ def do_class(self, parent=None, ident=0):
289290 log_debug ("[class]" , ident )
290291
291292 # TODO: what to do with "(ClassDesc)prevObject". (see 3rd line for classDesc:)
292- classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
293+ opcode , classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
293294 log_debug ("Classdesc: %s" % classdesc , ident )
294295 self ._add_reference (classdesc )
295296 return classdesc
@@ -300,7 +301,7 @@ def do_object(self, parent=None, ident=0):
300301 log_debug ("[object]" , ident )
301302
302303 # TODO: what to do with "(ClassDesc)prevObject". (see 3rd line for classDesc:)
303- classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
304+ opcode , classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
304305 # self.TC_REFERENCE hasn't shown in spec, but actually is here
305306
306307 self ._add_reference (java_object )
@@ -341,17 +342,9 @@ def do_object(self, parent=None, ident=0):
341342
342343 if classdesc .flags & self .SC_SERIALIZABLE and classdesc .flags & self .SC_WRITE_METHOD or classdesc .flags & self .SC_EXTERNALIZABLE and classdesc .flags & self .SC_BLOCK_DATA :
343344 # objectAnnotation
344- (opid , ) = self ._readStruct (">B" )
345- log_debug ("OpCode: 0x%X" % opid , ident )
346- if opid == self .TC_ENDBLOCKDATA : # 0x78:
347- log_debug ("TC_ENDBLOCKDATA: no object annotation" )
348- elif opid == self .TC_OBJECT :
349- self .object_stream .seek (- 1 , mode = 1 )
350- obj = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_OBJECT , self .TC_NULL , self .TC_REFERENCE ])
351- log_debug ("objectAnnotation: " + str (obj ))
352- else :
353- self .object_stream .seek (- 1 , mode = 1 )
354- raise NotImplementedError ("objectAnnotation isn't fully implemented yet" ) # TODO:
345+ while opcode != self .TC_ENDBLOCKDATA :
346+ opcode , obj = self ._read_and_exec_opcode (ident = ident + 1 ) # , expect=[self.TC_ENDBLOCKDATA, self.TC_BLOCKDATA, self.TC_OBJECT, self.TC_NULL, self.TC_REFERENCE])
347+ log_debug ("objectAnnotation value: " + str (obj ))
355348
356349 return java_object
357350
@@ -364,7 +357,7 @@ def do_string(self, parent=None, ident=0):
364357 def do_array (self , parent = None , ident = 0 ):
365358 # TC_ARRAY classDesc newHandle (int)<size> values[size]
366359 log_debug ("[array]" , ident )
367- classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
360+ opcode , classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
368361
369362 array = []
370363
@@ -379,7 +372,7 @@ def do_array(self, parent=None, ident=0):
379372
380373 if type_char == self .TYPE_OBJECT or type_char == self .TYPE_ARRAY :
381374 for i in range (size ):
382- res = self ._read_and_exec_opcode (ident = ident + 1 )
375+ opcode , res = self ._read_and_exec_opcode (ident = ident + 1 )
383376 log_debug ("Object value: %s" % str (res ), ident )
384377 array .append (res )
385378 else :
@@ -401,9 +394,9 @@ def do_null(self, parent=None, ident=0):
401394 def do_enum (self , parent = None , ident = 0 ):
402395 # TC_ENUM classDesc newHandle enumConstantName
403396 enum = JavaObject ()
404- classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
397+ opcode , classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
405398 self ._add_reference (enum )
406- enumConstantName = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
399+ opcode , enumConstantName = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
407400 return enumConstantName
408401
409402 def _create_hexdump (self , src , length = 16 ):
@@ -436,7 +429,7 @@ def _read_value(self, field_type, ident, name = ""):
436429 elif field_type == self .TYPE_DOUBLE :
437430 (res , ) = self ._readStruct (">d" )
438431 elif field_type == self .TYPE_OBJECT or field_type == self .TYPE_ARRAY :
439- res = self ._read_and_exec_opcode (ident = ident + 1 )
432+ opcode , res = self ._read_and_exec_opcode (ident = ident + 1 )
440433 else :
441434 raise RuntimeError ("Unknown typecode: %s" % field_type )
442435 log_debug ("* %s %s: " % (field_type , name ) + str (res ), ident )
0 commit comments