Class: SeccompTools::Explain::Renderer
- Inherits:
-
Object
- Object
- SeccompTools::Explain::Renderer
- 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, soa & b == cmust 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 == cbecomes(a & b) == cbuta >> b == cstays put), never by the extra readability rule in #clarity_wrap?. %i[== != < <= > >=].freeze
- DATA =
The
seccomp_datafield layout the rendered names come from. Const::BPF::SeccompData
Instance Method Summary collapse
-
#conjunction(constraints, sys) ⇒ String
Renders a conjunction of facts, e.g.
-
#initialize(fusion) ⇒ Renderer
constructor
A new instance of Renderer.
Constructor Details
#initialize(fusion) ⇒ Renderer
Returns a new instance of Renderer.
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".
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 |