| 1 |
#compdef ceccomp |
| 2 |
# Zsh completion script for ceccomp |
| 3 |
local -a subcmd options expl arch_compstr output_compstr |
| 4 |
local state |
| 5 |
|
| 6 |
local archs=( |
| 7 |
'x86_64' 'i386' 'x32' 'aarch64' 'arm' 'loongarch64' 'm68k' 'mips' 'mipsel' |
| 8 |
'mips64' 'mipsel64' 'mips64n32' 'mipsel64n32' 'parisc' 'parisc64' 'ppc64' 'ppc64le' |
| 9 |
'ppc' 's390x' 's390' 'riscv64' |
| 10 |
) |
| 11 |
arch_compstr=( |
| 12 |
'(-a --arch)'{-a,--arch}"[Target BPF architecture]:ARCH:($archs)" |
| 13 |
) |
| 14 |
color_compstr=( |
| 15 |
'(-c --color)'{-c,--color}'[When to display in color]:WHEN:(always auto never)' |
| 16 |
) |
| 17 |
output_compstr=( |
| 18 |
'(-o --output)'{-o,--output}'[Print to file to avoid mixing tracee output]:FILE:_files' |
| 19 |
) |
| 20 |
local syscalls=( |
| 21 |
'open' 'read' 'write' 'close' 'mmap' 'mprotect' 'execve' 'execveat' 'pread64' |
| 22 |
'readv' 'writev' 'preadv' 'preadv2' 'openat' 'openat2' 'sendfile64' 'send' |
| 23 |
'sendto' 'sendmsg' 'recv' 'recvfrom' 'recvmsg' 'io_uring_setup' 'io_uring_enter' |
| 24 |
'io_uring_register' 'ptrace' |
| 25 |
) |
| 26 |
|
| 27 |
if (( CURRENT == 2 )) { |
| 28 |
subcmd=( |
| 29 |
'asm:Assemble bpf text to raw bytes' |
| 30 |
'disasm:Disassemble raw bytes to bpf text' |
| 31 |
'trace:Run program or trace pid, extract bpf filter and then print to text' |
| 32 |
'emu:Emulate bpf program with given syscall and bpf text' |
| 33 |
'probe:Trace the program for the first filter and emulate common syscalls' |
| 34 |
'help:Display ceccomp help information' |
| 35 |
'version:Display ceccomp version' |
| 36 |
) |
| 37 |
_describe 'subcmd' subcmd |
| 38 |
return |
| 39 |
} elif (( CURRENT > 2 )) { |
| 40 |
case $words[2] { |
| 41 |
(asm) |
| 42 |
_arguments \ |
| 43 |
$arch_compstr \ |
| 44 |
$color_compstr \ |
| 45 |
'(-f --fmt)'{-f,--fmt}'[Output format of BPF]:FMT:(raw hexline hexfmt)' \ |
| 46 |
'2:BPF:_files' \ |
| 47 |
'*: :' |
| 48 |
;; |
| 49 |
(disasm) |
| 50 |
_arguments \ |
| 51 |
$arch_compstr \ |
| 52 |
$color_compstr \ |
| 53 |
'2:RAW:_files' \ |
| 54 |
'*: :' |
| 55 |
;; |
| 56 |
(trace) |
| 57 |
_arguments -C \ |
| 58 |
$color_compstr \ |
| 59 |
'(-p --pid)'{-p,--pid}'[Attach to which process to extract its filters]:PID:->getpid' \ |
| 60 |
'(-q --quiet)'{-q,--quiet}'[Print warning and error messages only]' \ |
| 61 |
'(-s --seize)'{-s,--seize}'[Follow pid to trace load-filter operation (pid mode)]' \ |
| 62 |
$output_compstr \ |
| 63 |
'*:arguments:_files' |
| 64 |
# complete non-kernel pids like kill |
| 65 |
if [[ $state == 'getpid' ]] { |
| 66 |
local line pids lines |
| 67 |
pids=() |
| 68 |
# extract command output line by line |
| 69 |
lines=("${(@f)$(ps --ppid 2 -p 2 -N -o pid=,tty=,user=,comm=)}") |
| 70 |
for line ($lines) { |
| 71 |
pids+=${line[(w)1]} # extract first word (pid) |
| 72 |
} |
| 73 |
_wanted nonk-pids expl 'non-kernel process ID' \ |
| 74 |
compadd -o nosort -ld lines -a pids |
| 75 |
} |
| 76 |
;; |
| 77 |
(probe) |
| 78 |
_arguments -C \ |
| 79 |
$color_compstr \ |
| 80 |
$output_compstr \ |
| 81 |
'(-q --quiet)'{-q,--quiet}'[Print warning and error messages only]' \ |
| 82 |
'*:arguments:_files' |
| 83 |
;; |
| 84 |
(emu) |
| 85 |
_arguments -C \ |
| 86 |
$arch_compstr \ |
| 87 |
$color_compstr \ |
| 88 |
'(-q --quiet)'{-q,--quiet}'[Print return value only]' \ |
| 89 |
'2:BPF:_files' \ |
| 90 |
':NR:->syscall_nr' \ |
| 91 |
':ARGV0:->argv0' \ |
| 92 |
':ARGV1:->argv1' \ |
| 93 |
':ARGV2:->argv2' \ |
| 94 |
':ARGV3:->argv3' \ |
| 95 |
':ARGV4:->argv4' \ |
| 96 |
':ARGV5:->argv5' \ |
| 97 |
':IP:->ip' \ |
| 98 |
'*: :' |
| 99 |
case $state { |
| 100 |
(syscall_nr) |
| 101 |
_message -r 'Hint: syscall_nr or syscall_name (to name but a few)' |
| 102 |
_values SYSCALL $syscalls |
| 103 |
;; |
| 104 |
(argv0) |
| 105 |
_message -r 'Hint: u64 for argv[0]' |
| 106 |
;; |
| 107 |
(argv1) |
| 108 |
_message -r 'Hint: u64 for argv[1]' |
| 109 |
;; |
| 110 |
(argv2) |
| 111 |
_message -r 'Hint: u64 for argv[2]' |
| 112 |
;; |
| 113 |
(argv3) |
| 114 |
_message -r 'Hint: u64 for argv[3]' |
| 115 |
;; |
| 116 |
(argv4) |
| 117 |
_message -r 'Hint: u64 for argv[4]' |
| 118 |
;; |
| 119 |
(argv5) |
| 120 |
_message -r 'Hint: u64 for argv[5]' |
| 121 |
;; |
| 122 |
(ip) |
| 123 |
_message -r 'Hint: u64 for instruction pointer' |
| 124 |
;; |
| 125 |
} |
| 126 |
;; |
| 127 |
(*) |
| 128 |
# help and version has no completion available |
| 129 |
return |
| 130 |
;; |
| 131 |
} |
| 132 |
} |