diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f9eb4c1..e33e26605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Added - Translator tool for easier localization +- AS3 improved goto declaration for properties and methods ### Fixed - [#1769] AS3 - Missing some body trait variable declaration diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropLexIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropLexIns.java index 47d20835f..6c70455fb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropLexIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropLexIns.java @@ -86,7 +86,7 @@ public class CallPropLexIns extends CallPropertyIns { Reference isStatic = new Reference<>(false); GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, receiver, multiname, isStatic, true); - stack.push(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, false, receiver, multiname, args, type)); + stack.push(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, false, receiver, multiname, args, type, isStatic.getVal())); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropVoidIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropVoidIns.java index 8c96966aa..b5e624124 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropVoidIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropVoidIns.java @@ -85,7 +85,7 @@ public class CallPropVoidIns extends InstructionDefinition { GraphTargetItem receiver = stack.pop(); Reference isStatic = new Reference<>(false); GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, receiver, multiname, isStatic, true); - output.add(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, true, receiver, multiname, args, type)); + output.add(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, true, receiver, multiname, args, type, isStatic.getVal())); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropertyIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropertyIns.java index edf3c4946..4319dcfa0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropertyIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/executing/CallPropertyIns.java @@ -86,7 +86,7 @@ public class CallPropertyIns extends InstructionDefinition { Reference isStatic = new Reference<>(false); GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, receiver, multiname, isStatic, true); - stack.push(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, false, receiver, multiname, args, type)); + stack.push(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, false, receiver, multiname, args, type, isStatic.getVal())); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/DeletePropertyIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/DeletePropertyIns.java index b4e122e7c..f79ea55c6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/DeletePropertyIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/DeletePropertyIns.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.DeletePropertyAVM2Item; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; +import com.jpexs.helpers.Reference; import java.util.List; /** @@ -55,8 +56,9 @@ public class DeletePropertyIns extends InstructionDefinition { int multinameIndex = ins.operands[0]; FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins); GraphTargetItem obj = stack.pop(); - //stack.add(new BooleanAVM2Item(ins, localData.lineStartInstruction, Boolean.TRUE));//property successfully deleted - stack.add(new DeletePropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname)); + Reference isStatic = new Reference<>(false); + GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, obj, multiname, isStatic, true); + stack.add(new DeletePropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, isStatic.getVal())); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java index 4519ef61d..938dd580a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetLexIns.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.AVM2LocalData; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; 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.FindPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.script.PropertyAVM2Item; @@ -30,6 +31,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.TypeItem; +import com.jpexs.helpers.Reference; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -44,12 +46,13 @@ public class GetLexIns extends InstructionDefinition { super(0x60, "getlex", new int[]{AVM2Code.DAT_MULTINAME_INDEX}, true); } - @Override - public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) { - int multinameIndex = ins.operands[0]; - Multiname multiname = localData.getConstants().getMultiname(multinameIndex); - String multinameStr = multiname.getName(localData.abc.constants, new ArrayList<>(), true, true); - GraphTargetItem slotType = null; + public static GraphTargetItem resolveLexType( + AVM2LocalData localData, + GraphTargetItem obj, + int multinameIndex, + Reference isStatic, boolean call) { + GraphTargetItem type = null; + String multinameStr = localData.abc.constants.getMultiname(multinameIndex).getName(localData.abc.constants, new ArrayList<>(), true, true); for (Trait t : localData.methodBody.traits.traits) { if (t instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) t; @@ -57,35 +60,50 @@ public class GetLexIns extends InstructionDefinition { tsc.getName(localData.abc).getName(localData.abc.constants, new ArrayList<>(), true, true), multinameStr )) { - slotType = PropertyAVM2Item.multinameToType(tsc.type_index, localData.abc.constants); + type = PropertyAVM2Item.multinameToType(tsc.type_index, localData.abc.constants); break; } } } - boolean isStatic = false; - if (slotType == null) { + if (type == null) { if (localData.abcIndex != null) { - String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString(); - GraphTargetItem thisPropType = currentClassName == null ? TypeItem.UNBOUNDED : localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true); - if (!thisPropType.equals(TypeItem.UNBOUNDED)) { - slotType = thisPropType; + String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString(); + GraphTargetItem thisPropType = TypeItem.UNBOUNDED; + if (currentClassName != null) { + if (call) { + thisPropType = localData.abcIndex.findPropertyCallType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true); + } else { + thisPropType = localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true); + } } - - if (slotType == null) { - TypeItem ti = new TypeItem(multiname.getNameWithNamespace(localData.abc.constants, true)); + if (!thisPropType.equals(TypeItem.UNBOUNDED)) { + type = thisPropType; + } + + if (type == null) { + TypeItem ti = new TypeItem(localData.abc.constants.getMultiname(multinameIndex).getNameWithNamespace(localData.abc.constants, true)); if (localData.abcIndex.findClass(ti) != null) { - slotType = ti; - isStatic = true; + type = ti; + isStatic.setVal(true); } } } } - if (slotType == null) { - slotType = TypeItem.UNBOUNDED; + if (type == null) { + type = TypeItem.UNBOUNDED; } - stack.push(new GetLexAVM2Item(ins, localData.lineStartInstruction, multiname, localData.getConstants(), slotType, isStatic)); + return type; + } + + @Override + public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) { + int multinameIndex = ins.operands[0]; + Multiname multiname = localData.getConstants().getMultiname(multinameIndex); + Reference isStatic = new Reference<>(false); + GraphTargetItem type = GetLexIns.resolveLexType(localData, null, multinameIndex, isStatic, false); + stack.push(new GetLexAVM2Item(ins, localData.lineStartInstruction, multiname, localData.getConstants(), type, isStatic.getVal())); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java index 63d79c2e8..24dd00e6e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java @@ -26,6 +26,8 @@ import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ExceptionAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; +import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -72,7 +74,7 @@ public abstract class AVM2Item extends GraphTargetItem { return true; } - protected GraphTextWriter formatProperty(GraphTextWriter writer, GraphTargetItem object, GraphTargetItem propertyName, LocalData localData) throws InterruptedException { + protected GraphTextWriter formatProperty(GraphTextWriter writer, GraphTargetItem object, GraphTargetItem propertyName, LocalData localData, boolean isStatic) throws InterruptedException { boolean empty = object.getThroughDuplicate() instanceof FindPropertyAVM2Item; if (object instanceof LocalRegAVM2Item) { if (((LocalRegAVM2Item) object).computedValue != null) { @@ -110,22 +112,22 @@ public abstract class AVM2Item extends GraphTargetItem { if (propertyName instanceof FullMultinameAVM2Item) { - //TODO: use type information in the GUI - /*HighlightData data = new HighlightData(); + HighlightData data = new HighlightData(); int multinameIndex = ((FullMultinameAVM2Item) propertyName).multinameIndex; int namespaceIndex = localData.constantsAvm2.getMultiname(multinameIndex).namespace_index; - data.specialValue = object.returnType().toString(); - data.namespaceIndex = namespaceIndex;*/ + data.propertyType = object.returnType().toString(); + data.namespaceIndex = namespaceIndex; + data.isStatic = isStatic; if (((FullMultinameAVM2Item) propertyName).name != null) { if (((FullMultinameAVM2Item) propertyName).namespace != null) { - writer.append("."); - //writer.hilightSpecial(".", HighlightSpecialType.PROPERTY_PARENT_TYPE, 0, data); + //writer.append("."); + writer.hilightSpecial(".", HighlightSpecialType.PROPERTY_TYPE, 0, data); } return propertyName.toString(writer, localData); } else { - //writer.hilightSpecial(".", HighlightSpecialType.PROPERTY_PARENT_TYPE, 0, data); - writer.append("."); + writer.hilightSpecial(".", HighlightSpecialType.PROPERTY_TYPE, 0, data); + //writer.append("."); return propertyName.toString(writer, localData); } } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CallPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CallPropertyAVM2Item.java index eca6ce6bb..057cef6c1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CallPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/CallPropertyAVM2Item.java @@ -46,14 +46,17 @@ public class CallPropertyAVM2Item extends AVM2Item { public boolean isVoid; public GraphTargetItem type; + + public boolean isStatic; - public CallPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, boolean isVoid, GraphTargetItem receiver, GraphTargetItem propertyName, List arguments, GraphTargetItem type) { + public CallPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, boolean isVoid, GraphTargetItem receiver, GraphTargetItem propertyName, List arguments, GraphTargetItem type, boolean isStatic) { super(instruction, lineStartIns, PRECEDENCE_PRIMARY); this.receiver = receiver; this.propertyName = propertyName; this.arguments = arguments; this.isVoid = isVoid; this.type = type; + this.isStatic = isStatic; } @Override @@ -65,7 +68,7 @@ public class CallPropertyAVM2Item extends AVM2Item { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - formatProperty(writer, receiver, propertyName, localData); + formatProperty(writer, receiver, propertyName, localData, isStatic); writer.spaceBeforeCallParenthesies(arguments.size()); writer.append("("); for (int a = 0; a < arguments.size(); a++) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetPropertyAVM2Item.java index c8ebdeba9..e8b3d2435 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetPropertyAVM2Item.java @@ -141,7 +141,7 @@ public class GetPropertyAVM2Item extends AVM2Item { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - return formatProperty(writer, object, propertyName, localData); + return formatProperty(writer, object, propertyName, localData, isStatic); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java index dd3c17132..1af7f9554 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java @@ -73,7 +73,7 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - formatProperty(writer, object, propertyName, localData); + formatProperty(writer, object, propertyName, localData, isStatic); if (compoundOperator != null) { writer.append(" "); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java index 71fad02ba..43fd1e875 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java @@ -88,7 +88,7 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - formatProperty(writer, object, propertyName, localData); + formatProperty(writer, object, propertyName, localData, isStatic); if (compoundOperator != null) { writer.append(" "); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/AsTypeAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/AsTypeAVM2Item.java index 382f1452b..2fe75d922 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/AsTypeAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/AsTypeAVM2Item.java @@ -19,10 +19,13 @@ package com.jpexs.decompiler.flash.abc.avm2.model.operations; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; +import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; +import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.BinaryOpItem; import java.util.ArrayList; import java.util.List; @@ -45,8 +48,8 @@ public class AsTypeAVM2Item extends BinaryOpItem { } @Override - public GraphTargetItem returnType() { - return rightSide; + public GraphTargetItem returnType() { + return rightSide.returnType(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/DeletePropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/DeletePropertyAVM2Item.java index 0af1f74a6..06db4a2ad 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/DeletePropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/DeletePropertyAVM2Item.java @@ -45,13 +45,15 @@ public class DeletePropertyAVM2Item extends AVM2Item { public GraphTargetItem object; public GraphTargetItem propertyName; - + private int line; + public boolean isStatic; + //Constructor for compiler public DeletePropertyAVM2Item(GraphTargetItem property, int line) { - this(null, null, property, null); - this.line = line; + this(null, null, property, null, false); + this.line = line; } @Override @@ -60,16 +62,17 @@ public class DeletePropertyAVM2Item extends AVM2Item { visitor.visit(propertyName); } - public DeletePropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName) { + public DeletePropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName, boolean isStatic) { super(instruction, lineStartIns, PRECEDENCE_UNARY); this.object = object; this.propertyName = propertyName; + this.isStatic = isStatic; } @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { writer.append("delete "); - formatProperty(writer, object, propertyName, localData); + formatProperty(writer, object, propertyName, localData, isStatic); return writer; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java index 29b673f04..66e2febd2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java @@ -46,13 +46,18 @@ public class HighlightData implements Cloneable, Serializable { public int regIndex = -1; public int namespaceIndex = -1; + + public boolean isStatic = false; + + public String propertyType; public boolean isEmpty() { return !declaration && declaredType == null && localName == null && subtype == null && specialValue == null && index == 0 && offset == 0 && regIndex == -1 && firstLineOffset == -1 && fileOffset == -1 - && namespaceIndex == -1; + && namespaceIndex == -1 + && propertyType == null; } public void merge(HighlightData data) { @@ -92,6 +97,12 @@ public class HighlightData implements Cloneable, Serializable { if (data.namespaceIndex != -1) { namespaceIndex = data.namespaceIndex; } + if (data.isStatic) { + isStatic = data.isStatic; + } + if (data.propertyType != null) { + propertyType = data.propertyType; + } } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java index d00b9382e..07fe713be 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java @@ -31,5 +31,5 @@ public enum HighlightSpecialType { TRY_TYPE, TRY_NAME, TEXT, ATTR_METADATA, ATTR_FINAL, ATTR_OVERRIDE, ATTR_0x8, - PROPERTY_PARENT_TYPE + PROPERTY_TYPE } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 48f1fb8a1..c818278af 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -1171,7 +1171,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener multinameIndexRef = new Reference<>(0); Reference classTrait = new Reference<>(false); Reference usedAbcRef = new Reference<>(null); - if (decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef)) { + if (decompiledTextArea.getPropertyTypeAtPos(getSwf().getAbcIndex(), pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef)) { return true; } ABC usedAbc = usedAbcRef.getVal(); @@ -1224,7 +1224,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener classTrait = new Reference<>(false); Reference multinameIndexRef = new Reference<>(0); Reference usedAbcRef = new Reference<>(null); - if (decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef)) { + if (decompiledTextArea.getPropertyTypeAtPos(getSwf().getAbcIndex(), pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef)) { UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(getAbcList().get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(), decompiledTextArea.getScriptLeaf().scriptIndex, classIndex.getVal(), traitIndex.getVal(), classTrait.getVal() ? TraitMultinameUsage.TRAITS_TYPE_CLASS : TraitMultinameUsage.TRAITS_TYPE_INSTANCE, null, -1) { }); return; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index cba691558..8710c7a58 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructSuperIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallSuperIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallSuperVoidIns; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ClassInfo; import com.jpexs.decompiler.flash.abc.types.InstanceInfo; import com.jpexs.decompiler.flash.abc.types.Multiname; @@ -32,6 +33,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction; import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.action.deobfuscation.BrokenScriptDetector; import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.gui.Main; @@ -44,6 +46,7 @@ import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.graph.DottedChain; +import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.awt.Point; @@ -317,27 +320,96 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL return -1; } - public boolean getPropertyTypeAtPos(int pos, Reference abcIndex, Reference classIndex, Reference traitIndex, Reference classTrait, Reference multinameIndex, Reference abcUsed) { + public boolean getPropertyTypeAtPos(AbcIndexing indexing, int pos, Reference abcIndex, Reference classIndex, Reference traitIndex, Reference classTrait, Reference multinameIndex, Reference abcUsed) { int m = getMultinameAtPos(pos, true, abcUsed); - if (m <= 0) { + + if (indexing == null) { return false; } + /*int m = getMultinameAtPos(pos, true, abcUsed); + if (m <= 0) { + return false; + }*/ SyntaxDocument sd = (SyntaxDocument) getDocument(); Token t = sd.getTokenAt(pos + 1); Token lastToken = t; Token prev; - while (t.type == TokenType.IDENTIFIER || t.type == TokenType.KEYWORD || t.type == TokenType.REGEX) { - prev = sd.getPrevToken(t); - if (prev != null) { - if (!".".equals(prev.getString(sd))) { - break; - } - t = sd.getPrevToken(prev); - } else { + String propName = t.getString(sd); + if (!(t.type == TokenType.IDENTIFIER || t.type == TokenType.KEYWORD || t.type == TokenType.REGEX)) { + return false; + } + prev = sd.getPrevToken(t); + if (prev == null) { + return false; + } + if (!".".equals(prev.getString(sd))) { + return false; + } + Highlighting sh = Highlighting.search(highlightedText.getSpecialHighlights(), new HighlightData(), prev.start, prev.start); + if (sh == null) { + return false; + } + + HighlightData data = sh.getProperties(); + + String parentType = data.propertyType; + if (parentType.equals("*")) { + return false; + } + AbcIndexing.TraitIndex propertyTraitIndex = indexing.findProperty(new AbcIndexing.PropertyDef(propName, new TypeItem(parentType), getABC(), data.namespaceIndex), data.isStatic, !data.isStatic); + if (propertyTraitIndex == null) { + return false; + } + + List abcs = getABC().getSwf().getAbcList(); + int index = 0; + boolean found = false; + for (ABCContainerTag cnt:abcs) { + if (cnt.getABC() == propertyTraitIndex.abc) { + abcIndex.setVal(index); + found = true; + break; + } + index++; + } + if (!found) { + return false; + } + + abcUsed.setVal(propertyTraitIndex.abc); + + index = propertyTraitIndex.abc.findClassByName(propertyTraitIndex.objType.toString()); + if (index == -1) { + return false; + } + classIndex.setVal(index); + + classTrait.setVal(data.isStatic); + + Traits ts; + if (data.isStatic) { + ts = propertyTraitIndex.abc.class_info.get(index).static_traits; + } else { + ts = propertyTraitIndex.abc.instance_info.get(index).instance_traits; + } + + found = false; + for (int i = 0; i < ts.traits.size(); i++) { + if (ts.traits.get(i) == propertyTraitIndex.trait) { + traitIndex.setVal(i); + found = true; break; } } + if (!found) { + return false; + } + + multinameIndex.setVal(propertyTraitIndex.trait.name_index); + + return true; + /* if (t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD && t.type != TokenType.REGEX) { return false; } @@ -346,9 +418,8 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL DottedChain currentType = locTypeRef.getVal(); if (currentType.equals(DottedChain.ALL)) { return false; - } - boolean found; - + } + while (!currentType.equals(DottedChain.ALL)) { String ident = t.getString(sd); found = false; @@ -361,7 +432,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL InstanceInfo ii = a.instance_info.get(cindex); for (int j = 0; j < ii.instance_traits.traits.size(); j++) { Trait tr = ii.instance_traits.traits.get(j); - if (ident.equals(tr.getName(a).getName(a.constants, null, false /*NOT RAW!*/, true))) { + if (ident.equals(tr.getName(a).getName(a.constants, null, false --not raw--, true))) { classIndex.setVal(cindex); abcIndex.setVal(i); traitIndex.setVal(j); @@ -376,7 +447,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL ClassInfo ci = a.class_info.get(cindex); for (int j = 0; j < ci.static_traits.traits.size(); j++) { Trait tr = ci.static_traits.traits.get(j); - if (ident.equals(tr.getName(a).getName(a.constants, null, false /*NOT RAW!*/, true))) { + if (ident.equals(tr.getName(a).getName(a.constants, null, false --not raw--, true))) { classIndex.setVal(cindex); abcIndex.setVal(i); traitIndex.setVal(j); @@ -402,7 +473,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } t = sd.getNextToken(t); } - return true; + return true;*/ } public int getMultinameAtPos(int pos, Reference abcUsed) {