# Buggy code
def ios_list_files(src, md5_hash, binary_form, mode):
    """List iOS files"""
    try:
        logger.info("Get Files, BIN Plist -> XML, and Normalize")
        # Multi function, Get Files, BIN Plist -> XML, normalize + to x
        filez = []
        certz = []
        sfiles = []
        database = []
        plist = []
        for dirname, _, files in os.walk(src):
            for jfile in files:
                if not jfile.endswith(".DS_Store"):
                    file_path = os.path.join(src, dirname, jfile)
                    if "+" in jfile:
                        plus2x = os.path.join(src, dirname, jfile.replace("+", "x"))
                        shutil.move(file_path, plus2x)
                        file_path = plus2x
                    fileparam = file_path.replace(src, "")
                    filez.append(fileparam)
                    ext = jfile.split(".")[-1]
                    if re.search("cer|pem|cert|crt|pub|key|pfx|p12", ext):
                        certz.append(
                            {
                                "file_path": escape(file_path.replace(src, "")),
                                "type": None,
                                "hash": None,
                            }
                        )

                    if re.search("db|sqlitedb|sqlite", ext):
                        database.append(
                            {
                                "file_path": escape(fileparam),
                                "type": mode,
                                "hash": md5_hash,
                            }
                        )

                    if jfile.endswith(".plist"):
                        if binary_form:
                            convert_bin_xml(file_path)
                        plist.append(
                            {
                                "file_path": escape(fileparam),
                                "type": mode,
                                "hash": md5_hash,
                            }
                        )

        if len(database) > 0:
            sfiles.append({"issue": "SQLite Files", "files": database})
        if len(plist) > 0:
            sfiles.append({"issue": "Plist Files", "files": plist})
        if len(certz) > 0:
            sfiles.append(
                {
                    "issue": "Certificate/Key Files Hardcoded inside the App.",
                    "files": certz,
                }
            )
        return filez, sfiles
    except:
        PrintException("[ERROR] iOS List Files")


# 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 ios_list_files(src, md5_hash, binary_form, mode):
    """List iOS files"""
    try:
        logger.info("Get Files, BIN Plist -> XML, and Normalize")
        # Multi function, Get Files, BIN Plist -> XML, normalize + to x
        filez = []
        certz = []
        sfiles = []
        database = []
        plist = []
        for dirname, _, files in os.walk(src):
            for jfile in files:
                if not jfile.endswith(".DS_Store"):
                    file_path = os.path.join(src, dirname, jfile)
                    if "+" in jfile:
                        plus2x = os.path.join(src, dirname, jfile.replace("+", "x"))
                        shutil.move(file_path, plus2x)
                        file_path = plus2x
                    fileparam = file_path.replace(src, "")
                    filez.append(fileparam)
                    ext = jfile.split(".")[-1]
                    if re.search("cer|pem|cert|crt|pub|key|pfx|p12", ext):
                        certz.append(
                            {
                                "file_path": escape(file_path.replace(src, "")),
                                "type": None,
                                "hash": None,
                            }
                        )

                    if re.search("db|sqlitedb|sqlite", ext):
                        database.append(
                            {
                                "file_path": escape(fileparam),
                                "type": mode,
                                "hash": md5_hash,
                            }
                        )

                    if jfile.endswith(".plist"):
                        if binary_form:
                            convert_bin_xml(file_path)
                        plist.append(
                            {
                                "file_path": escape(fileparam),
                                "type": mode,
                                "hash": md5_hash,
                            }
                        )

        if len(database) > 0:
            sfiles.append({"issue": "SQLite Files", "files": database})
        if len(plist) > 0:
            sfiles.append({"issue": "Plist Files", "files": plist})
        if len(certz) > 0:
            sfiles.append(
                {
                    "issue": "Certificate/Key Files Hardcoded inside the App.",
                    "files": certz,
                }
            )
        return filez, sfiles
    except:
        PrintException("iOS List Files")