Module: OneGadget::Fetcher::ClassMethods

Included in:
OneGadget::Fetcher
Defined in:
lib/one_gadget/fetcher.rb

Overview

Define class methods here.

Instance Method Summary collapse

Instance Method Details

#from_build_id(build_id, remote: true) ⇒ Array<OneGadget::Gadget::Gadget>?

Fetch one-gadget offsets of this build id.

Parameters:

  • The targets’ BuildID.

  • (defaults to: true)

    When local not found, try search in latest version?

Returns:

  • nil is returned if cannot find target id in database.



21
22
23
24
# 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) ⇒ Array<OneGadget::Gadget::Gadget>

Fetch one-gadget offsets from file.

Raises:

Parameters:

  • The absolute path of libc file.

Returns:

  • Array of all found gadgets is returned.



30
31
32
33
34
35
36
37
38
39
40
# 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