ooo-build r11365 - in trunk: . scratch/sc-xlsutil scratch/sc-xlsutil/src
- From: kyoshida svn gnome org
- To: svn-commits-list gnome org
- Subject: ooo-build r11365 - in trunk: . scratch/sc-xlsutil scratch/sc-xlsutil/src
- Date: Tue, 22 Jan 2008 23:06:56 +0000 (GMT)
Author: kyoshida
Date: Tue Jan 22 23:06:56 2008
New Revision: 11365
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11365&view=rev
Log:
2008-01-22 Kohei Yoshida <kyoshida novell com>
* scratch/sc-xlsutil/src/globals.py:
* scratch/sc-xlsutil/src/ole.py:
* scratch/sc-xlsutil/src/stream.py:
* scratch/sc-xlsutil/xls_dump.py: added support to dump directory
entries.
Modified:
trunk/ChangeLog
trunk/scratch/sc-xlsutil/src/globals.py
trunk/scratch/sc-xlsutil/src/ole.py
trunk/scratch/sc-xlsutil/src/stream.py
trunk/scratch/sc-xlsutil/xls_dump.py
Modified: trunk/scratch/sc-xlsutil/src/globals.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/globals.py (original)
+++ trunk/scratch/sc-xlsutil/src/globals.py Tue Jan 22 23:06:56 2008
@@ -4,11 +4,37 @@
def output (msg):
sys.stdout.write(msg)
-def dumpBytes (chars):
+def dumpBytes (chars, subDivide=None):
+ line = 0
+ subDivideLine = None
+ if subDivide != None:
+ subDivideLine = subDivide/16
for i in xrange(0, len(chars)):
byte = ord(chars[i])
output("%2.2X "%byte)
if (i+1)%16 == 0:
output("\n")
+ if subDivideLine != None and (line+1)%subDivideLine == 0:
+ output("\n")
+ line += 1
+
output("\n")
+def getSectorPos (secID, secSize):
+ return 512 + secID*secSize
+
+
+def getUTF8FromUTF16 (bytes):
+ # little endian utf-16 strings
+ byteCount = len(bytes)
+ loopCount = int(byteCount/2)
+ text = ''
+ for i in xrange(0, loopCount):
+ code = ''
+ if bytes[i*2+1] != '\x00':
+ code += bytes[i*2+1]
+ if bytes[i*2] != '\x00':
+ code += bytes[i*2]
+ text += unicode(code, 'utf-8')
+ return text
+
Modified: trunk/scratch/sc-xlsutil/src/ole.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/ole.py (original)
+++ trunk/scratch/sc-xlsutil/src/ole.py Tue Jan 22 23:06:56 2008
@@ -1,6 +1,6 @@
import sys
-import stream
+import stream, globals
# ----------------------------------------------------------------------------
# Reference: The Microsoft Compound Document File Format by Daniel Rentz
@@ -242,7 +242,7 @@
ssatID = self.getFirstSectorID(SectorType.SSAT)
if ssatID < 0:
return None
- chain = self.MSAT.getSAT().getSectorIDChain(ssatID)
+ chain = self.getSAT().getSectorIDChain(ssatID)
if len(chain) == 0:
return None
obj = SSAT(2**self.secSize, self.bytes)
@@ -252,6 +252,24 @@
return obj
+ def getDirectory (self):
+ dirID = self.getFirstSectorID(SectorType.Directory)
+ if dirID < 0:
+ return None
+ chain = self.getSAT().getSectorIDChain(dirID)
+ if len(chain) == 0:
+ return None
+ obj = Directory(2**self.secSize, self.bytes)
+ for secID in chain:
+ obj.addSector(secID)
+ return obj
+
+
+ def dummy ():
+ pass
+
+
+
class MSAT(object):
"""Master Sector Allocation Table (MSAT)
@@ -308,8 +326,8 @@
self.array = []
- def addSector (self, pos):
- self.sectorIDs.append(pos)
+ def addSector (self, id):
+ self.sectorIDs.append(id)
def buildArray (self):
@@ -368,6 +386,138 @@
output("%3d : %3d\n"%(i, item))
+class Directory(object):
+
+ class Type:
+ Empty = 0
+ UserStorage = 1
+ UserStream = 2
+ LockBytes = 3
+ Property = 4
+ RootStorage = 5
+
+ class NodeColor:
+ Red = 0
+ Black = 1
+ Unknown = 99
+
+ class Entry:
+ def __init__ (self):
+ self.Name = ''
+ self.CharBufferSize = 0
+ self.Type = Directory.Type.Empty
+ self.NodeColor = Directory.NodeColor.Unknown
+ self.DirIDLeft = -1
+ self.DirIDRight = -1
+ self.DirIDRoot = -1
+ self.UniqueID = None
+
+ def __init__ (self, sectorSize, bytes):
+ self.sectorSize = sectorSize
+ self.bytes = bytes
+ self.sectorIDs = []
+ self.entries = []
+
+
+ def addSector (self, id):
+ self.sectorIDs.append(id)
+
+ def output (self, dumpRawBytes=False):
+ print('')
+ print("="*68)
+ print("Directory")
+ print("-"*68)
+ print("sector(s) used:")
+ for secID in self.sectorIDs:
+ print(" sector %d"%secID)
+
+ if dumpRawBytes:
+ print("")
+ for secID in self.sectorIDs:
+ print("-"*68)
+ print(" Raw Hex Dump (sector %d)"%secID)
+ print("-"*68)
+ pos = globals.getSectorPos(secID, self.sectorSize)
+ globals.dumpBytes(self.bytes[pos:pos+self.sectorSize], 128)
+
+ for entry in self.entries:
+ print("-"*68)
+ if len(entry.Name) > 0:
+ print("name: %s (name buffer size: %d bytes)"%(entry.Name, entry.CharBufferSize))
+ else:
+ print("name: [empty] (name buffer size: %d bytes)"%entry.CharBufferSize)
+
+ output("type: ")
+ if entry.Type == Directory.Type.Empty:
+ print("empty")
+ elif entry.Type == Directory.Type.LockBytes:
+ print("lock bytes")
+ elif entry.Type == Directory.Type.Property:
+ print("property")
+ elif entry.Type == Directory.Type.RootStorage:
+ print("root storage")
+ elif entry.Type == Directory.Type.UserStorage:
+ print("user storage")
+ elif entry.Type == Directory.Type.UserStream:
+ print("user stream")
+ else:
+ print("[unknown type]")
+
+ output("node color: ")
+ if entry.NodeColor == Directory.NodeColor.Red:
+ print("red")
+ elif entry.NodeColor == Directory.NodeColor.Black:
+ print("black")
+ elif entry.NodeColor == Directory.NodeColor.Unknown:
+ print("[unknown color]")
+
+ print("linked dir entries: left: %d; right: %d; root: %d"%
+ (entry.DirIDLeft, entry.DirIDRight, entry.DirIDRoot))
+
+ if entry.UniqueID != None:
+ output("unique ID: ")
+ for byte in entry.UniqueID:
+ output("%2.2X "%ord(byte))
+ print("")
+
+
+
+ def parseDirEntries (self):
+ # combine all sectors first.
+ bytes = []
+ for secID in self.sectorIDs:
+ pos = globals.getSectorPos(secID, self.sectorSize)
+ bytes.extend(self.bytes[pos:pos+self.sectorSize])
+
+ self.entries = []
+
+ # each directory entry is exactly 128 bytes.
+ numEntries = int(len(bytes)/128)
+ if numEntries == 0:
+ return
+ for i in xrange(0, numEntries):
+ pos = i*128
+ self.entries.append(self.parseDirEntry(bytes[pos:pos+128]))
+
+
+ def parseDirEntry (self, bytes):
+ entry = Directory.Entry()
+ name = globals.getUTF8FromUTF16(bytes[0:64])
+ entry.Name = name
+ entry.CharBufferSize = getSignedInt(bytes[64:66])
+ entry.Type = getSignedInt(bytes[66:67])
+ entry.NodeColor = getSignedInt(bytes[67:68])
+
+ entry.DirIDLeft = getSignedInt(bytes[68:72])
+ entry.DirIDRight = getSignedInt(bytes[72:76])
+ entry.DirIDRoot = getSignedInt(bytes[76:80])
+
+ entry.UniqueID = bytes[80:96]
+
+ return entry
+
+ def dummy ():
+ pass
Modified: trunk/scratch/sc-xlsutil/src/stream.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/stream.py (original)
+++ trunk/scratch/sc-xlsutil/src/stream.py Tue Jan 22 23:06:56 2008
@@ -227,6 +227,13 @@
return
obj.output()
+ def printDirectory (self):
+ obj = self.header.getDirectory()
+ if obj == None:
+ return
+ obj.parseDirEntries()
+ obj.output()
+
def dumpHeader (self):
oleobj = ole.Header(self.chars)
self.pos = oleobj.dumpBytes()
Modified: trunk/scratch/sc-xlsutil/xls_dump.py
==============================================================================
--- trunk/scratch/sc-xlsutil/xls_dump.py (original)
+++ trunk/scratch/sc-xlsutil/xls_dump.py Tue Jan 22 23:06:56 2008
@@ -18,6 +18,7 @@
strm.printMSAT()
strm.printSAT()
strm.printSSAT()
+ strm.printDirectory()
success = True
while success:
success = self.__read(strm)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]