# Buggy code
def res_analysis(app_dir):
    """Perform the elf analysis."""
    try:
        logger.info("Static Android Resource Analysis Started")
        elf_desc = {
            "html_infected": (
                "Found html files infected by malware.",
                "high",
                "The built environment was probably infected by malware, The html file "
                "used in this APK is infected.",
            ),
        }
        html_an_dic = {}
        for k in list(elf_desc.keys()):
            html_an_dic[k] = []
        resraw = os.path.join(app_dir, "res", "raw")
        assets = os.path.join(app_dir, "assets")
        for resdir in (resraw, assets):
            if os.path.exists(resdir) and os.path.isdir(resdir):
                for pdir, dirl, filel in os.walk(resdir):
                    for filename in filel:
                        if filename.endswith(".htm") or filename.endswith(".html"):
                            try:
                                filepath = os.path.join(pdir, filename)
                                buf = ""
                                with io.open(filepath, mode="rb") as filp:
                                    buf = filp.read()
                                if "svchost.exe" in buf:
                                    html_an_dic["html_infected"].append(
                                        filepath.replace(app_dir, "")
                                    )
                            except Exception as e:
                                pass
        res = []
        for k, filelist in list(html_an_dic.items()):
            if len(filelist):
                descs = elf_desc.get(k)
                res.append(
                    {
                        "title": descs[0],
                        "stat": descs[1],
                        "desc": descs[2],
                        "file": " ".join(filelist),
                    }
                )
        return res

    except:
        PrintException("[ERROR] Performing Resourse Analysis")


# 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 res_analysis(app_dir):
    """Perform the elf analysis."""
    try:
        logger.info("Static Android Resource Analysis Started")
        elf_desc = {
            "html_infected": (
                "Found html files infected by malware.",
                "high",
                "The built environment was probably infected by malware, The html file "
                "used in this APK is infected.",
            ),
        }
        html_an_dic = {}
        for k in list(elf_desc.keys()):
            html_an_dic[k] = []
        resraw = os.path.join(app_dir, "res", "raw")
        assets = os.path.join(app_dir, "assets")
        for resdir in (resraw, assets):
            if os.path.exists(resdir) and os.path.isdir(resdir):
                for pdir, dirl, filel in os.walk(resdir):
                    for filename in filel:
                        if filename.endswith(".htm") or filename.endswith(".html"):
                            try:
                                filepath = os.path.join(pdir, filename)
                                buf = ""
                                with io.open(filepath, mode="rb") as filp:
                                    buf = filp.read()
                                if "svchost.exe" in buf:
                                    html_an_dic["html_infected"].append(
                                        filepath.replace(app_dir, "")
                                    )
                            except Exception as e:
                                pass
        res = []
        for k, filelist in list(html_an_dic.items()):
            if len(filelist):
                descs = elf_desc.get(k)
                res.append(
                    {
                        "title": descs[0],
                        "stat": descs[1],
                        "desc": descs[2],
                        "file": " ".join(filelist),
                    }
                )
        return res

    except:
        PrintException("Performing Resourse Analysis")