Class: Rex::PeScan::Scanner::PopPopRetScanner

Inherits:
JmpRegScanner show all
Defined in:
lib/rex/pescan/scanner.rb

Instance Attribute Summary

Attributes inherited from Generic

#pe, #regex

Instance Method Summary collapse

Methods inherited from JmpRegScanner

#_build_byte_list, #_parse_ret, #_ret_size

Methods inherited from Generic

#initialize, #scan

Constructor Details

This class inherits a constructor from Rex::PeScan::Scanner::Generic

Instance Method Details

#config(param) ⇒ Object



138
139
140
141
# File 'lib/rex/pescan/scanner.rb', line 138

def config(param)
	pops = _build_byte_list(0x58, (0 .. 7).to_a - [4]) # we don't want pop esp's...
	self.regex = Regexp.new("[#{pops}][#{pops}](\xc3|\xc2..)", nil, 'n')
end

#scan_section(section, param = {}) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rex/pescan/scanner.rb', line 143

def scan_section(section, param={})

	index = 0

	hits  = [ ]

	while index < section.size && (index = section.index(regex, index)) != nil
		rva     = section.offset_to_rva(index)
		message = ''

		pops = section.read(index, 2)
		reg1 = Rex::Arch::X86.reg_name32(pops[0,1].unpack("C*")[0] & 0x7)
		reg2 = Rex::Arch::X86.reg_name32(pops[1,1].unpack("C*")[0] & 0x7)

		message = "pop #{reg1}; pop #{reg2}; "

		retsize = _ret_size(section, index+2)
		message += _parse_ret(section.read(index+2, retsize))

		index += 2 + retsize

		hits << [ rva, message ]
	end

	return hits
end