Class: Rex::RopBuilder::RopBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/ropbuilder/rop.rb

Direct Known Subclasses

RopCollect

Instance Method Summary collapse

Constructor Details

#initializeRopBase

Returns a new instance of RopBase.



11
12
13
14
# File 'lib/rex/ropbuilder/rop.rb', line 11

def initialize()
	@stdio = Rex::Ui::Text::Output::Stdio.new
	@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/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


75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rex/ropbuilder/rop.rb', line 75

def print_msg(msg, color=true)
	if not @stdio
		@stdio = Rex::Ui::Text::Output::Stdio.new
	end

	if color == true
		@stdio.auto_color
	else
	    @stdio.disable_color
	end
	@stdio.print_raw(@stdio.substitute_colors(msg))
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/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