@@ -44,7 +44,6 @@ def handle
4444 return CLI . show ( parser . help ) if option [ :ifile ] . nil?
4545 raw = input
4646 insts = SeccompTools ::Disasm . to_bpf ( raw , option [ :arch ] ) . map ( &:inst )
47- disasm = SeccompTools ::Disasm . disasm ( raw , arch : option [ :arch ] )
4847 sys , *args = argv
4948 sys = Integer ( sys ) if sys
5049 args . map! { |v | Integer ( v ) }
@@ -54,26 +53,36 @@ def handle
5453 end
5554
5655 if option [ :verbose ] >= 1
57- disasm = disasm . lines
58- output { disasm . shift }
59- output { disasm . shift }
60- disasm . each_with_index do |line , idx |
61- output do
62- next line if trace . member? ( idx )
63- Util . colorize ( line , t : :gray )
64- end
65- # Too much remain, omit them.
66- rem = disasm . size - idx - 1
67- break output { Util . colorize ( "... (omitting #{ rem } lines)\n " , t : :gray ) } if rem > 3 && idx > res [ :pc ] + 4
68- end
69- output { "\n " }
56+ disasm = SeccompTools ::Disasm . disasm ( raw , arch : option [ :arch ] ) . lines
57+ output_emulate_path ( disasm , trace , res )
7058 end
7159 output do
7260 ret_type = Const ::BPF ::ACTION . invert [ res [ :ret ] & 0x7fff0000 ]
7361 errno = ret_type == :ERRNO ? "(#{ res [ :ret ] & 0xffff } )" : ''
7462 format ( "return %s%s at line %04d\n " , ret_type , errno , res [ :pc ] )
7563 end
7664 end
65+
66+ private
67+
68+ # output the path during emulation
69+ # @param [Array<String>] disasm
70+ # @param [Set] trace
71+ # @param [{Symbol => Object}] result
72+ def output_emulate_path ( disasm , trace , result )
73+ output { disasm . shift }
74+ output { disasm . shift }
75+ disasm . each_with_index do |line , idx |
76+ output do
77+ next line if trace . member? ( idx )
78+ Util . colorize ( line , t : :gray )
79+ end
80+ # Too much remain, omit them.
81+ rem = disasm . size - idx - 1
82+ break output { Util . colorize ( "... (omitting #{ rem } lines)\n " , t : :gray ) } if rem > 3 && idx > result [ :pc ] + 4
83+ end
84+ output { "\n " }
85+ end
7786 end
7887 end
7988end
0 commit comments