class Rex::OLE::DIFAT
Public Class Methods
new(stg)
click to toggle source
# File lib/rex/ole/difat.rb, line 12 def initialize stg @stg = stg @entries = [] end
Public Instance Methods
+(expr)
click to toggle source
# File lib/rex/ole/difat.rb, line 28 def +(expr) @entries += expr self end
<<(expr)
click to toggle source
# File lib/rex/ole/difat.rb, line 33 def <<(expr) @entries << expr end
[](idx)
click to toggle source
# File lib/rex/ole/difat.rb, line 24 def [](idx) @entries[idx] end
[]=(idx,expr)
click to toggle source
convenience access to entries
# File lib/rex/ole/difat.rb, line 20 def []=(idx,expr) @entries[idx] = expr end
each() { |el| ... }
click to toggle source
# File lib/rex/ole/difat.rb, line 49 def each @entries.each { |el| yield el } end
length()
click to toggle source
# File lib/rex/ole/difat.rb, line 37 def length @entries.length end
read()
click to toggle source
low-level functions
# File lib/rex/ole/difat.rb, line 82 def read @entries = [] # start with the header part @entries += @stg.header._sectFat # double indirect fat sect = @stg.header._sectDifStart while (sect != SECT_END) if (@entries.include?(sect)) raise RuntimeError, 'Sector chain loop detected (0x%08x)' % sect end @entries << sect buf = @stg.read_sector(sect, @stg.header.sector_size) # the last sect ptr in the block becomes the next entry sect = Util.get32(buf, ((@stg.header.idx_per_sect)-1) * 4) end # don't need these free ones, but it doesn't hurt to keep them. #@difat.delete(SECT_FREE) end
reset()
click to toggle source
# File lib/rex/ole/difat.rb, line 45 def reset @entries = [] end
slice!(start,stop)
click to toggle source
# File lib/rex/ole/difat.rb, line 41 def slice!(start,stop) @entries.slice!(start,stop) end
to_s()
click to toggle source
woop
# File lib/rex/ole/difat.rb, line 58 def to_s ret = "{ " @entries.each { |el| ret << ", " if (ret.length > 2) case el when SECT_END ret << "END" when SECT_DIF ret << "DIF" when SECT_FAT ret << "FAT" when SECT_FREE ret << "FREE" else ret << "0x%x" % el end } ret << " }" ret end
write()
click to toggle source
# File lib/rex/ole/difat.rb, line 106 def write len = @entries.length first109 = @entries.dup rest = nil if (len > 109) rest = first109.slice!(109,len) end @stg.header._sectFat = [] @stg.header._sectFat += first109 if (len < 109) need = 109 - len need.times { @stg.header._sectFat << SECT_FREE } end if (rest and rest.length > 0) raise RuntimeError, 'TODO: support writing DIF properly!' # may require adding more fat sectors :-/ #@stg.header._csectDif = rest.length #@stg.header._sectDifStart = idx end @stg.header._csectFat = len end