summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xcli.py12
-rwxr-xr-xmat.py44
2 files changed, 17 insertions, 39 deletions
diff --git a/cli.py b/cli.py
index b5bea20..bd87409 100755
--- a/cli.py
+++ b/cli.py
@@ -16,8 +16,6 @@ def parse():
16 help='List all the meta of a file without removing them') 16 help='List all the meta of a file without removing them')
17 common.add_option('--check', '-c', action='store_true', default=False, 17 common.add_option('--check', '-c', action='store_true', default=False,
18 help='Check if a file is free of harmfull metadatas') 18 help='Check if a file is free of harmfull metadatas')
19 common.add_option('--harmful', action='store_true', default=False,
20 help='List all the harmful meta of a file without removing them')
21 common.add_option('--version', action='callback', callback=displayVersion, 19 common.add_option('--version', action='callback', callback=displayVersion,
22 help='Display version and exit') 20 help='Display version and exit')
23 21
@@ -42,14 +40,6 @@ def list_meta(class_file, filename):
42 for key, item in class_file.get_meta().iteritems(): 40 for key, item in class_file.get_meta().iteritems():
43 print('\t%s : %s' % (key, item) ) 41 print('\t%s : %s' % (key, item) )
44 42
45def list_harmful_meta(class_file, filename):
46 '''
47 Print all the harmful meta of 'filename' on stdout
48 '''
49 print('[+] File %s :' % filename)
50 for key, item in class_file.get_harmful().iteritems():
51 print('\t%s : %s' % (key, item) )
52
53def is_clean(class_file, filename): 43def is_clean(class_file, filename):
54 ''' 44 '''
55 Say if 'filename' is clean or not 45 Say if 'filename' is clean or not
@@ -78,8 +68,6 @@ def main():
78 func = list_meta 68 func = list_meta
79 elif args.check is True: #only check if the file is clean 69 elif args.check is True: #only check if the file is clean
80 func = is_clean 70 func = is_clean
81 elif args.harmful is True: #only print harmful metadatas
82 func = list_harmful_meta
83 else: #clean the file 71 else: #clean the file
84 func = clean_meta 72 func = clean_meta
85 73
diff --git a/mat.py b/mat.py
index f59bdce..200fc04 100755
--- a/mat.py
+++ b/mat.py
@@ -18,6 +18,7 @@ import hachoir_parser.image
18__version__ = "0.1" 18__version__ = "0.1"
19__author__ = "jvoisin" 19__author__ = "jvoisin"
20 20
21POSTFIX = ".cleaned"
21 22
22class file(): 23class file():
23 def __init__(self, realname, filename, parser, editor): 24 def __init__(self, realname, filename, parser, editor):
@@ -52,8 +53,8 @@ class file():
52 ''' 53 '''
53 Check if the file is clean from harmful metadatas 54 Check if the file is clean from harmful metadatas
54 ''' 55 '''
55 for key, field in self.meta.iteritems(): 56 for field in self.editor:
56 if self._should_remove(key): 57 if self._should_remove(field):
57 return False 58 return False
58 return True 59 return True
59 60
@@ -61,37 +62,25 @@ class file():
61 ''' 62 '''
62 Remove all the files that are compromizing 63 Remove all the files that are compromizing
63 ''' 64 '''
64 for key, field in self.meta.iteritems(): 65 for field in self.editor:
65 if self._should_remove(key): 66 if self._should_remove(field):
66 self._remove(key) 67 self._remove(field)
67 hachoir_core.field.writeIntoFile(self.editor, self.filename + "cleaned") 68 hachoir_core.field.writeIntoFile(self.editor, self.filename + POSTFIX)
68 69
69 70 def _remove(self, field):
70 def _remove(self, key):
71 ''' 71 '''
72 Remove the given field 72 Remove the given field
73 ''' 73 '''
74 del self.editor[key] 74 del self.editor[field.name]
75 75
76 76
77 def get_meta(self): 77 def get_meta(self):
78 ''' 78 '''
79 return a dict with all the meta of the file 79 return a dict with all the meta of the file
80 ''' 80 '''
81 #am I useless ?
81 return self.meta 82 return self.meta
82 83
83 def get_harmful(self):
84 '''
85 return a dict with all the harmful meta of the file
86 '''
87 harmful = {}
88 for key, value in self.meta.iteritems():
89 if self._should_remove(key):
90 harmful[key] = value
91 return harmful
92
93
94
95 def _should_remove(self, key): 84 def _should_remove(self, key):
96 ''' 85 '''
97 return True if the field is compromizing 86 return True if the field is compromizing
@@ -100,19 +89,20 @@ class file():
100 raise NotImplementedError() 89 raise NotImplementedError()
101 90
102class JpegStripper(file): 91class JpegStripper(file):
103 def _should_remove(self, key): 92 def _should_remove(self, field):
104 if key in ('comment', 'author'): 93 if field.name.startswith('comment'):
94 return True
95 elif field.name in ("photoshop", "exif", "adobe"):
105 return True 96 return True
106 else: 97 else:
107 return False 98 return False
108 99
109class PngStripper(file): 100class PngStripper(file):
110 def _should_remove(self, key): 101 def _should_remove(self, field):
111 if key in ('comment', 'author'): 102 if field.name in ('comment'):
112 return True 103 return True
113 else: 104 else:
114 return False 105 return False
115 return False
116 106
117strippers = { 107strippers = {
118 hachoir_parser.image.JpegFile: JpegStripper, 108 hachoir_parser.image.JpegFile: JpegStripper,
@@ -131,7 +121,7 @@ def create_class_file(name):
131 filename = "" 121 filename = ""
132 realname = name 122 realname = name
133 filename = hachoir_core.cmd_line.unicodeFilename(name) 123 filename = hachoir_core.cmd_line.unicodeFilename(name)
134 parser = hachoir_parser.createParser(filename, realname) 124 parser = hachoir_parser.createParser(filename)
135 if not parser: 125 if not parser:
136 print("Unable to parse the file %s : sorry" % filename) 126 print("Unable to parse the file %s : sorry" % filename)
137 sys.exit(1) 127 sys.exit(1)