diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java index 938dd580a..74ea5c78b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java @@ -72,9 +72,9 @@ public class GetLexIns extends InstructionDefinition { GraphTargetItem thisPropType = TypeItem.UNBOUNDED; if (currentClassName != null) { if (call) { - thisPropType = localData.abcIndex.findPropertyCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true); + thisPropType = localData.abcIndex.findPropertyCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true, true); } else { - thisPropType = localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true); + thisPropType = localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true, true); } } if (!thisPropType.equals(TypeItem.UNBOUNDED)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetPropertyIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetPropertyIns.java index 74cb75334..b0cbe5d3f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetPropertyIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetPropertyIns.java @@ -165,9 +165,9 @@ public class GetPropertyIns extends InstructionDefinition { GraphTargetItem thisPropType = TypeItem.UNBOUNDED; if (currentClassName != null) { if (call) { - thisPropType = localData.abcIndex.findPropertyCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true); + thisPropType = localData.abcIndex.findPropertyCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true, true); } else { - thisPropType = localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true); + thisPropType = localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true, true); } } if (!thisPropType.equals(TypeItem.UNBOUNDED)) { @@ -230,9 +230,9 @@ public class GetPropertyIns extends InstructionDefinition { if (type == null) { if (call) { - type = localData.abcIndex.findPropertyCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic); + type = localData.abcIndex.findPropertyCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic, false); } else { - type = localData.abcIndex.findPropertyType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic); + type = localData.abcIndex.findPropertyType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic, false); } } } 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 2dd1b8fa7..bce844be4 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 @@ -2636,7 +2636,7 @@ public class AVM2SourceGenerator implements SourceGenerator { isType.setVal(false); AbcIndexing.TraitIndex sp = abc.findScriptProperty(pkg.addWithSuffix(propertyName)); if (sp == null) { - sp = abc.findProperty(new AbcIndexing.PropertyDef(propertyName, new TypeItem(pkg.addWithSuffix(obj)), abc.getSelectedAbc(), selectedNs), !instanceOnly, true); + sp = abc.findProperty(new AbcIndexing.PropertyDef(propertyName, new TypeItem(pkg.addWithSuffix(obj)), abc.getSelectedAbc(), selectedNs), !instanceOnly, true, true); } if (sp != null) { if (sp.trait instanceof TraitClass) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java index f205ce27f..7e1135aa8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java @@ -108,6 +108,8 @@ public final class AbcIndexing { private final String propName; + private String propNsString = null; + private final GraphTargetItem parent; private int propNsIndex = 0; @@ -116,7 +118,7 @@ public final class AbcIndexing { @Override public String toString() { - return parent.toString() + ":" + propName + (propNsIndex > 0 ? "[ns:" + propNsIndex + "]" : ""); + return parent.toString() + ":" + propName + (propNsIndex > 0 ? "[ns:" + propNsIndex + "]" : "") + (propNsString != null ? "[ns: " + propNsString + "]" : ""); } private void setPrivate(ABC abc, int propNsIndex) { @@ -124,10 +126,19 @@ public final class AbcIndexing { this.abc = abc; } + private void setProtected(ABC abc, int propNsIndex) { + this.abc = null; + this.propNsString = abc.constants.getNamespace(propNsIndex).getRawName(abc.constants); + } + public String getPropertyName() { return propName; } + public String getPropNsString() { + return propNsString; + } + /** * Creates key to property. * @@ -154,24 +165,37 @@ public final class AbcIndexing { return; } int k = abc.constants.getNamespace(propNsIndex).kind; - if (k != Namespace.KIND_PACKAGE && propNsIndex != builtInIndex) { - setPrivate(abc, propNsIndex); + if (k != Namespace.KIND_PACKAGE && propNsIndex != builtInIndex) { + if (k == Namespace.KIND_PROTECTED) { + setProtected(abc, propNsIndex); + } else { + setPrivate(abc, propNsIndex); + } } } + + public PropertyDef(String propName, GraphTargetItem parent, String propNsString) { + this.propName = propName; + this.parent = parent; + this.abc = null; + this.propNsString = propNsString; + } @Override public int hashCode() { - int hash = 7; - hash = 17 * hash + Objects.hashCode(this.propName); - hash = 17 * hash + Objects.hashCode(this.parent); - hash = 17 * hash + this.propNsIndex; - //? - //hash = 17 * hash + System.identityHashCode(this.abc); + int hash = 3; + hash = 37 * hash + Objects.hashCode(this.propName); + hash = 37 * hash + Objects.hashCode(this.propNsString); + hash = 37 * hash + Objects.hashCode(this.parent); + hash = 37 * hash + this.propNsIndex; return hash; } @Override public boolean equals(Object obj) { + if (this == obj) { + return true; + } if (obj == null) { return false; } @@ -179,18 +203,18 @@ public final class AbcIndexing { return false; } final PropertyDef other = (PropertyDef) obj; - if (!Objects.equals(this.propName, other.propName)) { - return false; - } - if (!Objects.equals(this.parent, other.parent)) { - return false; - } if (this.propNsIndex != other.propNsIndex) { return false; } - return true; //? - //return (this.abc == other.abc); + if (!Objects.equals(this.propName, other.propName)) { + return false; + } + if (!Objects.equals(this.propNsString, other.propNsString)) { + return false; + } + return Objects.equals(this.parent, other.parent); } + } /** @@ -330,16 +354,16 @@ public final class AbcIndexing { return classes.get(cls); } - public GraphTargetItem findPropertyType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance) { - TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance); + public GraphTargetItem findPropertyType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected) { + TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected); if (traitIndex == null) { return TypeItem.UNBOUNDED; } return traitIndex.returnType; } - public GraphTargetItem findPropertyCallType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance) { - TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance); + public GraphTargetItem findPropertyCallType(ABC abc, GraphTargetItem cls, String propName, int ns, boolean findStatic, boolean findInstance, boolean findProtected) { + TraitIndex traitIndex = findProperty(new PropertyDef(propName, cls, abc, ns), findStatic, findInstance, findProtected); if (traitIndex == null) { return TypeItem.UNBOUNDED; } @@ -390,20 +414,20 @@ public final class AbcIndexing { return null; } - public TraitIndex findProperty(PropertyDef prop, boolean findStatic, boolean findInstance) { + public TraitIndex findProperty(PropertyDef prop, boolean findStatic, boolean findInstance, boolean findProtected) { /*System.out.println("searching " + prop); for (PropertyDef p : instanceProperties.keySet()) { - if (p.parent.equals(new TypeItem("__AS3__.vec.Vector"))) { + if (p.parent.equals(new TypeItem("tests_classes.TestConvertParent"))) { System.out.println("- " + p); } } - System.out.println("-----------");*/ - + System.out.println("-----------"); +*/ //search all static first if (findStatic && classProperties.containsKey(prop)) { if (!classProperties.containsKey(prop)) { if (parent != null) { - TraitIndex ret = parent.findProperty(prop, findStatic, findInstance); + TraitIndex ret = parent.findProperty(prop, findStatic, findInstance, findProtected); if (ret != null) { return ret; } @@ -417,7 +441,7 @@ public final class AbcIndexing { if (findInstance && instanceProperties.containsKey(prop)) { if (!instanceProperties.containsKey(prop)) { if (parent != null) { - TraitIndex ret = parent.findProperty(prop, findStatic, findInstance); + TraitIndex ret = parent.findProperty(prop, findStatic, findInstance, findProtected); if (ret != null) { return ret; } @@ -430,22 +454,26 @@ public final class AbcIndexing { //now search parent class AbcIndexing.ClassIndex ci = findClass(prop.parent); if (ci != null && ci.parent != null && (prop.abc == null || prop.propNsIndex == 0)) { - ci = ci.parent; - //parent protected - DottedChain parentClass = ci.abc.instance_info.get(ci.index).getName(ci.abc.constants).getNameWithNamespace(ci.abc.constants, true); - TraitIndex pti = findProperty(new PropertyDef(prop.propName, new TypeItem(parentClass), ci.abc, ci.abc.instance_info.get(ci.index).protectedNS), findStatic, findInstance); - if (pti != null) { - return pti; - } - //parent public - pti = findProperty(new PropertyDef(prop.propName, new TypeItem(parentClass), null, 0), findStatic, findInstance); + AbcIndexing.ClassIndex ciParent = ci.parent; + DottedChain parentClass = ciParent.abc.instance_info.get(ciParent.index).getName(ciParent.abc.constants).getNameWithNamespace(ciParent.abc.constants, true); + TraitIndex pti = findProperty(new PropertyDef(prop.propName, new TypeItem(parentClass), prop.getPropNsString()), findStatic, findInstance, findProtected); if (pti != null) { return pti; } } + /*if (findProtected && prop.propNsIndex == 0) { + if (ci != null) { + int protNs = ci.abc.instance_info.get(ci.index).protectedNS; + PropertyDef prop2 = new PropertyDef(prop.propName, prop.parent, prop.abc, protNs); + TraitIndex pti = findProperty(prop2, findStatic, findInstance, false); + if (pti != null) { + return pti; + } + } + }*/ if (parent != null) { - TraitIndex pti = parent.findProperty(prop, findStatic, findInstance); + TraitIndex pti = parent.findProperty(prop, findStatic, findInstance, findProtected); if (pti != null) { return pti; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java index aa357c28d..8d23c9e74 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java @@ -219,7 +219,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { // however this namespace is in the ABC of the super class and not in abcIndex.getSelectedAbc() AbcIndexing.ClassIndex ci = abcIndex.findClass(objType); int superProtectedNs = ci.abc.instance_info.get(ci.index).protectedNS; - AbcIndexing.TraitIndex sp = abcIndex.findProperty(new AbcIndexing.PropertyDef(propertyName, objType, ci.abc, superProtectedNs), false, true); + AbcIndexing.TraitIndex sp = abcIndex.findProperty(new AbcIndexing.PropertyDef(propertyName, objType, ci.abc, superProtectedNs), false, true, true); if (sp != null) { objType = sp.objType; Namespace ns = sp.trait.getName(sp.abc).getNamespace(sp.abc.constants); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 4b8184f53..61a091777 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -230,7 +230,7 @@ public class TraitClass extends Trait implements TraitWithSlot { if (sIndex > -1) { int nsIndex = abc.constants.getNamespaceId(Namespace.KIND_PACKAGE, DottedChain.TOPLEVEL, sIndex, false); if (nsIndex > -1) { - convertData.thisHasDefaultToPrimitive = null == index.findProperty(new AbcIndexing.PropertyDef("toString", new TypeItem(instanceInfo.getName(abc.constants).getNameWithNamespace(abc.constants, true)), abc, nsIndex), false, true); + convertData.thisHasDefaultToPrimitive = null == index.findProperty(new AbcIndexing.PropertyDef("toString", new TypeItem(instanceInfo.getName(abc.constants).getNameWithNamespace(abc.constants, true)), abc, nsIndex), false, true, false); } else { convertData.thisHasDefaultToPrimitive = true; } 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 3741ae012..72dc0c94b 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 @@ -222,9 +222,11 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile @Test public void testConvert() { - decompileMethod("classic_air", "testConvert", "var a:* = undefined;\r\n" - + "var s:String = \"a\";\r\n" - + "var i:int = int(s);\r\n" + decompileMethod("classic_air", "testConvert", "var s:* = null;\r\n" + + "var i:int = 0;\r\n" + + "var a:* = undefined;\r\n" + + "s = \"a\";\r\n" + + "i = int(s);\r\n" + "var j:int;\r\n" + "s = String(j = n);\r\n" + "s = ns;\r\n" @@ -247,7 +249,9 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "i = int(v[0]);\r\n" + "s = v[1];\r\n" + "s = v.join(\"x\");\r\n" - + "i = int(v.join(\"x\"));\r\n", + + "i = int(v.join(\"x\"));\r\n" + + "i = int(prot);\r\n" + + "s = prot;\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 e375f7cac..7393a461b 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 @@ -221,9 +221,11 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testConvert() { - decompileMethod("classic", "testConvert", "var a:* = undefined;\r\n" - + "var s:String = \"a\";\r\n" - + "var i:int = int(s);\r\n" + decompileMethod("classic", "testConvert", "var s:String = null;\r\n" + + "var i:int = 0;\r\n" + + "var a:* = undefined;\r\n" + + "s = \"a\";\r\n" + + "i = int(s);\r\n" + "var j:int = this.n;\r\n" + "s = String(j);\r\n" + "s = this.ns;\r\n" @@ -246,7 +248,9 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "i = int(v[0]);\r\n" + "s = v[1];\r\n" + "s = v.join(\"x\");\r\n" - + "i = int(v.join(\"x\"));\r\n", + + "i = int(v.join(\"x\"));\r\n" + + "i = int(prot);\r\n" + + "s = prot;\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 ae2a2f35a..88d8ed447 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 a0b1cadf3..837392d73 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/build_both_debug.bat b/libsrc/ffdec_lib/testdata/as3_new/build_both_debug.bat new file mode 100644 index 000000000..d84078bd2 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/build_both_debug.bat @@ -0,0 +1,3 @@ +@echo off +call build_flex_debug.bat +call build_air_debug.bat \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as index 8e6c093d7..e3c983303 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as @@ -1,7 +1,8 @@ package tests { + import tests_classes.TestConvertParent; - public class TestConvert + public class TestConvert extends TestConvertParent { private var n:int = 1; private var ns:String = "b"; @@ -12,8 +13,10 @@ package tests public function run():void { - var s:String = "a"; - var i:int = int(s); + var s:String; + var i:int; + s = "a"; + i = int(s); var j:int = n; var a:*; s = String(j); @@ -44,6 +47,9 @@ package tests s = v[1]; s = v.join("x"); i = int(v.join("x")); + + i = int(prot); + s = prot; } } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestConvertParent.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestConvertParent.as new file mode 100644 index 000000000..a340943fb --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestConvertParent.as @@ -0,0 +1,8 @@ +package tests_classes +{ + + public class TestConvertParent + { + protected var prot:String = "5"; + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 750f6f6b2..8f55c1a46 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -357,7 +357,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL if (parentType.equals("*")) { return false; } - AbcIndexing.TraitIndex propertyTraitIndex = indexing.findProperty(new AbcIndexing.PropertyDef(propName, new TypeItem(parentType), getABC(), data.namespaceIndex), data.isStatic, !data.isStatic); + AbcIndexing.TraitIndex propertyTraitIndex = indexing.findProperty(new AbcIndexing.PropertyDef(propName, new TypeItem(parentType), getABC(), data.namespaceIndex), data.isStatic, !data.isStatic, true); if (propertyTraitIndex == null) { return false; }