klaola.h
1/* This file is part of the KDE project
2 Copyright (C) 1999 Werner Trobin <trobin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18
19DESCRIPTION
20
21 This class is used to decode OLE 2 streams. When instantiated, it
22 constructs an internal "filesystem" that corresponds to the OLE storage
23 tree. This tree can be navigated, and the individual OLE streams
24 returned as a linear memory buffer.
25*/
26
27#ifndef KLAOLA_H
28#define KLAOLA_H
29
30#include <myfile.h>
31#include <tqstring.h>
32#include <tqptrlist.h>
33
34class KLaola {
35
36public:
37 KLaola(const myFile &file); // see myfile.h!
38 ~KLaola();
39
40 bool isOk() {return ok;}
41
42 // A class representing an abstracted node in the OLE filesystem.
43
44 class OLENode {
45 public:
46 virtual ~OLENode() {};
47 virtual unsigned handle() const = 0;
48 virtual TQString name() const = 0;
49
50 // Does the node represent a stream datum, or a storage container
51 // of data?
52 virtual bool isDirectory() const = 0;
53
54 // If isDirectory() is true, return the CLSID associated with
55 // any child CompObj node. If the Node is a CompObj, return
56 // its CLSID. Otherwise return TQString().
57 //
58 // The CLSID is returned in the form:
59 //
60 // 00020900-0000-0000-C000-000000000046
61 //
62 virtual TQString readClassStream() const = 0;
63
64 // Return a human-readable description of a stream.
65 virtual TQString describe() const = 0;
66 protected:
67 OLENode() {}
68 };
69
70 // Wade through the "file system"
71
72 typedef TQPtrList<OLENode> NodeList;
73 NodeList parseRootDir();
74 NodeList parseCurrentDir();
75 const NodeList currentPath() const;
76 const NodeList find(const TQString &name, bool onlyCurrentDir=false);
77 bool enterDir(const OLENode *node);
78 bool leaveDir();
79
80 // Return the stream for a given node.
81 //
82 // Note: data - 512 byte blocks, but length is set correctly :)
83 myFile stream(const OLENode *node);
84 myFile stream(unsigned handle);
85
86private:
87 KLaola(const KLaola &);
88 const KLaola &operator=(const KLaola &);
89 static const int s_area;
90
91 unsigned char read8(int i) const;
92 unsigned short read16(int i) const;
93 unsigned int read32(int i) const;
94
95 // Parsing functions.
96 bool parseHeader();
97 void readBigBlockDepot();
98 void readSmallBlockDepot();
99 void readSmallBlockFile();
100 void readRootList();
101 void readPPSEntry(int pos, const int handle);
102 void createTree(const int handle, const short index);
103 const unsigned char *readBBStream(int start, bool setmaxSblock=false);
104 const unsigned char *readSBStream(int start) const;
105 int nextBigBlock(int pos) const;
106 int nextSmallBlock(int pos) const;
107
108 // Dump the parsed structure info (similar to "lls"
109 // of the LAOLA-project).
110 void testIt(TQString prefix = "");
111
112public:
113 typedef enum
114 {
115 DIRECTORY = 1,
116 FILE = 2,
117 ROOT_ENTRY = 5
118 } NodeType;
119
120 // If the first part of an on-disk name is less than 32, it is a prefix.
121 typedef enum
122 {
123 OLE_MANAGED_0,
124 CLSID,
125 OLE_MANAGED_2,
126 PARENT_MANAGED, // Marks an element as owned by the code that
127 // manages the parent storage of that element.
128 STRUCTURED_STORAGE, // For the exclusive use of the Structured Storage
129 // implementation.
130 RESERVED_FIRST,
131 RESERVED_LAST = 31,
132 NONE = 32
133 } Prefix;
134
135 class Node: public OLENode {
136 public:
137 Node(KLaola *laola) { m_laola = laola; }
138 ~Node() {}
139 unsigned handle() const { return m_handle; }
140 TQString name() const;
141 bool isDirectory() const { return (type == DIRECTORY) || (type == ROOT_ENTRY); }
142 TQString readClassStream() const;
143 TQString describe() const;
144
145 KLaola *m_laola;
146 unsigned m_handle; // PPS entry number
147 Prefix m_prefix;
148 TQString m_name;
149 NodeType type;
150 int prevHandle; // Last pps
151 int nextHandle; // Next pps
152 int dirHandle; // Dir pps
153 int ts1s; // Timestamp 1, seconds
154 int ts1d; // Timestamp 1, days
155 int ts2s; // Timestamp 2, seconds
156 int ts2d; // Timestamp 2, days
157 unsigned sb; // Starting block
158 unsigned size; // Size of property
159 bool deadDir; // true, if the dir is a "dead end"
160 };
161
162private:
163 // Lists of nodes.
164
165 NodeList m_nodeList;
166 NodeList m_currentPath;
167
168 // The OLE storage is represented as a tree. Each node in the tree may
169 // refer to a subtree. Each subtree is stored as a list of nodes.
170
171 struct TreeNode
172 {
173 Node *node;
174 short subtree;
175 };
176 typedef TQPtrList<TreeNode> SubTree;
177 TQPtrList<SubTree> m_nodeTree;
178
179 bool ok; // is the file OK?
180
181 myFile m_file;
182 unsigned char *bigBlockDepot;
183 unsigned char *smallBlockDepot;
184 unsigned char *smallBlockFile;
185
186 unsigned int maxblock; // maximum number of big-blocks
187 unsigned int maxSblock; // small-blocks
188 unsigned int num_of_bbd_blocks; // number of big block depot blocks
189 unsigned int root_startblock; // Root chain's first big block
190 unsigned int sbd_startblock; // small block depot's first big block
191 unsigned int *bbd_list; //array of num_of_bbd_blocks big block numbers
192};
193#endif // KLAOLA_H