class Rex::PeParsey::Section

Attributes

_isource[RW]
_section_header[RW]
base_rva[RW]

Public Class Methods

new(isource, base_rva, section_header = nil) click to toggle source

Initialize a section.

isource        - The ImageSource class backing the image
base_vma       - The address of this section base
section_header - The section header (struct2) although this is not
  required, which is why there is a base_vma.  This can be nil.
# File lib/rex/peparsey/section.rb, line 20
def initialize(isource, base_rva, section_header = nil)
  self._isource        = isource
  self.base_rva        = base_rva
  self._section_header = section_header
end

Public Instance Methods

_check_offset(offset, len = 1) click to toggle source
# File lib/rex/peparsey/section.rb, line 60
def _check_offset(offset, len = 1)
  if offset < 0 || offset+len > size
    raise BoundsError, "Offset #{offset} outside of section", caller
  end
end
contains_file_offset?(foffset) click to toggle source
# File lib/rex/peparsey/section.rb, line 117
def contains_file_offset?(foffset)
  contains_offset?(foffset - file_offset)
end
contains_offset?(offset) click to toggle source
# File lib/rex/peparsey/section.rb, line 113
def contains_offset?(offset)
  offset >= 0 && offset < size
end
contains_rva?(rva) click to toggle source
# File lib/rex/peparsey/section.rb, line 121
def contains_rva?(rva)
  contains_offset?(rva - base_rva)
end
file_offset() click to toggle source
# File lib/rex/peparsey/section.rb, line 26
def file_offset
  _isource.file_offset
end
file_offset_to_rva(foffset) click to toggle source
# File lib/rex/peparsey/section.rb, line 96
def file_offset_to_rva(foffset)
  return offset_to_rva(foffset - file_offset)
end
flags() click to toggle source
# File lib/rex/peparsey/section.rb, line 42
def flags
  # a section header is not required
  return nil if !_section_header
  _section_header.v['Characteristics']
end
index(*args) click to toggle source
# File lib/rex/peparsey/section.rb, line 84
def index(*args)
  _isource.index(*args)
end
name() click to toggle source
# File lib/rex/peparsey/section.rb, line 34
def name
  # a section header is not required
  return nil if !_section_header

  # FIXME make this better...
  _section_header.v['Name'].gsub(/\x00+$/n, '')
end
offset_to_rva(offset) click to toggle source
# File lib/rex/peparsey/section.rb, line 88
def offset_to_rva(offset)
  if !contains_offset?(offset)
    raise BoundsError, "Offset #{offset} outside of section", caller
  end

  return offset + base_rva
end
raw_size() click to toggle source
# File lib/rex/peparsey/section.rb, line 54
def raw_size
  # a section header is not required
  return nil if !_section_header
  _section_header.v['SizeOfRawData']
end
read(offset, len) click to toggle source
# File lib/rex/peparsey/section.rb, line 66
def read(offset, len)
  _check_offset(offset, len)
  return _isource.read(offset, len)
end
read_asciiz(offset) click to toggle source
# File lib/rex/peparsey/section.rb, line 75
def read_asciiz(offset)
  _check_offset(offset)
  return _isource.read_asciiz(offset)
end
read_asciiz_rva(rva) click to toggle source
# File lib/rex/peparsey/section.rb, line 80
def read_asciiz_rva(rva)
  return read_asciiz(rva_to_offset(rva))
end
read_rva(rva, len) click to toggle source
# File lib/rex/peparsey/section.rb, line 71
def read_rva(rva, len)
  return read(rva_to_offset(rva), len)
end
rva_to_file_offset(rva) click to toggle source
# File lib/rex/peparsey/section.rb, line 109
def rva_to_file_offset(rva)
  return rva_to_offset(rva) + file_offset
end
rva_to_offset(rva) click to toggle source
# File lib/rex/peparsey/section.rb, line 100
def rva_to_offset(rva)
  offset = rva - base_rva
  if !contains_offset?(offset)
    raise BoundsError, "RVA #{rva} outside of section", caller
  end

  return offset
end
size() click to toggle source
# File lib/rex/peparsey/section.rb, line 30
def size
  _isource.size
end
vma() click to toggle source
# File lib/rex/peparsey/section.rb, line 48
def vma
  # a section header is not required
  return nil if !_section_header
  _section_header.v['VirtualAddress']
end