Class: SeccompTools::CLI::Explain

Inherits:
Base
  • Object
show all
Includes:
FilterInput
Defined in:
lib/seccomp-tools/cli/explain.rb

Overview

Handle 'explain' command.

Constant Summary collapse

SUMMARY =

Summary of this command.

'Summarize a seccomp filter as a per-action policy.'
USAGE =

Usage of this command.

"explain - #{SUMMARY}\n\nUsage: seccomp-tools explain [options] [BPF_FILE|EXEC]".freeze

Instance Attribute Summary

Attributes inherited from Base

#argv, #option

Instance Method Summary collapse

Methods included from Dumpable

#dump_seccomp, #dumping_supported?

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SeccompTools::CLI::Base

Instance Method Details

#handlevoid

This method returns an undefined value.

Reads the filter(s) from a BPF file, an executable, or an existing process, then prints the policy of each.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/seccomp-tools/cli/explain.rb', line 35

def handle
  return unless super

  filters = collect_filters
  if filters.size > 1
    Logger.warn("#{filters.size} filters are installed; they stack, so a syscall must pass every one " \
                '(most restrictive wins). Each is explained separately below.')
  end
  filters.each_with_index do |(raw, arch, source), idx|
    label = filters.size > 1 ? "#{source} (filter ##{idx})" : source
    insts = SeccompTools::Disasm.to_bpf(raw, arch).map(&:inst)
    output { SeccompTools::Explain.new(insts, arch:, source: label).summarize.to_s }
  end
end

#parserOptionParser

Define option parser.

Returns:

  • (OptionParser)

    The parser of this command's options.



23
24
25
26
27
28
29
30
# File 'lib/seccomp-tools/cli/explain.rb', line 23

def parser
  @parser ||= OptionParser.new do |opt|
    opt.banner = usage

    option_filter_source(opt, 'explain')
    option_arch(opt, 'With an executable or --pid the architecture is auto-detected instead.')
  end
end