Extracting images from SWF files

I wanted to try to get at an image hidden inside an SWF file, a Flash game on Armor Games. Google searches for “SWF extract” and the like offer a lot of unsavoury software, but a quick search of Debian turned up SWFTools, a GPL toolchain for making and unmaking SWF files. Compiling on Linux was as easy as ./configure; make

To actually extract the images, you have to find their IDs first, then extract them one by one. The compiled SWF file doesn’t seem to keep the source filename, so you have to hunt by size or the like.

$ swfdump foo.swf | grep image 
[024]     14446 DEFINEBITSLOSSLESS2 defines id 1725 image 660x561 (32 bpp)
$ swfextract -p 1725 -o 1725.png foo.swf
$ ls -lg 1725.png
-rw-r--r-- 1 nelson nelson 14877 Feb 19 14:04 1725.png

That example is for a 600×561 lossless image, 14446 bytes long, with ID 1725. I didn’t see any quick way to get swfextract to just extract all the images, although of course it’d be easy enough to write a shell script to do it.