# Path: mobsf/MobSF/utils.py
# def print_n_send_error_response(request,
#                                 msg,
#                                 api=False,
#                                 exp='Description'):
#     """Print and log errors."""
#     logger.error(msg)
#     if api:
#         api_response = {'error': msg}
#         return api_response
#     else:
#         context = {
#             'title': 'Error',
#             'exp': exp,
#             'doc': msg,
#             'version': settings.MOBSF_VER,
#         }
#         template = 'general/error.html'
#         return render(request, template, context, status=500)
# 
# Path: mobsf/StaticAnalyzer/views/common/shared_func.py
# def find_java_source_folder(base_folder: Path):
#     # Find the correct java/kotlin source folder for APK/source zip
#     # Returns a Tuple of - (SRC_PATH, SRC_TYPE, SRC_SYNTAX)
#     return next(p for p in [(base_folder / 'java_source',
#                              'java', '*.java'),
#                             (base_folder / 'app' / 'src' / 'main' / 'java',
#                              'java', '*.java'),
#                             (base_folder / 'app' / 'src' / 'main' / 'kotlin',
#                              'kotlin', '*.kt'),
#                             (base_folder / 'src',
#                              'java', '*.java')]
#                 if p[0].exists())


import logging
import re
import json
from pathlib import Path
from django.conf import settings
from django.http import JsonResponse
from django.utils.html import escape
from mobsf.MobSF.utils import print_n_send_error_response
from mobsf.StaticAnalyzer.views.common.shared_func import (
    find_java_source_folder,
)
# -*- coding: utf_8 -*-
"""Find in java or smali files."""




logger = logging.getLogger(__name__)


def run(request):
    """Find filename/content in source files (ajax response)."""
    try:
        match = re.match('^[0-9a-f]{32}$', request.POST['md5'])
        if not match:
            raise ValueError('Invalid MD5 hash')
        md5 = request.POST['md5']
        query = request.POST['q']
        code = request.POST['code']
        search_type = request.POST['search_type']
        if search_type not in ['content', 'filename']:

# Path: mobsf/MobSF/utils.py
# def print_n_send_error_response(request,
#                                 msg,
#                                 api=False,
#                                 exp='Description'):
#     """Print and log errors."""
#     logger.error(msg)
#     if api:
#         api_response = {'error': msg}
#         return api_response
#     else:
#         context = {
#             'title': 'Error',
#             'exp': exp,
#             'doc': msg,
#             'version': settings.MOBSF_VER,
#         }
#         template = 'general/error.html'
#         return render(request, template, context, status=500)
# 
# Path: mobsf/StaticAnalyzer/views/common/shared_func.py
# def find_java_source_folder(base_folder: Path):
#     # Find the correct java/kotlin source folder for APK/source zip
#     # Returns a Tuple of - (SRC_PATH, SRC_TYPE, SRC_SYNTAX)
#     return next(p for p in [(base_folder / 'java_source',
#                              'java', '*.java'),
#                             (base_folder / 'app' / 'src' / 'main' / 'java',
#                              'java', '*.java'),
#                             (base_folder / 'app' / 'src' / 'main' / 'kotlin',
#                              'kotlin', '*.kt'),
#                             (base_folder / 'src',
#                              'java', '*.java')]
#                 if p[0].exists())


# Path: mobsf/StaticAnalyzer/views/android/find.py
import logging
import re
import json
from pathlib import Path
from django.conf import settings
from django.http import JsonResponse
from django.utils.html import escape
from mobsf.MobSF.utils import print_n_send_error_response
from mobsf.StaticAnalyzer.views.common.shared_func import (
    find_java_source_folder,
)

# -*- coding: utf_8 -*-
"""Find in java or smali files."""




logger = logging.getLogger(__name__)


def run(request):
    """Find filename/content in source files (ajax response)."""
    try:
        match = re.match('^[0-9a-f]{32}$', request.POST['md5'])
        if not match:
            raise ValueError('Invalid MD5 hash')
        md5 = request.POST['md5']
        query = request.POST['q']
        code = request.POST['code']
        search_type = request.POST['search_type']
        if search_type not in ['content', 'filename']:

            return print_n_send_error_response(request,