[Libreoffice-commits] .: src/msocrypto.py xls-dump.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Dec 17 14:10:30 PST 2012
src/msocrypto.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
xls-dump.py | 8 +++++
2 files changed, 83 insertions(+)
New commits:
commit 6dcfa7596d5b721b46787cd1d7b0ddb3a1e26105
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Dec 17 17:11:12 2012 -0500
Dump EncryptionInfo directory which stores info about encrypted documents.
This is true even for the OOXML-based file formats.
diff --git a/src/msocrypto.py b/src/msocrypto.py
new file mode 100644
index 0000000..c264d54
--- /dev/null
+++ b/src/msocrypto.py
@@ -0,0 +1,75 @@
+########################################################################
+#
+# 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/.
+#
+########################################################################
+
+import globals
+
+class EncryptionInfo(object):
+
+ class Type:
+ Unknown = -1
+ Standard = 0
+ Extensible = 1
+ Agile = 2
+
+ def __init__ (self, bytes):
+ self.strm = globals.ByteStream(bytes)
+ self.type = EncryptionInfo.Type.Unknown
+ self.size = -1
+
+ def read (self):
+ self.major = self.strm.readUnsignedInt(2)
+ self.minor = self.strm.readUnsignedInt(2)
+
+ if self.major == 3 or self.major == 4:
+ if self.minor == 2:
+ self.type = EncryptionInfo.Type.Standard
+ elif self.minor == 3:
+ self.type = EncryptionInfo.Type.Extensible
+ elif self.minor == 4:
+ self.type = EncryptionInfo.Type.Agile
+
+ flag = self.strm.readUnsignedInt(4)
+ self.fCryptoAPI = (flag & 0x00000004) != 0 # C
+ self.fDocProps = (flag & 0x00000008) != 0 # D (false if document properties are encrypted.)
+ self.fExternal = (flag & 0x00000010) != 0 # E (extensible encryption used)
+ self.fAES = (flag & 0x00000020) != 0 # F (ECMA-376 document)
+
+ if self.type == EncryptionInfo.Type.Standard or self.type == EncryptionInfo.Type.Extensible:
+ self.size = self.strm.readUnsignedInt(4)
+
+ def outputBoolean (self, name, value):
+ if value:
+ bs = "true"
+ else:
+ bs = "false"
+ print ("%s: %s"%(name, bs))
+
+ def outputInt (self, name, value):
+ print ("%s: %d"%(name, value))
+
+ def output (self):
+ print ("version: %d.%d"%(self.major, self.minor))
+ self.outputBoolean("crypto API", self.fCryptoAPI)
+ self.outputBoolean("encrypted document properties", not self.fDocProps)
+ self.outputBoolean("extensible encryption", self.fExternal)
+ self.outputBoolean("ECMA-376 document", self.fAES)
+ if self.type == EncryptionInfo.Type.Standard:
+ self.outputStandard()
+ elif self.type == EncryptionInfo.Type.Extensible:
+ self.outputExtensible()
+ elif self.type == EncryptionInfo.Type.Agile:
+ self.outputAgile()
+
+ def outputStandard (self):
+ self.outputInt("header stream size", self.size)
+
+ def outputExtensible (self):
+ self.outputInt("header stream size", self.size)
+
+ def outputAgile (self):
+ pass
diff --git a/xls-dump.py b/xls-dump.py
index 75e333e..0b7a7f6 100755
--- a/xls-dump.py
+++ b/xls-dump.py
@@ -30,6 +30,7 @@ import sys, os.path, optparse
sys.path.append(sys.path[0]+"/src")
import ole, xlsstream, globals, node, xlsmodel, olestream
import xlsparser
+import msocrypto
from globals import error
@@ -143,6 +144,13 @@ class XLDumper(object):
dirstrm.type = xlsstream.DirType.RevisionLog
self.__readSubStream(dirstrm)
+ elif dirname == "EncryptionInfo":
+ globals.dumpBytes(dirstrm.bytes, 512)
+ print("-"*globals.OutputWidth)
+ info = msocrypto.EncryptionInfo(dirstrm.bytes)
+ info.read()
+ info.output()
+
elif self.strmData.isPivotCacheStream(dirname):
dirstrm.type = xlsstream.DirType.PivotTableCache
self.__readSubStream(dirstrm)
More information about the Libreoffice-commits
mailing list