Fixed using temporary registers after for..in (causing §§pop instructions, etc.)

This commit is contained in:
Jindra Petřík
2018-05-27 10:49:42 +02:00
parent 8b91bfc1d7
commit 6ec124f71a
12 changed files with 182 additions and 6 deletions

View File

@@ -0,0 +1,55 @@
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf5.ActionEnumerate;
import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import static com.jpexs.decompiler.graph.GraphTargetItem.PRECEDENCE_PRIMARY;
import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.model.BranchStackResistant;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class EnumeratedValueActionItem extends ActionItem implements BranchStackResistant {
@Override
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
return ret;
}
public EnumeratedValueActionItem() {
super(null, null, PRECEDENCE_PRIMARY);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return writer.append("§§enumeration()");
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
}
@Override
public boolean hasReturnValue() {
return false;
}
}

View File

@@ -0,0 +1,55 @@
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf5.ActionEnumerate;
import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import static com.jpexs.decompiler.graph.GraphTargetItem.PRECEDENCE_PRIMARY;
import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.model.BranchStackResistant;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class EnumerationAssignmentValueActionItem extends ActionItem {
@Override
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
return ret;
}
public EnumerationAssignmentValueActionItem() {
super(null, null, PRECEDENCE_PRIMARY);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return writer.append("§§enum_assign()");
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
}
@Override
public boolean hasReturnValue() {
return true;
}
}

View File

@@ -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.swf5;
import com.jpexs.decompiler.flash.BaseLocalData;
@@ -20,6 +21,7 @@ import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionScriptObject;
import com.jpexs.decompiler.flash.action.LocalDataArea;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.flash.action.model.EnumeratedValueActionItem;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -67,7 +69,7 @@ public class ActionEnumerate extends Action {
@Override
public void translate(boolean insideDoInitAction, GraphSourceItem lineStartAction, TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem object = stack.pop();
GraphTargetItem object = stack.pop();
stack.push(new EnumeratedValueActionItem());
output.add(new EnumerateActionItem(this, lineStartAction, object));
}

View File

@@ -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.swf5;
import com.jpexs.decompiler.flash.BaseLocalData;
@@ -24,6 +25,8 @@ import com.jpexs.decompiler.flash.action.StoreTypeAction;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import com.jpexs.decompiler.flash.action.model.DecrementActionItem;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.model.EnumeratedValueActionItem;
import com.jpexs.decompiler.flash.action.model.EnumerationAssignmentValueActionItem;
import com.jpexs.decompiler.flash.action.model.IncrementActionItem;
import com.jpexs.decompiler.flash.action.model.PostDecrementActionItem;
import com.jpexs.decompiler.flash.action.model.PostIncrementActionItem;
@@ -113,6 +116,13 @@ public class ActionStoreRegister extends Action implements StoreTypeAction {
if (regNames.containsKey(registerNumber)) {
define = false;
}
if (value instanceof TemporaryRegister) {
if (((TemporaryRegister) value).value instanceof EnumerationAssignmentValueActionItem) {
value = ((TemporaryRegister) value).value;
}
}
variables.put("__register" + registerNumber, value);
if (value instanceof DirectValueActionItem) {
if (((DirectValueActionItem) value).value instanceof RegisterNumber) {
@@ -147,6 +157,10 @@ public class ActionStoreRegister extends Action implements StoreTypeAction {
return;
}
}
if ((value instanceof EnumeratedValueActionItem)) {
variables.put("__register" + registerNumber, new TemporaryRegister(registerNumber, new EnumerationAssignmentValueActionItem()));
}
stack.push(new StoreRegisterActionItem(this, lineStartAction, rn, value, define));
}

View File

@@ -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.swf6;
import com.jpexs.decompiler.flash.BaseLocalData;
@@ -20,6 +21,7 @@ import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionScriptObject;
import com.jpexs.decompiler.flash.action.LocalDataArea;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.flash.action.model.EnumeratedValueActionItem;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -47,6 +49,7 @@ public class ActionEnumerate2 extends Action {
@Override
public void translate(boolean insideDoInitAction, GraphSourceItem lineStartAction, TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem object = stack.pop();
stack.push(new EnumeratedValueActionItem());
output.add(new EnumerateActionItem(this, lineStartAction, object));
}

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BranchStackResistant;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DefaultItem;
@@ -1729,7 +1730,13 @@ public class Graph {
if (isLoop) {
//makeAllCommands(currentRet, stack);
stack = (TranslateStack) stack.clone();
//hack for as1/2 for..in to get enumeration through
GraphTargetItem topBsr = !stack.isEmpty() && (stack.peek() instanceof BranchStackResistant) ? stack.peek() : null;
stack.clear();
if (topBsr != null) {
stack.push(topBsr);
}
loopItem = new UniversalLoopItem(null, localData.lineStartInstruction, currentLoop, new ArrayList<>());
//loopItem.commands=printGraph(visited, localData, stack, allParts, parent, part, stopPart, loops);
currentRet.add(loopItem);
@@ -1980,9 +1987,15 @@ public class Graph {
GraphPart next = getCommonPart(localData, nps, loops);
TranslateStack trueStack = (TranslateStack) stack.clone();
TranslateStack falseStack = (TranslateStack) stack.clone();
//hack for as1/2 for..in to get enumeration through
GraphTargetItem topBsr = !stack.isEmpty() && (stack.peek() instanceof BranchStackResistant) ? stack.peek() : null;
trueStack.clear();
falseStack.clear();
if (topBsr != null) {
trueStack.add(topBsr);
falseStack.add(topBsr);
}
if (isEmpty) {
next = nps.get(0);
}
@@ -2534,6 +2547,9 @@ public class Graph {
}
while (stack.size() > 0) {
GraphTargetItem p = stack.pop();
if (p instanceof BranchStackResistant) {
continue;
}
if (!(p instanceof PopItem)) {
if (p instanceof FunctionActionItem) {
commands.add(clen, p);

View File

@@ -0,0 +1,11 @@
package com.jpexs.decompiler.graph.model;
/**
* An item which is passed on top of the stack when processing if branches or
* loop body. This is actually a hack to process AS1/2 for..in clauses
*
* @author JPEXS
*/
public interface BranchStackResistant {
}

View File

@@ -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.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;