Extract embedded Flash (SWF) files from a PowerPoint presentation

Posted by bb on Tuesday 20th of March 2012 at 8:44 am;.
Filed Under IT Tipz & Trix 

I was recently asked by my boss if I could dump all of the Adobe Flash videos out of our corporate PowerPoint presentation so that we can convert them to .mp4/.mov so we can put some of the animations on iPhone so our reps can show them to the customer.

It really is not as easy as it looks!

I googled a fair few sites looking for answers and there really isn’t much out there that will do this auto-magically for you. So I rolled my own 🙂

The procedure is very simple.

  • 1. Open PowerPoint file and ensure that it is saved as .pptx (the new XML Office format)
  • 2. Rename the .pptx as a .zip file (we all know that the new format is already zipped up right?)
  • 3. Open the .zip file in winrar/winzip or your preferred utility
  • 4. Navigate to the .\ppt\activeX directory in the archive
  • 5. Extract all the .bin files to another directory
  • 6. Run the php script below on it

All the script does is scan the files in the current directoy to see if they are .BIN files (which is where PowerPoint stores SWF files, as well as other embedded file types), search through that file for the beginning of the SWF file header (denoted by FWS), read the file length as defined in the header and save that section out to a new file with a .swf file extension.

Simples really 🙂

As always, hope it helps someone. Script follows :

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//Script to extract SWF files from pptx files (once unzipped)
//Set up file type an extension for checking</code>

$FWSMarker = "FWS";
$extension = ".BIN";

// Start parsing directory

if ($handle = opendir('.')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";

/* Loop over the directory searching for all files */

while (false !== ($entry = readdir($handle))) {

/* Check for file extension*/

$filename = strtoupper(rtrim($entry));
$entry_len = strlen($entry);
$entry_pos = $entry_len - strlen($extension);

/* If .BIN search in file for FWS*/

if (substr($filename, $entry_pos , strlen($extension)) == $extension )
{
echo "Found entry $entry that is a .bin file \n";
$newhandle = fopen($entry, "r");
$contents = fread($newhandle, filesize($entry));
$marker = strpos($contents, $FWSMarker);
if ($marker != 0)
{
echo "FWS Found at position : $marker\n";

// truncate file from before FWS marker

$newlen = strlen ($contents);
$contents = substr($contents, $marker, ($newlen-$marker));

// get SWF file length from SWF header and reverse (little endian)

$swflen = substr ($contents, 4, 4);
$swflen = strrev($swflen);

//convert file length into something php can work with

         $act_len="";
         for ($i=0; $i<4; $i++){
          $newchar=ord(substr($swflen,$i,1));
          $newchar=strval(dechex($newchar));
          $act_len=$act_len.$newchar;
          }
         // convert from hex to dec
         $act_len=hexdec($act_len);
         echo "Actual SWF file length : $act_len bytes\n";
         /* Truncate File to that length*/
         $contents=substr($contents,0,$act_len);
         /* Save New File */
         $newfilename = $entry.".swf";
         $newhandle = fopen($newfilename, 'w');
         fwrite($newhandle,$contents);
         echo "SWF file outputted to $newfilename \n\n";
         fclose($newhandle);
                 }
        }
    }
   
//Wrap it up and exit
   
    closedir($handle);
}

Yes – it could be cleaner and more efficient. This is the very definition of bb_code 🙂

Hopefully one day I’ll get a chance to automate the renaming, unzipping and extracting part which is currently done manually as I understand PHP has this functionality. However, life on the front line does mean that from time to time Close enough is Good enough. It worked for me, taking a mere 10 seconds to extract all of the embbeded SWFs in our corporate PowerPoint presentation (add 60 secs for the manual bit) … so not too shabby 🙂


1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading...


Comments

