Class: OneGadget::Fetcher::Objdump

Inherits:
Object
  • Object
show all
Defined in:
lib/one_gadget/fetchers/objdump.rb

Overview

Utilities for fetching instructions from libc using objdump.

Instance Method Summary collapse

Constructor Details

#initialize(file, arch) ⇒ Objdump

Instantiate an OneGadget::Fetcher::Objdump object.

Parameters:

  • file (String)

    Absolute path of target libc.

  • arch (Symbol)

    The architecture that objdump should support, usually same as the architecture of the target file.



16
17
18
19
20
# File 'lib/one_gadget/fetchers/objdump.rb', line 16

def initialize(file, arch)
  @file = file
  @arch = arch
  @options = []
end

Instance Method Details

#command(start: nil, stop: nil) ⇒ String

Returns The CLI command to be executed.

Parameters:

  • start (Integer) (defaults to: nil)

    The start address to be dumpped from.

  • stop (Integer) (defaults to: nil)

    The end address.

Returns:

  • (String)

    The CLI command to be executed.



33
34
35
36
37
38
39
40
41
# File 'lib/one_gadget/fetchers/objdump.rb', line 33

def command(start: nil, stop: nil)
  # --dwarf-start=0 is to make sure `suppress_bfd_header` is true to eliminate the file path in the output, see
  # issue #204 for more details.
  # Note: We might need to update this when the objdump act differently in the future.
  cmd = [bin, '--dwarf-start=0', '--no-show-raw-insn', '-w', '-d', *@options, @file]
  cmd.push('--start-address', start) if start
  cmd.push('--stop-address', stop) if stop
  ::Shellwords.join(cmd)
end

#extra_options=(options) ⇒ Object

Set the extra options to be passed to objdump.

Examples:

objdump.extra_options = %w[-M intel]

Parameters:

  • options (Array<String>)

    The options.



26
27
28
# File 'lib/one_gadget/fetchers/objdump.rb', line 26

def extra_options=(options)
  @options = options
end