Advertisement
eugene259

extract flash swf from powerpoint pps python script

Jun 8th, 2016 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | Source Code | 0 0
  1. # this is a conversion of http://blog.interrupt3h.com/?p=250
  2.  
  3. import mmap, os
  4. from argparse import ArgumentParser
  5.  
  6. MARKER=b'FWS'
  7. EXT='bin'
  8. FLASHEXT='swf'
  9.  
  10. def vprint(*arg, **args):
  11.     if options.verbose:
  12.         print(*arg, **args)
  13.  
  14. def newfilename(fn):
  15.     base, ext = os.path.splitext(fn)
  16.     return base+'.'+FLASHEXT
  17.  
  18. def process(fn):
  19.     with open(fn, 'rb', 0) as f, \
  20.         mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as s:
  21.         i = s.find(MARKER)
  22.         if i == -1:
  23.             print('unable to find marker')
  24.             return
  25.         nfn = newfilename(fn)
  26.         with open(nfn, 'wb') as nf:
  27.             nf.write(s[i:])
  28.         print('wrote flash to', nfn)
  29.  
  30. def filter_file(f):
  31.     base, ext = os.path.splitext(f)
  32.     ext = ext[1:]
  33.     return ext == EXT
  34.  
  35. def process_arg(arg):
  36.     if os.path.isdir(arg):
  37.         vprint('Filtering directory:', arg)
  38.         for f in os.listdir(arg):
  39.             process_arg(os.path.join(arg, f))
  40.     else:
  41.         vprint('Filtering file:', arg)
  42.         if filter_file(arg):
  43.             process(arg)
  44.  
  45. def process_args():
  46.     for arg in options.files:
  47.         vprint('Processing argument: ', arg)
  48.         process_arg(arg)
  49.  
  50. if __name__ == '__main__':
  51.     parser = ArgumentParser(usage='%(prog)s [options] filename')
  52.     parser.add_argument('-v', '--verbose', action='store_true', dest='verbose')
  53.     parser.add_argument('files', nargs='+', help='filenames to process')
  54.     options = parser.parse_args()
  55.     process_args()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement