Fixed #1867 AS3 - §§hasnext, §§nextvalue, §§nextname in some nonstandard compiled SWFs

This commit is contained in:
Jindra Petřík
2022-11-14 18:06:25 +01:00
parent 8d3d3eb62f
commit e33474d6f9
5 changed files with 53 additions and 2 deletions

View File

@@ -119,7 +119,7 @@ public class AVM2LocalData extends BaseLocalData {
public boolean inGetLoops = false;
public Set<Integer> seenMethods = new HashSet<>();
public AVM2LocalData() {
}

View File

@@ -80,6 +80,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.clauses.TryAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.StrictEqAVM2Item;
import com.jpexs.decompiler.flash.abc.types.ABCException;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.decompiler.graph.Graph;
import com.jpexs.decompiler.graph.GraphException;
@@ -88,6 +89,7 @@ import com.jpexs.decompiler.graph.GraphPartChangeException;
import com.jpexs.decompiler.graph.GraphSource;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.GraphTargetVisitorInterface;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.StopPartKind;
@@ -1906,7 +1908,40 @@ public class AVM2Graph extends Graph {
} else if (gti instanceof NextNameAVM2Item) {
return new ForInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(), varName, collection), w.commands);
}
} else {
GraphTargetItem first = w.commands.get(0);
Reference<Integer> kindRef = new Reference<>(0);
first.visitRecursively(new AbstractGraphTargetVisitor() {
private boolean handled = false;
@Override
public void visit(GraphTargetItem item) {
if (handled) {
return;
}
if ((item instanceof NextNameAVM2Item) || (item instanceof NextValueAVM2Item)) {
handled = true;
if (item instanceof NextValueAVM2Item){
NextValueAVM2Item nv = (NextValueAVM2Item) item;
nv.localReg = hn.index;
kindRef.setVal(1);
}
if (item instanceof NextNameAVM2Item){
NextNameAVM2Item nn = (NextNameAVM2Item) item;
nn.localReg = hn.index;
kindRef.setVal(2);
}
}
}
});
if (kindRef.getVal() == 1) {
return new ForEachInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(), hn.index, hn.obj), w.commands);
}
if (kindRef.getVal() == 2) {
return new ForInAVM2Item(w.getSrc(), w.getLineStartItem(), w.loop, new InAVM2Item(hn.getInstruction(), hn.getLineStartIns(),hn.index , hn.obj), w.commands);
}
}
}
}
}

View File

@@ -38,6 +38,8 @@ public class NextNameAVM2Item extends AVM2Item {
public GraphTargetItem index;
public GraphTargetItem obj;
public GraphTargetItem localReg;
public NextNameAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem index, GraphTargetItem obj) {
super(instruction, lineStartIns, NOPRECEDENCE);
@@ -53,6 +55,10 @@ public class NextNameAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (localReg != null) {
localReg.appendTo(writer, localData);
return writer;
}
writer.append("§§nextname");
writer.spaceBeforeCallParenthesies(2);
writer.append("(");

View File

@@ -38,6 +38,8 @@ public class NextValueAVM2Item extends AVM2Item {
public GraphTargetItem index;
public GraphTargetItem obj;
public GraphTargetItem localReg;
public NextValueAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem index, GraphTargetItem obj) {
super(instruction, lineStartIns, NOPRECEDENCE);
@@ -58,6 +60,10 @@ public class NextValueAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (localReg != null) {
localReg.appendTo(writer, localData);
return writer;
}
writer.append("§§nextvalue");
writer.spaceBeforeCallParenthesies(2);
writer.append("(");