summaryrefslogtreecommitdiff
path: root/lib/mat.py
diff options
context:
space:
mode:
authorjvoisin2011-06-24 19:41:51 +0200
committerjvoisin2011-06-24 19:41:51 +0200
commit9ebc62273ec8abfc4520660597fa80fe3de40203 (patch)
treef1d6f4ed1824a46b9dcc7ab142950cc0eb04692c /lib/mat.py
parent15e58d472dd942a675110cff8085124c0088f54f (diff)
Preliminary support of .tar archives
Diffstat (limited to 'lib/mat.py')
-rw-r--r--lib/mat.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/mat.py b/lib/mat.py
index 6abcd64..156c683 100644
--- a/lib/mat.py
+++ b/lib/mat.py
@@ -14,7 +14,7 @@ import hachoir_editor
14import images 14import images
15import audio 15import audio
16import misc 16import misc
17#import archive 17import archive
18 18
19__version__ = "0.1" 19__version__ = "0.1"
20__author__ = "jvoisin" 20__author__ = "jvoisin"
@@ -24,24 +24,34 @@ strippers = {
24 hachoir_parser.image.PngFile: images.PngStripper, 24 hachoir_parser.image.PngFile: images.PngStripper,
25 hachoir_parser.audio.MpegAudioFile: audio.MpegAudioStripper, 25 hachoir_parser.audio.MpegAudioFile: audio.MpegAudioStripper,
26 hachoir_parser.misc.PDFDocument: misc.PdfStripper, 26 hachoir_parser.misc.PDFDocument: misc.PdfStripper,
27 #hachoir_parser.archive.TarFile: archive.TarStripper, 27 hachoir_parser.archive.TarFile: archive.TarStripper,
28} 28}
29 29
30def create_class_file(name, backup): 30def is_secure(filename):
31 ''' 31 '''
32 return a $FILETYPEStripper() class, 32 Prevent shell injection
33 corresponding to the filetype of the given file
34 ''' 33 '''
35 if not(os.path.isfile(name)): #check if the file exist 34 if not(os.path.isfile(name)): #check if the file exist
36 print("Error: %s is not a valid file" % name) 35 print("Error: %s is not a valid file" % name)
37 sys.exit(1) 36 sys.exit(1)
37 filename.strip('\s') #separations
38 filename.strip('`') #injection `rm / -Rf`
39 filename.strip('\$(.*)')#injection $(rm / -Rf)
40 filename.strip(';')#injection $filename;rm / -Rf
41
42def create_class_file(name, backup):
43 '''
44 return a $FILETYPEStripper() class,
45 corresponding to the filetype of the given file
46 '''
47 #is_secure(name)
38 48
39 filename = "" 49 filename = ""
40 realname = name 50 realname = name
41 filename = hachoir_core.cmd_line.unicodeFilename(name) 51 filename = hachoir_core.cmd_line.unicodeFilename(name)
42 parser = hachoir_parser.createParser(filename) 52 parser = hachoir_parser.createParser(filename)
43 if not parser: 53 if not parser:
44 print("Unable to parse the file %s : sorry" % filename) 54 print("Unable to parse the file %s with hachoir-parser." % filename)
45 sys.exit(1) 55 sys.exit(1)
46 56
47 editor = hachoir_editor.createEditor(parser) 57 editor = hachoir_editor.createEditor(parser)