ooo-build r11332 - in trunk: . scratch/sc-xlsutil scratch/sc-xlsutil/src



Author: kyoshida
Date: Mon Jan 21 04:28:25 2008
New Revision: 11332
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11332&view=rev

Log:
2008-01-20  Kohei Yoshida  <kyoshida novell com>

	* scratch/sc-xlsutil/src/ole.py: 
	* scratch/sc-xlsutil/src/stream.py: added two new files for OLE dumping.
	
	* scratch/sc-xlsutil/xls_dump.py: moved some code into stream.py.


Added:
   trunk/scratch/sc-xlsutil/src/
   trunk/scratch/sc-xlsutil/src/ole.py
   trunk/scratch/sc-xlsutil/src/stream.py
Modified:
   trunk/ChangeLog
   trunk/scratch/sc-xlsutil/xls_dump.py

Added: trunk/scratch/sc-xlsutil/src/ole.py
==============================================================================
--- (empty file)
+++ trunk/scratch/sc-xlsutil/src/ole.py	Mon Jan 21 04:28:25 2008
@@ -0,0 +1,244 @@
+
+import sys
+import stream
+
+def output (msg):
+    sys.stdout.write(msg)
+
+def printSep (c='-', w=68, prefix=''):
+    print(prefix + c*w)
+
+def char2byte (chars):
+    bytes = []
+    for c in chars:
+        bytes.append(ord(c))
+    return bytes
+
+def getSignedInt (bytes):
+    # little endian
+    n = len(bytes)
+    if n == 0:
+        return 0
+
+    if type(bytes[0]) == type('c'):
+        bytes = char2byte(bytes)
+
+    isNegative = (bytes[-1] & 0x80) == 0x80
+
+    num, ff = 0, 0
+    for i in xrange(0, n):
+        num += bytes[i]*(256**i)
+        ff += 0xFF*(256**i)
+        i += 1
+
+    if isNegative:
+        # perform two's compliment.
+        num = -((num^ff) + 1)
+
+    return num
+
+class ByteOrder:
+    LittleEndian = 0
+    BigEndian = 1
+    Unknown = 2
+
+class Header(object):
+
+    @staticmethod
+    def byteOrder (chars):
+        b1, b2 = ord(chars[0]), ord(chars[1])
+        if b1 == 0xFE and b2 == 0xFF:
+            return ByteOrder.LittleEndian
+        elif b1 == 0xFF and b2 == 0xFE:
+            return ByteOrder.BigEndian
+        else:
+            return ByteOrder.Unknown
+
+    def __init__ (self, chars):
+        self.chars = chars
+        self.MSAT = None
+
+        self.docId = None
+        self.uId = None
+        self.revision = 0
+        self.version = 0
+        self.byteOrder = ByteOrder.Unknown
+        self.minStrmSize = 0
+        self.numSecMSAT = 0
+        self.numSecSSAT = 0
+        self.numSecSAT = 0
+        self.secIDFirstMSAT = -2
+        self.secSize = 512
+        self.secSizeShort = 64
+
+    def dumpBytes (self, initPos=0, quitAtBOF=True):
+        # dump OLE header until it reaches BOF.
+        i, bprev = initPos, 0
+        labelPrinted = False
+        while True:
+            b = ord(self.chars[i])
+            if quitAtBOF and bprev == 0x09 and b == 0x08:
+                # BOF reached
+                return i-1
+
+            if i%2 != 0:
+                if not labelPrinted:
+                    print("\n\nThe rest of the bytes:")
+                    labelPrinted = True
+                output("%2.2X %2.2X "%(bprev, b))
+
+            if (i+1)%16 == 0:
+                output("\n")
+
+            bprev = b
+            i += 1
+
+        return i
+
+    def dumpSectorBytes (self, initPos, secSize):
+        print('foo')
+        for i in xrange(0, secSize):
+            b = ord(self.chars[i+initPos])
+            output("%2.2X "%b)
+            if (i+1)%16 == 0:
+                output("\n")
+
+    def output (self):
+
+        def printRawBytes (bytes):
+            for b in bytes:
+                output("%2.2X "%ord(b))
+            output("\n")
+
+        printSep('=', 68)
+        print("Compound Document Header")
+        printSep('-', 68)
+
+        # document ID and unique ID
+        output("Document ID: ")
+        printRawBytes(self.docId)
+        output("Unique ID: ")
+        printRawBytes(self.uId)
+
+        # revision and version
+        print("revision: %d  version: %d"%(self.revision, self.version))
+
+        # byte order
+        output("byte order: ")
+        if self.byteOrder == ByteOrder.LittleEndian:
+            print("little endian")
+        elif self.byteOrder == ByteOrder.BigEndian:
+            print("big endian")
+        else:
+            print("unknown")
+
+        # sector size (usually 512 bytes)
+        print("Sector size: %d"%self.secSize)
+
+        # short sector size (usually 64 bytes)
+        print("Short sector size: %d"%self.secSizeShort)
+
+        # total number of sectors in SAT (equals the number of sector IDs 
+        # stored in the MSAT).
+        print("Total number of sectors used in SAT: %d"%self.numSecSAT)
+
+        # ???
+        print("Section ID of the first sector of the directory stream: %d"%self.secIDFirstDirStrm)
+
+        print("Minimum stream size: %d"%self.minStrmSize)
+
+        print("SecID of first SSAT sector: %d"%(512+self.secIDFirstSSAT*self.secSizeShort))
+
+        print("Total number of sectors used in SSAT: %d"%self.numSecSSAT)
+
+        if self.secIDFirstMSAT == -2:
+            # There is no more sector ID stored outside the header.
+            print("SecID of first MSAT sector: [end of chain]")
+        else:
+            # There is more sector IDs than 109 IDs stored in the header.
+            print("SecID of first MSAT sector: %d"%(512+self.secIDFirstMSAT*self.secSize))
+
+        print("Total number of sectors used to store additional MSAT: %d"%self.numSecMSAT)
+
+    def parse (self):
+
+        # document ID and unique ID
+        self.docId = self.chars[0:8]
+        self.uId = self.chars[8:24]
+
+        # revision and version
+        self.revision = getSignedInt(self.chars[24:26])
+        self.version = getSignedInt(self.chars[26:28])
+
+        # byte order
+        self.byteOrder = Header.byteOrder(self.chars[28:30])
+
+        # sector size (usually 512 bytes)
+        self.secSize = 2**getSignedInt(self.chars[30:32])
+
+        # short sector size (usually 64 bytes)
+        self.secSizeShort = 2**getSignedInt(self.chars[32:34])
+
+        # total number of sectors in SAT (equals the number of sector IDs 
+        # stored in the MSAT).
+        self.numSecSAT = getSignedInt(self.chars[44:48])
+
+        self.secIDFirstDirStrm = getSignedInt(self.chars[48:52])
+        self.minStrmSize = getSignedInt(self.chars[56:60])
+        self.secIDFirstSSAT = getSignedInt(self.chars[60:64])
+        self.numSecSSAT = getSignedInt(self.chars[64:68])
+        self.secIDFirstMSAT = getSignedInt(self.chars[68:72])
+        self.numSecMSAT = getSignedInt(self.chars[72:76])
+
+        self.MSAT = MSAT(self.secSize)
+
+        # First part of MSAT consisting of an array of up to 109 sector IDs.
+        # Each sector ID is 4 bytes in length.
+        for i in xrange(0, 109):
+            pos = 76 + i*4
+            id = getSignedInt(self.chars[pos:pos+4])
+            if id == -1:
+                break
+
+            self.MSAT.appendSectorID(id)
+
+        return 512
+#       return self.dumpBytes(512)
+
+    def dumpSAT (self):
+        for pos in self.secPosList:
+            self.dumpSectorBytes(pos, 512)
+        return
+
+    def getMSAT (self):
+        return self.MSAT
+
+
+class MSAT(object):
+    """Master Sector Allocation Table
+
+This class represents the master sector allocation table (MSAT) that
+stores sector IDs that point to the sectors that are used by the sector
+allocation table (SAT).  The actual SAT are to be constructed by 
+combining all the sectors pointed by the sector IDs in order of 
+occurrence.
+"""
+    def __init__ (self, sectorSize):
+        self.sectorSize = sectorSize
+        self.secIDs = []
+
+    def appendSectorID (self, id):
+        self.secIDs.append(id)
+
+    def output (self):
+        print('')
+        print("="*68)
+        print("Master Sector Allocation Table")
+        print("-"*68)
+
+        for id in self.secIDs:
+            print("sector ID: %5d   (pos: %7d)"%(id, 512+id*self.sectorSize))
+
+
+
+

