Class: Rex::PeScan::Search::DumpRVA

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/pescan/search.rb

Direct Known Subclasses

DumpOffset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pe) ⇒ DumpRVA


11
12
13
# File 'lib/rex/pescan/search.rb', line 11

def initialize(pe)
  self.pe = pe
end

Instance Attribute Details

#peObject

Returns the value of attribute pe


9
10
11
# File 'lib/rex/pescan/search.rb', line 9

def pe
  @pe
end

Instance Method Details

#config(param) ⇒ Object


15
16
17
# File 'lib/rex/pescan/search.rb', line 15

def config(param)
  @address = pe.vma_to_rva(param['args'])
end

#scan(param) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rex/pescan/search.rb', line 19

def scan(param)
  config(param)

  $stdout.puts "[#{param['file']}]"

  # Adjust based on -A and -B flags
  pre = param['before'] || 0
  suf = param['after']  || 16

  @address -= pre
  @address = 0 if (@address < 0 || ! @address)

  begin
    buf = pe.read_rva(@address, suf)
  rescue ::Rex::PeParsey::WtfError
    return
  end

  $stdout.puts pe.ptr_s(pe.rva_to_vma(@address)) + " " + buf.unpack("H*")[0]
  if(param['disasm'])
    insns = []
    buf.gsub!("; ", "\n")
    if buf.include?("retn")
      buf.gsub!("retn", "ret")
    end
    d2 = Metasm::Shellcode.disassemble(Metasm::Ia32.new, buf)
    addr = 0
    while ((di = d2.disassemble_instruction(addr)))
      insns << di.instruction
      disasm = "0x%08x\t" % (pe.rva_to_vma(@address) + addr)
      disasm << di.instruction.to_s
      $stdout.puts disasm
      addr = di.next_addr
    end
  end

end