Class: Rex::PeParsey::Section
- Inherits:
-
Object
- Object
- Rex::PeParsey::Section
- Defined in:
- lib/rex/peparsey/section.rb
Instance Attribute Summary collapse
-
#_isource ⇒ Object
Returns the value of attribute _isource.
-
#_section_header ⇒ Object
Returns the value of attribute _section_header.
-
#base_rva ⇒ Object
Returns the value of attribute base_rva.
Instance Method Summary collapse
- #_check_offset(offset, len = 1) ⇒ Object
- #contains_file_offset?(foffset) ⇒ Boolean
- #contains_offset?(offset) ⇒ Boolean
- #contains_rva?(rva) ⇒ Boolean
- #file_offset ⇒ Object
- #file_offset_to_rva(foffset) ⇒ Object
- #flags ⇒ Object
- #index(*args) ⇒ Object
-
#initialize(isource, base_rva, section_header = nil) ⇒ Section
constructor
Initialize a section.
- #name ⇒ Object
- #offset_to_rva(offset) ⇒ Object
- #raw_size ⇒ Object
- #read(offset, len) ⇒ Object
- #read_asciiz(offset) ⇒ Object
- #read_asciiz_rva(rva) ⇒ Object
- #read_rva(rva, len) ⇒ Object
- #rva_to_file_offset(rva) ⇒ Object
-
#rva_to_offset(rva) ⇒ Object
end.
- #size ⇒ Object
- #vma ⇒ Object
Constructor Details
#initialize(isource, base_rva, section_header = nil) ⇒ Section
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.
23 24 25 26 27 |
# File 'lib/rex/peparsey/section.rb', line 23 def initialize(isource, base_rva, section_header = nil) self._isource = isource self.base_rva = base_rva self._section_header = section_header end |
Instance Attribute Details
#_isource ⇒ Object
Returns the value of attribute _isource.
12 13 14 |
# File 'lib/rex/peparsey/section.rb', line 12 def _isource @_isource end |
#_section_header ⇒ Object
Returns the value of attribute _section_header.
12 13 14 |
# File 'lib/rex/peparsey/section.rb', line 12 def _section_header @_section_header end |
#base_rva ⇒ Object
Returns the value of attribute base_rva.
13 14 15 |
# File 'lib/rex/peparsey/section.rb', line 13 def base_rva @base_rva end |
Instance Method Details
#_check_offset(offset, len = 1) ⇒ Object
63 64 65 66 67 |
# File 'lib/rex/peparsey/section.rb', line 63 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) ⇒ Boolean
126 127 128 |
# File 'lib/rex/peparsey/section.rb', line 126 def contains_file_offset?(foffset) contains_offset?(foffset - file_offset) end |
#contains_offset?(offset) ⇒ Boolean
122 123 124 |
# File 'lib/rex/peparsey/section.rb', line 122 def contains_offset?(offset) offset >= 0 && offset < size end |
#contains_rva?(rva) ⇒ Boolean
130 131 132 |
# File 'lib/rex/peparsey/section.rb', line 130 def contains_rva?(rva) contains_offset?(rva - base_rva) end |
#file_offset ⇒ Object
29 30 31 |
# File 'lib/rex/peparsey/section.rb', line 29 def file_offset _isource.file_offset end |
#file_offset_to_rva(foffset) ⇒ Object
99 100 101 |
# File 'lib/rex/peparsey/section.rb', line 99 def file_offset_to_rva(foffset) return offset_to_rva(foffset - file_offset) end |
#flags ⇒ Object
45 46 47 48 49 |
# File 'lib/rex/peparsey/section.rb', line 45 def flags # a section header is not required return nil if !_section_header _section_header.v['Characteristics'] end |
#index(*args) ⇒ Object
87 88 89 |
# File 'lib/rex/peparsey/section.rb', line 87 def index(*args) _isource.index(*args) end |
#name ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rex/peparsey/section.rb', line 37 def name # a section header is not required return nil if !_section_header # FIXME make this better... _section_header.v['Name'].gsub(/\x00+$/, '') end |
#offset_to_rva(offset) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/rex/peparsey/section.rb', line 91 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 ⇒ Object
57 58 59 60 61 |
# File 'lib/rex/peparsey/section.rb', line 57 def raw_size # a section header is not required return nil if !_section_header _section_header.v['SizeOfRawData'] end |
#read(offset, len) ⇒ Object
69 70 71 72 |
# File 'lib/rex/peparsey/section.rb', line 69 def read(offset, len) _check_offset(offset, len) return _isource.read(offset, len) end |
#read_asciiz(offset) ⇒ Object
78 79 80 81 |
# File 'lib/rex/peparsey/section.rb', line 78 def read_asciiz(offset) _check_offset(offset) return _isource.read_asciiz(offset) end |
#read_asciiz_rva(rva) ⇒ Object
83 84 85 |
# File 'lib/rex/peparsey/section.rb', line 83 def read_asciiz_rva(rva) return read_asciiz(rva_to_offset(rva)) end |
#read_rva(rva, len) ⇒ Object
74 75 76 |
# File 'lib/rex/peparsey/section.rb', line 74 def read_rva(rva, len) return read(rva_to_offset(rva), len) end |
#rva_to_file_offset(rva) ⇒ Object
118 119 120 |
# File 'lib/rex/peparsey/section.rb', line 118 def rva_to_file_offset(rva) return rva_to_offset(rva) + file_offset end |
#rva_to_offset(rva) ⇒ Object
end
109 110 111 112 113 114 115 116 |
# File 'lib/rex/peparsey/section.rb', line 109 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 ⇒ Object
33 34 35 |
# File 'lib/rex/peparsey/section.rb', line 33 def size _isource.size end |
#vma ⇒ Object
51 52 53 54 55 |
# File 'lib/rex/peparsey/section.rb', line 51 def vma # a section header is not required return nil if !_section_header _section_header.v['VirtualAddress'] end |