Class: Ole::Storage::Header

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(values = DEFAULT) ⇒ Header

Returns a new instance of Header.



367
368
369
370
371
# File 'lib/ole/storage/base.rb', line 367

def initialize values=DEFAULT
	values = values.unpack(PACK) if String === values
	super(*values)
	validate!
end

Instance Attribute Details

#b_shiftObject

Returns the value of attribute b_shift

Returns:

  • (Object)

    the current value of b_shift



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def b_shift
  @b_shift
end

#byte_orderObject

Returns the value of attribute byte_order

Returns:

  • (Object)

    the current value of byte_order



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def byte_order
  @byte_order
end

#clsidObject

Returns the value of attribute clsid

Returns:

  • (Object)

    the current value of clsid



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def clsid
  @clsid
end

#csectdirObject

Returns the value of attribute csectdir

Returns:

  • (Object)

    the current value of csectdir



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def csectdir
  @csectdir
end

#dirent_startObject

Returns the value of attribute dirent_start

Returns:

  • (Object)

    the current value of dirent_start



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def dirent_start
  @dirent_start
end

#magicObject

Returns the value of attribute magic

Returns:

  • (Object)

    the current value of magic



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def magic
  @magic
end

#major_verObject

Returns the value of attribute major_ver

Returns:

  • (Object)

    the current value of major_ver



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def major_ver
  @major_ver
end

#mbat_startObject

Returns the value of attribute mbat_start

Returns:

  • (Object)

    the current value of mbat_start



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def mbat_start
  @mbat_start
end

#minor_verObject

Returns the value of attribute minor_ver

Returns:

  • (Object)

    the current value of minor_ver



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def minor_ver
  @minor_ver
end

#num_batObject

Returns the value of attribute num_bat

Returns:

  • (Object)

    the current value of num_bat



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def num_bat
  @num_bat
end

#num_mbatObject

Returns the value of attribute num_mbat

Returns:

  • (Object)

    the current value of num_mbat



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def num_mbat
  @num_mbat
end

#num_sbatObject

Returns the value of attribute num_sbat

Returns:

  • (Object)

    the current value of num_sbat



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def num_sbat
  @num_sbat
end

#reservedObject

Returns the value of attribute reserved

Returns:

  • (Object)

    the current value of reserved



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def reserved
  @reserved
end

#s_shiftObject

Returns the value of attribute s_shift

Returns:

  • (Object)

    the current value of s_shift



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def s_shift
  @s_shift
end

#sbat_startObject

Returns the value of attribute sbat_start

Returns:

  • (Object)

    the current value of sbat_start



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def sbat_start
  @sbat_start
end

#thresholdObject

Returns the value of attribute threshold

Returns:

  • (Object)

    the current value of threshold



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def threshold
  @threshold
end

#transacting_signatureObject

Returns the value of attribute transacting_signature

Returns:

  • (Object)

    the current value of transacting_signature



348
349
350
# File 'lib/ole/storage/base.rb', line 348

def transacting_signature
  @transacting_signature
end

Instance Method Details

#to_sObject



373
374
375
# File 'lib/ole/storage/base.rb', line 373

def to_s
	to_a.pack PACK
end

#validate!Object

Raises:



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