Class: Ole::Storage::Header
- Inherits:
-
Struct
- Object
- Struct
- Ole::Storage::Header
- Defined in:
- lib/ole/storage/base.rb
Overview
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.
Constant Summary collapse
- PACK =
'a8 a16 v2 a2 v2 a6 V3 a4 V5'
- SIZE =
0x4c
- MAGIC =
i have seen it pointed out that the first 4 bytes of hex, 0xd0cf11e0, is supposed to spell out docfile. hmmm :)
"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1"
- EOC =
what you get if creating new header from scratch. AllocationTable::EOC isn’t available yet. meh.
0xfffffffe
- 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 ]
Instance Attribute Summary collapse
-
#b_shift ⇒ Object
Returns the value of attribute b_shift.
-
#byte_order ⇒ Object
Returns the value of attribute byte_order.
-
#clsid ⇒ Object
Returns the value of attribute clsid.
-
#csectdir ⇒ Object
Returns the value of attribute csectdir.
-
#dirent_start ⇒ Object
Returns the value of attribute dirent_start.
-
#magic ⇒ Object
Returns the value of attribute magic.
-
#major_ver ⇒ Object
Returns the value of attribute major_ver.
-
#mbat_start ⇒ Object
Returns the value of attribute mbat_start.
-
#minor_ver ⇒ Object
Returns the value of attribute minor_ver.
-
#num_bat ⇒ Object
Returns the value of attribute num_bat.
-
#num_mbat ⇒ Object
Returns the value of attribute num_mbat.
-
#num_sbat ⇒ Object
Returns the value of attribute num_sbat.
-
#reserved ⇒ Object
Returns the value of attribute reserved.
-
#s_shift ⇒ Object
Returns the value of attribute s_shift.
-
#sbat_start ⇒ Object
Returns the value of attribute sbat_start.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#transacting_signature ⇒ Object
Returns the value of attribute transacting_signature.
Instance Method Summary collapse
-
#initialize(values = DEFAULT) ⇒ Header
constructor
A new instance of Header.
- #to_s ⇒ Object
- #validate! ⇒ Object
Constructor Details
Instance Attribute Details
#b_shift ⇒ Object
Returns the value of attribute b_shift
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def b_shift @b_shift end |
#byte_order ⇒ Object
Returns the value of attribute byte_order
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def byte_order @byte_order end |
#clsid ⇒ Object
Returns the value of attribute clsid
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def clsid @clsid end |
#csectdir ⇒ Object
Returns the value of attribute csectdir
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def csectdir @csectdir end |
#dirent_start ⇒ Object
Returns the value of attribute dirent_start
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def dirent_start @dirent_start end |
#magic ⇒ Object
Returns the value of attribute magic
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def magic @magic end |
#major_ver ⇒ Object
Returns the value of attribute major_ver
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def major_ver @major_ver end |
#mbat_start ⇒ Object
Returns the value of attribute mbat_start
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def mbat_start @mbat_start end |
#minor_ver ⇒ Object
Returns the value of attribute minor_ver
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def minor_ver @minor_ver end |
#num_bat ⇒ Object
Returns the value of attribute num_bat
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def num_bat @num_bat end |
#num_mbat ⇒ Object
Returns the value of attribute num_mbat
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def num_mbat @num_mbat end |
#num_sbat ⇒ Object
Returns the value of attribute num_sbat
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def num_sbat @num_sbat end |
#reserved ⇒ Object
Returns the value of attribute reserved
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def reserved @reserved end |
#s_shift ⇒ Object
Returns the value of attribute s_shift
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def s_shift @s_shift end |
#sbat_start ⇒ Object
Returns the value of attribute sbat_start
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def sbat_start @sbat_start end |
#threshold ⇒ Object
Returns the value of attribute threshold
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def threshold @threshold end |
#transacting_signature ⇒ Object
Returns the value of attribute transacting_signature
348 349 350 |
# File 'lib/ole/storage/base.rb', line 348 def transacting_signature @transacting_signature end |
Instance Method Details
#to_s ⇒ Object
373 374 375 |
# File 'lib/ole/storage/base.rb', line 373 def to_s to_a.pack PACK end |
#validate! ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/ole/storage/base.rb', line 377 def validate! raise FormatError, "OLE2 signature is invalid" unless magic == MAGIC if num_bat == 0 or # is that valid for a completely empty file? # not sure about this one. basically to do max possible bat given size of mbat num_bat > 109 && num_bat > 109 + num_mbat * (1 << b_shift - 2) or # shouldn't need to use the mbat as there is enough space in the header block num_bat < 109 && num_mbat != 0 or # given the size of the header is 76, if b_shift <= 6, blocks address the header. s_shift > b_shift or b_shift <= 6 or b_shift >= 31 or # we only handle little endian byte_order != "\xfe\xff" raise FormatError, "not valid OLE2 structured storage file" end # relaxed this, due to test-msg/qwerty_[1-3]*.msg they all had # 3 for this value. # transacting_signature != "\x00" * 4 or if threshold != 4096 or num_mbat == 0 && ![AllocationTable::EOC, AllocationTable::AVAIL].include?(mbat_start) or reserved != "\x00" * 6 Log.warn "may not be a valid OLE2 structured storage file" end true end |