Class: OneGadget::Fetchers::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::Fetchers::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, extra: []) ⇒ String

Returns The CLI command to be executed.

Parameters:

  • start (Integer) (defaults to: nil)

    The start address to be dumped from.

  • stop (Integer) (defaults to: nil)

    The end address.

  • extra (Array<String>) (defaults to: [])

    Options for this range alone, on top of #extra_options=.

Returns:

  • (String)

    The CLI command to be executed.



46
47
48
49
50
51
52
53
54
# File 'lib/one_gadget/fetchers/objdump.rb', line 46

def command(start: nil, stop: nil, extra: [])
  # --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', *disassemble_options, *@options, *extra, @file]
  cmd.push('--start-address', start) if start
  cmd.push('--stop-address', stop) if stop
  ::Shellwords.join(cmd)
end

#extra_options=(options) ⇒ void

This method returns an undefined value.

Set the extra options to be passed to objdump.

Examples:

objdump.extra_options = %w[-M intel]

Parameters:

  • options (Array<String>)

    The options.



38
39
40
# File 'lib/one_gadget/fetchers/objdump.rb', line 38

def extra_options=(options)
  @options = options
end

#read_raw(machine:, endian:, vma:) ⇒ void

This method returns an undefined value.

Read the file as a raw blob at vma instead of as an ELF, for one whose section headers are gone: objdump disassembles sections, and a file with none disassembles to nothing at all.

Parameters:

  • machine (String)

    The objdump architecture name, as Helper.objdump_arch gives it.

  • endian (Symbol)

    :little or :big.

  • vma (Integer)

    What the first byte of the file is loaded at.



29
30
31
# File 'lib/one_gadget/fetchers/objdump.rb', line 29

def read_raw(machine:, endian:, vma:)
  @raw = { machine:, endian:, vma: }
end