From 0a0e04bab8cd91cce8bd653ff427a6792dcc2340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 25 Feb 2021 20:51:27 +0100 Subject: [PATCH] handling imported vars fix --- .../parser/script/AVM2SourceGenerator.java | 2 ++ .../abc/avm2/parser/script/CallAVM2Item.java | 3 +++ ...leItem.java => ImportedSlotConstItem.java} | 20 ++++++++++++++----- .../parser/script/UnresolvedAVM2Item.java | 11 +++++----- libsrc/ffdec_lib/testdata/as3_new/src/Main.as | 1 + .../as3_new/src/tests/TestImportedVar.as | 14 +++++++++++++ 6 files changed, 41 insertions(+), 10 deletions(-) rename libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/{TypeAssignableItem.java => ImportedSlotConstItem.java} (91%) create mode 100644 libsrc/ffdec_lib/testdata/as3_new/src/tests/TestImportedVar.as 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 04873d0d8..5fb8f42ab 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 @@ -2709,6 +2709,8 @@ public class AVM2SourceGenerator implements SourceGenerator { typeItem = item; } else if (item instanceof ApplyTypeAVM2Item) { typeItem = ((ApplyTypeAVM2Item) item).object; + } else if (item instanceof ImportedSlotConstItem) { + typeItem = ((ImportedSlotConstItem) item).type; } else { throw new CompilationException("Invalid type:" + item + " (" + item.getClass().getName() + ")", 0/*??*/); } 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 2533ea3a5..f413ca034 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 @@ -73,6 +73,9 @@ public class CallAVM2Item extends AVM2Item { if (callable instanceof UnresolvedAVM2Item) { callable = ((UnresolvedAVM2Item) callable).resolved; } + if (callable instanceof ImportedSlotConstItem) { + callable = ((ImportedSlotConstItem) callable).type; + } if (callable instanceof NameAVM2Item) { NameAVM2Item n = (NameAVM2Item) callable; /*List allAbcs = new ArrayList<>(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/TypeAssignableItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ImportedSlotConstItem.java similarity index 91% rename from libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/TypeAssignableItem.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ImportedSlotConstItem.java index 9932176e3..beafe01dd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/TypeAssignableItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ImportedSlotConstItem.java @@ -30,11 +30,11 @@ import java.util.List; * * @author JPEXS */ -public class TypeAssignableItem extends AssignableAVM2Item { +public class ImportedSlotConstItem extends AssignableAVM2Item { - private final TypeItem type; + public TypeItem type; - public TypeAssignableItem(TypeItem type) { + public ImportedSlotConstItem(TypeItem type) { this.type = type; } @@ -50,12 +50,12 @@ public class TypeAssignableItem extends AssignableAVM2Item { @Override public GraphTargetItem returnType() { - return TypeItem.UNBOUNDED; + return type.returnType(); } @Override public AssignableAVM2Item copy() { - return new TypeAssignableItem(type); + return new ImportedSlotConstItem(type); } public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { @@ -116,4 +116,14 @@ public class TypeAssignableItem extends AssignableAVM2Item { return ret; } + @Override + public String toString() { + return type.toString(); + } + + @Override + public String toString(LocalData localData) throws InterruptedException { + return super.toString(localData); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java index 52153d1e9..774d562b2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java @@ -330,11 +330,12 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } if (name.size() == 1) { - resolved = new TypeAssignableItem(ret); - //TODO: check whether it is really an assignable and not a Class - if (assignedValue != null) { - ((TypeAssignableItem) resolved).assignedValue = assignedValue; - //throw new CompilationException("Cannot assign type", line); + AbcIndexing.TraitIndex ti = abc.findScriptProperty(imp); + if (ti != null && (ti.trait instanceof TraitSlotConst)) { + resolved = new ImportedSlotConstItem(ret); + if (assignedValue != null) { + ((ImportedSlotConstItem) resolved).assignedValue = assignedValue; + } } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as index 5f8d56e00..73b3c1067 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as @@ -54,6 +54,7 @@ package TestIfElse; TestIfInIf; TestIgnoreAndOr; + TestImportedVar; TestInc2; TestIncDec; TestInlineFunctions; diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestImportedVar.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestImportedVar.as new file mode 100644 index 000000000..45f1d8381 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestImportedVar.as @@ -0,0 +1,14 @@ +package tests +{ + import tests_classes.myvar; + + public class TestImportedVar + { + public function run():void + { + trace(myvar); + //myvar++; + myvar = 5; + } + } +}