[Libreoffice-commits] .: Branch 'feature/writeable-oletool' - src/ole.py src/oletool.py
Noel Power
noelp at kemper.freedesktop.org
Thu Oct 6 13:58:49 PDT 2011
src/ole.py | 30 ++++++++++++++++++++++++------
src/oletool.py | 29 ++++++++++++++++-------------
2 files changed, 40 insertions(+), 19 deletions(-)
New commits:
commit 77e73a40bbaf5273ba775e70026c4494bdfbe30f
Author: Noel Power <noel.power at novell.com>
Date: Thu Oct 6 21:58:13 2011 +0100
fixed lots of brainfarts and added lots of debug
diff --git a/src/ole.py b/src/ole.py
index c67df09..ae22314 100644
--- a/src/ole.py
+++ b/src/ole.py
@@ -92,6 +92,7 @@ class Header(object):
self.secSizeShort = 64
self.params = params
+ self.__SSAT = None
def getSectorSize (self):
return 2**self.secSize
@@ -277,8 +278,11 @@ class Header(object):
self.bytes[68:72] = struct.pack( '<l', self.secIDFirstMSAT )
self.bytes[72:76] = struct.pack( '<l', self.numSecMSAT )
# write the MSAT, SAT & SSAT
+ print "*** writing MSAT"
self.writeMSAT()
+ print "*** writing SAT"
self.getSAT().write()
+ print "*** writing SSAT"
self.getSSAT().write()
def writeMSAT (self):
@@ -319,17 +323,19 @@ class Header(object):
def getSSAT (self):
+ if self.__SSAT != None:
+ return self.__SSAT
ssatID = self.getFirstSectorID(BlockType.SSAT)
if ssatID < 0:
return None
chain = self.getSAT().getSectorIDChain(ssatID)
if len(chain) == 0:
return None
- obj = SSAT(2**self.secSize, self.bytes, self.params)
+ self.__SSAT = SSAT(2**self.secSize, self.bytes, self.params)
for secID in chain:
- obj.addSector(secID)
- obj.buildArray()
- return obj
+ self.__SSAT.addSector(secID)
+ self.__SSAT.buildArray()
+ return self.__SSAT
def expandSSAT( self, numExtraEntriesNeeded ):
# create enough sectors to increase SAT table to accomadate new entries
@@ -344,6 +350,8 @@ class Header(object):
# add the sectors into the SSAT
for sectorID in newSATSectors:
self.getSSAT().sectorIDs.append( sectorID )
+ #mark the sectors as used by the SAT table
+ self.getSAT().array[ sectorID ] = -2
# expand SSAT array with the contens of the new SATSectors
self.getSSAT().appendArray( newSATSectors )
# need to update the SectorIDChain for the SSAT
@@ -372,14 +380,17 @@ class Header(object):
print "Error: haven't implemented expanding the SAT to allow more sectors to be allocated for the MSAT"
return chain
self.createSATSectors( MSATSectors )
-
+ self.getSAT().appendArray( MSATSectors )
#is there room in the MSAT table header part
if len( self.getMSAT().secIDs ) + len( MSATSectors ) < 109:
for sector in MSATSectors:
self.getMSAT().appendSectorID( sector )
- self.getSAT().appendArray( MSATSectors )
+ self.getSAT().addSector( sector )
+ #mark MSAT sectors in SAT array as in use by MSAT
+ self.getSAT().array[ sector ] = -4
else:
print "*** extending the MSAT not supported yes"
+
#try again
chain = self.getSAT().getFreeChainEntries( numNeeded, 0 )
@@ -524,16 +535,20 @@ class SAT(object):
self.appendArray( self.sectorIDs )
def appendArray( self, sectorIDs ):
+ print "reading sectors", sectorIDs
numItems = self.sectorSize / 4
for secID in sectorIDs:
pos = 512 + secID*self.sectorSize
for i in xrange(0, numItems):
beginPos = pos + i*4
id = getSignedInt(self.bytes[beginPos:beginPos+4])
+ print "index %d, len(self.sectorIDs) %d sectorID %d pos %d value %d"%(len(self.array) , len(self.sectorIDs),secID, beginPos, id )
self.array.append(id)
+
def write (self):
#writes the contents of the SAT array to memory sectors
+ print "sectors making up the SAT or SAT are ",self.sectorIDs
for index in xrange(0, len( self.array )):
entryPos = 4 * index
#calculate the offset into a sector
@@ -716,6 +731,8 @@ entire file stream.
elif entry.StreamLocation == StreamLocation.SSAT:
chain = self.header.getSSAT().getSectorIDChain(entry.StreamSectorID)
+ print "__getRawStream extracting from chain ", chain
+
if entry.StreamLocation == StreamLocation.SSAT:
# Get the root storage stream.
if self.RootStorage == None:
@@ -743,6 +760,7 @@ entire file stream.
secSize = self.header.getSectorSize()
numSectors = len(targetChain)
print "writing out %d sectors"%(numSectors)
+ print "chain is ", targetChain
for i in xrange(0, numSectors ):
srcPos = ( i * secSize )
targetPos = 512 + ( targetChain[ i ] * secSize )
diff --git a/src/oletool.py b/src/oletool.py
index 7ec247e..768f91c 100755
--- a/src/oletool.py
+++ b/src/oletool.py
@@ -185,7 +185,7 @@ class OleContainer:
def updateEntry( self, directory, entry, filePath ):
file = open( filePath, 'rb' )
bytes = file.read();
- print "Entry is ",entry.Name
+ print "Entry is ",entry.Name,"StreamSectorID ",entry.StreamSectorID
theSAT = self.header.getSAT()
sectorSize = self.header.getSectorSize()
entry.StreamSize = len(bytes)
@@ -195,13 +195,16 @@ class OleContainer:
oldChain = []
if ( entry.StreamLocation == ole.StreamLocation.SSAT ):
+ print"using SSAT"
theSAT = self.header.getSSAT()
else:
+ print"using SAT"
theSAT = self.header.getSAT()
if ( entryID > -1 ):
oldChain = theSAT.getSectorIDChain(entryID)
theSAT.freeChainEntries( oldChain )
+ print "** debug self.header.getSSAT().array[0] = ",self.header.getSSAT().array[0]
if entry.StreamSize < self.header.minStreamSize:
print "going to use ssat"
theSAT = self.header.getSSAT()
@@ -222,15 +225,19 @@ class OleContainer:
newChain = self.header.getOrAllocateFreeSSATChainEntries( newNumChainEntries )
if ( newNumChainEntries != len(newChain) ):
raise Exception("no space available")
- entryID = newChain[ 0 ]
# populate and terminate the chain - #FIXME move to be a common
# routine
+ print "newChain (SSAT) ", newChain
+ for i in xrange(0,len(newChain)):
+ print "getSSAT().array[ %d ] = %d"%( newChain[i], directory.header.getSSAT().array[ newChain[i] ] )
+ entryID = newChain[ 0 ]
lastIndex = newChain[ len( newChain ) - 1 ]
- self.header.getSSAT().array[ lastIndex ] = -2
+ directory.header.getSSAT().array[ lastIndex ] = -2
for i in xrange(0,len(newChain) ):
if i > 0:
- self.header.getSSAT().array[ newChain[ i-1 ] ] = newChain[ i ]
- #OMG - the assignment above ( to put in the -2 ) doesn't seem to work
+ directory.header.getSSAT().array[ newChain[ i - 1 ] ] = newChain[ i ]
+ for i in xrange(0,len(newChain)):
+ print "after pop getSSAT().array[ %d ] = %d"%( newChain[i], directory.header.getSSAT().array[ newChain[i] ] )
#FIXME find out what is wrong, because the assignment of the end of
#chain ID above doesn't seem to work the line below loops :-/
print "newChain (SSAT) (retrieved)", theSAT.getSectorIDChain( entryID )
@@ -286,8 +293,9 @@ class OleContainer:
entry.UserFlags = bytearray(4)
entry.TimeCreated = bytearray(8)
entry.TimeModified = bytearray(8)
- entry.StreamSectorID = 0
+ entry.StreamSectorID = -1
entry.StreamSize = 0
+ entry.StreamLocation = ole.StreamLocation.SSAT
def deleteEntry(self, directory, node, tree ):
entry = node.Entry
@@ -366,13 +374,9 @@ class OleContainer:
lastEntry = directory.entries[ len( directory.entries ) - 1]
entry = ole.Directory.Entry()
self.makeEntryEmpty( entry )
+
directory.entries.append( entry )
dirID = len( directory.entries) - 1
- # if the old last entry was empty use that other wise use
- # the new one
- if lastEntry.Type == ole.Directory.Type.Empty:
- dirID = len( directory.entries ) - 2
- entry = lastEntry
entry.Name = childName
self.insertSiblingInTree ( directory, dirID, entry, directory.entries[ root.Entry.DirIDRoot ] )
@@ -422,7 +426,6 @@ class OleContainer:
else:
#storage
node = self.__findNodeByHierachicalName( root, dirPath )
- print "adding a new file to %s"%dirPath
entry = self.insertDirEntry( directory, node, fileLeafName )
if storageTestCreate:
entry.NodeColor = ole.Directory.NodeColor.Black
@@ -430,8 +433,8 @@ class OleContainer:
else:
#FIXME how to allocate the NodeColor
entry.NodeColor = node.Entry.NodeColor
- entry.NodeColor = node.Entry.NodeColor
entry.Type = directory.Type.UserStream
+
self.updateEntry( directory, entry, filePath )
self.header.write()
More information about the Libreoffice-commits
mailing list