AS3 GetSlot,SetSlot fix

This commit is contained in:
Jindra Pet��k
2013-05-03 21:21:22 +02:00
parent 2dd30438c7
commit 71d8f1cace
7 changed files with 72 additions and 11 deletions
@@ -476,6 +476,9 @@ public class ABC {
}
public Trait findTraitByTraitId(int classIndex, int traitId) {
if (classIndex == -1) {
return null;
}
if (traitId < class_info[classIndex].static_traits.traits.length) {
return class_info[classIndex].static_traits.traits[traitId];
} else if (traitId < class_info[classIndex].static_traits.traits.length + instance_info[classIndex].instance_traits.traits.length) {
@@ -487,6 +490,9 @@ public class ABC {
}
public int findMethodIdByTraitId(int classIndex, int traitId) {
if (classIndex == -1) {
return -1;
}
if (traitId < class_info[classIndex].static_traits.traits.length) {
if (class_info[classIndex].static_traits.traits[traitId] instanceof TraitMethodGetterSetter) {
return ((TraitMethodGetterSetter) class_info[classIndex].static_traits.traits[traitId]).method_info;
@@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.abc.types.traits.TraitWithSlot;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -57,8 +58,8 @@ public class GetSlotIns extends InstructionDefinition {
} else if (obj instanceof ScriptTreeItem) {
for (int t = 0; t < abc.script_info[((ScriptTreeItem) obj).scriptIndex].traits.traits.length; t++) {
Trait tr = abc.script_info[((ScriptTreeItem) obj).scriptIndex].traits.traits[t];
if (tr instanceof TraitSlotConst) {
if (((TraitSlotConst) tr).slot_id == slotIndex) {
if (tr instanceof TraitWithSlot) {
if (((TraitWithSlot) tr).getSlotIndex() == slotIndex) {
slotname = tr.getName(abc);
}
}
@@ -66,8 +67,8 @@ public class GetSlotIns extends InstructionDefinition {
} else if (obj instanceof NewActivationTreeItem) {
for (int t = 0; t < body.traits.traits.length; t++) {
if (body.traits.traits[t] instanceof TraitSlotConst) {
if (((TraitSlotConst) body.traits.traits[t]).slot_id == slotIndex) {
if (body.traits.traits[t] instanceof TraitWithSlot) {
if (((TraitWithSlot) body.traits.traits[t]).getSlotIndex() == slotIndex) {
slotname = body.traits.traits[t].getName(abc);
}
}
@@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.abc.avm2.treemodel.IncrementTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.PostDecrementTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.PostIncrementTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.ScriptTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.SetSlotTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.ThisTreeItem;
import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem;
@@ -37,7 +38,9 @@ import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.PreDecrementTree
import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.PreIncrementTreeItem;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.abc.types.traits.TraitWithSlot;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -59,17 +62,27 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
if (obj instanceof NewActivationTreeItem) {
((NewActivationTreeItem) obj).slots.put(slotIndex, value);
}
if (obj instanceof ExceptionTreeItem) {
slotname = constants.constant_multiname[((ExceptionTreeItem) obj).exception.name_index];
} else if (obj instanceof ClassTreeItem) {
slotname = ((ClassTreeItem) obj).className;
} else if (obj instanceof ThisTreeItem) {
slotname = ((ThisTreeItem) obj).className;
} else {
//if(value.startsWith("catched ")) return;
} else if (obj instanceof ScriptTreeItem) {
for (int t = 0; t < abc.script_info[((ScriptTreeItem) obj).scriptIndex].traits.traits.length; t++) {
Trait tr = abc.script_info[((ScriptTreeItem) obj).scriptIndex].traits.traits[t];
if (tr instanceof TraitWithSlot) {
if (((TraitWithSlot) tr).getSlotIndex() == slotIndex) {
slotname = tr.getName(abc);
}
}
}
} else if (obj instanceof NewActivationTreeItem) {
for (int t = 0; t < body.traits.traits.length; t++) {
if (body.traits.traits[t] instanceof TraitSlotConst) {
if (((TraitSlotConst) body.traits.traits[t]).slot_id == slotIndex) {
if (body.traits.traits[t] instanceof TraitWithSlot) {
if (((TraitWithSlot) body.traits.traits[t]).getSlotIndex() == slotIndex) {
slotname = body.traits.traits[t].getName(abc);
}
}
@@ -45,12 +45,17 @@ import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
public class TraitClass extends Trait {
public class TraitClass extends Trait implements TraitWithSlot {
public int slot_id;
public int class_info;
private static final String[] builtInClasses = {"ArgumentError", "arguments", "Array", "Boolean", "Class", "Date", "DefinitionError", "Error", "EvalError", "Function", "int", "JSON", "Math", "Namespace", "Number", "Object", "QName", "RangeError", "ReferenceError", "RegExp", "SecurityError", "String", "SyntaxError", "TypeError", "uint", "URIError", "VerifyError", "XML", "XMLList"};
@Override
public int getSlotIndex() {
return slot_id;
}
private static boolean isBuiltInClass(String name) {
for (String g : builtInClasses) {
if (g.equals(name)) {
@@ -24,11 +24,16 @@ import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.List;
import java.util.Stack;
public class TraitFunction extends Trait {
public class TraitFunction extends Trait implements TraitWithSlot {
public int slot_index;
public int method_info;
@Override
public int getSlotIndex() {
return slot_index;
}
@Override
public String toString(ABC abc, List<String> fullyQualifiedNames) {
return "Function " + abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " slot=" + slot_index + " method_info=" + method_info + " metadata=" + Helper.intArrToString(metadata);
@@ -30,7 +30,7 @@ import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.HashMap;
import java.util.List;
public class TraitSlotConst extends Trait {
public class TraitSlotConst extends Trait implements TraitWithSlot {
public int slot_id;
public int type_index;
@@ -38,6 +38,11 @@ public class TraitSlotConst extends Trait {
public int value_kind;
public GraphTargetItem assignedValue;
@Override
public int getSlotIndex() {
return slot_id;
}
@Override
public String toString(ABC abc, List<String> fullyQualifiedNames) {
String typeStr = "*";
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2013 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.abc.types.traits;
/**
*
* @author JPEXS
*/
public interface TraitWithSlot {
public int getSlotIndex();
}