Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions qark/decompiler/decompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

DECOMPILERS_PATH = os.path.join(LIB_PATH, "decompilers")

APK_TOOL_COMMAND = ("java -Djava.awt.headless=true -jar {apktool_path}/apktool.jar "
"d {path_to_source} --no-src --force -m --output {build_directory}")
DEX2JAR_COMMAND = "{dex2jar_path} {path_to_dex} -o {build_apk}.jar"
APK_TOOL_COMMAND = ("java -Djava.awt.headless=true -jar '{apktool_path}/apktool.jar' "
"d '{path_to_source}' --no-src --force -m --output '{build_directory}'")
DEX2JAR_COMMAND = "'{dex2jar_path}' '{path_to_dex}' -o '{build_apk}.jar'"


def escape_windows_path(path):
Expand Down Expand Up @@ -117,7 +117,7 @@ def _decompiler_function(self, decompiler):
build_directory=self.build_directory))

try:
retcode = subprocess.call(shlex.split(decompiler_command))
retcode = subprocess.call(shlex.split(decompiler_command.decode(encoding="utf-8")))
except Exception:
log.exception("%s failed to finish decompiling, continuing", decompiler.name)
else:
Expand Down Expand Up @@ -152,7 +152,7 @@ def run_apktool(self):
log.debug("Calling APKTool with following command")
log.debug(custom_apktool_command)
try:
subprocess.call(shlex.split(custom_apktool_command))
subprocess.call(shlex.split(custom_apktool_command.decode(encoding="utf-8")))
except Exception:
log.exception("Failed to run APKTool with command: %s", custom_apktool_command)
raise SystemExit("Failed to run APKTool")
Expand Down Expand Up @@ -203,7 +203,7 @@ def _run_dex2jar(self):

log.debug("Running dex2jar with command %s", dex2jar_command)
try:
ret_code = subprocess.call(shlex.split(dex2jar_command))
ret_code = subprocess.call(shlex.split(dex2jar_command.decode(encoding="utf-8")))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure backward compatibility with python2.7 (unfortunately has reach EOL prior to Jan 2021), simply check the type of the dex2jar_command variable using isinstance(dex2jar_command, bytes). If the check fails, simply run subprocess.call(shlex.split(dex2jar_command)) instead.

if ret_code != 0:
log.critical("Error running dex2jar command: %s", dex2jar_command)
raise SystemExit("Error running dex2jar")
Expand Down
6 changes: 3 additions & 3 deletions qark/decompiler/external_decompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
ExternalDecompiler.__init__(self,
name="cfr",
path_to_decompiler=os.path.join(PATH_TO_DECOMPILERS, "cfr_0_124.jar"),
command="java -jar {path_to_decompiler} {jar} --outputdir {build_directory}/cfr")
command="java -jar '{path_to_decompiler}' '{jar}' --outputdir '{build_directory}/cfr'")


class Procyon(ExternalDecompiler):
Expand All @@ -28,7 +28,7 @@ def __init__(self):
name="procyon",
path_to_decompiler=os.path.join(PATH_TO_DECOMPILERS,
"procyon-decompiler-1.0.jar"),
command="java -jar {path_to_decompiler} {jar} -o {build_directory}/procyon")
command="java -jar '{path_to_decompiler}' '{jar}' -o '{build_directory}/procyon'")


class Fernflower(ExternalDecompiler):
Expand All @@ -37,7 +37,7 @@ def __init__(self):
name="fernflower",
path_to_decompiler=os.path.join(PATH_TO_DECOMPILERS,
"fernflower.jar"),
command="java -jar {path_to_decompiler} -ren=1 {jar} {build_directory}/fernflower")
command="java -jar '{path_to_decompiler}' -ren=1 '{jar}' '{build_directory}/fernflower'")


DECOMPILERS = (CFR(), Procyon(), Fernflower())