diff options
| author | jvoisin | 2011-06-24 19:41:51 +0200 |
|---|---|---|
| committer | jvoisin | 2011-06-24 19:41:51 +0200 |
| commit | 9ebc62273ec8abfc4520660597fa80fe3de40203 (patch) | |
| tree | f1d6f4ed1824a46b9dcc7ab142950cc0eb04692c /lib/mat.py | |
| parent | 15e58d472dd942a675110cff8085124c0088f54f (diff) | |
Preliminary support of .tar archives
Diffstat (limited to 'lib/mat.py')
| -rw-r--r-- | lib/mat.py | 22 |
1 files changed, 16 insertions, 6 deletions
| @@ -14,7 +14,7 @@ import hachoir_editor | |||
| 14 | import images | 14 | import images |
| 15 | import audio | 15 | import audio |
| 16 | import misc | 16 | import misc |
| 17 | #import archive | 17 | import 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 | ||
| 30 | def create_class_file(name, backup): | 30 | def 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 | |||
| 42 | def 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) |
