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.
24 25 26 27 28 |
# File 'lib/rex/peparsey/section.rb', line 24 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.
13 14 15 |
# File 'lib/rex/peparsey/section.rb', line 13 def _isource @_isource end |
#_section_header ⇒ Object
Returns the value of attribute _section_header.
13 14 15 |
# File 'lib/rex/peparsey/section.rb', line 13 def _section_header @_section_header end |
#base_rva ⇒ Object
Returns the value of attribute base_rva.
14 15 16 |
# File 'lib/rex/peparsey/section.rb', line 14 def base_rva @base_rva end |
Instance Method Details
#_check_offset(offset, len = 1) ⇒ Object
64 65 66 67 68 |
# File 'lib/rex/peparsey/section.rb', line 64 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
127 128 129 |
# File 'lib/rex/peparsey/section.rb', line 127 def contains_file_offset?(foffset) contains_offset?(foffset - file_offset) end |
#contains_offset?(offset) ⇒ Boolean
123 124 125 |
# File 'lib/rex/peparsey/section.rb', line 123 def contains_offset?(offset) offset >= 0 && offset < size end |
#contains_rva?(rva) ⇒ Boolean
131 132 133 |
# File 'lib/rex/peparsey/section.rb', line 131 def contains_rva?(rva) contains_offset?(rva - base_rva) end |
#file_offset ⇒ Object
30 31 32 |
# File 'lib/rex/peparsey/section.rb', line 30 def file_offset _isource.file_offset end |
#file_offset_to_rva(foffset) ⇒ Object
100 101 102 |
# File 'lib/rex/peparsey/section.rb', line 100 def file_offset_to_rva(foffset) return offset_to_rva(foffset - file_offset) end |
#flags ⇒ Object
46 47 48 49 50 |
# File 'lib/rex/peparsey/section.rb', line 46 def flags # a section header is not required return nil if !_section_header _section_header.v['Characteristics'] end |
#index(*args) ⇒ Object
88 89 90 |
# File 'lib/rex/peparsey/section.rb', line 88 def index(*args) _isource.index(*args) end |
#name ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rex/peparsey/section.rb', line 38 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
92 93 94 95 96 97 98 |
# File 'lib/rex/peparsey/section.rb', line 92 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
58 59 60 61 62 |
# File 'lib/rex/peparsey/section.rb', line 58 def raw_size # a section header is not required return nil if !_section_header _section_header.v['SizeOfRawData'] end |
#read(offset, len) ⇒ Object
70 71 72 73 |
# File 'lib/rex/peparsey/section.rb', line 70 def read(offset, len) _check_offset(offset, len) return _isource.read(offset, len) end |
#read_asciiz(offset) ⇒ Object
79 80 81 82 |
# File 'lib/rex/peparsey/section.rb', line 79 def read_asciiz(offset) _check_offset(offset) return _isource.read_asciiz(offset) end |
#read_asciiz_rva(rva) ⇒ Object
84 85 86 |
# File 'lib/rex/peparsey/section.rb', line 84 def read_asciiz_rva(rva) return read_asciiz(rva_to_offset(rva)) end |
#read_rva(rva, len) ⇒ Object
75 76 77 |
# File 'lib/rex/peparsey/section.rb', line 75 def read_rva(rva, len) return read(rva_to_offset(rva), len) end |
#rva_to_file_offset(rva) ⇒ Object
119 120 121 |
# File 'lib/rex/peparsey/section.rb', line 119 def rva_to_file_offset(rva) return rva_to_offset(rva) + file_offset end |
#rva_to_offset(rva) ⇒ Object
end
110 111 112 113 114 115 116 117 |
# File 'lib/rex/peparsey/section.rb', line 110 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
34 35 36 |
# File 'lib/rex/peparsey/section.rb', line 34 def size _isource.size end |
#vma ⇒ Object
52 53 54 55 56 |
# File 'lib/rex/peparsey/section.rb', line 52 def vma # a section header is not required return nil if !_section_header _section_header.v['VirtualAddress'] end |