From 71d8f1caced8827a7726f07c6f4b0005e2614a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Fri, 3 May 2013 21:21:22 +0200 Subject: [PATCH] AS3 GetSlot,SetSlot fix --- .../com/jpexs/decompiler/flash/abc/ABC.java | 6 +++++ .../avm2/instructions/other/GetSlotIns.java | 9 ++++--- .../avm2/instructions/other/SetSlotIns.java | 21 ++++++++++++--- .../flash/abc/types/traits/TraitClass.java | 7 ++++- .../flash/abc/types/traits/TraitFunction.java | 7 ++++- .../abc/types/traits/TraitSlotConst.java | 7 ++++- .../flash/abc/types/traits/TraitWithSlot.java | 26 +++++++++++++++++++ 7 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitWithSlot.java diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index 4c7b58ee2..f17f9a6b4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -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; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSlotIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSlotIns.java index fff0c3b4f..8c180091f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSlotIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetSlotIns.java @@ -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); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java index 10e978d13..d94b4c812 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetSlotIns.java @@ -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); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 4952afbdd..e24b132d8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -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)) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index 530f3f11c..2faeebc24 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -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 fullyQualifiedNames) { return "Function " + abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " slot=" + slot_index + " method_info=" + method_info + " metadata=" + Helper.intArrToString(metadata); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index 72d7c4c2d..e1f0c14df 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -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 fullyQualifiedNames) { String typeStr = "*"; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitWithSlot.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitWithSlot.java new file mode 100644 index 000000000..8c03b0137 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitWithSlot.java @@ -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 . + */ +package com.jpexs.decompiler.flash.abc.types.traits; + +/** + * + * @author JPEXS + */ +public interface TraitWithSlot { + + public int getSlotIndex(); +}