Pulled out image_source
git-svn-id: file:///home/svn/framework3/trunk@5401 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
806946b71a
commit
a3ccb61b91
|
@ -23,6 +23,7 @@ class Msf::Module::Author
|
|||
'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com',
|
||||
'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl',
|
||||
'patrick' => 'patrick' + 0x40.chr + 'aushack.com',
|
||||
'ramon' => 'ramon' + 0x40.chr + 'risesecurity.org',
|
||||
}
|
||||
|
||||
#
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
require 'rex/elfparsey/elfbase'
|
||||
require 'rex/elfparsey/exceptions'
|
||||
require 'rex/elfparsey/image_source'
|
||||
require 'rex/image_source'
|
||||
|
||||
module Rex
|
||||
module ElfParsey
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'rex/elfparsey/image_source/image_source.rb'
|
||||
require 'rex/elfparsey/image_source/memory.rb'
|
||||
require 'rex/elfparsey/image_source/disk.rb'
|
|
@ -1,60 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rex/peparsey/image_source/image_source'
|
||||
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
module ElfParsey
|
||||
module ImageSource
|
||||
class Disk < ImageSource
|
||||
|
||||
attr_accessor :file, :file_offset, :size
|
||||
|
||||
WINDOW_SIZE = 4096
|
||||
WINDOW_OVERLAP = 64
|
||||
|
||||
def initialize(_file, _offset = 0, _len = nil)
|
||||
_len = _file.stat.size if !_len
|
||||
|
||||
self.file = _file
|
||||
self.file_offset = _offset
|
||||
self.size = _len
|
||||
end
|
||||
|
||||
def read(offset, len)
|
||||
if offset < 0 || offset+len > size
|
||||
raise RangeError, "Offset #{offset} outside of image source", caller
|
||||
end
|
||||
|
||||
file.seek(file_offset + offset)
|
||||
file.read(len)
|
||||
end
|
||||
|
||||
def index(search, offset = 0)
|
||||
# do a sliding window search across the disk
|
||||
while offset < size
|
||||
|
||||
# get a full window size if we can, we
|
||||
# don't want to read past our boundaries
|
||||
wsize = size - offset
|
||||
wsize = WINDOW_SIZE if wsize > WINDOW_SIZE
|
||||
|
||||
window = self.read(offset, wsize)
|
||||
res = window.index(search)
|
||||
return res + offset if res
|
||||
offset += WINDOW_SIZE - WINDOW_OVERLAP
|
||||
end
|
||||
end
|
||||
|
||||
def subsource(offset, len)
|
||||
self.class.new(file, file_offset+offset, len)
|
||||
end
|
||||
|
||||
def close
|
||||
file.close
|
||||
end
|
||||
end
|
||||
|
||||
end end end
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
module Rex
|
||||
module ElfParsey
|
||||
module ImageSource
|
||||
class ImageSource
|
||||
|
||||
#
|
||||
# Um, just some abstract class stuff I guess, this is the interface
|
||||
# that any image sources should subscribe to...
|
||||
#
|
||||
|
||||
def subsource(offset, len)
|
||||
raise "do something"
|
||||
end
|
||||
|
||||
def size
|
||||
raise "do something"
|
||||
end
|
||||
|
||||
def file_offset
|
||||
raise "do something"
|
||||
end
|
||||
|
||||
def close
|
||||
raise "do something"
|
||||
end
|
||||
|
||||
def read_asciiz(offset)
|
||||
# FIXME, make me better
|
||||
string = ''
|
||||
loop do
|
||||
char = read(offset, 1)
|
||||
break if char == "\x00"
|
||||
offset += 1
|
||||
string << char
|
||||
end
|
||||
return string
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end end end
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rex/peparsey/image_source/image_source'
|
||||
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
module ElfParsey
|
||||
module ImageSource
|
||||
class Memory < ImageSource
|
||||
|
||||
attr_accessor :rawdata, :size, :file_offset
|
||||
|
||||
def initialize(_rawdata, _file_offset = 0)
|
||||
self.rawdata = _rawdata
|
||||
self.size = _rawdata.length
|
||||
self.file_offset = _file_offset
|
||||
end
|
||||
|
||||
def read(offset, len)
|
||||
rawdata[offset, len]
|
||||
end
|
||||
|
||||
def subsource(offset, len)
|
||||
self.class.new(rawdata[offset, len], offset + file_offset)
|
||||
end
|
||||
|
||||
def close
|
||||
end
|
||||
|
||||
def index(*args)
|
||||
rawdata.index(*args)
|
||||
end
|
||||
end
|
||||
|
||||
end end end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# $Id$
|
||||
|
||||
require 'rex/image_source/image_source.rb'
|
||||
require 'rex/image_source/memory.rb'
|
||||
require 'rex/image_source/disk.rb'
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rex/peparsey/image_source/image_source'
|
||||
# $Id$
|
||||
|
||||
require 'rex/image_source/image_source'
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
module PeParsey
|
||||
module ImageSource
|
||||
class Disk < ImageSource
|
||||
|
||||
|
@ -56,5 +56,5 @@ class Disk < ImageSource
|
|||
end
|
||||
end
|
||||
|
||||
end end end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# $Id$
|
||||
|
||||
module Rex
|
||||
module PeParsey
|
||||
module ImageSource
|
||||
class ImageSource
|
||||
|
||||
|
@ -41,5 +42,5 @@ class ImageSource
|
|||
|
||||
end
|
||||
|
||||
end end end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rex/peparsey/image_source/image_source'
|
||||
# $Id$
|
||||
|
||||
require 'rex/image_source/image_source'
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
module PeParsey
|
||||
module ImageSource
|
||||
class Memory < ImageSource
|
||||
|
||||
|
@ -33,5 +33,5 @@ class Memory < ImageSource
|
|||
end
|
||||
end
|
||||
|
||||
end end end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,4 +1,6 @@
|
|||
#!/usr/bin/ruby
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# $Id$
|
||||
|
||||
module Rex
|
||||
module PeParsey
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'rex/peparsey/image_source/image_source.rb'
|
||||
require 'rex/peparsey/image_source/memory.rb'
|
||||
require 'rex/peparsey/image_source/disk.rb'
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# $Id$
|
||||
|
||||
require 'rex/peparsey/pebase'
|
||||
require 'rex/peparsey/exceptions'
|
||||
|
||||
require 'rex/peparsey/image_source'
|
||||
require 'rex/peparsey/section'
|
||||
|
||||
require 'rex/image_source'
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# $Id$
|
||||
|
||||
require 'rex/peparsey/pebase'
|
||||
require 'rex/peparsey/exceptions'
|
||||
|
||||
require 'rex/peparsey/image_source'
|
||||
require 'rex/peparsey/section'
|
||||
|
||||
require 'rex/image_source'
|
||||
require 'rex/struct2'
|
||||
|
||||
#
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rex/peparsey/exceptions'
|
||||
# $Id$
|
||||
|
||||
require 'rex/peparsey/exceptions'
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# $Id$
|
||||
|
||||
require 'rex/peparsey/pebase'
|
||||
require 'rex/peparsey/exceptions'
|
||||
|
||||
require 'rex/struct2'
|
||||
|
||||
module Rex
|
||||
|
|
Loading…
Reference in New Issue