diff --git a/CHANGELOG.md b/CHANGELOG.md index cd012614d..52c18c496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - [#1973] FLA export - improper calculation of shape instance count - FLA export - XML formatting with blank lines on Java9+ - [#1974] DefineBits image reading problem +- [#1963] AS2 properly decompile/direct edit long classes ## [18.3.5] - 2023-02-12 ### Added @@ -2963,11 +2964,11 @@ All notable changes to this project will be documented in this file. [#1972]: https://www.free-decompiler.com/flash/issues/1972 [#1973]: https://www.free-decompiler.com/flash/issues/1973 [#1974]: https://www.free-decompiler.com/flash/issues/1974 +[#1963]: https://www.free-decompiler.com/flash/issues/1963 [#1959]: https://www.free-decompiler.com/flash/issues/1959 [#1960]: https://www.free-decompiler.com/flash/issues/1960 [#1964]: https://www.free-decompiler.com/flash/issues/1964 [#1961]: https://www.free-decompiler.com/flash/issues/1961 -[#1963]: https://www.free-decompiler.com/flash/issues/1963 [#1968]: https://www.free-decompiler.com/flash/issues/1968 [#1971]: https://www.free-decompiler.com/flash/issues/1971 [#1957]: https://www.free-decompiler.com/flash/issues/1957 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java index 86bc28986..6cef1bccf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java @@ -84,6 +84,8 @@ public class SourceGeneratorLocalData implements Serializable { public List> catchesOpenedLoops = new ArrayList<>(); public List catchesTempRegs = new ArrayList<>(); + + public boolean secondRun = false; public String getFullClass() { return pkg == null ? currentClass : pkg.addWithSuffix(currentClass).toRawString(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionScript2ClassDetector.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionScript2ClassDetector.java index 0ff407e43..17f826bf5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionScript2ClassDetector.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionScript2ClassDetector.java @@ -695,6 +695,8 @@ public class ActionScript2ClassDetector { } else if (item instanceof DirectValueActionItem) { //ignore such values //TODO: maybe somehow display in the class ? + } else if (item instanceof ScriptEndItem){ + //ignore } else { throw new AssertException("unknown item - " + item.getClass().getSimpleName()); } @@ -812,7 +814,13 @@ public class ActionScript2ClassDetector { } List classPath = pathToSearchVariant1; classPath.remove(0); //remove _global - if (this.checkClassContent(ifItem.onTrue, variables, 0, pos, checkPos, commands, classPath, scriptPath)) { + if (ifItem.onTrue.isEmpty()) { //if can have zero offset as the code is larger than bytes limit. TODO: make this check also for variant 2 (?) + if (this.checkClassContent(commands, variables, checkPos + 1, pos, commands.size() - 1, commands, classPath, scriptPath)) { + return true; + } else { + break check_variant1; + } + } else if (this.checkClassContent(ifItem.onTrue, variables, 0, pos, checkPos, commands, classPath, scriptPath)) { return true; } else { break check_variant1; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index 06eb011e3..0e122f9a8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -2334,16 +2334,17 @@ public class ActionScript2Parser { return retTree; } - private List generateActionList(List tree, List constantPool) throws CompilationException { + private List generateActionList(List tree, List constantPool, boolean secondRun) throws CompilationException { ActionSourceGenerator gen = new ActionSourceGenerator(swfVersion, constantPool, charset); SourceGeneratorLocalData localData = new SourceGeneratorLocalData(new HashMap<>(), 0, Boolean.FALSE, 0); + localData.secondRun = secondRun; return gen.generate(localData, tree); } private List actionsFromTree(List tree, List constantPool, boolean doOrder, String charset) throws CompilationException, NeedsGenerateAgainException { List ret = new ArrayList<>(); - List srcList = generateActionList(tree, constantPool); + List srcList = generateActionList(tree, constantPool, doOrder == false); if (doOrder) { List orderedConstantPool = new ArrayList<>(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java index 58243e822..08921cd46 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java @@ -75,6 +75,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.logging.Logger; /** * @@ -868,7 +869,14 @@ public class ActionSourceGenerator implements SourceGenerator { ret.addAll(typeToActions(globalClassTypeStr, null)); ret.add(new ActionNot()); ret.add(new ActionNot()); - ret.add(new ActionIf(Action.actionsToBytes(ifbody, false, SWF.DEFAULT_VERSION).length,charset)); + int ifOffset = Action.actionsToBytes(ifbody, false, SWF.DEFAULT_VERSION).length; + if (ifOffset > 0x7fff) { + if (!localData.secondRun) { //to avoid printing the warning twice + Logger.getLogger(ActionSourceGenerator.class.getName()).warning("The class is long. If offset for its header would be longer than max value for SI16, 0 was stored instead. This should not have any negative impact."); + } + ifOffset = 0; + } + ret.add(new ActionIf(ifOffset, charset)); ret.addAll(ifbody); ret.add(new ActionPop()); return ret;