Class: Rex::OLE::DirEntry
- Inherits:
-
Object
- Object
- Rex::OLE::DirEntry
- Defined in:
- lib/rex/ole/direntry.rb
Overview
This class serves as the base class for SubStorage, Stream, and Directory head
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_sidChild ⇒ Object
Returns the value of attribute _sidChild.
-
#_sidLeftSib ⇒ Object
Returns the value of attribute _sidLeftSib.
-
#_sidRightSib ⇒ Object
Returns the value of attribute _sidRightSib.
-
#sid ⇒ Object
Returns the value of attribute sid.
Instance Method Summary collapse
- #<<(expr) ⇒ Object
- #each ⇒ Object
- #find_by_sid(sid, de = self) ⇒ Object
-
#find_stream_by_name_and_type(name, type) ⇒ Object
NOTE: this will not look at children.
-
#from_s(sid, buf) ⇒ Object
low-level functions.
-
#initialize(stg) ⇒ DirEntry
constructor
A new instance of DirEntry.
- #length ⇒ Object
- #name ⇒ Object
- #name=(arg) ⇒ Object
- #pack ⇒ Object
- #start_sector ⇒ Object
- #start_sector=(expr) ⇒ Object
- #to_s(extra_spaces = 0) ⇒ Object
- #type ⇒ Object
- #type=(arg) ⇒ Object
Constructor Details
#initialize(stg) ⇒ DirEntry
Returns a new instance of DirEntry.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rex/ole/direntry.rb', line 23 def initialize(stg) @stg = stg # default to a root entry :) @sid = 0 @_ab = "Root Entry" @_cb = nil # NOTE: this is not used until pack @_mse = STGTY_ROOT @_bflags = 0 @_sidLeftSib = SECT_FREE @_sidRightSib = SECT_FREE @_sidChild = SECT_FREE @_clsId = CLSID.new @_dwUserFlags = 0 @_ctime = "\x00" * 8 @_mtime = "\x00" * 8 @_sectStart = SECT_END @_ulSize = 0 # keep track of logical children (in a tree) @children = [] end |
Instance Attribute Details
#_sidChild ⇒ Object
Returns the value of attribute _sidChild.
21 22 23 |
# File 'lib/rex/ole/direntry.rb', line 21 def _sidChild @_sidChild end |
#_sidLeftSib ⇒ Object
Returns the value of attribute _sidLeftSib.
21 22 23 |
# File 'lib/rex/ole/direntry.rb', line 21 def _sidLeftSib @_sidLeftSib end |
#_sidRightSib ⇒ Object
Returns the value of attribute _sidRightSib.
21 22 23 |
# File 'lib/rex/ole/direntry.rb', line 21 def _sidRightSib @_sidRightSib end |
#sid ⇒ Object
Returns the value of attribute sid.
20 21 22 |
# File 'lib/rex/ole/direntry.rb', line 20 def sid @sid end |
Instance Method Details
#<<(expr) ⇒ Object
51 52 53 |
# File 'lib/rex/ole/direntry.rb', line 51 def <<(expr) @children << expr end |
#each ⇒ Object
55 56 57 58 59 |
# File 'lib/rex/ole/direntry.rb', line 55 def each @children.each { |de| yield de } end |
#find_by_sid(sid, de = self) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rex/ole/direntry.rb', line 98 def find_by_sid(sid, de=self) if (de.sid == sid) return de end @children.each { |cde| ret = find_by_sid(cde, sid) if (ret) return ret end } nil end |
#find_stream_by_name_and_type(name, type) ⇒ Object
NOTE: this will not look at children
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rex/ole/direntry.rb', line 86 def find_stream_by_name_and_type(name, type) @children.each { |de| next if (de.type != type) if (de.name == name) return de end } nil end |
#from_s(sid, buf) ⇒ Object
low-level functions
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rex/ole/direntry.rb', line 115 def from_s(sid, buf) @sid = sid @_ab = Util.getUnicodeString(buf[0x00,64]) @_cb = Util.get16(buf, 0x40) # too big? if (@_cb > 0x40) raise RuntimeError, 'Invalid directory entry name length %#x' % @_cb end # mismatch? if (@_ab.length > 0) declen = ((@_cb) / 2) - 1 if (declen != @_ab.length) raise RuntimeError, 'Directory entry name and length mismatch (%d != %d)' % [declen, @_ab.length] end end @_mse = Util.get8(buf, 0x42) @_bflags = Util.get8(buf, 0x43) @_sidLeftSib = Util.get32(buf, 0x44) @_sidRightSib = Util.get32(buf, 0x48) @_sidChild = Util.get32(buf, 0x4c) # only used for storages.. @_clsId = CLSID.new(buf[0x50,16]) @_dwUserFlags = Util.get32(buf, 0x60) @_ctime = buf[0x64,8] @_mtime = buf[0x6c,8] # only used for streams... @_sectStart = Util.get32(buf, 0x74) if (@stg.header._uMajorVersion == 4) @_ulSize = Util.get64(buf, 0x78) else @_ulSize = Util.get32(buf, 0x78) end # ignore _dptPropType and pad end |
#length ⇒ Object
47 48 49 |
# File 'lib/rex/ole/direntry.rb', line 47 def length @_ulSize end |
#name ⇒ Object
69 70 71 |
# File 'lib/rex/ole/direntry.rb', line 69 def name @_ab end |
#name=(arg) ⇒ Object
72 73 74 75 |
# File 'lib/rex/ole/direntry.rb', line 72 def name=(arg) # XXX: validate? @_ab = arg end |
#pack ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rex/ole/direntry.rb', line 157 def pack @_sectStart ||= SECT_END @_cb = (@_ab.length + 1) * 2 data = "" data << Util.putUnicodeString(@_ab) # gets padded/truncated to 0x40 bytes data << Util.pack16(@_cb) data << Util.pack8(@_mse) data << Util.pack8(@_bflags) data << Util.pack32(@_sidLeftSib) data << Util.pack32(@_sidRightSib) data << Util.pack32(@_sidChild) data << @_clsId.pack data << Util.pack32(@_dwUserFlags) data << @_ctime data << @_mtime data << Util.pack32(@_sectStart) data << Util.pack64(@_ulSize) data end |
#start_sector ⇒ Object
77 78 79 |
# File 'lib/rex/ole/direntry.rb', line 77 def start_sector @_sectStart end |
#start_sector=(expr) ⇒ Object
80 81 82 |
# File 'lib/rex/ole/direntry.rb', line 80 def start_sector=(expr) @_sectStart = expr end |
#to_s(extra_spaces = 0) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/rex/ole/direntry.rb', line 179 def to_s(extra_spaces=0) @_sectStart ||= SECT_END @_cb = (@_ab.length + 1) * 2 spstr = " " * extra_spaces ret = "%s{\n" % spstr ret << "%s sid => 0x%x" % [spstr, @sid] ret << ",\n" ret << "%s _ab => \"%s\"" % [spstr, Util.Printable(@_ab)] ret << ",\n" ret << "%s _cb => 0x%04x" % [spstr, @_cb] ret << ",\n" ret << "%s _mse => 0x%02x" % [spstr, @_mse] ret << ",\n" ret << "%s _bflags => 0x%02x" % [spstr, @_bflags] ret << ",\n" ret << "%s _sidLeftSib => 0x%08x" % [spstr, @_sidLeftSib] ret << ",\n" ret << "%s _sidRightSib => 0x%08x" % [spstr, @_sidRightSib] ret << ",\n" ret << "%s _sidChild => 0x%08x" % [spstr, @_sidChild] ret << ",\n" ret << "%s _clsId => %s" % [spstr, @_clsId.to_s] ret << ",\n" ret << "%s _dwUserFlags => 0x%08x" % [spstr, @_dwUserFlags] ret << ",\n" ret << "%s _ctime => %s" % [spstr, Rex::Text.to_hex_dump(@_ctime).strip] ret << "\n" ret << "%s _mtime => %s" % [spstr, Rex::Text.to_hex_dump(@_mtime).strip] ret << "\n" ret << "%s _sectStart => 0x%08x" % [spstr, @_sectStart] ret << ",\n" ret << "%s _ulSize => 0x%016x" % [spstr, @_ulSize] if (@_mse == STGTY_STREAM) ret << ",\n" ret << "%s data =>\n" % spstr if (@data) #ret << Util.Printable(@data) ret << Rex::Text.to_hex_dump(@data).strip else if (@_ulSize > 0) ret << "--NOT OPENED YET--" end end elsif (@_mse == STGTY_STORAGE) or (@_mse == STGTY_ROOT) if (@children.length > 0) ret << ",\n" ret << "%s *children* =>\n" % spstr @children.each { |de| ret << de.to_s(extra_spaces+2) ret << "\n" } end end ret << "\n" ret << "%s}" % spstr end |
#type ⇒ Object
62 63 64 |
# File 'lib/rex/ole/direntry.rb', line 62 def type @_mse end |
#type=(arg) ⇒ Object
65 66 67 |
# File 'lib/rex/ole/direntry.rb', line 65 def type=(arg) @_mse = arg end |