Class: SeccompTools::CLI::Disasm

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

Overview

Handle 'disasm' command.

Constant Summary collapse

SUMMARY =

Summary of this command.

'Disassemble seccomp bpf.'
USAGE =

Usage of this command.

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

Instance Attribute Summary

Attributes inherited from Base

#argv, #option

Instance Method Summary collapse

Constructor Details

#initializeDisasm

Instantiate a SeccompTools::CLI::Disasm object, showing raw BPF and inferred arguments by default.

Takes the same arguments as Base#initialize.



18
19
20
21
22
# File 'lib/seccomp-tools/cli/disasm.rb', line 18

def initialize(*)
  super
  option[:bpf] = true
  option[:arg_infer] = true
end

Instance Method Details

#handlevoid

This method returns an undefined value.

Disassembles the input file and writes the result.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/seccomp-tools/cli/disasm.rb', line 55

def handle
  return unless super

  option[:ifile] = argv.shift
  return CLI.show(parser.help) if option[:ifile].nil?

  output do
    SeccompTools::Disasm.disasm(input, arch: option[:arch], display_bpf: option[:bpf],
                                       arg_infer: option[:arg_infer])
  end
end

#parserOptionParser

Define option parser.

Returns:

  • (OptionParser)

    The parser of this command's options.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/seccomp-tools/cli/disasm.rb', line 27

def parser
  @parser ||= OptionParser.new do |opt|
    opt.banner = usage
    opt.on('-o', '--output FILE', 'Write output to FILE instead of stdout.') do |o|
      option[:ofile] = o
    end
    option_arch(opt)
    opt.on('--[no-]bpf', 'Display BPF bytes (code, jt, etc.).',
           'Default: true') do |f|
             option[:bpf] = f
           end
    opt.on('--[no-]arg-infer', 'Display syscall arguments with parameter names when possible.',
           'Default: true') do |f|
             option[:arg_infer] = f
           end
    opt.on('--asm-able', 'Make the output valid input for "seccomp-tools asm".',
           'By default, "seccomp-tools disasm" outputs a human-readable format meant for analysis.',
           'With this flag the output is simplified so it can be fed back to "seccomp-tools asm".',
           'This flag implies "--no-bpf --no-arg-infer".',
           'Default: false') do |_f|
             option[:bpf] = false
             option[:arg_infer] = false
           end
  end
end