Added: trunk/scratch/sc-xlsutil/src/stream.py
==============================================================================
--- (empty file)
+++ trunk/scratch/sc-xlsutil/src/stream.py	Mon Jan 21 04:28:25 2008
@@ -0,0 +1,265 @@
+
+import sys
+import ole
+
+recData = {
+    0x000A: ["EOF", "End of File"],
+    0x000C: ["CALCCOUNT", "Iteration Count"],
+    0x000D: ["CALCMODE", "Calculation Mode"],
+    0x000E: ["PRECISION", "Precision"],
+    0x000F: ["REFMODE", "Reference Mode"],
+    0x0100: ["SXVDEX", "Extended PivotTable View Fields"],
+    0x0103: ["SXFORMULA", "PivotTable Formula Record"],
+    0x0010: ["DELTA", "Iteration Increment"],
+    0x0011: ["ITERATION", "Iteration Mode"],
+    0x0122: ["SXDBEX", "PivotTable Cache Data"],
+    0x0012: ["PROTECT", "Protection Flag"],
+    0x013D: ["TABID", "Sheet Tab Index Array"],
+    0x0013: ["PASSWORD", "Protection Password"],
+    0x0014: ["HEADER", "Print Header on Each Page"],
+    0x0015: ["FOOTER", "Print Footer on Each Page"],
+    0x0160: ["USESELFS", "Natural Language Formulas Flag"],
+    0x0161: ["DSF", "Double Stream File"],
+    0x0016: ["EXTERNCOUNT", "Number of External References"],
+    0x0017: ["EXTERNSHEET", "External Reference"],
+    0x0019: ["WINDOWPROTECT", "Windows Are Protected"],
+    0x01A9: ["USERBVIEW", "Workbook Custom View Settings"],
+    0x01AA: ["USERSVIEWBEGIN", "Custom View Settings"],
+    0x01AB: ["USERSVIEWEND", "End of Custom View Records"],
+    0x01AD: ["QSI", "External Data Range"],
+    0x01AE: ["SUPBOOK", "Supporting Workbook"],
+    0x001A: ["VERTICALPAGEBREAKS", "Explicit Column Page Breaks"],
+    0x01B0: ["CONDFMT", "Conditional Formatting Range Information"],
+    0x01B1: ["CF", "Conditional Formatting Conditions"],
+    0x01B2: ["DVAL", "Data Validation Information"],
+    0x01B5: ["DCONBIN", "Data Consolidation Information"],
+    0x01B6: ["TXO", "Text Object"],
+    0x01B7: ["REFRESHALL", "Refresh Flag"],
+    0x01B8: ["HLINK", "Hyperlink"],
+    0x01BB: ["SXFDBTYPE", "SQL Datatype Identifier"],
+    0x01BE: ["DV", "Data Validation Criteria"],
+    0x001B: ["HORIZONTALPAGEBREAKS", "Explicit Row Page Breaks"],
+    0x001C: ["NOTE", "Comment Associated with a Cell"],
+    0x001D: ["SELECTION", "Current Selection"],
+    0x0200: ["DIMENSIONS", "Cell Table Size"],
+    0x0201: ["BLANK", "Cell Value"],
+    0x0203: ["NUMBER", "Cell Value"],
+    0x0204: ["LABEL", "Cell Value"],
+    0x0205: ["BOOLERR", "Cell Value"],
+    0x0207: ["STRING", "String Value of a Formula"],
+    0x0208: ["ROW", "Describes a Row"],
+    0x020B: ["INDEX", "Index Record"],
+    0x0218: ["NAME", "Defined Name"],
+    0x0221: ["ARRAY", "Array-Entered Formula"],
+    0x0223: ["EXTERNNAME", "Externally Referenced Name"],
+    0x0225: ["DEFAULTROWHEIGHT", "Default Row Height"],
+    0x0231: ["FONT", "Font Description"],
+    0x0236: ["TABLE", "Data Table"],
+    0x0026: ["LEFTMARGIN", "Left Margin Measurement"],
+    0x0027: ["RIGHTMARGIN", "Right Margin Measurement"],
+    0x0028: ["TOPMARGIN", "Top Margin Measurement"],
+    0x0293: ["STYLE", "Style Information"],
+    0x0029: ["BOTTOMMARGIN", "Bottom Margin Measurement"],
+    0x002A: ["PRINTHEADERS", "Print Row/Column Labels"],
+    0x002B: ["PRINTGRIDLINES", "Print Gridlines Flag"],
+    0x002F: ["FILEPASS", "File Is Password-Protected"],
+    0x003C: ["CONTINUE", "Continues Long Records"],
+    0x0406: ["FORMULA", "Cell Formula"],
+    0x0040: ["BACKUP", "Save Backup Version of the File"],
+    0x041E: ["FORMAT", "Number Format"],
+    0x0041: ["PANE", "Number of Panes and Their Position"],
+    0x0042: ["CODEPAGE/CODENAME", "Default Code Page/VBE Object Name"],
+    0x004D: ["PLS", "Environment-Specific Print Record"],
+    0x0050: ["DCON", "Data Consolidation Information"],
+    0x0051: ["DCONREF", "Data Consolidation References"],
+    0x0052: ["DCONNAME", "Data Consolidation Named References"],
+    0x0055: ["DEFCOLWIDTH", "Default Width for Columns"],
+    0x0059: ["XCT", "CRN Record Count"],
+    0x005A: ["CRN", "Nonresident Operands"],
+    0x005B: ["FILESHARING", "File-Sharing Information"],
+    0x005C: ["WRITEACCESS", "Write Access User Name"],
+    0x005D: ["OBJ", "Describes a Graphic Object"],
+    0x005E: ["UNCALCED", "Recalculation Status"],
+    0x005F: ["SAVERECALC", "Recalculate Before Save"],
+    0x0060: ["TEMPLATE", "Workbook Is a Template"],
+    0x0063: ["OBJPROTECT", "Objects Are Protected"],
+    0x007D: ["COLINFO", "Column Formatting Information"],
+    0x007E: ["RK", "Cell Value"],
+    0x007F: ["IMDATA", "Image Data"],
+    0x0809: ["BOF", "Beginning of File"],
+    0x0080: ["GUTS", "Size of Row and Column Gutters"],
+    0x0081: ["WSBOOL", "Additional Workspace Information"],
+    0x0082: ["GRIDSET", "State Change of Gridlines Option"],
+    0x0083: ["HCENTER", "Center Between Horizontal Margins"],
+    0x0084: ["VCENTER", "Center Between Vertical Margins"],
+    0x0085: ["BOUNDSHEET", "Sheet Information"],
+    0x0086: ["WRITEPROT", "Workbook Is Write-Protected"],
+    0x0087: ["ADDIN", "Workbook Is an Add-in Macro"],
+    0x0088: ["EDG", "Edition Globals"],
+    0x0089: ["PUB", "Publisher"],
+    0x008C: ["COUNTRY", "Default Country and WIN.INI Country"],
+    0x008D: ["HIDEOBJ", "Object Display Options"],
+    0x0090: ["SORT", "Sorting Options"],
+    0x0091: ["SUB", "Subscriber"],
+    0x0092: ["PALETTE", "Color Palette Definition"],
+    0x0094: ["LHRECORD", ".WK? File Conversion Information"],
+    0x0095: ["LHNGRAPH", "Named Graph Information"],
+    0x0096: ["SOUND", "Sound Note"],
+    0x0098: ["LPR", "Sheet Was Printed Using LINE.PRINT()"],
+    0x0099: ["STANDARDWIDTH", "Standard Column Width"],
+    0x009A: ["FNGROUPNAME", "Function Group Name"],
+    0x009B: ["FILTERMODE", "Sheet Contains Filtered List"],
+    0x009C: ["FNGROUPCOUNT", "Built-in Function Group Count"],
+    0x009D: ["AUTOFILTERINFO", "Drop-Down Arrow Count"],
+    0x009E: ["AUTOFILTER", "AutoFilter Data"],
+    0x00A0: ["SCL", "Window Zoom Magnification"],
+    0x00A1: ["SETUP", "Page Setup"],
+    0x00A9: ["COORDLIST", "Polygon Object Vertex Coordinates"],
+    0x00AB: ["GCW", "Global Column-Width Flags"],
+    0x00AE: ["SCENMAN", "Scenario Output Data"],
+    0x00AF: ["SCENARIO", "Scenario Data"],
+    0x00B0: ["SXVIEW", "View Definition"],
+    0x00B1: ["SXVD", "View Fields"],
+    0x00B2: ["SXVI", "View Item"],
+    0x00B4: ["SXIVD", "Row/Column Field IDs"],
+    0x00B5: ["SXLI", "Line Item Array"],
+    0x00B6: ["SXPI", "Page Item"],
+    0x00B8: ["DOCROUTE", "Routing Slip Information"],
+    0x00B9: ["RECIPNAME", "Recipient Name"],
+    0x00BC: ["SHRFMLA", "Shared Formula"],
+    0x00BD: ["MULRK", "Multiple RK Cells"],
+    0x00BE: ["MULBLANK", "Multiple Blank Cells"],
+    0x00C1: ["MMS", "ADDMENU/DELMENU Record Group Count"],
+    0x00C2: ["ADDMENU", "Menu Addition"],
+    0x00C3: ["DELMENU", "Menu Deletion"],
+    0x00C5: ["SXDI", "Data Item"],
+    0x00C6: ["SXDB", "PivotTable Cache Data"],
+    0x00CD: ["SXSTRING", "String"],
+    0x00D0: ["SXTBL", "Multiple Consolidation Source Info"],
+    0x00D1: ["SXTBRGIITM", "Page Item Name Count"],
+    0x00D2: ["SXTBPG", "Page Item Indexes"],
+    0x00D3: ["OBPROJ", "Visual Basic Project"],
+    0x00D5: ["SXIDSTM", "Stream ID"],
+    0x00D6: ["RSTRING", "Cell with Character Formatting"],
+    0x00D7: ["DBCELL", "Stream Offsets"],
+    0x00DA: ["BOOKBOOL", "Workbook Option Flag"],
+    0x00DC: ["PARAMQRY", "Query Parameters"],
+    0x00DC: ["SXEXT", "External Source Information"],
+    0x00DD: ["SCENPROTECT", "Scenario Protection"],
+    0x00DE: ["OLESIZE", "Size of OLE Object"],
+    0x00DF: ["UDDESC", "Description String for Chart Autoformat"],
+    0x00E0: ["XF", "Extended Format"],
+    0x00E1: ["INTERFACEHDR", "Beginning of User Interface Records"],
+    0x00E2: ["INTERFACEEND", "End of User Interface Records"],
+    0x00E3: ["SXVS", "View Source"],
+    0x00EA: ["TABIDCONF", "Sheet Tab ID of Conflict History"],
+    0x00EB: ["MSODRAWINGGROUP", "Microsoft Office Drawing Group"],
+    0x00EC: ["MSODRAWING", "Microsoft Office Drawing"],
+    0x00ED: ["MSODRAWINGSELECTION", "Microsoft Office Drawing Selection"],
+    0x00F0: ["SXRULE", "PivotTable Rule Data"],
+    0x00F1: ["SXEX", "PivotTable View Extended Information"],
+    0x00F2: ["SXFILT", "PivotTable Rule Filter"],
+    0x00F6: ["SXNAME", "PivotTable Name"],
+    0x00F7: ["SXSELECT", "PivotTable Selection Information"],
+    0x00F8: ["SXPAIR", "PivotTable Name Pair"],
+    0x00F9: ["SXFMLA", "PivotTable Parsed Expression"],
+    0x00FB: ["SXFORMAT", "PivotTable Format Record"],
+    0x00FC: ["SST", "Shared String Table"],
+    0x00FD: ["LABELSST", "Cell Value"],
+    0x003D: ["WINDOW1", "Window Information"],
+    0x0022: ["DATEMODE", "Base Date for Displaying Date Values"],
+    0x023E: ["WINDOW2", "Sheet Window Information"],
+    0x01AF: ["PROT4REV", "Shared Workbook Protection Flag"],
+    0x01BC: ["PROT4REVPASS", "Shared Workbook Protection Password"],
+    0x0031: ["FONT", "Font and Character Formatting"],
+    0x00FF: ["EXTSST", "Extended Shared String Table"] }
+
+def output (msg):
+    sys.stdout.write(msg)
+
+class XLStream(object):
+
+    def __init__ (self, file):
+        self.chars = file.read()
+        self.size = len(self.chars)
+        self.pos = 0
+        self.version = None
+
+        self.header = None
+        self.MSAT = None
+
+    def __printSep (self, c='-', w=68, prefix=''):
+        print(prefix + c*w)
+
+    def printStreamInfo (self):
+        self.__printSep('=', 68)
+        print("Excel File Format Dumper by Kohei Yoshida")
+        print("  total stream size: %d bytes"%self.size)
+        self.__printSep('=', 68)
+        print('')
+
+    def printHeader (self):
+        self.header = ole.Header(self.chars)
+        self.pos = self.header.parse()
+        self.header.output()
+        self.MSAT = self.header.getMSAT()
+
+    def printMSAT (self):
+        self.MSAT.output()
+
+    def dumpHeader (self):
+        oleobj = ole.Header(self.chars)
+        self.pos = oleobj.dumpBytes()
+
+    def seekBOF (self):
+        while self.pos < self.size-1:
+            b1, b2 = ord(self.chars[self.pos]), ord(self.chars[self.pos+1])
+            word = b1 + b2*256
+            if word == 0x0809:
+                self.version = 'BIFF5/BIFF8'
+                return
+            self.pos += 2
+
+    def readRaw (self, size=1):
+        # assume little endian
+        bytes = 0
+        for i in xrange(0, size):
+            b = ord(self.chars[self.pos])
+            if i == 0:
+                bytes = b
+            else:
+                bytes += b*(256**i)
+            self.pos += 1
+
+        return bytes
+
+    def readByteArray (self, size=1):
+        bytes = []
+        for i in xrange(0, size):
+            bytes.append(ord(self.chars[self.pos]))
+            self.pos += 1
+        return bytes
+
+    def readRecord (self):
+        pos = self.pos
+        header = self.readRaw(2)
+        size = self.readRaw(2)
+        print("")
+        self.__printSep('=', 61, "%4.4Xh: "%header)
+        if recData.has_key(header):
+            print("%4.4Xh: %s - %s (%4.4Xh)"%(header, recData[header][0], recData[header][1], header))
+        else:
+            print("%4.4Xh: [unknown record name] (%4.4Xh)"%(header, header))
+        print("%4.4Xh:   size = %d; pos = %d"%(header, size, pos))
+        self.__printSep('-', 61, "%4.4Xh: "%header)
+        bytes = self.readByteArray(size)
+        for i in xrange(0, size):
+            if (i+1) % 16 == 1:
+                output("%4.4Xh: "%header)
+            output("%2.2X "%bytes[i])
+            if (i+1) % 16 == 0 and i != size-1:
+                print("")
+        if size > 0:
+            print("")
+
+        return header

