From abb47659a19ac772765934f184c65fe16cb3bee7 Mon Sep 17 00:00:00 2001 From: Ajin Abraham Date: Sat, 16 Sep 2023 23:18:15 -0700 Subject: [PATCH] [HOTFIX] Fix jadx and apktool failure due to JDK changes (#2269) * Fix jadx and apktool failure due to JDK zip64 changes --- mobsf/DynamicAnalyzer/tools/apk_patcher.py | 2 + mobsf/StaticAnalyzer/tools/jadx/bin/jadx | 2 +- mobsf/StaticAnalyzer/tools/jadx/bin/jadx.bat | 2 +- .../views/android/manifest_utils.py | 1 + .../StaticAnalyzer/views/android/win_fixes.py | 53 ------------------- tox.ini | 1 - 6 files changed, 5 insertions(+), 56 deletions(-) delete mode 100755 mobsf/StaticAnalyzer/views/android/win_fixes.py diff --git a/mobsf/DynamicAnalyzer/tools/apk_patcher.py b/mobsf/DynamicAnalyzer/tools/apk_patcher.py index feff9b5938..64dbf0b275 100644 --- a/mobsf/DynamicAnalyzer/tools/apk_patcher.py +++ b/mobsf/DynamicAnalyzer/tools/apk_patcher.py @@ -37,6 +37,7 @@ def __init__(self, app_dir, tools_dir, apk_file) -> None: def decompile_apk(self): """Decompile APK.""" args = [find_java_binary(), + '-Djdk.util.zip.disableZip64ExtraFieldValidation=true', '-jar', self.apktool_path, '--frame-path', @@ -53,6 +54,7 @@ def decompile_apk(self): def recompile_apk(self): """Recompile APK.""" args = [find_java_binary(), + '-Djdk.util.zip.disableZip64ExtraFieldValidation=true', '-jar', self.apktool_path, '-f', 'b', diff --git a/mobsf/StaticAnalyzer/tools/jadx/bin/jadx b/mobsf/StaticAnalyzer/tools/jadx/bin/jadx index ba4d10f84b..2bd64af4a6 100755 --- a/mobsf/StaticAnalyzer/tools/jadx/bin/jadx +++ b/mobsf/StaticAnalyzer/tools/jadx/bin/jadx @@ -86,7 +86,7 @@ APP_NAME="jadx" APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and JADX_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xms128M" "-XX:MaxRAMPercentage=70.0" "-XX:+UseG1GC"' +DEFAULT_JVM_OPTS='"-Djdk.util.zip.disableZip64ExtraFieldValidation=true" "-Xms128M" "-XX:MaxRAMPercentage=70.0" "-XX:+UseG1GC"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/mobsf/StaticAnalyzer/tools/jadx/bin/jadx.bat b/mobsf/StaticAnalyzer/tools/jadx/bin/jadx.bat index 850f8f5e3a..7cb681d019 100755 --- a/mobsf/StaticAnalyzer/tools/jadx/bin/jadx.bat +++ b/mobsf/StaticAnalyzer/tools/jadx/bin/jadx.bat @@ -33,7 +33,7 @@ set APP_HOME=%DIRNAME%.. for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi @rem Add default JVM options here. You can also use JAVA_OPTS and JADX_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xms128M" "-XX:MaxRAMPercentage=70.0" "-XX:+UseG1GC" +set DEFAULT_JVM_OPTS="-Djdk.util.zip.disableZip64ExtraFieldValidation=true" "-Xms128M" "-XX:MaxRAMPercentage=70.0" "-XX:+UseG1GC" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/mobsf/StaticAnalyzer/views/android/manifest_utils.py b/mobsf/StaticAnalyzer/views/android/manifest_utils.py index a843ea03aa..33ffc5559d 100644 --- a/mobsf/StaticAnalyzer/views/android/manifest_utils.py +++ b/mobsf/StaticAnalyzer/views/android/manifest_utils.py @@ -68,6 +68,7 @@ def get_manifest_apk(app_path, app_dir, tools_dir): output_dir = os.path.join(app_dir, 'apktool_out') args = [find_java_binary(), '-jar', + '-Djdk.util.zip.disableZip64ExtraFieldValidation=true', apktool_path, '--match-original', '--frame-path', diff --git a/mobsf/StaticAnalyzer/views/android/win_fixes.py b/mobsf/StaticAnalyzer/views/android/win_fixes.py deleted file mode 100755 index 729f85d9db..0000000000 --- a/mobsf/StaticAnalyzer/views/android/win_fixes.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf_8 -*- -"""Holds the different winfixes.""" - -import logging -import os - -from django.conf import settings - -from mobsf.MobSF.utils import find_java_binary - -logger = logging.getLogger(__name__) - - -def win_fix_java(tools_dir): - """Run JAVA path fix in Windows.""" - try: - logger.info('Running JAVA path fix in Windows') - dmy = os.path.join(tools_dir, 'd2j2/d2j_invoke.tmp') - org = os.path.join(tools_dir, 'd2j2/d2j_invoke.bat') - dat = '' - with open(dmy, 'r') as file_pointer: - dat = file_pointer.read().replace( - '[xxx]', find_java_binary()) - with open(org, 'w') as file_pointer: - file_pointer.write(dat) - except Exception: - logger.exception('Running JAVA path fix in Windows') - - -def win_fix_python3(tools_dir): - """Run Python 3 path fix in Windows.""" - try: - logger.info('Running Python 3 path fix in Windows') - python3_path = '' - if len(settings.PYTHON3_PATH) > 2: - python3_path = settings.python3_path - else: - pathenv = os.environ['path'] - if pathenv: - paths = pathenv.split(';') - for path in paths: - if 'python3' in path.lower(): - python3_path = path - python3 = '"' + os.path.join(python3_path, 'python') + '"' - dmy = os.path.join(tools_dir, 'enjarify/enjarify.tmp') - org = os.path.join(tools_dir, 'enjarify/enjarify.bat') - dat = '' - with open(dmy, 'r') as file_pointer: - dat = file_pointer.read().replace('[xxx]', python3) - with open(org, 'w') as file_pointer: - file_pointer.write(dat) - except Exception: - logger.exception('Running Python 3 path fix in Windows') diff --git a/tox.ini b/tox.ini index 4d3189c08b..f07dc92e4a 100644 --- a/tox.ini +++ b/tox.ini @@ -71,7 +71,6 @@ exclude = build mobsf/DynamicAnalyzer/tools/adb/ mobsf/StaticAnalyzer/migrations/ - mobsf/StaticAnalyzer/tools/enjarify/ ignore = D100, D101,