1
0
Fork 0
mat2/main.py

76 lines
2.3 KiB
Python
Raw Normal View History

2018-04-04 00:21:39 +02:00
#!/usr/bin/python3
2018-04-02 19:12:10 +02:00
import os
2018-03-06 23:20:18 +01:00
import sys
2018-04-01 17:13:34 +02:00
import mimetypes
2018-03-06 23:20:18 +01:00
from shutil import copyfile
import argparse
2018-03-19 23:43:49 +01:00
from src import parser_factory
2018-03-06 23:20:18 +01:00
2018-04-02 23:40:00 +02:00
def __check_file(filename:str, mode:int = os.R_OK) -> bool:
2018-04-02 19:12:10 +02:00
if not os.path.isfile(filename):
print("[-] %s is not a regular file." % filename)
return False
elif not os.access(filename, mode):
print("[-] %s is not readable and writeable." % filename)
return False
return True
2018-03-06 23:20:18 +01:00
def create_arg_parser():
parser = argparse.ArgumentParser(description='Metadata anonymisation toolkit 2')
parser.add_argument('files', nargs='*')
info = parser.add_argument_group('Information')
info.add_argument('-c', '--check', action='store_true',
help='check if a file is free of harmful metadatas')
info.add_argument('-l', '--list', action='store_true',
help='list all supported fileformats')
info.add_argument('-s', '--show', action='store_true',
help='list all the harmful metadata of a file without removing them')
return parser
2018-04-01 17:13:34 +02:00
def show_meta(filename:str):
2018-04-02 19:12:10 +02:00
if not __check_file(filename):
return
p, mtype = parser_factory.get_parser(filename)
2018-03-31 21:15:48 +02:00
if p is None:
2018-04-01 17:13:34 +02:00
print("[-] %s's format (%s) is not supported" % (filename, mtype))
2018-03-31 21:15:48 +02:00
return
2018-04-02 19:12:10 +02:00
print("[+] Metadata for %s:" % filename)
2018-03-06 23:20:18 +01:00
for k,v in p.get_meta().items():
2018-04-02 19:12:10 +02:00
print(" %s: %s" % (k, v))
def clean_meta(filename:str):
if not __check_file(filename, os.R_OK|os.W_OK):
return
p, mtype = parser_factory.get_parser(filename)
2018-04-02 19:12:10 +02:00
if p is None:
print("[-] %s's format (%s) is not supported" % (filename, mtype))
return
p.remove_all()
2018-03-06 23:20:18 +01:00
def main():
arg_parser = create_arg_parser()
args = arg_parser.parse_args()
2018-04-02 19:12:10 +02:00
2018-03-06 23:20:18 +01:00
if args.show:
for f in args.files:
show_meta(f)
elif args.list:
print('[+] Supported formats:')
for parser in parser_factory._get_parsers():
for mtype in parser.mimetypes:
extensions = ', '.join(mimetypes.guess_all_extensions(mtype))
print(' - %s (%s)' % (mtype, extensions))
elif args.files:
2018-04-02 19:12:10 +02:00
for f in args.files:
clean_meta(f)
else:
arg_parser.print_help()
2018-03-06 23:20:18 +01:00
if __name__ == '__main__':
main()