# Buggy code
def get_context_from_analysis(
    app_dic, man_data_dic, man_an_dic, code_an_dic, cert_dic, bin_anal, apk_id
) -> dict:
    """Get the context for APK/ZIP from analysis results"""
    try:
        context = {
            "title": "Static Analysis",
            "name": app_dic["app_name"],
            "size": app_dic["size"],
            "md5": app_dic["md5"],
            "sha1": app_dic["sha1"],
            "sha256": app_dic["sha256"],
            "packagename": man_data_dic["packagename"],
            "mainactivity": man_data_dic["mainactivity"],
            "targetsdk": man_data_dic["target_sdk"],
            "maxsdk": man_data_dic["max_sdk"],
            "minsdk": man_data_dic["min_sdk"],
            "androvername": man_data_dic["androvername"],
            "androver": man_data_dic["androver"],
            "manifest": man_an_dic["manifest_anal"],
            "permissions": man_an_dic["permissons"],
            "binary_analysis": bin_anal,
            "files": app_dic["files"],
            "certz": app_dic["certz"],
            "icon_hidden": app_dic["icon_hidden"],
            "icon_found": app_dic["icon_found"],
            "activities": man_data_dic["activities"],
            "receivers": man_data_dic["receivers"],
            "providers": man_data_dic["providers"],
            "services": man_data_dic["services"],
            "libraries": man_data_dic["libraries"],
            "browsable_activities": man_an_dic["browsable_activities"],
            "act_count": man_an_dic["cnt_act"],
            "prov_count": man_an_dic["cnt_pro"],
            "serv_count": man_an_dic["cnt_ser"],
            "bro_count": man_an_dic["cnt_bro"],
            "certinfo": cert_dic["cert_info"],
            "issued": cert_dic["issued"],
            "sha256Digest": cert_dic["sha256Digest"],
            "api": code_an_dic["api"],
            "findings": code_an_dic["findings"],
            "urls": code_an_dic["urls"],
            "domains": code_an_dic["domains"],
            "emails": code_an_dic["emails"],
            "strings": app_dic["strings"],
            "zipped": app_dic["zipped"],
            "mani": app_dic["mani"],
            "e_act": man_an_dic["exported_cnt"]["act"],
            "e_ser": man_an_dic["exported_cnt"]["ser"],
            "e_bro": man_an_dic["exported_cnt"]["bro"],
            "e_cnt": man_an_dic["exported_cnt"]["cnt"],
            "apkid": apk_id,
        }
        return context
    except:
        PrintException("[ERROR] Rendering to Template")


# Traceback (KeyError)
[INFO] 08/Feb/2019 16:17:54 - VM Starting
[INFO] 08/Feb/2019 16:17:55 - "POST /DynamicAnalyzer/ HTTP/1.1" 200 32400
[INFO] 08/Feb/2019 16:17:55 - "GET /static/css/devices.min.css HTTP/1.1" 200 44241
[INFO] 08/Feb/2019 16:17:55 - "GET /download/screen/screen.png HTTP/1.1" 302 0
[DEBUG] 08/Feb/2019 16:17:55 - Exception while resolving variable 'exp' in template 'general/error.html'.
Traceback (most recent call last):
File "/home/userhome/Mobile-Security-Framework-MobSF/venv/lib/python3.6/site-packages/django/template/base.py", line 829, in _resolve_lookup
current = current[bit]
File "/home/userhome/Mobile-Security-Framework-MobSF/venv/lib/python3.6/site-packages/django/template/context.py", line 83, in __getitem__
raise KeyError(key)
KeyError: 'exp'

During handling of the above exception, another exception occurred:

# Fixed code
def get_context_from_analysis(
    app_dic, man_data_dic, man_an_dic, code_an_dic, cert_dic, bin_anal, apk_id
) -> dict:
    """Get the context for APK/ZIP from analysis results"""
    try:
        context = {
            "title": "Static Analysis",
            "name": app_dic["app_name"],
            "size": app_dic["size"],
            "md5": app_dic["md5"],
            "sha1": app_dic["sha1"],
            "sha256": app_dic["sha256"],
            "packagename": man_data_dic["packagename"],
            "mainactivity": man_data_dic["mainactivity"],
            "targetsdk": man_data_dic["target_sdk"],
            "maxsdk": man_data_dic["max_sdk"],
            "minsdk": man_data_dic["min_sdk"],
            "androvername": man_data_dic["androvername"],
            "androver": man_data_dic["androver"],
            "manifest": man_an_dic["manifest_anal"],
            "permissions": man_an_dic["permissons"],
            "binary_analysis": bin_anal,
            "files": app_dic["files"],
            "certz": app_dic["certz"],
            "icon_hidden": app_dic["icon_hidden"],
            "icon_found": app_dic["icon_found"],
            "activities": man_data_dic["activities"],
            "receivers": man_data_dic["receivers"],
            "providers": man_data_dic["providers"],
            "services": man_data_dic["services"],
            "libraries": man_data_dic["libraries"],
            "browsable_activities": man_an_dic["browsable_activities"],
            "act_count": man_an_dic["cnt_act"],
            "prov_count": man_an_dic["cnt_pro"],
            "serv_count": man_an_dic["cnt_ser"],
            "bro_count": man_an_dic["cnt_bro"],
            "certinfo": cert_dic["cert_info"],
            "issued": cert_dic["issued"],
            "sha256Digest": cert_dic["sha256Digest"],
            "api": code_an_dic["api"],
            "findings": code_an_dic["findings"],
            "urls": code_an_dic["urls"],
            "domains": code_an_dic["domains"],
            "emails": code_an_dic["emails"],
            "strings": app_dic["strings"],
            "zipped": app_dic["zipped"],
            "mani": app_dic["mani"],
            "e_act": man_an_dic["exported_cnt"]["act"],
            "e_ser": man_an_dic["exported_cnt"]["ser"],
            "e_bro": man_an_dic["exported_cnt"]["bro"],
            "e_cnt": man_an_dic["exported_cnt"]["cnt"],
            "apkid": apk_id,
        }
        return context
    except:
        PrintException("Rendering to Template")