mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-18 06:01:53 +00:00
AS3: Detecting local register types
This commit is contained in:
@@ -1832,6 +1832,23 @@ public HashMap<Integer,String> getLocalRegNamesFromDebug(ABC abc){
|
||||
return maxRegister+1;
|
||||
}
|
||||
|
||||
public HashMap<Integer,String> getLocalRegTypes(ConstantPool constants){
|
||||
HashMap<Integer,String> ret=new HashMap<Integer,String>();
|
||||
AVM2Instruction prev=null;
|
||||
for(AVM2Instruction ins:code){
|
||||
if(ins.definition instanceof SetLocalTypeIns){
|
||||
if(prev!=null){
|
||||
if(prev.definition instanceof CoerceOrConvertTypeIns)
|
||||
{
|
||||
ret.put(((SetLocalTypeIns)ins.definition).getRegisterId(ins),((CoerceOrConvertTypeIns)prev.definition).getTargetType(constants, prev));
|
||||
}
|
||||
}
|
||||
}
|
||||
prev=ins;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted,HashMap<Integer,String> localRegNames) {
|
||||
toSourceCount = 0;
|
||||
loopList = new ArrayList<Loop>();
|
||||
@@ -1866,10 +1883,15 @@ public HashMap<Integer,String> getLocalRegNamesFromDebug(ABC abc){
|
||||
paramCount++;
|
||||
}
|
||||
}
|
||||
HashMap<Integer,String> localRegTypes=getLocalRegTypes(constants);
|
||||
for(int i=paramCount+1;i<regCount;i++)
|
||||
{
|
||||
if((!(localRegs.get(i) instanceof NewActivationTreeItem))&&(!isKilled(i, 0, code.size()-1))){
|
||||
sub+="var "+TreeItem.localRegName(localRegNames,i)+";\r\n";
|
||||
sub+="var "+TreeItem.localRegName(localRegNames,i);
|
||||
if(localRegTypes.containsKey(i)){
|
||||
sub+=":"+localRegTypes.get(i);
|
||||
}
|
||||
sub+=";\r\n";
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -36,6 +36,10 @@ public class CoerceAIns extends InstructionDefinition implements CoerceOrConvert
|
||||
super(0x82, "coerce_a", new int[]{});
|
||||
}
|
||||
|
||||
public String getTargetType(){
|
||||
return "*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
|
||||
//coerce any type
|
||||
@@ -51,4 +55,8 @@ public class CoerceAIns extends InstructionDefinition implements CoerceOrConvert
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "*";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,11 @@ public class CoerceIns extends InstructionDefinition implements CoerceOrConvertT
|
||||
int multinameIndex = ins.operands[0];
|
||||
stack.push(new CoerceTreeItem(ins, (TreeItem) stack.pop(), constants.constant_multiname[multinameIndex].getName(constants)));
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
int multinameIndex = ins.operands[0];
|
||||
return constants.constant_multiname[multinameIndex].getName(constants);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
|
||||
package com.jpexs.asdec.abc.avm2.instructions.types;
|
||||
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface CoerceOrConvertTypeIns {
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins);
|
||||
}
|
||||
|
||||
@@ -52,4 +52,8 @@ public class CoerceSIns extends InstructionDefinition implements CoerceOrConvert
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "String";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,8 @@ public class ConvertBIns extends InstructionDefinition implements CoerceOrConver
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "Boolean";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +69,8 @@ public class ConvertDIns extends InstructionDefinition implements CoerceOrConver
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "Number";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,4 +67,8 @@ public class ConvertIIns extends InstructionDefinition implements CoerceOrConver
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "int";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,8 @@ public class ConvertOIns extends InstructionDefinition implements CoerceOrConver
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "Object";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,8 @@ public class ConvertSIns extends InstructionDefinition implements CoerceOrConver
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "String";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,8 @@ public class ConvertUIns extends InstructionDefinition implements CoerceOrConver
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return -1+1;
|
||||
}
|
||||
|
||||
public String getTargetType(ConstantPool constants,AVM2Instruction ins){
|
||||
return "uint";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user