Method: Rex::OLE::FAT#write

Defined in:
lib/rex/ole/fat.rb

#write(difat) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rex/ole/fat.rb', line 62

def write(difat)
  # we build the difat as we write these..
  difat.reset

  # allocate the sectors
  fat_sects = []
  left = @entries.length
  while (left > 0)
    if (left > @stg.header.idx_per_sect)
      left -= @stg.header.idx_per_sect
    else
      left = 0
    end
    fat_sects << allocate_sector(SECT_FAT)
  end

  # write the fat into the difat/allocated sectors
  copy = @entries.dup
  fat_sects.each { |fs|
    part = copy.slice!(0, @stg.header.idx_per_sect)
    sbuf = Util.pack32array(part)

    if (sbuf.length != @stg.header.sector_size)
      raise RuntimeError, 'Unsupported number of fat sectors (not multiple of idx per sect)'
    end

    @stg.write_sector_raw(fs, sbuf)
    difat << fs
  }
end