[Libreoffice-commits] .: src/olestream.py xls-dump.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Apr 11 22:10:52 PDT 2011
src/olestream.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
xls-dump.py | 29 +++++++++++++++------
2 files changed, 95 insertions(+), 8 deletions(-)
New commits:
commit 34b65645ed664fa0a95f182233177c861041ac89
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Tue Apr 12 01:08:43 2011 -0400
Parse \1CompObj stream.
This tream contains info about clipboard format.
diff --git a/src/olestream.py b/src/olestream.py
index a073406..d266f80 100644
--- a/src/olestream.py
+++ b/src/olestream.py
@@ -28,6 +28,8 @@
import sys
import globals
+class CompObjStreamError(Exception): pass
+
class MonikerStream(object):
def __init__ (self, bytes):
self.strm = globals.ByteStream(bytes)
@@ -79,6 +81,78 @@ class OLEStream(object):
print ("CLS ID: %s"%globals.getRawBytes(clsID, True, False))
# globals.dumpBytes(self.strm.bytes, 512)
+class CompObjStream(object):
+
+ def __init__ (self, bytes):
+ self.strm = globals.ByteStream(bytes)
+
+ def read (self):
+ # CompObjHeader
+ reserved = self.strm.readBytes(4)
+ ver = self.strm.readUnsignedInt(4)
+ reserved = self.strm.readBytes(20)
+ print ("version: 0x%4.4X"%ver)
+
+ # LengthPrefixedAnsiString
+ length = self.strm.readUnsignedInt(4)
+ displayName = self.strm.readBytes(length)
+ if ord(displayName[-1]) != 0x00:
+ # must be null-terminated.
+ raise CompObjStreamError()
+
+ print ("display name: " + displayName[:-1])
+
+ # ClipboardFormatOrAnsiString
+ marker = self.strm.readUnsignedInt(4)
+ if marker == 0:
+ # Don't do anything.
+ pass
+ elif marker == 0xFFFFFFFF or marker == 0xFFFFFFFE:
+ clipFormatID = self.strm.readUnsignedInt(4)
+ print ("clipboard format ID: %d"%clipFormatID)
+ else:
+ clipName = self.strm.readBytes(marker)
+ if ord(clipName[-1]) != 0x00:
+ # must be null-terminated.
+ raise CompObjStreamError()
+ print ("clipboard format name: %s"%clipName[:-1])
+
+ # LengthPrefixedAnsiString
+ length = self.strm.readUnsignedInt(4)
+ if length == 0 or length > 0x00000028:
+ # the spec says this stream is now invalid.
+ raise CompObjStreamError()
+
+ reserved = self.strm.readBytes(length)
+ if ord(reserved[-1]) != 0x00:
+ # must be null-terminated.
+ raise CompObjStreamError()
+
+ print ("reserved name : %s"%reserved[:-1])
+ unicodeMarker = self.strm.readUnsignedInt(4)
+ if unicodeMarker != 0x71B239F4:
+ raise CompObjStreamError()
+
+ # LengthPrefixedUnicodeString
+ length = self.strm.readUnsignedInt(4)
+ if length > 0:
+ s = globals.getUTF8FromUTF16(self.strm.readBytes(length*2))
+ print ("display name (unicode): %s"%s)
+
+ # ClipboardFormatOrAnsiString
+ marker = self.strm.readUnsignedInt(4)
+ if marker == 0:
+ # Don't do anything.
+ pass
+ elif marker == 0xFFFFFFFF or marker == 0xFFFFFFFE:
+ clipFormatID = self.strm.readUnsignedInt(4)
+ print ("clipboard format ID: %d"%clipFormatID)
+ else:
+ clipName = globals.getUTF8FromUTF16(self.strm.readBytes(marker*2))
+ if ord(clipName[-1]) != 0x00:
+ # must be null-terminated.
+ raise CompObjStreamError()
+ print ("clipboard format name: %s"%clipName[:-1])
diff --git a/xls-dump.py b/xls-dump.py
index ca3e8c0..e2c6bbe 100755
--- a/xls-dump.py
+++ b/xls-dump.py
@@ -32,20 +32,27 @@ import ole, xlsstream, globals, node, xlsmodel, olestream
from globals import error
+def equalsName (name, array):
+ if len(name) != len(array):
+ return False
+
+ for i in xrange(0, len(name)):
+ if ord(name[i]) != array[i]:
+ return False
+
+ return True
+
def isOleStream (dirname):
"""Determine whether or not a stream is an OLE stream.
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):
- return False
-
- for i in xrange(0, len(dirname)):
- if ord(dirname[i]) != name[i]:
- return False
+ name = [0x01, 0x4F, 0x6C, 0x65] # 0x01, 'Ole'
+ return equalsName(dirname, name)
- return True
+def isCompObjStream (dirname):
+ name = [0x01, 0x43, 0x6F, 0x6D, 0x70, 0x4F, 0x62, 0x6A] # 0x01, 'CompObj'
+ return equalsName(dirname, name)
class XLDumper(object):
@@ -134,6 +141,8 @@ class XLDumper(object):
self.__readSubStream(dirstrm)
elif isOleStream(dirname):
self.__readOleStream(dirstrm)
+ elif isCompObjStream(dirname):
+ self.__readCompObjStream(dirstrm)
else:
globals.dumpBytes(dirstrm.bytes, 512)
@@ -151,6 +160,10 @@ class XLDumper(object):
strm = olestream.OLEStream(dirstrm.bytes)
strm.read()
+ def __readCompObjStream (self, dirstrm):
+ strm = olestream.CompObjStream(dirstrm.bytes)
+ strm.read()
+
def __readSubStreamXML (self, strm):
try:
while True:
More information about the Libreoffice-commits
mailing list