Fixed #1888 AS3 - Coerce to string

This commit is contained in:
Jindra Petřík
2023-01-13 18:28:49 +01:00
parent 84af94475a
commit 5d428eaa8b
9 changed files with 56 additions and 48 deletions

View File

@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- [#1894] Switch inside loop
- [#1801] AS3 - AIR/Flash switching
- [#1892] AS3 - internal modifier after implicit namespace
- [#1888] AS3 - Coerce to string
## [18.3.2] - 2023-01-10
### Removed
@@ -2871,6 +2872,7 @@ All notable changes to this project will be documented in this file.
[#1888]: https://www.free-decompiler.com/flash/issues/1888
[#1894]: https://www.free-decompiler.com/flash/issues/1894
[#1801]: https://www.free-decompiler.com/flash/issues/1801
[#1892]: https://www.free-decompiler.com/flash/issues/1892
[#1935]: https://www.free-decompiler.com/flash/issues/1935
[#1931]: https://www.free-decompiler.com/flash/issues/1931
[#1934]: https://www.free-decompiler.com/flash/issues/1934
@@ -2927,7 +2929,6 @@ All notable changes to this project will be documented in this file.
[#1769]: https://www.free-decompiler.com/flash/issues/1769
[#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
[#1887]: https://www.free-decompiler.com/flash/issues/1887
[#1882]: https://www.free-decompiler.com/flash/issues/1882
[#1880]: https://www.free-decompiler.com/flash/issues/1880

View File

@@ -58,8 +58,47 @@ public class CoerceAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
//return hilight("(" + type + ")", highlight)+
return value.toString(writer, localData);
//Same for ConvertAVM2Item
boolean displayCoerce = true;
GraphTargetItem valueReturnType = value.returnType();
switch (typeObj.toString()) {
case "*":
displayCoerce = false;
break;
case "Boolean":
displayCoerce = !valueReturnType.equals(TypeItem.BOOLEAN) &&
!valueReturnType.equals(TypeItem.UNBOUNDED);
break;
case "Number":
case "int":
case "uint":
displayCoerce = !valueReturnType.equals(TypeItem.INT) &&
!valueReturnType.equals(TypeItem.NUMBER) &&
!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);
break;
default:
displayCoerce = false;
break;
//default:
// there should be something like instanceof, or not, just comment it out...
// displayCoerce = !valueReturnType.equals(typeObj);
}
if (displayCoerce) {
typeObj.toString(writer, localData).append("(");
}
value.toString(writer, localData);
if (displayCoerce) {
writer.append(")");
}
return writer;
}
@Override

View File

@@ -49,12 +49,9 @@ public class ConvertAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
//Same for CoerceAVM2Item
boolean displayConvert = true;
GraphTargetItem valueReturnType = value.returnType();
/*if (valueReturnType instanceof TypeItem) {
TypeItem ti = (TypeItem)valueReturnType;
ti.fullTypeName.toRawString()
}*/
switch (type.toString()) {
case "Boolean":
displayConvert = !valueReturnType.equals(TypeItem.BOOLEAN) &&
@@ -70,6 +67,9 @@ public class ConvertAVM2Item extends AVM2Item {
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;
}

View File

@@ -98,18 +98,7 @@ public class DeclarationAVM2Item extends AVM2Item {
srcData.regIndex = lti.regIndex;
GraphTargetItem val = lti.value;
GraphTargetItem coerType = TypeItem.UNBOUNDED;
if (lti.value instanceof CoerceAVM2Item) {
coerType = ((CoerceAVM2Item) lti.value).typeObj;
}
if (lti.value instanceof ConvertAVM2Item) {
coerType = ((ConvertAVM2Item) lti.value).type;
}
//strip coerce if its declared as this type
if ((lti.value instanceof CoerceAVM2Item) && coerType.equals(type) && !coerType.equals(TypeItem.UNBOUNDED)) {
val = val.value;
}
srcData.declaredType = (coerType instanceof TypeItem) ? ((TypeItem) coerType).fullTypeName : DottedChain.ALL;
srcData.declaredType = (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName : DottedChain.ALL;
writer.append("var ");
writer.append(localName);
writer.append(":");
@@ -126,19 +115,7 @@ public class DeclarationAVM2Item extends AVM2Item {
srcData.localName = ssti.getNameAsStr(localData);
srcData.declaration = true;
GraphTargetItem val = ssti.value;
GraphTargetItem coerType = TypeItem.UNBOUNDED;
if (ssti.value instanceof CoerceAVM2Item) {
coerType = ((CoerceAVM2Item) ssti.value).typeObj;
}
if (ssti.value instanceof ConvertAVM2Item) {
coerType = ((ConvertAVM2Item) ssti.value).type;
}
//strip coerce if its declared as this type
if ((ssti.value instanceof CoerceAVM2Item) && coerType.equals(type) && !coerType.equals(TypeItem.UNBOUNDED)) {
val = val.value;
}
GraphTargetItem val = ssti.value;
srcData.declaredType = (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName : DottedChain.ALL;
writer.append("var ");
ssti.getName(writer, localData);
@@ -158,19 +135,7 @@ public class DeclarationAVM2Item extends AVM2Item {
srcData.localName = ((FullMultinameAVM2Item) spti.propertyName).resolvedMultinameName;
srcData.declaration = true;
GraphTargetItem val = spti.value;
GraphTargetItem coerType = TypeItem.UNBOUNDED;
if (spti.value instanceof CoerceAVM2Item) {
coerType = ((CoerceAVM2Item) spti.value).typeObj;
}
if (spti.value instanceof ConvertAVM2Item) {
coerType = ((ConvertAVM2Item) spti.value).type;
}
//strip coerce if its declared as this type
if ((spti.value instanceof CoerceAVM2Item) && coerType.equals(type) && !coerType.equals(TypeItem.UNBOUNDED)) {
val = val.value;
}
GraphTargetItem val = spti.value;
srcData.declaredType = (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName : DottedChain.ALL;
writer.append("var ");
writer.append(IdentifiersDeobfuscation.printIdentifier(true, ((FullMultinameAVM2Item) spti.propertyName).resolvedMultinameName));

View File

@@ -292,7 +292,8 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
+ "if(o)\r\n"
+ "{\r\n"
+ "trace(\"obj\");\r\n"
+ "}\r\n",
+ "}\r\n"
+ "s = xlist;\r\n",
false);
}

View File

@@ -291,7 +291,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
+ "if(Boolean(o))\r\n"
+ "{\r\n"
+ "trace(\"obj\");\r\n"
+ "}\r\n",
+ "}\r\n"
+ "s = xlist;\r\n",
false);
}

View File

@@ -89,7 +89,8 @@ package tests
if (o) {
trace("obj");
}
}
s = xlist;
}
}
}