module OneGadget::Fetcher::ClassMethods
Define class methods here.
Public Instance Methods
from_build_id(build_id, remote: true)
click to toggle source
Fetch one-gadget offsets of this build id. @param [String] build_id The targets’ BuildID. @param [Boolean] remote
When local not found, try search in latest version?
@return [Array<OneGadget::Gadget::Gadget>?]
+nil+ is returned if cannot find target id in database.
# File lib/one_gadget/fetcher.rb, line 21 def from_build_id(build_id, remote: true) OneGadget::Helper.verify_build_id!(build_id) OneGadget::Gadget.builds(build_id, remote: remote) end
from_file(file)
click to toggle source
Fetch one-gadget offsets from file. @param [String] file The absolute path of libc file. @return [Array<OneGadget::Gadget::Gadget>]
Array of all found gadgets is returned.
# File lib/one_gadget/fetcher.rb, line 30 def from_file(file) arch = OneGadget::Helper.architecture(file) klass = { aarch64: OneGadget::Fetcher::AArch64, amd64: OneGadget::Fetcher::Amd64, i386: OneGadget::Fetcher::I386 }[arch] raise Error::UnsupportedArchitectureError, arch if klass.nil? trim_gadgets(klass.new(file).find) end
Private Instance Methods
trim_gadgets(gadgets)
click to toggle source
Unique, remove gadgets with harder constraints.
# File lib/one_gadget/fetcher.rb, line 45 def trim_gadgets(gadgets) gadgets = gadgets.uniq(&:constraints).sort_by { |g| g.constraints.size } res = [] gadgets.each_with_index do |g, i| res << g unless i.times.any? do |j| (gadgets[j].constraints - g.constraints).empty? end end res.sort_by(&:offset) end