@@ -34,6 +34,7 @@ def __init__(self):
3434 self .flags = None
3535 self .fields_names = []
3636 self .fields_types = []
37+ self .superclass = None
3738
3839 def __str__ (self ):
3940 return "[%s:0x%X]" % (self .name , self .serialVersionUID )
@@ -102,7 +103,10 @@ def readObject(self):
102103
103104 the_rest = self .object_stream .read ()
104105 if len (the_rest ):
105- print "Warning!!!!: Stream still has %s bytes left." % str (the_rest )
106+ print "Warning!!!!: Stream still has %s bytes left." % len (the_rest )
107+ print self .hexdump (the_rest )
108+ else :
109+ print "Ok!!!!"
106110
107111 return res
108112
@@ -166,9 +170,14 @@ def do_classdesc(self, parent=None, ident=0):
166170 field_type = "boolean"
167171 elif type == 0x5B : # '[': Array
168172 field_type = self .read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
169- field_type = "array of " + field_type
173+ if field_type is not None :
174+ field_type = "array of " + field_type
175+ else :
176+ field_type = "array of None"
170177 elif type == 0x42 : # 'B': Byte
171178 field_type = "byte"
179+ elif type == 0x46 : # 'F': Float
180+ field_type = "float"
172181 elif type == 0x4C : # 'L': Object
173182 field_type = self .read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_STRING , self .TC_REFERENCE ])
174183 else :
@@ -186,7 +195,8 @@ def do_classdesc(self, parent=None, ident=0):
186195 self .print_ident ("OpCode: 0x%X" % opid , ident )
187196 # superClassDesc
188197 superclassdesc = self .read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_NULL ])
189- print superclassdesc
198+ self .print_ident (str (superclassdesc ), ident )
199+ clazz .superclass = superclassdesc
190200
191201 return clazz
192202
@@ -225,28 +235,79 @@ def do_object(self, parent=None, ident=0):
225235 pass
226236 else :
227237 raise NotImplementedError ("only nowrclass is implemented." )
228- for field_name in classdesc .fields_names :
229- res = self .read_and_exec_opcode (ident = ident + 1 )
238+ # create megalist
239+ tempclass = classdesc
240+ megalist = []
241+ megatypes = []
242+ while tempclass :
243+ print ">>>" , tempclass .fields_names , tempclass
244+ fieldscopy = tempclass .fields_names [:]
245+ fieldscopy .extend (megalist )
246+ megalist = fieldscopy
247+
248+ fieldscopy = tempclass .fields_types [:]
249+ fieldscopy .extend (megatypes )
250+ megatypes = fieldscopy
251+
252+ tempclass = tempclass .superclass
253+
254+ print "Prepared list of values:" , megalist
255+ print "Prepared list of types:" , megatypes
256+
257+ for field_name , field_type in zip (megalist , megatypes ):
258+ if field_type == "boolean" :
259+ (val , ) = self ._readStruct (">B" , 1 )
260+ res = bool (val )
261+ elif field_type == "byte" :
262+ (res , ) = self ._readStruct (">b" , 1 )
263+ elif field_type == "integer" :
264+ (res , ) = self ._readStruct (">i" , 4 )
265+ elif field_type == "long" :
266+ (res , ) = self ._readStruct (">q" , 8 )
267+ elif field_type == "float" :
268+ (res , ) = self ._readStruct (">f" , 4 )
269+ elif field_type == "double" :
270+ (res , ) = self ._readStruct (">d" , 8 )
271+ else :
272+ res = self .read_and_exec_opcode (ident = ident + 1 )
230273 java_object .__setattr__ (field_name , res )
231274 return java_object
232275
276+ # field_type = "double"
277+ # field_type = "long"
278+ # field_type = "array of " + field_type
279+
280+
233281 def do_string (self , parent = None , ident = 0 ):
234282 self .print_ident ("[string]" , ident )
235283 ba = self ._readString ()
236- # (handle, ) = self._readStruct(">B", 1)
237284 return str (ba )
238285
239286 def do_reference (self , parent = None , ident = 0 ):
287+ # TODO: Reference isn't supported yed
240288 (handle , reference ) = self ._readStruct (">HH" , 4 )
289+ print "## Reference:" , handle , reference
290+ # raise NotImplementedError("Reference isn't supported yed.")
241291
242292 def do_null (self , parent = None , ident = 0 ):
243293 return None
244294
245295 def do_default_stuff (self , parent = None , ident = 0 ):
246- raise RuntimeError ("Unknown opcode " )
296+ raise RuntimeError ("Unknown OpCode " )
247297
248298 def print_ident (self , message , ident ):
249299 print " " * ident + str (message )
300+
301+ def hexdump (self , src , length = 16 ):
302+ FILTER = '' .join ([(len (repr (chr (x )))== 3 ) and chr (x ) or '.' for x in range (256 )])
303+ result = []
304+ for i in xrange (0 , len (src ), length ):
305+ s = src [i :i + length ]
306+ hexa = ' ' .join (["%02X" % ord (x ) for x in s ])
307+ printable = s .translate (FILTER )
308+ result .append ("%04X %-*s %s\n " % (i , length * 3 , hexa , printable ))
309+ return '' .join (result )
310+
250311 # =====================================================================================
251312
252313 def dump (self , obj ):
0 commit comments