19 Responses to “Extract embedded Flash (SWF) files from a PowerPoint presentation”

  1. Samir on April 4th, 2012 1:48 pm

    Hi bb,

    I have exactly the same issue as you. Excuse my noobish question but how do you run the php script on the .bin files?

    Best wishes,

    Samir

  2. Adolfo on April 11th, 2012 4:13 am

    How do I run the php script?

  3. Mike on May 2nd, 2012 9:48 am

    hi, i tried this, script gives error..

    Parse error: parse error, expecting `’)” in C:\int\test\something.php on line 55

    i have added only the php to your script and made it as file then put in on php server, then run the page name… the bin files are next to the php anything else should be done?

  4. bb on June 21st, 2012 12:42 pm

    Hi guys,

    Samir and Adolfo – I ran it under windows from the command line so it would have been something like php-win filename.php

    Mike – please accept my apologies, you will notice that the line the error is on (I suspect) is :

    for ($i=0; $i &_l_t; $i++);

    I have added the underscores as it keeps getting converted to <. This has been mangled by the highlighting script, or more likely me. It should read for ($i=0; $i<4; $i++){ Sorry for any confusion - I will update the post now.

  5. Shahnawaz Alam on August 15th, 2012 9:05 am

    Wow.. It worked like wonders.. Thanks a lot..

  6. IGP on November 15th, 2012 5:54 pm

    This is a great script worked perfectly for me on multiple .bin files.

    Great job!!

    IGP

  7. Charles on December 6th, 2012 10:25 pm

    I msut be missing something. wish i were getting errors to post.
    I copied the script as posted. Saved as convet.php
    Installed WAMP
    in a command line
    c:\wamp\www\bin\php\php5.3.13\php-win.exe convert.php

    and nothing. I know I missed something. I must have my bin files in the wrong place or something. Any help is great.

    Thanks.

  8. bb on December 7th, 2012 10:54 am

    Hi Charles,

    Can you try with php.exe convert.php and see if that works?

    BB

  9. JD Thompson on April 15th, 2013 9:57 pm

    I had a PPT file that was giving me an ‘invalid archive’ error when I changed the extension to .zip. However, I was able to open PPT and open the SWF with my copy of Flash Player by double-clicking the SWF object.

    Flash player then saves the SWF as a temporary file on our hard drive (see Flash Player > File menu for location). Go to that directory (you may have to type it into windows explorer) and grab the SWF.

    Hope this helps!

  10. Eric on August 20th, 2013 6:12 pm

    I get an error when I run the script saying that I need an x64 bit program and this is not compatible with the version I am running.
    What I really want is to send someone this presentation and have them send back to me the swf.

    Please advise and thank you

  11. bb on August 21st, 2013 11:07 am

    Eric,

    If you want to send me the presentation I can look at it for you. There will be a non-refundable, upfront charge of £500 🙂

    Otherwise I suggest you look at your PHP installation – the script is x86/x64 agnostic as far as I am aware.

    bb

  12. Anuj on June 28th, 2014 6:16 am

    will you please explain that how i run this php script?
    i tried to run this using xamp but nothing happen.

    Thank you.

  13. Bill on July 25th, 2014 4:06 pm

    Awesome script. I modified it some and tried to replace the flash in the bin file and can’t get it to work. Had any luck with that?

  14. bb on August 7th, 2014 7:44 am

    Hi Bill,

    I would imagine it was easier to do that in Powerpoint itself, if you were only looking at changing one or two.

    I really don’t know if it is possible to batch change them – I don’t know how they are indexed. If they are referenced by a file pointer, it could only be replaced by an equal or smaller sized SWF – and even then the smaller SWF would need to be padded out to the size if you are chopping the BIN file up and then gluing it back together.

    I would imagine (please – we are in complete WAG territory here) that there is some kind of lookup table that references the SWF_on_page_1 to the file offset for the appropriate SWF. You could either replace the offset with the address of the end of the file where you append the SWF or else you would have to make adjustments to all the referenced items after that. In other words if the new SWF is 500bytes bigger than the one you replace, each following referenced pointer would have to be increased by 500bytes (assuming you directly replaced the SWF).

    As I say – this is all complete guesswork and not something I have looked into I am afraid.

  15. Mike on May 5th, 2015 10:36 am

    For all who had trouble running the script: I needed to add the following lines to make it work:
    first line at the beginning:

    Save as a php file and run using this syntax (at least that worked for me using php 5.6.8):
    php -f script.php

  16. Mike on May 5th, 2015 10:42 am

    Shoots, the site removed the script contents from my comment.
    Basically, you need to correct the syntax – check the correct stard and end of .php files in the manual:
    http://php.net/manual/en/language.basic-syntax.php

  17. Ofer on September 5th, 2015 7:04 am

    Works like charm , although one SWF was not full extracted , was not able to “play” it in the flash player , it was extracted as a single image …
    I guess the BIN file of this flash is more complicated so the end of the file is not marked AS it should…

  18. sebus on September 8th, 2015 3:10 pm

    php-win did nothing, had to add

    and then php.exe did process it perfectly fine

  19. eugene on June 8th, 2016 5:05 am

    did not want to install php so converted to python: http://pastebin.com/xJY3KJcZ

Leave a Reply