mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-03 14:24:36 +00:00
AS2 execution fixes
This commit is contained in:
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.ecma.Null;
|
||||
import com.jpexs.decompiler.flash.ecma.Undefined;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
@@ -47,7 +48,7 @@ public class CoerceSIns extends InstructionDefinition implements CoerceOrConvert
|
||||
if (value == Null.INSTANCE) {
|
||||
lda.operandStack.push(value);
|
||||
} else {
|
||||
lda.operandStack.push(value.toString());
|
||||
lda.operandStack.push(EcmaScript.toString(value));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
@@ -38,7 +39,7 @@ public class ConvertSIns extends InstructionDefinition implements CoerceOrConver
|
||||
@Override
|
||||
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
|
||||
Object obj = lda.operandStack.pop();
|
||||
lda.operandStack.push(obj.toString());
|
||||
lda.operandStack.push(EcmaScript.toString(obj));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.EscapeXAttrAVM2Item;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import java.util.List;
|
||||
@@ -35,8 +36,8 @@ public class EscXAttrIns extends InstructionDefinition {
|
||||
|
||||
@Override
|
||||
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
|
||||
String s = lda.operandStack.pop().toString();
|
||||
//escape
|
||||
String s = EcmaScript.toString(lda.operandStack.pop());
|
||||
// todo: escape
|
||||
lda.operandStack.push(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.EscapeXElemAVM2Item;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import java.util.List;
|
||||
@@ -35,8 +36,8 @@ public class EscXElemIns extends InstructionDefinition {
|
||||
|
||||
@Override
|
||||
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
|
||||
String s = lda.operandStack.pop().toString();
|
||||
//escape
|
||||
String s = EcmaScript.toString(lda.operandStack.pop());
|
||||
// todo: escape
|
||||
lda.operandStack.push(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionAsciiToChar;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -51,11 +52,11 @@ public class AsciiToCharActionItem extends ActionItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(value.getResultAsNumber());
|
||||
return getResult(value.getResult());
|
||||
}
|
||||
|
||||
public static String getResult(Double ascii) {
|
||||
int res = (int) (double) ascii;
|
||||
public static String getResult(Object ascii) {
|
||||
int res = (char) EcmaScript.toInt32(ascii);
|
||||
if (res == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionMBAsciiToChar;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -51,11 +52,11 @@ public class MBAsciiToCharActionItem extends ActionItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(value.getResultAsNumber());
|
||||
return getResult(value.getResult());
|
||||
}
|
||||
|
||||
public static String getResult(Double ascii) {
|
||||
int res = (int) (double) ascii;
|
||||
public static String getResult(Object ascii) {
|
||||
int res = (char) EcmaScript.toInt32(ascii);
|
||||
if (res == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionToInteger;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -51,11 +52,11 @@ public class ToIntegerActionItem extends ActionItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(value.getResultAsNumber());
|
||||
return getResult(value.getResult());
|
||||
}
|
||||
|
||||
public static long getResult(Double num) {
|
||||
return Math.round(num);
|
||||
public static long getResult(Object num) {
|
||||
return EcmaScript.toInt32(num);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionBitAnd;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -34,11 +35,11 @@ public class BitAndActionItem extends BinaryOpItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(rightSide.getResultAsNumber(), leftSide.getResultAsNumber());
|
||||
return getResult(rightSide.getResult(), leftSide.getResult());
|
||||
}
|
||||
|
||||
public static long getResult(Double rightResult, Double leftResult) {
|
||||
return ((long) (double) leftResult) & ((long) (double) rightResult);
|
||||
public static long getResult(Object rightResult, Object leftResult) {
|
||||
return EcmaScript.toInt32(leftResult) & EcmaScript.toInt32(rightResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionBitOr;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -34,11 +35,11 @@ public class BitOrActionItem extends BinaryOpItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(rightSide.getResultAsNumber(), leftSide.getResultAsNumber());
|
||||
return getResult(rightSide.getResult(), leftSide.getResult());
|
||||
}
|
||||
|
||||
public static long getResult(Double rightResult, Double leftResult) {
|
||||
return ((long) (double) leftResult) | ((long) (double) rightResult);
|
||||
public static long getResult(Object rightResult, Object leftResult) {
|
||||
return EcmaScript.toInt32(leftResult) | EcmaScript.toInt32(rightResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionBitXor;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -37,11 +38,11 @@ public class BitXorActionItem extends BinaryOpItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(rightSide.getResultAsNumber(), leftSide.getResultAsNumber());
|
||||
return getResult(rightSide.getResult(), leftSide.getResult());
|
||||
}
|
||||
|
||||
public static long getResult(Double rightResult, Double leftResult) {
|
||||
return ((long) (double) leftResult) ^ ((long) (double) rightResult);
|
||||
public static long getResult(Object rightResult, Object leftResult) {
|
||||
return EcmaScript.toInt32(leftResult) ^ EcmaScript.toInt32(rightResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,7 +46,7 @@ public class EqActionItem extends BinaryOpItem implements LogicalOpItem, EqualsT
|
||||
|
||||
public static Boolean getResult(Object rightResult, Object leftResult, boolean version2) {
|
||||
if (version2) {
|
||||
return EcmaScript.equals(leftResult, rightResult);
|
||||
return EcmaScript.equals(true, leftResult, rightResult);
|
||||
} else {
|
||||
//For SWF 4 and older, it should return 1 or 0
|
||||
return (Action.toFloatPoint(leftResult) == Action.toFloatPoint(rightResult));
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionBitLShift;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -34,11 +35,11 @@ public class LShiftActionItem extends BinaryOpItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(rightSide.getResultAsNumber(), leftSide.getResultAsNumber());
|
||||
return getResult(rightSide.getResult(), leftSide.getResult());
|
||||
}
|
||||
|
||||
public static int getResult(Double rightResult, Double leftResult) {
|
||||
return ((int) (double) leftResult) << ((int) (double) rightResult);
|
||||
public static int getResult(Object rightResult, Object leftResult) {
|
||||
return EcmaScript.toInt32(leftResult) << EcmaScript.toInt32(rightResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,7 @@ public class NeqActionItem extends BinaryOpItem implements LogicalOpItem, Invert
|
||||
@Override
|
||||
public Object getResult() {
|
||||
if (version2) {
|
||||
return !EcmaScript.equals(leftSide.getResult(), rightSide.getResult());
|
||||
return !EcmaScript.equals(true, leftSide.getResult(), rightSide.getResult());
|
||||
} else {
|
||||
//For SWF 4 and older, it should return 1 or 0
|
||||
return (Action.toFloatPoint(leftSide.getResult()) != Action.toFloatPoint(rightSide.getResult()));
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.swf5.ActionBitRShift;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -34,12 +35,12 @@ public class RShiftActionItem extends BinaryOpItem {
|
||||
|
||||
@Override
|
||||
public Object getResult() {
|
||||
return getResult(rightSide.getResultAsNumber(), leftSide.getResultAsNumber());
|
||||
return getResult(rightSide.getResult(), leftSide.getResult());
|
||||
}
|
||||
|
||||
public static long getResult(Double rightResult, Double leftResult) {
|
||||
long rightResult2 = ((long) (double) rightResult) & 0x1f;
|
||||
return ((long) (double) leftResult) >> rightResult2;
|
||||
public static long getResult(Object rightResult, Object leftResult) {
|
||||
long rightResult2 = EcmaScript.toInt32(rightResult) & 0x1f;
|
||||
return EcmaScript.toInt32(leftResult) >> rightResult2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,8 +43,7 @@ public class StrictEqActionItem extends BinaryOpItem implements LogicalOpItem, I
|
||||
public static boolean getResult(Object rightResult, Object leftResult) {
|
||||
Object x = leftResult;
|
||||
Object y = rightResult;
|
||||
return EcmaScript.type(x) == EcmaScript.type(y)
|
||||
&& EcmaScript.equals(x, y);
|
||||
return EcmaScript.strictEquals(true, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,8 +39,7 @@ public class StrictNeqActionItem extends BinaryOpItem implements LogicalOpItem,
|
||||
public Object getResult() {
|
||||
Object x = leftSide.getResult();
|
||||
Object y = rightSide.getResult();
|
||||
return EcmaScript.type(x) != EcmaScript.type(y)
|
||||
|| (!EcmaScript.equals(x, y));
|
||||
return !EcmaScript.strictEquals(true, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ActionAsciiToChar extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(AsciiToCharActionItem.getResult(lda.popAsNumber()));
|
||||
lda.stack.push(AsciiToCharActionItem.getResult(lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionMBAsciiToChar extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(MBAsciiToCharActionItem.getResult(lda.popAsNumber()));
|
||||
lda.stack.push(MBAsciiToCharActionItem.getResult(lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -254,6 +255,13 @@ public class ActionPush extends Action {
|
||||
updateLength();
|
||||
}
|
||||
|
||||
public ActionPush(Object[] values) {
|
||||
super(0x96, 0);
|
||||
this.values = new ArrayList<>();
|
||||
this.values.addAll(Arrays.asList(values));
|
||||
updateLength();
|
||||
}
|
||||
|
||||
public ActionPush(FlasmLexer lexer, List<String> constantPool) throws IOException, ActionParseException {
|
||||
super(0x96, 0);
|
||||
this.constantPool = constantPool;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionToInteger extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(ToIntegerActionItem.getResult(lda.popAsNumber()));
|
||||
lda.stack.push(ToIntegerActionItem.getResult(lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionBitAnd extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(BitAndActionItem.getResult(lda.popAsNumber(), lda.popAsNumber()));
|
||||
lda.stack.push(BitAndActionItem.getResult(lda.pop(), lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionBitLShift extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(LShiftActionItem.getResult(lda.popAsNumber(), lda.popAsNumber()));
|
||||
lda.stack.push(LShiftActionItem.getResult(lda.pop(), lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionBitOr extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(BitOrActionItem.getResult(lda.popAsNumber(), lda.popAsNumber()));
|
||||
lda.stack.push(BitOrActionItem.getResult(lda.pop(), lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionBitRShift extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(RShiftActionItem.getResult(lda.popAsNumber(), lda.popAsNumber()));
|
||||
lda.stack.push(RShiftActionItem.getResult(lda.pop(), lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ActionBitXor extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
lda.stack.push(BitXorActionItem.getResult(lda.popAsNumber(), lda.popAsNumber()));
|
||||
lda.stack.push(BitXorActionItem.getResult(lda.pop(), lda.pop()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user