From e33474d6f99812e12f3ae883fc86ec32325022b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 14 Nov 2022 18:06:25 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20#1867=20AS3=20-=20=C2=A7=C2=A7hasnext,?= =?UTF-8?q?=20=C2=A7=C2=A7nextvalue,=20=C2=A7=C2=A7nextname=20in=20some=20?= =?UTF-8?q?nonstandard=20compiled=20SWFs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 +++- .../decompiler/flash/abc/AVM2LocalData.java | 2 +- .../flash/abc/avm2/graph/AVM2Graph.java | 35 +++++++++++++++++++ .../abc/avm2/model/NextNameAVM2Item.java | 6 ++++ .../abc/avm2/model/NextValueAVM2Item.java | 6 ++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f91e60107..34edb2e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed +- [#1867] AS3 - §§hasnext, §§nextvalue, §§nextname in some nonstandard compiled SWFs ## [16.3.0] - 2022-11-14 ### Added @@ -2438,7 +2440,8 @@ All notable changes to this project will be documented in this file. ### Added - Initial public release -[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.2.0...dev +[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.3.0...dev +[16.3.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.2.0...version16.3.0 [16.2.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.1.0...version16.2.0 [16.1.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.0.4...version16.1.0 [16.0.4]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.0.3...version16.0.4 @@ -2566,6 +2569,7 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1867]: https://www.free-decompiler.com/flash/issues/1867 [#1649]: https://www.free-decompiler.com/flash/issues/1649 [#1701]: https://www.free-decompiler.com/flash/issues/1701 [#1864]: https://www.free-decompiler.com/flash/issues/1864 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java index e33e16442..d4615063f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java @@ -119,7 +119,7 @@ public class AVM2LocalData extends BaseLocalData { public boolean inGetLoops = false; public Set seenMethods = new HashSet<>(); - + public AVM2LocalData() { } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index 240f0145b..0624f141f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -80,6 +80,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.clauses.TryAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.StrictEqAVM2Item; import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphException; @@ -88,6 +89,7 @@ import com.jpexs.decompiler.graph.GraphPartChangeException; import com.jpexs.decompiler.graph.GraphSource; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.Loop; import com.jpexs.decompiler.graph.ScopeStack; import com.jpexs.decompiler.graph.StopPartKind; @@ -1906,7 +1908,40 @@ public class AVM2Graph extends Graph { } else if (gti instanceof NextNameAVM2Item) { return new ForInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(), varName, collection), w.commands); } + } else { + GraphTargetItem first = w.commands.get(0); + Reference kindRef = new Reference<>(0); + first.visitRecursively(new AbstractGraphTargetVisitor() { + private boolean handled = false; + @Override + public void visit(GraphTargetItem item) { + if (handled) { + return; + } + if ((item instanceof NextNameAVM2Item) || (item instanceof NextValueAVM2Item)) { + handled = true; + if (item instanceof NextValueAVM2Item){ + NextValueAVM2Item nv = (NextValueAVM2Item) item; + nv.localReg = hn.index; + kindRef.setVal(1); + } + if (item instanceof NextNameAVM2Item){ + NextNameAVM2Item nn = (NextNameAVM2Item) item; + nn.localReg = hn.index; + kindRef.setVal(2); + } + } + } + }); + + if (kindRef.getVal() == 1) { + return new ForEachInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(), hn.index, hn.obj), w.commands); + } + if (kindRef.getVal() == 2) { + return new ForInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(),hn.index , hn.obj), w.commands); + } } + } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextNameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextNameAVM2Item.java index e642f9875..53f32abf0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextNameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextNameAVM2Item.java @@ -38,6 +38,8 @@ public class NextNameAVM2Item extends AVM2Item { public GraphTargetItem index; public GraphTargetItem obj; + + public GraphTargetItem localReg; public NextNameAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem index, GraphTargetItem obj) { super(instruction, lineStartIns, NOPRECEDENCE); @@ -53,6 +55,10 @@ public class NextNameAVM2Item extends AVM2Item { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + if (localReg != null) { + localReg.appendTo(writer, localData); + return writer; + } writer.append("§§nextname"); writer.spaceBeforeCallParenthesies(2); writer.append("("); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextValueAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextValueAVM2Item.java index 606d18368..a3e8c57c7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextValueAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NextValueAVM2Item.java @@ -38,6 +38,8 @@ public class NextValueAVM2Item extends AVM2Item { public GraphTargetItem index; public GraphTargetItem obj; + + public GraphTargetItem localReg; public NextValueAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem index, GraphTargetItem obj) { super(instruction, lineStartIns, NOPRECEDENCE); @@ -58,6 +60,10 @@ public class NextValueAVM2Item extends AVM2Item { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + if (localReg != null) { + localReg.appendTo(writer, localData); + return writer; + } writer.append("§§nextvalue"); writer.spaceBeforeCallParenthesies(2); writer.append("(");