Class: Rex::RopBuilder::RopBase
- Inherits:
-
Object
- Object
- Rex::RopBuilder::RopBase
- Includes:
- Text::Color
- Defined in:
- lib/rex/rop_builder/rop.rb
Direct Known Subclasses
Instance Method Summary collapse
- #import(file) ⇒ Object
-
#initialize ⇒ RopBase
constructor
A new instance of RopBase.
- #print_error(msg = '') ⇒ Object
- #print_msg(msg, color = true) ⇒ Object
- #print_status(msg = '') ⇒ Object
- #supports_color? ⇒ Boolean
- #to_csv(gadgets = []) ⇒ Object
Constructor Details
#initialize ⇒ RopBase
Returns a new instance of RopBase.
12 13 14 |
# File 'lib/rex/rop_builder/rop.rb', line 12 def initialize() @gadgets = [] end |
Instance Method Details
#import(file) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rex/rop_builder/rop.rb', line 44 def import(file) begin data = File.new(file, 'r').read rescue 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? 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_error(msg = '') ⇒ Object
79 80 81 |
# File 'lib/rex/rop_builder/rop.rb', line 79 def print_error(msg = '') print_msg("%bld%red[-]%clr #{msg}") end |
#print_msg(msg, color = true) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/rex/rop_builder/rop.rb', line 83 def print_msg(msg, color=true) if color msg = substitute_colors(msg) end puts msg end |
#print_status(msg = '') ⇒ Object
90 91 92 |
# File 'lib/rex/rop_builder/rop.rb', line 90 def print_status(msg = '') print_msg("%bld%blu[*]%clr #{msg}") end |
#supports_color? ⇒ Boolean
75 76 77 |
# File 'lib/rex/rop_builder/rop.rb', line 75 def supports_color? true end |
#to_csv(gadgets = []) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rex/rop_builder/rop.rb', line 16 def to_csv(gadgets = []) if gadgets.empty? and @gadgets.nil? or @gadgets.empty? 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::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 |