AS3 instruction execute fixes

This commit is contained in:
honfika@gmail.com
2015-11-06 09:37:35 +01:00
parent 22f5bfa5c3
commit 8088e50276
28 changed files with 107 additions and 67 deletions

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2RangeErrorException;
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.AlchemyStoreAVM2Item;
@@ -39,11 +40,16 @@ public class Sf32Ins extends InstructionDefinition implements AlchemyTypeIns {
}
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) throws AVM2RangeErrorException {
int addr = (int) (double) EcmaScript.toNumber(lda.operandStack.pop());
byte[] domainMemory = lda.getDomainMemory();
if (addr < 0 || addr >= domainMemory.length) {
throw new AVM2RangeErrorException(1506);
}
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
// todo: set domainMemory
//lda.getDomainMemory()[addr] = ...
//domainMemory[addr] = ...
return true;
}

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2RangeErrorException;
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.AlchemyStoreAVM2Item;
@@ -39,11 +40,16 @@ public class Sf64Ins extends InstructionDefinition implements AlchemyTypeIns {
}
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) throws AVM2RangeErrorException {
int addr = (int) (double) EcmaScript.toNumber(lda.operandStack.pop());
byte[] domainMemory = lda.getDomainMemory();
if (addr < 0 || addr >= domainMemory.length) {
throw new AVM2RangeErrorException(1506);
}
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
// todo: set domainMemory
//lda.getDomainMemory()[addr] = ...
//domainMemory[addr] = ...
return true;
}

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2RangeErrorException;
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.AlchemyStoreAVM2Item;
@@ -39,11 +40,16 @@ public class Si16Ins extends InstructionDefinition implements AlchemyTypeIns {
}
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) throws AVM2RangeErrorException {
int addr = (int) (double) EcmaScript.toNumber(lda.operandStack.pop());
byte[] domainMemory = lda.getDomainMemory();
if (addr < 0 || addr >= domainMemory.length) {
throw new AVM2RangeErrorException(1506);
}
int value = EcmaScript.toInt32(lda.operandStack.pop());
// todo: set domainMemory
//lda.getDomainMemory()[addr] = ...
//domainMemory[addr] = ...
return true;
}

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2RangeErrorException;
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.AlchemyStoreAVM2Item;
@@ -39,11 +40,16 @@ public class Si32Ins extends InstructionDefinition implements AlchemyTypeIns {
}
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) throws AVM2RangeErrorException {
int addr = (int) (double) EcmaScript.toNumber(lda.operandStack.pop());
byte[] domainMemory = lda.getDomainMemory();
if (addr < 0 || addr >= domainMemory.length) {
throw new AVM2RangeErrorException(1506);
}
int value = EcmaScript.toInt32(lda.operandStack.pop());
// todo: set domainMemory
//lda.getDomainMemory()[addr] = ...
//domainMemory[addr] = ...
return true;
}

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2RangeErrorException;
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.AlchemyStoreAVM2Item;
@@ -39,11 +40,16 @@ public class Si8Ins extends InstructionDefinition implements AlchemyTypeIns {
}
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) EcmaScript.toNumber(lda.operandStack.pop());
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) throws AVM2RangeErrorException {
int addr = (int) (double) EcmaScript.toNumber(lda.operandStack.pop());
byte[] domainMemory = lda.getDomainMemory();
if (addr < 0 || addr >= domainMemory.length) {
throw new AVM2RangeErrorException(1506);
}
int value = EcmaScript.toInt32(lda.operandStack.pop());
// todo: set domainMemory
//lda.getDomainMemory()[addr] = ...
//domainMemory[addr] = ...
return true;
}

View File

@@ -40,8 +40,7 @@ public class Sxi16Ins extends InstructionDefinition implements AlchemyTypeIns {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) (((int) (double) EcmaScript.toNumber(lda.operandStack.pop())) & 0xffff);
// todo: extend value to 32 bits
int value = (int) ((short) (EcmaScript.toInt32(lda.operandStack.pop()) & 0xffff));
lda.operandStack.push(value);
return true;
}

View File

@@ -40,8 +40,7 @@ public class Sxi1Ins extends InstructionDefinition implements AlchemyTypeIns {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) (((int) (double) EcmaScript.toNumber(lda.operandStack.pop())) & 1);
// todo: extend value to 32 bits
int value = -(EcmaScript.toInt32(lda.operandStack.pop()) & 0x1);
lda.operandStack.push(value);
return true;
}

View File

@@ -40,8 +40,7 @@ public class Sxi8Ins extends InstructionDefinition implements AlchemyTypeIns {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double value = (double) (((int) (double) EcmaScript.toNumber(lda.operandStack.pop())) & 0xff);
// todo: extend value to 32 bits
int value = (int) ((byte) (EcmaScript.toInt32(lda.operandStack.pop()) & 0xff));
lda.operandStack.push(value);
return true;
}

View File

@@ -24,7 +24,6 @@ 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.operations.AddAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.EcmaType;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -39,14 +38,8 @@ public class AddIIns extends InstructionDefinition {
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Object right = lda.operandStack.pop();
Object left = lda.operandStack.pop();
if (EcmaScript.type(left) == EcmaType.STRING || EcmaScript.type(right) == EcmaType.STRING) {
String ret = EcmaScript.toString(left) + EcmaScript.toString(right);
lda.operandStack.push(ret);
} else {
int ret = EcmaScript.toInt32(left) + EcmaScript.toInt32(right);
lda.operandStack.push(ret);
}
int ret = EcmaScript.toInt32(left) + EcmaScript.toInt32(right);
lda.operandStack.push(ret);
return true;
}

View File

