MS OLE2

## MS OLE2 MS OLE2 — |

## Synopsis

                GsfInfileMSOle;
    GsfInfile*  gsf_infile_msole_new            (GsfInput *source,
                                                 GError **err);
    gboolean    gsf_infile_msole_get_class_id   (GsfInfileMSOle const *ole,
                                                 guint8 *res);
                GsfOutfileMSOle;
    GsfOutfile* gsf_outfile_msole_new           (GsfOutput *sink);
    gboolean    gsf_outfile_msole_set_class_id  (GsfOutfileMSOle *ole,
                                                 guint8 const *clsid);
    gboolean    gsf_msole_metadata_read         (GsfInput *in,
                                                 GError **err);
    gboolean    gsf_msole_metadata_write        (GsfOutput *out,
                                                 gboolean doc_not_component,
                                                 GError **err);
    GIConv      gsf_msole_iconv_open_codepages_for_export
                                                (guint codepage_to,
                                                 char const *from);
    GIConv      gsf_msole_iconv_open_codepage_for_import
                                                (char const *to,
                                                 int codepage);
    GIConv      gsf_msole_iconv_open_for_export (void);
    GIConv      gsf_msole_iconv_open_codepage_for_export
                                                (guint codepage_to);
    GIConv      gsf_msole_iconv_open_for_import (int codepage);
    guint       gsf_msole_iconv_win_codepage    (void);
    guint       gsf_msole_codepage_to_lid       (int codepage);
    guint       gsf_msole_lid_to_codepage       (guint lid);
    gchar*      gsf_msole_lid_to_codepage_str   (guint lid);
    guint       gsf_msole_lid_for_language      (char const *lang);
    GByteArray* gsf_msole_inflate               (GsfInput *input,
                                                 gsf_off_t offset);

    #define     OLE_HEADER_START_BAT
    #define     OLE_HEADER_MAJOR_VER
    #define     OLE_HEADER_METABAT_SIZE
    #define     OLE_HEADER_DIRENT_START
    #define     OLE_HEADER_NUM_SBAT
    #define     OLE_HEADER_BB_SHIFT
    #define     OLE_HEADER_NUM_BAT
    #define     OLE_HEADER_THRESHOLD
    #define     OLE_HEADER_METABAT_BLOCK
    #define     OLE_HEADER_SBAT_START
    #define     OLE_HEADER_SIGNATURE
    #define     OLE_HEADER_BYTE_ORDER
    #define     OLE_HEADER_SB_SHIFT
    #define     OLE_HEADER_NUM_METABAT
    #define     OLE_HEADER_SIZE
    #define     OLE_HEADER_CLSID
    #define     OLE_HEADER_MINOR_VER
    #define     OLE_DEFAULT_BB_SHIFT
    #define     OLE_DEFAULT_SB_SHIFT
    #define     DIRENT_DETAILS_SIZE
    #define     DIRENT_SIZE
    #define     DIRENT_NAME_LEN
    #define     DIRENT_TYPE_PROPERTY
    #define     DIRENT_TYPE_FILE
    #define     DIRENT_MAGIC_END
    #define     DIRENT_TYPE_DIR
    #define     DIRENT_MAX_NAME_SIZE
    #define     DIRENT_FILE_SIZE
    #define     DIRENT_FIRSTBLOCK
    #define     DIRENT_TYPE_INVALID
    #define     DIRENT_USERFLAGS
    #define     DIRENT_COLOUR
    #define     DIRENT_MODIFY_TIME
    #define     DIRENT_TYPE_LOCKBYTES
    #define     DIRENT_CREATE_TIME
    #define     DIRENT_PREV
    #define     DIRENT_NEXT
    #define     DIRENT_CHILD
    #define     DIRENT_TYPE
    #define     DIRENT_CLSID
    #define     DIRENT_TYPE_ROOTDIR
    #define     BAT_MAGIC_METABAT
    #define     BAT_MAGIC_BAT
    #define     BAT_INDEX_SIZE
    #define     BAT_MAGIC_END_OF_CHAIN
    #define     BAT_MAGIC_UNUSED

## Object Hierarchy

      GObject
       +----GsfInput
             +----GsfInfile
                   +----GsfInfileMSOle

      GObject
       +----GsfOutput
             +----GsfOutfile
                   +----GsfOutfileMSOle

## Description

## Details

### GsfInfileMSOle

    typedef struct _GsfInfileMSOle GsfInfileMSOle;

### gsf_infile_msole_new ()

    GsfInfile*  gsf_infile_msole_new            (GsfInput *source,
                                                 GError **err);

Opens the root directory of an MS OLE file. NOTE : adds a reference to `source`

`source` : |
`err` : |
Returns : | : the new ole file handler

### gsf_infile_msole_get_class_id ()

    gboolean    gsf_infile_msole_get_class_id   (GsfInfileMSOle const *ole,
                                                 guint8 *res);

