diff --git a/CHANGELOG.md b/CHANGELOG.md index e33e26605..a5d760e51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - [#1891] AS3 - duplicate variable declaration in some cases - All SWF classes inside DoABC tags in the taglist view - Exception on package selection inside DoABC tag on taglist view +- [#1892] AS3 - Package internal custom namespaces ## [17.0.2] - 2022-11-22 ### Fixed @@ -2661,6 +2662,7 @@ All notable changes to this project will be documented in this file. [#1890]: https://www.free-decompiler.com/flash/issues/1890 [#1810]: https://www.free-decompiler.com/flash/issues/1810 [#1891]: https://www.free-decompiler.com/flash/issues/1891 +[#1892]: https://www.free-decompiler.com/flash/issues/1892 [#1882]: https://www.free-decompiler.com/flash/issues/1882 [#1880]: https://www.free-decompiler.com/flash/issues/1880 [#1881]: https://www.free-decompiler.com/flash/issues/1881 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java index 93aa0126a..b8a634ae6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -2128,10 +2128,13 @@ public class ABC implements Openable { return null; } Namespace ns = constants.getNamespace(link_ns_index); - if (ns.kind != Namespace.KIND_NAMESPACE) { + if (ns.kind != Namespace.KIND_NAMESPACE && ns.kind != Namespace.KIND_PACKAGE_INTERNAL) { return null; } String name = constants.getString(ns.name_index); + if (name.equals("http://adobe.com/AS3/2006/builtin")) { + return null; + } for (ABCContainerTag abcTag : getAbcTags()) { DottedChain dc = abcTag.getABC().nsValueToName(name); nsname = dc.getLast(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java index 6c8dfa389..656c1796b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java @@ -135,7 +135,7 @@ public class FullMultinameAVM2Item extends AVM2Item { AVM2ConstantPool constants = localData.constantsAvm2; List fullyQualifiedNames = property ? new ArrayList<>() : localData.fullyQualifiedNames; if (multinameIndex > 0 && multinameIndex < constants.getMultinameCount()) { - writer.append(constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames, false, true)); + writer.append(constants.getMultiname(multinameIndex).getNameWithCustomNamespace(localData.abc, fullyQualifiedNames, false, true)); } else { writer.append("§§multiname(").append(multinameIndex).append(")"); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java index e66e4bb6c..48c6713b1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java @@ -363,7 +363,8 @@ public class Multiname { } else { String name = abc.constants.getString(name_index); - if (namespace_index > 0 && getNamespace(abc.constants).kind == Namespace.KIND_NAMESPACE) { + int nskind = namespace_index <= 0 ? -1 : getNamespace(abc.constants).kind; + if (nskind == Namespace.KIND_NAMESPACE || nskind == Namespace.KIND_PACKAGE_INTERNAL) { DottedChain dc = abc.findCustomNs(namespace_index); String nsname = dc != null ? dc.getLast() : null; 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 b3f432cba..8cbe5bf15 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 @@ -190,6 +190,21 @@ public abstract class Trait implements Cloneable, Serializable { return false; } + + public void writeUses(int scriptIndex, int classIndex, boolean isStatic, ABC abc, GraphTextWriter writer) throws InterruptedException { + List dependencies = new ArrayList<>(); + List uses = new ArrayList<>(); + String customNs = null; + Namespace ns = getName(abc).getNamespace(abc.constants); + if (ns.kind == Namespace.KIND_NAMESPACE) { + customNs = ns.getName(abc.constants).toRawString(); + } + getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, uses, null, new ArrayList<>()); + for (String us : uses) { + writer.appendNoHilight("use namespace " + us + ";").newLine(); + } + } + public void writeImportsUsages(int scriptIndex, int classIndex, boolean isStatic, ABC abc, GraphTextWriter writer, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { List namesInThisPackage = new ArrayList<>(); @@ -275,12 +290,12 @@ public abstract class Trait implements Cloneable, Serializable { if (hasImport) { writer.newLine(); } - for (String us : uses) { + /*for (String us : uses) { writer.appendNoHilight("use namespace " + us + ";").newLine(); } if (uses.size() > 0) { writer.newLine(); - } + }*/ } public final GraphTextWriter getMetaData(Trait parent, ConvertData convertData, ABC abc, GraphTextWriter writer) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index 07a61f5d2..bb5cff694 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -90,6 +90,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { writer.startBlock(); int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { + //writeUses(scriptIndex, classIndex, isStatic, abc, writer); abc.bodies.get(bodyIndex).toString(abcIndex,path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false, true), exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); } writer.endBlock(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index c7c726f88..51bc0ba67 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -145,6 +145,7 @@ public class TraitMethodGetterSetter extends Trait { convertTraitHeader(abc, writer); } if (bodyIndex != -1) { + //writeUses(scriptIndex, classIndex, isStatic, abc, writer); abc.bodies.get(bodyIndex).toString(abcIndex, path, exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); } } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java index 30f1c43ed..2bf1e2801 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java @@ -189,7 +189,7 @@ public class DependencyParser { private static boolean parseUsagesFromNS(String ignoredCustom, ABC abc, List dependencies, List uses, int namespace_index, DottedChain ignorePackage, String name) { Namespace ns = abc.constants.getNamespace(namespace_index); - if (ns.kind == Namespace.KIND_NAMESPACE) { + if (ns.kind == Namespace.KIND_NAMESPACE || ns.kind == Namespace.KIND_PACKAGE_INTERNAL) { String nsVal = ns.getName(abc.constants).toRawString(); for (ABCContainerTag abcTag : abc.getAbcTags()) { DottedChain nsimport = abcTag.getABC().nsValueToName(nsVal); @@ -199,7 +199,7 @@ public class DependencyParser { if (!nsimport.isEmpty()) { Dependency depNs = new Dependency(nsimport, DependencyType.NAMESPACE); - if (!nsimport.getWithoutLast().equals(ignorePackage) && !dependencies.contains(depNs)) { + if ((ignorePackage == null || !nsimport.getWithoutLast().equals(ignorePackage)) && !dependencies.contains(depNs)) { dependencies.add(depNs); } if (ignoredCustom != null && nsVal.equals(ignoredCustom)) { 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 b98625d86..3741ae012 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 @@ -1271,7 +1271,8 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var a:* = ns::unnamespacedFunc();\r\n" + "var b:* = ns::[name];\r\n" + "trace(b.c);\r\n" - + "var c:int = myInternal::neco;\r\n", + + "var c:int = myInternal::neco;\r\n" + + "var d:int = myInternal2::neco;\r\n", false); } 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 016ffc7c3..e375f7cac 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 @@ -1266,7 +1266,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var a:* = ns::unnamespacedFunc();\r\n" + "var b:* = ns::[name];\r\n" + "trace(b.c);\r\n" - + "var c:* = myInternal::neco;\r\n", + + "var c:* = myInternal::neco;\r\n" + + "var d:* = this.myInternal2::neco;\r\n", false); } 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 d93a361ac..ae2a2f35a 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 13fff6c80..a0b1cadf3 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/tests/TestNames.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as index 2b97da03c..28eacd50e 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as @@ -1,10 +1,15 @@ package tests { import tests_other.myInternal; + import tests_other.myInternal2; + + public class TestNames { - myInternal var neco:int; + myInternal var neco:int; + myInternal2 var neco:int; + var nic:int; public function run():* { @@ -13,8 +18,10 @@ package tests var a:* = ns::unnamespacedFunc(); var b:* = ns::[name]; trace(b.c); - var c:* = myInternal::neco; - } + var c:* = myInternal::neco; + use namespace myInternal2; + var d:* = neco; + } public function getNamespace():Namespace { @@ -30,5 +37,10 @@ package tests { trace("hello"); } + + myInternal2 function namespacedFunc2() : void + { + trace("hello"); + } } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests_other/myInternal2.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests_other/myInternal2.as new file mode 100644 index 000000000..22f751d5a --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests_other/myInternal2.as @@ -0,0 +1,4 @@ +package tests_other +{ + public namespace myInternal2; +} \ No newline at end of file