Skip to content

Commit

Permalink
Fix missing gadgets when two gadgets are too close (#122)
Browse files Browse the repository at this point in the history
Close #119
  • Loading branch information
david942j authored Jun 18, 2020
1 parent 96813ff commit fc3daee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/one_gadget/fetchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ def find
# @return [Array<String>]
# Each +String+ returned is multi-lines of assembly code.
def candidates(&block)
cands = `#{objdump_cmd}|egrep '#{call_str}.*<exec[^+]*>$' -B 30`.split('--').map do |cand|
cand.lines.map(&:strip).reject(&:empty?).join("\n")
call_regexp = "#{call_str}.*<exec[^+]*>$"
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?))
Expand Down

0 comments on commit fc3daee

Please sign in to comment.