diff --git a/pysoot/lifter.py b/pysoot/lifter.py index 2f95fd4..4f179db 100644 --- a/pysoot/lifter.py +++ b/pysoot/lifter.py @@ -1,6 +1,6 @@ - import os import logging +import subprocess from .errors import ParameterError from .soot_manager import SootManager @@ -31,7 +31,8 @@ def __init__(self, input_file=None, input_format="jar", ir_format="shimple", add if android_sdk is not None: l.warning("when input_format is 'jar', setting android_sdk is pointless") library_jars = ["rt.jar", "jce.jar"] - absolute_library_jars = {os.path.realpath(os.path.join(self_dir, "../bin/" + jar)) for jar in library_jars} + java_home = _get_java_home() + absolute_library_jars = {os.path.join(java_home, "lib", jar) for jar in library_jars} if additional_jars is not None: absolute_library_jars |= {os.path.realpath(jar) for jar in additional_jars} if additional_jar_roots is not None: @@ -71,3 +72,18 @@ def _get_ir(self): else: ipc_options = {'return_result': False, 'return_pickle': False, 'save_pickle': self.save_to_file} self.classes = self.soot_wrapper.get_classes(_ipc_options=ipc_options) + + +def _get_java_home() -> str: + # Use $JAVA_HOME if it is set + if "JAVA_HOME" in os.environ: + return os.environ["JAVA_HOME"] + + # Command to get Java properties + command = ["java", '-XshowSettings:properties', '-version'] + # Execute the command and capture the output + result = subprocess.run(command, capture_output=True, text=True) + # Extract JAVA_HOME from the output + for line in result.stderr.splitlines(): + if "java.home" in line: + return line.split('=')[1].strip()