22import os
33import webbrowser
44import time
5+ import sys
56try :
67 from urllib import pathname2url # Python 2.x
78except :
@@ -27,7 +28,10 @@ def escape(toescape):
2728 # handle extended unicode
2829 toescape = toescape .encode ('ascii' , 'xmlcharrefreplace' )
2930 # still escape the basics
30- return '' .join (escape_table .get (chr (i ), chr (i )) for i in toescape )
31+ if sys .version_info [0 ] == 3 :
32+ return '' .join (escape_table .get (chr (i ), chr (i )) for i in toescape )
33+ else :
34+ return '' .join (escape_table .get (i , i ) for i in toescape )
3135
3236
3337def save_svg (bv , function ):
@@ -47,15 +51,18 @@ def save_svg(bv, function):
4751 result = show_message_box ("Open SVG" , "Would you like to view the exported SVG?" ,
4852 buttons = MessageBoxButtonSet .YesNoButtonSet , icon = MessageBoxIcon .QuestionIcon )
4953 if result == MessageBoxButtonResult .YesButton :
50- url = 'file:{}' .format (pathname2url (outputfile ))
54+ url = 'file:{}' .format (pathname2url (bytes ( outputfile ) ))
5155 webbrowser .open (url )
5256
5357
5458def instruction_data_flow (function , address ):
5559 ''' TODO: Extract data flow information '''
5660 length = function .view .get_instruction_length (address )
5761 func_bytes = function .view .read (address , length )
58- hex = func_bytes .hex ()
62+ if sys .version_info [0 ] == 3 :
63+ hex = func_bytes .hex ()
64+ else :
65+ hex = func_bytes .encode ('hex' )
5966 padded = ' ' .join ([hex [i :i + 2 ] for i in range (0 , len (hex ), 2 )])
6067 return 'Opcode: {bytes}' .format (bytes = padded )
6168
0 commit comments