2006-04-15 20:26:41 +00:00
|
|
|
#!/usr/bin/env ruby
|
2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2006-04-15 20:26:41 +00:00
|
|
|
|
2008-02-13 02:43:56 +00:00
|
|
|
require 'rex/image_source'
|
2006-04-15 20:26:41 +00:00
|
|
|
require 'rex/peparsey/exceptions'
|
2008-02-13 02:43:56 +00:00
|
|
|
require 'rex/peparsey/pebase'
|
2006-04-15 20:26:41 +00:00
|
|
|
require 'rex/peparsey/section'
|
|
|
|
require 'rex/struct2'
|
|
|
|
|
|
|
|
#
|
|
|
|
# This class is for use with memdump.exe generated dump images. It basically
|
|
|
|
# just lies, gets the ImageBase from the file name, and generates 1 big
|
|
|
|
# header_section with all of the data in it...
|
|
|
|
#
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module PeParsey
|
2008-11-10 21:18:12 +00:00
|
|
|
class PeMemDump < Pe
|
2006-04-15 20:26:41 +00:00
|
|
|
|
|
|
|
def self.new_from_string(data)
|
|
|
|
raise NotImplementError
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.new_from_file(filename, disk_backed = false)
|
2013-03-08 00:16:57 +00:00
|
|
|
|
2006-04-15 20:26:41 +00:00
|
|
|
if filename[-4, 4] != '.rng'
|
2007-03-27 01:56:19 +00:00
|
|
|
raise "Not a .rng file: #{filename}"
|
2006-04-15 20:26:41 +00:00
|
|
|
end
|
2013-03-08 00:16:57 +00:00
|
|
|
|
2008-11-10 21:18:12 +00:00
|
|
|
if filename[-9, 9] == "index.rng"
|
|
|
|
raise SkipError
|
|
|
|
end
|
2006-04-15 20:26:41 +00:00
|
|
|
|
2007-04-03 02:42:30 +00:00
|
|
|
file = File.open(filename, 'rb')
|
2006-04-15 20:26:41 +00:00
|
|
|
|
|
|
|
if disk_backed
|
|
|
|
obj = ImageSource::Disk.new(file)
|
|
|
|
else
|
|
|
|
obj = ImageSource::Memory.new(file.read)
|
|
|
|
obj.close
|
|
|
|
end
|
|
|
|
|
2008-11-10 21:18:12 +00:00
|
|
|
return self.new(obj, filename.gsub(/.*[\/\\]/, '')[0,8].hex)
|
2006-04-15 20:26:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(isource, base)
|
|
|
|
self._isource = isource
|
2007-03-27 01:56:19 +00:00
|
|
|
self.header_section = Section.new(isource, base, nil)
|
2008-11-10 21:18:12 +00:00
|
|
|
self.sections = [ self.header_section ]
|
|
|
|
self.image_base = 0
|
|
|
|
end
|
2013-03-08 00:16:57 +00:00
|
|
|
|
2008-11-10 21:18:12 +00:00
|
|
|
def all_sections
|
|
|
|
self.sections
|
2006-04-15 20:26:41 +00:00
|
|
|
end
|
|
|
|
|
2008-11-10 21:18:12 +00:00
|
|
|
# No 64-bit support
|
|
|
|
def ptr_64?
|
|
|
|
false
|
|
|
|
end
|
2006-04-15 20:26:41 +00:00
|
|
|
|
2008-11-10 21:18:12 +00:00
|
|
|
end end end
|