diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d015f599..976fbae27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - [#1763] AS3 - initialization of activation object in some cases - AS3 - direct editation - arguments object on method with activation - AS3 - direct editation - bit not +- AS3 - direct editation - call on local register ## [15.0.0] - 2021-11-29 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java index dac380048..16a0fcce8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java @@ -78,34 +78,33 @@ public class CallAVM2Item extends AVM2Item { } if (callable instanceof NameAVM2Item) { NameAVM2Item n = (NameAVM2Item) callable; - /*List allAbcs = new ArrayList<>(); - allAbcs.add(g.abc); - allAbcs.addAll(g.allABCs);*/ - String cname = localData.currentClass; - DottedChain pkgName = localData.pkg; - GraphTargetItem obj = null; - Reference outName = new Reference<>(""); - Reference outNs = new Reference<>(DottedChain.EMPTY); - Reference outPropNs = new Reference<>(DottedChain.EMPTY); - Reference outPropNsKind = new Reference<>(1); - Reference outPropNsIndex = new Reference<>(0); - Reference outPropType = new Reference<>(null); - Reference outPropValue = new Reference<>(null); - Reference outPropValueABC = new Reference<>(null); - List otherNs = new ArrayList<>(); - for (NamespaceItem on : openedNamespaces) { - if (on.isResolved()) { - otherNs.add(on.getCpoolIndex(g.abcIndex)); + if (!localData.registerVars.containsKey(n.getVariableName())) { + String cname = localData.currentClass; + DottedChain pkgName = localData.pkg; + GraphTargetItem obj = null; + Reference outName = new Reference<>(""); + Reference outNs = new Reference<>(DottedChain.EMPTY); + Reference outPropNs = new Reference<>(DottedChain.EMPTY); + Reference outPropNsKind = new Reference<>(1); + Reference outPropNsIndex = new Reference<>(0); + Reference outPropType = new Reference<>(null); + Reference outPropValue = new Reference<>(null); + Reference outPropValueABC = new Reference<>(null); + List otherNs = new ArrayList<>(); + for (NamespaceItem on : openedNamespaces) { + if (on.isResolved()) { + otherNs.add(on.getCpoolIndex(g.abcIndex)); + } } + if (cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueABC)) { + NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), n.line, "this", null, false, n.openedNamespaces, abcIndex); + nobj.setRegNumber(0); + obj = nobj; + } + PropertyAVM2Item p = new PropertyAVM2Item(obj, n.getVariableName(), g.abcIndex, n.openedNamespaces, new ArrayList<>()); + p.setAssignedValue(n.getAssignedValue()); + callable = p; } - if (cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueABC)) { - NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), n.line, "this", null, false, n.openedNamespaces, abcIndex); - nobj.setRegNumber(0); - obj = nobj; - } - PropertyAVM2Item p = new PropertyAVM2Item(obj, n.getVariableName(), g.abcIndex, n.openedNamespaces, new ArrayList<>()); - p.setAssignedValue(n.getAssignedValue()); - callable = p; } int propIndex = -1; diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java index 903e5f465..2e1ae07f1 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java @@ -35,6 +35,13 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile false); } + @Test + public void testCallLocal() { + decompileMethod("classic_air", "testCallLocal", "var f:Function = getF();\r\n" + + "var b:int = f(1,3);\r\n", + false); + } + @Test public void testCatchFinally() { decompileMethod("classic_air", "testCatchFinally", "var a:int = 5;\r\n" diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java index bc8f6a150..28c0350ea 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java @@ -35,6 +35,13 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes false); } + @Test + public void testCallLocal() { + decompileMethod("classic", "testCallLocal", "var f:Function = this.getF();\r\n" + + "var b:int = f(1,3);\r\n", + false); + } + @Test public void testCatchFinally() { decompileMethod("classic", "testCatchFinally", "var a:* = 5;\r\n" diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf index af8abec9b..2564af4ef 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf index 999321e54..ff926929a 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as index 9b67fd771..07f038411 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as @@ -17,6 +17,7 @@ package { TestActivationArguments; TestArguments; + TestCallLocal; TestCatchFinally; TestChain2; TestChainedAssignments; diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallLocal.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallLocal.as new file mode 100644 index 000000000..50f69eea6 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallLocal.as @@ -0,0 +1,19 @@ +package tests +{ + + public class TestCallLocal + { + public function getF(): Function + { + return function(a:int, b:int):int { + return a + b; + }; + } + + public function run():* + { + var f:Function = getF(); + var b:int = f(1, 3); + } + } +}