[Libreoffice-commits] .: 2 commits - oletool.diff src/oletool.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Apr 11 14:04:16 PDT 2011
oletool.diff | 230 ---------------------------------------------------------
src/oletool.py | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 205 insertions(+), 230 deletions(-)
New commits:
commit 816dbb70848ae45866b68765daea1c614d0ffc51
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Mon Apr 11 17:02:30 2011 -0400
Removed the patch; appplied to mso-dumper proper.
diff --git a/oletool.diff b/oletool.diff
deleted file mode 100644
index af564e1..0000000
--- a/oletool.diff
+++ /dev/null
@@ -1,230 +0,0 @@
---- /dev/null 2011-01-31 08:27:50.166383946 +0000
-+++ 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
---- src/ole.py
-+++ 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
-
commit da7531850f7c9a59c14e244d16d5efd9b522a0b2
Author: Noel Power <noel.power at novell.com>
Date: Mon Apr 11 17:01:48 2011 -0400
New tool for listing/adding/replacing/extracting ole files/content.
diff --git a/oletool.diff b/oletool.diff
index c882229..af564e1 100644
--- a/oletool.diff
+++ b/oletool.diff
@@ -1,5 +1,5 @@
--- /dev/null 2011-01-31 08:27:50.166383946 +0000
-+++ scratch/mso-dumper/src/oletool.py 2011-01-31 09:15:32.000000000 +0000
++++ src/oletool.py 2011-01-31 09:15:32.000000000 +0000
@@ -0,0 +1,204 @@
+#!/usr/bin/env python
+import sys, os.path, optparse
@@ -207,8 +207,8 @@
+ 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
+--- src/ole.py
++++ src/ole.py
@@ -526,7 +526,8 @@ entire file stream.
self.RootStorageBytes += self.header.bytes[pos:pos+self.sectorSize]
diff --git a/src/oletool.py b/src/oletool.py
new file mode 100755
index 0000000..f94da8f
--- /dev/null
+++ b/src/oletool.py
@@ -0,0 +1,205 @@
+#!/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.getRawStream( 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()
More information about the Libreoffice-commits
mailing list