# Path: mobsf/MobSF/utils.py
# def python_dict(value):
#     if not value:
#         value = {}
#     if isinstance(value, dict):
#         return value
#     return ast.literal_eval(value)
# 
# def python_list(value):
#     if not value:
#         value = []
#     if isinstance(value, list):
#         return value
#     return ast.literal_eval(value)
# 
# Path: mobsf/StaticAnalyzer/models.py
# class StaticAnalyzerIOS(models.Model):
#     FILE_NAME = models.CharField(max_length=255, default='')
#     APP_NAME = models.CharField(max_length=255, default='')
#     APP_TYPE = models.CharField(max_length=20, default='')
#     SIZE = models.CharField(max_length=50, default='')
#     MD5 = models.CharField(max_length=32, default='', primary_key=True)
#     SHA1 = models.CharField(max_length=40, default='')
#     SHA256 = models.CharField(max_length=64, default='')
#     BUILD = models.TextField(default='')
#     APP_VERSION = models.CharField(max_length=100, default='')
#     SDK_NAME = models.CharField(max_length=50, default='')
#     PLATFORM = models.CharField(max_length=50, default='')
#     MIN_OS_VERSION = models.CharField(max_length=50, default='')
#     BUNDLE_ID = models.TextField(default='')
#     BUNDLE_URL_TYPES = models.TextField(default=[])
#     BUNDLE_SUPPORTED_PLATFORMS = models.CharField(max_length=50, default=[])
#     ICON_FOUND = models.BooleanField(default=False)
#     INFO_PLIST = models.TextField(default='')
#     BINARY_INFO = models.TextField(default={})
#     PERMISSIONS = models.TextField(default={})
#     ATS_ANALYSIS = models.TextField(default=[])
#     BINARY_ANALYSIS = models.TextField(default=[])
#     MACHO_ANALYSIS = models.TextField(default={})
#     IOS_API = models.TextField(default={})
#     CODE_ANALYSIS = models.TextField(default={})
#     FILE_ANALYSIS = models.TextField(default=[])
#     LIBRARIES = models.TextField(default=[])
#     FILES = models.TextField(default=[])
#     URLS = models.TextField(default=[])
#     DOMAINS = models.TextField(default={})
#     EMAILS = models.TextField(default=[])
#     STRINGS = models.TextField(default=[])
#     FIREBASE_URLS = models.TextField(default=[])
#     APPSTORE_DETAILS = models.TextField(default={})
#     SECRETS = models.TextField(default=[])
#     TRACKERS = models.TextField(default={})
# 
# Path: mobsf/StaticAnalyzer/models.py
# class RecentScansDB(models.Model):
#     ANALYZER = models.CharField(max_length=50, default='')
#     SCAN_TYPE = models.CharField(max_length=10, default='')
#     FILE_NAME = models.CharField(max_length=260, default='')
#     APP_NAME = models.CharField(max_length=260, default='')
#     PACKAGE_NAME = models.CharField(max_length=260, default='')
#     VERSION_NAME = models.CharField(max_length=50, default='')
#     MD5 = models.CharField(max_length=32, default='', primary_key=True)
#     TIMESTAMP = models.DateTimeField(default=datetime.now)


import logging
from django.conf import settings
from mobsf.MobSF.utils import python_dict, python_list
from mobsf.StaticAnalyzer.models import StaticAnalyzerIOS
from mobsf.StaticAnalyzer.models import RecentScansDB


