1010from refinery .lib .java import JvClassFile , JvCode , opc
1111
1212
13+ def _parse_descriptor (descriptor : str ):
14+ def parse_type_list (args : str ):
15+ while args :
16+ suffix = ''
17+ while args .startswith ('[' ):
18+ args = args [1 :]
19+ suffix += '[]'
20+ code , args = args [0 ], args [1 :]
21+ if code == 'L' :
22+ spec , _ , args = args .partition (';' )
23+ spec = spec .replace ('/' , '.' )
24+ else :
25+ spec = {
26+ 'Z' : 'boolean' ,
27+ 'B' : 'byte' ,
28+ 'S' : 'short' ,
29+ 'I' : 'int' ,
30+ 'J' : 'long' ,
31+ 'F' : 'float' ,
32+ 'D' : 'double' ,
33+ 'C' : 'char' ,
34+ 'V' : 'void' ,
35+ }[code ]
36+ yield spec + suffix
37+
38+ args , retval = re .match (R'^\((.*?)\)(.*?)$' , descriptor ).groups ()
39+ retval , = parse_type_list (retval )
40+ return retval , tuple (parse_type_list (args ))
41+
42+
1343class jvdasm (PathExtractorUnit ):
1444 """
1545 Disassembles the JVM bytecode instructions of methods of classes defined in Java class
@@ -33,8 +63,9 @@ def unpack(self, data):
3363 continue
3464 code : JvCode = attribute .parse (JvCode )
3565 with io .StringIO () as display :
36- args , retval = re .match (R'^\((.*?)\)(.*?)$' , method .descriptor ).groups ()
37- print (F'{ jc .this !s} ::{ method !s} { method .descriptor } ' , file = display )
66+ rv , args = _parse_descriptor (method .descriptor )
67+ args = ', ' .join (args )
68+ print (F'{ rv } { jc .this !s} ::{ method !s} ({ args } )' , file = display )
3869 for op in code .disassembly :
3970 olen = len (op .raw )
4071 if op .table is None :
0 commit comments