88from .soot_manager import SootManager
99
1010
11- l = logging .getLogger ("pysoot.lifter" )
11+ log = logging .getLogger ("pysoot.lifter" )
1212self_dir = os .path .dirname (os .path .realpath (__file__ ))
1313
1414
15- class Lifter (object ):
16-
17- def __init__ (self , input_file = None , input_format = "jar" , ir_format = "shimple" , additional_jars = None ,
18- additional_jar_roots = None , android_sdk = None , save_to_file = None ):
15+ class Lifter :
16+ def __init__ (
17+ self ,
18+ input_file = None ,
19+ input_format = "jar" ,
20+ ir_format = "shimple" ,
21+ additional_jars = None ,
22+ additional_jar_roots = None ,
23+ android_sdk = None ,
24+ save_to_file = None ,
25+ ):
1926
2027 self .input_file = os .path .realpath (input_file )
2128 self .save_to_file = save_to_file
@@ -31,47 +38,71 @@ def __init__(self, input_file=None, input_format="jar", ir_format="shimple", add
3138
3239 if input_format == "jar" :
3340 if android_sdk is not None :
34- l .warning ("when input_format is 'jar', setting android_sdk is pointless" )
41+ log .warning (
42+ "when input_format is 'jar', setting android_sdk is pointless"
43+ )
3544 absolute_library_jars = {_find_jrt_jar ()}
3645 if additional_jars is not None :
37- absolute_library_jars |= {os .path .realpath (jar ) for jar in additional_jars }
46+ absolute_library_jars |= {
47+ os .path .realpath (jar ) for jar in additional_jars
48+ }
3849 if additional_jar_roots is not None :
3950 for jar_root in additional_jar_roots :
4051 for jar_name in os .listdir (jar_root ):
4152 if jar_name .endswith (".jar" ):
42- absolute_path = os .path .realpath (os .path .join (jar_root , jar_name ))
53+ absolute_path = os .path .realpath (
54+ os .path .join (jar_root , jar_name )
55+ )
4356 if absolute_path not in absolute_library_jars :
4457 absolute_library_jars .add (absolute_path )
4558 seperator = ";" if os .name == "nt" else ":"
4659 bad_jars = [p for p in absolute_library_jars if seperator in p ]
4760 if len (bad_jars ) > 0 :
48- raise ParameterError ("these jars have a semicolon in their name: " + repr (bad_jars ))
61+ raise ParameterError (
62+ "these jars have a semicolon in their name: " + repr (bad_jars )
63+ )
4964 self .soot_classpath = seperator .join (absolute_library_jars )
5065
5166 elif input_format == "apk" :
5267 if android_sdk is None :
53- raise ParameterError ("when format is apk, android_sdk should point to something like: "
54- "~/Android/Sdk/platforms" )
68+ raise ParameterError (
69+ "when format is apk, android_sdk should point to something like: "
70+ "~/Android/Sdk/platforms"
71+ )
5572 if additional_jars is not None or additional_jar_roots is not None :
56- l .warning ("when input_format is 'apk', setting additional_jars or additional_jar_roots is pointless" )
73+ log .warning (
74+ "when input_format is 'apk', setting additional_jars or "
75+ "additional_jar_roots is pointless"
76+ )
5777 self .android_sdk = android_sdk
5878
5979 self ._get_ir ()
6080
6181 def _get_ir (self ):
6282 config = {}
63- settings = ["input_file" , "input_format" , "ir_format" , "android_sdk" , "soot_classpath" , "main_class" ]
83+ settings = [
84+ "input_file" ,
85+ "input_format" ,
86+ "ir_format" ,
87+ "android_sdk" ,
88+ "soot_classpath" ,
89+ "main_class" ,
90+ ]
6491 for s in settings :
6592 config [s ] = str (getattr (self , s , None ))
6693
6794 self .soot_wrapper = SootManager ()
6895
69- l .info ("Running Soot with the following config: " + repr (config ))
96+ log .info ("Running Soot with the following config: " + repr (config ))
7097 self .soot_wrapper .init (** config )
7198 if self .save_to_file is None :
7299 self .classes = self .soot_wrapper .get_classes ()
73100 else :
74- ipc_options = {'return_result' : False , 'return_pickle' : False , 'save_pickle' : self .save_to_file }
101+ ipc_options = {
102+ "return_result" : False ,
103+ "return_pickle" : False ,
104+ "save_pickle" : self .save_to_file ,
105+ }
75106 self .classes = self .soot_wrapper .get_classes (_ipc_options = ipc_options )
76107
77108
@@ -81,13 +112,13 @@ def _get_java_home() -> str:
81112 return os .environ ["JAVA_HOME" ]
82113
83114 # Command to get Java properties
84- command = ["java" , ' -XshowSettings:properties' , ' -version' ]
115+ command = ["java" , " -XshowSettings:properties" , " -version" ]
85116 # Execute the command and capture the output
86117 result = subprocess .run (command , capture_output = True , text = True )
87118 # Extract JAVA_HOME from the output
88119 for line in result .stderr .splitlines ():
89120 if "java.home" in line :
90- return line .split ('=' )[1 ].strip ()
121+ return line .split ("=" )[1 ].strip ()
91122
92123 raise JavaNotFoundError
93124
0 commit comments