Ole and Accessing Files Embedded in Microsoft Access








Ole and Accessing Files Embedded in Microsoft Access

The Microsoft Access team in 1990 needed a way to not only store files in an Access database, but also to present it to the user, with other software installed on the user’s computer. Because back then, there was no reliable way to find out through the OS what software handled what file type, they had to come up with a new solution which was called Object Linking and Embedding (OLE).

How a file is stored inside Microsoft Access (OLE Structure)?

1. Package header
2. Ole header
3. Datablock length
4. Data
5. Metafilepict block
6. Ole footer

The Package Header structure:
A Signature (short): this indicates that the file is a package
The header size (short)
An object type (uint): 0 = linked, 1= embedded, 2 = either
The length of the friendly name in the header (short)
The length of the class name in the header (short)
The offset of the friendly name (short)
The offset of the class name (short)
The size of the object (int)
The friendly name (string, variable length)
The class name (string, variable length)

The Ole Header structure:
The Ole version (uint)
The Format (uint)
The object type name length (int)
The object type name (string, variable length)
The Ole header actually ends with 8 empty bytes followed by 4 bytes that make up the length of the Datablock as an int.

The Datablock and Data structures:
Inside the datablock can be the actual file, but also there can be a structured storage. To determine if this is a structured storage, there is actually an 8 byte signature at the start of the storage.

The Metafilepict block
When you work with images, there is another block called the metafilepict block. You are not likely to find a CONTENTS element if you need to read the metafilepict block.

Where is the Metafilepict block?

The start position of the Metafilepict can be calculated by using the following formula:

Metefilepict start position = total Package Header length + total Ole Header length + 8 (empty bytes) + 4 (Data length bytes) + Data length + 45 (Metafilepict header length)

The stream at this position contains the actual image file.

Copyright © All Rights Reserved - C# Learners