Estrazione immagini da Flash SWF

http://stackoverflow.com/questions/11679113/command-line-extract-from-swf

La Adobe indica che
http://www.adobe.com/content/dam/Adobe/en/devnet/swf/pdf/swf_file_format_spec_v10.pdf

The header begins with a three-byte signature of either 0x46, 0x57, 0x53 (“FWS”); or 0x43, 0x57, 0x53 (“CWS”).

An FWS signature indicates an uncompressed SWF file;
CWS indicates that the entire file after the first 8 bytes (that is, after the FileLength field) was compressed by using the ZLIB open standard. The data format that the ZLIB library uses is described by Request for Comments (RFCs) documents 1950 to 1952. CWS file compression is permitted in SWF 6 or later only.

Infatti, preso un SWF qualsiasi contenente un’ immagine, ottengo:

$ hexdump -C RIMUOVERE\ BYTES.swf | head -n 1
00000000  43 57 53 06 04 d9 03 00  78 da b4 ba 79 38 d4 5f  |CWS.....x...y8._|

Perciò bisogna

  1. rimuovere i primi 8 byte
  2. decomprimere con ZLIB ciò che viene dopo

Ecco uno script bash che fa questo lavoro:

#!/bin/bash
for swf in "$@"
do
    signature=$(dd if="$swf" bs=1 count=3 2> /dev/null)
    case "$signature" in
        FWS)
            echo -e "uncompressed\t$swf"
            ;;
        CWS)
            targetname="$(dirname "$swf")/uncompressed_$(basename "$swf")"
            echo "uncompressing to $targetname"

            dd if="$swf" bs=1 skip=8 2>/dev/null |
                (echo -n 'FWS'; 
                 dd if="$swf" bs=1 skip=3 count=5 2>/dev/null;
                 zlib-flate -uncompress) > "$targetname"
            ;;
        *)
            {
                echo -e "unrecognized\t$swf"
                file "$swf"
            } > /dev/stderr
            ;;
    esac

done

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...