Skip to content

Commit

Permalink
Fix missing libs by fetching them from JAVA_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Jan 9, 2024
1 parent b07c493 commit 06d458f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pysoot/lifter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import os
import logging
import subprocess

from .errors import ParameterError
from .soot_manager import SootManager
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit 06d458f

Please sign in to comment.