@@ -319,6 +319,37 @@ class JavaObjectConstants(object):
319319
320320 BASE_REFERENCE_IDX = 0x7E0000
321321
322+
323+ class OpCodeDebug (object ):
324+ # Type codes
325+ OP_CODE = {getattr (JavaObjectConstants , key ): key
326+ for key in dir (JavaObjectConstants ) if key .startswith ("TC_" )}
327+
328+ TYPE = {getattr (JavaObjectConstants , key ): key
329+ for key in dir (JavaObjectConstants ) if key .startswith ("TYPE_" )}
330+
331+ STREAM_CONSTANT = {getattr (JavaObjectConstants , key ): key
332+ for key in dir (JavaObjectConstants )
333+ if key .startswith ("SC_" )}
334+
335+ @staticmethod
336+ def op_id (op_id ):
337+ return OpCodeDebug .OP_CODE .get (
338+ op_id , "<unknown OP:{0}>" .format (op_id ))
339+
340+ @staticmethod
341+ def type_code (type_id ):
342+ return OpCodeDebug .TYPE .get (
343+ type_id , "<unknown Type:{0}>" .format (type_id ))
344+
345+ @staticmethod
346+ def flags (flags ):
347+ names = sorted (
348+ descr for key , descr in OpCodeDebug .STREAM_CONSTANT .items ()
349+ if key & flags )
350+ return ', ' .join (names )
351+
352+
322353# ------------------------------------------------------------------------------
323354
324355
@@ -420,10 +451,12 @@ def _read_and_exec_opcode(self, ident=0, expect=None):
420451 :raise RuntimeError: Unknown opcode
421452 """
422453 (opid ,) = self ._readStruct (">B" )
423- log_debug ("OpCode: 0x{0:X}" .format (opid ), ident )
454+ log_debug ("OpCode: 0x{0:X} -- {1}"
455+ .format (opid , OpCodeDebug .op_id (opid )), ident )
424456
425457 if expect and opid not in expect :
426- raise IOError ("Unexpected opcode 0x{0:X}" .format (opid ))
458+ raise IOError ("Unexpected opcode 0x{0:X} -- {1}"
459+ .format (opid , OpCodeDebug .op_id (opid )))
427460
428461 try :
429462 handler = self .opmap [opid ]
@@ -497,8 +530,9 @@ def do_classdesc(self, parent=None, ident=0):
497530
498531 self ._add_reference (clazz )
499532
500- log_debug ("Serial: 0x{0:X} / {0:d} - classDescFlags: 0x{1:X}"
501- .format (serialVersionUID , classDescFlags ), ident )
533+ log_debug ("Serial: 0x{0:X} / {0:d} - classDescFlags: 0x{1:X} {2}"
534+ .format (serialVersionUID , classDescFlags ,
535+ OpCodeDebug .flags (classDescFlags )), ident )
502536 (length ,) = self ._readStruct (">H" )
503537 log_debug ("Fields num: 0x{0:X}" .format (length ), ident )
504538
@@ -624,6 +658,9 @@ def do_object(self, parent=None, ident=0):
624658 raise NotImplementedError ("externalContents isn't implemented yet" )
625659
626660 if classdesc .flags & self .SC_SERIALIZABLE :
661+ # TODO: look at ObjectInputStream.readSerialData()
662+ # FIXME: Handle the SC_WRITE_METHOD flag
663+
627664 # create megalist
628665 tempclass = classdesc
629666 megalist = []
0 commit comments