[Libreoffice-commits] .: scratch/mso-dumper
Noel Power
noelp at kemper.freedesktop.org
Mon Jan 31 02:20:04 PST 2011
scratch/mso-dumper/oletool.diff | 230 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 230 insertions(+)
New commits:
commit e524d02fd320bd9a2cc62c4cf72755db0a5e892a
Author: Noel Power <noel.power at novell.com>
Date: Mon Jan 31 10:19:28 2011 +0000
new tool for listing/adding/replacing/extracting ole files/content
diff --git a/scratch/mso-dumper/oletool.diff b/scratch/mso-dumper/oletool.diff
new file mode 100644
index 0000000..c882229
--- /dev/null
+++ b/scratch/mso-dumper/oletool.diff
@@ -0,0 +1,230 @@
+--- /dev/null 2011-01-31 08:27:50.166383946 +0000
++++ scratch/mso-dumper/src/oletool.py 2011-01-31 09:15:32.000000000 +0000
+@@ -0,0 +1,204 @@
++#!/usr/bin/env python
++import sys, os.path, optparse
++
++sys.path.append(sys.path[0]+"/src")
++
++import ole, globals
++
++from globals import encodeName
++class DateTime:
++ def __init__(self):
++ self.day = 0
++ self.month = 0
++ self.year = 0
++ self.hour = 0
++ self.second = 0
++
++class DirNode:
++
++ def __init__(self, entry):
++ self.Nodes = []
++ self.Entry = entry;
++ self.HierachicalName = ''
++
++ def isStorage():
++ return entry.Type == Directory.Type.RootStorage
++
++class OleContainer:
++
++ def __init__(self,filePath, params ):
++ self.filePath = filePath
++ self.header = None
++ self.params = params
++ self.pos = None
++
++ def __getModifiedTime(self, entry):
++ # need parse/decode Entry.TimeModified
++ # ( although the documentation indicates that it might not be
++ # worth it 'cause they are not universally used
++ modified = DateTime
++ modified.day = 0
++ modified.month = 0
++ modified.year = 0
++ modified.hour = 0
++ modified.second = 0
++ return modified
++
++ def __parseFile (self):
++ file = open(self.filePath, 'rb')
++ self.strmData = globals.StreamData()
++ self.chars = file.read()
++ file.close()
++
++ def __addSiblings( self, entries, parent, child ):
++ # add left siblings
++ nextLeft = child.Entry.DirIDLeft
++ if ( nextLeft > 0 ):
++ newEntry = DirNode( entries[ nextLeft ] )
++ newEntry.HierachicalName = parent.HierachicalName + globals.encodeName( newEntry.Entry.Name )
++ if newEntry.Entry.DirIDRoot > 0:
++ newEntry.HierachicalName = newEntry.HierachicalName + '/'
++
++ self.__addSiblings( entries, parent, newEntry )
++ parent.Nodes.insert( 0, newEntry )
++
++ nextRight = child.Entry.DirIDRight
++ # add children to the right
++ if ( nextRight > 0 ):
++ newEntry = DirNode( entries[ nextRight ] )
++ newEntry.HierachicalName = parent.HierachicalName + globals.encodeName( newEntry.Entry.Name )
++ if newEntry.Entry.DirIDRoot > 0:
++ newEntry.HierachicalName = newEntry.HierachicalName + '/'
++ self.__addSiblings( entries, parent, newEntry )
++ parent.Nodes.append( newEntry )
++
++ def __buildTreeImpl(self, entries, parent ):
++
++ if ( parent.Entry.DirIDRoot > 0 ):
++ newEntry = DirNode( entries[ parent.Entry.DirIDRoot ] )
++ newEntry.HierachicalName = parent.HierachicalName + globals.encodeName( newEntry.Entry.Name )
++ if ( newEntry.Entry.DirIDRoot > 0 ):
++ newEntry.HierachicalName = newEntry.HierachicalName + '/'
++
++ self.__addSiblings( entries, parent, newEntry )
++ parent.Nodes.append( newEntry )
++
++ for child in parent.Nodes:
++ if child.Entry.DirIDRoot > 0:
++ self.__buildTreeImpl( entries, child )
++
++ def __buildTree(self, entries ):
++ treeRoot = DirNode( entries[0] )
++ self.__buildTreeImpl( entries, treeRoot )
++ return treeRoot
++
++ def __findEntryByHierachicalName( self, node, name ):
++ if node.HierachicalName == name:
++ return node.Entry
++ else:
++ for child in node.Nodes:
++ result = self.__findEntryByHierachicalName( child, name )
++ if result != None:
++ return result
++ return None
++
++ def __printListReport( self, treeNode, stats ):
++
++ dateInfo = self.__getModifiedTime( treeNode.Entry )
++
++ if len( treeNode.HierachicalName ) > 0 :
++ print '{0:8d} {1:0<2d}-{2:0<2d}-{3:0<2d} {4:0<2d}:{5:0<2d} {6}'.format(treeNode.Entry.StreamSize, dateInfo.day, dateInfo.month, dateInfo.year, dateInfo.hour, dateInfo.second, treeNode.HierachicalName )
++
++ for node in treeNode.Nodes:
++ # ignore the root
++ self.__printListReport( node, stats )
++
++ def __printHeader(self):
++ print ("OLE: %s")%self.filePath
++ print (" Length Date Time Name")
++ print ("-------- ---- ---- ----")
++
++ def listEntries(self):
++ self.__parseFile()
++ #if self.header == None:
++ # self.header = ole.Header(self.chars, self.params)
++ # self.pos = self.header.parse()
++ self.header = ole.Header(self.chars, self.params)
++ self.pos = self.header.parse()
++ obj = self.header.getDirectory()
++ if obj != None:
++ obj.parseDirEntries()
++ count = 0
++ for entry in obj.entries:
++ print("Entry [0x%x] Name %s Root 0x%x Left 0x%x Right %x")%( count, entry.Name, entry.DirIDRoot, entry.DirIDLeft, entry.DirIDRight )
++ count = count + 1
++ def list(self):
++ # need to share the inititialisation and parse stuff between the different options
++ self.__parseFile()
++ if self.header == None:
++ self.header = ole.Header(self.chars, self.params)
++ self.pos = self.header.parse()
++ obj = self.header.getDirectory()
++ if obj != None:
++ obj.parseDirEntries()
++ count = 0
++ rootNode = self.__buildTree( obj.entries )
++
++ self.__printHeader()
++ self.__printListReport( rootNode, obj.entries )
++ # need to print a footer ( total bytes, total files like unzip )
++
++ def extract(self, name):
++ if self.header == None:
++ self.__parseFile()
++ self.header = ole.Header(self.chars, self.params)
++ self.pos = self.header.parse()
++
++ obj = self.header.getDirectory()
++ if obj != None:
++ obj.parseDirEntries()
++
++ root = self.__buildTree( obj.entries )
++ entry = self.__findEntryByHierachicalName( root, name )
++
++ if entry == None or entry.DirIDRoot > 0 :
++ print "can't extract %s"%name
++ return
++
++ bytes = obj.getRawStreamByEntry( entry )
++
++ file = open(entry.Name, 'wb')
++ file.write( bytes )
++ file.close
++def main ():
++ parser = optparse.OptionParser()
++ parser.add_option("-l", "--list", action="store_true", dest="list", default=False, help="lists ole contents")
++ parser.add_option("-x", "--extract", action="store_true", dest="extract", default=False, help="extract file")
++
++
++ options, args = parser.parse_args()
++
++ params = globals.Params()
++
++ params.list = options.list
++ params.extract = options.extract
++
++ if len(args) < 1:
++ globals.error("takes at least one arguments\n")
++ parser.print_help()
++ sys.exit(1)
++
++ container = OleContainer( args[ 0 ], params )
++
++ if params.list == True:
++ container.list()
++ if params.extract:
++ files = args
++ files.pop(0)
++
++ for file in files:
++ container.extract( file )
++# container.listEntries()
++
++if __name__ == '__main__':
++ main()
+diff --git a/scratch/mso-dumper/src/ole.py b/scratch/mso-dumper/src/ole.py
+index 9b01928..3db2458 100644
+--- a/scratch/mso-dumper/src/ole.py
++++ b/scratch/mso-dumper/src/ole.py
+@@ -526,7 +526,8 @@ entire file stream.
+ self.RootStorageBytes += self.header.bytes[pos:pos+self.sectorSize]
+
+
+- def __getRawStream (self, entry):
++ def getRawStreamByEntry (self, entry):
++
+ chain = []
+ if entry.StreamLocation == StreamLocation.SAT:
+ chain = self.header.getSAT().getSectorIDChain(entry.StreamSectorID)
+@@ -561,7 +562,7 @@ entire file stream.
+ bytes = []
+ for entry in self.entries:
+ if entry.Name == name:
+- bytes = self.__getRawStream(entry)
++ bytes = self.getRawStreamByEntry(entry)
+ break
+ return bytes
+
More information about the Libreoffice-commits
mailing list