@@ -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.operations.BitAndAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -35,9 +36,9 @@ public class BitAndIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Long value2 = (Long) lda.operandStack.pop();
Long value1 = (Long) lda.operandStack.pop();
Long value3 = value1 & value2;
long value2 = EcmaScript.toInt32(lda.operandStack.pop());
long value1 = EcmaScript.toInt32(lda.operandStack.pop());
long value3 = value1 & value2;
lda.operandStack.push(value3);
return true;
}

View File

@@ -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.operations.BitOrAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -35,9 +36,9 @@ public class BitOrIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Long value2 = (Long) lda.operandStack.pop();
Long value1 = (Long) lda.operandStack.pop();
Long value3 = value1 | value2;
long value2 = EcmaScript.toInt32(lda.operandStack.pop());
long value1 = EcmaScript.toInt32(lda.operandStack.pop());
long value3 = value1 | value2;
lda.operandStack.push(value3);
return true;
}

View File

@@ -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.operations.BitXorAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -35,9 +36,9 @@ public class BitXorIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Long value2 = (Long) lda.operandStack.pop();
Long value1 = (Long) lda.operandStack.pop();
Long value3 = value1 ^ value2;
long value2 = EcmaScript.toInt32(lda.operandStack.pop());
long value1 = EcmaScript.toInt32(lda.operandStack.pop());
long value3 = value1 ^ value2;
lda.operandStack.push(value3);
return true;
}

View File

@@ -37,8 +37,8 @@ public class LShiftIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
int value2 = EcmaScript.toInt32(lda.operandStack.pop()) & 0x1F;
long value1 = EcmaScript.toInt32(lda.operandStack.pop());
long value3 = value1 << value2;
int value1 = EcmaScript.toInt32(lda.operandStack.pop());
int value3 = value1 << value2;
lda.operandStack.push(value3);
return true;
}

View File

@@ -36,8 +36,8 @@ public class URShiftIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
int value2 = EcmaScript.toInt32(lda.operandStack.pop()) & 0x1F;
long value1 = EcmaScript.toInt32(lda.operandStack.pop());
long value2 = EcmaScript.toInt32(lda.operandStack.pop()) & 0x1F;
long value1 = EcmaScript.toInt32(lda.operandStack.pop()) & 0xffffffffL;
long value3 = value1 >>> value2;
lda.operandStack.push(value3);
return true;

View File

@@ -24,6 +24,7 @@ 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.operations.GeAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -36,9 +37,11 @@ public class GreaterEqualsIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double right = EcmaScript.toNumber(lda.operandStack.pop());
Double left = EcmaScript.toNumber(lda.operandStack.pop());
lda.operandStack.push(left >= right);
Object rightObj = lda.operandStack.pop();
Object leftObj = lda.operandStack.pop();
Object cmp = EcmaScript.compare(leftObj, rightObj);
lda.operandStack.push(cmp != Undefined.INSTANCE && ((int) cmp) != -1);
return true;
}

View File

@@ -24,6 +24,7 @@ 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.operations.GtAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -36,9 +37,11 @@ public class GreaterThanIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double right = EcmaScript.toNumber(lda.operandStack.pop());
Double left = EcmaScript.toNumber(lda.operandStack.pop());
lda.operandStack.push(left > right);
Object rightObj = lda.operandStack.pop();
Object leftObj = lda.operandStack.pop();
Object cmp = EcmaScript.compare(leftObj, rightObj);
lda.operandStack.push(cmp != Undefined.INSTANCE && ((int) cmp) == 1);
return true;
}

View File

@@ -24,6 +24,7 @@ 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.operations.LeAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -36,9 +37,11 @@ public class LessEqualsIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double right = EcmaScript.toNumber(lda.operandStack.pop());
Double left = EcmaScript.toNumber(lda.operandStack.pop());
lda.operandStack.push(left <= right);
Object rightObj = lda.operandStack.pop();
Object leftObj = lda.operandStack.pop();
Object cmp = EcmaScript.compare(leftObj, rightObj);
lda.operandStack.push(cmp != Undefined.INSTANCE && ((int) cmp) != 1);
return true;
}

View File

@@ -24,6 +24,7 @@ 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.operations.LtAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -36,9 +37,11 @@ public class LessThanIns extends InstructionDefinition {
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) {
Double right = EcmaScript.toNumber(lda.operandStack.pop());
Double left = EcmaScript.toNumber(lda.operandStack.pop());
lda.operandStack.push(left < right);
Object rightObj = lda.operandStack.pop();
Object leftObj = lda.operandStack.pop();
Object cmp = EcmaScript.compare(leftObj, rightObj);
lda.operandStack.push(cmp != Undefined.INSTANCE && ((int) cmp) == -1);
return true;
}

View File

@@ -19,8 +19,8 @@ package com.jpexs.decompiler.flash.abc.avm2.instructions.types;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2TypeErrorException;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.exceptions.AVM2TypeErrorException;
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;
@@ -41,6 +41,10 @@ public class ConvertOIns extends InstructionDefinition implements CoerceOrConver
@Override
public boolean execute(LocalDataArea lda, AVM2ConstantPool constants, AVM2Instruction ins) throws AVM2TypeErrorException {
Object obj = lda.operandStack.peek();
if (EcmaScript.type(obj) == EcmaType.NULL) {
throw new AVM2TypeErrorException(1009);
}
if (EcmaScript.type(obj) == EcmaType.UNDEFINED) {
throw new AVM2TypeErrorException(1010);
}

View File

@@ -351,7 +351,7 @@ public class EcmaScript {
return 0L;
}
long posInt = (long) (double) (Math.signum(n) * Math.floor(Math.abs(n)));
posInt %= (1L << 32);
posInt &= 0xffffffffL;
return posInt;
}