ooo-build r14913 - in trunk: . scratch/sd-pptutil scratch/sd-pptutil/src



Author: thorstenb
Date: Tue Dec 23 01:34:37 2008
New Revision: 14913
URL: http://svn.gnome.org/viewvc/ooo-build?rev=14913&view=rev

Log:
    * scratch/sd-pptutil/*: cleanup; added more specialized BIFF
    record parser.



Modified:
   trunk/ChangeLog
   trunk/scratch/sd-pptutil/ppt-dump.py
   trunk/scratch/sd-pptutil/src/record.py
   trunk/scratch/sd-pptutil/src/stream.py

Modified: trunk/scratch/sd-pptutil/ppt-dump.py
==============================================================================
--- trunk/scratch/sd-pptutil/ppt-dump.py	(original)
+++ trunk/scratch/sd-pptutil/ppt-dump.py	Tue Dec 23 01:34:37 2008
@@ -31,7 +31,7 @@
 
     def dump (self):
         file = open(self.filepath, 'rb')
-        strm = stream.PPTStream(file.read(), self.params)
+        strm = stream.PPTFile(file.read(), self.params)
         file.close()
         strm.printStreamInfo()
         strm.printHeader()
@@ -44,21 +44,17 @@
             dirstrm = strm.getDirectoryStreamByName(dirname)
             self.__printDirHeader(dirname, len(dirstrm.bytes))
             if  dirname == "PowerPoint Document":
-                self.__readSubStream(dirstrm)
+                if not self.__readSubStream(dirstrm):
+                    return False
             elif  dirname == "Current User":
-                self.__readSubStream(dirstrm)
+                if not self.__readSubStream(dirstrm):
+                    return False
             else:
                 globals.dumpBytes(dirstrm.bytes, 512)
 
     def __readSubStream (self, strm):
-        try:
-            # read bytes from BOF to EOF.
-            header = 0x0000
-            while header != 0x000A:
-                header = strm.readRecord()
-            return True
-        except stream.EndOfStream:
-            return False
+        # read all records in substream
+        return strm.readRecords()
 
 
 def main (args):
@@ -89,7 +85,9 @@
         return
 
     dumper = PPTDumper(args[0], params)
-    dumper.dump()
+    if not dumper.dump():
+        error("FAILURE\n")
+        
 
 if __name__ == '__main__':
     main(sys.argv)

Modified: trunk/scratch/sd-pptutil/src/record.py
==============================================================================
--- trunk/scratch/sd-pptutil/src/record.py	(original)
+++ trunk/scratch/sd-pptutil/src/record.py	Tue Dec 23 01:34:37 2008
@@ -7,12 +7,13 @@
 
 class BaseRecordHandler(object):
 
-    def __init__ (self, recordType, recordInstance, size, bytes):
+    def __init__ (self, recordType, recordInstance, size, bytes, prefix=''):
         self.recordType = recordType
         self.recordInstance = recordInstance
         self.size = size
         self.bytes = bytes
         self.lines = []
+        self.prefix = prefix
         self.pos = 0       # current byte position
 
     def parseBytes (self):
@@ -24,11 +25,14 @@
 """
         pass
 
+    def __print (self, text):
+        print(self.prefix + text)
+
     def output (self):
         self.parseBytes()
-        print("%4.4Xh: %s"%(self.recordType, "-"*61))
+        self.__print("%4.4Xh: %s"%(self.recordType, "-"*61))
         for line in self.lines:
-            print("%4.4Xh: %s"%(self.recordType, line))
+            self.__print("%4.4Xh: %s"%(self.recordType, line))
 
     def appendLine (self, line):
         self.lines.append(line)
@@ -120,7 +124,155 @@
                 self.appendLine("%4.4Xh: [unknown property type: %4.4Xh, value: %8.8Xh, complex: %d, blip: %d]"%(propType, propValue, isComplex, isBlip))
 
 # -------------------------------------------------------------------
-# special record handlers: properties
+# special record handlers: text style properties
+
+class TextStyles(BaseRecordHandler):
+    """Text style properties."""
+
+    def parseBytes (self):
+        # 4 bytes: total len of para attribs
+        # <para attribs>
+        # 4 bytes: total len of char attribs
+        # <char attribs>
+        paraAttribLen = self.readUnsignedInt(4)
+        paraAttribEndPos = self.pos + paraAttribLen
+        while self.pos < paraAttribEndPos:
+            self.parseParaStyle()
+            self.appendLine("-"*61)
+
+        charAttribLen = self.readUnsignedInt(4)
+        charAttribEndPos = self.pos + charAttribLen
+        while self.pos < charAttribEndPos:
+            self.parseCharStyle()
+            self.appendLine("-"*61)
+
+    def appendParaProp (self, text):
+        self.appendLine("para prop given: "+text)
+
+    def appendCharProp (self, text):
+        self.appendLine("char prop given: "+text)
+
+    def parseParaStyle (self):
+        indentLevel = self.readUnsignedInt(2)
+        styleMask = self.readUnsignedInt(4)
+
+        self.appendLine("para props for indent: %d"%indentLevel)
+
+        if styleMask & 0x000F:
+            bulletFlags = self.readUnsignedInt(2)
+            # filter bits not in flag field
+            bulletFlags = bulletFlags & (styleMask & 0x000F)
+            self.appendParaProp("bullet flags %4.4Xh"%bulletFlags)
+
+        if styleMask & 0x0080:
+            bulletChar = self.readUnsignedInt(2)
+            self.appendParaProp("bullet char %4.4Xh"%bulletChar)
+
+        if styleMask & 0x0010:
+            bulletTypeface = self.readUnsignedInt(2)
+            self.appendParaProp("bullet typeface %d"%bulletTypeface)
+
+        if styleMask & 0x0040:
+            bulletSize = self.readSignedInt(2)
+            self.appendParaProp("bullet size %d"%bulletSize)
+
+        if styleMask & 0x0020:
+            bulletColorAtom = ColorPropertyHandler(self.readUnsignedInt(2), self.readUnsignedInt(4), False, False, self.appendParaProp)
+            bulletColorAtom.output()
+            self.appendParaProp("bullet color atom")
+
+        if styleMask & 0x0800:
+            paraAlignment = self.readSignedInt(2)
+            self.appendParaProp("para alignment %4.4Xh"%paraAlignment)
+
+        if styleMask & 0x0400:
+            paraIndent = self.readSignedInt(2)
+            self.appendParaProp("para indent %d"%paraIndent)
+
+        if styleMask & 0x0200:
+            unused = self.readSignedInt(2)
+            self.appendParaProp("unused para property %4.4Xh"%unused)
+
+        if styleMask & 0x0100:
+            paraLeftMargin = self.readSignedInt(2)
+            self.appendParaProp("para left margin %d"%paraLeftMargin)
+
+        if styleMask & 0x1000:
+            paraLineSpacing = self.readSignedInt(2)
+            self.appendParaProp("para linespacing %d"%paraLineSpacing)
+
+        if styleMask & 0x2000:
+            paraSpaceBefore = self.readSignedInt(2)
+            self.appendParaProp("para space before %d"%paraSpaceBefore)
+
+        if styleMask & 0x4000:
+            paraSpaceAfter = self.readSignedInt(2)
+            self.appendParaProp("para space after %d"%paraSpaceAfter)
+
+        if styleMask & 0x8000:
+            paraDefaultTabSize = self.readSignedInt(2)
+            self.appendParaProp("para default tab size %d"%paraDefaultTabSize)
+
+        if styleMask & 0x100000:
+            numTabStops = self.readUnsignedInt(2)
+            for i in xrange(0, numTabStops):
+                tabDistance = self.readUnsignedInt(2)
+                tabAlignment = self.readUnsignedInt(2)
+                self.appendParaProp("para tab stop %d: distance %d, align %4.4Xh"%(i, tabDistance, tabAlignment))
+
+        if styleMask & 0x10000:
+            paraBaseline = self.readUnsignedInt(2)
+            self.appendParaProp("para baseline %d"%paraBaseline)
+
+        if styleMask & 0xE0000:
+            paraAsianLinebreaking = self.readUnsignedInt(2)
+            # filter bits not in flag field
+            paraAsianLinebreaking = paraAsianLinebreaking & ((styleMask & 0xE0000) / 0x20000)
+            self.appendParaProp("para asian line breaking flags %4.4Xh"%paraAsianLinebreaking)
+
+        if styleMask & 0x200000:
+            paraTextDirection = self.readUnsignedInt(2)
+            self.appendParaProp("para text direction %4.4Xh"%paraTextDirection)
+
+    def parseCharStyle (self):
+        styleMask = self.readUnsignedInt(4)
+
+        if styleMask & 0xFFFF:
+            charFlags = self.readUnsignedInt(2)
+            self.appendCharProp("char flags %4.4Xh"%charFlags)
+
+        if styleMask & 0x10000:
+            typeFace = self.readUnsignedInt(2)
+            self.appendCharProp("char typeface %d"%typeFace)
+
+        if styleMask & 0x200000:
+            oldTypeFace = self.readUnsignedInt(2)
+            self.appendCharProp("char old asian typeface %d"%oldTypeFace)
+
+        if styleMask & 0x400000:
+            ansiTypeFace = self.readUnsignedInt(2)
+            self.appendCharProp("char ansi typeface %d"%ansiTypeFace)
+
+        if styleMask & 0x800000:
+            symbolTypeFace = self.readUnsignedInt(2)
+            self.appendCharProp("char symbol typeface %d"%symbolTypeFace)
+
+        if styleMask & 0x20000:
+            fontSize = self.readUnsignedInt(2)
+            self.appendCharProp("char font size %d"%fontSize)
+
+        if styleMask & 0x40000:
+            charColorAtom = ColorPropertyHandler(self.readUnsignedInt(2), self.readUnsignedInt(4), False, False, self.appendCharProp)
+            charColorAtom.output()
+            self.appendCharProp("char color atom")
+
+        if styleMask & 0x80000:
+            fontPosition = self.readSignedInt(2)
+            self.appendCharProp("char font position %d"%fontPosition)
+
+
+# -------------------------------------------------------------------
+# special record handlers: property atoms
 
 class BasePropertyHandler():
     """Base property handler."""
@@ -146,7 +298,8 @@
             if propData.has_key(i):
                 propEntry = propData[i]
                 if type(propEntry[1]) == type(BoolPropertyHandler):
-                    self.printer("%4.4Xh: %s = %d [\"%s\"]"%(self.propType, propEntry[0], (self.propValue & bitMask) != 0, propEntry[2]))
+                    flagValue = self.getTrueFalse(self.propValue & bitMask)
+                    self.printer("%4.4Xh: %s = %d [\"%s\"]"%(self.propType, propEntry[0], flagValue, propEntry[2]))
             bitMask *= 2
 
             
@@ -165,6 +318,24 @@
 class ColorPropertyHandler(BasePropertyHandler):
     """Color property."""   
 
+    def split (self, packedColor):
+        return (packedColor & 0xFF0000) / 0x10000, (packedColor & 0xFF00) / 0x100, (packedColor & 0xFF)
+    
+    def output (self):
+        propEntry = ["<color atom>", None, "undocumented color property"]
+        if propData.has_key(self.propType):
+            propEntry = propData[self.propType]
+        colorValue = self.propValue & 0xFFFFFF
+        if self.propValue & 0xFE000000 == 0xFE000000:
+            self.printer("%4.4Xh: %s = (%d,%d,%d) [\"%s\"]"%(self.propType, propEntry[0], split(colorValue), propEntry[2]))
+        elif self.propValue & 0x08000000 or self.propValue & 0x10000000:
+            self.printer("%4.4Xh: %s = schemecolor(%d) [\"%s\"]"%(self.propType, propEntry[0], colorValue, propEntry[2]))
+        elif self.propValue & 0x04000000:
+            self.printer("%4.4Xh: %s = colorschemecolor(%d) [\"%s\"]"%(self.propType, propEntry[0], colorValue, propEntry[2]))
+        else:
+            self.printer("%4.4Xh: %s = <unidentified color>(%4.4Xh) [\"%s\"]"%(self.propType, propEntry[0], colorValue, propEntry[2]))
+
+
 class CharPropertyHandler(BasePropertyHandler):
     """string property."""  
 
@@ -467,6 +638,7 @@
  904:  ["DFF_Prop_lidRegroup",                   LongPropertyHandler,              "Regroup ID"],
  927:  ["DFF_Prop_tableProperties",             LongPropertyHandler, ""],
  928:  ["DFF_Prop_tableRowProperties",          LongPropertyHandler, ""],
+ 937:  ["DFF_Prop_xmlstuff",                     LongPropertyHandler, "Embedded ooxml"],
  953:  ["DFF_Prop_fEditedWrap",                  BoolPropertyHandler,              "Has the wrap polygon been edited?"],
  954:  ["DFF_Prop_fBehindDocument",              BoolPropertyHandler,              "Word-only (shape is behind text)"],
  955:  ["DFF_Prop_fOnDblClickNotify",            BoolPropertyHandler,              "Notify client on a double click"],

Modified: trunk/scratch/sd-pptutil/src/stream.py
==============================================================================
--- trunk/scratch/sd-pptutil/src/stream.py	(original)
+++ trunk/scratch/sd-pptutil/src/stream.py	Tue Dec 23 01:34:37 2008
@@ -9,226 +9,227 @@
 
 recData = {
 
-	0:  ["DFF_PST_Unknown"],      
-	1:  ["DFF_PST_SubContainerCompleted"],      
-	2:	["DFF_PST_IRRAtom"],                    
-	3:	["DFF_PST_PSS"],                        
-	4:	["DFF_PST_SubContainerException"],      
-	6:	["DFF_PST_ClientSignal1"],              
-	7:	["DFF_PST_ClientSignal2"],              
-   10:	["DFF_PST_PowerPointStateInfoAtom"],    
- 1000:	["DFF_PST_Document"],                   
- 1001:	["DFF_PST_DocumentAtom"],               
- 1002:	["DFF_PST_EndDocument"],                
- 1003:	["DFF_PST_SlidePersist"],               
- 1004:	["DFF_PST_SlideBase"],                  
- 1005:	["DFF_PST_SlideBaseAtom"],              
- 1006:	["DFF_PST_Slide"],                      
- 1007:	["DFF_PST_SlideAtom"],                  
- 1008:	["DFF_PST_Notes"],                      
- 1009:	["DFF_PST_NotesAtom"],                  
- 1010:	["DFF_PST_Environment"],                
- 1011:	["DFF_PST_SlidePersistAtom"],           
- 1012:	["DFF_PST_Scheme"],                     
- 1013:	["DFF_PST_SchemeAtom"],                 
- 1014:	["DFF_PST_DocViewInfo"],                
- 1015:	["DFF_PST_SslideLayoutAtom"],           
- 1016:	["DFF_PST_MainMaster"],                 
- 1017:	["DFF_PST_SSSlideInfoAtom"],            
- 1018:	["DFF_PST_SlideViewInfo"],              
- 1019:	["DFF_PST_GuideAtom"],                  
- 1020:	["DFF_PST_ViewInfo"],                   
- 1021:	["DFF_PST_ViewInfoAtom"],               
- 1022:	["DFF_PST_SlideViewInfoAtom"],          
- 1023:	["DFF_PST_VBAInfo"],                    
- 1024:	["DFF_PST_VBAInfoAtom"],                
- 1025:	["DFF_PST_SSDocInfoAtom"],              
- 1026:	["DFF_PST_Summary"],                    
- 1027:	["DFF_PST_Texture"],                    
- 1028:	["DFF_PST_VBASlideInfo"],               
- 1029:	["DFF_PST_VBASlideInfoAtom"],           
- 1030:	["DFF_PST_DocRoutingSlip"],             
- 1031:	["DFF_PST_OutlineViewInfo"],            
- 1032:	["DFF_PST_SorterViewInfo"],             
- 1033:	["DFF_PST_ExObjList"],                  
- 1034:	["DFF_PST_ExObjListAtom"],              
- 1035:	["DFF_PST_PPDrawingGroup"],             
- 1036:	["DFF_PST_PPDrawing"],                  
- 1040:	["DFF_PST_NamedShows"],                 
- 1041:	["DFF_PST_NamedShow"],                  
- 1042:	["DFF_PST_NamedShowSlides"],            
- 1055:	["DFF_PST_RoundTripShapeId"],           
- 2000:	["DFF_PST_List"],                       
- 2005:	["DFF_PST_FontCollection"],             
- 2017:	["DFF_PST_ListPlaceholder"],            
- 2019:	["DFF_PST_BookmarkCollection"],         
- 2020:	["DFF_PST_SoundCollection"],            
- 2021:	["DFF_PST_SoundCollAtom"],              
- 2022:	["DFF_PST_Sound"],                      
- 2023:	["DFF_PST_SoundData"],                  
- 2025:	["DFF_PST_BookmarkSeedAtom"],           
- 2026:	["DFF_PST_GuideList"],                  
- 2028:	["DFF_PST_RunArray"],                   
- 2029:	["DFF_PST_RunArrayAtom"],               
- 2030:	["DFF_PST_ArrayElementAtom"],           
- 2031:	["DFF_PST_Int4ArrayAtom"],              
- 2032:	["DFF_PST_ColorSchemeAtom"],            
- 3008:	["DFF_PST_OEShape"],                    
- 3009:	["DFF_PST_ExObjRefAtom"],               
- 3011:	["DFF_PST_OEPlaceholderAtom"],          
- 3020:	["DFF_PST_GrColor"],                    
- 3025:	["DFF_PST_GrectAtom"],                  
- 3031:	["DFF_PST_GratioAtom"],                 
- 3032:	["DFF_PST_Gscaling"],                   
- 3034:	["DFF_PST_GpointAtom"],                 
- 3035:	["DFF_PST_OEShapeAtom"],                
- 3998:	["DFF_PST_OutlineTextRefAtom"],         
- 3999:	["DFF_PST_TextHeaderAtom"],             
- 4000:	["DFF_PST_TextCharsAtom", record.UniString],
- 4001:	["DFF_PST_StyleTextPropAtom"],          
- 4002:	["DFF_PST_BaseTextPropAtom"],           
- 4003:	["DFF_PST_TxMasterStyleAtom"],          
- 4004:	["DFF_PST_TxCFStyleAtom"],              
- 4005:	["DFF_PST_TxPFStyleAtom"],              
- 4006:	["DFF_PST_TextRulerAtom"],              
- 4007:	["DFF_PST_TextBookmarkAtom"],           
- 4008:	["DFF_PST_TextBytesAtom", record.String],
- 4009:	["DFF_PST_TxSIStyleAtom"],              
- 4010:	["DFF_PST_TextSpecInfoAtom"],           
- 4011:	["DFF_PST_DefaultRulerAtom"],           
- 4023:	["DFF_PST_FontEntityAtom"],             
- 4024:	["DFF_PST_FontEmbedData"],              
- 4025:	["DFF_PST_TypeFace"],                   
- 4026:	["DFF_PST_CString"],                    
- 4027:	["DFF_PST_ExternalObject"],             
- 4033:	["DFF_PST_MetaFile"],                   
- 4034:	["DFF_PST_ExOleObj"],                   
- 4035:	["DFF_PST_ExOleObjAtom"],               
- 4036:	["DFF_PST_ExPlainLinkAtom"],            
- 4037:	["DFF_PST_CorePict"],                   
- 4038:	["DFF_PST_CorePictAtom"],               
- 4039:	["DFF_PST_ExPlainAtom"],                
- 4040:	["DFF_PST_SrKinsoku"],                  
- 4041:	["DFF_PST_Handout"],                    
- 4044:	["DFF_PST_ExEmbed"],                    
- 4045:	["DFF_PST_ExEmbedAtom"],                
- 4046:	["DFF_PST_ExLink"],                     
- 4047:	["DFF_PST_ExLinkAtom_old"],             
- 4048:	["DFF_PST_BookmarkEntityAtom"],         
- 4049:	["DFF_PST_ExLinkAtom"],                 
- 4050:	["DFF_PST_SrKinsokuAtom"],              
- 4051:	["DFF_PST_ExHyperlinkAtom"],            
- 4053:	["DFF_PST_ExPlain"],                    
- 4054:	["DFF_PST_ExPlainLink"],                
- 4055:	["DFF_PST_ExHyperlink"],                
- 4056:	["DFF_PST_SlideNumberMCAtom"],          
- 4057:	["DFF_PST_HeadersFooters"],             
- 4058:	["DFF_PST_HeadersFootersAtom"],         
- 4062:	["DFF_PST_RecolorEntryAtom"],           
- 4063:	["DFF_PST_TxInteractiveInfoAtom"],      
- 4065:	["DFF_PST_EmFormatAtom"],               
- 4066:	["DFF_PST_CharFormatAtom"],             
- 4067:	["DFF_PST_ParaFormatAtom"],             
- 4068:	["DFF_PST_MasterText"],                 
- 4071:	["DFF_PST_RecolorInfoAtom"],            
- 4073:	["DFF_PST_ExQuickTime"],                
- 4074:	["DFF_PST_ExQuickTimeMovie"],           
- 4075:	["DFF_PST_ExQuickTimeMovieData"],       
- 4076:	["DFF_PST_ExSubscription"],             
- 4077:	["DFF_PST_ExSubscriptionSection"],      
- 4078:	["DFF_PST_ExControl"],                  
- 4091:	["DFF_PST_ExControlAtom"],              
- 4080:	["DFF_PST_SlideListWithText"],          
- 4081:	["DFF_PST_AnimationInfoAtom"],          
- 4082:	["DFF_PST_InteractiveInfo"],            
- 4083:	["DFF_PST_InteractiveInfoAtom"],        
- 4084:	["DFF_PST_SlideList"],                  
- 4085:	["DFF_PST_UserEditAtom"],               
- 4086:	["DFF_PST_CurrentUserAtom"],            
- 4087:	["DFF_PST_DateTimeMCAtom"],             
- 4088:	["DFF_PST_GenericDateMCAtom"],          
- 4089:	["DFF_PST_HeaderMCAtom"],               
- 4090:	["DFF_PST_FooterMCAtom"],               
- 4100:	["DFF_PST_ExMediaAtom"],                
- 4101:	["DFF_PST_ExVideo"],                    
- 4102:	["DFF_PST_ExAviMovie"],                 
- 4103:	["DFF_PST_ExMCIMovie"],                 
- 4109:	["DFF_PST_ExMIDIAudio"],                
- 4110:	["DFF_PST_ExCDAudio"],                  
- 4111:	["DFF_PST_ExWAVAudioEmbedded"],         
- 4112:	["DFF_PST_ExWAVAudioLink"],             
- 4113:	["DFF_PST_ExOleObjStg"],                
- 4114:	["DFF_PST_ExCDAudioAtom"],              
- 4115:	["DFF_PST_ExWAVAudioEmbeddedAtom"],     
- 4116:	["DFF_PST_AnimationInfo"],              
- 4117:	["DFF_PST_RTFDateTimeMCAtom"],          
- 5000:	["DFF_PST_ProgTags"],                   
- 5001:	["DFF_PST_ProgStringTag"],              
- 5002:	["DFF_PST_ProgBinaryTag"],              
- 5003:	["DFF_PST_BinaryTagData"],              
- 6000:	["DFF_PST_PrintOptions"],               
- 6001:	["DFF_PST_PersistPtrFullBlock"],        
- 6002:	["DFF_PST_PersistPtrIncrementalBlock"], 
-10000:	["DFF_PST_RulerIndentAtom"],            
-10001:	["DFF_PST_GscalingAtom"],               
-10002:	["DFF_PST_GrColorAtom"],                
-10003:	["DFF_PST_GLPointAtom"],                
-10004:	["DFF_PST_GlineAtom"],                  
+    0:  ["DFF_PST_Unknown"],      
+    1:  ["DFF_PST_SubContainerCompleted"],      
+    2:  ["DFF_PST_IRRAtom"],                    
+    3:  ["DFF_PST_PSS"],                        
+    4:  ["DFF_PST_SubContainerException"],      
+    6:  ["DFF_PST_ClientSignal1"],              
+    7:  ["DFF_PST_ClientSignal2"],              
+   10:  ["DFF_PST_PowerPointStateInfoAtom"],    
+ 1000:  ["DFF_PST_Document"],                   
+ 1001:  ["DFF_PST_DocumentAtom"],               
+ 1002:  ["DFF_PST_EndDocument"],                
+ 1003:  ["DFF_PST_SlidePersist"],               
+ 1004:  ["DFF_PST_SlideBase"],                  
+ 1005:  ["DFF_PST_SlideBaseAtom"],              
+ 1006:  ["DFF_PST_Slide"],                      
+ 1007:  ["DFF_PST_SlideAtom"],                  
+ 1008:  ["DFF_PST_Notes"],                      
+ 1009:  ["DFF_PST_NotesAtom"],                  
+ 1010:  ["DFF_PST_Environment"],                
+ 1011:  ["DFF_PST_SlidePersistAtom"],           
+ 1012:  ["DFF_PST_Scheme"],                     
+ 1013:  ["DFF_PST_SchemeAtom"],                 
+ 1014:  ["DFF_PST_DocViewInfo"],                
+ 1015:  ["DFF_PST_SslideLayoutAtom"],           
+ 1016:  ["DFF_PST_MainMaster"],                 
+ 1017:  ["DFF_PST_SSSlideInfoAtom"],            
+ 1018:  ["DFF_PST_SlideViewInfo"],              
+ 1019:  ["DFF_PST_GuideAtom"],                  
+ 1020:  ["DFF_PST_ViewInfo"],                   
+ 1021:  ["DFF_PST_ViewInfoAtom"],               
+ 1022:  ["DFF_PST_SlideViewInfoAtom"],          
+ 1023:  ["DFF_PST_VBAInfo"],                    
+ 1024:  ["DFF_PST_VBAInfoAtom"],                
+ 1025:  ["DFF_PST_SSDocInfoAtom"],              
+ 1026:  ["DFF_PST_Summary"],                    
+ 1027:  ["DFF_PST_Texture"],                    
+ 1028:  ["DFF_PST_VBASlideInfo"],               
+ 1029:  ["DFF_PST_VBASlideInfoAtom"],           
+ 1030:  ["DFF_PST_DocRoutingSlip"],             
+ 1031:  ["DFF_PST_OutlineViewInfo"],            
+ 1032:  ["DFF_PST_SorterViewInfo"],             
+ 1033:  ["DFF_PST_ExObjList"],                  
+ 1034:  ["DFF_PST_ExObjListAtom"],              
+ 1035:  ["DFF_PST_PPDrawingGroup"],             
+ 1036:  ["DFF_PST_PPDrawing"],                  
+ 1040:  ["DFF_PST_NamedShows"],                 
+ 1041:  ["DFF_PST_NamedShow"],                  
+ 1042:  ["DFF_PST_NamedShowSlides"],            
+ 1055:  ["DFF_PST_RoundTripShapeId"],           
+ 2000:  ["DFF_PST_List"],                       
+ 2005:  ["DFF_PST_FontCollection"],             
+ 2017:  ["DFF_PST_ListPlaceholder"],            
+ 2019:  ["DFF_PST_BookmarkCollection"],         
+ 2020:  ["DFF_PST_SoundCollection"],            
+ 2021:  ["DFF_PST_SoundCollAtom"],              
+ 2022:  ["DFF_PST_Sound"],                      
+ 2023:  ["DFF_PST_SoundData"],                  
+ 2025:  ["DFF_PST_BookmarkSeedAtom"],           
+ 2026:  ["DFF_PST_GuideList"],                  
+ 2028:  ["DFF_PST_RunArray"],                   
+ 2029:  ["DFF_PST_RunArrayAtom"],               
+ 2030:  ["DFF_PST_ArrayElementAtom"],           
+ 2031:  ["DFF_PST_Int4ArrayAtom"],              
+ 2032:  ["DFF_PST_ColorSchemeAtom"],            
+ 3008:  ["DFF_PST_OEShape"],                    
+ 3009:  ["DFF_PST_ExObjRefAtom"],               
+ 3011:  ["DFF_PST_OEPlaceholderAtom"],          
+ 3020:  ["DFF_PST_GrColor"],                    
+ 3025:  ["DFF_PST_GrectAtom"],                  
+ 3031:  ["DFF_PST_GratioAtom"],                 
+ 3032:  ["DFF_PST_Gscaling"],                   
+ 3034:  ["DFF_PST_GpointAtom"],                 
+ 3035:  ["DFF_PST_OEShapeAtom"],                
+ 3998:  ["DFF_PST_OutlineTextRefAtom"],         
+ 3999:  ["DFF_PST_TextHeaderAtom"],             
+ 4000:  ["DFF_PST_TextCharsAtom", record.UniString],
+ 4001:  ["DFF_PST_StyleTextPropAtom", record.TextStyles],          
+ 4002:  ["DFF_PST_BaseTextPropAtom"],           
+ 4003:  ["DFF_PST_TxMasterStyleAtom"],          
+ 4004:  ["DFF_PST_TxCFStyleAtom"],              
+ 4005:  ["DFF_PST_TxPFStyleAtom"],              
+ 4006:  ["DFF_PST_TextRulerAtom"],              
+ 4007:  ["DFF_PST_TextBookmarkAtom"],           
+ 4008:  ["DFF_PST_TextBytesAtom", record.String],
+ 4009:  ["DFF_PST_TxSIStyleAtom"],              
+ 4010:  ["DFF_PST_TextSpecInfoAtom"],           
+ 4011:  ["DFF_PST_DefaultRulerAtom"],           
+ 4023:  ["DFF_PST_FontEntityAtom"],             
+ 4024:  ["DFF_PST_FontEmbedData"],              
+ 4025:  ["DFF_PST_TypeFace"],                   
+ 4026:  ["DFF_PST_CString"],                    
+ 4027:  ["DFF_PST_ExternalObject"],             
+ 4033:  ["DFF_PST_MetaFile"],                   
+ 4034:  ["DFF_PST_ExOleObj"],                   
+ 4035:  ["DFF_PST_ExOleObjAtom"],               
+ 4036:  ["DFF_PST_ExPlainLinkAtom"],            
+ 4037:  ["DFF_PST_CorePict"],                   
+ 4038:  ["DFF_PST_CorePictAtom"],               
+ 4039:  ["DFF_PST_ExPlainAtom"],                
+ 4040:  ["DFF_PST_SrKinsoku"],                  
+ 4041:  ["DFF_PST_Handout"],                    
+ 4044:  ["DFF_PST_ExEmbed"],                    
+ 4045:  ["DFF_PST_ExEmbedAtom"],                
+ 4046:  ["DFF_PST_ExLink"],                     
+ 4047:  ["DFF_PST_ExLinkAtom_old"],             
+ 4048:  ["DFF_PST_BookmarkEntityAtom"],         
+ 4049:  ["DFF_PST_ExLinkAtom"],                 
+ 4050:  ["DFF_PST_SrKinsokuAtom"],              
+ 4051:  ["DFF_PST_ExHyperlinkAtom"],            
+ 4053:  ["DFF_PST_ExPlain"],                    
+ 4054:  ["DFF_PST_ExPlainLink"],                
+ 4055:  ["DFF_PST_ExHyperlink"],                
+ 4056:  ["DFF_PST_SlideNumberMCAtom"],          
+ 4057:  ["DFF_PST_HeadersFooters"],             
+ 4058:  ["DFF_PST_HeadersFootersAtom"],         
+ 4062:  ["DFF_PST_RecolorEntryAtom"],           
+ 4063:  ["DFF_PST_TxInteractiveInfoAtom"],      
+ 4065:  ["DFF_PST_EmFormatAtom"],               
+ 4066:  ["DFF_PST_CharFormatAtom"],             
+ 4067:  ["DFF_PST_ParaFormatAtom"],             
+ 4068:  ["DFF_PST_MasterText"],                 
+ 4071:  ["DFF_PST_RecolorInfoAtom"],            
+ 4073:  ["DFF_PST_ExQuickTime"],                
+ 4074:  ["DFF_PST_ExQuickTimeMovie"],           
+ 4075:  ["DFF_PST_ExQuickTimeMovieData"],       
+ 4076:  ["DFF_PST_ExSubscription"],             
+ 4077:  ["DFF_PST_ExSubscriptionSection"],      
+ 4078:  ["DFF_PST_ExControl"],                  
+ 4091:  ["DFF_PST_ExControlAtom"],              
+ 4080:  ["DFF_PST_SlideListWithText"],          
+ 4081:  ["DFF_PST_AnimationInfoAtom"],          
+ 4082:  ["DFF_PST_InteractiveInfo"],            
+ 4083:  ["DFF_PST_InteractiveInfoAtom"],        
+ 4084:  ["DFF_PST_SlideList"],                  
+ 4085:  ["DFF_PST_UserEditAtom"],               
+ 4086:  ["DFF_PST_CurrentUserAtom"],            
+ 4087:  ["DFF_PST_DateTimeMCAtom"],             
+ 4088:  ["DFF_PST_GenericDateMCAtom"],          
+ 4089:  ["DFF_PST_HeaderMCAtom"],               
+ 4090:  ["DFF_PST_FooterMCAtom"],               
+ 4100:  ["DFF_PST_ExMediaAtom"],                
+ 4101:  ["DFF_PST_ExVideo"],                    
+ 4102:  ["DFF_PST_ExAviMovie"],                 
+ 4103:  ["DFF_PST_ExMCIMovie"],                 
+ 4109:  ["DFF_PST_ExMIDIAudio"],                
+ 4110:  ["DFF_PST_ExCDAudio"],                  
+ 4111:  ["DFF_PST_ExWAVAudioEmbedded"],         
+ 4112:  ["DFF_PST_ExWAVAudioLink"],             
+ 4113:  ["DFF_PST_ExOleObjStg"],                
+ 4114:  ["DFF_PST_ExCDAudioAtom"],              
+ 4115:  ["DFF_PST_ExWAVAudioEmbeddedAtom"],     
+ 4116:  ["DFF_PST_AnimationInfo"],              
+ 4117:  ["DFF_PST_RTFDateTimeMCAtom"],          
+ 5000:  ["DFF_PST_ProgTags"],                   
+ 5001:  ["DFF_PST_ProgStringTag"],              
+ 5002:  ["DFF_PST_ProgBinaryTag"],              
+ 5003:  ["DFF_PST_BinaryTagData"],              
+ 6000:  ["DFF_PST_PrintOptions"],               
+ 6001:  ["DFF_PST_PersistPtrFullBlock"],        
+ 6002:  ["DFF_PST_PersistPtrIncrementalBlock"], 
+10000:  ["DFF_PST_RulerIndentAtom"],            
+10001:  ["DFF_PST_GscalingAtom"],               
+10002:  ["DFF_PST_GrColorAtom"],                
+10003:  ["DFF_PST_GLPointAtom"],                
+10004:  ["DFF_PST_GlineAtom"],                  
 
 0xF000: ["DFF_msofbtDggContainer"],    
-0xF006:	["DFF_msofbtDgg"],             
-0xF016:	["DFF_msofbtCLSID"],           
-0xF00B:	["DFF_msofbtOPT", record.Property],             
-0xF11A:	["DFF_msofbtColorMRU"],        
-0xF11E:	["DFF_msofbtSplitMenuColors"], 
-0xF001:	["DFF_msofbtBstoreContainer"], 
-0xF007:	["DFF_msofbtBSE"],             
-0xF018:	["DFF_msofbtBlipFirst"],       
-0xF117:	["DFF_msofbtBlipLast"],        
-								  
-0xF002:	["DFF_msofbtDgContainer"],     
-0xF008:	["DFF_msofbtDg"],              
-0xF118:	["DFF_msofbtRegroupItems"],    
-0xF120:	["DFF_msofbtColorScheme"],     
-0xF003:	["DFF_msofbtSpgrContainer"],   
-0xF004:	["DFF_msofbtSpContainer"],     
-0xF009:	["DFF_msofbtSpgr"],            
-0xF00A:	["DFF_msofbtSp"],              
-0xF00C:	["DFF_msofbtTextbox"],         
-0xF00D:	["DFF_msofbtClientTextbox"],   
-0xF00E:	["DFF_msofbtAnchor"],          
-0xF00F:	["DFF_msofbtChildAnchor"],     
-0xF010:	["DFF_msofbtClientAnchor"],    
-0xF011:	["DFF_msofbtClientData"],      
-0xF11F:	["DFF_msofbtOleObject"],       
-0xF11D:	["DFF_msofbtDeletedPspl"],     
-0xF122:	["DFF_msofbtUDefProp"],        
-0xF005:	["DFF_msofbtSolverContainer"], 
-0xF012:	["DFF_msofbtConnectorRule"],   
-0xF013:	["DFF_msofbtAlignRule"],       
-0xF014:	["DFF_msofbtArcRule"],         
-0xF015:	["DFF_msofbtClientRule"],      
-0xF017:	["DFF_msofbtCalloutRule"],     
-								  
-0xF119:	["DFF_msofbtSelection"]       
+0xF006: ["DFF_msofbtDgg"],             
+0xF016: ["DFF_msofbtCLSID"],           
+0xF00B: ["DFF_msofbtOPT", record.Property],             
+0xF11A: ["DFF_msofbtColorMRU"],        
+0xF11E: ["DFF_msofbtSplitMenuColors"], 
+0xF001: ["DFF_msofbtBstoreContainer"], 
+0xF007: ["DFF_msofbtBSE"],             
+0xF018: ["DFF_msofbtBlipFirst"],       
+0xF117: ["DFF_msofbtBlipLast"],        
+                                  
+0xF002: ["DFF_msofbtDgContainer"],     
+0xF008: ["DFF_msofbtDg"],              
+0xF118: ["DFF_msofbtRegroupItems"],    
+0xF120: ["DFF_msofbtColorScheme"],     
+0xF003: ["DFF_msofbtSpgrContainer"],   
+0xF004: ["DFF_msofbtSpContainer"],     
+0xF009: ["DFF_msofbtSpgr"],            
+0xF00A: ["DFF_msofbtSp"],              
+0xF00C: ["DFF_msofbtTextbox"],         
+0xF00D: ["DFF_msofbtClientTextbox"],   
+0xF00E: ["DFF_msofbtAnchor"],          
+0xF00F: ["DFF_msofbtChildAnchor"],     
+0xF010: ["DFF_msofbtClientAnchor"],    
+0xF011: ["DFF_msofbtClientData"],      
+0xF11F: ["DFF_msofbtOleObject"],       
+0xF11D: ["DFF_msofbtDeletedPspl"],     
+0xF122: ["DFF_msofbtUDefProp"],        
+0xF005: ["DFF_msofbtSolverContainer"], 
+0xF012: ["DFF_msofbtConnectorRule"],   
+0xF013: ["DFF_msofbtAlignRule"],       
+0xF014: ["DFF_msofbtArcRule"],         
+0xF015: ["DFF_msofbtClientRule"],      
+0xF017: ["DFF_msofbtCalloutRule"],     
+                                  
+0xF119: ["DFF_msofbtSelection"]       
 
 }
 
-class PPTStream(object):
-
+class PPTFile(object):
+    """Represents the whole powerpoint file - feed will all bytes."""
     def __init__ (self, chars, params):
         self.chars = chars
         self.size = len(self.chars)
-        self.pos = 0
         self.version = None
+        self.params = params
 
-        self.header = None
+        self.header = ole.Header(self.chars, self.params)
+        self.pos = self.header.parse()
 
-        self.params = params
 
     def __printSep (self, c='-', w=68, prefix=''):
         print(prefix + c*w)
 
+
     def printStreamInfo (self):
         self.__printSep('=', 68)
         print("PPT File Format Dumper by Kohei Yoshida & Thorsten Behrens")
@@ -236,11 +237,11 @@
         self.__printSep('=', 68)
         print('')
 
+
     def printHeader (self):
-        self.header = ole.Header(self.chars, self.params)
-        self.pos = self.header.parse()
         self.header.output()
 
+
     def __getDirectoryObj (self):
         obj = self.header.getDirectory()
         if obj == None:
@@ -248,6 +249,7 @@
         obj.parseDirEntries()
         return obj
 
+
     def printDirectory (self):
         obj = self.__getDirectoryObj()
         if obj == None:
@@ -272,101 +274,93 @@
 
 
 class PPTDirStream(object):
-
-    def __init__ (self, bytes, params):
+    """Represents one single powerpoint file subdirectory, like e.g. \"PowerPoint Document\"."""
+    def __init__ (self, bytes, params, prefix=''):
         self.bytes = bytes
         self.size = len(self.bytes)
         self.pos = 0
-
+        self.prefix = prefix
         self.params = params
 
 
-    def readRaw (self, size=1):
-        # PPT stores little endian
-        bytes = 0
-        for i in xrange(0, size):
-            b = ord(self.bytes[self.pos])
-            if i == 0:
-                bytes = b
-            else:
-                bytes += b*(256**i)
-            self.pos += 1
-
+    def readBytes (self, size=1):
+        if self.size - self.pos < size:
+            raise EndOfStream
+        bytes = self.bytes[self.pos:self.pos+size]
+        self.pos += size
         return bytes
 
-    def readRawByteArray (self, size=1):
-        bytes = []
-        for i in xrange(0, size):
-            if self.pos >= self.size:
-                raise EndOfStream
-            bytes.append(ord(self.bytes[self.pos]))
-            self.pos += 1
-        return bytes
 
-    def readByteArray (self, size=1):
-        bytes = []
-        for i in xrange(0, size):
-            if self.pos >= self.size:
-                raise EndOfStream
-            bytes.append(self.bytes[self.pos])
-            self.pos += 1
-        return bytes
+    def readUnsignedInt (self, size=1):
+        return globals.getUnsignedInt(self.readBytes(size))
+
+
+    def __print (self, text):
+        print(self.prefix + text)
+
 
     def __printSep (self, c='-', w=68, prefix=''):
-        print(prefix + c*w)
+        self.__print(prefix + c*w)
 
-    def readRecord (self):
-        if self.size - self.pos < 4:
-            raise EndOfStream
 
-        pos = self.pos
-        recordInstance = self.readRaw(2)
-        recordVersion = (recordInstance & 0x000F)
-        recordInstance = recordInstance / 16
-        recordType = self.readRaw(2)
-        size = self.readRaw(4)
+    def readRecords (self):
+        try:
+            # read until data is exhausted
+            while self.pos < self.size:
+                print("")
+                self.readRecord()
+            return True 
+        except EndOfStream:
+            return False
 
-        # substream? recurse into that
-        if recordVersion == 0x0F:
-            substrm = PPTDirStream(self.readByteArray(size), self.params )
-            
-            try:
-                # read bytes until DFF_PST_SubContainerCompleted
-                header = 0x0000
-                while header != 0x0001:
-                    header = substrm.readRecord()
-                return recordInstance
-            except EndOfStream:
-                return recordInstance
-
-        bytes = self.readRawByteArray(size)
-
-        # record handler that parses the raw bytes and displays more 
-        # meaningful information.
-        handler = None 
 
-        print("")
-        self.__printSep('=', 61, "%4.4Xh: "%recordType)
+    def printRecordHeader (self, startPos, recordInstance, recordVersion, recordType, size):
+        self.__printSep('=')
         if recData.has_key(recordType):
-            print("%4.4Xh: %s (%4.4Xh %4.4Xh)"%
-                  (recordType, recData[recordType][0], recordType, recordInstance))
-            if len(recData[recordType]) >= 2:
-                handler = recData[recordType][1](recordType, recordInstance, size, bytes)
+            self.__print("[%s]"%recData[recordType][0])
         else:
-            print("%4.4Xh: [unknown record name] (%4.4Xh)"%(recordType, recordInstance))
-        print("%4.4Xh:   size = %d; pos = %d"%(recordType, size, pos))
+            self.__print("[anon record]")
+        self.__print("(type: %4.4Xh inst: %4.4Xh, vers: %4.4Xh, start: %d, size: %d)"%
+              (recordType, recordInstance, recordVersion, startPos, size))
+        self.__printSep('=')
+
+
+    def printRecordDump (self, bytes, recordType):
+        size = len(bytes)
         self.__printSep('-', 61, "%4.4Xh: "%recordType)
         for i in xrange(0, size):
             if (i+1) % 16 == 1:
-                output("%4.4Xh: "%recordType)
-            output("%2.2X "%bytes[i])
+                output(self.prefix + "%4.4Xh: "%recordType)
+            output("%2.2X "%ord(bytes[i]))
             if (i+1) % 16 == 0 and i != size-1:
                 print("")
         if size > 0:
             print("")
 
-        if handler != None:
-            # record handler exists.  Parse the record and display more info.
-            handler.output()
+    
+    def readRecord (self):
+        startPos = self.pos
+        recordInstance = self.readUnsignedInt(2)
+        recordVersion = (recordInstance & 0x000F)
+        recordInstance = recordInstance / 16
+        recordType = self.readUnsignedInt(2)
+        size = self.readUnsignedInt(4)
 
-        return recordType
+        self.printRecordHeader(startPos, recordInstance, recordVersion, recordType, size)
+        bytes = self.readBytes(size)
+        
+        if recData.has_key(recordType) and len(recData[recordType]) >= 2:
+            assert(recordVersion != 0x0F)
+            # call special record handler, if any
+            handler = recData[recordType][1](recordType, recordInstance, size, bytes, self.prefix)
+            print("")
+            if handler != None:
+                handler.output()
+            self.printRecordDump(bytes, recordType)
+        elif recordVersion == 0x0F:
+            # substream? recurse into that
+            subSubStrm = PPTDirStream(bytes, self.params, self.prefix+" ")
+            subSubStrm.readRecords()
+        elif size > 0:
+            print("")
+            self.printRecordDump(bytes, recordType)



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