Module: SeccompTools::Disasm
- Defined in:
- lib/seccomp-tools/disasm/disasm.rb
Overview
Disassembler of seccomp BPF.
Class Method Summary collapse
-
.disasm(raw, arch: nil, display_bpf: true, arg_infer: true) ⇒ String
Disassemble BPF codes.
-
.to_bpf(raw, arch) ⇒ Array<BPF>
Convert raw BPF string to array of BPF.
Class Method Details
.disasm(raw, arch: nil, display_bpf: true, arg_infer: true) ⇒ String
Disassemble BPF codes.
Emulates the filter to track what each register holds, so syscall names and argument positions can be inferred and shown as comments.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/seccomp-tools/disasm/disasm.rb', line 33 def disasm(raw, arch: nil, display_bpf: true, arg_infer: true) codes = to_bpf(raw, arch) states = Array.new(codes.size) { Set.new } states[0].add(Symbolic::State.initial) # A forward pass (jumps only go forward) tracking, per line, the states that can reach it, so # syscall names and argument positions can be inferred from what each register holds. Unlike # the Executor, this over-approximates - it forks every conditional instead of folding - so # dead lines are still rendered. dis = codes.zip(states).map do |code, sts| sts.each do |st| code.branch(st) do |pc, s| states[pc].add(s) unless pc >= states.size end end code.states = sts code.disasm(code: display_bpf, arg_infer:) end.join("\n") if display_bpf <<-EOS line CODE JT JF K ================================= #{dis} EOS else "#{dis}\n" end end |