Retrieves the 16 byte indentifier (often a GUID in MS Windows apps) stored within the directory associated with `ole` and stores it in `res`.

`ole` : | a GsfInfileMSOle
`res` : | 16 byte identifier (often a GUID in MS Windows apps)
Returns : | TRUE on success

### GsfOutfileMSOle

    typedef struct _GsfOutfileMSOle GsfOutfileMSOle;

### gsf_outfile_msole_new ()

    GsfOutfile* gsf_outfile_msole_new           (GsfOutput *sink);

Creates the root directory of an MS OLE file and manages the addition of children.

NOTE : adds a reference to `sink`

`sink` : | a GsfOutput to hold the OLE2 file
Returns : | : the new ole file handler

### gsf_outfile_msole_set_class_id ()

    gboolean    gsf_outfile_msole_set_class_id  (GsfOutfileMSOle *ole,
                                                 guint8 const *clsid);

Write `clsid` to the directory associated with `ole`.

`ole` : | a GsfOutfileMSOle
`clsid` : | 16 byte identifier (often a GUID in MS Windows apps)
Returns : | TRUE on success.

### gsf_msole_metadata_read ()

    gboolean    gsf_msole_metadata_read         (GsfInput *in,
                                                 GError **err);

`in` : |
`err` : |
Returns : |

### gsf_msole_metadata_write ()

    gboolean    gsf_msole_metadata_write        (GsfOutput *out,
                                                 gboolean doc_not_component,
                                                 GError **err);

`out` : |
`doc_not_component` : |
`err` : |
Returns : |

### gsf_msole_iconv_open_codepages_for_export ()

    GIConv      gsf_msole_iconv_open_codepages_for_export
                                                (guint codepage_to,
                                                 char const *from);

`codepage_to` : |
`from` : |
Returns : | an iconv converter to go from utf8 -> to our best guess at a useful windows codepage.

### gsf_msole_iconv_open_codepage_for_import ()

    GIConv      gsf_msole_iconv_open_codepage_for_import
                                                (char const *to,
                                                 int codepage);

`to` : |
`codepage` : |
Returns : | an iconv converter for `codepage` -> utf8.

### gsf_msole_iconv_open_for_export ()

    GIConv      gsf_msole_iconv_open_for_export (void);

Returns : | an iconv convert to go from utf8 -> to our best guess at a useful windows codepage.

### gsf_msole_iconv_open_codepage_for_export ()

    GIConv      gsf_msole_iconv_open_codepage_for_export
                                                (guint codepage_to);

`codepage_to` : |
Returns : | an iconv converter to go from utf8 -> to our best guess at a useful windows codepage.

### gsf_msole_iconv_open_for_import ()

    GIConv      gsf_msole_iconv_open_for_import (int codepage);

`codepage` : |
Returns : | an iconv converter for single byte encodings `codepage` -> utf8. Attempt to handle the semantics of a specification for multibyte encodings since this is only supposed to be used for single bytes.

### gsf_msole_iconv_win_codepage ()

    guint       gsf_msole_iconv_win_codepage    (void);

Returns : | our best guess at the applicable windows code page based on an environment variable or the current locale.

### gsf_msole_codepage_to_lid ()

    guint       gsf_msole_codepage_to_lid       (int codepage);

`codepage` : |
Returns : |

### gsf_msole_lid_to_codepage ()

    guint       gsf_msole_lid_to_codepage       (guint lid);

`lid` : |
Returns : | our best guess at the codepage for the given language id

### gsf_msole_lid_to_codepage_str ()

    gchar*      gsf_msole_lid_to_codepage_str   (guint lid);

`lid` : |
Returns : | the Iconv codepage string for the given LID. Return value must be `g_free()`'d

### gsf_msole_lid_for_language ()

    guint       gsf_msole_lid_for_language      (char const *lang);

`lang` : |
Returns : | the LID (Language Identifier) for the input language. If lang is `null`, return 0x0400 ("-none-"), and not 0x0000 ("no proofing")

### gsf_msole_inflate ()

    GByteArray* gsf_msole_inflate               (GsfInput *input,
                                                 gsf_off_t offset);

Decompresses an LZ compressed stream.

`input` : | stream to read from
`offset` : | offset into it for start byte of compresse stream
Returns : | A GByteArray that the caller is responsible for freeing

### OLE_HEADER_START_BAT

    #define OLE_HEADER_START_BAT	 0x4c

### OLE_HEADER_MAJOR_VER

    #define OLE_HEADER_MAJOR_VER	 0x1a	/* 0x3 been seen in wild */

### OLE_HEADER_METABAT_SIZE

    #define OLE_HEADER_METABAT_SIZE	 ((OLE_HEADER_SIZE - OLE_HEADER_START_BAT) / BAT_INDEX_SIZE)

