Class: SeccompTools::Instruction::Base

Inherits:
Object
  • Object
show all
Includes:
Const::BPF
Defined in:
lib/seccomp-tools/instruction/base.rb

Overview

Base class of instructions.

Subclasses must implement #branch and #symbolize.

Direct Known Subclasses

ALU, JMP, LD, MISC, RET

Constant Summary

Constants included from Const::BPF

Const::BPF::ACTION, Const::BPF::COMMAND, Const::BPF::JMP, Const::BPF::MISCOP, Const::BPF::MODE, Const::BPF::OP, Const::BPF::PR_SET_SECCOMP, Const::BPF::SECCOMP_MODE_FILTER, Const::BPF::SECCOMP_MODE_STRICT, Const::BPF::SECCOMP_RET_ACTION_FULL, Const::BPF::SECCOMP_RET_DATA, Const::BPF::SECCOMP_SET_MODE_FILTER, Const::BPF::SECCOMP_SET_MODE_STRICT, Const::BPF::SIZEOF_SECCOMP_DATA, Const::BPF::SRC

Instance Method Summary collapse

Methods included from Const::BPF

action_label

Constructor Details

#initialize(bpf) ⇒ Base

Instantiate a SeccompTools::Instruction::Base object.

Parameters:



21
22
23
# File 'lib/seccomp-tools/instruction/base.rb', line 21

def initialize(bpf)
  @bpf = bpf
end

Instance Method Details

#branch(_state) ⇒ Array<(Integer, Symbolic::State)>

Returns the possible branches after executing this instruction.

Each branch is the line number to be executed next, paired with the Symbolic::State that reaching that line implies. Non-jump instructions have exactly one branch, the following line.

Examples:

# For ALU, LD, LDX, ST, STX
inst.line #=> 10
inst.branch(state)
#=> [[11, state]]

Parameters:

Returns:

  • (Array<(Integer, Symbolic::State)>)

    Pairs of the next line number and the state at that line.

Raises:

  • (NotImplementedError)

    Always, subclasses must override this method.



49
50
# File 'lib/seccomp-tools/instruction/base.rb', line 49

def branch(_state); raise NotImplementedError
end

#invalid(msg = 'unknown') ⇒ Object

Helper to raise exception with message.

Parameters:

  • msg (String) (defaults to: 'unknown')

    Error message.

Raises:

  • (ArgumentError)


29
30
31
# File 'lib/seccomp-tools/instruction/base.rb', line 29

def invalid(msg = 'unknown')
  raise ArgumentError, "Line #{line} is invalid: #{msg}"
end

#symbolizeArray<Symbol, Integer>

Returns tokens that represent this instruction.

Examples:

ret_a.symbolize #=> [:ret, :a]
ret_k.symbolize #=> [:ret, 0x7fff0000]
jeq.symbolize #=> [:cmp, :==, 0, 0, 1]

Returns:

  • (Array<Symbol, Integer>)

    The instruction as a tuple, the exact shape depends on the instruction class.

Raises:

  • (NotImplementedError)

    Always, subclasses must override this method.



61
62
# File 'lib/seccomp-tools/instruction/base.rb', line 61

def symbolize; raise NotImplementedError
end