# Buggy code
def get_otool_out(tools_dir, cmd_type, bin_path, bin_dir):
    """Get otool args by OS and type."""
    if len(settings.OTOOL_BINARY) > 0 and is_file_exists(settings.OTOOL_BINARY):
        otool_bin = settings.OTOOL_BINARY
    else:
        otool_bin = "otool"
    if len(settings.JTOOL_BINARY) > 0 and is_file_exists(settings.JTOOL_BINARY):
        jtool_bin = settings.JTOOL_BINARY
    else:
        jtool_bin = os.path.join(tools_dir, "jtool.ELF64")
    jtool2_bin = os.path.join(tools_dir, "jtool2.ELF64")
    # jtool execute permission check
    for toolbin in [jtool_bin, jtool2_bin]:
        if not os.access(toolbin, os.X_OK):
            os.chmod(toolbin, stat.S_IEXEC)
    plat = platform.system()
    if cmd_type == "libs":
        if plat == "Darwin":
            args = [otool_bin, "-L", bin_path]
            args2 = args
        elif plat == "Linux":
            args = [jtool_bin, "-arch", "arm", "-L", "-v", bin_path]
            args2 = [jtool2_bin, "-L", "-v", "-q", bin_path]
        else:
            # Platform Not Supported
            return None
        try:
            libs = subprocess.check_output(args2).decode("utf-8", "ignore")
        except Exception:
            libs = subprocess.check_output(args).decode("utf-8", "ignore")
        libs = smart_text(escape(libs.replace(bin_dir + "/", "")))
        return libs.split("\n")
    elif cmd_type == "header":
        if plat == "Darwin":
            args = [otool_bin, "-hv", bin_path]
            args2 = args
        elif plat == "Linux":
            args = [jtool_bin, "-arch", "arm", "-h", "-v", bin_path]
            args2 = [jtool2_bin, "-h", "-v", "-q", bin_path]
        else:
            # Platform Not Supported
            return None
        try:
            return subprocess.check_output(args2)
        except Exception:
            return subprocess.check_output(args)
    elif cmd_type == "symbols":
        if plat == "Darwin":
            args = [otool_bin, "-Iv", bin_path]
            args2 = args
            return subprocess.check_output(args)
        elif plat == "Linux":
            args = [jtool_bin, "-arch", "arm", "-S", bin_path]
            arg2 = [jtool2_bin, "-S", bin_path]
            try:
                with open(os.devnull, "w") as devnull:
                    return subprocess.check_output(arg2, stderr=devnull)
            except Exception:
                return subprocess.check_output(args)
        else:
            # Platform Not Supported
            return None
    elif cmd_type == "classdump":
        # Handle Classdump in Linux
        # Add timeout to handle ULEB128 malformed
        return [jtool_bin, "-arch", "arm", "-d", "objc", "-v", bin_path]
    return None


# Traceback (FileNotFoundError)
MobSFy Android Instance Traceback (most recent call last): File "C:\Users\Lijoy KFH\Mobile-Security-Framework-MobSF-master\DynamicAnalyzer\views\android\environment.py", line 408, in mobsfy_init self.mobsf_agents_setup('frida') File "C:\Users\Lijoy KFH\Mobile-Security-Framework-MobSF-master\DynamicAnalyzer\views\android\environment.py", line 418, in mobsf_agents_setup self.install_mobsf_ca('install') File "C:\Users\Lijoy KFH\Mobile-Security-Framework-MobSF-master\DynamicAnalyzer\views\android\environment.py", line 140, in install_mobsf_ca pem = open(get_ca_dir(), 'rb').read() FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Lijoy KFH\\.mitmproxy\\mitmproxy-ca-cert.pem' [ERROR] 12/Apr/2020 18:53:11 – Failed to MobSFy the instance [ERROR] 12/Apr/2020 18:53:11 – Internal Server Error: /android_dynamic/"

# Fixed code
def get_otool_out(tools_dir, cmd_type, bin_path, bin_dir):
    """Get otool args by OS and type."""
    if len(settings.OTOOL_BINARY) > 0 and is_file_exists(settings.OTOOL_BINARY):
        otool_bin = settings.OTOOL_BINARY
    else:
        otool_bin = "otool"
    if len(settings.JTOOL_BINARY) > 0 and is_file_exists(settings.JTOOL_BINARY):
        jtool_bin = settings.JTOOL_BINARY
    else:
        jtool_bin = os.path.join(tools_dir, "jtool.ELF64")
    jtool2_bin = os.path.join(tools_dir, "jtool2.ELF64")
    # jtool execute permission check
    for toolbin in [jtool_bin, jtool2_bin]:
        if not os.access(toolbin, os.X_OK):
            os.chmod(toolbin, stat.S_IEXEC)
    plat = platform.system()
    if cmd_type == "libs":
        if plat == "Darwin":
            args = [otool_bin, "-L", bin_path]
            args2 = args
        elif plat == "Linux":
            args = [jtool_bin, "-arch", "arm", "-L", "-v", bin_path]
            args2 = [jtool2_bin, "-L", "-v", "-q", bin_path]
        else:
            # Platform Not Supported
            return None
        try:
            libs = subprocess.check_output(args2).decode("utf-8", "ignore")
        except Exception:
            libs = subprocess.check_output(args).decode("utf-8", "ignore")
        libs = smart_text(escape(libs.replace(bin_dir + "/", "")))
        return libs.split("\n")
    elif cmd_type == "header":
        if plat == "Darwin":
            args = [otool_bin, "-hv", bin_path]
            args2 = args
        elif plat == "Linux":
            args = [jtool_bin, "-arch", "arm", "-h", "-v", bin_path]
            args2 = [jtool2_bin, "-h", "-v", "-q", bin_path]
        else:
            # Platform Not Supported
            return None
        try:
            return subprocess.check_output(args2)
        except Exception:
            return subprocess.check_output(args)
    elif cmd_type == "symbols":
        if plat == "Darwin":
            args = [otool_bin, "-Iv", bin_path]
            return subprocess.check_output(args)
        elif plat == "Linux":
            args = [jtool_bin, "-arch", "arm", "-S", bin_path]
            arg2 = [jtool2_bin, "-S", bin_path]
            try:
                with open(os.devnull, "w") as devnull:
                    return subprocess.check_output(arg2, stderr=devnull)
            except Exception:
                return subprocess.check_output(args)
        else:
            # Platform Not Supported
            return None
    elif cmd_type == "classdump":
        # Handle Classdump in Linux
        # Add timeout to handle ULEB128 malformed
        return [jtool_bin, "-arch", "arm", "-d", "objc", "-v", bin_path]
    return None