Class: SeccompTools::Explain::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/seccomp-tools/explain/renderer.rb

Overview

Renders path-condition facts (Symbolic::Constraints and Qwords) as C-like conditions, naming the seccomp_data fields and parenthesizing exactly where the expression would otherwise be misread.

Constant Summary collapse

PREC =

C-like operator precedence (higher binds tighter), used to parenthesize a rendered condition exactly where it would otherwise be misread - notably that == binds tighter than the bitwise operators, so a & b == c must be shown as (a & b) == c.

{
  :* => 12, :/ => 12, :+ => 11, :- => 11, :<< => 10, :>> => 10,
  :< => 9, :<= => 9, :> => 9, :>= => 9, :== => 8, :!= => 8,
  :& => 7, :^ => 6, :| => 5
}.freeze
UNARY_PREC =

Unary negation binds tighter than any binary operator.

13
COMPARISON =

The comparison operators. When one is the parent, operands are parenthesized by precedence alone (so a & b == c becomes (a & b) == c but a >> b == c stays put), never by the extra readability rule in #clarity_wrap?.

%i[== != < <= > >=].freeze
DATA =

The seccomp_data field layout the rendered names come from.

Const::BPF::SeccompData

Instance Method Summary collapse

Constructor Details

#initialize(fusion) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:

  • fusion (QwordFusion)

    Supplies the endian-correct word offsets of the 64-bit fields, for naming their halves.



32
33
34
# File 'lib/seccomp-tools/explain/renderer.rb', line 32

def initialize(fusion)
  @fusion = fusion
end

Instance Method Details

#conjunction(constraints, sys) ⇒ String

Renders a conjunction of facts, e.g. "fd == 0x1 && (flags & 0xf) < 0x5".

Parameters:

  • constraints (Array<Symbolic::Constraint, Qword>)
  • sys (Symbol?)

    The syscall the facts belong to, if pinned - names the arguments.

Returns:

  • (String)


41
42
43
44
45
46
47
48
49
# File 'lib/seccomp-tools/explain/renderer.rb', line 41

def conjunction(constraints, sys)
  constraints.map do |c|
    if c.is_a?(Qword)
      "#{data_name(@fusion.lo_off(c.base), sys)} #{c.op} 0x#{c.val.to_s(16)}"
    else
      constraint(c, sys)
    end
  end.join(' && ')
end