Modified: trunk/scratch/sc-xlsutil/xls_dump.py
==============================================================================
--- trunk/scratch/sc-xlsutil/xls_dump.py	(original)
+++ trunk/scratch/sc-xlsutil/xls_dump.py	Mon Jan 21 04:28:25 2008
@@ -1,251 +1,8 @@
 #!/usr/bin/env python
 
 import sys, os.path
-
-recData = {
-    0x000A: ["EOF", "End of File"],
-    0x000C: ["CALCCOUNT", "Iteration Count"],
-    0x000D: ["CALCMODE", "Calculation Mode"],
-    0x000E: ["PRECISION", "Precision"],
-    0x000F: ["REFMODE", "Reference Mode"],
-    0x0100: ["SXVDEX", "Extended PivotTable View Fields"],
-    0x0103: ["SXFORMULA", "PivotTable Formula Record"],
-    0x0010: ["DELTA", "Iteration Increment"],
-    0x0011: ["ITERATION", "Iteration Mode"],
-    0x0122: ["SXDBEX", "PivotTable Cache Data"],
-    0x0012: ["PROTECT", "Protection Flag"],
-    0x013D: ["TABID", "Sheet Tab Index Array"],
-    0x0013: ["PASSWORD", "Protection Password"],
-    0x0014: ["HEADER", "Print Header on Each Page"],
-    0x0015: ["FOOTER", "Print Footer on Each Page"],
-    0x0160: ["USESELFS", "Natural Language Formulas Flag"],
-    0x0161: ["DSF", "Double Stream File"],
-    0x0016: ["EXTERNCOUNT", "Number of External References"],
-    0x0017: ["EXTERNSHEET", "External Reference"],
-    0x0019: ["WINDOWPROTECT", "Windows Are Protected"],
-    0x01A9: ["USERBVIEW", "Workbook Custom View Settings"],
-    0x01AA: ["USERSVIEWBEGIN", "Custom View Settings"],
-    0x01AB: ["USERSVIEWEND", "End of Custom View Records"],
-    0x01AD: ["QSI", "External Data Range"],
-    0x01AE: ["SUPBOOK", "Supporting Workbook"],
-    0x001A: ["VERTICALPAGEBREAKS", "Explicit Column Page Breaks"],
-    0x01B0: ["CONDFMT", "Conditional Formatting Range Information"],
-    0x01B1: ["CF", "Conditional Formatting Conditions"],
-    0x01B2: ["DVAL", "Data Validation Information"],
-    0x01B5: ["DCONBIN", "Data Consolidation Information"],
-    0x01B6: ["TXO", "Text Object"],
-    0x01B7: ["REFRESHALL", "Refresh Flag"],
-    0x01B8: ["HLINK", "Hyperlink"],
-    0x01BB: ["SXFDBTYPE", "SQL Datatype Identifier"],
-    0x01BE: ["DV", "Data Validation Criteria"],
-    0x001B: ["HORIZONTALPAGEBREAKS", "Explicit Row Page Breaks"],
-    0x001C: ["NOTE", "Comment Associated with a Cell"],
-    0x001D: ["SELECTION", "Current Selection"],
-    0x0200: ["DIMENSIONS", "Cell Table Size"],
-    0x0201: ["BLANK", "Cell Value"],
-    0x0203: ["NUMBER", "Cell Value"],
-    0x0204: ["LABEL", "Cell Value"],
-    0x0205: ["BOOLERR", "Cell Value"],
-    0x0207: ["STRING", "String Value of a Formula"],
-    0x0208: ["ROW", "Describes a Row"],
-    0x020B: ["INDEX", "Index Record"],
-    0x0218: ["NAME", "Defined Name"],
-    0x0221: ["ARRAY", "Array-Entered Formula"],
-    0x0223: ["EXTERNNAME", "Externally Referenced Name"],
-    0x0225: ["DEFAULTROWHEIGHT", "Default Row Height"],
-    0x0231: ["FONT", "Font Description"],
-    0x0236: ["TABLE", "Data Table"],
-    0x0026: ["LEFTMARGIN", "Left Margin Measurement"],
-    0x0027: ["RIGHTMARGIN", "Right Margin Measurement"],
-    0x0028: ["TOPMARGIN", "Top Margin Measurement"],
-    0x0293: ["STYLE", "Style Information"],
-    0x0029: ["BOTTOMMARGIN", "Bottom Margin Measurement"],
-    0x002A: ["PRINTHEADERS", "Print Row/Column Labels"],
-    0x002B: ["PRINTGRIDLINES", "Print Gridlines Flag"],
-    0x002F: ["FILEPASS", "File Is Password-Protected"],
-    0x003C: ["CONTINUE", "Continues Long Records"],
-    0x0406: ["FORMULA", "Cell Formula"],
-    0x0040: ["BACKUP", "Save Backup Version of the File"],
-    0x041E: ["FORMAT", "Number Format"],
-    0x0041: ["PANE", "Number of Panes and Their Position"],
-    0x0042: ["CODEPAGE/CODENAME", "Default Code Page/VBE Object Name"],
-    0x004D: ["PLS", "Environment-Specific Print Record"],
-    0x0050: ["DCON", "Data Consolidation Information"],
-    0x0051: ["DCONREF", "Data Consolidation References"],
-    0x0052: ["DCONNAME", "Data Consolidation Named References"],
-    0x0055: ["DEFCOLWIDTH", "Default Width for Columns"],
-    0x0059: ["XCT", "CRN Record Count"],
-    0x005A: ["CRN", "Nonresident Operands"],
-    0x005B: ["FILESHARING", "File-Sharing Information"],
-    0x005C: ["WRITEACCESS", "Write Access User Name"],
-    0x005D: ["OBJ", "Describes a Graphic Object"],
-    0x005E: ["UNCALCED", "Recalculation Status"],
-    0x005F: ["SAVERECALC", "Recalculate Before Save"],
-    0x0060: ["TEMPLATE", "Workbook Is a Template"],
-    0x0063: ["OBJPROTECT", "Objects Are Protected"],
-    0x007D: ["COLINFO", "Column Formatting Information"],
-    0x007E: ["RK", "Cell Value"],
-    0x007F: ["IMDATA", "Image Data"],
-    0x0809: ["BOF", "Beginning of File"],
-    0x0080: ["GUTS", "Size of Row and Column Gutters"],
-    0x0081: ["WSBOOL", "Additional Workspace Information"],
-    0x0082: ["GRIDSET", "State Change of Gridlines Option"],
-    0x0083: ["HCENTER", "Center Between Horizontal Margins"],
-    0x0084: ["VCENTER", "Center Between Vertical Margins"],
-    0x0085: ["BOUNDSHEET", "Sheet Information"],
-    0x0086: ["WRITEPROT", "Workbook Is Write-Protected"],
-    0x0087: ["ADDIN", "Workbook Is an Add-in Macro"],
-    0x0088: ["EDG", "Edition Globals"],
-    0x0089: ["PUB", "Publisher"],
-    0x008C: ["COUNTRY", "Default Country and WIN.INI Country"],
-    0x008D: ["HIDEOBJ", "Object Display Options"],
-    0x0090: ["SORT", "Sorting Options"],
-    0x0091: ["SUB", "Subscriber"],
-    0x0092: ["PALETTE", "Color Palette Definition"],
-    0x0094: ["LHRECORD", ".WK? File Conversion Information"],
-    0x0095: ["LHNGRAPH", "Named Graph Information"],
-    0x0096: ["SOUND", "Sound Note"],
-    0x0098: ["LPR", "Sheet Was Printed Using LINE.PRINT()"],
-    0x0099: ["STANDARDWIDTH", "Standard Column Width"],
-    0x009A: ["FNGROUPNAME", "Function Group Name"],
-    0x009B: ["FILTERMODE", "Sheet Contains Filtered List"],
-    0x009C: ["FNGROUPCOUNT", "Built-in Function Group Count"],
-    0x009D: ["AUTOFILTERINFO", "Drop-Down Arrow Count"],
-    0x009E: ["AUTOFILTER", "AutoFilter Data"],
-    0x00A0: ["SCL", "Window Zoom Magnification"],
-    0x00A1: ["SETUP", "Page Setup"],
-    0x00A9: ["COORDLIST", "Polygon Object Vertex Coordinates"],
-    0x00AB: ["GCW", "Global Column-Width Flags"],
-    0x00AE: ["SCENMAN", "Scenario Output Data"],
-    0x00AF: ["SCENARIO", "Scenario Data"],
-    0x00B0: ["SXVIEW", "View Definition"],
-    0x00B1: ["SXVD", "View Fields"],
-    0x00B2: ["SXVI", "View Item"],
-    0x00B4: ["SXIVD", "Row/Column Field IDs"],
-    0x00B5: ["SXLI", "Line Item Array"],
-    0x00B6: ["SXPI", "Page Item"],
-    0x00B8: ["DOCROUTE", "Routing Slip Information"],
-    0x00B9: ["RECIPNAME", "Recipient Name"],
-    0x00BC: ["SHRFMLA", "Shared Formula"],
-    0x00BD: ["MULRK", "Multiple RK Cells"],
-    0x00BE: ["MULBLANK", "Multiple Blank Cells"],
-    0x00C1: ["MMS", "ADDMENU/DELMENU Record Group Count"],
-    0x00C2: ["ADDMENU", "Menu Addition"],
-    0x00C3: ["DELMENU", "Menu Deletion"],
-    0x00C5: ["SXDI", "Data Item"],
-    0x00C6: ["SXDB", "PivotTable Cache Data"],
-    0x00CD: ["SXSTRING", "String"],
-    0x00D0: ["SXTBL", "Multiple Consolidation Source Info"],
-    0x00D1: ["SXTBRGIITM", "Page Item Name Count"],
-    0x00D2: ["SXTBPG", "Page Item Indexes"],
-    0x00D3: ["OBPROJ", "Visual Basic Project"],
-    0x00D5: ["SXIDSTM", "Stream ID"],
-    0x00D6: ["RSTRING", "Cell with Character Formatting"],
-    0x00D7: ["DBCELL", "Stream Offsets"],
-    0x00DA: ["BOOKBOOL", "Workbook Option Flag"],
-    0x00DC: ["PARAMQRY", "Query Parameters"],
-    0x00DC: ["SXEXT", "External Source Information"],
-    0x00DD: ["SCENPROTECT", "Scenario Protection"],
-    0x00DE: ["OLESIZE", "Size of OLE Object"],
-    0x00DF: ["UDDESC", "Description String for Chart Autoformat"],
-    0x00E0: ["XF", "Extended Format"],
-    0x00E1: ["INTERFACEHDR", "Beginning of User Interface Records"],
-    0x00E2: ["INTERFACEEND", "End of User Interface Records"],
-    0x00E3: ["SXVS", "View Source"],
-    0x00EA: ["TABIDCONF", "Sheet Tab ID of Conflict History"],
-    0x00EB: ["MSODRAWINGGROUP", "Microsoft Office Drawing Group"],
-    0x00EC: ["MSODRAWING", "Microsoft Office Drawing"],
-    0x00ED: ["MSODRAWINGSELECTION", "Microsoft Office Drawing Selection"],
-    0x00F0: ["SXRULE", "PivotTable Rule Data"],
-    0x00F1: ["SXEX", "PivotTable View Extended Information"],
-    0x00F2: ["SXFILT", "PivotTable Rule Filter"],
-    0x00F6: ["SXNAME", "PivotTable Name"],
-    0x00F7: ["SXSELECT", "PivotTable Selection Information"],
-    0x00F8: ["SXPAIR", "PivotTable Name Pair"],
-    0x00F9: ["SXFMLA", "PivotTable Parsed Expression"],
-    0x00FB: ["SXFORMAT", "PivotTable Format Record"],
-    0x00FC: ["SST", "Shared String Table"],
-    0x00FD: ["LABELSST", "Cell Value"],
-    0x003D: ["WINDOW1", "Window Information"],
-    0x0022: ["DATEMODE", "Base Date for Displaying Date Values"],
-    0x023E: ["WINDOW2", "Sheet Window Information"],
-    0x01AF: ["PROT4REV", "Shared Workbook Protection Flag"],
-    0x01BC: ["PROT4REVPASS", "Shared Workbook Protection Password"],
-    0x0031: ["FONT", "Font and Character Formatting"],
-    0x00FF: ["EXTSST", "Extended Shared String Table"] }
-
-def output (msg):
-    sys.stdout.write(msg)
-
-class XLStream(object):
-
-    def __init__ (self, file):
-        self.chars = file.read()
-        self.size = len(self.chars)
-        self.pos = 0
-        self.version = None
-
-    def __printSep (self, prefix='', c='-', w=68):
-        print(prefix + c*w)
-
-    def printStreamInfo (self):
-        self.__printSep('', '=', 68)
-        print("Excel File Format Dumper by Kohei Yoshida")
-        print("  total stream size: %d bytes"%self.size)
-        self.__printSep('', '=', 68)
-
-    def seekBOF (self):
-        while self.pos < self.size-1:
-            b1, b2 = ord(self.chars[self.pos]), ord(self.chars[self.pos+1])
-            word = b1 + b2*256
-            if word == 0x0809:
-                self.version = 'BIFF5/BIFF8'
-                return
-            self.pos += 2
-
-    def readRaw (self, size=1):
-        # assume little endian
-        bytes = 0
-        for i in xrange(0, size):
-            b = ord(self.chars[self.pos])
-            if i == 0:
-                bytes = b
-            else:
-                bytes += b*(i*256)
-            self.pos += 1
-
-        return bytes
-
-    def readByteArray (self, size=1):
-        bytes = []
-        for i in xrange(0, size):
-            bytes.append(ord(self.chars[self.pos]))
-            self.pos += 1
-        return bytes
-
-    def readRecord (self):
-        pos = self.pos
-        header = self.readRaw(2)
-        size = self.readRaw(2)
-        print("")
-        self.__printSep("%4.4Xh: "%header, '=', 61)
-        if recData.has_key(header):
-            print("%4.4Xh: %s - %s (%4.4Xh)"%(header, recData[header][0], recData[header][1], header))
-        else:
-            print("%4.4Xh: [unknown record name] (%4.4Xh)"%(header, header))
-        print("%4.4Xh:   size = %d; pos = %d"%(header, size, pos))
-        self.__printSep("%4.4Xh: "%header, '-', 61)
-        bytes = self.readByteArray(size)
-        for i in xrange(0, size):
-            if (i+1) % 16 == 1:
-                output("%4.4Xh: "%header)
-            output("%2.2X "%bytes[i])
-            if (i+1) % 16 == 0 and i != size-1:
-                print("")
-        if size > 0:
-            print("")
-
-        return header
+sys.path.append(sys.path[0]+"/src")
+import ole, stream
 
 class XLDumper(object):
 
@@ -254,8 +11,10 @@
 
     def dump (self):
         file = open(self.filepath, 'r')
-        strm = XLStream(file)
+        strm = stream.XLStream(file)
         strm.printStreamInfo()
+        strm.printHeader()
+        strm.printMSAT()
         success = True
         while success: 
             success = self.__read(strm)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]