Method: Rex::OLE::Header#write

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

#write(fd) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/rex/ole/header.rb', line 162

def write(fd)
  hdr = ""
  hdr << @_abSig
  hdr << @_clid.pack
  hdr << Util.pack16(@_uMinorVersion)
  hdr << Util.pack16(@_uMajorVersion)
  hdr << Util.pack16(@_uByteOrder)
  hdr << Util.pack16(@_uSectorShift)
  hdr << Util.pack16(@_uMiniSectorShift)
  if (@_uMajorVersion == 0x04)
    hdr << "\x00" * 6 # reserved bytes
    hdr << Util.pack32(@_csectDir)
  else
    hdr << "\x00" * 10 # reserved bytes
  end

  fs_count = @_csectFat
  fs_count ||= 0
  hdr << Util.pack32(fs_count)

  dir_start = @_sectDirStart
  dir_start ||= SECT_END
  hdr << Util.pack32(dir_start)

  hdr << Util.pack32(@_signature)
  hdr << Util.pack32(@_ulMiniSectorCutoff)
  hdr << Util.pack32(@_sectMiniFatStart)
  hdr << Util.pack32(@_csectMiniFat)
  hdr << Util.pack32(@_sectDifStart)
  hdr << Util.pack32(@_csectDif)
  hdr << Util.pack32array(@_sectFat)

  fd.seek(0, ::IO::SEEK_SET)
  fd.write(hdr)
end