# Path: mobsf/MobSF/utils.py
# def filename_from_path(path):
#     head, tail = ntpath.split(path)
#     return tail or ntpath.basename(head)
# 
# Path: mobsf/StaticAnalyzer/views/common/shared_func.py
# def url_n_email_extract(dat, relative_path):
#     """Extract URLs and Emails from Source Code."""
#     urls = []
#     emails = []
#     urllist = []
#     url_n_file = []
#     email_n_file = []
#     # URLs Extraction My Custom regex
#     pattern = re.compile(
#         (
#             r'((?:https?://|s?ftps?://|'
#             r'file://|javascript:|data:|www\d{0,3}[.])'
#             r'[\w().=/;,#:@?&~*+!$%\'{}-]+)'
#         ),
#         re.UNICODE)
#     urllist = re.findall(pattern, dat)
#     uflag = 0
#     for url in urllist:
#         if url not in urls:
#             urls.append(url)
#             uflag = 1
#     if uflag == 1:
#         url_n_file.append(
#             {'urls': urls, 'path': escape(relative_path)})
# 
#     # Email Extraction Regex
#     regex = re.compile(r'[\w.-]{1,20}@[\w-]{1,20}\.[\w]{2,10}')
#     eflag = 0
#     for email in regex.findall(dat.lower()):
#         if (email not in emails) and (not email.startswith('//')):
#             emails.append(email)
#             eflag = 1
#     if eflag == 1:
#         email_n_file.append(
#             {'emails': emails, 'path': escape(relative_path)})
#     return urllist, url_n_file, email_n_file


import logging
from pathlib import Path
from django.conf import settings
from mobsf.MobSF.utils import filename_from_path
from mobsf.StaticAnalyzer.views.common.shared_func import (
    url_n_email_extract,
)
from mobsf.StaticAnalyzer.views.sast_engine import (
    niap_scan,
    scan,
)
            {'.java', '.kt'},
            [src],
            skp)
        api_findings = scan(
            api_rules.as_posix(),
            {'.java', '.kt'},
            [src],
            skp)
        # NIAP Scan
        logger.info('Running NIAP Analyzer')
        niap_findings = niap_scan(
            niap_rules.as_posix(),
            {'.java', '.xml'},
            [src],
            manifest_file,
            None)
        # Extract URLs and Emails
        for pfile in Path(src).rglob('*'):
            if (
                (pfile.suffix in ('.java', '.kt')
                    and any(skip_path in pfile.as_posix()
                            for skip_path in skp) is False)
            ):
                content = None
                try:
                    content = pfile.read_text('utf-8', 'ignore')
                    # Certain file path cannot be read in windows
                except Exception:
                    continue
                relative_java_path = pfile.as_posix().replace(src, '')

# Path: mobsf/MobSF/utils.py
# def filename_from_path(path):
#     head, tail = ntpath.split(path)
#     return tail or ntpath.basename(head)
# 
# Path: mobsf/StaticAnalyzer/views/common/shared_func.py
# def url_n_email_extract(dat, relative_path):
#     """Extract URLs and Emails from Source Code."""
#     urls = []
#     emails = []
#     urllist = []
#     url_n_file = []
#     email_n_file = []
#     # URLs Extraction My Custom regex
#     pattern = re.compile(
#         (
#             r'((?:https?://|s?ftps?://|'
#             r'file://|javascript:|data:|www\d{0,3}[.])'
#             r'[\w().=/;,#:@?&~*+!$%\'{}-]+)'
#         ),
#         re.UNICODE)
#     urllist = re.findall(pattern, dat)
#     uflag = 0
#     for url in urllist:
#         if url not in urls:
#             urls.append(url)
#             uflag = 1
#     if uflag == 1:
#         url_n_file.append(
#             {'urls': urls, 'path': escape(relative_path)})
# 
#     # Email Extraction Regex
#     regex = re.compile(r'[\w.-]{1,20}@[\w-]{1,20}\.[\w]{2,10}')
#     eflag = 0
#     for email in regex.findall(dat.lower()):
#         if (email not in emails) and (not email.startswith('//')):
#             emails.append(email)
#             eflag = 1
#     if eflag == 1:
#         email_n_file.append(
#             {'emails': emails, 'path': escape(relative_path)})
#     return urllist, url_n_file, email_n_file


# Path: mobsf/StaticAnalyzer/views/android/code_analysis.py
import logging
from pathlib import Path
from django.conf import settings
from mobsf.MobSF.utils import filename_from_path
from mobsf.StaticAnalyzer.views.common.shared_func import (
    url_n_email_extract,
)
from mobsf.StaticAnalyzer.views.sast_engine import (
    niap_scan,
    scan,
)

            {'.java', '.kt'},
            [src],
            skp)
        api_findings = scan(
            api_rules.as_posix(),
            {'.java', '.kt'},
            [src],
            skp)
        # NIAP Scan
        logger.info('Running NIAP Analyzer')
        niap_findings = niap_scan(
            niap_rules.as_posix(),
            {'.java', '.xml'},
            [src],
            manifest_file,
            None)
        # Extract URLs and Emails
        for pfile in Path(src).rglob('*'):
            if (
                (pfile.suffix in ('.java', '.kt')
                    and any(skip_path in pfile.as_posix()
                            for skip_path in skp) is False)
            ):
                content = None
                try:
                    content = pfile.read_text('utf-8', 'ignore')
                    # Certain file path cannot be read in windows
                except Exception:
                    continue
                relative_java_path = pfile.as_posix().replace(src, '')

                urls, urls_nf, emails_nf = url_n_email_extract(