-
Notifications
You must be signed in to change notification settings - Fork 2
/
ole-extract.py
81 lines (62 loc) · 2.27 KB
/
ole-extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import olefile
import oletools.oleid
filename = "tests/PCB-sl13nw6fpl4rim5mrg3x-1.PcbLib"
outFolder = "ole"
class DumpOle(object):
def __init__(self, filename, outFolder):
ole = olefile.OleFileIO(filename)
listdir = ole.listdir()
streams = []
for direntry in listdir:
#print direntry
streams.append('/'.join(direntry))
self.CreateDirs(streams)
self.WriteFiles(ole, streams, outFolder)
def CreateDirs(self, streams):
for stream in streams:
filePath = outFolder + '/' + str(stream)
if not os.path.exists(os.path.dirname(filePath)):
os.makedirs(os.path.dirname(filePath))
#browse_stream(ole, stream)
def WriteFiles(self, ole, streams, outFolder):
for stream in streams:
f = open(outFolder + '/' + stream, 'wb')
file = ole.openstream(stream)
print type(stream)
while True:
s = file.read(8192)
if not s:
break
f.write(s)
f.close()
class PackageOle(object):
def __init__(self, filename, outFolder):
ole = olefile.OleFileIO()
file = ole.open(filename, True)
listdir = ole.listdir()
streams = []
for direntry in listdir:
#print direntry
streams.append('/'.join(direntry))
def CreateDirs(self, streams):
for stream in streams:
filePath = outFolder + '/' + str(stream)
if not os.path.exists(os.path.dirname(filePath)):
os.makedirs(os.path.dirname(filePath))
#browse_stream(ole, stream)
def WriteFiles(self, ole, streams, outFolder):
for stream in streams:
f = open(outFolder + '/' + stream, 'wb')
file = ole.openstream(stream)
while True:
s = file.read(8192)
if not s:
break
f.write(s)
f.close()
if __name__ == "__main__":
obj = DumpOle(filename, outFolder)
#obj = PackageOle(filename, outFolder)