1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/**
* ms-biff.h: MS Excel BIFF support for Gnumeric
*
* Author:
* Michael Meeks (michael@ximian.com)
*
* (C) 1998-2002 Michael Meeks
**/
#ifndef GNUMERIC_BIFF_H
#define GNUMERIC_BIFF_H
#include <gsf/gsf.h>
#include "rc4.h"
#include "md5.h"
typedef enum { MS_BIFF_CRYPTO_NONE = 0,
MS_BIFF_CRYPTO_XOR,
MS_BIFF_CRYPTO_RC4,
MS_BIFF_CRYPTO_UNKNOWN } MsBiffCrypto ;
typedef enum { MS_BIFF_V2 = 2,
MS_BIFF_V3 = 3,
MS_BIFF_V4 = 4,
MS_BIFF_V5 = 5, /* Excel 5.0 */
MS_BIFF_V7 = 7, /* Excel 95 */
MS_BIFF_V8 = 8, /* Excel 97 */
MS_BIFF_V_UNKNOWN = 0} MsBiffVersion ;
/*******************************************************************************/
/* Read Side */
/*******************************************************************************/
/**
* Returns query data, it is imperative that copies of
* 'data *' should _not_ be kept.
**/
typedef struct {
guint16 opcode;
guint32 length;
gboolean data_malloced, non_decrypted_data_malloced;
guint8 *data, *non_decrypted_data;
guint32 streamPos;
GsfInput *input;
MsBiffCrypto encryption;
guint8 xor_key[16];
RC4_KEY rc4_key;
MD5_CTX md5_ctxt;
int block;
gboolean dont_decrypt_next_record;
} BiffQuery;
/* Sets up a query on a stream */
BiffQuery *ms_biff_query_new (GsfInput *);
gboolean ms_biff_query_set_decrypt (BiffQuery *q, MsBiffVersion version,
char const *password);
/* Updates the BiffQuery structure with the next BIFF record
* returns: TRUE for succes, and FALSE for EOS(tream) */
gboolean ms_biff_query_next (BiffQuery *);
gboolean ms_biff_query_peek_next (BiffQuery *, guint16 *opcode);
void ms_biff_query_destroy (BiffQuery *);
void ms_biff_query_dump (BiffQuery *);
guint32 ms_biff_query_bound_check (BiffQuery *q,
guint32 offset, unsigned len);
/*******************************************************************************/
/* Write Side */
/*******************************************************************************/
typedef struct _BiffPut {
guint16 opcode;
guint32 length; /* NB. can be extended by a continue opcode */
guint8 *data;
int streamPos;
unsigned curpos; /* Curpos is offset from beginning of header */
gboolean data_malloced;
int len_fixed;
GsfOutput *output;
MsBiffVersion version;
/* a buffer for generating unicode */
char *buf;
unsigned buf_len;
unsigned codepage;
GIConv convert;
} BiffPut;
/* Sets up a record on a stream */
BiffPut *ms_biff_put_new (GsfOutput *, MsBiffVersion version, int codepage);
void ms_biff_put_destroy (BiffPut *bp);
/**
* If between the 'next' and 'commit' ls / ms_op are changed they will be
* written correctly.
**/
/* For known length records shorter than 0x2000 bytes. */
guint8 *ms_biff_put_len_next (BiffPut *bp, guint16 opcode, guint32 len);
/* For unknown length records */
void ms_biff_put_var_next (BiffPut *bp, guint16 opcode);
void ms_biff_put_var_write (BiffPut *bp, guint8 const *dat, guint32 len);
/* Seeks to pos bytes after the beggining of the record */
void ms_biff_put_var_seekto (BiffPut *bp, int pos);
/* Must commit after each record */
void ms_biff_put_commit (BiffPut *bp);
/* convenience routines for simple records */
void ms_biff_put_empty (BiffPut *bp, guint16 opcode);
void ms_biff_put_2byte (BiffPut *bp, guint16 opcode, guint16 data);
unsigned ms_biff_max_record_len (BiffPut const *bp);
#endif /* GNUMERIC_BIFF_H */
|