From f8fa4a0a3f907177e89f8028b35182fc4380ff56 Mon Sep 17 00:00:00 2001 From: Ajin Abraham Date: Thu, 28 Nov 2024 16:55:54 -0800 Subject: [PATCH] Handle aapt/aapt2 search in windows --- mobsf/StaticAnalyzer/views/android/aapt.py | 7 +++++-- mobsf/StaticAnalyzer/views/android/app.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mobsf/StaticAnalyzer/views/android/aapt.py b/mobsf/StaticAnalyzer/views/android/aapt.py index b899c85b6..3163a4830 100644 --- a/mobsf/StaticAnalyzer/views/android/aapt.py +++ b/mobsf/StaticAnalyzer/views/android/aapt.py @@ -3,6 +3,7 @@ import re import logging import subprocess +from platform import system from pathlib import Path from django.conf import settings @@ -37,7 +38,8 @@ def __init__(self, apk_path): and Path(settings.AAPT2_BINARY).exists()): self.aapt2_path = settings.AAPT2_BINARY else: - self.aapt2_path = find_aapt('aapt2') + aapt2 = 'aapt2.exe' if system() == 'Windows' else 'aapt2' + self.aapt2_path = find_aapt(aapt2) # Check for custom AAPT path in settings if (getattr(settings, 'AAPT_BINARY', '') @@ -45,7 +47,8 @@ def __init__(self, apk_path): and Path(settings.AAPT_BINARY).exists()): self.aapt_path = settings.AAPT_BINARY else: - self.aapt_path = find_aapt('aapt') + aapt = 'aapt.exe' if system() == 'Windows' else 'aapt' + self.aapt_path = find_aapt(aapt) # Ensure both aapt and aapt2 are found if not (self.aapt2_path and self.aapt_path): diff --git a/mobsf/StaticAnalyzer/views/android/app.py b/mobsf/StaticAnalyzer/views/android/app.py index db9f5fca6..5a2f22eaf 100644 --- a/mobsf/StaticAnalyzer/views/android/app.py +++ b/mobsf/StaticAnalyzer/views/android/app.py @@ -32,6 +32,10 @@ def aapt_parse(app_dict): if not app_dict.get('files'): app_dict['files'] = aapt_obj.get_apk_files() app_dict['apk_strings'] = aapt_obj.get_apk_strings() + except FileNotFoundError: + msg = 'aapt and aapt2 not found, skipping APK feature extraction' + logger.warning(msg) + append_scan_status(checksum, msg) except Exception as exp: msg = 'Failed to extract APK features using aapt/aapt2' logger.warning(msg)