filters

klaola.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 Werner Trobin <trobin@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 
00019 DESCRIPTION
00020 
00021     This class is used to decode OLE 2 streams. When instantiated, it
00022     constructs an internal "filesystem" that corresponds to the OLE storage
00023     tree. This tree can be navigated, and the individual OLE streams
00024     returned as a linear memory buffer.
00025 */
00026 
00027 #ifndef KLAOLA_H
00028 #define KLAOLA_H
00029 
00030 #include <myfile.h>
00031 #include <qstring.h>
00032 #include <qptrlist.h>
00033 
00034 class KLaola {
00035 
00036 public:
00037     KLaola(const myFile &file);               // see myfile.h!
00038     ~KLaola();
00039 
00040     bool isOk() {return ok;}
00041 
00042     // A class representing an abstracted node in the OLE filesystem.
00043 
00044     class OLENode {
00045     public:
00046         virtual ~OLENode() {};
00047         virtual unsigned handle() const = 0;
00048         virtual QString name() const = 0;
00049 
00050         // Does the node represent a stream datum, or a storage container
00051         // of data?
00052         virtual bool isDirectory() const = 0;
00053 
00054         // If isDirectory() is true, return the CLSID associated with
00055         // any child CompObj node. If the Node is a CompObj, return
00056         // its CLSID. Otherwise return QString::null.
00057         //
00058         // The CLSID is returned in the form:
00059         //
00060         //  00020900-0000-0000-C000-000000000046
00061         //
00062         virtual QString readClassStream() const = 0;
00063 
00064         // Return a human-readable description of a stream.
00065         virtual QString describe() const = 0;
00066     protected:
00067         OLENode() {}
00068     };
00069 
00070     // Wade through the "file system"
00071 
00072     typedef QPtrList<OLENode> NodeList;
00073     NodeList parseRootDir();
00074     NodeList parseCurrentDir();
00075     const NodeList currentPath() const;
00076     const NodeList find(const QString &name, bool onlyCurrentDir=false);
00077     bool enterDir(const OLENode *node);
00078     bool leaveDir();
00079 
00080     // Return the stream for a given node.
00081     //
00082     // Note: data - 512 byte blocks, but length is set correctly :)
00083     myFile stream(const OLENode *node);
00084     myFile stream(unsigned handle);
00085 
00086 private:
00087     KLaola(const KLaola &);
00088     const KLaola &operator=(const KLaola &);
00089     static const int s_area;
00090 
00091     unsigned char read8(int i) const;
00092     unsigned short read16(int i) const;
00093     unsigned int read32(int i) const;
00094 
00095     // Parsing functions.
00096     bool parseHeader();
00097     void readBigBlockDepot();
00098     void readSmallBlockDepot();
00099     void readSmallBlockFile();
00100     void readRootList();
00101     void readPPSEntry(int pos, const int handle);
00102     void createTree(const int handle, const short index);
00103     const unsigned char *readBBStream(int start, bool setmaxSblock=false);
00104     const unsigned char *readSBStream(int start) const;
00105     int nextBigBlock(int pos) const;
00106     int nextSmallBlock(int pos) const;
00107 
00108     // Dump the parsed structure info (similar to "lls"
00109     // of the LAOLA-project).
00110     void testIt(QString prefix = "");
00111 
00112 public:
00113     typedef enum
00114     {
00115         DIRECTORY = 1,
00116         FILE = 2,
00117         ROOT_ENTRY = 5
00118     } NodeType;
00119 
00120     // If the first part of an on-disk name is less than 32, it is a prefix.
00121     typedef enum
00122     {
00123         OLE_MANAGED_0,
00124         CLSID,
00125         OLE_MANAGED_2,
00126         PARENT_MANAGED,         // Marks an element as owned by the code that
00127                                 // manages the parent storage of that element.
00128         STRUCTURED_STORAGE,     // For the exclusive use of the Structured Storage
00129                                 // implementation.
00130         RESERVED_FIRST,
00131         RESERVED_LAST = 31,
00132         NONE = 32
00133     } Prefix;
00134 
00135     class Node: public OLENode {
00136     public:
00137         Node(KLaola *laola) { m_laola = laola; }
00138         ~Node() {}
00139         unsigned handle() const { return  m_handle; }
00140         QString name() const;
00141         bool isDirectory() const { return (type == DIRECTORY) || (type == ROOT_ENTRY); }
00142         QString readClassStream() const;
00143         QString describe() const;
00144 
00145         KLaola *m_laola;
00146         unsigned m_handle;       // PPS entry number
00147         Prefix m_prefix;
00148         QString m_name;
00149         NodeType type;
00150         int prevHandle;   // Last pps
00151         int nextHandle;   // Next pps
00152         int dirHandle;    // Dir pps
00153         int ts1s;         // Timestamp 1, seconds
00154         int ts1d;         // Timestamp 1, days
00155         int ts2s;         // Timestamp 2, seconds
00156         int ts2d;         // Timestamp 2, days
00157         unsigned sb;      // Starting block
00158         unsigned size;    // Size of property
00159         bool deadDir;     // true, if the dir is a "dead end"
00160     };
00161 
00162 private:
00163     // Lists of nodes.
00164 
00165     NodeList m_nodeList;
00166     NodeList m_currentPath;
00167 
00168     // The OLE storage is represented as a tree. Each node in the tree may
00169     // refer to a subtree. Each subtree is stored as a list of nodes.
00170 
00171     struct TreeNode
00172     {
00173         Node *node;
00174         short subtree;
00175     };
00176     typedef QPtrList<TreeNode> SubTree;
00177     QPtrList<SubTree> m_nodeTree;
00178 
00179     bool ok;        // is the file OK?
00180 
00181     myFile m_file;
00182     unsigned char *bigBlockDepot;
00183     unsigned char *smallBlockDepot;
00184     unsigned char *smallBlockFile;
00185 
00186     unsigned int maxblock;          // maximum number of big-blocks
00187     unsigned int maxSblock;         //                   small-blocks
00188     unsigned int num_of_bbd_blocks; // number of big block depot blocks
00189     unsigned int root_startblock;   // Root chain's first big block
00190     unsigned int sbd_startblock;    // small block depot's first big block
00191     unsigned int *bbd_list;         //array of num_of_bbd_blocks big block numbers
00192 };
00193 #endif // KLAOLA_H
KDE Home | KDE Accessibility Home | Description of Access Keys