Since version 0.32, OleFileIO_PL comes with experimental write features. For now it is possible to write sectors, and to write over an existing stream. More features will be added over time.
Before OleFileIO_PL v0.32 is released, you may get the latest code from Bitbucket using Mercurial, or use the link "Download Repository" from the dowload page.
This code is brand new and has not been thoroughly tested yet. Please send me your feedback or report issues.
Before using the write features, the OLE file must be opened in read/write mode:
import OleFileIO_PL
ole = OleFileIO_PL.OleFileIO('test.doc', write_mode=True)
The write_sect method can overwrite any sector of the file. If the provided data is smaller than the sector size (normally 512 bytes, sometimes 4KB), data is padded with null characters.
Here is an example:
ole.write_sect(0x17, b'TEST')
Note: following the MS-CFB specifications, sector 0 is actually the second sector of the file. You may use -1 as index to write the first sector.
The write_stream method can overwrite an existing stream in the file. The new stream data must be the exact same size as the existing one. For now, write_stream can only write streams of 4KB or larger (stored in the main FAT).
For example, you may change text in a MS Word document:
ole = OleFileIO_PL.OleFileIO('test.doc', write_mode=True) data = ole.openstream('WordDocument').read() data = data.replace(b'foo', b'bar') ole.write_stream('WordDocument', data) ole.close()
See issue #6 for more details. The next features to be implemented should be: