def dumpstreams(stream, paths, out): from office.OleFileIO_PL import OleFileIO stream = stream.split('/') out = out if out.endswith('/') else '%s/'%out if not os.path.exists(out): raise OSError('path "%s" not found'% out) for filename in paths: if not os.path.exists(filename): log('%s : file not found',filename) continue try: ole = OleFileIO(filename) except IOError,msg: log('%s : not an ole file : %s',filename,msg) continue if stream not in ole.listdir(): # log('%s : stream "%s" not found'%(filename, repr(stream))) continue name = '%s.stream'%(os.path.basename(filename)) path = '%s%s'%(out,name) log('%s : writing stream "%s"'%(filename, path)) try: stm = ole.openstream(stream) except IOError, msg: log('%s : stream %s error : %s', filename,stream,msg) continue
def dumpstreams(stream, paths, out): from office.OleFileIO_PL import OleFileIO stream = stream.split('/') out = out if out.endswith('/') else '%s/' % out if not os.path.exists(out): raise OSError('path "%s" not found' % out) for filename in paths: if not os.path.exists(filename): log('%s : file not found', filename) continue try: ole = OleFileIO(filename) except IOError as msg: log('%s : not an ole file : %s', filename, msg) continue if stream not in ole.listdir(): # log('%s : stream "%s" not found'%(filename, repr(stream))) continue name = '%s.stream' % (os.path.basename(filename)) path = '%s%s' % (out, name) log('%s : writing stream "%s"' % (filename, path)) try: stm = ole.openstream(stream) except IOError as msg: log('%s : stream %s error : %s', filename, stream, msg) continue file(path, 'wb').write(stm.read()) return
def liststreams(paths): from office.OleFileIO_PL import OleFileIO result = {} for filename in paths: if not os.path.exists(filename): log('%s : file not found',filename) continue try: ole = OleFileIO(filename) except IOError,msg: log('%s : not an ole file : %s',filename,msg) continue streams = ['/'.join(x) for x in ole.listdir()] for x in streams: if x not in result: result[x] = 0 result[x] += 1 continue
def liststreams(paths): from office.OleFileIO_PL import OleFileIO result = {} for filename in paths: if not os.path.exists(filename): log('%s : file not found', filename) continue try: ole = OleFileIO(filename) except IOError, msg: log('%s : not an ole file : %s', filename, msg) continue streams = ['/'.join(x) for x in ole.listdir()] for x in streams: if x not in result: result[x] = 0 result[x] += 1 continue
def liststreams(paths): from office.OleFileIO_PL import OleFileIO result = {} for filename in paths: if not os.path.exists(filename): log('%s : file not found', filename) continue try: ole = OleFileIO(filename) except IOError as msg: log('%s : not an ole file : %s', filename, msg) continue streams = ['/'.join(x) for x in ole.listdir()] for x in streams: if x not in result: result[x] = 0 result[x] += 1 continue result = result.items() result.sort(lambda a, b: cmp(a[1], b[1])) print('\n'.join('%d : %s' % (v, repr(k)) for k, v in result))
if command is not provided, then dump a list of all the streams in file. commands: -d index dump specified stream to stdout -o decimal offfset translate the ole file offset into a stream index and it's offset -ox hex offset translate the ole file offset into a stream index and it's offset '''%sys.argv[0] if len(sys.argv) <= 1: raise Exception(usage) filename = sys.argv[1] b = OleFileIO(filename) # list streams if len(sys.argv) == 2: print liststreams(b) else: command,args = sys.argv[2],sys.argv[3:] # -d index if command == '-d': index, = args index = int(index) print dumpstream(b, index) # -o offset elif command == '-o': offset, = args
if command is not provided, then dump a list of all the streams in file. commands: -d index dump specified stream to stdout -o decimal offfset translate the ole file offset into a stream index and it's offset -ox hex offset translate the ole file offset into a stream index and it's offset ''' % sys.argv[0] if len(sys.argv) <= 1: raise Exception(usage) filename = sys.argv[1] b = OleFileIO(filename) # list streams if len(sys.argv) == 2: print liststreams(b) else: command, args = sys.argv[2], sys.argv[3:] # -d index if command == '-d': index, = args index = int(index) print dumpstream(b, index) # -o offset elif command == '-o': offset, = args