diff --git a/tools/kexttool/kext.py b/tools/kexttool/kext.py index 7603c1f..a7034a9 100644 --- a/tools/kexttool/kext.py +++ b/tools/kexttool/kext.py @@ -1,10 +1,26 @@ import yaml import io import os +import glob class KextSource: __kext_info = {} __src_dir_path = '' + + + def scan(path): + result = [] + scan_arg = os.path.join(path, '**/extension.yaml') + + for filename in glob.iglob(scan_arg, recursive=True): + try: + kext_src = KextSource(filename) + except Exception as e: + continue + + result.append(kext_src) + + return result def __init__(self, info_file): diff --git a/tools/kexttool/scan.py b/tools/kexttool/scan.py new file mode 100644 index 0000000..4fbdcc0 --- /dev/null +++ b/tools/kexttool/scan.py @@ -0,0 +1,32 @@ +import glob +import os +from kexttool import kext + +def list_all(pretty=False): + cwd = os.getcwd() + scan_arg = os.path.join(cwd, 'extensions', '**/extension.yaml') + + nr_extensions = 0 + + # root_dir needs a trailing slash (i.e. /root/dir/) + for filename in glob.iglob(scan_arg, recursive=True): + try: + kext_src = kext.KextSource(filename) + except Exception as e: + print('E: cannot read kernel extension source manifest (reason: {})'.format(e)) + continue + + if pretty: + print('* {}'.format(kext_src.name())) + print(' Bundle ID: {}'.format(kext_src.id())) + print(' License: {}'.format(kext_src.license())) + print(' Copyright: {}'.format(kext_src.copyright())) + print(' Location: {}'.format(kext_src.src_dirpath())) + print(' Sources:') + + for src in kext_src.sources(): + print(' {}'.format(src)) + else: + print('\033[1;96m* \033[0;1m{}\033[0m ({})'.format(kext_src.id(), kext_src.src_dirpath())) + + nr_extensions = nr_extensions + 1 diff --git a/tools/kexttool/select.py b/tools/kexttool/select.py new file mode 100644 index 0000000..04d3b6b --- /dev/null +++ b/tools/kexttool/select.py @@ -0,0 +1,19 @@ +import inquirer +import os +from kexttool import kext + + +def select_kexts(): + all_kexts = [ k.id() for k in kext.KextSource.scan(os.path.join(os.getcwd(), 'extensions')) ] + if len(all_kexts) == 0: + print('No kernel extensions available.') + return + + questions = [ + inquirer.Checkbox('kexts', + message="Select kexts to include in the kernel image", + choices=all_kexts, + ) + ] + answers = inquirer.prompt(questions) + print(answers["kexts"]) diff --git a/tools/socks.kexttool b/tools/socks.kexttool index eb60ded..5f4bd43 100755 --- a/tools/socks.kexttool +++ b/tools/socks.kexttool @@ -3,30 +3,25 @@ # -*- mode: python -*- import glob +import inquirer import os -from kexttool import kext +import sys +from kexttool import kext, scan, select -cwd = os.getcwd() -scan_arg = os.path.join(cwd, 'extensions', '**/extension.yaml') -nr_extensions = 0 +if len(sys.argv) < 2: + print('usage: {} '.format(sys.argv[0])) + exit(0) -# root_dir needs a trailing slash (i.e. /root/dir/) -for filename in glob.iglob(scan_arg, recursive=True): - try: - kext_src = kext.KextSource(filename) - except Exception as e: - print('E: cannot read kernel extension source manifest (reason: {})'.format(e)) - continue +cmd = sys.argv[1] - print('* {}'.format(kext_src.name())) - print(' Bundle ID: {}'.format(kext_src.id())) - print(' License: {}'.format(kext_src.license())) - print(' Copyright: {}'.format(kext_src.copyright())) - print(' Location: {}'.format(kext_src.src_dirpath())) - print(' Sources:') +commands = { + 'select': select.select_kexts, + 'list': scan.list_all +} - for src in kext_src.sources(): - print(' {}'.format(src)) +if cmd not in commands: + print('E: unknown command \'{}\''.format(cmd)) + exit(-1) - nr_extensions = nr_extensions + 1 +commands[cmd]()