[Libreoffice-commits] .: src/olestream.py xls-dump.py

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Apr 11 20:07:46 PDT 2011


 src/olestream.py |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xls-dump.py      |    9 +++--
 2 files changed, 89 insertions(+), 4 deletions(-)

New commits:
commit 805a172756f7a7ea757f83ee0907f6393a7a5263
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Mon Apr 11 23:05:05 2011 -0400

    First cut on parsing OLEStream.
    
    But some things aren't right, as I'm not getting the info I expect.
    I need to work on improving this (if I can).

diff --git a/src/olestream.py b/src/olestream.py
new file mode 100644
index 0000000..a073406
--- /dev/null
+++ b/src/olestream.py
@@ -0,0 +1,84 @@
+########################################################################
+#
+#  Copyright (c) 2011 Kohei Yoshida
+#  
+#  Permission is hereby granted, free of charge, to any person
+#  obtaining a copy of this software and associated documentation
+#  files (the "Software"), to deal in the Software without
+#  restriction, including without limitation the rights to use,
+#  copy, modify, merge, publish, distribute, sublicense, and/or sell
+#  copies of the Software, and to permit persons to whom the
+#  Software is furnished to do so, subject to the following
+#  conditions:
+#  
+#  The above copyright notice and this permission notice shall be
+#  included in all copies or substantial portions of the Software.
+#  
+#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+#  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+#  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+#  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+#  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+#  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+#  OTHER DEALINGS IN THE SOFTWARE.
+#
+########################################################################
+
+import sys
+import globals
+
+class MonikerStream(object):
+    def __init__ (self, bytes):
+        self.strm = globals.ByteStream(bytes)
+
+    def read (self):
+        print ("moniker size: %d"%(len(self.strm.bytes)-16))
+        clsID = self.strm.readBytes(16)
+        print ("CLS ID: %s"%globals.getRawBytes(clsID, True, False))
+        print ("stream data (implemention specific):")
+        globals.dumpBytes(self.strm.readRemainingBytes())
+        print ("")
+
+class OLEStream(object):
+
+    def __init__ (self, bytes):
+        self.strm = globals.ByteStream(bytes)
+
+    def read (self):
+        ver = self.strm.readUnsignedInt(4)
+        print ("version: 0x%8.8X"%ver)
+        flags = self.strm.readUnsignedInt(4)
+        print ("flags: %d"%flags)
+        linkUpdateOption = self.strm.readUnsignedInt(4)
+        print ("link update option: %d"%linkUpdateOption)
+        reserved = self.strm.readUnsignedInt(4)
+        print ("")
+
+        # Reserved moniker (must be ignored)
+        monikerSize = self.strm.readUnsignedInt(4)
+        if monikerSize > 0:
+            strm = MonikerStream(self.strm.readBytes(monikerSize+16))
+            strm.read()
+
+        # Relative source moniker (relative path to the linked object)
+        monikerSize = self.strm.readUnsignedInt(4)
+        if monikerSize > 0:
+            strm = MonikerStream(self.strm.readBytes(monikerSize+16))
+            strm.read()
+
+        # Absolute source moniker (absolute path to the linked object)
+        monikerSize = self.strm.readUnsignedInt(4)
+        if monikerSize > 0:
+            strm = MonikerStream(self.strm.readBytes(monikerSize+16))
+            strm.read()
+
+        clsIDIndicator = self.strm.readSignedInt(4)
+        print ("cls ID indicator: %d"%clsIDIndicator)
+        clsID = self.strm.readBytes(16)
+        print ("CLS ID: %s"%globals.getRawBytes(clsID, True, False))
+#       globals.dumpBytes(self.strm.bytes, 512)
+
+
+
+
diff --git a/xls-dump.py b/xls-dump.py
index 7864b99..18e75a9 100755
--- a/xls-dump.py
+++ b/xls-dump.py
@@ -28,14 +28,14 @@
 
 import sys, os.path, optparse
 sys.path.append(sys.path[0]+"/src")
-import ole, xlsstream, globals, node, xlsmodel
+import ole, xlsstream, globals, node, xlsmodel, olestream
 
 from globals import error
 
 def isOleStream (dirname):
     """Determine whether or not a stream is an OLE stream.
 
-Accodring to the spec, an OLE stream is always named 0x1,'O','l','e'."""
+Accodring to the spec, an OLE stream is always named '\1Ole'."""
 
     name = [0x01, 0x4F, 0x6C, 0x65] # 0x01, 'O', 'l', 'e'
     if len(dirname) != len(name):
@@ -147,8 +147,9 @@ class XLDumper(object):
         except xlsstream.EndOfStream:
             return False
 
-    def __readOleStream (self, strm):
-        globals.dumpBytes(strm.bytes, 512)
+    def __readOleStream (self, dirstrm):
+        strm = olestream.OLEStream(dirstrm.bytes)
+        strm.read()
 
     def __readSubStreamXML (self, strm):
         try:


More information about the Libreoffice-commits mailing list