Class: SeccompTools::Instruction::ALU

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

Overview

Instruction alu, performs an arithmetic or bitwise operation on the accumulator register A.

The right operand is either the X register or the immediate k.

Constant Summary collapse

OP_SYM =

Mapping from name to operator.

{
  add: :+,
  sub: :-,
  mul: :*,
  div: :/,
  or: :|,
  and: :&,
  lsh: :<<,
  rsh: :>>,
  # neg: :-, # should not be invoked
  # mod: :%, # the kernel rejects BPF_MOD (see Const::BPF::OP), so it never reaches here
  xor: :^
}.freeze

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 inherited from Base

#initialize, #invalid

Methods included from Const::BPF

action_label

Constructor Details

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

Instance Method Details

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

Parameters:

Returns:

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

    Always the next line, with A marked as no longer tracked.



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

def branch(state)
  [[line + 1, state.with(a: Symbolic::Expr.opaque)]]
end

#decompileString

Decompile instruction.

Returns:

  • (String)

    The operation as assembly, e.g. "A &= 0x7fff".



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

def decompile
  return 'A = -A' if op == :neg

  "A #{op_sym}= #{src_str}"
end

#symbolize[:alu, Symbol, (:x, Integer, nil)]

Returns:

  • ([:alu, Symbol, (:x, Integer, nil)])

    The operator and its right operand, which is :x for the X register, an Integer for an immediate, or nil for the unary neg.



38
39
40
41
42
# File 'lib/seccomp-tools/instruction/alu.rb', line 38

def symbolize
  return [:alu, :neg, nil] if op == :neg

  [:alu, op_sym, src]
end