[Libreoffice-commits] mso-dumper.git: .gitignore Makefile msodumper/swlaycacherecord.py swlaycache-dump.py

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Sep 12 09:43:32 UTC 2018


 .gitignore                    |    1 
 Makefile                      |    1 
 msodumper/swlaycacherecord.py |   81 ++++++++++++++++++++++++++++++++++++++++++
 swlaycache-dump.py            |   33 +++++++++++++++++
 4 files changed, 116 insertions(+)

New commits:
commit 6de82e66a940e6438f1b567f56d720743f650fda
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Wed Sep 12 11:39:04 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Wed Sep 12 11:42:42 2018 +0200

    Add a dumper for the Writer binary layout cache
    
    It's not a Microsoft format, but we have an easy to use framework here
    to inspect binary files...
    
    (This is the layout-cache stream in ODT files, if it's there.)

diff --git a/.gitignore b/.gitignore
index 0d20b64..d18402d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 *.pyc
+.*.swp
diff --git a/Makefile b/Makefile
index 8fb1a68..badc2f5 100644
--- a/Makefile
+++ b/Makefile
@@ -5,3 +5,4 @@ check:
 	pep8 --ignore=E501 doc-dump.py msodumper/doc{record,sprm,stream}.py test/doc/test.py
 	pep8 --ignore=E501 emf-dump.py msodumper/{emf,wmf}record.py
 	pep8 --ignore=E501 vsd-dump.py msodumper/vsdstream.py test/vsd-test.py
+	pycodestyle --ignore=E501 swlaycache-dump.py msodumper/swlaycacherecord.py
diff --git a/msodumper/swlaycacherecord.py b/msodumper/swlaycacherecord.py
new file mode 100644
index 0000000..dac75e4
--- /dev/null
+++ b/msodumper/swlaycacherecord.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python3
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from .binarystream import BinaryStream
+
+
+class SwLayCacheStream(BinaryStream):
+    def __init__(self, bytes):
+        BinaryStream.__init__(self, bytes)
+
+    def dump(self):
+        print('<stream type="SwLayCache" size="%d">' % self.size)
+        posOrig = self.pos
+        header = Header(self)
+        header.dump()
+
+        while posOrig + self.size > self.pos:
+            record = CacheRecord(self)
+            record.dump()
+        print('</stream>')
+
+
+class Record(BinaryStream):
+    def __init__(self, parent):
+        BinaryStream.__init__(self, parent.bytes)
+        self.parent = parent
+        self.pos = parent.pos
+
+
+class Header(Record):
+    def __init__(self, parent):
+        Record.__init__(self, parent)
+
+    def dump(self):
+        self.printAndSet("nMajorVersion", self.readuInt16())
+        self.printAndSet("nMinorVersion", self.readuInt16())
+        self.parent.pos = self.pos
+
+
+class CacheRecord(Record):
+    def __init__(self, parent):
+        Record.__init__(self, parent)
+
+    def dump(self):
+        val = self.readuInt32()
+        print('<record type="' + RecordType[val & 0xff] + '">')
+        self.printAndSet("cRecTyp", val & 0xff)  # 1..8th bits
+        self.printAndSet("nSize", val >> 8)  # 9th..32th bits
+        if self.cRecTyp == 0x70:  # SW_LAYCACHE_IO_REC_PAGES
+            self.printAndSet("cFlags", self.readuInt8())
+        elif self.cRecTyp == 0x46:  # SW_LAYCACHE_IO_REC_FLY
+            self.printAndSet("cFlags", self.readuInt8())
+            self.printAndSet("nPgNum", self.readuInt16(), hexdump=False)
+            self.printAndSet("nIndex", self.readuInt32(), hexdump=False)
+            self.printAndSet("nX", self.readuInt32(), hexdump=False)
+            self.printAndSet("nY", self.readuInt32(), hexdump=False)
+            self.printAndSet("nW", self.readuInt32(), hexdump=False)
+            self.printAndSet("nH", self.readuInt32(), hexdump=False)
+        elif self.cRecTyp == 0x50:  # SW_LAYCACHE_IO_REC_PARA
+            self.printAndSet("cFlags", self.readuInt8())
+            self.printAndSet("nIndex", self.readuInt32(), hexdump=False)
+            if self.cFlags & 0x01:
+                print('<todo what="CacheRecord::dump: unhandled cRecTyp == SW_LAYCACHE_IO_REC_PARA && cFalgs == 1/>' % hex(self.cRecTyp))
+        else:
+            print('<todo what="CacheRecord::dump: unhandled cRecTyp=%s"/>' % hex(self.cRecTyp))
+            self.pos += self.nSize - 4  # 'val' is already read
+        print('</record>')
+        self.parent.pos = self.pos
+
+
+RecordType = {
+    0x70: 'SW_LAYCACHE_IO_REC_PAGES',  # 'p'
+    0x46: 'SW_LAYCACHE_IO_REC_FLY',  # 'F'
+    0x50: 'SW_LAYCACHE_IO_REC_PARA',  # 'P'
+}
+
+# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:
diff --git a/swlaycache-dump.py b/swlaycache-dump.py
new file mode 100755
index 0000000..6b0cc06
--- /dev/null
+++ b/swlaycache-dump.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from msodumper import swlaycacherecord
+import sys
+
+
+# Dumps the Star Writer binary layout cache format.
+class SwLayCacheDumper:
+    def __init__(self, filepath):
+        self.filepath = filepath
+
+    def dump(self):
+        file = open(self.filepath, 'rb')
+        strm = swlaycacherecord.SwLayCacheStream(file.read())
+        file.close()
+        print('<?xml version="1.0"?>')
+        strm.dump()
+
+
+def main(args):
+    dumper = SwLayCacheDumper(args[1])
+    dumper.dump()
+
+
+if __name__ == '__main__':
+    main(sys.argv)
+
+# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list