diff --git a/lib/one_gadget/fetchers/base.rb b/lib/one_gadget/fetchers/base.rb index d25872ee..1780ed39 100644 --- a/lib/one_gadget/fetchers/base.rb +++ b/lib/one_gadget/fetchers/base.rb @@ -45,8 +45,17 @@ def find # @return [Array] # Each +String+ returned is multi-lines of assembly code. def candidates(&block) - cands = `#{objdump_cmd}|egrep '#{call_str}.*$' -B 30`.split('--').map do |cand| - cand.lines.map(&:strip).reject(&:empty?).join("\n") + call_regexp = "#{call_str}.*$" + cands = [] + `#{objdump_cmd}|egrep '#{call_regexp}' -B 30`.split('--').each do |cand| + lines = cand.lines.map(&:strip).reject(&:empty?) + # split with call_regexp + loop do + idx = lines.index { |l| l =~ /#{call_regexp}/ } + break if idx.nil? + + cands << lines.shift(idx + 1).join("\n") + end end # remove all jmps cands = slice_prefix(cands, &method(:branch?))