Commit 2e4cab81 authored by Michael Meeks's avatar Michael Meeks
Browse files

remove 'ole' ( its in module libole2 now ),

fix Makefile.
parent 0a05d6ab
1999-09-26 Michael Meeks <michael@nuclecu.unam.mx>
* Makefile.am: remove the 'ole' test program
* ole.c: Removed, see module libole2 in test/test-ole.
* ms-escher.c (ms_escher_read_ClientData): Remove realize & queue
objects instead. Add precondition on state->sheet.
......
......@@ -37,17 +37,4 @@ libexcel_a_SOURCES = \
ms-summary.c \
ms-summary.h
noinst_PROGRAMS = \
ole
ole_SOURCES = \
ms-biff.c \
ole.c
ole_LDADD = \
libole2/libole2.a \
$(GNOME_LIBDIR) \
$(GNOME_LIBS) \
$(INTLLIBS)
SUBDIRS = libole2
/**
* ole.c: OLE2 file format helper program,
* good for dumping OLE streams, and
* corresponding biff records, and hopefuly
* some more ...
*
* Author:
* Michael Meeks (michael@imaginator.com)
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "ms-ole.h"
#include "ms-ole-summary.h"
#define BIFF_TYPES_FILE "biff-types.h"
static char delim[]=" \t\n";
typedef struct {
guint16 opcode;
char *name;
} GENERIC_TYPE;
static GPtrArray *biff_types = NULL;
static char *cur_dir = NULL;
static void dump_vba (MsOle *f);
static void
read_types (char *fname, GPtrArray **types)
{
FILE *file = fopen(fname, "r");
char buffer[1024];
*types = g_ptr_array_new ();
if (!file) {
char *newname = g_strconcat ("../", fname, NULL);
file = fopen (newname, "r");
}
if (!file) {
printf ("Can't find vital file '%s'\n", fname);
return;
}
while (!feof(file)) {
char *p;
fgets(buffer,1023,file);
for (p=buffer;*p;p++)
if (*p=='0' && *(p+1)=='x') {
GENERIC_TYPE *bt = g_new (GENERIC_TYPE,1);
char *name, *pt;
bt->opcode=strtol(p+2,0,16);
pt = buffer;
while (*pt && *pt != '#') pt++; /* # */
while (*pt && !isspace(*pt)) pt++; /* define */
while (*pt && isspace(*pt)) pt++; /* ' ' */
while (*pt && *pt != '_') pt++; /* BIFF_ */
name = *pt?pt+1:pt;
while (*pt && !isspace(*pt)) pt++;
bt->name=g_strndup(name, (pt-name));
g_ptr_array_add (*types, bt);
break;
}
}
fclose (file);
}
static char*
get_biff_opcode_name (guint16 opcode)
{
int lp;
if (!biff_types)
read_types (BIFF_TYPES_FILE, &biff_types);
/* Count backwars to give preference to non-filtered record types */
for (lp=biff_types->len; --lp >= 0 ;) {
GENERIC_TYPE *bt = g_ptr_array_index (biff_types, lp);
if (bt->opcode>0xff) {
if (bt->opcode == opcode)
return bt->name;
} else {
if (bt->opcode == (opcode&0xff))
return bt->name;
}
}
return "Unknown";
}
static void
list_files (MsOle *ole)
{
char **names;
MsOleErr result;
int lp;
result = ms_ole_directory (&names, ole, cur_dir);
if (result != MS_OLE_ERR_OK) {
g_warning ("Failed dir");
return;
}
if (!names[0])
g_warning ("You entered a file !");
for (lp = 0; names[lp]; lp++) {
MsOleStat s;
result = ms_ole_stat (&s, ole, cur_dir, names[lp]);
if (s.type == MsOleStreamT)
printf ("'%25s : length %d bytes\n", names[lp], s.size);
else
printf ("'[%s] : Storage ( directory )\n", names [lp]);
}
}
static void
list_commands ()
{
printf ("command can be one or all of:\n");
printf (" * ls: list files\n");
printf (" * cd: enter storage\n");
printf (" * biff <stream name>: dump biff records, merging continues\n");
printf (" * biffraw <stream name>: dump biff records no merge + raw data\n");
printf (" * dump <stream name>: dump stream\n");
printf (" * summary : dump document summary info\n");
printf (" * debug : dump internal ole library status\n");
printf (" * vba : attempt to dump vba \n");
printf (" Raw transfer commands\n");
printf (" * get <stream name> <fname>\n");
printf (" * put <fname> <stream name>\n");
printf (" * copyin [<fname>,]...\n");
printf (" * copyout [<fname>,]...\n");
printf (" * quit,exit,bye: exit\n");
}
static void
syntax_error(char *err)
{
if (err) {
printf("Error; '%s'\n",err);
exit(1);
}
printf ("Sytax:\n");
printf (" ole <ole-file> [-i] [commands...]\n\n");
printf (" -i: Interactive, queries for fresh commands\n\n");
list_commands ();
exit(1);
}
/* ---------------------------- End cut ---------------------------- */
static void
enter_dir (MsOle *ole)
{
char *newpath, *ptr;
ptr = strtok (NULL, delim);
if (!ptr) {
printf ("Takes a directory argument\n");
return;
}
if (!g_strcasecmp (ptr, "..")) {
guint lp;
char **tmp;
GString *newp = g_string_new ("");
tmp = g_strsplit (cur_dir, "/", -1);
lp = 0;
if (!tmp[lp])
return;
while (tmp[lp+1]) {
g_string_sprintfa (newp, "%s/", tmp[lp]);
lp++;
}
g_free (cur_dir);
cur_dir = newp->str;
g_string_free (newp, FALSE);
} else {
MsOleStat s;
MsOleErr result;
newpath = g_strconcat (cur_dir, ptr, "/", NULL);
result = ms_ole_stat (&s, ole, newpath, "");
if (result == MS_OLE_ERR_EXIST) {
printf ("Storage '%s' not found\n", ptr);
g_free (newpath);
return;
}
if (result != MS_OLE_ERR_OK) {
g_warning ("internal error");
g_free (newpath);
return;
}
if (s.type == MsOleStreamT) {
printf ("Trying to enter a stream. (%d)\n", s.type);
g_free (newpath);
return;
}
g_free (cur_dir);
cur_dir = newpath;
}
}
static void
do_dump (MsOle *ole)
{
char *ptr;
MsOleStream *stream;
guint8 *buffer;
ptr = strtok (NULL, delim);
if (!ptr) {
printf ("Need a stream name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, ptr, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", ptr);
return;
}
buffer = g_malloc (stream->size);
stream->read_copy (stream, buffer, stream->size);
printf ("Stream : '%s' length 0x%x\n", ptr, stream->size);
if (buffer)
dump (buffer, stream->size);
else
printf ("Failed read\n");
ms_ole_stream_close (&stream);
}
/*
* This is a massively cut down version ...
*/
typedef struct {
guint16 opcode;
guint32 length; /* NB. can be extended by a continue opcode */
guint8 *data;
guint32 streamPos;
MsOleStream *pos;
} BiffQuery;
static BiffQuery *
ms_biff_query_new (MsOleStream *ptr)
{
BiffQuery *bq ;
if (!ptr)
return 0;
bq = g_new0 (BiffQuery, 1);
bq->opcode = 0;
bq->length = 0;
bq->pos = ptr;
return bq;
}
static int
ms_biff_query_next (BiffQuery *bq)
{
guint8 tmp[4];
int ans=1;
if (!bq || bq->pos->position >= bq->pos->size)
return 0;
if (bq->data)
g_free (bq->data);
bq->streamPos = bq->pos->position;
if (!bq->pos->read_copy (bq->pos, tmp, 4))
return 0;
bq->opcode = MS_OLE_GET_GUINT16 (tmp);
bq->length = MS_OLE_GET_GUINT16 (tmp+2);
if (bq->length > 0) {
bq->data = g_new0 (guint8, bq->length);
if (!bq->pos->read_copy(bq->pos, bq->data, bq->length)) {
ans = 0;
g_free (bq->data);
bq->length = 0;
}
}
if (!bq->length) {
bq->data = NULL;
return 1;
}
return (ans);
}
static void
do_biff (MsOle *ole)
{
char *ptr;
MsOleStream *stream;
ptr = strtok (NULL, delim);
if (!ptr) {
printf ("Need a stream name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, ptr, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", ptr);
return;
}
{
BiffQuery *q = ms_biff_query_new (stream);
guint16 last_opcode=0xffff;
guint32 last_length=0;
guint32 count=0;
while (ms_biff_query_next(q)) {
if (q->opcode == last_opcode &&
q->length == last_length)
count++;
else {
if (count>0)
printf (" x %d\n", count+1);
else
printf ("\n");
count=0;
printf ("Opcode 0x%3x : %15s, length %d",
q->opcode, get_biff_opcode_name (q->opcode), q->length);
}
last_opcode=q->opcode;
last_length=q->length;
}
printf ("\n");
ms_ole_stream_close (&stream);
}
}
static void
do_biff_raw (MsOle *ole)
{
char *ptr;
MsOleStream *stream;
ptr = strtok (NULL, delim);
if (!ptr) {
printf ("Need a stream name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, ptr, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", ptr);
return;
}
{
guint8 data[4], *buffer;
buffer = g_new (guint8, 65550);
while (stream->read_copy (stream, data, 4)) {
guint32 len=MS_OLE_GET_GUINT16(data+2);
/* printf ("0x%4x Opcode 0x%3x : %15s, length 0x%x (=%d)\n", stream->position,
MS_OLE_GET_GUINT16(data), get_biff_opcode_name (MS_OLE_GET_GUINT16(data)),
len, len);*/
printf ("Opcode 0x%3x : %15s, length 0x%x (=%d)\n",
MS_OLE_GET_GUINT16(data), get_biff_opcode_name (MS_OLE_GET_GUINT16(data)),
len, len);
stream->read_copy (stream, buffer, len);
dump (buffer, len);
buffer[0]=0;
buffer[len-1]=0;
}
ms_ole_stream_close (&stream);
}
}
static void
really_get (MsOle *ole, char *from, char *to)
{
MsOleStream *stream;
if (ms_ole_stream_open (&stream, ole, cur_dir, from, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", from);
return;
} else {
guint8 *buffer = g_malloc (stream->size);
FILE *f = fopen (to, "w");
stream->read_copy (stream, buffer, stream->size);
printf ("Stream : '%s' length 0x%x\n", from, stream->size);
if (f && buffer) {
fwrite (buffer, 1, stream->size, f);
fclose (f);
} else
printf ("Failed write to '%s'\n", to);
ms_ole_stream_close (&stream);
}
}
static void
do_get (MsOle *ole)
{
char *from, *to;
from = strtok (NULL, delim);
to = strtok (NULL, delim);
really_get (ole, from, to);
}
static void
really_put (MsOle *ole, char *from, char *to)
{
MsOleStream *stream;
char buffer[8200];
if (!from || !to) {
printf ("Null name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, to, 'w') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", to);
return;
} else {
FILE *f = fopen (from, "r");
size_t len;
int block=0;
if (!f || !stream) {
printf ("Failed write\n");
return;
}
stream->lseek (stream, 0, MsOleSeekSet);
do {
guint32 lenr = 1+ (int)(8192.0*rand()/(RAND_MAX+1.0));
len = fread (buffer, 1, lenr, f);
printf ("Transfering block %d = %d bytes\n", block++, len);
stream->write (stream, buffer, len);
} while (!feof(f) && len>0);
fclose (f);
ms_ole_stream_close (&stream);
}
}
static void
do_summary (MsOle *ole)
{
MsOleSummary *si;
MsOleSummaryPreview preview;
gboolean ok;
gchar *txt;
guint32 num;
si = ms_ole_summary_open (ole);
if (!si) {
printf ("No summary information\n");
return;
}
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_TITLE, &ok);
if (ok)
printf ("The title is %s\n", txt);
else
printf ("no title found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_SUBJECT, &ok);
if (ok)
printf ("The subject is %s\n", txt);
else
printf ("no subject found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_AUTHOR, &ok);
if (ok)
printf ("The author is %s\n", txt);
else
printf ("no author found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_KEYWORDS, &ok);
if (ok)
printf ("The keywords are %s\n", txt);
else
printf ("no keywords found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_COMMENTS, &ok);
if (ok)
printf ("The comments are %s\n", txt);
else
printf ("no comments found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_TEMPLATE, &ok);
if (ok)
printf ("The template was %s\n", txt);
else
printf ("no template found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_LASTAUTHOR, &ok);
if (ok)
printf ("The last author was %s\n", txt);
else
printf ("no last author found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_REVNUMBER, &ok);
if (ok)
printf ("The rev no was %s\n", txt);
else
printf ("no rev no found\n");
g_free (txt);
txt = ms_ole_summary_get_string (si, MS_OLE_SUMMARY_APPNAME, &ok);
if (ok)
printf ("The app name was %s\n", txt);
else
printf ("no app name found\n");
g_free (txt);
/* txt = wvSumInfoGetTime(&yr, &mon, &day, &hr, &min, &sec,PID_TOTAL_EDITTIME,&si);
if (ok)
printf ("Total edit time was %d/%d/%d %d:%d:%d\n",day,mon,yr,hr,min,sec);
else
printf ("no total edit time found\n");
g_free (txt);
txt = wvSumInfoGetTime(&yr, &mon, &day, &hr, &min, &sec,PID_LASTPRINTED,&si);
if (ok)
printf ("Last printed on %d/%d/%d %d:%d:%d\n",day,mon,yr,hr,min,sec);
else
printf ("no last printed time found\n");
txt = wvSumInfoGetTime(&yr, &mon, &day, &hr, &min, &sec,PID_CREATED,&si);
if (ok)
printf ("Created on %d/%d/%d %d:%d:%d\n",day,mon,yr,hr,min,sec);
else
printf ("no creation time found\n");
txt = wvSumInfoGetTime(&yr, &mon, &day, &hr, &min, &sec,PID_LASTSAVED,&si);
if (ok)
printf ("Last Saved on %d/%d/%d %d:%d:%d\n",day,mon,yr,hr,min,sec);
else
printf ("no lastsaved date found\n");*/
num = ms_ole_summary_get_long (si, MS_OLE_SUMMARY_PAGECOUNT, &ok);
if (ok)
printf ("PageCount is %d\n", num);
else
printf ("no pagecount\n");
num = ms_ole_summary_get_long (si, MS_OLE_SUMMARY_WORDCOUNT, &ok);
if (ok)
printf ("WordCount is %d\n", num);
else
printf ("no wordcount\n");
num = ms_ole_summary_get_long (si, MS_OLE_SUMMARY_CHARCOUNT, &ok);
if (ok)
printf ("CharCount is %d\n", num);
else
printf ("no charcount\n");
num = ms_ole_summary_get_long (si, MS_OLE_SUMMARY_SECURITY, &ok);
if (ok)
printf ("Security is %d\n", num);
else
printf ("no security\n");
preview = ms_ole_summary_get_preview (si, MS_OLE_SUMMARY_THUMBNAIL, &ok);
if (ok) {
printf ("preview is %d bytes long\n", preview.len);
ms_ole_summary_preview_destroy (preview);
} else
printf ("no preview found\n");
ms_ole_summary_close (si);
}
static void
do_put (MsOle *ole)
{
char *from, *to;
from = strtok (NULL, delim);
to = strtok (NULL, delim);
if (!from || !to) {
printf ("put <