Issue #48 Decompile only specified class

This commit is contained in:
Jindra Petk
2013-04-20 11:51:59 +02:00
parent 05d1aa0f79
commit 3e0eb0fe48
4 changed files with 53 additions and 3 deletions

View File

@@ -411,8 +411,9 @@ public class Main {
System.out.println(" ...opens SWF file with the decompiler GUI");
System.out.println(" 3) -proxy (-PXXX)");
System.out.println(" ...auto start proxy in the tray. Optional parameter -P specifies port for proxy. Defaults to 55555. ");
System.out.println(" 4) -export (as|pcode|image|shape|movie|sound) outdirectory infile");
System.out.println(" 4) -export (as|pcode|image|shape|movie|sound) outdirectory infile [-selectas3class class1 class2 ...]");
System.out.println(" ...export infile sources to outdirectory as AsctionScript code (\"as\" argument) or as PCode (\"pcode\" argument), images, shapes or movies");
System.out.println(" When \"as\" or \"pcode\" type specified, optional \"-selectas3class\" parameter can be passed to export only selected classes (ActionScript 3 only)");
System.out.println(" 5) -dumpSWF infile");
System.out.println(" ...dumps list of SWF tags to console");
System.out.println(" 6) -compress infile outfile");
@@ -425,6 +426,7 @@ public class Main {
System.out.println("java -jar FFDec.jar -proxy");
System.out.println("java -jar FFDec.jar -proxy -P1234");
System.out.println("java -jar FFDec.jar -export as \"C:\\decompiled\\\" myfile.swf");
System.out.println("java -jar FFDec.jar -export as \"C:\\decompiled\\\" myfile.swf -selectas3class com.example.MyClass com.example.SecondClass");
System.out.println("java -jar FFDec.jar -export pcode \"C:\\decompiled\\\" myfile.swf");
System.out.println("java -jar FFDec.jar -dumpSWF myfile.swf");
System.out.println("java -jar FFDec.jar -compress myfile.swf myfiledec.swf");
@@ -524,7 +526,14 @@ public class Main {
exfile.exportShapes(outDir.getAbsolutePath());
exportOK = true;
} else if (exportFormat.equals("as") || exportFormat.equals("pcode")) {
exportOK = exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode"));
if ((pos + 5 < args.length) && (args[pos + 4].equals("-selectas3class"))) {
exportOK = true;
for (int i = pos + 5; i < args.length; i++) {
exportOK = exportOK && exfile.exportAS3Class(args[i], outDir.getAbsolutePath(), exportFormat.equals("pcode"));
}
} else {
exportOK = exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode"));
}
} else if (exportFormat.equals("movie")) {
exfile.exportMovies(outDir.getAbsolutePath());
exportOK = true;

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash;
import SevenZip.Compression.LZMA.Encoder;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionGraphSource;
import com.jpexs.decompiler.flash.action.swf4.ActionEquals;
@@ -380,6 +381,37 @@ public class SWF {
return true;
}
public boolean exportAS3Class(String className, String outdir, boolean isPcode) throws Exception {
List<ABCContainerTag> abcTags = new ArrayList<ABCContainerTag>();
for (Tag t : tags) {
if (t instanceof ABCContainerTag) {
ABCContainerTag cnt = (ABCContainerTag) t;
abcTags.add(cnt);
}
}
for (int i = 0; i < abcTags.size(); i++) {
ABC abc = abcTags.get(i).getABC();
int scriptIndex = abc.findScriptByPath(className);
if (scriptIndex > -1) {
String cnt = "";
if (abc.script_info.length > 1) {
cnt = "script " + (i + 1) + "/" + abc.script_info.length + " ";
}
String path = abc.script_info[scriptIndex].getPath(abc);
String packageName = path.substring(0, path.lastIndexOf("."));
if (packageName.equals("")) {
path = path.substring(1);
}
String exStr = "Exporting " + "tag " + (i + 1) + "/" + abcTags.size() + " " + cnt + path + " ...";
informListeners("export", exStr);
abc.script_info[scriptIndex].export(abc, abcTags, outdir, isPcode);
return true;
}
}
return false;
}
public boolean exportActionScript(String outdir, boolean isPcode) throws Exception {
boolean asV3Found = false;
final EventListener evl = new EventListener() {

View File

@@ -872,4 +872,13 @@ public class ABC {
}
return -1;
}
public int findScriptByPath(String name) {
for (int c = 0; c < script_info.length; c++) {
String s = script_info[c].getPath(this);
if (name.equals(s)) {
return c;
}
}
return -1;
}
}

View File

@@ -1019,7 +1019,7 @@ public class Graph {
checkContinueAtTheEnd(retw, whileTrueLoop);
List<GraphTargetItem> finalCommands = forFinalCommands.get(whileTrueLoop);
IfItem ifi = null;
if (!finalCommands.isEmpty()) {
if ((finalCommands!=null) && !finalCommands.isEmpty()) {
if (finalCommands.get(finalCommands.size() - 1) instanceof IfItem) {
ifi = (IfItem) finalCommands.get(finalCommands.size() - 1);
finalCommands.remove(finalCommands.size() - 1);