diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e15e094..c03fd29be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Changed +- AS1/2 Better unresolved constant handling - §§constant(xx) func instead of §§constantxx ## [11.1.0] - 2018-05-24 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java index 3c123ca6d..f29fd5e71 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.abc.RenameType; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java new file mode 100644 index 000000000..b9fbc0107 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2010-2018 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. */ +package com.jpexs.decompiler.flash.action.model; + +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.swf4.ActionPush; +import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; +import com.jpexs.decompiler.flash.ecma.Undefined; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.SimpleValue; +import com.jpexs.decompiler.graph.SourceGenerator; +import com.jpexs.decompiler.graph.model.LocalData; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +/** + * + * @author JPEXS + */ +public class UnresolvedConstantActionItem extends ActionItem implements SimpleValue { + + public GraphTargetItem computedRegValue; + + public final int pos; + + private int index; + + public UnresolvedConstantActionItem(int index) { + this(null, null, 0, index); + } + + public UnresolvedConstantActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, int instructionPos, int index) { + super(instruction, lineStartIns, PRECEDENCE_PRIMARY); + this.index = index; + this.pos = instructionPos; + } + + @Override + protected int getPos() { + return pos; + } + + @Override + public boolean isVariableComputed() { + return (computedRegValue != null); + } + + @Override + public Object getResult() { + return Undefined.INSTANCE; + } + + @Override + public boolean isSimpleValue() { + return false; + } + + @Override + public String toStringNoQuotes(LocalData localData) { + return "\u00A7\u00A7constant(" + index + ")"; + } + + public int getIndex() { + return index; + } + + @Override + public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) { + return writer.append("\u00A7\u00A7constant(" + index + ")"); + } + + public String toStringNoH(ConstantPool constants) { + return "\u00A7\u00A7constant(" + index + ")"; + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { + return writer.append("\u00A7\u00A7constant(" + index + ")"); + } + + @Override + public boolean isCompileTime(Set dependencies) { + return true; + } + + @Override + public int hashCode() { + return index; + } + + @Override + public boolean valueEquals(GraphTargetItem obj) { + if (obj == null) { + return false; + } + if (!(obj instanceof UnresolvedConstantActionItem)) { + return false; + } + final UnresolvedConstantActionItem other = (UnresolvedConstantActionItem) obj; + if (!Objects.equals(index, other.index)) { + return false; + } + + return true; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final UnresolvedConstantActionItem other = (UnresolvedConstantActionItem) obj; + if (!Objects.equals(this.index, other.index)) { + return false; + } + return true; + } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + return toSourceMerge(localData, generator, new ActionPush(new ConstantIndex(index))); + } + + @Override + public boolean hasReturnValue() { + return true; + } + + public boolean isString() { + return true; + } + + public String getAsString() { + if (!isString()) { + return null; + } + return (String) getResult(); + } + + @Override + public String toString() { + return "" + getResult(); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index 9e506a13a..52862a607 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -80,6 +80,7 @@ import com.jpexs.decompiler.flash.action.model.TraceActionItem; import com.jpexs.decompiler.flash.action.model.TypeOfActionItem; import com.jpexs.decompiler.flash.action.model.UnLoadMovieActionItem; import com.jpexs.decompiler.flash.action.model.UnLoadMovieNumActionItem; +import com.jpexs.decompiler.flash.action.model.UnresolvedConstantActionItem; import com.jpexs.decompiler.flash.action.model.clauses.ClassActionItem; import com.jpexs.decompiler.flash.action.model.clauses.ForInActionItem; import com.jpexs.decompiler.flash.action.model.clauses.IfFrameLoadedActionItem; @@ -1583,6 +1584,12 @@ public class ActionScript2Parser { expectedType(SymbolType.PARENT_OPEN); switch ("" + s.value) { //AS 1/2: + //AS2: + case "constant": + s = lexer.lex(); + expected(s, lexer.yyline(), SymbolType.INTEGER); + ret = new UnresolvedConstantActionItem((int) (long) (Long) s.value); + break; case "enumerate": ret = new EnumerateActionItem(null, null, expression(inFunction, inMethod, allowRemainder, variables, functions)); break; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index bcf989921..9d22ee15c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.LocalDataArea; import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; import com.jpexs.decompiler.flash.action.model.TemporaryRegister; +import com.jpexs.decompiler.flash.action.model.UnresolvedConstantActionItem; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; @@ -394,7 +395,8 @@ public class ActionPush extends Action { for (Object o : values) { if (o instanceof ConstantIndex) { if ((constantPool == null) || (((ConstantIndex) o).index >= constantPool.size())) { - o = "\u00A7\u00A7constant" + ((ConstantIndex) o).index; + stack.push(new UnresolvedConstantActionItem(((ConstantIndex) o).index)); + continue; } else { o = constantPool.get(((ConstantIndex) o).index); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ConstantIndex.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ConstantIndex.java index cd3658621..d3d573523 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ConstantIndex.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ConstantIndex.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.action.swf4; import com.jpexs.helpers.Helper;