class Rex::RopBuilder::RopBase

Public Class Methods

new() click to toggle source
# File lib/rex/ropbuilder/rop.rb, line 11
def initialize()
  @stdio = Rex::Ui::Text::Output::Stdio.new
  @gadgets = []
end

Public Instance Methods

import(file) click to toggle source
# File lib/rex/ropbuilder/rop.rb, line 44
def import(file)
  begin
    data = File.new(file, 'r').read
  rescue
    @stdio.print_error("Error reading #{file}")
    return []
  end

  if data.empty? or data.nil?
    return []
  end

  data.gsub!(/\"/, '')
  data.gsub!("Address,Raw,Disassembly\n", '')

  @gadgets = []

  data.each_line do |line|
    addr, raw, disasm = line.split(',', 3)
    if addr.nil? or raw.nil? or disasm.nil?
      @stdio.print_error("Import file format corrupted")
      return []
    end
    disasm.gsub!(/: /, ":\t")
    disasm.gsub!(' | ', "\n")
    raw = [raw].pack('H*')
    @gadgets << {:file => file, :address => addr, :raw => raw, :disasm => disasm.chomp!}
  end
    @gadgets
end
print_msg(msg, color=true) click to toggle source
to_csv(gadgets = []) click to toggle source
# File lib/rex/ropbuilder/rop.rb, line 16
def to_csv(gadgets = [])
  if gadgets.empty? and @gadgets.nil? or @gadgets.empty?
    @stdio.print_error("No gadgets collected to convert to CSV format.")
    return
  end

  # allow the users to import gadget collections from multiple files
  if @gadgets.empty? or @gadgets.nil?
    @gadgets = gadgets
  end

  table = Rex::Ui::Text::Table.new(
  'Header'    => "#{@file} ROP Gadgets",
  'Indent'    => 1,
  'Columns'   =>
  [
    "Address",
    "Raw",
    "Disassembly",
  ])

  @gadgets.each do |gadget|
    table << [gadget[:address], gadget[:raw].unpack('H*')[0], gadget[:disasm].gsub(/\n/, ' | ')]
  end

  return table.to_csv
end