blob: a8070f104cae344b52e82432fcfac1914d420257 (
plain)
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
|
import parser
import pdfrw
import shutil
class PdfStripper(parser.Generic_parser):
'''
Represent a pdf file, with the help of pdfrw
'''
def __init__(self, filename):
self.filename = filename
self.trailer = pdfrw.PdfReader(self.filename)
self.writer = pdfrw.PdfWriter()
def remove_all(self):
'''
Remove all the files that are compromizing
'''
self.trailer.Info.Title = ''
self.trailer.Info.Author = ''
self.trailer.Info.Producer = ''
self.trailer.Info.Creator = ''
self.trailer.Info.CreationDate = ''
self.trailer.Info.ModDate = ''
self.writer.trailer = self.trailer
self.writer.write(self.filename + parser.POSTFIX)
if self.backup is False:
self.secure_remove() #remove the old file
shutil.rename(self.filename+ POSTFIX, self.filename)#rename the new
def is_clean(self):
'''
Check if the file is clean from harmful metadatas
'''
for field in self.trailer.Info:
if field != '':
return False
return True
def get_meta(self):
'''
return a dict with all the meta of the file
'''
metadata = {}
for key, value in self.trailer.Info.iteritems():
metadata[key[1:]] = value[1:-1]
return metadata
|