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

Returns a new instance of Disasm.



15
16
17
18
19
# File 'lib/seccomp-tools/cli/disasm.rb', line 15

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

Instance Method Details

#handlevoid

This method returns an undefined value.

Handle options.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/seccomp-tools/cli/disasm.rb', line 51

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)


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

def parser
  @parser ||= OptionParser.new do |opt|
    opt.banner = usage
    opt.on('-o', '--output FILE', 'Output result into 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', 'Output with this flag is a valid input of "seccomp-tools asm".',
           'By default, "seccomp-tools disasm" is in a human-readable format that easy for analysis.',
           'Passing this flag can have the output be simplified to a valid input for "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