def get_context_from_db_entry(db_entry):
    """Return the context for IPA/ZIP from DB."""
    try:
        logger.info('Analysis is already Done. Fetching data from the DB...')
        context = {
            'version': settings.MOBSF_VER,
            'title': 'Static Analysis',
            'file_name': db_entry[0].FILE_NAME,
            'app_name': db_entry[0].APP_NAME,
            'app_type': db_entry[0].APP_TYPE,
            'size': db_entry[0].SIZE,
            'md5': db_entry[0].MD5,
            'sha1': db_entry[0].SHA1,
            'sha256': db_entry[0].SHA256,
            'build': db_entry[0].BUILD,
            'app_version': db_entry[0].APP_VERSION,
            'sdk_name': db_entry[0].SDK_NAME,
            'platform': db_entry[0].PLATFORM,
            'min_os_version': db_entry[0].MIN_OS_VERSION,
            'bundle_id': db_entry[0].BUNDLE_ID,
            'bundle_url_types': python_list(db_entry[0].BUNDLE_URL_TYPES),
            'bundle_supported_platforms':
                python_list(db_entry[0].BUNDLE_SUPPORTED_PLATFORMS),
            'icon_found': db_entry[0].ICON_FOUND,
            'info_plist': db_entry[0].INFO_PLIST,
            'binary_info': python_dict(db_entry[0].BINARY_INFO),
            'permissions': python_dict(db_entry[0].PERMISSIONS),
            'ats_analysis': python_list(db_entry[0].ATS_ANALYSIS),

# Path: mobsf/MobSF/utils.py
# def python_dict(value):
#     if not value:
#         value = {}
#     if isinstance(value, dict):
#         return value
#     return ast.literal_eval(value)
# 
# def python_list(value):
#     if not value:
#         value = []
#     if isinstance(value, list):
#         return value
#     return ast.literal_eval(value)
# 
# Path: mobsf/StaticAnalyzer/models.py
# class StaticAnalyzerIOS(models.Model):
#     FILE_NAME = models.CharField(max_length=255, default='')
#     APP_NAME = models.CharField(max_length=255, default='')
#     APP_TYPE = models.CharField(max_length=20, default='')
#     SIZE = models.CharField(max_length=50, default='')
#     MD5 = models.CharField(max_length=32, default='', primary_key=True)
#     SHA1 = models.CharField(max_length=40, default='')
#     SHA256 = models.CharField(max_length=64, default='')
#     BUILD = models.TextField(default='')
#     APP_VERSION = models.CharField(max_length=100, default='')
#     SDK_NAME = models.CharField(max_length=50, default='')
#     PLATFORM = models.CharField(max_length=50, default='')
#     MIN_OS_VERSION = models.CharField(max_length=50, default='')
#     BUNDLE_ID = models.TextField(default='')
#     BUNDLE_URL_TYPES = models.TextField(default=[])
#     BUNDLE_SUPPORTED_PLATFORMS = models.CharField(max_length=50, default=[])
#     ICON_FOUND = models.BooleanField(default=False)
#     INFO_PLIST = models.TextField(default='')
#     BINARY_INFO = models.TextField(default={})
#     PERMISSIONS = models.TextField(default={})
#     ATS_ANALYSIS = models.TextField(default=[])
#     BINARY_ANALYSIS = models.TextField(default=[])
#     MACHO_ANALYSIS = models.TextField(default={})
#     IOS_API = models.TextField(default={})
#     CODE_ANALYSIS = models.TextField(default={})
#     FILE_ANALYSIS = models.TextField(default=[])
#     LIBRARIES = models.TextField(default=[])
#     FILES = models.TextField(default=[])
#     URLS = models.TextField(default=[])
#     DOMAINS = models.TextField(default={})
#     EMAILS = models.TextField(default=[])
#     STRINGS = models.TextField(default=[])
#     FIREBASE_URLS = models.TextField(default=[])
#     APPSTORE_DETAILS = models.TextField(default={})
#     SECRETS = models.TextField(default=[])
#     TRACKERS = models.TextField(default={})
# 
# Path: mobsf/StaticAnalyzer/models.py
# class RecentScansDB(models.Model):
#     ANALYZER = models.CharField(max_length=50, default='')
#     SCAN_TYPE = models.CharField(max_length=10, default='')
#     FILE_NAME = models.CharField(max_length=260, default='')
#     APP_NAME = models.CharField(max_length=260, default='')
#     PACKAGE_NAME = models.CharField(max_length=260, default='')
#     VERSION_NAME = models.CharField(max_length=50, default='')
#     MD5 = models.CharField(max_length=32, default='', primary_key=True)
#     TIMESTAMP = models.DateTimeField(default=datetime.now)


# Path: mobsf/StaticAnalyzer/views/ios/db_interaction.py
import logging
from django.conf import settings
from mobsf.MobSF.utils import python_dict, python_list
from mobsf.StaticAnalyzer.models import StaticAnalyzerIOS
from mobsf.StaticAnalyzer.models import RecentScansDB



def get_context_from_db_entry(db_entry):
    """Return the context for IPA/ZIP from DB."""
    try:
        logger.info('Analysis is already Done. Fetching data from the DB...')
        context = {
            'version': settings.MOBSF_VER,
            'title': 'Static Analysis',
            'file_name': db_entry[0].FILE_NAME,
            'app_name': db_entry[0].APP_NAME,
            'app_type': db_entry[0].APP_TYPE,
            'size': db_entry[0].SIZE,
            'md5': db_entry[0].MD5,
            'sha1': db_entry[0].SHA1,
            'sha256': db_entry[0].SHA256,
            'build': db_entry[0].BUILD,
            'app_version': db_entry[0].APP_VERSION,
            'sdk_name': db_entry[0].SDK_NAME,
            'platform': db_entry[0].PLATFORM,
            'min_os_version': db_entry[0].MIN_OS_VERSION,
            'bundle_id': db_entry[0].BUNDLE_ID,
            'bundle_url_types': python_list(db_entry[0].BUNDLE_URL_TYPES),
            'bundle_supported_platforms':
                python_list(db_entry[0].BUNDLE_SUPPORTED_PLATFORMS),
            'icon_found': db_entry[0].ICON_FOUND,
            'info_plist': db_entry[0].INFO_PLIST,
            'binary_info': python_dict(db_entry[0].BINARY_INFO),
            'permissions': python_dict(db_entry[0].PERMISSIONS),
            'ats_analysis': python_list(db_entry[0].ATS_ANALYSIS),

            'binary_analysis': python_list(db_entry[0].BINARY_ANALYSIS),