summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmat-cli21
-rw-r--r--mat/archive.py12
-rw-r--r--mat/office.py6
-rw-r--r--mat/parser.py2
4 files changed, 21 insertions, 20 deletions
diff --git a/mat-cli b/mat-cli
index 41ce335..2ee0637 100755
--- a/mat-cli
+++ b/mat-cli
@@ -25,7 +25,7 @@ The default behaviour is to clean files given in argument')
25 help='Keep a backup copy') 25 help='Keep a backup copy')
26 options.add_option('--force', '-f', action='store_true', default=False, 26 options.add_option('--force', '-f', action='store_true', default=False,
27 help='Don\'t check if files are clean before cleaning') 27 help='Don\'t check if files are clean before cleaning')
28 options.add_option('--ugly', '-u', action='store_true', default=False, 28 options.add_option('--strict', '-u', action='store_true', default=False,
29 help='Strict cleaning mode : loss can occur') 29 help='Strict cleaning mode : loss can occur')
30 30
31 info = optparse.OptionGroup(parser, 'Informations') 31 info = optparse.OptionGroup(parser, 'Informations')
@@ -42,6 +42,8 @@ The default behaviour is to clean files given in argument')
42 42
43 values, arguments = parser.parse_args() 43 values, arguments = parser.parse_args()
44 if not arguments and values.list is False: 44 if not arguments and values.list is False:
45 # if no argument and no files are passed,
46 # print help and exit
45 parser.print_help() 47 parser.print_help()
46 sys.exit(0) 48 sys.exit(0)
47 return values, arguments 49 return values, arguments
@@ -65,11 +67,10 @@ def list_meta(class_file, filename, force):
65 print('No harmful metadata found') 67 print('No harmful metadata found')
66 else: 68 else:
67 meta = class_file.get_meta() 69 meta = class_file.get_meta()
68 if meta is None: 70 print ('Harmful metadata found:')
69 print('No harmful metadata found') 71 if meta is not None:
70 else:
71 for key, value in class_file.get_meta().iteritems(): 72 for key, value in class_file.get_meta().iteritems():
72 print(key + ' : ' + str(value)) 73 print('\t' + key + ' : ' + str(value))
73 74
74 75
75def is_clean(class_file, filename, force): 76def is_clean(class_file, filename, force):
@@ -95,15 +96,15 @@ def clean_meta(class_file, filename, force):
95 else: 96 else:
96 print('Unable to clean %s', filename) 97 print('Unable to clean %s', filename)
97 98
98def clean_meta_ugly(class_file, filename, force): 99def clean_meta_strict(class_file, filename, force):
99 ''' 100 '''
100 Clean the file 'filename', ugly way 101 Clean the file 'filename', strict way
101 ''' 102 '''
102 print('[+] Cleaning %s' % filename) 103 print('[+] Cleaning %s' % filename)
103 if force is False and class_file.is_clean(): 104 if force is False and class_file.is_clean():
104 print('%s is already clean' % filename) 105 print('%s is already clean' % filename)
105 else: 106 else:
106 class_file.remove_all_ugly() 107 class_file.remove_all_strict()
107 print('%s cleaned' % filename) 108 print('%s cleaned' % filename)
108 109
109 110
@@ -139,8 +140,8 @@ def main():
139 func = list_meta 140 func = list_meta
140 elif args.check is True: # only check if the file is clean 141 elif args.check is True: # only check if the file is clean
141 func = is_clean 142 func = is_clean
142 elif args.ugly is True: # destructive anonymisation method 143 elif args.strict is True: # destructive anonymisation method
143 func = clean_meta_ugly 144 func = clean_meta_strict
144 elif args.list is True: # print the list of all supported format 145 elif args.list is True: # print the list of all supported format
145 list_supported() 146 list_supported()
146 else: # clean the file 147 else: # clean the file
diff --git a/mat/archive.py b/mat/archive.py
index 65527d2..9993102 100644
--- a/mat/archive.py
+++ b/mat/archive.py
@@ -41,16 +41,16 @@ class GenericArchiveStripper(parser.GenericParser):
41 ''' 41 '''
42 return self._remove_all('normal') 42 return self._remove_all('normal')
43 43
44 def remove_all_ugly(self): 44 def remove_all_strict(self):
45 ''' 45 '''
46 call remove_all() with in argument : "ugly" 46 call remove_all() with in argument : "strict"
47 ''' 47 '''
48 return self._remove_all('ugly') 48 return self._remove_all('strict')
49 49
50 def _remove_all(self, method): 50 def _remove_all(self, method):
51 ''' 51 '''
52 Remove all meta, normal way if method is "normal", 52 Remove all meta, normal way if method is "normal",
53 else, use the ugly way (with possible data loss) 53 else, use the strict way (with possible data loss)
54 ''' 54 '''
55 raise NotImplementedError 55 raise NotImplementedError
56 56
@@ -146,7 +146,7 @@ harmless format' % item.filename)
146 if method is 'normal': 146 if method is 'normal':
147 cfile.remove_all() 147 cfile.remove_all()
148 else: 148 else:
149 cfile.remove_all_ugly() 149 cfile.remove_all_strict()
150 logging.debug('Processing %s from %s' % (item.filename, 150 logging.debug('Processing %s from %s' % (item.filename,
151 self.filename)) 151 self.filename))
152 zipout.write(name, item.filename) 152 zipout.write(name, item.filename)
@@ -193,7 +193,7 @@ class TarStripper(GenericArchiveStripper):
193 if method is 'normal': 193 if method is 'normal':
194 cfile.remove_all() 194 cfile.remove_all()
195 else: 195 else:
196 cfile.remove_all_ugly() 196 cfile.remove_all_strict()
197 tarout.add(name, item.name, filter=self._remove) 197 tarout.add(name, item.name, filter=self._remove)
198 except: 198 except:
199 logging.info('%s\' format is not supported or harmless' % 199 logging.info('%s\' format is not supported or harmless' %
diff --git a/mat/office.py b/mat/office.py
index e3febba..e1d738e 100644
--- a/mat/office.py
+++ b/mat/office.py
@@ -87,7 +87,7 @@ class OpenDocumentStripper(archive.GenericArchiveStripper):
87 if method == 'normal': 87 if method == 'normal':
88 cfile.remove_all() 88 cfile.remove_all()
89 else: 89 else:
90 cfile.remove_all_ugly() 90 cfile.remove_all_strict()
91 logging.debug('Processing %s from %s' % (item, 91 logging.debug('Processing %s from %s' % (item,
92 self.filename)) 92 self.filename))
93 zipout.write(name, item) 93 zipout.write(name, item)
@@ -150,7 +150,7 @@ class PdfStripper(parser.GenericParser):
150 return self._remove_meta() 150 return self._remove_meta()
151 151
152 152
153 def remove_all_ugly(self): 153 def remove_all_strict(self):
154 ''' 154 '''
155 Opening the PDF with poppler, then doing a render 155 Opening the PDF with poppler, then doing a render
156 on a cairo pdfsurface for each pages. 156 on a cairo pdfsurface for each pages.
@@ -261,7 +261,7 @@ class OpenXmlStripper(archive.GenericArchiveStripper):
261 if method == 'normal': 261 if method == 'normal':
262 cfile.remove_all() 262 cfile.remove_all()
263 else: 263 else:
264 cfile.remove_all_ugly() 264 cfile.remove_all_strict()
265 logging.debug('Processing %s from %s' % (item, 265 logging.debug('Processing %s from %s' % (item,
266 self.filename)) 266 self.filename))
267 zipout.write(name, item) 267 zipout.write(name, item)
diff --git a/mat/parser.py b/mat/parser.py
index 651b244..6dc5d0b 100644
--- a/mat/parser.py
+++ b/mat/parser.py
@@ -78,7 +78,7 @@ class GenericParser(object):
78 except: 78 except:
79 return False 79 return False
80 80
81 def remove_all_ugly(self): 81 def remove_all_strict(self):
82 ''' 82 '''
83 If the remove_all() is not efficient enough, 83 If the remove_all() is not efficient enough,
84 this method is implemented : 84 this method is implemented :