Class: SeccompTools::Instruction::LD

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

Overview

Instruction ld, loads a value into the accumulator register A.

The value can be an immediate, a word of struct seccomp_data, or a slot of the scratch memory. LDX inherits from this class and targets the X register instead.

Direct Known Subclasses

LDX, ST

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

Parameters:

Returns:

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

    Always the next line, with the loaded value recorded in the register.



47
48
49
50
51
52
53
54
55
# File 'lib/seccomp-tools/instruction/ld.rb', line 47

def branch(state)
  v = load_val
  val = case v[:rel]
        when :immi then Symbolic::Expr.imm(v[:val])
        when :mem then state.mem[v[:val]]
        when :data then Symbolic::Expr.data(v[:val])
        end
  [[line + 1, reg == 'X' ? state.with(x: val) : state.with(a: val)]]
end

#decompileString

Decompile instruction.

Returns:

  • (String)

    The assignment as assembly, e.g. "A = sys_number".



17
18
19
20
21
22
23
24
# File 'lib/seccomp-tools/instruction/ld.rb', line 17

def decompile
  ret = "#{reg} = "
  _, _reg, type = symbolize
  return ret + type[:val].to_s if type[:rel] == :immi
  return ret + "mem[#{type[:val]}]" if type[:rel] == :mem

  ret + seccomp_data_str
end

#regString

Name of the register being loaded into.

Returns:

  • (String)

    The accumulator register, "A".



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

def reg
  'A'
end

#symbolize[:ld, Symbol, {rel: Symbol, val: Integer}]

Returns:

  • ([:ld, Symbol, {rel: Symbol, val: Integer}])

    The target register and the value being loaded, whose :rel is one of :immi, :mem or :data.



30
31
32
33
# File 'lib/seccomp-tools/instruction/ld.rb', line 30

def symbolize
  type = load_val
  [:ld, reg.downcase.to_sym, type]
end