之前用過一個Java的encoder/decoder叫做transform-swf,可以直接下載他的jar檔來用:transform-3.0.2.jar
他號稱可以支援到Flash 10,不過因為是五六年前的東西,我不敢保證是否能正確剖析最新的swf檔。
簡單的剖析swf中的影像(ExtractAvm1.java):
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
import com.flagstone.transform.*;
import com.flagstone.transform.movieclip.*;
import com.flagstone.transform.image.*;
public class ExtractAvm1 {
public static void main(String[] args) throws IOException, DataFormatException {
FileInputStream input = new FileInputStream(args[0]);
Movie movie = new Movie();
movie.decodeFromStream(input);
List<MovieTag> tags = movie.getObjects();
Iterator<MovieTag> iterator = tags.iterator();
while(iterator.hasNext()) {
MovieTag tag = iterator.next();
String s = tag.toString();
if(s.indexOf("DefineJPEGImage4") > -1) {
DefineJPEGImage4 tmp = (DefineJPEGImage4)tag;
System.out.println(tmp);
System.out.println("\twidth: " + tmp.getWidth() + ", height: " + tmp.getHeight());
continue;
}
if(s.indexOf("DefineJPEGImage3") > -1) {
DefineJPEGImage3 tmp = (DefineJPEGImage3)tag;
System.out.println(tmp);
System.out.println("\twidth: " + tmp.getWidth() + ", height: " + tmp.getHeight());
continue;
}
if(s.indexOf("DefineJPEGImage2") > -1) {
DefineJPEGImage2 tmp = (DefineJPEGImage2)tag;
System.out.println(tmp);
System.out.println("\twidth: " + tmp.getWidth() + ", height: " + tmp.getHeight());
continue;
}
if(s.indexOf("DefineJPEGImage") > -1) {
DefineJPEGImage tmp = (DefineJPEGImage)tag;
System.out.println(tmp);
System.out.println("\twidth: " + tmp.getWidth() + ", height: " + tmp.getHeight());
continue;
}
if(s.indexOf("DefineImage2") > -1) {
DefineImage2 tmp = (DefineImage2)tag;
System.out.println(tmp);
System.out.println("\twidth: " + tmp.getWidth() + ", height: " + tmp.getHeight());
continue;
}
if(s.indexOf("DefineImage") > -1) {
DefineImage tmp = (DefineImage)tag;
System.out.println(tmp);
System.out.println("\twidth: " + tmp.getWidth() + ", height: " + tmp.getHeight());
continue;
}
}
}
}
編譯:
javac -cp transform-3.0.2.jar:. ExtractAvm1.java
執行:
java -cp transform-3.0.2.jar:. ExtractAvm1 xxx.swf
結果看起來會像這樣:
DefineJPEGImage: { identifier=72; image=byte<9401> ...}
width: 240, height: 180
DefineJPEGImage2: { identifier=279; image=byte<38527> ...}
width: 140, height: 105
另外也有花錢的工具,我比較推這個:Sothink SWF Decompiler