diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index c834e21d8..bc344c736 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash; import SevenZip.Compression.LZMA.Decoder; @@ -128,6 +129,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.RGBA; +import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.filters.BEVELFILTER; import com.jpexs.decompiler.flash.types.filters.BlendComposite; import com.jpexs.decompiler.flash.types.filters.COLORMATRIXFILTER; @@ -250,46 +252,98 @@ public final class SWF implements SWFContainerItem, Timelined { * LZMA Properties */ public byte[] lzmaProperties; + @Internal public byte[] uncompressedData; + @Internal public byte[] originalUncompressedData; - public FileAttributesTag fileAttributes; /** * ScaleForm GFx */ public boolean gfx = false; + @Internal public SWFList swfList; + @Internal public String file; + @Internal public String fileTitle; - public boolean readOnly; - public boolean isAS3; - public Map characters = new HashMap<>(); - public List abcList; + @Internal + private Map characters; + @Internal + private List abcList; + @Internal private JPEGTablesTag jtt; + @Internal public Map sourceFontNamesMap = new HashMap<>(); public static final double unitDivisor = 20; private static final Logger logger = Logger.getLogger(SWF.class.getName()); + @Internal private Timeline timeline; + @Internal public DumpInfoSwfNode dumpInfo; + @Internal public DefineBinaryDataTag binaryData; + @Internal private final HashMap deobfuscated = new HashMap<>(); + @Internal private final IdentifiersDeobfuscation deobfuscation = new IdentifiersDeobfuscation(); + @Internal private static Cache frameCache = Cache.getInstance(false, "frame"); + @Internal private final Cache as2Cache = Cache.getInstance(true, "as2"); + @Internal private final Cache as3Cache = Cache.getInstance(true, "as3"); public void updateCharacters() { - characters.clear(); - parseCharacters(tags); + characters = null; + } + + public Map getCharacters() { + if (characters == null) { + Map chars = new HashMap<>(); + parseCharacters(tags, chars); + characters = chars; + } + + return characters; + } + + public CharacterTag getCharacter(int characterId) { + return getCharacters().get(characterId); + } + + public List getAbcList() { + if (abcList == null) { + ArrayList newAbcList = new ArrayList<>(); + getAbcTags(tags, newAbcList); + abcList = newAbcList; + } + + return abcList; + } + + public boolean isAS3() { + FileAttributesTag fileAttributes = getFileAttributes(); + return (fileAttributes != null && fileAttributes.actionScript3) || (fileAttributes == null && !getAbcList().isEmpty()); + } + + public FileAttributesTag getFileAttributes() { + for (Tag t : tags) { + if (t instanceof FileAttributesTag) { + return (FileAttributesTag) t; + } + } + + return null; } public int getNextCharacterId() { int max = -1; - for (int characterId : characters.keySet()) { + for (int characterId : getCharacters().keySet()) { if (characterId > max) { max = characterId; } @@ -326,7 +380,7 @@ public final class SWF implements SWFContainerItem, Timelined { boolean moved = false; for (Integer id : needed) { if (!addedCharacterIds.contains(id)) { - CharacterTag neededCharacter = characters.get(id); + CharacterTag neededCharacter = getCharacter(id); if (neededCharacter == null) { continue; } @@ -364,13 +418,13 @@ public final class SWF implements SWFContainerItem, Timelined { } } - private void parseCharacters(List list) { + private void parseCharacters(List list, Map characters) { for (Tag t : list) { if (t instanceof CharacterTag) { characters.put(((CharacterTag) t).getCharacterId(), (CharacterTag) t); } if (t instanceof DefineSpriteTag) { - parseCharacters(((DefineSpriteTag) t).getSubTags()); + parseCharacters(((DefineSpriteTag) t).getSubTags(), characters); } } } @@ -573,6 +627,10 @@ public final class SWF implements SWFContainerItem, Timelined { } } + public SWF() { + + } + public SWF(InputStream is, boolean parallelRead) throws IOException, InterruptedException { this(is, null, parallelRead, false); } @@ -643,11 +701,8 @@ public final class SWF implements SWFContainerItem, Timelined { this.tags = tags; if (!checkOnly) { checkInvalidSprites(); - updateCharacters(); assignExportNamesToSymbols(); assignClassesToSymbols(); - findFileAttributes(); - findABCTags(); SWFDecompilerPlugin.fireSwfParsed(this); } else { @@ -695,18 +750,10 @@ public final class SWF implements SWFContainerItem, Timelined { return new File(title).getName(); } - private void findABCTags() { - - ArrayList newAbcList = new ArrayList<>(); - getABCTags(tags, newAbcList); - isAS3 = (fileAttributes != null && fileAttributes.actionScript3) || (fileAttributes == null && !newAbcList.isEmpty()); - abcList = newAbcList; - } - - private static void getABCTags(List list, List actionScripts) { + private static void getAbcTags(List list, List actionScripts) { for (Tag t : list) { if (t instanceof DefineSpriteTag) { - getABCTags(((DefineSpriteTag) t).getSubTags(), actionScripts); + getAbcTags(((DefineSpriteTag) t).getSubTags(), actionScripts); } if (t instanceof ABCContainerTag) { actionScripts.add((ABCContainerTag) t); @@ -714,15 +761,6 @@ public final class SWF implements SWFContainerItem, Timelined { } } - private void findFileAttributes() { - for (Tag t : tags) { - if (t instanceof FileAttributesTag) { - fileAttributes = (FileAttributesTag) t; - break; - } - } - } - public void assignExportNamesToSymbols() { HashMap exportNames = new HashMap<>(); for (Tag t : tags) { @@ -905,6 +943,7 @@ public final class SWF implements SWFContainerItem, Timelined { public boolean exportAS3Class(String className, String outdir, ScriptExportMode exportMode, boolean parallel) throws Exception { boolean exported = false; + List abcList = getAbcList(); for (int i = 0; i < abcList.size(); i++) { ABC abc = abcList.get(i).getABC(); List scrs = abc.findScriptPacksByPath(className); @@ -941,7 +980,7 @@ public final class SWF implements SWFContainerItem, Timelined { public List> getAS3Packs() { List> packs = new ArrayList<>(); - for (ABCContainerTag abcTag : abcList) { + for (ABCContainerTag abcTag : getAbcList()) { packs.addAll(abcTag.getABC().getScriptPacks()); } return uniqueAS3Packs(packs); @@ -1025,7 +1064,7 @@ public final class SWF implements SWFContainerItem, Timelined { @Override public Void call() throws Exception { for (MyEntry item : packs) { - ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, abcList, exportMode, parallel); + ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, getAbcList(), exportMode, parallel); ret.add(task.call()); } return null; @@ -1040,7 +1079,7 @@ public final class SWF implements SWFContainerItem, Timelined { ExecutorService executor = Executors.newFixedThreadPool(Configuration.parallelThreadCount.get()); List> futureResults = new ArrayList<>(); for (MyEntry item : packs) { - Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, abcList, exportMode, parallel)); + Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, getAbcList(), exportMode, parallel)); futureResults.add(future); } @@ -1080,7 +1119,7 @@ public final class SWF implements SWFContainerItem, Timelined { } }; - if (isAS3) { + if (isAS3()) { ret.addAll(exportActionScript3(handler, outdir, exportMode, parallel)); } else { ret.addAll(exportActionScript2(handler, outdir, exportMode, parallel, evl)); @@ -1286,7 +1325,7 @@ public final class SWF implements SWFContainerItem, Timelined { public static void writeLibrary(SWF fswf, Set library, OutputStream fos) throws IOException { for (int c : library) { - CharacterTag ch = fswf.characters.get(c); + CharacterTag ch = fswf.getCharacter(c); if (ch instanceof FontTag) { fos.write(Utf8Helper.getBytes("function " + getTypePrefix(ch) + c + "(ctx,ch,textColor){\r\n")); fos.write(Utf8Helper.getBytes(((FontTag) ch).toHtmlCanvas(1))); @@ -1327,8 +1366,8 @@ public final class SWF implements SWFContainerItem, Timelined { if (containerId == 0) { tim = getTimeline(); } else { - tim = ((Timelined) characters.get(containerId)).getTimeline(); - path = File.separator + Helper.makeFileName(characters.get(containerId).getExportFileName()); + tim = ((Timelined) getCharacter(containerId)).getTimeline(); + path = File.separator + Helper.makeFileName(getCharacter(containerId).getExportFileName()); } if (frames == null) { int frameCnt = tim.getFrames().size(); @@ -1411,7 +1450,7 @@ public final class SWF implements SWFContainerItem, Timelined { writeLibrary(fswf, library, fos); - String currentName = ftim.id == 0 ? "main" : getTypePrefix(fswf.characters.get(ftim.id)) + ftim.id; + String currentName = ftim.id == 0 ? "main" : getTypePrefix(fswf.getCharacter(ftim.id)) + ftim.id; fos.write(Utf8Helper.getBytes("function " + currentName + "(ctx,ctrans,frame,ratio,time){\r\n")); fos.write(Utf8Helper.getBytes("\tctx.save();\r\n")); @@ -1856,7 +1895,7 @@ public final class SWF implements SWFContainerItem, Timelined { } public int deobfuscateIdentifiers(RenameType renameType) throws InterruptedException { - findFileAttributes(); + FileAttributesTag fileAttributes = getFileAttributes(); if (fileAttributes == null) { int cnt = 0; cnt += deobfuscateAS2Identifiers(renameType); @@ -2217,7 +2256,7 @@ public final class SWF implements SWFContainerItem, Timelined { } boolean parallel = Configuration.parallelSpeedUp.get(); HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); - pack.toSource(writer, swf.abcList, script.traits.traits, ScriptExportMode.AS, parallel); + pack.toSource(writer, swf.getAbcList(), script.traits.traits, ScriptExportMode.AS, parallel); HighlightedText hilightedCode = new HighlightedText(writer); CachedDecompilation res = new CachedDecompilation(hilightedCode); swf.as3Cache.put(pack, res); @@ -2298,13 +2337,13 @@ public final class SWF implements SWFContainerItem, Timelined { continue; } DepthState layer = frameObj.layers.get(i); - if (!timeline.swf.characters.containsKey(layer.characterId)) { + if (!timeline.swf.getCharacters().containsKey(layer.characterId)) { continue; } if (!layer.isVisible) { continue; } - CharacterTag character = timeline.swf.characters.get(layer.characterId); + CharacterTag character = timeline.swf.getCharacter(layer.characterId); if (colorTransform == null) { colorTransform = new ColorTransform(); @@ -2512,13 +2551,13 @@ public final class SWF implements SWFContainerItem, Timelined { continue; } DepthState layer = frameObj.layers.get(i); - if (!timeline.swf.characters.containsKey(layer.characterId)) { + if (!timeline.swf.getCharacters().containsKey(layer.characterId)) { continue; } if (!layer.isVisible) { continue; } - CharacterTag character = timeline.swf.characters.get(layer.characterId); + CharacterTag character = timeline.swf.getCharacter(layer.characterId); if (colorTransform == null) { colorTransform = new ColorTransform(); @@ -2657,13 +2696,13 @@ public final class SWF implements SWFContainerItem, Timelined { continue; } DepthState layer = frameObj.layers.get(i); - if (!timeline.swf.characters.containsKey(layer.characterId)) { + if (!timeline.swf.getCharacters().containsKey(layer.characterId)) { continue; } if (!layer.isVisible) { continue; } - CharacterTag character = timeline.swf.characters.get(layer.characterId); + CharacterTag character = timeline.swf.getCharacter(layer.characterId); Matrix mat = new Matrix(layer.matrix); mat = mat.preConcatenate(transformation); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 6f8cd15e1..53e01de8f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.parser.script; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java index 7e3c077e4..ccd9c34b8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.parser.script; import com.jpexs.decompiler.flash.SWC; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index be355afc7..db8f2b967 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 119ace081..5b3cba91f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/IndenetedStringBuilder.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/IndenetedStringBuilder.java new file mode 100644 index 000000000..5f42bf00f --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/IndenetedStringBuilder.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.exporters.swf; + +import com.jpexs.helpers.Helper; + +/** + * + * @author JPEXS + */ +public class IndenetedStringBuilder { + + private final StringBuilder builder = new StringBuilder(); + private final String indentString; + private int indent; + + public IndenetedStringBuilder(String indentString) { + super(); + this.indentString = indentString; + } + + public void indent() { + indent++; + } + + public void unindent() { + indent--; + } + + public void appendLine(String str) { + for (int i = 0; i < indent; i++) { + builder.append(indentString); + } + + builder.append(str); + builder.append(Helper.newLine); + } + + @Override + public String toString() { + return builder.toString(); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfFile.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfFile.java new file mode 100644 index 000000000..3cec483f2 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfFile.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.exporters.swf; + +import com.jpexs.decompiler.flash.SWF; +import java.io.IOException; + +/** + * + * @author JPEXS + */ +public class SwfFile { + + public SWF getSwf() { + return null; + } + + public void saveTo(String fileName) throws IOException { + /*SWF swf = getSwf(); + try (FileOutputStream fos = new FileOutputStream(fileName)) { + swf.saveTo(fos, SWFCompression.ZLIB); + }*/ + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java new file mode 100644 index 000000000..bc9cd3dae --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.exporters.swf; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.helpers.CodeFormatting; +import com.jpexs.decompiler.flash.helpers.FileTextWriter; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.helpers.LazyObject; +import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.Helper; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author JPEXS + */ +public class SwfJavaExporter { + + private static final String javaIndentString = " "; + + private static final String[] allowedSubTypes = new String[] { "List", "String", "ByteArrayRange", "RECT", "MATRIX", "CXFORMWITHALPHA", + "CXFORM", "CLIPEVENTFLAGS", "CLIPACTIONRECORD", "CLIPACTIONS", "COLORMATRIXFILTER", "RGBA", "ARGB", "RGB", + "CONVOLUTIONFILTER", "BLURFILTER", "DROPSHADOWFILTER", "GLOWFILTER", "BEVELFILTER", "GRADIENTGLOWFILTER", "GRADIENTBEVELFILTER", + "FILTERLIST", "FILTER", "BUTTONRECORD", "BUTTONCONDACTION", "GRADRECORD", "GRADIENT", "FOCALGRADIENT", "FILLSTYLE", + "FILLSTYLEARRAY", "LINESTYLE", "LINESTYLE2", "LINESTYLEARRAY", "SHAPERECORD", "SHAPE", "SHAPEWITHSTYLE", "SHAPERECORDS", + "SOUNDINFO", "SOUNDENVELOPE", "GLYPHENTRY", "TEXTRECORD", "MORPHGRADRECORD", "MORPHGRADIENT", "MORPHFOCALGRADIENT", + "MORPHFILLSTYLE", "MORPHFILLSTYLEARRAY", "MORPHLINESTYLE", "MORPHLINESTYLE2", "MORPHLINESTYLEARRAY", "KERNINGRECORD", + "LANGCODE", "ZONERECORD", "ZONEDATA", "PIX15", "PIX24", "COLORMAPDATA", "BITMAPDATA", "ALPHABITMAPDATA", "ALPHACOLORMAPDATA" }; + + public List exportJavaCode(SWF swf, String outdir) throws IOException { + final File file = new File(outdir + File.separator + Helper.makeFileName("SwfFile.java")); + CodeFormatting codeFormatting = Configuration.getCodeFormatting(); + codeFormatting.indentString = javaIndentString; + try (FileTextWriter writer = new FileTextWriter(codeFormatting, new FileOutputStream(file))) { + exportJavaCode(swf, writer); + } + + List ret = new ArrayList<>(); + ret.add(file); + return ret; + } + + public void exportJavaCode(SWF swf, GraphTextWriter writer) throws IOException { + Map objectNames = new HashMap<>(); + writer.append("package com.jpexs.decompiler.flash.exporters.swf;").newLine(); + writer.newLine(); + writer.append("import com.jpexs.decompiler.flash.SWF;").newLine(); + writer.append("import com.jpexs.decompiler.flash.SWFCompression;").newLine(); + writer.append("import com.jpexs.decompiler.flash.tags.*;").newLine(); + writer.append("import com.jpexs.decompiler.flash.types.*;").newLine(); + writer.append("import com.jpexs.decompiler.flash.types.filters.*;").newLine(); + writer.append("import com.jpexs.decompiler.flash.types.shaperecords.*;").newLine(); + writer.append("import com.jpexs.helpers.ByteArrayRange;").newLine(); + writer.append("import java.io.FileOutputStream;").newLine(); + writer.append("import java.io.IOException;").newLine(); + writer.append("import java.util.ArrayList;").newLine(); + writer.append("import java.util.List;").newLine(); + writer.newLine(); + writer.append("@SuppressWarnings(\"unchecked\")").newLine(); + writer.append("public class SwfFile {").newLine(); + writer.newLine(); + writer.indent(); + IndenetedStringBuilder sb = new IndenetedStringBuilder(javaIndentString); + generateJavaCode(writer, sb, objectNames, swf, 0); + writer.unindent(); + writer.append(" public SWF getSwf() {").newLine(); + writer.append(" SWF swf = swf();").newLine(); + writer.append(" swf.updateCharacters();").newLine(); + writer.append(" return swf;").newLine(); + writer.append(" }").newLine(); + writer.newLine(); + writer.append(" public void saveTo(String fileName) throws IOException {").newLine(); + writer.append(" SWF swf = getSwf();").newLine(); + writer.append(" swf.clearModified();").newLine(); + writer.append(" try (FileOutputStream fos = new FileOutputStream(fileName)) {").newLine(); + writer.append(" swf.saveTo(fos, SWFCompression.ZLIB);").newLine(); + writer.append(" }").newLine(); + writer.append(" }").newLine(); + writer.append("}").newLine(); + } + + private static String getNextId(Map objectNames, String type) { + Integer nextId = objectNames.get(type); + if (nextId == null) { + nextId = 0; + } else { + nextId++; + } + + objectNames.put(type, nextId); + return type + nextId; + } + + private static String getIndent(int indent, String indentStr) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < indent; i++) { + sb.append(indentStr); + } + return sb.toString(); + } + + private static Object generateJavaCode(GraphTextWriter writer, IndenetedStringBuilder sb, Map objectNames, Object obj, int level){ + if (obj == null) { + return null; + } + + Class cls = obj.getClass(); + Object value = null; + + if (cls == Byte.class || cls == byte.class || + cls == Short.class || cls == short.class || + cls == Integer.class || cls == int.class || + cls == Long.class || cls == long.class || + cls == Float.class || cls == float.class || + cls == Double.class || cls == double.class || + cls == Boolean.class || cls == boolean.class || + cls == Character.class || cls == char.class || + cls == String.class) { + value = obj; + if (value instanceof Float) { + value = value + "f"; + } else if (value instanceof String) { + value = "\"" + Helper.escapeJavaString((String) value) + "\""; + } + } else if (cls.isEnum()) { + value = cls.getSimpleName() + "." + obj; + } else if (obj instanceof ByteArrayRange) { + ByteArrayRange range = (ByteArrayRange) obj; + String className = "ByteArrayRange"; + String tagObjName = getNextId(objectNames, "objByteArrayRange"); + byte[] data = range.getRangeData(); + StringBuilder sb2 = new StringBuilder(); + final int maxBytePerString = 32767; + boolean isLong = data.length > maxBytePerString; + if (isLong) { + // string should be splitted to avoid "constant string too long" compile error + sb2.append("String.join(\"\", "); + } + + int stringCount = (int) Math.ceil(data.length / (double) maxBytePerString); + for (int i = 0; i < stringCount; i++) { + if (i != 0) { + sb2.append(", "); + } + + sb2.append("\""); + int from = i * maxBytePerString; + int to = Math.min(from + maxBytePerString, data.length); + for (int j = from; j < to; j++) { + sb2.append(String.format("%02x", data[j])); + } + + sb2.append("\""); + } + + if (isLong) { + sb2.append(")"); + } + + sb.appendLine(className + " " + tagObjName + " = new ByteArrayRange(" + sb2.toString() + ");"); + value = tagObjName; + } else if (List.class.isAssignableFrom(cls)) { + List list = (List) obj; + String tagObjName = getNextId(objectNames, "objList"); + sb.appendLine("List " + tagObjName + " = new ArrayList();"); + for (int i = 0; i < list.size(); i++) { + Object val = generateJavaCode(writer, sb, objectNames, list.get(i), level + 1); + sb.appendLine(tagObjName + ".add(" + val + ");"); + } + value = tagObjName; + } else if (cls.isArray()) { + String tagObjName = getNextId(objectNames, "objArray"); + String arrayType = cls.getComponentType().getSimpleName(); + int length = Array.getLength(obj); + sb.appendLine(arrayType + "[] " + tagObjName + " = new " + arrayType + "[" + length + "];"); + for (int i = 0; i < length; i++) { + Object val = generateJavaCode(writer, sb, objectNames, Array.get(obj, i), level + 1); + sb.appendLine(tagObjName + "[" + i + "] = " + val + ";"); + } + value = tagObjName; + } else { + if (obj instanceof LazyObject) { + ((LazyObject) obj).load(); + } + + String className = obj.getClass().getSimpleName(); + boolean isSwf = level == 0; + String resultName = isSwf ? "swf" : "result"; + String tagObjName = isSwf ? "swf" : getNextId(objectNames, "obj" + className); + IndenetedStringBuilder sb2 = new IndenetedStringBuilder(javaIndentString); + sb2.indent(); + sb2.indent(); + String indent = getIndent(writer.getIndent() + 1, javaIndentString); + Field fields[] = obj.getClass().getFields(); + for (Field f : fields) { + if (Modifier.isStatic(f.getModifiers())) { + continue; + } + + Internal inter = f.getAnnotation(Internal.class); + if (inter != null) { + continue; + } + + try { + f.setAccessible(true); + Object value2 = generateJavaCode(writer, sb2, objectNames, f.get(obj), level + 1); + if (value2 != null) { + sb2.appendLine(resultName + "." + f.getName() + " = " + value2 + ";"); + } + } catch (IllegalArgumentException | IllegalAccessException ex) { + Logger.getLogger(SwfJavaExporter.class.getName()).log(Level.SEVERE, null, ex); + } + } + + writer.append("private " + className + " " + tagObjName + "(" + (isSwf ? "" : "SWF swf") + ") {").newLine(); + writer.indent(); + writer.append(className + " " + resultName + " = new " + className + "(" + (obj instanceof Tag ? "swf" : "") + ");" + Helper.newLine); + writer.append(sb2.toString()); + writer.append(indent + "return " + resultName + ";").newLine(); + writer.unindent(); + writer.append("}").newLine().newLine(); + value = tagObjName + "(swf)"; + } + + return value; + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java index 3393fe28a..85527eb75 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/FileTextWriter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.helpers; import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java index f0fe9f105..54cec1fc3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.helpers; import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java index ee780e5df..78f4e48e4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.helpers; import com.jpexs.decompiler.flash.configuration.Configuration; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/LazyObject.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/LazyObject.java new file mode 100644 index 000000000..125132f07 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/LazyObject.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.helpers; + +/** + * + * @author JPEXS + */ +public interface LazyObject { + + public void load(); +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java index 3f407e43d..1a5e27961 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.abc.ABC; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java index 939ca063f..974c60638 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -26,6 +27,7 @@ import com.jpexs.decompiler.flash.types.ALPHACOLORMAPDATA; import com.jpexs.decompiler.flash.types.ARGB; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.Conditional; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; @@ -64,9 +66,9 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag { public static final int FORMAT_8BIT_COLORMAPPED = 3; public static final int FORMAT_32BIT_ARGB = 5; - @Internal + @HideInRawEdit private ALPHACOLORMAPDATA colorMapData; - @Internal + @HideInRawEdit private ALPHABITMAPDATA bitmapData; @Internal private boolean decompressed = false; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java index 654c2bfe8..32804b46f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.flash.types.COLORMAPDATA; import com.jpexs.decompiler.flash.types.PIX24; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.annotations.Conditional; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; @@ -65,9 +67,9 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag { public static final int FORMAT_15BIT_RGB = 4; public static final int FORMAT_24BIT_RGB = 5; - @Internal + @HideInRawEdit private COLORMAPDATA colorMapData; - @Internal + @HideInRawEdit private BITMAPDATA bitmapData; @Internal private boolean decompressed = false; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java index cb89a14f7..f863f12c5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -202,7 +203,7 @@ public class DefineButton2Tag extends ButtonTag implements ASMSourceContainer { } RECT rect = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); for (BUTTONRECORD r : characters) { - CharacterTag ch = swf.characters.get(r.characterId); + CharacterTag ch = swf.getCharacter(r.characterId); if (ch instanceof BoundedTag) { BoundedTag bt = (BoundedTag) ch; if (!added.contains(bt)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index ea54efe7a..9f6538efe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -38,7 +39,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RECT; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; @@ -74,7 +75,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { * Actions to perform */ //public List actions; - @Internal + @HideInRawEdit public ByteArrayRange actionBytes; public static final int ID = 7; @@ -253,7 +254,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { } RECT rect = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); for (BUTTONRECORD r : characters) { - CharacterTag ch = swf.characters.get(r.characterId); + CharacterTag ch = swf.getCharacter(r.characterId); if (ch instanceof BoundedTag) { BoundedTag bt = (BoundedTag) ch; if (!added.contains(bt)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java index 740687a2b..3020f2a2c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -26,7 +27,6 @@ import com.jpexs.decompiler.flash.types.LANGCODE; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPE; import com.jpexs.decompiler.flash.types.annotations.Conditional; -import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.helpers.ByteArrayRange; @@ -57,8 +57,6 @@ public class DefineFont2Tag extends FontTag { public boolean fontFlagsBold; public LANGCODE languageCode; public String fontName; - @Internal - public int numGlyphs; public List glyphShapeTable; @SWFType(value = BasicType.UI8, alternateValue = BasicType.UI16, alternateCondition = "fontFlagsWideCodes") @@ -136,6 +134,7 @@ public class DefineFont2Tag extends FontTag { byte[] fontNameBytes = Utf8Helper.getBytes(fontName); sos.writeUI8(fontNameBytes.length); sos.write(fontNameBytes); + int numGlyphs = glyphShapeTable.size(); sos.writeUI16(numGlyphs); List offsetTable = new ArrayList<>(); @@ -232,7 +231,7 @@ public class DefineFont2Tag extends FontTag { } else { fontName = new String(sis.readBytesEx(fontNameLen, "fontName")); } - numGlyphs = sis.readUI16("numGlyphs"); + int numGlyphs = sis.readUI16("numGlyphs"); long[] offsetTable = new long[numGlyphs]; long pos = sis.getPos(); for (int i = 0; i < numGlyphs; i++) { //offsetTable @@ -428,9 +427,6 @@ public class DefineFont2Tag extends FontTag { fontAdvanceTable.set(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character))); } } - if (!exists) { - numGlyphs++; - } setModified(true); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java index 04e4f0bb3..721330ac5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -28,7 +29,6 @@ import com.jpexs.decompiler.flash.types.LANGCODE; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPE; import com.jpexs.decompiler.flash.types.annotations.Conditional; -import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.helpers.ByteArrayRange; @@ -56,8 +56,6 @@ public class DefineFont3Tag extends FontTag { public boolean fontFlagsBold; public LANGCODE languageCode; public String fontName; - @Internal - public int numGlyphs; public List glyphShapeTable; @@ -142,7 +140,7 @@ public class DefineFont3Tag extends FontTag { } else { fontName = new String(sis.readBytesEx(fontNameLen, "fontName")); } - numGlyphs = sis.readUI16("numGlyphs"); + int numGlyphs = sis.readUI16("numGlyphs"); long[] offsetTable = new long[numGlyphs]; long pos = sis.getPos(); for (int i = 0; i < numGlyphs; i++) { //offsetTable @@ -209,6 +207,7 @@ public class DefineFont3Tag extends FontTag { List offsetTable = new ArrayList<>(); ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream(); SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion()); + int numGlyphs = glyphShapeTable.size(); for (int i = 0; i < numGlyphs; i++) { offsetTable.add(sos3.getPos()); sos3.writeSHAPE(glyphShapeTable.get(i), 1); @@ -428,9 +427,6 @@ public class DefineFont3Tag extends FontTag { fontAdvanceTable.set(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character))); } } - if (!exists) { - numGlyphs++; - } setModified(true); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index 558bdc9dd..c3cf11331 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -96,7 +97,7 @@ public class DefineSpriteTag extends CharacterTag implements DrawableTag, Timeli RECT ret = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); boolean foundSomething = false; for (int c : characters) { - Tag t = swf.characters.get(c); + Tag t = swf.getCharacter(c); RECT r = null; if (t instanceof BoundedTag) { BoundedTag bt = (BoundedTag) t; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java index 65401d12b..6a1ca703e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -23,7 +24,7 @@ import com.jpexs.decompiler.flash.abc.ABCInputStream; import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.types.BasicType; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayInputStream; @@ -43,7 +44,7 @@ public class DoABCDefineTag extends Tag implements ABCContainerTag { /** * ActionScript 3 bytecodes */ - @Internal + @HideInRawEdit private final ABC abc; /** * A 32-bit flags value, which may contain the following bits set: diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java index 1ac948bd1..b25ef44af 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -22,7 +23,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -37,7 +38,7 @@ public class DoABCTag extends Tag implements ABCContainerTag { /** * ActionScript 3 bytecodes */ - @Internal + @HideInRawEdit private final ABC abc; public static final int ID = 72; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index 7c148ab85..ed6f2716b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -24,7 +25,7 @@ import com.jpexs.decompiler.flash.action.ActionListReader; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; import java.io.IOException; @@ -43,7 +44,7 @@ public class DoActionTag extends Tag implements ASMSource { * List of actions to perform */ //public List actions = new ArrayList(); - @Internal + @HideInRawEdit public ByteArrayRange actionBytes; public static final int ID = 12; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 6b3223df2..87463bddc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -27,7 +28,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.types.BasicType; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; @@ -49,7 +50,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { * List of actions to perform */ //public List actions = new ArrayList(); - @Internal + @HideInRawEdit public ByteArrayRange actionBytes; public static final int ID = 59; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java index 43cf98af4..fa56a729d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java @@ -12,13 +12,14 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -27,7 +28,7 @@ import java.io.OutputStream; public class JPEGTablesTag extends Tag { public static final int ID = 8; - @Internal + @HideInRawEdit public byte[] jpegData; /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java index 69c25ce56..dd1a0c65f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -31,7 +32,7 @@ import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RGBA; import com.jpexs.decompiler.flash.types.annotations.Conditional; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; @@ -123,7 +124,7 @@ public class PlaceObject2Tag extends CharacterIdTag implements ASMSourceContaine * @since SWF 5 If PlaceFlagHasClipActions, Clip Actions Data */ @Conditional("placeFlagHasClipActions") - @Internal //TODO: make editable + @HideInRawEdit //TODO: make editable public CLIPACTIONS clipActions; public static final int ID = 26; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java index eee92f66d..32ee78466 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.EndOfStreamException; @@ -32,6 +33,7 @@ import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RGBA; import com.jpexs.decompiler.flash.types.annotations.Conditional; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; @@ -180,7 +182,7 @@ public class PlaceObject3Tag extends CharacterIdTag implements ASMSourceContaine * @since SWF 5 If PlaceFlagHasClipActions, Clip Actions Data */ @Conditional(value = "placeFlagHasClipActions", minSwfVersion = 5) - @Internal //TODO: make editable + @HideInRawEdit //TODO: make editable public CLIPACTIONS clipActions; /** * If PlaceFlagHasVisible, 0 = Place invisible, 1 = Place visible diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java index 07235d9d3..5ac6dafdf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.EndOfStreamException; @@ -32,6 +33,7 @@ import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RGBA; import com.jpexs.decompiler.flash.types.annotations.Conditional; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; @@ -180,7 +182,7 @@ public class PlaceObject4Tag extends CharacterIdTag implements ASMSourceContaine * @since SWF 5 If PlaceFlagHasClipActions, Clip Actions Data */ @Conditional(value = "placeFlagHasClipActions", minSwfVersion = 5) - @Internal //TODO: make editable + @HideInRawEdit //TODO: make editable public CLIPACTIONS clipActions; /** * If PlaceFlagHasVisible, 0 = Place invisible, 1 = Place visible diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java index 2b569c599..e684bdca2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java @@ -12,13 +12,14 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -33,7 +34,7 @@ public class SoundStreamBlockTag extends Tag { public static final int ID = 19; - @Internal + @HideInRawEdit public ByteArrayRange streamSoundData; /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java index 0a0099729..1da1424a3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; @@ -415,10 +416,18 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { } public long getPos() { + if (originalRange == null) { + return -1; + } + return originalRange.getPos(); } public long getDataPos() { + if (originalRange == null) { + return -1; + } + return originalRange.getPos() + (isLongOriginal() ? 6 : 2); } @@ -474,8 +483,8 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { for (Integer characterId : needed2) { if (!visited.contains(characterId)) { visited.add(characterId); - if (swf.characters.containsKey(characterId)) { - swf.characters.get(characterId).getNeededCharacters(needed2); + if (swf.getCharacters().containsKey(characterId)) { + swf.getCharacter(characterId).getNeededCharacters(needed2); break; } } @@ -483,7 +492,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { } for (Integer characterId : needed2) { - if (swf.characters.containsKey(characterId)) { + if (swf.getCharacters().containsKey(characterId)) { needed.add(characterId); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java index 407810ffb..b49d02d9c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.SWF; @@ -23,6 +24,7 @@ import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter; import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter; import com.jpexs.decompiler.flash.exporters.shape.PathExporter; import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter; +import com.jpexs.decompiler.flash.helpers.LazyObject; import com.jpexs.decompiler.flash.timeline.DepthState; import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; @@ -42,7 +44,7 @@ import java.util.Set; * * @author JPEXS */ -public abstract class ShapeTag extends CharacterTag implements DrawableTag { +public abstract class ShapeTag extends CharacterTag implements DrawableTag, LazyObject { private final int markerSize = 10; @@ -51,6 +53,11 @@ public abstract class ShapeTag extends CharacterTag implements DrawableTag { } public abstract SHAPEWITHSTYLE getShapes(); + + @Override + public void load() { + getShapes(); + } public abstract int getShapeNum(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 12e192757..9cf7bdca7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.SWF; @@ -291,7 +292,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { } } if (rec.styleFlagsHasFont) { - font = (FontTag) swf.characters.get(rec.fontId); + font = (FontTag) swf.getCharacter(rec.fontId); glyphs = font == null ? null : font.getGlyphShapeTable(); textHeight = rec.textHeight; } @@ -337,7 +338,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { ExportRectangle result = null; for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { - font = (FontTag) swf.characters.get(rec.fontId); + font = (FontTag) swf.getCharacter(rec.fontId); glyphs = font == null ? null : font.getGlyphShapeTable(); textHeight = rec.textHeight; } @@ -428,7 +429,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { } } if (rec.styleFlagsHasFont) { - font = (FontTag) swf.characters.get(rec.fontId); + font = (FontTag) swf.getCharacter(rec.fontId); fontId = rec.fontId; glyphs = font.getGlyphShapeTable(); textHeight = rec.textHeight; @@ -474,7 +475,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { } } if (rec.styleFlagsHasFont) { - font = (FontTag) swf.characters.get(rec.fontId); + font = (FontTag) swf.getCharacter(rec.fontId); glyphs = font.getGlyphShapeTable(); textHeight = rec.textHeight; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java index 4b23ad803..a914eddfc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.tags.gfx; import com.jpexs.decompiler.flash.SWF; @@ -387,7 +388,6 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { ret.codeTable = new ArrayList<>(); ret.glyphShapeTable = new ArrayList<>(); List shp = getGlyphShapeTable(); - ret.numGlyphs = shp.size(); for (int g = 0; g < shp.size(); g++) { ret.fontAdvanceTable.add(resize(getGlyphAdvance(g))); ret.codeTable.add((int) glyphToChar(g)); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java index bb9a28015..1b481bb01 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.timeline; import com.jpexs.decompiler.flash.SWF; @@ -353,11 +354,11 @@ public class Timeline { for (int depth : frameObj.layers.keySet()) { DepthState layer = frameObj.layers.get(depth); if (layer.characterId != -1) { - if (!swf.characters.containsKey(layer.characterId)) { + if (!swf.getCharacters().containsKey(layer.characterId)) { continue; } usedCharacters.add(layer.characterId); - swf.characters.get(layer.characterId).getNeededCharactersDeep(usedCharacters); + swf.getCharacter(layer.characterId).getNeededCharactersDeep(usedCharacters); } } } @@ -391,7 +392,7 @@ public class Timeline { for (int d = maxDepth; d >= 0; d--) { DepthState ds = fr.layers.get(d); if (ds != null) { - CharacterTag c = swf.characters.get(ds.characterId); + CharacterTag c = swf.getCharacter(ds.characterId); if (c instanceof Timelined) { int frameCount = ((Timelined) c).getTimeline().frames.size(); if (frameCount == 0) { @@ -437,7 +438,7 @@ public class Timeline { if (!ds.isVisible) { continue; } - CharacterTag c = swf.characters.get(ds.characterId); + CharacterTag c = swf.getCharacter(ds.characterId); if (c instanceof DrawableTag) { Matrix m = new Matrix(ds.matrix); m = m.preConcatenate(transformation); @@ -507,7 +508,7 @@ public class Timeline { if (!ds.isVisible) { continue; } - CharacterTag c = swf.characters.get(ds.characterId); + CharacterTag c = swf.getCharacter(ds.characterId); if (c instanceof DrawableTag) { Matrix m = new Matrix(ds.matrix); m = m.preConcatenate(transformation); @@ -567,13 +568,13 @@ public class Timeline { continue; } DepthState layer = frameObj.layers.get(i); - if (!swf.characters.containsKey(layer.characterId)) { + if (!swf.getCharacters().containsKey(layer.characterId)) { continue; } if (!layer.isVisible) { continue; } - CharacterTag character = swf.characters.get(layer.characterId); + CharacterTag character = swf.getCharacter(layer.characterId); if (character instanceof DrawableTag) { DrawableTag drawable = (DrawableTag) character; if (!drawable.isSingleFrame()) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHGRADIENT.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHGRADIENT.java index 9a36fb508..353dd2cc4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHGRADIENT.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MORPHGRADIENT.java @@ -12,10 +12,10 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.types; -import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.io.Serializable; @@ -35,8 +35,6 @@ public class MORPHGRADIENT implements Serializable { */ @SWFType(value = BasicType.UB, count = 2) public int interPolationMode; - @Internal - public int numGradients; public MORPHGRADRECORD[] gradientRecords; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/HideInRawEdit.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/HideInRawEdit.java new file mode 100644 index 000000000..92772dfbe --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/HideInRawEdit.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.types.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Field is internal + * + * @author JPEXS + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface HideInRawEdit { + +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java index 066ff7647..ae193bb67 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWFOutputStream; @@ -26,8 +27,8 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; */ public class CurvedEdgeRecord extends SHAPERECORD { - public boolean typeFlag = true; - public boolean straightFlag = false; + public static final boolean typeFlag = true; + public static final boolean straightFlag = false; @Calculated @SWFType(value = BasicType.UB, count = 4) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java index 5900ca945..417751728 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.types.BasicType; @@ -24,7 +25,8 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; */ public class EndShapeRecord extends SHAPERECORD { - public boolean typeFlag = false; + public static final boolean typeFlag = false; + @SWFType(value = BasicType.UB, count = 5) public int endOfShape = 0; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java index f7e77a04f..ef507e933 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWFOutputStream; @@ -38,8 +39,8 @@ public class StraightEdgeRecord extends SHAPERECORD { ser.deltaY = (int) readSB(ser.numBits + 2); } */ - public boolean typeFlag = true; - public boolean straightFlag = true; + public static final boolean typeFlag = true; + public static final boolean straightFlag = true; @Calculated @SWFType(value = BasicType.UB, count = 4) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java index b74d80abb..b86a6b0f9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWFOutputStream; @@ -30,7 +31,7 @@ import java.util.Set; */ public final class StyleChangeRecord extends SHAPERECORD implements Cloneable { - public boolean typeFlag = false; + public static final boolean typeFlag = false; public boolean stateNewStyles; public boolean stateLineStyle; public boolean stateFillStyle1; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index fd204fcfd..710e04e5f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.xfl; import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; @@ -2679,7 +2680,7 @@ public class XFLConverter { public static void convertSWF(AbortRetryIgnoreHandler handler, SWF swf, String swfFileName, String outfile, boolean compressed, String generator, String generatorVerName, String generatorVersion, boolean parallel, FLAVersion flaVersion) throws IOException { - FileAttributesTag fa = swf.fileAttributes; + FileAttributesTag fa = swf.getFileAttributes(); boolean useAS3 = false; boolean useNetwork = false; diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/ByteArrayRange.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/ByteArrayRange.java index 8915ccd80..7694d6504 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/ByteArrayRange.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/ByteArrayRange.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.helpers; /** @@ -39,6 +40,16 @@ public class ByteArrayRange { this.length = length; } + public ByteArrayRange(String hexString) { + byte[] array = new byte[hexString.length() / 2]; + for (int i = 0; i < hexString.length() / 2; i++) { + array[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16); + } + this.array = array; + this.pos = 0; + this.length = array.length; + } + public byte[] getArray() { return array; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 99fee512e..29761c690 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.helpers; import com.jpexs.decompiler.flash.AppResources; @@ -179,6 +180,42 @@ public class Helper { return ret.toString(); } + /** + * Escapes string by adding backslashes + * + * @param s String to escape + * @return Escaped string + */ + public static String escapeJavaString(String s) { + StringBuilder ret = new StringBuilder(s.length()); + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '\n') { + ret.append("\\n"); + } else if (c == '\r') { + ret.append("\\r"); + } else if (c == '\t') { + ret.append("\\t"); + } else if (c == '\b') { + ret.append("\\b"); + } else if (c == '\t') { + ret.append("\\t"); + } else if (c == '\f') { + ret.append("\\f"); + } else if (c == '\\') { + ret.append("\\\\"); + } else if (c == '"') { + ret.append("\\\""); + } else if (c < 32) { + ret.append("\\u").append(padZeros(Integer.toHexString((int) c), 4)); + } else { + ret.append(c); + } + } + + return ret.toString(); + } + public static String getValidHtmlId(String text) { // ID and NAME tokens must begin with a letter ([A-Za-z]) and // may be followed by any number of letters, digits ([0-9]), diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java index 94d321762..9293b762f 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3Test.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.abc.ABC; diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java index f8ddc9cfc..375b17b7d 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.abc.ABC; @@ -81,10 +82,10 @@ public class RecompileTest { Configuration.autoDeobfuscate.set(false); try { SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + filename)), false); - if (swf.isAS3) { + if (swf.isAS3()) { boolean dotest = false; List allAbcs = new ArrayList<>(); - for (ABCContainerTag ct : swf.abcList) { + for (ABCContainerTag ct : swf.getAbcList()) { allAbcs.add(ct.getABC()); } for (ABC abc : allAbcs) { @@ -101,7 +102,7 @@ public class RecompileTest { } System.out.println("Recompiling:" + en.getKey().toString() + "..."); - en.getValue().toSource(htw, swf.abcList, abc.script_info.get(s).traits.traits, ScriptExportMode.AS, false); + en.getValue().toSource(htw, swf.getAbcList(), abc.script_info.get(s).traits.traits, ScriptExportMode.AS, false); String original = htw.toString(); com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser.compile(original, abc, allAbcs, false, en.getKey().className + ".as", abc.instance_info.size()); //remove last compiled script: diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java index 3d2576bef..0ff132d30 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.generators; import com.jpexs.decompiler.flash.SWF; diff --git a/src/com/jpexs/browsers/cache/chrome/CacheAddr.java b/src/com/jpexs/browsers/cache/chrome/CacheAddr.java index a4c174dd0..4df9fd95b 100644 --- a/src/com/jpexs/browsers/cache/chrome/CacheAddr.java +++ b/src/com/jpexs/browsers/cache/chrome/CacheAddr.java @@ -29,34 +29,34 @@ import java.util.Map; */ public class CacheAddr { - public static final int EXTERNAL = 0; - public static final int RANKINGS = 1; - public static final int BLOCK_256 = 2; - public static final int BLOCK_1K = 3; - public static final int BLOCK_4K = 4; - public static final int BLOCK_FILES = 5; - public static final int BLOCK_ENTRIES = 6; - public static final int BLOCK_EVICTED = 7; - public static final String blockNames[] = new String[]{"EXTERNAL", "RANKINGS", "BLOCK_256", "BLOCK_1K", "BLOCK_4K", "BLOCK_FILES", "BLOCK_ENTRIES", "BLOCK_EVICTED"}; - public static final int blockSizes[] = new int[]{0, 36, 256, 1024, 4096, 8, 104, 48}; - public static final long kInitializedMask = 0x80000000L; - public static final long kFileTypeMask = 0x70000000L; - public static final int kFileTypeOffset = 28; - public static final long kReservedBitsMask = 0x0c000000L; - public static final long kNumBlocksMask = 0x03000000L; - public static final int kNumBlocksOffset = 24; - public static final long kFileSelectorMask = 0x00ff0000L; - public static final int FileSelectorOffset = 16; - public static final long kStartBlockMask = 0x0000FFFFL; - public static final long kFileNameMask = 0x0FFFFFFFL; - public boolean initialized; - public int fileType; - public int numBlocks; - public int fileSelector; - public int startBlock; - public int fileName; - public long val; - public File rootPath; + private static final int EXTERNAL = 0; + private static final int RANKINGS = 1; + private static final int BLOCK_256 = 2; + private static final int BLOCK_1K = 3; + private static final int BLOCK_4K = 4; + private static final int BLOCK_FILES = 5; + private static final int BLOCK_ENTRIES = 6; + private static final int BLOCK_EVICTED = 7; + private static final String blockNames[] = new String[]{"EXTERNAL", "RANKINGS", "BLOCK_256", "BLOCK_1K", "BLOCK_4K", "BLOCK_FILES", "BLOCK_ENTRIES", "BLOCK_EVICTED"}; + private static final int blockSizes[] = new int[]{0, 36, 256, 1024, 4096, 8, 104, 48}; + private static final long kInitializedMask = 0x80000000L; + private static final long kFileTypeMask = 0x70000000L; + private static final int kFileTypeOffset = 28; + private static final long kReservedBitsMask = 0x0c000000L; + private static final long kNumBlocksMask = 0x03000000L; + private static final int kNumBlocksOffset = 24; + private static final long kFileSelectorMask = 0x00ff0000L; + private static final int FileSelectorOffset = 16; + private static final long kStartBlockMask = 0x0000FFFFL; + private static final long kFileNameMask = 0x0FFFFFFFL; + private final boolean initialized; + private final int fileType; + private int numBlocks; + private int fileSelector; + private int startBlock; + private int fileName; + private final long val; + private final File rootPath; private final Map dataFiles; private final File externalFilesDir; diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index ae7ced839..5e7302fbd 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -514,8 +514,8 @@ public class CommandLineArgumentParser { } public boolean contains(int index) { - Integer minimum = min == null ? Integer.MIN_VALUE : min; - Integer maximum = max == null ? Integer.MAX_VALUE : max; + int minimum = min == null ? Integer.MIN_VALUE : min; + int maximum = max == null ? Integer.MAX_VALUE : max; return index >= minimum && index <= maximum; } @@ -1216,8 +1216,8 @@ public class CommandLineArgumentParser { fmts = new String[]{fmtStr}; } Map ret = new HashMap<>(); - for (int i = 0; i < fmts.length; i++) { - String parts[] = fmts[i].split(":"); + for (String fmt : fmts) { + String[] parts = fmt.split(":"); ret.put(parts[0].toLowerCase(), parts[1].toLowerCase()); } return ret; @@ -1327,12 +1327,12 @@ public class CommandLineArgumentParser { System.err.println("CharacterId should be integer"); System.exit(1); } - if (!swf.characters.containsKey(characterId)) { + if (!swf.getCharacters().containsKey(characterId)) { System.err.println("CharacterId does not exist"); System.exit(1); } - CharacterTag characterTag = swf.characters.get(characterId); + CharacterTag characterTag = swf.getCharacter(characterId); String repFile = args.remove(); byte[] data = Helper.readFile(repFile); if (characterTag instanceof DefineBinaryDataTag) { diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index e308004bf..de5c6bde7 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.RGBA; import com.jpexs.decompiler.flash.types.annotations.Conditional; +import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.Multiline; import com.jpexs.decompiler.flash.types.annotations.SWFArray; @@ -828,6 +829,10 @@ public class GenericTagTreePanel extends GenericTagPanel { if (inter != null) { continue; } + HideInRawEdit hide = f.getAnnotation(HideInRawEdit.class); + if (hide != null) { + continue; + } ret.add(f); } return ret; diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 8f44a1ab1..9db7b4e47 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -263,7 +263,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis ret += ", "; } first = false; - CharacterTag c = tim.swf.characters.get(ds.characterId); + CharacterTag c = tim.swf.getCharacter(ds.characterId); if (c instanceof ButtonTag) { newStateUnderCursor = ds; handCursor = true; @@ -298,7 +298,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (selectedDepth > -1 && frame > -1) { DepthState ds = timelined.getTimeline().getFrames().get(frame).layers.get(selectedDepth); if (ds != null) { - CharacterTag cht = timelined.getTimeline().swf.characters.get(ds.characterId); + CharacterTag cht = timelined.getTimeline().swf.getCharacter(ds.characterId); if (cht != null) { debugLabel.setText(cht.getName()); } @@ -351,10 +351,10 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis lastMouseEvent = e; shouldDraw.set(true); if (stateUnderCursor != null) { - ButtonTag b = (ButtonTag) swf.characters.get(stateUnderCursor.characterId); + ButtonTag b = (ButtonTag) swf.getCharacter(stateUnderCursor.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar2 != 0) { //OverUpToOverDown - playSound((SoundTag) swf.characters.get(sounds.buttonSoundChar2), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar2), counter); } } } @@ -367,10 +367,10 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis lastMouseEvent = e; shouldDraw.set(true); if (stateUnderCursor != null) { - ButtonTag b = (ButtonTag) swf.characters.get(stateUnderCursor.characterId); + ButtonTag b = (ButtonTag) swf.getCharacter(stateUnderCursor.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar3 != 0) { //OverDownToOverUp - playSound((SoundTag) swf.characters.get(sounds.buttonSoundChar3), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar3), counter); } } } @@ -387,20 +387,20 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (stateUnderCursor != null) { if (lastUnderCur == null || lastUnderCur.instanceId != stateUnderCursor.instanceId) { // New mouse entered - ButtonTag b = (ButtonTag) swf.characters.get(stateUnderCursor.characterId); + ButtonTag b = (ButtonTag) swf.getCharacter(stateUnderCursor.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar1 != 0) { //IddleToOverUp - playSound((SoundTag) swf.characters.get(sounds.buttonSoundChar1), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar1), counter); } } } if (lastUnderCur != null) { if (stateUnderCursor == null || stateUnderCursor.instanceId != lastUnderCur.instanceId) { // Old mouse leave - ButtonTag b = (ButtonTag) swf.characters.get(lastUnderCur.characterId); + ButtonTag b = (ButtonTag) swf.getCharacter(lastUnderCur.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar0 != 0) { //OverUpToIddle - playSound((SoundTag) swf.characters.get(sounds.buttonSoundChar0), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar0), counter); } } } @@ -666,7 +666,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis List os = new ArrayList<>(); DepthState ds = drawable.getTimeline().getFrames().get(frame).layers.get(selectedDepth); if (ds != null) { - CharacterTag cht = swf.characters.get(ds.characterId); + CharacterTag cht = swf.getCharacter(ds.characterId); if (cht != null) { if (cht instanceof DrawableTag) { DrawableTag dt = (DrawableTag) cht; @@ -746,8 +746,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis List sounds = new ArrayList<>(); List soundClasses = new ArrayList<>(); timeline.getSounds(frame, time, stateUnderCursor, mouseButton, sounds, soundClasses); - for (int cid : swf.characters.keySet()) { - CharacterTag c = swf.characters.get(cid); + for (int cid : swf.getCharacters().keySet()) { + CharacterTag c = swf.getCharacter(cid); for (String cls : soundClasses) { if (cls.equals(c.getClassName())) { sounds.add(cid); @@ -756,7 +756,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis } for (int sndId : sounds) { - CharacterTag c = swf.characters.get(sndId); + CharacterTag c = swf.getCharacter(sndId); if (c instanceof SoundTag) { SoundTag st = (SoundTag) c; playSound(st, counter); diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index a56d928c2..768e13f15 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -125,7 +125,7 @@ public class Main { public static final String DEBUGGER_PACKAGE = "com.jpexs.decompiler.flash.debugger"; private static ABCContainerTag getDebuggerABCTag(SWF swf) { - for (ABCContainerTag ac : swf.abcList) { + for (ABCContainerTag ac : swf.getAbcList()) { ABC a = ac.getABC(); for (MyEntry m : a.getScriptPacks()) { if (isDebuggerClass(m.getKey().packageStr, null)) { @@ -308,7 +308,6 @@ public class Main { } }, Configuration.parallelSpeedUp.get()); swf.fileTitle = streamEntry.getKey(); - swf.readOnly = true; result.add(swf); } } else { @@ -1177,7 +1176,7 @@ public class Main { if (hasDebugger(swf)) { String debuggerPkg = getDebuggerPackage(swf); //change trace to fname - for (ABCContainerTag ct : swf.abcList) { + for (ABCContainerTag ct : swf.getAbcList()) { ABC a = ct.getABC(); for (int i = 1; i < a.constants.constant_multiname.size(); i++) { Multiname m = a.constants.constant_multiname.get(i); @@ -1197,10 +1196,10 @@ public class Main { ABCContainerTag found = getDebuggerABCTag(swf); if (found != null) { swf.tags.remove((Tag) found); - swf.abcList.remove(found); + swf.getAbcList().remove(found); //Change all debugger calls to normal trace - for (ABCContainerTag ct : swf.abcList) { + for (ABCContainerTag ct : swf.getAbcList()) { ABC a = ct.getABC(); for (int i = 1; i < a.constants.constant_multiname.size(); i++) { Multiname m = a.constants.constant_multiname.get(i); @@ -1223,7 +1222,7 @@ public class Main { //load debug swf SWF debugSWF = new SWF(Main.class.getClassLoader().getResourceAsStream("com/jpexs/decompiler/flash/gui/debugger/debug.swf"), false); - ABCContainerTag firstAbc = swf.abcList.get(0); + ABCContainerTag firstAbc = swf.getAbcList().get(0); String newdebuggerpkg = DEBUGGER_PACKAGE; if (Configuration.randomDebuggerPackage.get()) { @@ -1231,7 +1230,7 @@ public class Main { } //add debug ABC tags to main SWF - for (ABCContainerTag ds : debugSWF.abcList) { + for (ABCContainerTag ds : debugSWF.getAbcList()) { ABC a = ds.getABC(); //Append random hex to Debugger package name for (int i = 1; i < a.constants.constant_namespace.size(); i++) { @@ -1248,12 +1247,12 @@ public class Main { //Add to target SWF ((Tag) ds).setSwf(swf); swf.tags.add(swf.tags.indexOf(firstAbc), (Tag) ds); - swf.abcList.add(swf.abcList.indexOf(firstAbc), ds); + swf.getAbcList().add(swf.getAbcList().indexOf(firstAbc), ds); ((Tag) ds).setModified(true); } } catch (Exception ex) { - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Error while attaching debugger", ex); + logger.log(Level.SEVERE, "Error while attaching debugger", ex); //ignore } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index 81db8b93d..0c1f4f88b 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -329,7 +329,7 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene public void updateComponents(SWF swf) { super.updateComponents(swf); boolean swfLoaded = swf != null; - List abcList = swfLoaded ? swf.abcList : null; + List abcList = swfLoaded ? swf.getAbcList() : null; boolean hasAbc = swfLoaded && abcList != null && !abcList.isEmpty(); /*saveCommandButton.setEnabled(swfLoaded); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 8103bdc79..55b6e5e50 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -94,6 +94,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener private static final String ACTION_CLOSE_ALL = "CLOSEALL"; private static final String ACTION_EXPORT_FLA = "EXPORTFLA"; public static final String ACTION_EXPORT_SEL = "EXPORTSEL"; + public static final String ACTION_EXPORT_JAVA_SOURCE = "EXPORTJAVASOURCE"; private static final String ACTION_EXPORT = "EXPORT"; private static final String ACTION_IMPORT_TEXT = "IMPORTTEXT"; private static final String ACTION_CHECK_UPDATES = "CHECKUPDATES"; @@ -611,7 +612,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener public void updateComponents(SWF swf) { super.updateComponents(swf); boolean swfLoaded = swf != null; - List abcList = swfLoaded ? swf.abcList : null; + List abcList = swfLoaded ? swf.getAbcList() : null; boolean hasAbc = swfLoaded && abcList != null && !abcList.isEmpty(); boolean hasDebugger = hasAbc && Main.hasDebugger(swf); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index cc4d50406..cf7cbad13 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -57,6 +57,7 @@ import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings; import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings; import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; +import com.jpexs.decompiler.flash.exporters.swf.SwfJavaExporter; import com.jpexs.decompiler.flash.gui.abc.ABCPanel; import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel; import com.jpexs.decompiler.flash.gui.abc.DeobfuscationDialog; @@ -77,6 +78,7 @@ import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineSoundTag; import com.jpexs.decompiler.flash.tags.DefineSpriteTag; +import com.jpexs.decompiler.flash.tags.FileAttributesTag; import com.jpexs.decompiler.flash.tags.SymbolClassTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; @@ -628,7 +630,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : "")); - List abcList = swf.abcList; + List abcList = swf.getAbcList(); boolean hasAbc = !abcList.isEmpty(); @@ -1001,8 +1003,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec ret.addAll(swf.exportFrames(handler, selFile + File.separator + "frames", entry.getKey(), entry.getValue(), new FramesExportSettings(export.getValue(FramesExportMode.class), export.getZoom()))); } - List abcList = swf.abcList; - if (swf.isAS3) { + List abcList = swf.getAbcList(); + if (swf.isAS3()) { for (int i = 0; i < as3scripts.size(); i++) { ScriptPack tls = as3scripts.get(i); Main.startWork(translate("work.exporting") + " " + (i + 1) + "/" + as3scripts.size() + " " + tls.getPath() + " ..."); @@ -1151,7 +1153,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec protected Void doInBackground() throws Exception { boolean found = false; if (searchDialog.searchInASRadioButton.isSelected()) { - if (swf.isAS3) { + if (swf.isAS3()) { if (abcPanel != null && abcPanel.search(txt, searchDialog.ignoreCaseCheckBox.isSelected(), searchDialog.regexpCheckBox.isSelected())) { found = true; View.execInEventDispatch(new Runnable() { @@ -1326,9 +1328,11 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (swf == null) { return; } - if (swf.fileAttributes != null && swf.fileAttributes.actionScript3) { + + FileAttributesTag fileAttributes = swf.getFileAttributes(); + if (fileAttributes != null && fileAttributes.actionScript3) { final int multiName = getABCPanel().decompiledTextArea.getMultinameUnderCaret(); - final List abcList = swf.abcList; + final List abcList = swf.getAbcList(); if (multiName > 0) { new CancellableWorker() { @Override @@ -1389,9 +1393,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec List flaFilters = new ArrayList<>(); List xflFilters = new ArrayList<>(); List versions = new ArrayList<>(); + boolean isAS3 = swf.isAS3(); for (int i = FLAVersion.values().length - 1; i >= 0; i--) { final FLAVersion v = FLAVersion.values()[i]; - if (!swf.isAS3 && v.minASVersion() > 2) { + if (!isAS3 && v.minASVersion() > 2) { // This version does not support AS1/2 } else { versions.add(v); @@ -1594,7 +1599,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec new FontExportSettings(export.getValue(FontExportMode.class))); swf.exportFrames(errorHandler, selFile + File.separator + "frames", 0, null, new FramesExportSettings(export.getValue(FramesExportMode.class), export.getZoom())); - for (CharacterTag c : swf.characters.values()) { + for (CharacterTag c : swf.getCharacters().values()) { if (c instanceof DefineSpriteTag) { swf.exportFrames(errorHandler, selFile + File.separator + "frames", c.getCharacterId(), null, new FramesExportSettings(export.getValue(FramesExportMode.class), export.getZoom())); @@ -1629,6 +1634,23 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } + public void exportJavaSource() { + List sel = tagTree.getSelected(tagTree); + for (TreeItem item : sel) { + if (item instanceof SWF) { + SWF swf = (SWF) item; + final String selFile = selectExportDir(); + if (selFile != null) { + try { + new SwfJavaExporter().exportJavaCode(swf, selFile); + } catch (IOException ex) { + logger.log(Level.SEVERE, null, ex); + } + } + } + } + } + public void restoreControlFlow(final boolean all) { Main.startWork(translate("work.restoringControlFlow")); if ((!all) || confirmExperimental()) { @@ -1637,7 +1659,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec protected Object doInBackground() throws Exception { int cnt = 0; if (all) { - for (ABCContainerTag tag : getABCPanel().swf.abcList) { + for (ABCContainerTag tag : getABCPanel().swf.getAbcList()) { tag.getABC().restoreControlFlow(); } } else { @@ -1725,7 +1747,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec protected Object doInBackground() throws Exception { try { if (deobfuscationDialog.processAllCheckbox.isSelected()) { - for (ABCContainerTag tag : getABCPanel().swf.abcList) { + for (ABCContainerTag tag : getABCPanel().swf.getAbcList()) { if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_DEAD_CODE) { tag.getABC().removeDeadCode(); } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_TRAPS) { @@ -1978,6 +2000,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec switch (e.getActionCommand()) { + case MainFrameRibbonMenu.ACTION_EXPORT_JAVA_SOURCE: { + exportJavaSource(); + } case MainFrameRibbonMenu.ACTION_EXPORT_SEL: export(true); break; @@ -2264,7 +2289,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec stopFlashPlayer(); if (treeItem instanceof ScriptPack) { final ScriptPack scriptLeaf = (ScriptPack) treeItem; - final List abcList = scriptLeaf.abc.swf.abcList; + final List abcList = scriptLeaf.abc.swf.getAbcList(); if (setSourceWorker != null) { setSourceWorker.cancel(true); setSourceWorker = null; @@ -2283,7 +2308,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } getABCPanel().detailPanel.methodTraitPanel.methodCodePanel.clear(); - getABCPanel().navigator.setABC(abcList, scriptLeaf.abc); + getABCPanel().navigator.setAbc(abcList, scriptLeaf.abc); getABCPanel().navigator.setClassIndex(classIndex, scriptLeaf.scriptIndex); getABCPanel().setAbc(scriptLeaf.abc); getABCPanel().decompiledTextArea.setScript(scriptLeaf, abcList); diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 11a057c54..cf26a5429 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -589,7 +589,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { t.getNeededCharactersDeep(needed); for (int n : needed) { if (!doneCharacters.contains(n)) { - classicTag(swf.characters.get(n)).writeTag(sos2); + classicTag(swf.getCharacter(n)).writeTag(sos2); doneCharacters.add(n); } } @@ -649,7 +649,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { if (isSprite && chtId == n) { continue; } - classicTag(swf.characters.get(n)).writeTag(sos2); + classicTag(swf.getCharacter(n)).writeTag(sos2); } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 29fbc0c61..38bb938b0 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -257,16 +257,17 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se this.swf = null; this.abc = null; constantTable.setModel(new DefaultTableModel()); - navigator.clearABC(); + navigator.clearAbc(); } public void setSwf(SWF swf) { if (this.swf != swf) { this.swf = swf; - if (swf.abcList.size() > 0) { - this.abc = swf.abcList.get(0).getABC(); + List abcList = swf.getAbcList(); + if (abcList.size() > 0) { + this.abc = abcList.get(0).getABC(); } - navigator.setABC(swf.abcList, abc); + navigator.setAbc(abcList, abc); } } @@ -394,7 +395,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se @Override public void propertyChange(PropertyChangeEvent pce) { if (!directEditing) { - Configuration.guiAvm2SplitPaneDividerLocation.set((int) pce.getNewValue()); + Configuration.guiAvm2SplitPaneDividerLocation.set((Integer) pce.getNewValue()); } } }); @@ -407,7 +408,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se public void actionPerformed(ActionEvent e) { int multinameIndex = decompiledTextArea.getMultinameUnderCaret(); if (multinameIndex > -1) { - UsageFrame usageFrame = new UsageFrame(swf.abcList, abc, multinameIndex, ABCPanel.this, false); + UsageFrame usageFrame = new UsageFrame(swf.getAbcList(), abc, multinameIndex, ABCPanel.this, false); usageFrame.setVisible(true); } } @@ -471,7 +472,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se } int multinameIndex = constantTable.convertRowIndexToModel(rowIndex); if (multinameIndex > 0) { - UsageFrame usageFrame = new UsageFrame(t.swf.abcList, abc, multinameIndex, t, false); + UsageFrame usageFrame = new UsageFrame(t.swf.getAbcList(), abc, multinameIndex, t, false); usageFrame.setVisible(true); } } @@ -505,19 +506,19 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se if (multinameIndex == 0) { return false; } - List usages = abc.findMultinameDefinition(swf.abcList, multinameIndex); + List usages = abc.findMultinameDefinition(swf.getAbcList(), multinameIndex); Multiname m = abc.constants.constant_multiname.get(multinameIndex); //search other ABC tags if this is not private multiname if (m.namespace_index > 0 && abc.constants.constant_namespace.get(m.namespace_index).kind != Namespace.KIND_PRIVATE) { - for (ABCContainerTag at : swf.abcList) { + for (ABCContainerTag at : swf.getAbcList()) { ABC a = at.getABC(); if (a == abc) { continue; } int mid = a.constants.getMultinameId(m, false); if (mid > 0) { - usages.addAll(a.findMultinameDefinition(swf.abcList, mid)); + usages.addAll(a.findMultinameDefinition(swf.getAbcList(), mid)); } } } @@ -539,32 +540,32 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se Reference multinameIndexRef = new Reference<>(0); if (decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef)) { - UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(swf.abcList, swf.abcList.get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(), classIndex.getVal(), traitIndex.getVal(), classTrait.getVal(), null, -1) { + UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(swf.getAbcList(), swf.getAbcList().get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(), classIndex.getVal(), traitIndex.getVal(), classTrait.getVal(), null, -1) { }); return; } int multinameIndex = decompiledTextArea.getMultinameAtPos(pos); if (multinameIndex > -1) { - List usages = abc.findMultinameDefinition(swf.abcList, multinameIndex); + List usages = abc.findMultinameDefinition(swf.getAbcList(), multinameIndex); Multiname m = abc.constants.constant_multiname.get(multinameIndex); //search other ABC tags if this is not private multiname if (m.namespace_index > 0 && abc.constants.constant_namespace.get(m.namespace_index).kind != Namespace.KIND_PRIVATE) { - for (ABCContainerTag at : swf.abcList) { + for (ABCContainerTag at : swf.getAbcList()) { ABC a = at.getABC(); if (a == abc) { continue; } int mid = a.constants.getMultinameId(m, false); if (mid > 0) { - usages.addAll(a.findMultinameDefinition(swf.abcList, mid)); + usages.addAll(a.findMultinameDefinition(swf.getAbcList(), mid)); } } } //more than one? display list if (usages.size() > 1) { - UsageFrame usageFrame = new UsageFrame(swf.abcList, abc, multinameIndex, ABCPanel.this, true); + UsageFrame usageFrame = new UsageFrame(swf.getAbcList(), abc, multinameIndex, ABCPanel.this, true); usageFrame.setVisible(true); return; } else if (!usages.isEmpty()) { //one @@ -699,7 +700,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se public void updateSearchPos(ABCPanelSearchResult item) { ScriptPack pack = item.scriptPack; setAbc(pack.abc); - decompiledTextArea.setScript(pack, swf.abcList); + decompiledTextArea.setScript(pack, swf.getAbcList()); hilightScript(pack); decompiledTextArea.setCaretPosition(0); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 668c9b450..ff3b248d5 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -76,7 +76,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi } public void setHex(ScriptExportMode exportMode, boolean force) { - if (this.exportMode == exportMode & !force) { + if (this.exportMode == exportMode && !force) { return; } this.exportMode = exportMode; @@ -274,9 +274,9 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi lineStart = i + 1; } } - if (lineCnt == -1) { - //lineEnd = text.length() - 1; - } + //if (lineCnt == -1) { + // lineEnd = text.length() - 1; + //} //select(lineStart, lineEnd); setCaretPosition(lineStart); //requestFocus(); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index c13c8ee91..610342d37 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -85,8 +85,8 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } public void fireScript() { - for (int i = 0; i < scriptListeners.size(); i++) { - scriptListeners.get(i).run(); + for (Runnable scriptListener : scriptListeners) { + scriptListener.run(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/TraitsList.java b/src/com/jpexs/decompiler/flash/gui/abc/TraitsList.java index 0b4ed530c..5c1923f5d 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/TraitsList.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/TraitsList.java @@ -55,13 +55,13 @@ public class TraitsList extends JList implements ListSelectionListener { setBackground(Color.white); } - public void clearABC() { + public void clearAbc() { this.abc = null; this.abcTags = null; setModel(new DefaultListModel<>()); } - public void setABC(List abcTags, ABC abc) { + public void setAbc(List abcTags, ABC abc) { this.abc = abc; this.abcTags = abcTags; setModel(new DefaultListModel<>()); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 173d26431..cb8d06b24 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -548,3 +548,5 @@ menu.tools.replace = Text Replace message.confirm.close = There are unsaved changes. Do you really want to close {swfName}? message.confirm.closeAll = There are unsaved changes. Do you really want to close all SWFs? + +contextmenu.exportJavaSource = Export Java Source diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties index dba6fc19b..ec6757983 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties @@ -548,3 +548,5 @@ menu.tools.replace = Sz\u00f6veg csere message.confirm.close = Mentetlen v\u00e1ltoz\u00e1sok vannak. Szeretm\u00e9 m\u00e9gis bez\u00e9rni a k\u00f6vetkez\u0151t: {swfName}? message.confirm.closeAll = Mentetlen v\u00e1ltoz\u00e1sok vannak. Szeretn\u00e9 bez\u00e1rni az \u00f6sszes SWF-t ? + +contextmenu.exportJavaSource = Java k\u00f3d export\u00e1l\u00e1s diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 84376efa8..71a9823e1 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -76,6 +76,7 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { private JMenuItem replaceMenuItem; private JMenuItem rawEditMenuItem; private JMenuItem jumpToCharacterMenuItem; + private JMenuItem exportJavaSourceMenuItem; private JMenuItem closeMenuItem; private JMenu addTagMenu; private JMenu moveTagMenu; @@ -122,6 +123,11 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { jumpToCharacterMenuItem.setVisible(false); add(jumpToCharacterMenuItem); + exportJavaSourceMenuItem = new JMenuItem(mainPanel.translate("contextmenu.exportJavaSource")); + exportJavaSourceMenuItem.setActionCommand(MainFrameRibbonMenu.ACTION_EXPORT_JAVA_SOURCE); + exportJavaSourceMenuItem.addActionListener(mainPanel); + add(exportJavaSourceMenuItem); + closeMenuItem = new JMenuItem(mainPanel.translate("contextmenu.closeSwf")); closeMenuItem.setActionCommand(ACTION_CLOSE_SWF); closeMenuItem.addActionListener(this); @@ -398,7 +404,7 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { } CharacterIdTag characterIdTag = (CharacterIdTag) itemj; - mainPanel.setTagTreeSelectedNode(itemj.getSwf().characters.get(characterIdTag.getCharacterId())); + mainPanel.setTagTreeSelectedNode(itemj.getSwf().getCharacter(characterIdTag.getCharacterId())); } break; case ACTION_EXPAND_RECURSIVE: { diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java index 69c103f09..4ef00db32 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java @@ -227,8 +227,8 @@ public class TagTreeModel implements TreeModel { nodeList.add(otherNode); } - if (swf.isAS3) { - if (!swf.abcList.isEmpty()) { + if (swf.isAS3()) { + if (!swf.getAbcList().isEmpty()) { nodeList.add(new ClassesListTreeModel(swf)); } } else { diff --git a/src/com/jpexs/decompiler/flash/gui/timeline/TimelineBodyPanel.java b/src/com/jpexs/decompiler/flash/gui/timeline/TimelineBodyPanel.java index 9c194e31a..e063414c5 100644 --- a/src/com/jpexs/decompiler/flash/gui/timeline/TimelineBodyPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/timeline/TimelineBodyPanel.java @@ -142,7 +142,7 @@ public class TimelineBodyPanel extends JPanel implements MouseListener, KeyListe flPrev = timeLine.getFrames().get(f - 1).layers.get(d); } - CharacterTag cht = fl == null ? null : timeLine.swf.characters.get(fl.characterId); + CharacterTag cht = fl == null ? null : timeLine.swf.getCharacter(fl.characterId); boolean shapeTween = cht != null && (cht instanceof MorphShapeTag); boolean motionTweenStart = (!motionTween) && (flNext != null && flNext.motionTween); boolean motionTweenEnd = (!motionTween) && (flPrev != null && flPrev.motionTween);