Class: SeccompTools::Instruction::JMP

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

Overview

Instruction jmp, an unconditional jump or a comparison of A against X or an immediate.

Jumps are always forward, jt and jf being offsets relative to the following line.

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 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)>

See Base#branch.

Unlike the other instructions, a conditional jump has two possible successors. On the taken branch of an equality test the state is narrowed, recording that A is known to equal the compared value.

Examples:

# 0000: if (A == 0) goto 0002 else goto 0003
jeq.branch(state) #=> [[2, narrowed_state], [3, state]]

Parameters:

Returns:

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

    One pair for an unconditional jump, two otherwise.



50
51
52
53
54
55
56
# File 'lib/seccomp-tools/instruction/jmp.rb', line 50

def branch(state)
  return [[at(k), state]] if jop == :none
  return [[at(jt), state]] if jt == jf
  return [[at(jt), narrow(state)], [at(jf), state]] if jop == :==

  [[at(jt), state], [at(jf), state]]
end

#decompileString

Decompile instruction.

Returns:

  • (String)

    The jump as assembly, e.g. "if (A == read) goto 0003".



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/seccomp-tools/instruction/jmp.rb', line 15

def decompile
  return goto(k) if jop == :none
  # if jt == 0 && jf == 0 => no-op # should not happen
  # jt == 0 => if(!) goto jf;
  # jf == 0 => if() goto jt;
  # otherwise => if () goto jt; else goto jf;
  return '/* no-op */' if jt.zero? && jf.zero?
  return goto(jt) if jt == jf
  return if_str(neg: true) + goto(jf) if jt.zero?

  if_str + goto(jt) + (jf.zero? ? '' : " else #{goto(jf)}")
end

#symbolize[:cmp, Symbol, (:x, Integer), Integer, Integer], [:jmp, Integer]

Returns:

  • ([:cmp, Symbol, (:x, Integer), Integer, Integer], [:jmp, Integer])

    [:jmp, offset] for an unconditional jump, otherwise +[:cmp, operator, right operand, jt, jf]+.



32
33
34
35
36
# File 'lib/seccomp-tools/instruction/jmp.rb', line 32

def symbolize
  return [:jmp, k] if jop == :none

  [:cmp, jop, src, jt, jf]
end