diff --git a/CHANGELOG.md b/CHANGELOG.md index d203c4c39..0d8ee6fc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ All notable changes to this project will be documented in this file. - [#1892] AS3 - internal modifier after implicit namespace - [#1888] AS3 - Coerce to string - AS3 - local registers type declarations vs for..in clause +- [#1888] AS3 - Coerce to int when Number +- AS3 - super properties resolving ## [18.3.2] - 2023-01-10 ### Removed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 6a0b1b8f5..fd586ad9d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -255,6 +255,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetSlotAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.InitPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item; @@ -1780,6 +1781,8 @@ public class AVM2Code implements Cloneable { vtype = ((CoerceAVM2Item) assignment.value).typeObj; } else if (assignment instanceof LocalRegAVM2Item) { //for..in vtype = ((LocalRegAVM2Item)assignment).type; + } else if (assignment instanceof GetSlotAVM2Item) { //for..in + vtype = ((GetSlotAVM2Item)assignment).slotType; } else if ((assignment.value instanceof SimpleValue) && ((SimpleValue) assignment.value).isSimpleValue()) { vtype = assignment.value.returnType(); } @@ -2196,19 +2199,19 @@ public class AVM2Code implements Cloneable { type = new TypeItem(abc.constants.getMultiname(param_types[i]).getNameWithNamespace(abc.constants, true)); } if (d.length > r) { - d[r] = new DeclarationAVM2Item(new SetLocalAVM2Item(null, null, r, new NullAVM2Item(null, null)), type); + d[r] = new DeclarationAVM2Item(new SetLocalAVM2Item(null, null, r, new NullAVM2Item(null, null), type), type); } r++; } if (abc.method_info.get(body.method_info).flagNeed_arguments()) { if (d.length > r) { - d[r] = new DeclarationAVM2Item(new SetLocalAVM2Item(null, null, r, new NullAVM2Item(null, null)), TypeItem.ARRAY /*?*/); + d[r] = new DeclarationAVM2Item(new SetLocalAVM2Item(null, null, r, new NullAVM2Item(null, null), TypeItem.ARRAY), TypeItem.ARRAY /*?*/); } r++; } if (abc.method_info.get(body.method_info).flagNeed_rest()) { if (d.length > r) { - d[r] = new DeclarationAVM2Item(new SetLocalAVM2Item(null, null, r, new NullAVM2Item(null, null)), TypeItem.ARRAY/*?*/); + d[r] = new DeclarationAVM2Item(new SetLocalAVM2Item(null, null, r, new NullAVM2Item(null, null), TypeItem.ARRAY), TypeItem.ARRAY/*?*/); } r++; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/SetTypeIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/SetTypeIns.java index fb500c55d..2b3bd322c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/SetTypeIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/SetTypeIns.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.AVM2LocalData; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; @@ -33,7 +34,18 @@ import java.util.List; */ public interface SetTypeIns { - public static void handleResult(GraphTargetItem value, TranslateStack stack, List output, AVM2LocalData localData, GraphTargetItem result, int regId) { + public static GraphTargetItem handleNumberToInt(GraphTargetItem value, GraphTargetItem type) { + if ((value instanceof ConvertAVM2Item) || (value instanceof CoerceAVM2Item)) { + if (type != null && (type.equals(TypeItem.INT) || type.equals(TypeItem.UINT))) { + if (value.value.returnType().equals(TypeItem.NUMBER)) { + return value.value; + } + } + } + return value; + } + + public static void handleResult(GraphTargetItem value, TranslateStack stack, List output, AVM2LocalData localData, GraphTargetItem result, int regId, GraphTargetItem type) { GraphTargetItem notCoercedValue = value; if ((value instanceof CoerceAVM2Item) || (value instanceof ConvertAVM2Item)) { notCoercedValue = value.value; @@ -84,7 +96,7 @@ public interface SetTypeIns { } } } - } + } output.add(result); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/SetLocalTypeIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/SetLocalTypeIns.java index 0aea35dec..23f402ade 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/SetLocalTypeIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/SetLocalTypeIns.java @@ -124,7 +124,7 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S } } - SetLocalAVM2Item result = new SetLocalAVM2Item(ins, localData.lineStartInstruction, regId, value); + SetLocalAVM2Item result = new SetLocalAVM2Item(ins, localData.lineStartInstruction, regId, value, value.returnType()); if (value.getNotCoerced() instanceof CompoundableBinaryOp) { CompoundableBinaryOp binaryOp = (CompoundableBinaryOp) value.getNotCoerced(); if (binaryOp.getLeftSide() instanceof LocalRegAVM2Item) { @@ -136,7 +136,7 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S } } - SetTypeIns.handleResult(value, stack, output, localData, result, regId); + SetTypeIns.handleResult(value, stack, output, localData, result, regId, value.returnType()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSuperIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSuperIns.java index 675b2be54..2b7862630 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSuperIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSuperIns.java @@ -21,18 +21,20 @@ import com.jpexs.decompiler.flash.abc.AVM2LocalData; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; +import static com.jpexs.decompiler.flash.abc.avm2.instructions.other.GetPropertyIns.resolvePropertyType; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetSuperAVM2Item; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; +import com.jpexs.helpers.Reference; import java.util.List; /** * * @author JPEXS */ -public class GetSuperIns extends InstructionDefinition { - +public class GetSuperIns extends InstructionDefinition { + public GetSuperIns() { super(0x04, "getsuper", new int[]{AVM2Code.DAT_MULTINAME_INDEX}, true); } @@ -42,7 +44,13 @@ public class GetSuperIns extends InstructionDefinition { int multinameIndex = ins.operands[0]; FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins); GraphTargetItem obj = stack.pop(); - stack.push(new GetSuperAVM2Item(ins, localData.lineStartInstruction, obj, multiname)); + + Reference isStatic = new Reference<>(false); + Reference type = new Reference<>(null); + Reference callType = new Reference<>(null); + resolvePropertyType(localData, obj, multiname, isStatic, type, callType); + + stack.push(new GetSuperAVM2Item(ins, localData.lineStartInstruction, obj, multiname, type.getVal(), callType.getVal(),isStatic.getVal())); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java index aec57cd94..93ef4f17e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java @@ -364,7 +364,7 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns SetPropertyAVM2Item result = new SetPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, value, type.getVal(), callType.getVal(), isStatic.getVal()); handleCompound(localData, obj, multiname, value, output, result); - SetTypeIns.handleResult(value, stack, output, localData, result, -1); + SetTypeIns.handleResult(value, stack, output, localData, result, -1, type.getVal()); } public static void handleCompound(AVM2LocalData localData, GraphTargetItem obj, FullMultinameAVM2Item multiname, GraphTargetItem value, List output, SetTypeAVM2Item result) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java index 7d2047eae..ae4e5d859 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java @@ -168,7 +168,7 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns { } } - SetTypeIns.handleResult(value, stack, output, localData, result, -1); + SetTypeIns.handleResult(value, stack, output, localData, result, -1, slotType); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java index 33f71bc88..1dcb4314a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSuperIns.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.SetSuperAVM2Item; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.model.CompoundableBinaryOp; +import com.jpexs.helpers.Reference; import java.util.List; import java.util.Objects; @@ -49,7 +50,13 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns { FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins); GraphTargetItem obj = stack.pop(); - SetSuperAVM2Item result = new SetSuperAVM2Item(ins, localData.lineStartInstruction, value, obj, multiname); + + Reference isStatic = new Reference<>(false); + Reference type = new Reference<>(null); + Reference callType = new Reference<>(null); + GetPropertyIns.resolvePropertyType(localData, obj /*??*/, multiname, isStatic, type, callType); + + SetSuperAVM2Item result = new SetSuperAVM2Item(ins, localData.lineStartInstruction, value, obj, multiname, type.getVal(), callType.getVal(), isStatic.getVal()); if (value.getNotCoercedNoDup() instanceof CompoundableBinaryOp) { if (!obj.hasSideEffect() && !multiname.hasSideEffect()) { @@ -64,7 +71,7 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns { } } - SetTypeIns.handleResult(value, stack, output, localData, result, -1); + SetTypeIns.handleResult(value, stack, output, localData, result, -1, type.getVal()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java index 9d1cd0aa1..2bb118d3d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CoerceAVM2Item.java @@ -66,23 +66,33 @@ public class CoerceAVM2Item extends AVM2Item { displayCoerce = false; break; case "Boolean": - displayCoerce = !valueReturnType.equals(TypeItem.BOOLEAN) && - !valueReturnType.equals(TypeItem.UNBOUNDED); + displayCoerce = !valueReturnType.equals(TypeItem.BOOLEAN) + && !valueReturnType.equals(TypeItem.UNBOUNDED); break; case "Number": + displayCoerce = !valueReturnType.equals(TypeItem.INT) + && !valueReturnType.equals(TypeItem.NUMBER) + && !valueReturnType.equals(TypeItem.UINT) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + break; case "int": + displayCoerce = !valueReturnType.equals(TypeItem.INT) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + break; case "uint": - displayCoerce = !valueReturnType.equals(TypeItem.INT) && - !valueReturnType.equals(TypeItem.NUMBER) && - !valueReturnType.equals(TypeItem.UINT) && - !valueReturnType.equals(TypeItem.UNBOUNDED); + if (valueReturnType.equals(TypeItem.INT) && (value instanceof IntegerValueAVM2Item)) { + displayCoerce = (((IntegerValueAVM2Item) value).value < 0); + } else { + displayCoerce = !valueReturnType.equals(TypeItem.UINT) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + } break; case "String": - displayCoerce = !valueReturnType.equals(TypeItem.STRING) && - !valueReturnType.equals(new TypeItem("XML")) && - !valueReturnType.equals(new TypeItem("XMLList")) && - !valueReturnType.equals(new TypeItem("null")) && - !valueReturnType.equals(TypeItem.UNBOUNDED); + displayCoerce = !valueReturnType.equals(TypeItem.STRING) + && !valueReturnType.equals(new TypeItem("XML")) + && !valueReturnType.equals(new TypeItem("XMLList")) + && !valueReturnType.equals(new TypeItem("null")) + && !valueReturnType.equals(TypeItem.UNBOUNDED); break; default: displayCoerce = false; @@ -149,7 +159,7 @@ public class CoerceAVM2Item extends AVM2Item { } if (typeObj instanceof TypeItem) { return typeObj; - } + } return new TypeItem(typeObj.toString()); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java index 4af94ed2f..6c30fa375 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ConvertAVM2Item.java @@ -54,24 +54,34 @@ public class ConvertAVM2Item extends AVM2Item { GraphTargetItem valueReturnType = value.returnType(); switch (type.toString()) { case "Boolean": - displayConvert = !valueReturnType.equals(TypeItem.BOOLEAN) && - !valueReturnType.equals(TypeItem.UNBOUNDED); + displayConvert = !valueReturnType.equals(TypeItem.BOOLEAN) + && !valueReturnType.equals(TypeItem.UNBOUNDED); break; case "Number": + displayConvert = !valueReturnType.equals(TypeItem.INT) + && !valueReturnType.equals(TypeItem.NUMBER) + && !valueReturnType.equals(TypeItem.UINT) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + break; case "int": + displayConvert = !valueReturnType.equals(TypeItem.INT) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + break; case "uint": - displayConvert = !valueReturnType.equals(TypeItem.INT) && - !valueReturnType.equals(TypeItem.NUMBER) && - !valueReturnType.equals(TypeItem.UINT) && - !valueReturnType.equals(TypeItem.UNBOUNDED); + if (valueReturnType.equals(TypeItem.INT) && (value instanceof IntegerValueAVM2Item)) { + displayConvert = (((IntegerValueAVM2Item) value).value < 0); + } else { + displayConvert = !valueReturnType.equals(TypeItem.UINT) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + } break; case "String": - displayConvert = !valueReturnType.equals(TypeItem.STRING) && - !valueReturnType.equals(new TypeItem("XML")) && - !valueReturnType.equals(new TypeItem("XMLList")) && - !valueReturnType.equals(new TypeItem("null")) && - !valueReturnType.equals(TypeItem.UNBOUNDED); - break; + displayConvert = !valueReturnType.equals(TypeItem.STRING) + && !valueReturnType.equals(new TypeItem("XML")) + && !valueReturnType.equals(new TypeItem("XMLList")) + && !valueReturnType.equals(new TypeItem("null")) + && !valueReturnType.equals(TypeItem.UNBOUNDED); + break; } if (displayConvert) { type.toString(writer, localData).append("("); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java index 74687b845..efd7c3928 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java @@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; -import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.LocalData; import java.util.Objects; @@ -34,10 +33,19 @@ public class GetSuperAVM2Item extends AVM2Item { public FullMultinameAVM2Item propertyName; - public GetSuperAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, FullMultinameAVM2Item propertyName) { + public GraphTargetItem type; + + public GraphTargetItem callType; + + public boolean isStatic; + + public GetSuperAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, FullMultinameAVM2Item propertyName, GraphTargetItem type, GraphTargetItem callType, boolean isStatic) { super(instruction, lineStartIns, PRECEDENCE_PRIMARY); this.object = object; this.propertyName = propertyName; + this.type = type; + this.callType = callType; + this.isStatic = isStatic; } @Override @@ -60,7 +68,7 @@ public class GetSuperAVM2Item extends AVM2Item { @Override public GraphTargetItem returnType() { - return TypeItem.UNBOUNDED; + return type; } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java index 065f45069..5350b7ff6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java @@ -146,7 +146,7 @@ public class IntegerValueAVM2Item extends NumberValueAVM2Item implements Integer } @Override - public GraphTargetItem returnType() { + public GraphTargetItem returnType() { return TypeItem.INT; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java index 4f488f45f..7845419a7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; +import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.AssignmentAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -43,6 +44,8 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig public GraphTargetItem compoundValue; public String compoundOperator; + + public GraphTargetItem type; @Override public DeclarationAVM2Item getDeclaration() { @@ -54,9 +57,10 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig this.declaration = declaration; } - public SetLocalAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, int regIndex, GraphTargetItem value) { + public SetLocalAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, int regIndex, GraphTargetItem value, GraphTargetItem type) { super(instruction, lineStartIns, PRECEDENCE_ASSIGMENT, value); this.regIndex = regIndex; + this.type = type; } @Override @@ -73,8 +77,8 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig writer.append(" = "); /*if (declaration != null && !declaration.type.equals(TypeItem.UNBOUNDED) && (value instanceof ConvertAVM2Item)) { return value.value.toString(writer, localData); - }*/ - return value.toString(writer, localData); + }*/ + return SetTypeIns.handleNumberToInt(value, type).toString(writer, localData); } @Override @@ -141,7 +145,7 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig @Override public GraphTargetItem returnType() { - return value.returnType(); + return type; } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java index 8bcd6ecb2..5a8958273 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; +import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.AssignmentAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; @@ -103,7 +104,7 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As /*if (declaration != null && !declaration.type.equals(TypeItem.UNBOUNDED) && (value instanceof ConvertAVM2Item)) { return value.value.toString(writer, localData); }*/ - return value.toString(writer, localData); + return SetTypeIns.handleNumberToInt(value, type).toString(writer, localData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java index 88f1a90a2..9cbbea922 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.model; +import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.AssignmentAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.abc.types.Multiname; @@ -102,7 +103,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign /*if (declaration != null && !declaration.type.equals(TypeItem.UNBOUNDED) && (value instanceof ConvertAVM2Item)) { return value.value.toString(writer, localData); }*/ - return value.toString(writer, localData); + return SetTypeIns.handleNumberToInt(value, type).toString(writer, localData); } public String getNameAsStr(LocalData localData) throws InterruptedException { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java index 7db0b5d7c..d4451705f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.model; +import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.GraphPart; @@ -40,6 +41,12 @@ public class SetSuperAVM2Item extends AVM2Item implements SetTypeAVM2Item { public GraphTargetItem compoundValue; public String compoundOperator; + + public GraphTargetItem type; + + public GraphTargetItem callType; + + public boolean isStatic; @Override public DeclarationAVM2Item getDeclaration() { @@ -65,10 +72,13 @@ public class SetSuperAVM2Item extends AVM2Item implements SetTypeAVM2Item { return value.getFirstPart(); } - public SetSuperAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value, GraphTargetItem object, FullMultinameAVM2Item propertyName) { + public SetSuperAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value, GraphTargetItem object, FullMultinameAVM2Item propertyName, GraphTargetItem type, GraphTargetItem callType, boolean isStatic) { super(instruction, lineStartIns, PRECEDENCE_ASSIGMENT, value); this.object = object; this.propertyName = propertyName; + this.type = type; + this.callType = callType; + this.isStatic = isStatic; } @Override @@ -88,7 +98,7 @@ public class SetSuperAVM2Item extends AVM2Item implements SetTypeAVM2Item { return compoundValue.toString(writer, localData); } writer.append(" = "); - return value.toString(writer, localData); + return SetTypeIns.handleNumberToInt(value, type).toString(writer, localData); } @Override @@ -109,7 +119,7 @@ public class SetSuperAVM2Item extends AVM2Item implements SetTypeAVM2Item { @Override public GraphTargetItem getObject() { - return new GetSuperAVM2Item(getInstruction(), getLineStartIns(), object, propertyName); + return new GetSuperAVM2Item(getInstruction(), getLineStartIns(), object, propertyName, type, callType, isStatic); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java index ceb809ebf..fec57217d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model.clauses; import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; +import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; @@ -60,8 +61,8 @@ public class DeclarationAVM2Item extends AVM2Item { public DeclarationAVM2Item(GraphTargetItem assignment) { this(assignment, null); - } - + } + @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { @@ -105,7 +106,7 @@ public class DeclarationAVM2Item extends AVM2Item { type.appendTry(writer, localData); if (showValue) { writer.append(" = "); - val.toString(writer, localData); + SetTypeIns.handleNumberToInt(val, type).toString(writer, localData); } return writer; } @@ -124,7 +125,7 @@ public class DeclarationAVM2Item extends AVM2Item { type.appendTry(writer, localData); if (showValue) { writer.append(" = "); - val.toString(writer, localData); + SetTypeIns.handleNumberToInt(val, type).toString(writer, localData); } return writer; } @@ -144,7 +145,7 @@ public class DeclarationAVM2Item extends AVM2Item { type.appendTry(writer, localData); if (showValue) { writer.append(" = "); - val.toString(writer, localData); + SetTypeIns.handleNumberToInt(val, type).toString(writer, localData); } return writer; } 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 e392bd267..008384201 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 @@ -229,6 +229,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var xlist:XMLList;\r\n" + "var lc:LocalClass;\r\n" + "var f:Function;\r\n" + + "var d:Number;\r\n" + "var s:String = \"a\";\r\n" + "var i:int = int(s);\r\n" + "var j:int = n;\r\n" @@ -293,7 +294,18 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"obj\");\r\n" + "}\r\n" - + "s = xlist;\r\n", + + "s = xlist;\r\n" + + "d = 0;\r\n" + + "d = 1;\r\n" + + "d = 1.5;\r\n" + + "i = 1;\r\n" + + "i = 1.5;\r\n" + + "o[int(d * 5)] = 1;\r\n" + + "this.n = 1.5;\r\n" + + "super.prot = 1.5;\r\n" + + "super.prot = int(s);\r\n" + + "i = super.prot;\r\n" + + "s = String(super.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 d8c37a363..b923fdf14 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 @@ -225,6 +225,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var xlist:XMLList;\r\n" + "var lc:LocalClass;\r\n" + "var f:Function;\r\n" + + "var d:Number;\r\n" + "var s:String = null;\r\n" + "var i:int = 0;\r\n" + "var a:* = undefined;\r\n" @@ -292,7 +293,18 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"obj\");\r\n" + "}\r\n" - + "s = xlist;\r\n", + + "s = xlist;\r\n" + + "d = 0;\r\n" + + "d = 1;\r\n" + + "d = 1.5;\r\n" + + "i = 1;\r\n" + + "i = 1.5;\r\n" + + "o[int(d * 5)] = 1;\r\n" + + "this.n = 1.5;\r\n" + + "super.prot = 1.5;\r\n" + + "super.prot = int(s);\r\n" + + "i = super.prot;\r\n" + + "s = String(super.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 4e882cd39..d3504faf6 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 a82b31fdc..594f35119 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/TestConvert.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as index dad6f8c1b..dd25bfba7 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as @@ -90,7 +90,19 @@ package tests if (o) { trace("obj"); } - s = xlist; + s = xlist; + var d:Number = 0; + d = 1; + d = 1.5; + i = 1; + i = 1.5; + o[int(d * 5)] = 1; + this.n = 1.5; + super.prot = 1.5; + super.prot = int(s); + i = super.prot; + s = String(super.prot); + } } }