diff --git a/trunk/libsrc/jpproxy/src/com/jpexs/proxy/Main.java b/trunk/libsrc/jpproxy/src/com/jpexs/proxy/Main.java index 3d99542f9..2b41fa0c1 100644 --- a/trunk/libsrc/jpproxy/src/com/jpexs/proxy/Main.java +++ b/trunk/libsrc/jpproxy/src/com/jpexs/proxy/Main.java @@ -11,7 +11,7 @@ import java.util.List; public class Main { - public static final String REPLACEMENTSFILE = "." + File.separator + "config" + File.separator + "replacements.ini"; + public static final String REPLACEMENTSFILE = "." + File.separator + "config" + File.separator + "replacements.ini"; public static boolean DEBUG_MODE = false; public static void main(String[] argv) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 56fb76211..0cc431ab4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -93,6 +93,7 @@ import com.jpexs.decompiler.flash.types.filters.Filtering; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.sound.AdpcmDecoder; import com.jpexs.decompiler.flash.xfl.XFLConverter; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphSourceItemContainer; @@ -532,7 +533,7 @@ public class SWF { return true; } - public boolean exportAS3Class(String className, String outdir, boolean isPcode, boolean parallel) throws Exception { + public boolean exportAS3Class(String className, String outdir, ExportMode exportMode, boolean parallel) throws Exception { List abcTags = new ArrayList<>(); for (Tag t : tags) { @@ -551,7 +552,7 @@ public class SWF { } String exStr = "Exporting " + "tag " + (i + 1) + "/" + abcTags.size() + " " + cnt + scr.getPath() + " ..."; informListeners("export", exStr); - scr.export(outdir, abcTags, isPcode, parallel); + scr.export(outdir, abcTags, exportMode, parallel); return true; } } @@ -592,7 +593,7 @@ public class SWF { ScriptPack pack; String directory; List abcList; - boolean pcode; + ExportMode exportMode; ClassPath path; AtomicInteger index; int count; @@ -601,11 +602,11 @@ public class SWF { long startTime; long stopTime; - public ExportPackTask(AbortRetryIgnoreHandler handler, AtomicInteger index, int count, ClassPath path, ScriptPack pack, String directory, List abcList, boolean pcode, boolean parallel) { + public ExportPackTask(AbortRetryIgnoreHandler handler, AtomicInteger index, int count, ClassPath path, ScriptPack pack, String directory, List abcList, ExportMode exportMode, boolean parallel) { this.pack = pack; this.directory = directory; this.abcList = abcList; - this.pcode = pcode; + this.exportMode = exportMode; this.path = path; this.index = index; this.count = count; @@ -619,7 +620,7 @@ public class SWF { @Override public void run() throws IOException { startTime = System.currentTimeMillis(); - this.result = pack.export(directory, abcList, pcode, parallel); + this.result = pack.export(directory, abcList, exportMode, parallel); stopTime = System.currentTimeMillis(); } }; @@ -632,7 +633,7 @@ public class SWF { } } - public List exportActionScript2(AbortRetryIgnoreHandler handler, String outdir, boolean isPcode, boolean parallel, EventListener evl) throws IOException { + public List exportActionScript2(AbortRetryIgnoreHandler handler, String outdir, ExportMode exportMode, boolean parallel, EventListener evl) throws IOException { List ret = new ArrayList<>(); List list2 = new ArrayList<>(); list2.addAll(tags); @@ -645,11 +646,11 @@ public class SWF { outdir += "scripts" + File.separator; AtomicInteger cnt = new AtomicInteger(1); int totalCount = TagNode.getTagCountRecursive(list); - ret.addAll(TagNode.exportNodeAS(tags, handler, list, outdir, isPcode, cnt, totalCount, evl)); + ret.addAll(TagNode.exportNodeAS(tags, handler, list, outdir, exportMode, cnt, totalCount, evl)); return ret; } - public List exportActionScript3(AbortRetryIgnoreHandler handler, String outdir, boolean isPcode, boolean parallel) { + public List exportActionScript3(AbortRetryIgnoreHandler handler, String outdir, ExportMode exportMode, boolean parallel) { ExecutorService executor = Executors.newFixedThreadPool(parallel ? 20 : 1); List> futureResults = new ArrayList<>(); AtomicInteger cnt = new AtomicInteger(1); @@ -661,7 +662,7 @@ public class SWF { } List> packs = getAS3Packs(); for (MyEntry item : packs) { - Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.key, item.value, outdir, abcTags, isPcode, parallel)); + Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.key, item.value, outdir, abcTags, exportMode, parallel)); futureResults.add(future); } @@ -683,7 +684,7 @@ public class SWF { return ret; } - public List exportActionScript(AbortRetryIgnoreHandler handler, String outdir, boolean isPcode, boolean parallel) throws Exception { + public List exportActionScript(AbortRetryIgnoreHandler handler, String outdir, ExportMode exportMode, boolean parallel) throws Exception { boolean asV3Found = false; List ret = new ArrayList<>(); final EventListener evl = new EventListener() { @@ -701,9 +702,9 @@ public class SWF { } if (asV3Found) { - ret.addAll(exportActionScript3(handler, outdir, isPcode, parallel)); + ret.addAll(exportActionScript3(handler, outdir, exportMode, parallel)); } else { - ret.addAll(exportActionScript2(handler, outdir, isPcode, parallel, evl)); + ret.addAll(exportActionScript2(handler, outdir, exportMode, parallel, evl)); } return ret; } @@ -1586,7 +1587,7 @@ public class SWF { GraphSourceItem ins = code.get(ip); if (debugMode) { - System.err.println("Visit " + ip + ": ofs" + Helper.formatAddress(((Action) ins).getAddress()) + ":" + ((Action) ins).getASMSource(new ArrayList(), new ArrayList(), new ArrayList(), code.version, false) + " stack:" + Helper.stackToString(stack, LocalData.create(new ConstantPool()))); + System.err.println("Visit " + ip + ": ofs" + Helper.formatAddress(((Action) ins).getAddress()) + ":" + ((Action) ins).getASMSource(new ArrayList(), new ArrayList(), new ArrayList(), code.version, ExportMode.PCODE) + " stack:" + Helper.stackToString(stack, LocalData.create(new ConstantPool()))); } if (ins.isExit()) { break; diff --git a/trunk/src/com/jpexs/decompiler/flash/TagNode.java b/trunk/src/com/jpexs/decompiler/flash/TagNode.java index 07e825bf8..caf0d2704 100644 --- a/trunk/src/com/jpexs/decompiler/flash/TagNode.java +++ b/trunk/src/com/jpexs/decompiler/flash/TagNode.java @@ -47,6 +47,7 @@ import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.Container; import com.jpexs.decompiler.flash.tags.base.ContainerItem; import com.jpexs.decompiler.flash.tags.base.Exportable; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.Helper; import java.io.File; import java.io.FileOutputStream; @@ -251,13 +252,13 @@ public class TagNode { return count; } - public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, boolean isPcode) throws IOException { + public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, ExportMode exportMode) throws IOException { AtomicInteger cnt = new AtomicInteger(1); int totalCount = TagNode.getTagCountRecursive(nodeList); - return exportNodeAS(allTags, handler, nodeList, outdir, isPcode, cnt, totalCount, null); + return exportNodeAS(allTags, handler, nodeList, outdir, exportMode, cnt, totalCount, null); } - public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, boolean isPcode, AtomicInteger index, int count, EventListener ev) throws IOException { + public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, ExportMode exportMode, AtomicInteger index, int count, EventListener ev) throws IOException { File dir = new File(outdir); List ret = new ArrayList<>(); if (!outdir.endsWith(File.separator)) { @@ -297,9 +298,13 @@ public class TagNode { File file = new File(f); String res; ASMSource asm = ((ASMSource) node.tag); - if (isPcode) { + if (exportMode == ExportMode.HEX) { HilightedTextWriter writer = new HilightedTextWriter(false, asm.getActionSourceIndent()); - asm.getASMSource(SWF.DEFAULT_VERSION, false, writer, null); + asm.getActionBytesAsHex(writer); + res = asm.getActionSourcePrefix() + writer.toString() + asm.getActionSourceSuffix(); + } else if (exportMode != ExportMode.SOURCE) { + HilightedTextWriter writer = new HilightedTextWriter(false, asm.getActionSourceIndent()); + asm.getASMSource(SWF.DEFAULT_VERSION, exportMode, writer, null); res = asm.getActionSourcePrefix() + writer.toString() + asm.getActionSourceSuffix(); } else { List as = asm.getActions(SWF.DEFAULT_VERSION); @@ -337,7 +342,7 @@ public class TagNode { } while (retry); } } else { - ret.addAll(exportNodeAS(allTags, handler, node.subItems, outdir + name, isPcode, index, count, ev)); + ret.addAll(exportNodeAS(allTags, handler, node.subItems, outdir + name, exportMode, index, count, ev)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index fb1c3dc22..3f0b2e317 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -734,7 +734,7 @@ public class ABC { } } - /*public void export(String directory, boolean pcode, List abcList, boolean parallel) throws IOException { + /*public void export(String directory, ExportMode exportMode, List abcList, boolean parallel) throws IOException { export(directory, pcode, abcList, "", parallel); }*/ public List> getScriptPacks() { @@ -744,7 +744,7 @@ public class ABC { } return ret; } - /*public List export(String directory, boolean pcode, List abcList, String abcStr, boolean parallel) throws IOException { + /*public List export(String directory, ExportMode exportMode, List abcList, String abcStr, boolean parallel) throws IOException { ExecutorService executor = Executors.newFixedThreadPool(20); List> futureResults = new ArrayList<>(); AtomicInteger cnt = new AtomicInteger(1); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index c09bbce14..899eb5265 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.helpers.Helper; import java.io.File; @@ -103,7 +104,7 @@ public class ScriptPack { return Helper.joinStrings(pathParts, File.separator); } - public File export(String directory, List abcList, boolean pcode, boolean parallel) throws IOException { + public File export(String directory, List abcList, ExportMode exportMode, boolean parallel) throws IOException { String scriptName = getPathScriptName(); String packageName = getPathPackage(); File outDir = new File(directory + File.separatorChar + makeDirPath(packageName)); @@ -122,9 +123,9 @@ public class ScriptPack { Namespace ns = name.getNamespace(abc.constants); HilightedTextWriter writer = new HilightedTextWriter(false); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { - abc.script_info[scriptIndex].traits.traits[t].convertPackaged(null, "", abcList, abc, false, pcode, scriptIndex, -1, writer, new ArrayList(), parallel); + abc.script_info[scriptIndex].traits.traits[t].convertPackaged(null, "", abcList, abc, false, exportMode, scriptIndex, -1, writer, new ArrayList(), parallel); } else { - abc.script_info[scriptIndex].traits.traits[t].convert(null, "", abcList, abc, false, pcode, scriptIndex, -1, writer, new ArrayList(), parallel); + abc.script_info[scriptIndex].traits.traits[t].convert(null, "", abcList, abc, false, exportMode, scriptIndex, -1, writer, new ArrayList(), parallel); } String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); fos.write(s.getBytes("utf-8")); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 2e0e3b905..44ee0a8a8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -74,6 +74,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphPart; import com.jpexs.decompiler.graph.GraphSourceItem; @@ -718,11 +719,11 @@ public class AVM2Code implements Serializable { return writer; } - public HilightedTextWriter toASMSource(ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, boolean hex, HilightedTextWriter writer) { - return toASMSource(constants, trait, info, body, new ArrayList(), hex, writer); + public HilightedTextWriter toASMSource(ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, ExportMode exportMode, HilightedTextWriter writer) { + return toASMSource(constants, trait, info, body, new ArrayList(), exportMode, writer); } - public HilightedTextWriter toASMSource(ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, List outputMap, boolean hex, HilightedTextWriter writer) { + public HilightedTextWriter toASMSource(ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, List outputMap, ExportMode exportMode, HilightedTextWriter writer) { invalidateCache(); if (trait != null) { if (trait instanceof TraitFunction) { @@ -899,81 +900,86 @@ public class AVM2Code implements Serializable { int ip = 0; int largeLimit = 20000; boolean markOffsets = code.size() <= largeLimit; - for (AVM2Instruction ins : code) { - if (hex) { - writer.appendNoHilight(""); - writer.appendNoHilight(Helper.bytesToHexString(ins.getBytes())); - writer.appendNoHilight("\n"); - } - if (ins.labelname != null) { - writer.appendNoHilight(ins.labelname + ":"); - } else if (offsets.contains(ofs)) { - writer.appendNoHilight("ofs" + Helper.formatAddress(ofs) + ":"); - } - /*for (int e = 0; e < body.exceptions.length; e++) { - if (body.exceptions[e].start == ofs) { - ret.append("exceptionstart " + e + ":"); - } - if (body.exceptions[e].end == ofs) { - ret.append("exceptionend " + e + ":"); - } - if (body.exceptions[e].target == ofs) { - ret.append("exceptiontarget " + e + ":"); - } - }*/ - if (ins.replaceWith != null) { - for (Object o : ins.replaceWith) { - if (o instanceof Integer) { - AVM2Instruction ins2 = code.get((Integer) o); - if (ins2.isIgnored()) { - continue; - } - writer.append("", ins2.mappedOffset > -1 ? ins2.mappedOffset : ofs); - writer.appendNoHilight(ins2.toStringNoAddress(constants, new ArrayList()) + " ;copy from " + Helper.formatAddress(pos2adr((Integer) o))); - writer.newLine(); - outputMap.add((Integer) o); - } else if (o instanceof ControlFlowTag) { - ControlFlowTag cft = (ControlFlowTag) o; - if (cft.name.equals("appendjump")) { - writer.appendNoHilight("jump ofs" + Helper.formatAddress(pos2adr(cft.value))).newLine(); - outputMap.add(-1); - } - if (cft.name.equals("mark")) { - writer.appendNoHilight("ofs" + Helper.formatAddress(pos2adr(cft.value)) + ":"); - } - } + + if (exportMode == ExportMode.HEX) { + Helper.byteArrayToHex(writer, getBytes()); + } else { + for (AVM2Instruction ins : code) { + if (exportMode == ExportMode.PCODEWITHHEX) { + writer.appendNoHilight(""); + writer.appendNoHilight(Helper.bytesToHexString(ins.getBytes())); + writer.appendNoHilight("\n"); } - } else { - if (!ins.isIgnored()) { - if (markOffsets) { - writer.append("", ins.mappedOffset > -1 ? ins.mappedOffset : ofs); - } - int fixBranch = ins.getFixBranch(); - if (fixBranch > -1) { - if (ins.definition instanceof IfTypeIns) { - for (int i = 0; i < -ins.definition.getStackDelta(ins, null/*IfTypeIns do not require ABCs*/); i++) { - writer.appendNoHilight(new DeobfuscatePopIns().instructionName).newLine(); + if (ins.labelname != null) { + writer.appendNoHilight(ins.labelname + ":"); + } else if (offsets.contains(ofs)) { + writer.appendNoHilight("ofs" + Helper.formatAddress(ofs) + ":"); + } + /*for (int e = 0; e < body.exceptions.length; e++) { + if (body.exceptions[e].start == ofs) { + ret.append("exceptionstart " + e + ":"); + } + if (body.exceptions[e].end == ofs) { + ret.append("exceptionend " + e + ":"); + } + if (body.exceptions[e].target == ofs) { + ret.append("exceptiontarget " + e + ":"); + } + }*/ + if (ins.replaceWith != null) { + for (Object o : ins.replaceWith) { + if (o instanceof Integer) { + AVM2Instruction ins2 = code.get((Integer) o); + if (ins2.isIgnored()) { + continue; } - if (fixBranch == 0) { //jump - writer.appendNoHilight(new JumpIns().instructionName + " ofs" + Helper.formatAddress(ofs + ins.getBytes().length + ins.operands[0])); - } else { - //nojump, ignore + writer.append("", ins2.mappedOffset > -1 ? ins2.mappedOffset : ofs); + writer.appendNoHilight(ins2.toStringNoAddress(constants, new ArrayList()) + " ;copy from " + Helper.formatAddress(pos2adr((Integer) o))); + writer.newLine(); + outputMap.add((Integer) o); + } else if (o instanceof ControlFlowTag) { + ControlFlowTag cft = (ControlFlowTag) o; + if (cft.name.equals("appendjump")) { + writer.appendNoHilight("jump ofs" + Helper.formatAddress(pos2adr(cft.value))).newLine(); + outputMap.add(-1); + } + if (cft.name.equals("mark")) { + writer.appendNoHilight("ofs" + Helper.formatAddress(pos2adr(cft.value)) + ":"); } } - //TODO: lookupswitch ? - } else { - if (ins.changeJumpTo > -1) { - writer.appendNoHilight(ins.definition.instructionName + " ofs" + Helper.formatAddress(pos2adr(ins.changeJumpTo))); + } + } else { + if (!ins.isIgnored()) { + if (markOffsets) { + writer.append("", ins.mappedOffset > -1 ? ins.mappedOffset : ofs); + } + int fixBranch = ins.getFixBranch(); + if (fixBranch > -1) { + if (ins.definition instanceof IfTypeIns) { + for (int i = 0; i < -ins.definition.getStackDelta(ins, null/*IfTypeIns do not require ABCs*/); i++) { + writer.appendNoHilight(new DeobfuscatePopIns().instructionName).newLine(); + } + if (fixBranch == 0) { //jump + writer.appendNoHilight(new JumpIns().instructionName + " ofs" + Helper.formatAddress(ofs + ins.getBytes().length + ins.operands[0])); + } else { + //nojump, ignore + } + } + //TODO: lookupswitch ? } else { - writer.appendNoHilight(ins.toStringNoAddress(constants, new ArrayList())); + if (ins.changeJumpTo > -1) { + writer.appendNoHilight(ins.definition.instructionName + " ofs" + Helper.formatAddress(pos2adr(ins.changeJumpTo))); + } else { + writer.appendNoHilight(ins.toStringNoAddress(constants, new ArrayList())); + } } + writer.newLine(); + outputMap.add(ip); } - writer.newLine(); - outputMap.add(ip); } + ofs += ins.getBytes().length; + ip++; } - ofs += ins.getBytes().length; - ip++; } return writer; } @@ -2101,7 +2107,7 @@ public class AVM2Code implements Serializable { try { List outputMap = new ArrayList<>(); HilightedTextWriter writer = new HilightedTextWriter(false); - toASMSource(constants, trait, info, body, outputMap, false, writer); + toASMSource(constants, trait, info, body, outputMap, ExportMode.PCODE, writer); String src = writer.toString(); AVM2Code acode = ASM3Parser.parse(new ByteArrayInputStream(src.getBytes("UTF-8")), constants, null, body, info); @@ -2143,7 +2149,7 @@ public class AVM2Code implements Serializable { try { List outputMap = new ArrayList<>(); HilightedTextWriter writer = new HilightedTextWriter(false); - toASMSource(constants, trait, info, body, outputMap, false, writer); + toASMSource(constants, trait, info, body, outputMap, ExportMode.PCODE, writer); String src = writer.toString(); AVM2Code acode = ASM3Parser.parse(new ByteArrayInputStream(src.getBytes("UTF-8")), constants, trait, body, info); for (int i = 0; i < acode.code.size(); i++) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java index cb7a6a746..f8a518ab7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.NewFunction import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.LocalData; import java.util.List; @@ -72,7 +73,7 @@ public class NewFunctionAVM2Item extends AVM2Item { writer.indent(); if (body != null) { try { - body.toString(path + "/inner", false, isStatic, scriptIndex, classIndex, abc, null, constants, methodInfo, new Stack()/*scopeStack*/, false, writer, fullyQualifiedNames, null); + body.toString(path + "/inner", ExportMode.SOURCE, isStatic, scriptIndex, classIndex, abc, null, constants, methodInfo, new Stack()/*scopeStack*/, false, writer, fullyQualifiedNames, null); } catch (Exception ex) { Logger.getLogger(NewFunctionIns.class.getName()).log(Level.SEVERE, "error during newfunction", ex); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 7a820178f..a1c04f502 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; @@ -109,21 +110,21 @@ public class MethodBody implements Cloneable, Serializable { return ret; } - public String toString(final String path, boolean pcode, final boolean isStatic, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ConstantPool constants, final MethodInfo[] method_info, final Stack scopeStack, final boolean isStaticInitializer, final List fullyQualifiedNames, final Traits initTraits) { + public String toString(final String path, ExportMode exportMode, final boolean isStatic, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ConstantPool constants, final MethodInfo[] method_info, final Stack scopeStack, final boolean isStaticInitializer, final List fullyQualifiedNames, final Traits initTraits) { HilightedTextWriter writer = new HilightedTextWriter(false); - toString(path, pcode, isStatic, scriptIndex, classIndex, abc, trait, constants, method_info, scopeStack, isStaticInitializer, writer, fullyQualifiedNames, initTraits); + toString(path, exportMode, isStatic, scriptIndex, classIndex, abc, trait, constants, method_info, scopeStack, isStaticInitializer, writer, fullyQualifiedNames, initTraits); String src = writer.toString(); src = Graph.removeNonRefenrencedLoopLabels(src); return src; } - public HilightedTextWriter toString(final String path, boolean pcode, final boolean isStatic, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ConstantPool constants, final MethodInfo[] method_info, final Stack scopeStack, final boolean isStaticInitializer, final HilightedTextWriter writer, final List fullyQualifiedNames, final Traits initTraits) { + public HilightedTextWriter toString(final String path, ExportMode exportMode, final boolean isStatic, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ConstantPool constants, final MethodInfo[] method_info, final Stack scopeStack, final boolean isStaticInitializer, final HilightedTextWriter writer, final List fullyQualifiedNames, final Traits initTraits) { if (debugMode) { System.err.println("Decompiling " + path); } - if (pcode) { + if (exportMode != ExportMode.SOURCE) { writer.indent(); - code.toASMSource(constants, trait, method_info[this.method_info], this, false, writer); + code.toASMSource(constants, trait, method_info[this.method_info], this, exportMode, writer); writer.unindent(); } else { if (!Configuration.getConfig("decompile", true)) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index 920dc6aca..fdf0a5a9c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import java.util.ArrayList; import java.util.List; @@ -80,7 +81,7 @@ public class ScriptInfo { return "method_index=" + init_index + "\r\n" + traits.toString(abc, fullyQualifiedNames); } - public HilightedTextWriter convert(List abcTags, ABC abc, boolean pcode, HilightedTextWriter writer, int scriptIndex, boolean parallel) { - return traits.convert(null, "", abcTags, abc, false, pcode, true, scriptIndex, -1, writer, new ArrayList(), parallel); + public HilightedTextWriter convert(List abcTags, ABC abc, ExportMode exportMode, HilightedTextWriter writer, int scriptIndex, boolean parallel) { + return traits.convert(null, "", abcTags, abc, false, exportMode, true, scriptIndex, -1, writer, new ArrayList(), parallel); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index d36e5d27e..9e5158eca 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.helpers.Helper; import java.io.File; @@ -115,19 +116,19 @@ public abstract class Trait implements Serializable { return abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata); } - public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { writer.appendNoHilight(abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata)); return writer; } - public HilightedTextWriter convertPackaged(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcod, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convertPackaged(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { Namespace ns = abc.constants.constant_multiname[name_index].getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { String nsname = ns.getName(abc.constants); writer.appendNoHilight("package " + nsname).newLine(); writer.appendNoHilight("{").newLine(); writer.indent(); - convert(parent, path, abcTags, abc, isStatic, pcod, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + convert(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); writer.newLine(); writer.unindent(); writer.appendNoHilight("}"); @@ -135,8 +136,8 @@ public abstract class Trait implements Serializable { return writer; } - public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { - convert(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + convert(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); return writer; } @@ -158,7 +159,7 @@ public abstract class Trait implements Serializable { return packageName + "." + objectName; } - public void export(Trait parent, String directory, ABC abc, List abcList, boolean pcode, int scriptIndex, int classIndex, boolean isStatic, boolean parallel) throws IOException { + public void export(Trait parent, String directory, ABC abc, List abcList, ExportMode exportMode, int scriptIndex, int classIndex, boolean isStatic, boolean parallel) throws IOException { Multiname name = getName(abc); Namespace ns = name.getNamespace(abc.constants); String packageName = ns.getName(abc.constants); @@ -174,7 +175,7 @@ public abstract class Trait implements Serializable { String fileName = outDir.toString() + File.separator + objectName + ".as"; try (FileOutputStream fos = new FileOutputStream(fileName)) { HilightedTextWriter writer = new HilightedTextWriter(false); - convertPackaged(parent, "", abcList, abc, isStatic, pcode, scriptIndex, classIndex, writer, new ArrayList(), parallel); + convertPackaged(parent, "", abcList, abc, isStatic, exportMode, scriptIndex, classIndex, writer, new ArrayList(), parallel); String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); fos.write(s.getBytes()); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index fcb237904..e33322202 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -33,6 +33,7 @@ import com.jpexs.decompiler.flash.abc.types.NamespaceSet; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; import java.util.ArrayList; @@ -322,13 +323,13 @@ public class TraitClass extends Trait implements TraitWithSlot { } @Override - public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { String classHeader = abc.instance_info[class_info].getClassHeaderStr(abc, fullyQualifiedNames); return writer.appendNoHilight(classHeader); } @Override - public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { writer.startClass(class_info); String packageName = abc.instance_info[class_info].getName(abc.constants).getNamespace(abc.constants).getName(abc.constants); @@ -426,7 +427,7 @@ public class TraitClass extends Trait implements TraitWithSlot { writer.startTrait(abc.class_info[class_info].static_traits.traits.length + abc.instance_info[class_info].instance_traits.traits.length + 1); writer.appendNoHilight("{").newLine(); writer.mark(); - abc.bodies[bodyIndex].toString(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".staticinitializer", pcode, true, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new Stack(), true, writer, fullyQualifiedNames, abc.class_info[class_info].static_traits); + abc.bodies[bodyIndex].toString(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".staticinitializer", exportMode, true, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new Stack(), true, writer, fullyQualifiedNames, abc.class_info[class_info].static_traits); boolean empty = !writer.getMark(); writer.appendNoHilight("}").newLine(); writer.endTrait(); @@ -468,7 +469,7 @@ public class TraitClass extends Trait implements TraitWithSlot { } writer.appendNoHilight(") {").newLine(); if (bodyIndex != -1) { - abc.bodies[bodyIndex].toString(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".initializer", pcode, false, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new Stack(), false, writer, fullyQualifiedNames, abc.instance_info[class_info].instance_traits); + abc.bodies[bodyIndex].toString(path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".initializer", exportMode, false, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new Stack(), false, writer, fullyQualifiedNames, abc.instance_info[class_info].instance_traits); } writer.appendNoHilight("}").newLine(); writer.endTrait(); @@ -476,9 +477,9 @@ public class TraitClass extends Trait implements TraitWithSlot { } //static variables,constants & methods - abc.class_info[class_info].static_traits.convert(this, path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, true, pcode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); + abc.class_info[class_info].static_traits.convert(this, path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); - abc.instance_info[class_info].instance_traits.convert(this, path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, false, pcode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); + abc.instance_info[class_info].instance_traits.convert(this, path +/*packageName +*/ "/" + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); writer.unindent(); writer.appendNoHilight("}"); // class diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index a00c19856..c7e126bcb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; import java.util.List; @@ -41,7 +42,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; MethodBody body = abc.findBody(method_info); if (body == null) { @@ -61,15 +62,15 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { - convertHeader(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + convertHeader(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); if (abc.instance_info[classIndex].isInterface()) { writer.appendNoHilight(";"); } else { writer.appendNoHilight(" {").newLine(); int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { - abc.bodies[bodyIndex].toString(path + "." + abc.constants.constant_multiname[name_index].getName(abc.constants, fullyQualifiedNames), pcode, isStatic, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new Stack(), false, writer, fullyQualifiedNames, null); + abc.bodies[bodyIndex].toString(path + "." + abc.constants.constant_multiname[name_index].getName(abc.constants, fullyQualifiedNames), exportMode, isStatic, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new Stack(), false, writer, fullyQualifiedNames, null); } writer.newLine(); writer.appendNoHilight("}"); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index a0abbe34e..a80cf728d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; import java.util.List; @@ -36,7 +37,7 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convertHeader(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; @@ -65,15 +66,15 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { - convertHeader(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + convertHeader(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); int bodyIndex = abc.findBodyIndex(method_info); if (classIndex != -1 && abc.instance_info[classIndex].isInterface() || bodyIndex == -1) { writer.appendNoHilight(";"); } else { writer.appendNoHilight(" {").newLine(); if (bodyIndex != -1) { - abc.bodies[bodyIndex].toString(path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames), pcode, isStatic, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new Stack(), false, writer, fullyQualifiedNames, null); + abc.bodies[bodyIndex].toString(path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames), exportMode, isStatic, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new Stack(), false, writer, fullyQualifiedNames, null); } writer.appendNoHilight("}"); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index 5aaaf1c97..6c83a6be2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.ValueKind; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.Helper; @@ -132,7 +133,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { } @Override - public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index df076baa0..858fa6145 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -80,7 +81,7 @@ public class Traits implements Serializable { List abcTags; ABC abc; boolean isStatic; - boolean pcode; + ExportMode exportMode; int scriptIndex; int classIndex; HilightedTextWriter writer; @@ -89,7 +90,7 @@ public class Traits implements Serializable { boolean parallel; Trait parent; - public TraitConvertTask(Trait trait, Trait parent, boolean makePackages, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, int traitIndex, boolean parallel) { + public TraitConvertTask(Trait trait, Trait parent, boolean makePackages, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, int traitIndex, boolean parallel) { this.trait = trait; this.parent = parent; this.makePackages = makePackages; @@ -97,7 +98,7 @@ public class Traits implements Serializable { this.abcTags = abcTags; this.abc = abc; this.isStatic = isStatic; - this.pcode = pcode; + this.exportMode = exportMode; this.scriptIndex = scriptIndex; this.classIndex = classIndex; this.writer = writer; @@ -120,9 +121,9 @@ public class Traits implements Serializable { writer.startTrait(h); } if (makePackages) { - trait.convertPackaged(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + trait.convertPackaged(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } else { - trait.convert(parent, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + trait.convert(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } if (trait instanceof TraitClass) { writer.endClass(); @@ -133,7 +134,7 @@ public class Traits implements Serializable { } } - public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, boolean makePackages, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { + public HilightedTextWriter convert(Trait parent, String path, List abcTags, ABC abc, boolean isStatic, ExportMode exportMode, boolean makePackages, int scriptIndex, int classIndex, HilightedTextWriter writer, List fullyQualifiedNames, boolean parallel) { ExecutorService executor = null; List> futureResults = null; List traitConvertTasks = null; @@ -146,7 +147,7 @@ public class Traits implements Serializable { } for (int t = 0; t < traits.length; t++) { HilightedTextWriter writer2 = new HilightedTextWriter(writer.getIsHighlighted(), writer.getIndent()); - TraitConvertTask task = new TraitConvertTask(traits[t], parent, makePackages, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, writer2, fullyQualifiedNames, t, parallel); + TraitConvertTask task = new TraitConvertTask(traits[t], parent, makePackages, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer2, fullyQualifiedNames, t, parallel); if (parallel) { Future future = executor.submit(task); futureResults.add(future); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java index 1f49f9bbb..afee23d5d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import java.util.ArrayList; import java.util.List; @@ -41,12 +42,12 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage { writer.appendNoHilight(super.toString(abcTags, abc) + " "); if (parentTraitIndex > -1) { if (isStatic) { - ((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + ((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); } else { - ((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + ((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); } } - ((TraitSlotConst) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + ((TraitSlotConst) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); return writer.toString(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java index c054453e3..e82665caf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import java.util.ArrayList; import java.util.List; @@ -55,13 +56,13 @@ public abstract class MethodMultinameUsage extends TraitMultinameUsage { } else { if (parentTraitIndex > -1) { if (isStatic){ - ((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + ((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); } else { - ((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + ((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); } writer.appendNoHilight(" "); } - ((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + ((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader(null, "", abcTags, abc, isStatic, ExportMode.SOURCE, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); } return writer.toString(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index ef355e3e2..9b98739ea 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -50,6 +50,7 @@ import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.collections.MyEntry; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphSource; import com.jpexs.decompiler.graph.GraphSourceItem; @@ -396,8 +397,8 @@ public class Action implements GraphSourceItem { * @param path * @return HilightedTextWriter */ - public static HilightedTextWriter actionsToString(List listeners, long address, List list, List importantOffsets, int version, boolean hex, HilightedTextWriter writer, long swfPos, String path) { - return actionsToString(listeners, address, list, importantOffsets, new ArrayList(), version, hex, writer, swfPos, path); + public static HilightedTextWriter actionsToString(List listeners, long address, List list, List importantOffsets, int version, ExportMode exportMode, HilightedTextWriter writer, long swfPos, String path) { + return actionsToString(listeners, address, list, importantOffsets, new ArrayList(), version, exportMode, writer, swfPos, path); } /** @@ -414,7 +415,7 @@ public class Action implements GraphSourceItem { * @param path * @return HilightedTextWriter */ - private static HilightedTextWriter actionsToString(List listeners, long address, List list, List importantOffsets, List constantPool, int version, boolean hex, HilightedTextWriter writer, long swfPos, String path) { + private static HilightedTextWriter actionsToString(List listeners, long address, List list, List importantOffsets, List constantPool, int version, ExportMode exportMode, HilightedTextWriter writer, long swfPos, String path) { long offset; if (importantOffsets == null) { //setActionsAddresses(list, 0, version); @@ -438,7 +439,7 @@ public class Action implements GraphSourceItem { a = (Action) s; } pos++; - if (hex) { + if (exportMode == ExportMode.PCODEWITHHEX) { if (lastPush) { writer.newLine(); lastPush = false; @@ -495,7 +496,7 @@ public class Action implements GraphSourceItem { lastPush = false; } writer.append("", offset); - writer.appendNoHilight(a.replaceWith.getASMSource(list, importantOffsets, constantPool, version, hex)); + writer.appendNoHilight(a.replaceWith.getASMSource(list, importantOffsets, constantPool, version, exportMode)); writer.newLine(); } else if (a.isIgnored()) { if (lastPush) { @@ -519,7 +520,7 @@ public class Action implements GraphSourceItem { writer.newLine(); lastPush = false; } - writer.appendNoHilight(a.beforeInsert.getASMSource(list, importantOffsets, constantPool, version, hex)); + writer.appendNoHilight(a.beforeInsert.getASMSource(list, importantOffsets, constantPool, version, exportMode)); writer.newLine(); } //if (!(a instanceof ActionNop)) { @@ -534,7 +535,7 @@ public class Action implements GraphSourceItem { add = ""; if ((a instanceof ActionPush) && lastPush) { writer.appendNoHilight(" "); - ((ActionPush) a).paramsToStringReplaced(list, importantOffsets, constantPool, version, hex, writer); + ((ActionPush) a).paramsToStringReplaced(list, importantOffsets, constantPool, version, exportMode, writer); } else { if (lastPush) { writer.newLine(); @@ -565,7 +566,7 @@ public class Action implements GraphSourceItem { } } } else { - a.getASMSourceReplaced(list, importantOffsets, constantPool, version, hex, writer); + a.getASMSourceReplaced(list, importantOffsets, constantPool, version, exportMode, writer); } writer.appendNoHilight(a.isIgnored() ? "; ignored" : ""); writer.appendNoHilight(add); @@ -584,7 +585,7 @@ public class Action implements GraphSourceItem { writer.newLine(); lastPush = false; } - writer.appendNoHilight(a.afterInsert.getASMSource(list, importantOffsets, constantPool, version, hex)); + writer.appendNoHilight(a.afterInsert.getASMSource(list, importantOffsets, constantPool, version, exportMode)); writer.newLine(); } } @@ -623,7 +624,7 @@ public class Action implements GraphSourceItem { * @param hex Add hexadecimal * @return String of P-code source */ - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { return toString(); } @@ -1231,7 +1232,7 @@ public class Action implements GraphSourceItem { String s = null; try { HilightedTextWriter writer = new HilightedTextWriter(false); - Action.actionsToString(new ArrayList(), address, ret, null, version, false, writer, swfPos, path); + Action.actionsToString(new ArrayList(), address, ret, null, version, ExportMode.PCODE, writer, swfPos, path); s = writer.toString(); ret = ASMParser.parse(address, swfPos, true, s, SWF.DEFAULT_VERSION, false); } catch (Exception ex) { @@ -1260,8 +1261,8 @@ public class Action implements GraphSourceItem { } } - public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex, HilightedTextWriter writer) { - writer.appendNoHilight(getASMSource(container, knownAddreses, constantPool, version, hex)); + public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode, HilightedTextWriter writer) { + writer.appendNoHilight(getASMSource(container, knownAddreses, constantPool, version, exportMode)); return writer; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java index f7f9afb3f..ddfed86a0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphSourceItemContainer; @@ -678,7 +679,7 @@ public class ActionListReader { } if (debugMode) { - String atos = a.getASMSource(new ArrayList(), new ArrayList(), cpool.constants, version, false); + String atos = a.getASMSource(new ArrayList(), new ArrayList(), cpool.constants, version, ExportMode.PCODE); if (a instanceof GraphSourceItemContainer) { atos = a.toString(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java b/trunk/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java index 2e13918d0..1db2c55e9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.action.special.ActionEnd; import com.jpexs.decompiler.flash.action.special.ActionStore; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import java.io.ByteArrayOutputStream; @@ -89,13 +90,13 @@ public class ActionWaitForFrame extends Action implements ActionStore { } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String ret = "WaitForFrame " + frame + " " + skipCount; for (int i = 0; i < skipped.size(); i++) { if (skipped.get(i) instanceof ActionEnd) { break; } - ret += "\r\n" + skipped.get(i).getASMSource(container, knownAddreses, constantPool, version, hex); + ret += "\r\n" + skipped.get(i).getASMSource(container, knownAddreses, constantPool, version, exportMode); } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java index 7921667d0..c25292474 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSource; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.helpers.Helper; @@ -82,7 +83,7 @@ public class ActionIf extends Action { } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String ofsStr = Helper.formatAddress(getAddress() + getBytes(version).length + offset); return "If loc" + ofsStr + (compileTime ? " ;compileTime" : ""); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java index 16a97a6b0..129a1ed91 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSource; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.helpers.Helper; @@ -81,7 +82,7 @@ public class ActionJump extends Action { } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String ofsStr = Helper.formatAddress(getAddress() + getBytes(version).length + offset); return "Jump loc" + ofsStr; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index be134f839..60a4191ca 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; @@ -227,7 +228,7 @@ public class ActionPush extends Action { } @Override - public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex, HilightedTextWriter writer) { + public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode, HilightedTextWriter writer) { if (replacement == null || replacement.size() < values.size()) { return toString(writer); } @@ -238,7 +239,7 @@ public class ActionPush extends Action { return writer; } - public HilightedTextWriter paramsToStringReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex, HilightedTextWriter writer) { + public HilightedTextWriter paramsToStringReplaced(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode, HilightedTextWriter writer) { if (replacement == null || replacement.size() < values.size()) { return paramsToString(writer); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java index 649b0b9a6..c67a2ecac 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.action.special.ActionEnd; import com.jpexs.decompiler.flash.action.special.ActionStore; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import java.io.ByteArrayOutputStream; @@ -116,13 +117,13 @@ public class ActionWaitForFrame2 extends Action implements ActionStore { } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String ret = "WaitForFrame2 " + skipCount; for (int i = 0; i < skipped.size(); i++) { if (skipped.get(i) instanceof ActionEnd) { break; } - ret += "\r\n" + skipped.get(i).getASMSource(container, knownAddreses, constantPool, version, hex); + ret += "\r\n" + skipped.get(i).getASMSource(container, knownAddreses, constantPool, version, exportMode); } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java index 4e11faca0..b6ddf3a1c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.action.model.FunctionActionItem; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphSourceItemContainer; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -155,7 +156,7 @@ public class ActionDefineFunction extends Action implements GraphSourceItemConta } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String paramStr = ""; for (int i = 0; i < paramNames.size(); i++) { paramStr += "\"" + Helper.escapeString(paramNames.get(i)) + "\""; @@ -166,7 +167,7 @@ public class ActionDefineFunction extends Action implements GraphSourceItemConta } @Override - public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex, HilightedTextWriter writer) { + public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode, HilightedTextWriter writer) { List oldParamNames = paramNames; if (replacedParamNames != null) { paramNames = replacedParamNames; @@ -175,7 +176,7 @@ public class ActionDefineFunction extends Action implements GraphSourceItemConta if (replacedFunctionName != null) { functionName = replacedFunctionName; } - String ret = getASMSource(container, knownAddreses, constantPool, version, hex); + String ret = getASMSource(container, knownAddreses, constantPool, version, exportMode); paramNames = oldParamNames; functionName = oldFunctionName; writer.appendNoHilight(ret); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java index 656ede840..74e48fa72 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.model.clauses.WithActionItem; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphSourceItemContainer; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -80,7 +81,7 @@ public class ActionWith extends Action implements GraphSourceItemContainer { } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { return "With {"; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java index 38285b6a9..b5aaee438 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.action.model.FunctionActionItem; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphSourceItemContainer; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -233,7 +234,7 @@ public class ActionDefineFunction2 extends Action implements GraphSourceItemCont } @Override - public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex, HilightedTextWriter writer) { + public HilightedTextWriter getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode, HilightedTextWriter writer) { List oldParamNames = paramNames; if (replacedParamNames != null) { paramNames = replacedParamNames; @@ -242,7 +243,7 @@ public class ActionDefineFunction2 extends Action implements GraphSourceItemCont if (replacedFunctionName != null) { functionName = replacedFunctionName; } - String ret = getASMSource(container, knownAddreses, constantPool, version, hex); + String ret = getASMSource(container, knownAddreses, constantPool, version, exportMode); paramNames = oldParamNames; functionName = oldFunctionName; writer.appendNoHilight(ret); @@ -251,7 +252,7 @@ public class ActionDefineFunction2 extends Action implements GraphSourceItemCont } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String paramStr = ""; for (int i = 0; i < paramNames.size(); i++) { paramStr += paramRegisters.get(i) + " \"" + Helper.escapeString(paramNames.get(i)) + "\""; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java b/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java index b35669f76..4747f2fbf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphSourceItemContainer; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -152,7 +153,7 @@ public class ActionTry extends Action implements GraphSourceItemContainer { } @Override - public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, ExportMode exportMode) { String ret = ""; ret += "Try "; if (catchBlockFlag) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java b/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java index 4b4e6ed08..575ba8275 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java @@ -26,7 +26,7 @@ public class ExportDialog extends AppDialog { {translate("images.pngjpeg")}, {translate("movies.flv")}, {translate("sounds.mp3wavflv"), translate("sounds.flv")}, - {translate("actionscript.as"), translate("actionscript.pcode")} + {translate("actionscript.as"), translate("actionscript.pcode"), translate("actionscript.pcodehex"), translate("actionscript.hex")} }; String[] optionNames = { translate("shapes"), diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index 40449b9f6..967478882 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import static com.jpexs.decompiler.flash.gui.AppStrings.translate; import com.jpexs.decompiler.flash.gui.player.FlashPlayerPanel; import com.jpexs.decompiler.flash.gui.proxy.ProxyFrame; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.Cache; import com.jpexs.helpers.Helper; import com.jpexs.helpers.ProgressListener; @@ -700,7 +701,7 @@ 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|binaryData|text|textplain|all) outdirectory infile [-selectas3class class1 class2 ...]"); + System.out.println(" 4) -export (as|pcode|pcodehex|hex|image|shape|movie|sound|binaryData|text|textplain|all|all_as|all_pcode|all_pcodehex|all_hex) 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, movies, binaryData, text with formatting, plain text or all."); 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"); @@ -1044,12 +1045,17 @@ public class Main { switch (exportFormat) { case "all": + case "all_as": + case "all_pcode": + case "all_pcodehex": + case "all_hex": + ExportMode allExportMode = strToExportFormat(exportFormat.substring(3)); System.out.println("Exporting images..."); exfile.exportImages(handler, outDir.getAbsolutePath() + File.separator + "images"); System.out.println("Exporting shapes..."); exfile.exportShapes(handler, outDir.getAbsolutePath() + File.separator + "shapes"); System.out.println("Exporting scripts..."); - exfile.exportActionScript(handler, outDir.getAbsolutePath() + File.separator + "scripts", false, Configuration.getConfig("parallelSpeedUp", true)); + exfile.exportActionScript(handler, outDir.getAbsolutePath() + File.separator + "scripts", allExportMode, Configuration.getConfig("parallelSpeedUp", true)); System.out.println("Exporting movies..."); exfile.exportMovies(handler, outDir.getAbsolutePath() + File.separator + "movies"); System.out.println("Exporting sounds..."); @@ -1070,13 +1076,16 @@ public class Main { break; case "as": case "pcode": + case "pcodehex": + case "hex": + ExportMode exportMode = strToExportFormat(exportFormat); 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"), Configuration.getConfig("parallelSpeedUp", true)); + exportOK = exportOK && exfile.exportAS3Class(args[i], outDir.getAbsolutePath(), exportMode, Configuration.getConfig("parallelSpeedUp", true)); } } else { - exportOK = !exfile.exportActionScript(handler, outDir.getAbsolutePath(), exportFormat.equals("pcode"), Configuration.getConfig("parallelSpeedUp", true)).isEmpty(); + exportOK = !exfile.exportActionScript(handler, outDir.getAbsolutePath(), exportMode, Configuration.getConfig("parallelSpeedUp", true)).isEmpty(); } break; case "movie": @@ -1175,6 +1184,18 @@ public class Main { } } + private static ExportMode strToExportFormat(String exportFormatStr) { + if (exportFormatStr.equals("pcode")) { + return ExportMode.PCODE; + } else if (exportFormatStr.equals("pcodehex")) { + return ExportMode.PCODEWITHHEX; + } else if (exportFormatStr.equals("hex")) { + return ExportMode.HEX; + } else { + return ExportMode.SOURCE; + } + } + private static void setConfigurations(String cfgStr) { String[] cfgs; if (cfgStr.contains(",")) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 642eace71..8a180763f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -97,6 +97,7 @@ import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.TEXTRECORD; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.Cache; import com.jpexs.helpers.Helper; import com.jpexs.process.ProcessTools; @@ -2112,10 +2113,10 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel private SearchDialog searchDialog; public List exportSelection(AbortRetryIgnoreHandler handler, String selFile, ExportDialog export) throws IOException { - final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1; + final ExportMode exportMode = ExportMode.get(export.getOption(ExportDialog.OPTION_ACTIONSCRIPT)); final boolean isMp3OrWav = export.getOption(ExportDialog.OPTION_SOUNDS) == 0; final boolean isFormatted = export.getOption(ExportDialog.OPTION_TEXTS) == 1; - + List ret = new ArrayList<>(); List sel = getAllSelected(tagTree); @@ -2175,7 +2176,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel for (int i = 0; i < tlsList.size(); i++) { ScriptPack tls = tlsList.get(i); Main.startWork(translate("work.exporting") + " " + (i + 1) + "/" + tlsList.size() + " " + tls.getPath() + " ..."); - ret.add(tls.export(selFile, abcList, isPcode, Configuration.getConfig("parallelSpeedUp", true))); + ret.add(tls.export(selFile, abcList, exportMode, Configuration.getConfig("parallelSpeedUp", true))); } } else { List allNodes = new ArrayList<>(); @@ -2184,7 +2185,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel allNodes.add(asn); TagNode.setExport(allNodes, false); TagNode.setExport(actionNodes, true); - ret.addAll(TagNode.exportNodeAS(swf.tags, handler, allNodes, selFile, isPcode)); + ret.addAll(TagNode.exportNodeAS(swf.tags, handler, allNodes, selFile, exportMode)); } } return ret; @@ -2718,7 +2719,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel Main.startWork(translate("work.exporting") + "..."); final String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath(); Configuration.setConfig("lastExportDir", Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath()); - final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1; + final ExportMode exportMode = ExportMode.get(export.getOption(ExportDialog.OPTION_ACTIONSCRIPT)); final boolean isMp3OrWav = export.getOption(ExportDialog.OPTION_SOUNDS) == 0; final boolean isFormatted = export.getOption(ExportDialog.OPTION_TEXTS) == 1; final boolean onlySel = e.getActionCommand().endsWith("SEL"); @@ -2735,7 +2736,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel swf.exportMovies(errorHandler, selFile + File.separator + "movies"); swf.exportSounds(errorHandler, selFile + File.separator + "sounds", isMp3OrWav, isMp3OrWav); swf.exportBinaryData(errorHandler, selFile + File.separator + "binaryData"); - swf.exportActionScript(errorHandler, selFile, isPcode, Configuration.getConfig("parallelSpeedUp", true)); + swf.exportActionScript(errorHandler, selFile, exportMode, Configuration.getConfig("parallelSpeedUp", true)); } } catch (Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Error during export", ex); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 868165eb3..75fd4f3db 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.gui.GraphFrame; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; import java.io.ByteArrayInputStream; @@ -135,7 +136,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi return; } HilightedTextWriter writer = new HilightedTextWriter(true); - abc.bodies[bodyIndex].code.toASMSource(abc.constants, trait, abc.method_info[abc.bodies[bodyIndex].method_info], abc.bodies[bodyIndex], true, writer); + abc.bodies[bodyIndex].code.toASMSource(abc.constants, trait, abc.method_info[abc.bodies[bodyIndex].method_info], abc.bodies[bodyIndex], ExportMode.PCODEWITHHEX, writer); String textWithHexTags = writer.toString(); textWithHex = Helper.hexToComments(textWithHexTags); textNoHex = Helper.stripComments(textWithHexTags); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 4e11e3cd7..eca1db268 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.Graph; import com.jpexs.helpers.Cache; import java.util.ArrayList; @@ -453,7 +454,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL if (!cache.contains(scriptLeaf)) { HilightedTextWriter writer = new HilightedTextWriter(true); for (int scriptTraitIndex : scriptLeaf.traitIndices) { - script.traits.traits[scriptTraitIndex].convertPackaged(null, scriptLeaf.getPath().toString(), abcList, abc, false, false, scriptIndex, -1, writer, new ArrayList(), Configuration.getConfig("parallelSpeedUp", true)); + script.traits.traits[scriptTraitIndex].convertPackaged(null, scriptLeaf.getPath().toString(), abcList, abc, false, ExportMode.SOURCE, scriptIndex, -1, writer, new ArrayList(), Configuration.getConfig("parallelSpeedUp", true)); } String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); hilightedCode = s; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java index 3859fa0ef..35bd53122 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/TraitsListItem.java @@ -7,6 +7,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import com.jpexs.decompiler.graph.ExportMode; import java.util.ArrayList; import java.util.List; @@ -68,11 +69,11 @@ public class TraitsListItem { String s = ""; if ((type != Type.INITIALIZER) && isStatic) { HilightedTextWriter writer = new HilightedTextWriter(false); - abc.class_info[classIndex].static_traits.traits[index].convertHeader(null, "", abcTags, abc, true, false, scriptIndex, classIndex, writer, new ArrayList(), false); + abc.class_info[classIndex].static_traits.traits[index].convertHeader(null, "", abcTags, abc, true, ExportMode.SOURCE, scriptIndex, classIndex, writer, new ArrayList(), false); s = writer.toString(); } else if ((type != Type.INITIALIZER) && (!isStatic)) { HilightedTextWriter writer = new HilightedTextWriter(false); - abc.instance_info[classIndex].instance_traits.traits[index].convertHeader(null, "", abcTags, abc, false, false, scriptIndex, classIndex, writer, new ArrayList(), false); + abc.instance_info[classIndex].instance_traits.traits[index].convertHeader(null, "", abcTags, abc, false, ExportMode.SOURCE, scriptIndex, classIndex, writer, new ArrayList(), false); s = writer.toString(); } else if (!isStatic) { s = STR_INSTANCE_INITIALIZER; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 2cffab351..7e88828fe 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -38,6 +38,7 @@ import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Cache; import com.jpexs.helpers.Helper; @@ -278,7 +279,7 @@ public class ActionPanel extends JPanel implements ActionListener { setText(hex ? srcWithHex : (hexOnly ? srcHexOnly : srcNoHex)); } - public void setSource(ASMSource src, final boolean useCache) { + public void setSource(final ASMSource src, final boolean useCache) { this.src = src; Main.startWork(translate("work.decompiling") + "..."); final ASMSource asm = (ASMSource) src; @@ -310,12 +311,12 @@ public class ActionPanel extends JPanel implements ActionListener { List actions = asm.getActions(SWF.DEFAULT_VERSION); lastCode = actions; HilightedTextWriter writer = new HilightedTextWriter(true); - asm.getASMSource(SWF.DEFAULT_VERSION, true, writer, actions); + asm.getASMSource(SWF.DEFAULT_VERSION, ExportMode.PCODEWITHHEX, writer, actions); lastDisasm = writer.toString(); asm.removeDisassemblyListener(listener); srcWithHex = Helper.hexToComments(lastDisasm); srcNoHex = Helper.stripComments(lastDisasm); - srcHexOnly = getHexText(srcWithHex); + srcHexOnly = Helper.byteArrToString(src.getActionBytes()); setHex(hexButton.isSelected(), hexOnlyButton.isSelected()); if (Configuration.getConfig("decompile", true)) { decompiledEditor.setText("//" + translate("work.decompiling") + "..."); @@ -717,33 +718,6 @@ public class ActionPanel extends JPanel implements ActionListener { return data; } - private String getHexText(String srcWithHex) { - StringBuilder result = new StringBuilder(); - String nl = System.getProperty("line.separator"); - result.append("#hexdata").append(nl); - - /* // hex data from decompiled actions - Scanner scanner = new Scanner(srcWithHex); - while (scanner.hasNextLine()) { - String line = scanner.nextLine().trim(); - if (line.startsWith(";")) { - result.append(line.substring(1).trim()).append(nl); - } else { - result.append(";").append(line).append(nl); - } - }*/ - - byte[] data = src.getActionBytes(); - for (int i = 0; i < data.length; i++) { - if (i % 8 == 0) { - result.append(nl); - } - result.append(String.format("%02x ", data[i])); - } - - return result.toString(); - } - public void updateSearchPos() { searchPos.setText((foundPos + 1) + "/" + found.size()); setSource(found.get(foundPos), true); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties index 6a2d59f1c..4e4017d4b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties @@ -32,6 +32,8 @@ sounds.flv = FLV (Audio only) actionscript = ActionScript actionscript.as = ActionScript actionscript.pcode = P-code +actionscript.pcodehex = P-code with Hex +actionscript.hex = Hex dialog.title = Export... diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog_hu.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog_hu.properties index b3939386d..6a20546bc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog_hu.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog_hu.properties @@ -30,8 +30,10 @@ sounds.mp3wavflv = MP3/WAV/FLV sounds.flv = FLV (Csak hang) actionscript = ActionScript -actionscript.as = AS -actionscript.pcode = PCODE +actionscript.as = ActionScript +actionscript.pcode = P-code +actionscript.pcodehex = P-code \u00e9s Hexa +actionscript.hex = Hexa dialog.title = Export\u00e1l\u00e1s... diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index cee35d794..21c2cb112 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -33,7 +33,9 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.types.BUTTONRECORD; import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RECT; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.Cache; +import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReReadableInputStream; import java.awt.Color; import java.awt.Point; @@ -137,11 +139,11 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT * @return ASM source */ @Override - public HilightedTextWriter getASMSource(int version, boolean hex, HilightedTextWriter writer, List actions) { + public HilightedTextWriter getASMSource(int version, ExportMode exportMode, HilightedTextWriter writer, List actions) { if (actions == null) { actions = getActions(version); } - return Action.actionsToString(listeners, 0, actions, null, version, hex, writer, getPos() + hdrSize, toString()/*FIXME?*/); + return Action.actionsToString(listeners, 0, actions, null, version, exportMode, writer, getPos() + hdrSize, toString()/*FIXME?*/); } /** @@ -197,6 +199,11 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT this.actionBytes = actionBytes; } + @Override + public HilightedTextWriter getActionBytesAsHex(HilightedTextWriter writer) { + return Helper.byteArrayToHex(writer, actionBytes); + } + @Override public Set getNeededCharacters() { HashSet needed = new HashSet<>(); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index fcd330631..f7961cb12 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -23,6 +23,8 @@ import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionListReader; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; +import com.jpexs.decompiler.graph.ExportMode; +import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReReadableInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -75,11 +77,11 @@ public class DoActionTag extends Tag implements ASMSource { * @return ASM source */ @Override - public HilightedTextWriter getASMSource(int version, boolean hex, HilightedTextWriter writer, List actions) { + public HilightedTextWriter getASMSource(int version, ExportMode exportMode, HilightedTextWriter writer, List actions) { if (actions == null) { actions = getActions(version); } - return Action.actionsToString(listeners, 0, actions, null, version, hex, writer, getPos(), toString()/*FIXME?*/); + return Action.actionsToString(listeners, 0, actions, null, version, exportMode, writer, getPos(), toString()/*FIXME?*/); } /** @@ -140,6 +142,12 @@ public class DoActionTag extends Tag implements ASMSource { public void setActionBytes(byte[] actionBytes) { this.actionBytes = actionBytes; } + + @Override + public HilightedTextWriter getActionBytesAsHex(HilightedTextWriter writer) { + return Helper.byteArrayToHex(writer, actionBytes); + } + List listeners = new ArrayList<>(); @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 1d11a97db..caa2460cc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.action.ActionListReader; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReReadableInputStream; import java.io.ByteArrayInputStream; @@ -102,11 +103,11 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { * @return ASM source */ @Override - public HilightedTextWriter getASMSource(int version, boolean hex, HilightedTextWriter writer, List actions) { + public HilightedTextWriter getASMSource(int version, ExportMode exportMode, HilightedTextWriter writer, List actions) { if (actions == null) { actions = getActions(version); } - return Action.actionsToString(listeners, 0, actions, null, version, hex, writer, getPos() + 2, toString()/*FIXME?*/); + return Action.actionsToString(listeners, 0, actions, null, version, exportMode, writer, getPos() + 2, toString()/*FIXME?*/); } @Override @@ -151,6 +152,11 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { this.actionBytes = actionBytes; } + @Override + public HilightedTextWriter getActionBytesAsHex(HilightedTextWriter writer) { + return Helper.byteArrayToHex(writer, actionBytes); + } + @Override public int getCharacterId() { return spriteId; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java index 2c0f1f383..ca71b40cf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.DisassemblyListener; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.ExportMode; import java.util.List; /** @@ -35,7 +36,7 @@ public interface ASMSource { * @param hex Add hexadecimal? * @return ASM source */ - public HilightedTextWriter getASMSource(int version, boolean hex, HilightedTextWriter writer, List actions); + public HilightedTextWriter getASMSource(int version, ExportMode exportMode, HilightedTextWriter writer, List actions); /** * Whether or not this object contains ASM source @@ -64,6 +65,8 @@ public interface ASMSource { public void setActionBytes(byte[] actionBytes); + public HilightedTextWriter getActionBytesAsHex(HilightedTextWriter writer); + public long getPos(); public void addDisassemblyListener(DisassemblyListener listener); diff --git a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index 7330968de..a5dbf8ee7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.ContainerItem; import com.jpexs.decompiler.flash.tags.base.Exportable; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReReadableInputStream; import java.io.ByteArrayInputStream; @@ -148,11 +149,11 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem { * @return ASM source */ @Override - public HilightedTextWriter getASMSource(int version, boolean hex, HilightedTextWriter writer, List actions) { + public HilightedTextWriter getASMSource(int version, ExportMode exportMode, HilightedTextWriter writer, List actions) { if (actions == null) { actions = getActions(version); } - return Action.actionsToString(listeners, 0, actions, null, version, hex, writer, getPos() + 4, toString()/*FIXME?*/); + return Action.actionsToString(listeners, 0, actions, null, version, exportMode, writer, getPos() + 4, toString()/*FIXME?*/); } /** @@ -197,6 +198,12 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem { public void setActionBytes(byte[] actionBytes) { this.actionBytes = actionBytes; } + + @Override + public HilightedTextWriter getActionBytesAsHex(HilightedTextWriter writer) { + return Helper.byteArrayToHex(writer, actionBytes); + } + List listeners = new ArrayList<>(); @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 17bf27099..e4de6a0e3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java @@ -25,6 +25,8 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.ContainerItem; import com.jpexs.decompiler.flash.tags.base.Exportable; +import com.jpexs.decompiler.graph.ExportMode; +import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReReadableInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -152,11 +154,11 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem { * @return ASM source */ @Override - public HilightedTextWriter getASMSource(int version, boolean hex, HilightedTextWriter writer, List actions) { + public HilightedTextWriter getASMSource(int version, ExportMode exportMode, HilightedTextWriter writer, List actions) { if (actions == null) { actions = getActions(version); } - return Action.actionsToString(listeners, 0, actions, null, version, hex, writer, getPos() + hdrPos, toString()/*FIXME?*/); + return Action.actionsToString(listeners, 0, actions, null, version, exportMode, writer, getPos() + hdrPos, toString()/*FIXME?*/); } /** @@ -194,6 +196,12 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem { public void setActionBytes(byte[] actionBytes) { this.actionBytes = actionBytes; } + + @Override + public HilightedTextWriter getActionBytesAsHex(HilightedTextWriter writer) { + return Helper.byteArrayToHex(writer, actionBytes); + } + List listeners = new ArrayList<>(); @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index cca20bb78..c4cf1fcf7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -89,6 +89,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import com.jpexs.decompiler.flash.types.sound.MP3FRAME; +import com.jpexs.decompiler.graph.ExportMode; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.Point; @@ -2875,7 +2876,7 @@ public class XFLConverter { } if (useAS3) { try { - swf.exportActionScript(handler, outDir.getAbsolutePath(), false, parallel); + swf.exportActionScript(handler, outDir.getAbsolutePath(), ExportMode.SOURCE, parallel); } catch (Exception ex) { Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, "Error during ActionScript3 export", ex); } diff --git a/trunk/src/com/jpexs/decompiler/graph/ExportMode.java b/trunk/src/com/jpexs/decompiler/graph/ExportMode.java new file mode 100644 index 000000000..1c8850156 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/graph/ExportMode.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.graph; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author JPEXS + */ +public enum ExportMode { + + // The order (or values) shoud be the same as in ExportDialog + SOURCE(0), PCODE(1), PCODEWITHHEX(2), HEX(3); + + private static final Map lookup = new HashMap<>(); + + static { + for(ExportMode s : EnumSet.allOf(ExportMode.class)) + lookup.put(s.getCode(), s); + } + + private int code; + + private ExportMode(int code) { + this.code = code; + } + + public int getCode() { return code; } + + public static ExportMode get(int code) { + return lookup.get(code); + } +} diff --git a/trunk/src/com/jpexs/helpers/Helper.java b/trunk/src/com/jpexs/helpers/Helper.java index 1e15d53fb..8d8549eb3 100644 --- a/trunk/src/com/jpexs/helpers/Helper.java +++ b/trunk/src/com/jpexs/helpers/Helper.java @@ -17,6 +17,7 @@ package com.jpexs.helpers; import com.jpexs.decompiler.flash.gui.Freed; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.LocalData; import java.awt.Component; @@ -548,6 +549,37 @@ public class Helper { return timeStr; } + public static HilightedTextWriter byteArrayToHex(HilightedTextWriter writer, byte[] data) { + writer.appendNoHilight("#hexdata").newLine(); + + /* // hex data from decompiled actions + Scanner scanner = new Scanner(srcWithHex); + while (scanner.hasNextLine()) { + String line = scanner.nextLine().trim(); + if (line.startsWith(";")) { + result.append(line.substring(1).trim()).append(nl); + } else { + result.append(";").append(line).append(nl); + } + }*/ + + for (int i = 0; i < data.length; i++) { + if (i % 8 == 0) { + writer.newLine(); + } + writer.appendNoHilight(String.format("%02x ", data[i])); + } + + writer.newLine(); + return writer; + } + + public static String byteArrayToHex(byte[] data) { + HilightedTextWriter writer = new HilightedTextWriter(false); + byteArrayToHex(writer, data); + return writer.toString(); + } + public static T timedCall(Callable c, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { FutureTask task = new FutureTask<>(c); THREAD_POOL.execute(task); diff --git a/trunk/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java b/trunk/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java index 2a24a2730..eb7cde301 100644 --- a/trunk/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java +++ b/trunk/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java @@ -5,6 +5,7 @@ import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.DoActionTag; +import com.jpexs.decompiler.graph.ExportMode; import java.io.FileInputStream; import java.io.IOException; import java.util.List; @@ -41,7 +42,7 @@ public class ActionScript2AssemblerTest extends ActionStript2TestBase { doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); String actualResult = Action.actionsToSource(doa.getActions(swf.version), swf.version, "", false, 0); HilightedTextWriter writer = new HilightedTextWriter(false); - doa.getASMSource(swf.version, false, writer, null); + doa.getASMSource(swf.version, ExportMode.PCODE, writer, null); String decompiled = writer.toString(); assertEquals(actualResult.trim(), "ok = false;"); diff --git a/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java b/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java index 3484d99d2..5ad1fb466 100644 --- a/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java +++ b/trunk/test/com/jpexs/decompiler/flash/ActionScript3Test.java @@ -4,6 +4,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.DoABCDefineTag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import java.io.FileInputStream; import java.io.IOException; @@ -43,7 +44,7 @@ public class ActionScript3Test { private void decompileMethod(String methodName, String expectedResult, boolean isStatic) { int bodyIndex = abc.findMethodBodyByName(clsIndex, methodName); assertTrue(bodyIndex > -1); - String actualResult = abc.bodies[bodyIndex].toString(methodName, false, isStatic, -1/*FIX?*/, clsIndex, abc,null, abc.constants, abc.method_info, new Stack(), false, new ArrayList(), abc.instance_info[clsIndex].instance_traits); + String actualResult = abc.bodies[bodyIndex].toString(methodName, ExportMode.SOURCE, isStatic, -1/*FIX?*/, clsIndex, abc,null, abc.constants, abc.method_info, new Stack(), false, new ArrayList(), abc.instance_info[clsIndex].instance_traits); actualResult = actualResult.replaceAll("[ \r\n]", ""); expectedResult = expectedResult.replaceAll("[ \r\n]", ""); assertEquals(actualResult, expectedResult); diff --git a/trunk/test/com/jpexs/decompiler/flash/ExportTest.java b/trunk/test/com/jpexs/decompiler/flash/ExportTest.java index 97f2a3389..16e02761e 100644 --- a/trunk/test/com/jpexs/decompiler/flash/ExportTest.java +++ b/trunk/test/com/jpexs/decompiler/flash/ExportTest.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash; +import com.jpexs.decompiler.graph.ExportMode; import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; @@ -79,19 +80,19 @@ public class ExportTest { @Test(dataProvider = "swfFiles") public void testDecompileAS(File f) { - testDecompile(f, false); + testDecompile(f, ExportMode.SOURCE); } @Test(dataProvider = "swfFiles") public void testDecompilePcode(File f) { - testDecompile(f, true); + testDecompile(f, ExportMode.PCODE); } - public void testDecompile(File f, boolean isPcode) { + public void testDecompile(File f, ExportMode exportMode) { try { SWF swf = new SWF(new FileInputStream(f), false); Configuration.DEBUG_COPY = true; - String folderName = isPcode ? "outputp" : "output"; + String folderName = exportMode == ExportMode.SOURCE ? "output" : "outputp"; File fdir = new File(TESTDATADIR + File.separator + folderName + File.separator + f.getName()); fdir.mkdirs(); @@ -106,7 +107,7 @@ public class ExportTest { return this; } - }, fdir.getAbsolutePath(), isPcode, false); + }, fdir.getAbsolutePath(), exportMode, false); } catch (Exception ex) { fail(); } diff --git a/trunk/test/com/jpexs/decompiler/flash/generators/AS3Generator.java b/trunk/test/com/jpexs/decompiler/flash/generators/AS3Generator.java index 3b2b41f02..424e6e169 100644 --- a/trunk/test/com/jpexs/decompiler/flash/generators/AS3Generator.java +++ b/trunk/test/com/jpexs/decompiler/flash/generators/AS3Generator.java @@ -8,6 +8,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; import com.jpexs.decompiler.flash.tags.DoABCDefineTag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.decompiler.graph.GraphTargetItem; import java.io.FileInputStream; import java.io.PrintWriter; @@ -44,7 +45,7 @@ public class AS3Generator { s.append("(){\r\ndecompileMethod(\""); s.append(name); s.append("\", "); - String src = abc.findBody(((TraitMethodGetterSetter) t).method_info).toString("", false, false, -1/*FIX?*/, classId, abc, null,abc.constants, abc.method_info, new Stack(), false, new ArrayList(), abc.instance_info[classId].instance_traits); + String src = abc.findBody(((TraitMethodGetterSetter) t).method_info).toString("", ExportMode.SOURCE, false, -1/*FIX?*/, classId, abc, null,abc.constants, abc.method_info, new Stack(), false, new ArrayList(), abc.instance_info[classId].instance_traits); String[] srcs = src.split("[\r\n]+"); for (int i = 0; i < srcs.length; i++) { String ss = srcs[i];