mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-08 21:18:37 +00:00
AS3 instruction execution fixes
This commit is contained in:
@@ -737,7 +737,7 @@ public abstract class Action implements GraphSourceItem {
|
||||
protected long popLong(TranslateStack stack) {
|
||||
GraphTargetItem item = stack.pop();
|
||||
if (item instanceof DirectValueActionItem) {
|
||||
return (long) (double) EcmaScript.toNumber(((DirectValueActionItem) item).value);
|
||||
return (long) (double) EcmaScript.toNumberAs2(((DirectValueActionItem) item).value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1021,7 +1021,7 @@ public abstract class Action implements GraphSourceItem {
|
||||
}
|
||||
|
||||
//return in for..in
|
||||
if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) instanceof Null)) {
|
||||
if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) == Null.INSTANCE)) {
|
||||
if (ip + 3 <= end) {
|
||||
if ((actions.get(ip + 1) instanceof ActionEquals) || (actions.get(ip + 1) instanceof ActionEquals2)) {
|
||||
if (actions.get(ip + 2) instanceof ActionNot) {
|
||||
@@ -1355,10 +1355,10 @@ public abstract class Action implements GraphSourceItem {
|
||||
if (o instanceof Long) {
|
||||
return (Long) o;
|
||||
}
|
||||
if (o instanceof Null) {
|
||||
if (o == Null.INSTANCE) {
|
||||
return Double.NaN;
|
||||
}
|
||||
if (o instanceof Undefined) {
|
||||
if (o == Undefined.INSTANCE) {
|
||||
return Double.NaN;
|
||||
}
|
||||
if (o instanceof Boolean) {
|
||||
|
||||
@@ -168,7 +168,7 @@ public class ActionGraph extends Graph {
|
||||
NeqActionItem ne = (NeqActionItem) wi.expression.get(wi.expression.size() - 1);
|
||||
if (ne.rightSide instanceof DirectValueActionItem) {
|
||||
DirectValueActionItem dv = (DirectValueActionItem) ne.rightSide;
|
||||
if (dv.value instanceof Null) {
|
||||
if (dv.value == Null.INSTANCE) {
|
||||
GraphTargetItem en = list.get(t - 1);
|
||||
if (en instanceof EnumerateActionItem) {
|
||||
EnumerateActionItem eti = (EnumerateActionItem) en;
|
||||
@@ -467,7 +467,7 @@ public class ActionGraph extends Graph {
|
||||
int oldIp = ip;
|
||||
//return in for..in
|
||||
GraphSourceItem action = code.get(ip);
|
||||
if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) instanceof Null)) {
|
||||
if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) == Null.INSTANCE)) {
|
||||
if (ip + 4 < code.size()) {
|
||||
if ((code.get(ip + 1) instanceof ActionEquals) || (code.get(ip + 1) instanceof ActionEquals2)) {
|
||||
if (code.get(ip + 2) instanceof ActionNot) {
|
||||
|
||||
@@ -59,6 +59,6 @@ public class LocalDataArea {
|
||||
}
|
||||
|
||||
public Double popAsNumber() {
|
||||
return EcmaScript.toNumber(stack.pop());
|
||||
return EcmaScript.toNumberAs2(stack.pop());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CallMethodActionItem extends ActionItem {
|
||||
boolean blankMethod = false;
|
||||
boolean dvai = methodName instanceof DirectValueActionItem;
|
||||
if (dvai) {
|
||||
if (((DirectValueActionItem) methodName).value instanceof Undefined) {
|
||||
if (((DirectValueActionItem) methodName).value == Undefined.INSTANCE) {
|
||||
blankMethod = true;
|
||||
}
|
||||
if (((DirectValueActionItem) methodName).value instanceof String) {
|
||||
|
||||
@@ -188,7 +188,7 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue {
|
||||
}
|
||||
dependencies.add(computedRegValue);
|
||||
}
|
||||
return (value instanceof Double) || (value instanceof Float) || (value instanceof Boolean) || (value instanceof Long) || (value instanceof Null) || (computedRegValue != null && computedRegValue.isCompileTime(dependencies)) || (value instanceof String) || (value instanceof ConstantIndex);
|
||||
return (value instanceof Double) || (value instanceof Float) || (value instanceof Boolean) || (value instanceof Long) || (value == Null.INSTANCE) || (computedRegValue != null && computedRegValue.isCompileTime(dependencies)) || (value instanceof String) || (value instanceof ConstantIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,10 +80,10 @@ public class MBStringExtractActionItem extends ActionItem {
|
||||
|
||||
public static String getResult(Object count, Object index, Object value) {
|
||||
String str = EcmaScript.toString(value);
|
||||
int idx = (int) (double) EcmaScript.toNumber(index);
|
||||
int idx = (int) (double) EcmaScript.toNumberAs2(index);
|
||||
idx--; // index seems to be 1 based
|
||||
|
||||
int cnt = (int) (double) EcmaScript.toNumber(count);
|
||||
int cnt = (int) (double) EcmaScript.toNumberAs2(count);
|
||||
|
||||
/*if (idx < 0) {
|
||||
idx = str.length() + idx;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MBStringLengthActionItem extends ActionItem {
|
||||
}
|
||||
|
||||
public static Double getResult(Object obj) {
|
||||
return EcmaScript.toNumber(EcmaScript.toString(obj).length());
|
||||
return EcmaScript.toNumberAs2(EcmaScript.toString(obj).length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,7 @@ public class NewMethodActionItem extends ActionItem {
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
boolean blankMethod = false;
|
||||
if (methodName instanceof DirectValueActionItem) {
|
||||
if (((DirectValueActionItem) methodName).value instanceof Undefined) {
|
||||
if (((DirectValueActionItem) methodName).value == Undefined.INSTANCE) {
|
||||
blankMethod = true;
|
||||
} else if (((DirectValueActionItem) methodName).value instanceof String) {
|
||||
if (((DirectValueActionItem) methodName).value.equals("")) {
|
||||
@@ -71,7 +71,7 @@ public class NewMethodActionItem extends ActionItem {
|
||||
if (!blankMethod) {
|
||||
writer.append(".");
|
||||
if (methodName instanceof DirectValueActionItem) {
|
||||
if (((DirectValueActionItem) methodName).value instanceof Undefined) {
|
||||
if (((DirectValueActionItem) methodName).value == Undefined.INSTANCE) {
|
||||
} else if (((DirectValueActionItem) methodName).value instanceof String) {
|
||||
((DirectValueActionItem) methodName).toStringNoQuotes(writer, localData);
|
||||
} else {
|
||||
|
||||
@@ -69,10 +69,10 @@ public class StringExtractActionItem extends ActionItem {
|
||||
|
||||
public static String getResult(Object count, Object index, Object value) {
|
||||
String str = EcmaScript.toString(value);
|
||||
int idx = (int) (double) EcmaScript.toNumber(index);
|
||||
int idx = (int) (double) EcmaScript.toNumberAs2(index);
|
||||
idx--; // index seems to be 1 based
|
||||
|
||||
int cnt = (int) (double) EcmaScript.toNumber(count);
|
||||
int cnt = (int) (double) EcmaScript.toNumberAs2(count);
|
||||
|
||||
/*if (idx < 0) {
|
||||
idx = str.length() + idx;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class StringLengthActionItem extends ActionItem {
|
||||
}
|
||||
|
||||
public static Double getResult(Object obj) {
|
||||
return EcmaScript.toNumber(EcmaScript.toString(obj).length());
|
||||
return EcmaScript.toNumberAs2(EcmaScript.toString(obj).length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,7 +71,7 @@ public class AddActionItem extends BinaryOpItem {
|
||||
if (EcmaScript.type(leftResult) == EcmaType.STRING || EcmaScript.type(rightResult) == EcmaType.STRING) {
|
||||
return EcmaScript.toString(leftResult) + EcmaScript.toString(rightResult);
|
||||
}
|
||||
return EcmaScript.toNumber(leftResult) + EcmaScript.toNumber(rightResult);
|
||||
return EcmaScript.toNumberAs2(leftResult) + EcmaScript.toNumberAs2(rightResult);
|
||||
} else {
|
||||
return Action.toFloatPoint(leftResult) + Action.toFloatPoint(rightResult);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.ecma.Undefined;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -44,14 +45,13 @@ public class GeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
|
||||
@Override
|
||||
public Object getResult() {
|
||||
if (version2) {
|
||||
Object ret = EcmaScript.compare(leftSide.getResult(), rightSide.getResult());
|
||||
if (ret == Boolean.TRUE) {
|
||||
return Boolean.FALSE;
|
||||
Object ret = EcmaScript.compare(leftSide.getResult(), rightSide.getResult(), true);
|
||||
if (ret == Undefined.INSTANCE) {
|
||||
return ret;
|
||||
}
|
||||
if (ret == Boolean.FALSE) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return ret;//undefined
|
||||
|
||||
int reti = (int) ret;
|
||||
return reti != -1;
|
||||
} else {
|
||||
//For SWF 4 and older, it should return 1 or 0
|
||||
return Action.toFloatPoint(leftSide.getResult()) >= Action.toFloatPoint(rightSide.getResult());
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionGreater;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.ecma.Undefined;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -43,7 +44,13 @@ public class GtActionItem extends BinaryOpItem implements LogicalOpItem {
|
||||
}
|
||||
|
||||
public static Object getResult(Object rightResult, Object leftResult) {
|
||||
return EcmaScript.compare(rightResult, leftResult);
|
||||
Object ret = EcmaScript.compare(rightResult, leftResult, true);
|
||||
if (ret == Undefined.INSTANCE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int reti = (int) ret;
|
||||
return reti == -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionNot;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionGreater;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.ecma.Undefined;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -40,14 +41,13 @@ public class LeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
Object ret = EcmaScript.compare(rightSide.getResult(), leftSide.getResult());
|
||||
if (ret == Boolean.TRUE) {
|
||||
return Boolean.FALSE;
|
||||
Object ret = EcmaScript.compare(rightSide.getResult(), leftSide.getResult(), true);
|
||||
if (ret == Undefined.INSTANCE) {
|
||||
return ret;
|
||||
}
|
||||
if (ret == Boolean.FALSE) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return ret;//undefined
|
||||
|
||||
int reti = (int) ret;
|
||||
return reti != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionLess;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionLess2;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.ecma.Undefined;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -47,7 +48,13 @@ public class LtActionItem extends BinaryOpItem implements LogicalOpItem {
|
||||
|
||||
public static Object getResult(Object rightResult, Object leftResult, boolean version2) {
|
||||
if (version2) {
|
||||
return EcmaScript.compare(leftResult, rightResult);
|
||||
Object ret = EcmaScript.compare(leftResult, rightResult, true);
|
||||
if (ret == Undefined.INSTANCE) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int reti = (int) ret;
|
||||
return reti == -1;
|
||||
} else {
|
||||
//For SWF 4 and older, it should return 1 or 0
|
||||
return Action.toFloatPoint(leftResult) < Action.toFloatPoint(rightResult);
|
||||
|
||||
@@ -144,9 +144,9 @@ public class ActionPush extends Action {
|
||||
} else if (o instanceof Float) {
|
||||
sos.writeUI8(1);
|
||||
sos.writeFLOAT((Float) o);
|
||||
} else if (o instanceof Null) {
|
||||
} else if (o == Null.INSTANCE) {
|
||||
sos.writeUI8(2);
|
||||
} else if (o instanceof Undefined) {
|
||||
} else if (o == Undefined.INSTANCE) {
|
||||
sos.writeUI8(3);
|
||||
} else if (o instanceof RegisterNumber) {
|
||||
sos.writeUI8(4);
|
||||
@@ -194,9 +194,9 @@ public class ActionPush extends Action {
|
||||
res += Utf8Helper.getBytesLength((String) o) + 2;
|
||||
} else if (o instanceof Float) {
|
||||
res += 5;
|
||||
} else if (o instanceof Null) {
|
||||
} else if (o == Null.INSTANCE) {
|
||||
res++;
|
||||
} else if (o instanceof Undefined) {
|
||||
} else if (o == Undefined.INSTANCE) {
|
||||
res++;
|
||||
} else if (o instanceof RegisterNumber) {
|
||||
res += 2;
|
||||
|
||||
Reference in New Issue
Block a user