2006-04-16 01:56:17 +00:00
|
|
|
module Rex
|
|
|
|
module PeScan
|
|
|
|
module Search
|
|
|
|
|
2008-10-05 02:40:55 +00:00
|
|
|
require "rex/assembly/nasm"
|
|
|
|
|
2006-04-16 01:56:17 +00:00
|
|
|
class DumpRVA
|
|
|
|
attr_accessor :pe
|
|
|
|
|
|
|
|
def initialize(pe)
|
|
|
|
self.pe = pe
|
|
|
|
end
|
|
|
|
|
|
|
|
def config(param)
|
|
|
|
@address = pe.vma_to_rva(param['args'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def scan(param)
|
|
|
|
config(param)
|
|
|
|
|
2006-04-16 04:41:54 +00:00
|
|
|
$stdout.puts "[#{param['file']}]"
|
|
|
|
|
2006-04-16 01:56:17 +00:00
|
|
|
# Adjust based on -A and -B flags
|
|
|
|
pre = param['before'] || 0
|
|
|
|
suf = param['after'] || 16
|
|
|
|
|
|
|
|
@address -= pre
|
|
|
|
@address = 0 if (@address < 0 || ! @address)
|
2008-11-10 21:18:12 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
buf = pe.read_rva(@address, suf)
|
|
|
|
rescue ::Rex::PeParsey::WtfError
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2006-09-02 06:49:06 +00:00
|
|
|
$stdout.puts pe.ptr_s(pe.rva_to_vma(@address)) + " " + buf.unpack("H*")[0]
|
2008-10-05 02:40:55 +00:00
|
|
|
if(param['disasm'])
|
2008-11-10 21:18:12 +00:00
|
|
|
::Rex::Assembly::Nasm.disassemble(buf).split("\n").each do |line|
|
|
|
|
$stdout.puts "\t#{line.strip}"
|
|
|
|
end
|
2008-10-05 02:40:55 +00:00
|
|
|
end
|
|
|
|
|
2006-04-16 01:56:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class DumpOffset < DumpRVA
|
|
|
|
def config(param)
|
|
|
|
begin
|
|
|
|
@address = pe.file_offset_to_rva(param['args'])
|
|
|
|
rescue Rex::PeParsey::BoundsError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-11-10 21:18:12 +00:00
|
|
|
end
|