### OLE_HEADER_DIRENT_START

    #define OLE_HEADER_DIRENT_START  0x30

### OLE_HEADER_NUM_SBAT

    #define OLE_HEADER_NUM_SBAT      0x40

### OLE_HEADER_BB_SHIFT

    #define OLE_HEADER_BB_SHIFT      0x1e

### OLE_HEADER_NUM_BAT

    #define OLE_HEADER_NUM_BAT	 0x2c

### OLE_HEADER_THRESHOLD

    #define OLE_HEADER_THRESHOLD	 0x38

### OLE_HEADER_METABAT_BLOCK

    #define OLE_HEADER_METABAT_BLOCK 0x44

### OLE_HEADER_SBAT_START

    #define OLE_HEADER_SBAT_START    0x3c

### OLE_HEADER_SIGNATURE

    #define OLE_HEADER_SIGNATURE	 0x00

### OLE_HEADER_BYTE_ORDER

    #define OLE_HEADER_BYTE_ORDER	 0x1c	/* 0xfe 0xff == Intel Little Endian */

### OLE_HEADER_SB_SHIFT

    #define OLE_HEADER_SB_SHIFT      0x20

### OLE_HEADER_NUM_METABAT

    #define OLE_HEADER_NUM_METABAT   0x48

### OLE_HEADER_SIZE

    #define OLE_HEADER_SIZE		 0x200	/* independent of big block size size */

### OLE_HEADER_CLSID

    #define OLE_HEADER_CLSID	 0x08	/* See ReadClassStg */

### OLE_HEADER_MINOR_VER

    #define OLE_HEADER_MINOR_VER	 0x18	/* 0x33 and 0x3e have been seen */

### OLE_DEFAULT_BB_SHIFT

    #define OLE_DEFAULT_BB_SHIFT	 9

### OLE_DEFAULT_SB_SHIFT

    #define OLE_DEFAULT_SB_SHIFT	 6

### DIRENT_DETAILS_SIZE

    #define DIRENT_DETAILS_SIZE	0x40

### DIRENT_SIZE

    #define DIRENT_SIZE		(DIRENT_MAX_NAME_SIZE + DIRENT_DETAILS_SIZE)

### DIRENT_NAME_LEN

    #define DIRENT_NAME_LEN		0x40	/* length in bytes incl 0 terminator */

### DIRENT_TYPE_PROPERTY

    #define DIRENT_TYPE_PROPERTY	4	/* ? */

### DIRENT_TYPE_FILE

    #define DIRENT_TYPE_FILE	2

### DIRENT_MAGIC_END

    #define DIRENT_MAGIC_END	0xffffffff

### DIRENT_TYPE_DIR

    #define DIRENT_TYPE_DIR		1

### DIRENT_MAX_NAME_SIZE

    #define DIRENT_MAX_NAME_SIZE	0x40

### DIRENT_FILE_SIZE

    #define DIRENT_FILE_SIZE	0x78

### DIRENT_FIRSTBLOCK

    #define DIRENT_FIRSTBLOCK	0x74

### DIRENT_TYPE_INVALID

    #define DIRENT_TYPE_INVALID	0

### DIRENT_USERFLAGS

    #define DIRENT_USERFLAGS	0x60	/* only for dirs */

### DIRENT_COLOUR

    #define DIRENT_COLOUR		0x43

### DIRENT_MODIFY_TIME

    #define DIRENT_MODIFY_TIME	0x6c	/* for files */

### DIRENT_TYPE_LOCKBYTES

    #define DIRENT_TYPE_LOCKBYTES	3	/* ? */

### DIRENT_CREATE_TIME

    #define DIRENT_CREATE_TIME	0x64	/* for files */

### DIRENT_PREV

    #define DIRENT_PREV		0x44

### DIRENT_NEXT

    #define DIRENT_NEXT		0x48

### DIRENT_CHILD

    #define DIRENT_CHILD		0x4c

### DIRENT_TYPE

    #define DIRENT_TYPE		0x42

### DIRENT_CLSID

    #define DIRENT_CLSID		0x50	/* only for dirs */

### DIRENT_TYPE_ROOTDIR

    #define DIRENT_TYPE_ROOTDIR	5

### BAT_MAGIC_METABAT

    #define BAT_MAGIC_METABAT	0xfffffffc	/* a metabat block -4 */

### BAT_MAGIC_BAT

    #define BAT_MAGIC_BAT		0xfffffffd	/* a bat block,    -3 */

### BAT_INDEX_SIZE

    #define BAT_INDEX_SIZE		 4

### BAT_MAGIC_END_OF_CHAIN

    #define BAT_MAGIC_END_OF_CHAIN	0xfffffffe	/*		   -2 */

### BAT_MAGIC_UNUSED

    #define BAT_MAGIC_UNUSED	0xffffffff	/*		   -1 */