Class | Ole::Storage::Header |
In: |
lib/ole/storage/base.rb
|
Parent: | Struct.new( :magic, :clsid, :minor_ver, :major_ver, :byte_order, :b_shift, :s_shift, :reserved, :csectdir, :num_bat, :dirent_start, :transacting_signature, :threshold, :sbat_start, :num_sbat, :mbat_start, :num_mbat |
A class which wraps the ole header
Header.new can be both used to load from a string, or to create from defaults. Serialization is accomplished with the to_s method.
PACK | = | 'a8 a16 v2 a2 v2 a6 V3 a4 V5' | ||
SIZE | = | 0x4c | ||
MAGIC | = | "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1" | i have seen it pointed out that the first 4 bytes of hex, 0xd0cf11e0, is supposed to spell out docfile. hmmm :) | |
EOC | = | 0xfffffffe | what you get if creating new header from scratch. AllocationTable::EOC isn‘t available yet. meh. | |
DEFAULT | = | [ MAGIC, 0.chr * 16, 59, 3, "\xfe\xff", 9, 6, 0.chr * 6, 0, 1, EOC, 0.chr * 4, 4096, EOC, 0, EOC, 0 |
# File lib/ole/storage/base.rb, line 362 362: def initialize values=DEFAULT 363: values = values.unpack(PACK) if String === values 364: super(*values) 365: validate! 366: end
# File lib/ole/storage/base.rb, line 372 372: def validate! 373: raise FormatError, "OLE2 signature is invalid" unless magic == MAGIC 374: if num_bat == 0 or # is that valid for a completely empty file? 375: # not sure about this one. basically to do max possible bat given size of mbat 376: num_bat > 109 && num_bat > 109 + num_mbat * (1 << b_shift - 2) or 377: # shouldn't need to use the mbat as there is enough space in the header block 378: num_bat < 109 && num_mbat != 0 or 379: # given the size of the header is 76, if b_shift <= 6, blocks address the header. 380: s_shift > b_shift or b_shift <= 6 or b_shift >= 31 or 381: # we only handle little endian 382: byte_order != "\xfe\xff" 383: raise FormatError, "not valid OLE2 structured storage file" 384: end 385: # relaxed this, due to test-msg/qwerty_[1-3]*.msg they all had 386: # 3 for this value. 387: # transacting_signature != "\x00" * 4 or 388: if threshold != 4096 or 389: num_mbat == 0 && mbat_start != AllocationTable::EOC or 390: reserved != "\x00" * 6 391: Log.warn "may not be a valid OLE2 structured storage file" 392: end 393: true 394: end