AS1/2 Improved direct editing

AS1/2 Improved decompilation of various global functions
This commit is contained in:
Jindra Pet��k
2013-07-15 23:07:36 +02:00
parent 61b3c13105
commit 49ef4c0961
175 changed files with 5356 additions and 2183 deletions
@@ -109,4 +109,9 @@ public abstract class TreeItem extends GraphTargetItem {
return "_loc" + reg + "_";
}
}
@Override
public boolean hasReturnValue() {
throw new UnsupportedOperationException(); //Not supported in AVM2 yet
}
}
@@ -92,4 +92,9 @@ public class ForEachInTreeItem extends LoopItem implements Block {
}
return ret;
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -92,4 +92,9 @@ public class ForInTreeItem extends LoopItem implements Block {
}
return ret;
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -298,9 +298,7 @@ public class Action implements GraphSourceItem {
* @return Array of bytes
*/
public byte[] getBytes(int version) {
byte ret[] = new byte[1];
ret[0] = (byte) actionCode;
return ret;
return surroundWithAction(new byte[0], version);
}
/**
@@ -315,7 +313,9 @@ public class Action implements GraphSourceItem {
SWFOutputStream sos2 = new SWFOutputStream(baos2, version);
try {
sos2.writeUI8(actionCode);
sos2.writeUI16(data.length);
if (actionCode >= 0x80) {
sos2.writeUI16(data.length);
}
sos2.write(data);
sos2.close();
} catch (IOException e) {
@@ -1075,7 +1075,7 @@ public class Action implements GraphSourceItem {
for (int i = 0; i < prevCount; i++) {
output2.add(output.get(i));
}
output2.add(new ClassTreeItem(className, extendsOp, implementsOp, functions, vars, staticFunctions, staticVars));
output2.add(new ClassTreeItem(className, extendsOp, implementsOp, null/*FIXME*/, functions, vars, staticFunctions, staticVars));
return output2;
}
@@ -1143,7 +1143,7 @@ public class Action implements GraphSourceItem {
for (int i = 0; i < prevCount; i++) {
output2.add(output.get(i));
}
output2.add(new ClassTreeItem(className, extendsOp, implementsOp, functions, vars, staticFunctions, staticVars));
output2.add(new ClassTreeItem(className, extendsOp, implementsOp, null/*FIXME*/, functions, vars, staticFunctions, staticVars));
return output2;
}
/*if (parts.get(pos) instanceof PopTreeItem) {
@@ -1209,7 +1209,7 @@ public class Action implements GraphSourceItem {
for (int i = 0; i < prevCount; i++) {
output2.add(output.get(i));
}
output2.add(new ClassTreeItem(className, extendsOp, implementsOp, functions, vars, staticFunctions, staticVars));
output2.add(new ClassTreeItem(className, extendsOp, implementsOp, null/*FIXME*/, functions, vars, staticFunctions, staticVars));
return output2;
}
} else {
@@ -1345,4 +1345,21 @@ public class Action implements GraphSourceItem {
public int getFixBranch() {
return fixedBranch;
}
public static GraphTargetItem gettoset(GraphTargetItem get, GraphTargetItem value) {
GraphTargetItem ret = get;
if (ret instanceof GetVariableTreeItem) {
GetVariableTreeItem gv = (GetVariableTreeItem) ret;
ret = new SetVariableTreeItem(null, gv.name, value);
} else if (ret instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) ret;
ret = new SetMemberTreeItem(null, mem.object, mem.memberName, value);
} else if ((ret instanceof DirectValueTreeItem) && ((DirectValueTreeItem) ret).value instanceof RegisterNumber) {
ret = new StoreRegisterTreeItem(null, (RegisterNumber) ((DirectValueTreeItem) ret).value, value, false);
} else if (ret instanceof GetPropertyTreeItem) {
GetPropertyTreeItem gp = (GetPropertyTreeItem) ret;
ret = new SetPropertyTreeItem(null, gp.target, gp.propertyIndex, value);
}
return ret;
}
}
@@ -27,9 +27,12 @@ import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals;
import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.EnumerateTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.FunctionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.SetTarget2TreeItem;
import com.jpexs.decompiler.flash.action.treemodel.SetTargetTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.SetTypeTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.StoreRegisterTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.clauses.ForInTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.clauses.TellTargetTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.operations.NeqTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.operations.StrictEqTreeItem;
import com.jpexs.decompiler.flash.ecma.Null;
@@ -95,8 +98,66 @@ public class ActionGraph extends Graph {
list.clear();
list.addAll(ret);
}
int targetStart;
int targetEnd;
boolean again;
do {
again = false;
targetStart = -1;
targetEnd = -1;
GraphTargetItem targetStartItem = null;
GraphTargetItem target = null;
for (int t = 0; t < list.size(); t++) {
GraphTargetItem it = list.get(t);
if (it instanceof SetTargetTreeItem) {
SetTargetTreeItem st = (SetTargetTreeItem) it;
if (st.target.equals("")) {
if (targetStart > -1) {
targetEnd = t;
break;
}
} else {
target = new DirectValueTreeItem(null, 0, st.target, new ArrayList<String>());
targetStart = t;
targetStartItem = it;
}
}
if (it instanceof SetTarget2TreeItem) {
SetTarget2TreeItem st = (SetTarget2TreeItem) it;
if ((st.target instanceof DirectValueTreeItem) && st.target.getResult().equals("")) {
if (targetStart > -1) {
targetEnd = t;
break;
}
} else {
targetStart = t;
target = st.target;
targetStartItem = it;
}
}
}
if ((targetStart > -1) && (targetEnd > -1)) {
List<GraphTargetItem> newlist = new ArrayList<>();
for (int i = 0; i < targetStart; i++) {
newlist.add(list.get(i));
}
List<GraphTargetItem> tellist = new ArrayList<>();
for (int i = targetStart + 1; i < targetEnd; i++) {
tellist.add(list.get(i));
}
newlist.add(new TellTargetTreeItem(targetStartItem.src, target, tellist));
for (int i = targetEnd + 1; i < list.size(); i++) {
newlist.add(list.get(i));
}
list.clear();
list.addAll(newlist);
again = true;
}
} while (again);
for (int t = 0; t < list.size(); t++) {
GraphTargetItem it = list.get(t);
if (it instanceof WhileItem) {
WhileItem wi = (WhileItem) it;
if ((!wi.commands.isEmpty()) && (wi.commands.get(0) instanceof SetTypeTreeItem)) {
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,766 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.parser.script;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.action.swf4.ActionJump;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionPop;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSetVariable;
import com.jpexs.decompiler.flash.action.swf4.ConstantIndex;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionCallFunction;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction;
import com.jpexs.decompiler.flash.action.swf5.ActionGetMember;
import com.jpexs.decompiler.flash.action.swf5.ActionNewObject;
import com.jpexs.decompiler.flash.action.swf5.ActionPushDuplicate;
import com.jpexs.decompiler.flash.action.swf5.ActionSetMember;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals;
import com.jpexs.decompiler.flash.action.swf7.ActionExtends;
import com.jpexs.decompiler.flash.action.swf7.ActionImplementsOp;
import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.FunctionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.GetMemberTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.GetVariableTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.operations.Inverted;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.graph.AndItem;
import com.jpexs.decompiler.flash.graph.BreakItem;
import com.jpexs.decompiler.flash.graph.CommaExpressionItem;
import com.jpexs.decompiler.flash.graph.ContinueItem;
import com.jpexs.decompiler.flash.graph.DoWhileItem;
import com.jpexs.decompiler.flash.graph.DuplicateItem;
import com.jpexs.decompiler.flash.graph.ForItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.IfItem;
import com.jpexs.decompiler.flash.graph.NotItem;
import com.jpexs.decompiler.flash.graph.OrItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.graph.SwitchItem;
import com.jpexs.decompiler.flash.graph.TernarOpItem;
import com.jpexs.decompiler.flash.graph.WhileItem;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ActionScriptSourceGenerator implements SourceGenerator {
@Override
public List<GraphSourceItem> generate(List<Object> localData, AndItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
ret.addAll(generateToActionList(localData, item.leftSide));
ret.add(new ActionPushDuplicate());
ret.add(new ActionNot());
List<Action> andExpr = generateToActionList(localData, item.rightSide);
andExpr.add(0, new ActionPop());
int andExprLen = Action.actionsToBytes(andExpr, false, SWF.DEFAULT_VERSION).length;
ret.add(new ActionIf(andExprLen));
ret.addAll(andExpr);
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, OrItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
ret.addAll(generateToActionList(localData, item.leftSide));
ret.add(new ActionPushDuplicate());
List<Action> orExpr = generateToActionList(localData, item.rightSide);
orExpr.add(0, new ActionPop());
int orExprLen = Action.actionsToBytes(orExpr, false, SWF.DEFAULT_VERSION).length;
ret.add(new ActionIf(orExprLen));
ret.addAll(orExpr);
return ret;
}
public List<Action> toActionList(List<GraphSourceItem> items) {
List<Action> ret = new ArrayList<>();
for (GraphSourceItem s : items) {
if (s instanceof Action) {
ret.add((Action) s);
}
}
return ret;
}
private List<Action> nonempty(List<Action> list) {
if (list == null) {
return new ArrayList<>();
}
return list;
}
private List<GraphSourceItem> generateIf(List<Object> localData, GraphTargetItem expression, List<GraphTargetItem> onTrueCmds, List<GraphTargetItem> onFalseCmds, boolean ternar) {
List<GraphSourceItem> ret = new ArrayList<>();
if (expression instanceof Inverted) {
ret.addAll(((Inverted) expression).invert().toSource(localData, this));
} else {
ret.addAll(expression.toSource(localData, this));
ret.add(new ActionNot());
}
List<Action> onTrue = null;
List<Action> onFalse = null;
if (ternar) {
onTrue = toActionList(onTrueCmds.get(0).toSource(localData, this));
} else {
onTrue = generateToActionList(localData, onTrueCmds);
}
if (onFalseCmds != null && !onFalseCmds.isEmpty()) {
if (ternar) {
onFalse = toActionList(onFalseCmds.get(0).toSource(localData, this));
} else {
onFalse = generateToActionList(localData, onFalseCmds);
}
}
byte onTrueBytes[] = Action.actionsToBytes(onTrue, false, SWF.DEFAULT_VERSION);
int onTrueLen = onTrueBytes.length;
ActionIf ifaif = new ActionIf(0);
ret.add(ifaif);
ret.addAll(onTrue);
ifaif.setJumpOffset(onTrueLen);
ActionJump ajmp = null;
if (onFalse != null) {
if (!((!nonempty(onTrue).isEmpty())
&& (onTrue.get(onTrue.size() - 1) instanceof ActionJump)
&& ((((ActionJump) onTrue.get(onTrue.size() - 1)).isContinue)
|| (((ActionJump) onTrue.get(onTrue.size() - 1)).isBreak)))) {
ajmp = new ActionJump(0);
ret.add(ajmp);
onTrueLen += ajmp.getBytes(SWF.DEFAULT_VERSION).length;
}
ifaif.setJumpOffset(onTrueLen);
byte onFalseBytes[] = Action.actionsToBytes(onFalse, false, SWF.DEFAULT_VERSION);
int onFalseLen = onFalseBytes.length;
if (ajmp != null) {
ajmp.setJumpOffset(onFalseLen);
}
ret.addAll(onFalse);
}
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, IfItem item) {
return generateIf(localData, item.expression, item.onTrue, item.onFalse, false);
}
private void fixLoop(List<Action> code, int breakOffset) {
fixLoop(code, breakOffset, Integer.MAX_VALUE);
}
private void fixLoop(List<Action> code, int breakOffset, int continueOffset) {
int pos = 0;
for (Action a : code) {
pos += a.getBytes(SWF.DEFAULT_VERSION).length;
if (a instanceof ActionJump) {
ActionJump aj = (ActionJump) a;
if (aj.isContinue && (continueOffset != Integer.MAX_VALUE)) {
aj.setJumpOffset(-pos + continueOffset);
aj.isContinue = false;
}
if (aj.isBreak) {
aj.setJumpOffset(-pos + breakOffset);
aj.isBreak = false;
}
}
}
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, TernarOpItem item) {
List<GraphTargetItem> onTrue = new ArrayList<>();
onTrue.add(item.onTrue);
List<GraphTargetItem> onFalse = new ArrayList<>();
onFalse.add(item.onFalse);
return generateIf(localData, item.expression, onTrue, onFalse, true);
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, WhileItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
List<Action> whileExpr = new ArrayList<>();
List<GraphTargetItem> ex = new ArrayList<>(item.expression);
if (!ex.isEmpty()) {
GraphTargetItem lastItem = ex.remove(ex.size() - 1);
whileExpr.addAll(generateToActionList(localData, ex));
whileExpr.addAll(toActionList(lastItem.toSource(localData, this))); //Want result
}
List<Action> whileBody = generateToActionList(localData, item.commands);
whileExpr.add(new ActionNot());
ActionIf whileaif = new ActionIf(0);
whileExpr.add(whileaif);
ActionJump whileajmp = new ActionJump(0);
whileBody.add(whileajmp);
int whileExprLen = Action.actionsToBytes(whileExpr, false, SWF.DEFAULT_VERSION).length;
int whileBodyLen = Action.actionsToBytes(whileBody, false, SWF.DEFAULT_VERSION).length;
whileajmp.setJumpOffset(-(whileExprLen
+ whileBodyLen));
whileaif.setJumpOffset(whileBodyLen);
ret.addAll(whileExpr);
fixLoop(whileBody, whileBodyLen, -whileExprLen);
ret.addAll(whileBody);
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, DoWhileItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
List<Action> doExpr = generateToActionList(localData, item.expression);
List<Action> doBody = generateToActionList(localData, item.commands);
int doBodyLen = Action.actionsToBytes(doBody, false, SWF.DEFAULT_VERSION).length;
int doExprLen = Action.actionsToBytes(doExpr, false, SWF.DEFAULT_VERSION).length;
ret.addAll(doBody);
ret.addAll(doExpr);
ActionIf doif = new ActionIf(0);
ret.add(doif);
doif.setJumpOffset(-doBodyLen - doExprLen - doif.getBytes(SWF.DEFAULT_VERSION).length);
fixLoop(doBody, doBodyLen + doExprLen + doif.getBytes(SWF.DEFAULT_VERSION).length, doBodyLen);
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, ForItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
List<Action> forExpr = generateToActionList(localData, item.expression);
List<Action> forBody = generateToActionList(localData, item.commands);
List<Action> forFinalCommands = generateToActionList(localData, item.finalCommands);
forExpr.add(new ActionNot());
ActionIf foraif = new ActionIf(0);
forExpr.add(foraif);
ActionJump forajmp = new ActionJump(0);
int forajmpLen = forajmp.getBytes(SWF.DEFAULT_VERSION).length;
int forExprLen = Action.actionsToBytes(forExpr, false, SWF.DEFAULT_VERSION).length;
int forBodyLen = Action.actionsToBytes(forBody, false, SWF.DEFAULT_VERSION).length;
int forFinalLen = Action.actionsToBytes(forFinalCommands, false, SWF.DEFAULT_VERSION).length;
forajmp.setJumpOffset(-(forExprLen
+ forBodyLen + forFinalLen + forajmpLen));
foraif.setJumpOffset(forBodyLen + forFinalLen + forajmpLen);
ret.addAll(forExpr);
ret.addAll(forBody);
ret.addAll(forFinalCommands);
ret.add(forajmp);
fixLoop(forBody, forBodyLen + forFinalLen + forajmpLen, forBodyLen);
return ret;
}
private long uniqLast = 0;
public String uniqId() {
uniqLast++;
return "" + uniqLast;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, SwitchItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
HashMap<String, Integer> registerVars = getRegisterVars(localData);
int exprReg = 0;
for (int i = 0; i < 256; i++) {
if (!registerVars.containsValue(i)) {
registerVars.put("__switch" + uniqId(), i);
exprReg = i;
break;
}
}
ret.addAll(toActionList(item.switchedObject.toSource(localData, this)));
boolean firstCase = true;
List<List<ActionIf>> caseIfs = new ArrayList<>();
List<List<Action>> caseCmds = new ArrayList<>();
List<List<List<Action>>> caseExprsAll = new ArrayList<>();
loopm:
for (int m = 0; m < item.caseValues.size(); m++) {
List<List<Action>> caseExprs = new ArrayList<>();
List<ActionIf> caseIfsOne = new ArrayList<>();
int mapping = item.valuesMapping.get(m);
for (; m < item.caseValues.size(); m++) {
int newmapping = item.valuesMapping.get(m);
if (newmapping != mapping) {
m--;
break;
}
List<Action> curCaseExpr = generateToActionList(localData, item.caseValues.get(m));
caseExprs.add(curCaseExpr);
if (firstCase) {
curCaseExpr.add(0, new ActionStoreRegister(exprReg));
} else {
curCaseExpr.add(0, new ActionPush(new RegisterNumber(exprReg)));
}
curCaseExpr.add(new ActionStrictEquals());
ActionIf aif = new ActionIf(0);
caseIfsOne.add(aif);
curCaseExpr.add(aif);
ret.addAll(curCaseExpr);
firstCase = false;
}
caseExprsAll.add(caseExprs);
caseIfs.add(caseIfsOne);
List<Action> caseCmd = generateToActionList(localData, item.caseCommands.get(mapping));
caseCmds.add(caseCmd);
}
ActionJump defJump = new ActionJump(0);
ret.add(defJump);
List<Action> defCmd = new ArrayList<>();
if (!item.defaultCommands.isEmpty()) {
defCmd = generateToActionList(localData, item.defaultCommands);
}
for (List<Action> caseCmd : caseCmds) {
ret.addAll(caseCmd);
}
ret.addAll(defCmd);
List<List<Integer>> exprLengths = new ArrayList<>();
for (List<List<Action>> caseExprs : caseExprsAll) {
List<Integer> lengths = new ArrayList<>();
for (List<Action> caseExpr : caseExprs) {
lengths.add(Action.actionsToBytes(caseExpr, false, SWF.DEFAULT_VERSION).length);
}
exprLengths.add(lengths);
}
List<Integer> caseLengths = new ArrayList<>();
for (List<Action> caseCmd : caseCmds) {
caseLengths.add(Action.actionsToBytes(caseCmd, false, SWF.DEFAULT_VERSION).length);
}
int defLength = Action.actionsToBytes(defCmd, false, SWF.DEFAULT_VERSION).length;
for (int i = 0; i < caseIfs.size(); i++) {
for (int c = 0; c < caseIfs.get(i).size(); c++) {
int jmpPos = 0;
for (int j = c + 1; j < caseIfs.get(i).size(); j++) {
jmpPos += exprLengths.get(i).get(j);
}
for (int k = i + 1; k < caseIfs.size(); k++) {
for (int m = 0; m < caseIfs.get(k).size(); m++) {
jmpPos += exprLengths.get(k).get(m);
}
}
jmpPos += defJump.getBytes(SWF.DEFAULT_VERSION).length;
for (int n = 0; n < i; n++) {
jmpPos += caseLengths.get(n);
}
caseIfs.get(i).get(c).setJumpOffset(jmpPos);
}
}
int defJmpPos = 0;
for (int i = 0; i < caseIfs.size(); i++) {
defJmpPos += caseLengths.get(i);
}
defJump.setJumpOffset(defJmpPos);
List<Action> caseCmdsAll = new ArrayList<>();
int breakOffset = 0;
for (int i = 0; i < caseCmds.size(); i++) {
caseCmdsAll.addAll(caseCmds.get(i));
breakOffset += caseLengths.get(i);
}
breakOffset += defLength;
fixLoop(caseCmdsAll, breakOffset);
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, NotItem item) {
if (item.getOriginal() instanceof Inverted) {
GraphTargetItem norig = ((Inverted) item).invert();
return norig.toSource(localData, this);
}
List<GraphSourceItem> ret = new ArrayList<>();
ret.addAll(item.getOriginal().toSource(localData, this));
ret.add(new ActionNot());
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, DuplicateItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
ret.add(new ActionPushDuplicate());
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, BreakItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
ActionJump abreak = new ActionJump(0);
abreak.isBreak = true;
ret.add(abreak);
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, ContinueItem item) {
List<GraphSourceItem> ret = new ArrayList<>();
ActionJump acontinue = new ActionJump(0);
acontinue.isContinue = true;
ret.add(acontinue);
return ret;
}
private List<Action> generateToActionList(List<Object> localData, List<GraphTargetItem> commands) {
return toActionList(generate(localData, commands));
}
private List<Action> generateToActionList(List<Object> localData, GraphTargetItem command) {
return toActionList(command.toSource(localData, this));
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, List<GraphTargetItem> commands) {
List<GraphSourceItem> ret = new ArrayList<>();
for (GraphTargetItem item : commands) {
ret.addAll(item.toSourceIgnoreReturnValue(localData, this));
}
return ret;
}
@SuppressWarnings("unchecked")
public HashMap<String, Integer> getRegisterVars(List<Object> localData) {
return (HashMap<String, Integer>) localData.get(0);
}
public void setRegisterVars(List<Object> localData, HashMap<String, Integer> value) {
localData.set(0, value);
}
public void setInFunction(List<Object> localData, boolean value) {
localData.set(1, value);
}
public boolean isInFunction(List<Object> localData) {
return (Boolean) localData.get(1);
}
public boolean isInMethod(List<Object> localData) {
return (Boolean) localData.get(2);
}
public void setInMethod(List<Object> localData, boolean value) {
localData.set(2, value);
}
public int getForInLevel(List<Object> localData) {
return (Integer) localData.get(3);
}
public void setForInLevel(List<Object> localData, int value) {
localData.set(3, value);
}
public int getTempRegister(List<Object> localData) {
HashMap<String, Integer> registerVars = getRegisterVars(localData);
int tmpReg = 0;
for (int i = 0; i < 256; i++) {
if (!registerVars.containsValue(i)) {
tmpReg = i;
break;
}
}
return tmpReg;
}
private String getName(GraphTargetItem item) {
if (item instanceof DirectValueTreeItem) {
DirectValueTreeItem dv = (DirectValueTreeItem) item;
return (String) dv.getResult();
}
if (item instanceof GetVariableTreeItem) {
GetVariableTreeItem gv = (GetVariableTreeItem) item;
return getName(gv.name);
}
if (item instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) item;
return getName(mem.memberName);
}
return null;
}
private List<String> getVarParts(GraphTargetItem item) {
List<String> ret = new ArrayList<>();
do {
if (item instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) item;
ret.add(0, getName(mem));
item = mem.object;
}
} while (item instanceof GetMemberTreeItem);
String f = getName(item);
if (f != null) {
ret.add(0, f);
}
return ret;
}
private int getVarLength(GraphTargetItem item) {
int len = 1;
do {
if (item instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) item;
item = mem.object;
len++;
}
} while (item instanceof GetMemberTreeItem);
return len;
}
private GraphTargetItem removeVarLast(GraphTargetItem item, int cnt) {
item = (GraphTargetItem) Helper.deepCopy(item);
for (int i = 0; i < cnt; i++) {
if (item instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) item;
item = mem.object;
}
}
return item;
}
private GraphTargetItem addGlobalPrefix(GraphTargetItem item) {
item = (GraphTargetItem) Helper.deepCopy(item);
GraphTargetItem first = item;
GetMemberTreeItem mem = null;
do {
if (item instanceof GetMemberTreeItem) {
mem = (GetMemberTreeItem) item;
item = mem.object;
}
} while (item instanceof GetMemberTreeItem);
if (item instanceof GetVariableTreeItem) {
GetVariableTreeItem v = (GetVariableTreeItem) item;
item = new GetMemberTreeItem(null, new GetVariableTreeItem(null, new DirectValueTreeItem(null, 0, "_global", new ArrayList<String>())), v.name);
if (mem != null) {
mem.object = item;
}
}
return first;
}
private List<Action> typeToActions(List<String> type, List<Action> value) {
List<Action> ret = new ArrayList<>();
if (type.isEmpty()) {
return ret;
}
ret.add(pushConst(type.get(0)));
if (type.size() == 1 && (value != null)) {
ret.addAll(value);
ret.add(new ActionSetVariable());
} else {
ret.add(new ActionGetVariable());
}
for (int i = 1; i < type.size(); i++) {
ret.add(pushConst(type.get(i)));
if ((i == type.size() - 1) && (value != null)) {
ret.addAll(value);
ret.add(new ActionSetMember());
} else {
ret.add(new ActionGetMember());
}
}
return ret;
}
private List<String> constantPool;
public ActionScriptSourceGenerator(List<String> constantPool) {
this.constantPool = constantPool;
}
public List<String> getConstantPool() {
return constantPool;
}
public DirectValueTreeItem pushConstTargetItem(String s) {
int index = constantPool.indexOf(s);
if (index == -1) {
constantPool.add(s);
index = constantPool.indexOf(s);
}
return new DirectValueTreeItem(null, 0, new ConstantIndex(index), constantPool);
}
public ActionPush pushConst(String s) {
int index = constantPool.indexOf(s);
if (index == -1) {
constantPool.add(s);
index = constantPool.indexOf(s);
}
return new ActionPush(new ConstantIndex(index));
}
public List<GraphSourceItem> generateTraits(List<Object> localData, boolean isInterface, GraphTargetItem name, GraphTargetItem extendsVal, List<GraphTargetItem> implementsStr, GraphTargetItem constructor, List<GraphTargetItem> functions, List<MyEntry<GraphTargetItem, GraphTargetItem>> vars, List<GraphTargetItem> staticFunctions, List<MyEntry<GraphTargetItem, GraphTargetItem>> staticVars) {
List<String> extendsStr = getVarParts(extendsVal);
List<GraphSourceItem> ret = new ArrayList<>();
List<String> nameStr = getVarParts(name);
for (int i = 0; i < nameStr.size() - 1; i++) {
List<Action> notBody = new ArrayList<>();
List<String> globalClassTypeStr = new ArrayList<>();
globalClassTypeStr.add("_global");
for (int j = 0; j <= i; j++) {
globalClassTypeStr.add(nameStr.get(j));
}
List<Action> val = new ArrayList<>();
val.add(new ActionPush((Long) 0L));
val.add(pushConst("Object"));
val.add(new ActionNewObject());
notBody.addAll(typeToActions(globalClassTypeStr, val));
ret.addAll(typeToActions(globalClassTypeStr, null));
ret.add(new ActionNot());
ret.add(new ActionNot());
ret.add(new ActionIf(Action.actionsToBytes(notBody, false, SWF.DEFAULT_VERSION).length));
ret.addAll(notBody);
}
List<Action> ifbody = new ArrayList<>();
List<String> globalClassTypeStr = new ArrayList<>();
globalClassTypeStr.add("_global");
globalClassTypeStr.addAll(nameStr);
ParsedSymbol s = null;
List<Action> constr = new ArrayList<>();
if (constructor == null) {
List<Action> val = new ArrayList<>();
val.add(new ActionDefineFunction("", new ArrayList<String>(), 0, SWF.DEFAULT_VERSION));
if (!isInterface) {
val.add(new ActionStoreRegister(1));
}
constr.addAll(typeToActions(globalClassTypeStr, val));
} else {
constr.addAll(toActionList(((FunctionTreeItem) constructor).toSource(localData, this)));
constr.add(new ActionStoreRegister(1));
constr = (typeToActions(globalClassTypeStr, constr));
}
if (!isInterface) {
for (GraphTargetItem f : staticFunctions) {
FunctionTreeItem fi = (FunctionTreeItem) f;
ifbody.add(new ActionPush(new RegisterNumber(1/*static*/)));
ifbody.add(new ActionPush(getName(fi.calculatedFunctionName)));
ifbody.addAll(toActionList(fi.toSource(localData, this)));
ifbody.add(new ActionSetMember());
}
for (GraphTargetItem f : functions) {
FunctionTreeItem fi = (FunctionTreeItem) f;
ifbody.add(new ActionPush(new RegisterNumber(2/*instance*/)));
ifbody.add(new ActionPush(getName(fi.calculatedFunctionName)));
ifbody.addAll(toActionList(fi.toSource(localData, this)));
ifbody.add(new ActionSetMember());
}
for (MyEntry<GraphTargetItem, GraphTargetItem> en : staticVars) {
ifbody.add(new ActionPush(new RegisterNumber(1/*static*/)));
ifbody.add(new ActionPush(getName(en.key)));
ifbody.addAll(toActionList(en.value.toSource(localData, this)));
ifbody.add(new ActionSetMember());
}
for (MyEntry<GraphTargetItem, GraphTargetItem> en : vars) {
ifbody.add(new ActionPush(new RegisterNumber(2/*instance*/)));
ifbody.add(new ActionPush(getName(en.key)));
ifbody.addAll(toActionList(en.value.toSource(localData, this)));
ifbody.add(new ActionSetMember());
}
}
if (!isInterface) {
ifbody.add(new ActionPush((Long) 1L));
ifbody.add(new ActionPush(new Null()));
ifbody.addAll(typeToActions(globalClassTypeStr, null));
ifbody.add(pushConst("prototype"));
ifbody.add(new ActionGetMember());
ifbody.add(new ActionPush((Long) 3L));
ifbody.add(pushConst("ASSetPropFlags"));
ifbody.add(new ActionCallFunction());
}
if (constr.isEmpty()) {
List<Action> val = new ArrayList<>();
val.add(new ActionDefineFunction("", new ArrayList<String>(), 0, SWF.DEFAULT_VERSION));
if (!isInterface) {
val.add(new ActionStoreRegister(1));
}
constr.addAll(typeToActions(globalClassTypeStr, val));
}
if (!extendsStr.isEmpty()) {
constr.addAll(typeToActions(globalClassTypeStr, null));
constr.addAll(typeToActions(extendsStr, null));
constr.add(new ActionExtends());
}
if (!isInterface) {
constr.add(new ActionPush(new RegisterNumber(1)));
constr.add(pushConst("prototype"));
constr.add(new ActionGetMember());
constr.add(new ActionStoreRegister(2));
constr.add(new ActionPop());
}
if (!implementsStr.isEmpty()) {
for (GraphTargetItem imp : implementsStr) {
List<String> impList = getVarParts(imp);
List<String> globImp = new ArrayList<>();
globImp.add("_global");
globImp.addAll(impList);
constr.addAll(typeToActions(globImp, null));
}
constr.add(new ActionPush(new Long(implementsStr.size())));
constr.addAll(typeToActions(globalClassTypeStr, null));
constr.add(new ActionImplementsOp());
}
ifbody.addAll(0, constr);
ret.addAll(typeToActions(globalClassTypeStr, null));
ret.add(new ActionNot());
ret.add(new ActionNot());
ret.add(new ActionIf(Action.actionsToBytes(ifbody, false, SWF.DEFAULT_VERSION).length));
ret.addAll(ifbody);
ret.add(new ActionPop());
return ret;
}
@Override
public List<GraphSourceItem> generate(List<Object> localData, CommaExpressionItem item) {
if (item.commands.isEmpty()) {
return new ArrayList<>();
}
//We need to handle commands and last expression separately, otherwise last expression result will be popped
List<GraphTargetItem> cmds = new ArrayList<>(item.commands);
GraphTargetItem lastExpr = cmds.remove(cmds.size() - 1);
List<GraphSourceItem> ret = new ArrayList<>();
ret.addAll(generate(localData, cmds));
ret.addAll(lastExpr.toSource(localData, this));
return ret;
}
}
@@ -0,0 +1,48 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.parser.script;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class LexBufferer implements LexListener {
private List<ParsedSymbol> items = new ArrayList<>();
@Override
public void onLex(ParsedSymbol s) {
items.add(s);
}
@Override
public void onPushBack(ParsedSymbol s) {
if (items.get(items.size() - 1) == s) {
items.remove(items.size() - 1);
}
}
public void pushAllBack(ActionScriptLexer lexer) {
for (int i = items.size() - 1; i >= 0; i--) {
lexer.pushback(items.get(i));
}
items.clear();
}
}
@@ -0,0 +1,28 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.parser.script;
/**
*
* @author JPEXS
*/
public interface LexListener {
public void onLex(ParsedSymbol s);
public void onPushBack(ParsedSymbol s);
}
@@ -171,5 +171,14 @@ public enum SymbolType {
UNDEFINED,
NEWLINE,
NAN,
GETVERSION
GETVERSION,
CALL,
LOADMOVIENUM,
LOADVARIABLESNUM,
PRINT,
PRINTNUM,
PRINTASBITMAP,
PRINTASBITMAPNUM,
UNLOADMOVIE,
UNLOADMOVIENUM
}
@@ -17,6 +17,8 @@
package com.jpexs.decompiler.flash.action.parser.script;
import com.jpexs.decompiler.flash.action.parser.ParseException;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
%%
@@ -43,17 +45,43 @@ import java.util.Stack;
public int yyline() {
return yyline+1;
}
private List<LexListener> listeners=new ArrayList<>();
public void addListener(LexListener listener){
listeners.add(listener);
}
public void removeListener(LexListener listener){
listeners.remove(listener);
}
public void informListenersLex(ParsedSymbol s){
for(LexListener l:listeners){
l.onLex(s);
}
}
public void informListenersPushBack(ParsedSymbol s){
for(LexListener l:listeners){
l.onPushBack(s);
}
}
public void pushback(ParsedSymbol symb) {
pushedBack.push(symb);
last = null;
informListenersPushBack(symb);
}
ParsedSymbol last;
public ParsedSymbol lex() throws java.io.IOException, ParseException{
ParsedSymbol ret=null;
if(!pushedBack.isEmpty()){
return last=pushedBack.pop();
ret = last = pushedBack.pop();
}else{
ret = last = yylex();
}
return last=yylex();
informListenersLex(ret);
return ret;
}
%}
@@ -195,6 +223,15 @@ SingleCharacter = [^\r\n\'\\]
"Infinity" { return new ParsedSymbol(SymbolGroup.GLOBALCONST,SymbolType.INFINITY,yytext()); }
"NaN" { return new ParsedSymbol(SymbolGroup.GLOBALCONST,SymbolType.NAN,yytext()); }
"getVersion" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.GETVERSION,yytext()); }
"call" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.CALL,yytext()); }
"loadMovieNum" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.LOADMOVIENUM,yytext()); }
"loadVariablesNum" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.LOADVARIABLESNUM,yytext()); }
"printAsBitmapNum" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.PRINTASBITMAPNUM,yytext()); }
"printNum" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.PRINTNUM,yytext()); }
"printAsBitmap" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.PRINTASBITMAP,yytext()); }
"print" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.PRINT,yytext()); }
"unloadMovie" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.UNLOADMOVIE,yytext()); }
"unloadMovieNum" { return new ParsedSymbol(SymbolGroup.GLOBALFUNC,SymbolType.UNLOADMOVIENUM,yytext()); }
/* operators */
@@ -41,6 +41,12 @@ public class ActionGetURL extends Action {
public String urlString;
public String targetString;
public ActionGetURL(String urlString, String targetString) {
super(0x83, 0);
this.urlString = urlString;
this.targetString = targetString;
}
public ActionGetURL(int actionLength, SWFInputStream sis, int version) throws IOException {
super(0x83, actionLength);
//byte data[] = sis.readBytes(actionLength);
@@ -86,10 +92,10 @@ public class ActionGetURL extends Action {
try {
int num = Integer.valueOf(targetString.substring(levelPrefix.length()));
if (urlString.equals("")) {
output.add(new UnLoadMovieNumTreeItem(this, num));
output.add(new UnLoadMovieNumTreeItem(this, new DirectValueTreeItem((Long) (long) (int) num)));
} else {
DirectValueTreeItem urlStringDi = new DirectValueTreeItem(null, 0, urlString, new ArrayList<String>());
output.add(new LoadMovieNumTreeItem(this, urlStringDi, num, 1/*GET*/));
output.add(new LoadMovieNumTreeItem(this, urlStringDi, new DirectValueTreeItem((Long) (long) (int) num), 1/*GET*/));
}
return;
} catch (NumberFormatException nfe) {
@@ -67,6 +67,6 @@ public class ActionGotoFrame extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new GotoFrameTreeItem(this, frame + 1));
output.add(new GotoFrameTreeItem(this, frame));
}
}
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.NextFrameTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionNextFrame extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "nextFrame()"));
output.add(new NextFrameTreeItem(this));
}
}
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.PlayTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionPlay extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "Play()"));
output.add(new PlayTreeItem(this));
}
}
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.PrevFrameTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionPrevFrame extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "prevFrame()"));
output.add(new PrevFrameTreeItem(this));
}
}
@@ -34,6 +34,11 @@ public class ActionSetTarget extends Action {
public String targetName;
public ActionSetTarget(String targetName) {
super(0x8B, 0);
this.targetName = targetName;
}
public ActionSetTarget(int actionLength, SWFInputStream sis, int version) throws IOException {
super(0x8B, actionLength);
//byte data[] = sis.readBytes(actionLength);
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.StopTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionStop extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "stop()"));
output.add(new StopTreeItem(this));
}
}
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.StopAllSoundsTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionStopSounds extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "stopAllSounds()"));
output.add(new StopAllSoundsTreeItem(this));
}
}
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.ToggleHighQualityTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionToggleQuality extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "toggleHighQuality()"));
output.add(new ToggleHighQualityTreeItem(this));
}
}
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf4;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.SimpleActionTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.StopDragTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -36,6 +36,6 @@ public class ActionEndDrag extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
output.add(new SimpleActionTreeItem(this, "stopDrag()"));
output.add(new StopDragTreeItem(this));
}
}
@@ -36,6 +36,7 @@ import com.jpexs.decompiler.flash.action.treemodel.UnLoadMovieTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
@@ -95,9 +96,8 @@ public class ActionGetURL2 extends Action {
GraphTargetItem targetString = stack.pop();
GraphTargetItem urlString = stack.pop();
Integer num = null;
if (targetString instanceof DirectValueTreeItem) {
DirectValueTreeItem di = (DirectValueTreeItem) targetString;
Object res = di.getResult();
if (targetString.isCompileTime()) {
Object res = targetString.getResult();
if (res instanceof String) {
String tarStr = (String) res;
String levelPrefix = "_level";
@@ -111,7 +111,7 @@ public class ActionGetURL2 extends Action {
}
if (loadVariablesFlag) {
if (num != null) {
output.add(new LoadVariablesNumTreeItem(this, urlString, num, sendVarsMethod));
output.add(new LoadVariablesNumTreeItem(this, urlString, new DirectValueTreeItem(null, 0, (Long) (long) (int) num, new ArrayList<String>()), sendVarsMethod));
} else {
output.add(new LoadVariablesTreeItem(this, urlString, targetString, sendVarsMethod));
}
@@ -125,24 +125,26 @@ public class ActionGetURL2 extends Action {
String printPrefix = "print:#";
String printAsBitmapPrefix = "printasbitmap:#";
String urlStr = null;
if ((urlString instanceof DirectValueTreeItem) && (urlString.getResult() instanceof String)) {
if (urlString.isCompileTime() && (urlString.getResult() instanceof String)) {
urlStr = (String) urlString.getResult();
}
if (num != null) {
if ("".equals(urlStr)) {
output.add(new UnLoadMovieNumTreeItem(this, num));
output.add(new UnLoadMovieNumTreeItem(this, new DirectValueTreeItem(null, 0, (Long) (long) (int) num, new ArrayList<String>())));
} else if (urlStr != null && urlStr.startsWith(printPrefix)) {
output.add(new PrintNumTreeItem(this, num, urlStr.substring(printPrefix.length())));
output.add(new PrintNumTreeItem(this, new DirectValueTreeItem((Long) (long) (int) num),
new DirectValueTreeItem(urlStr.substring(printPrefix.length()))));
} else if (urlStr != null && urlStr.startsWith(printAsBitmapPrefix)) {
output.add(new PrintAsBitmapNumTreeItem(this, num, urlStr.substring(printAsBitmapPrefix.length())));
output.add(new PrintAsBitmapNumTreeItem(this, new DirectValueTreeItem((Long) (long) (int) num), new DirectValueTreeItem(urlStr.substring(printAsBitmapPrefix.length()))));
} else {
output.add(new LoadMovieNumTreeItem(this, urlString, num, sendVarsMethod));
output.add(new LoadMovieNumTreeItem(this, urlString, new DirectValueTreeItem(null, 0, (Long) (long) (int) num, new ArrayList<String>()), sendVarsMethod));
}
} else {
if (urlStr != null && urlStr.startsWith(printPrefix)) {
output.add(new PrintTreeItem(this, targetString, urlStr.substring(printPrefix.length())));
output.add(new PrintTreeItem(this, targetString, new DirectValueTreeItem(urlStr.substring(printPrefix.length()))));
} else if (urlStr != null && urlStr.startsWith(printAsBitmapPrefix)) {
output.add(new PrintAsBitmapTreeItem(this, targetString, urlStr.substring(printAsBitmapPrefix.length())));
output.add(new PrintAsBitmapTreeItem(this, targetString, new DirectValueTreeItem(urlStr.substring(printAsBitmapPrefix.length()))));
} else {
output.add(new GetURL2TreeItem(this, urlString, targetString, sendVarsMethod));
}
@@ -37,6 +37,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ActionPush extends Action {
@@ -169,11 +171,12 @@ public class ActionPush extends Action {
}
sos.close();
} catch (IOException e) {
Logger.getLogger(ActionPush.class.getName()).log(Level.SEVERE, "Error during push to bytes", e);
}
return surroundWithAction(baos.toByteArray(), version);
}
public ActionPush(Object... values) throws IOException, ParseException {
public ActionPush(Object... values) {
super(0x96, 0);
this.values = new ArrayList<>();
for (Object o : values) {
@@ -17,7 +17,7 @@
package com.jpexs.decompiler.flash.action.swf4;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.operations.StringLengthTreeItem;
import com.jpexs.decompiler.flash.action.treemodel.StringLengthTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.HashMap;
import java.util.List;
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionAsciiToChar;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class AsciiToCharTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class AsciiToCharTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionAsciiToChar());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionCallFunction;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class CallFunctionTreeItem extends TreeItem {
@@ -95,4 +97,14 @@ public class CallFunctionTreeItem extends TreeItem {
}
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, toSourceCall(localData, generator, arguments), functionName, new ActionCallFunction());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionCallMethod;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class CallMethodTreeItem extends TreeItem {
@@ -74,4 +76,14 @@ public class CallMethodTreeItem extends TreeItem {
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, toSourceCall(localData, generator, arguments), scriptObject, methodName, new ActionCallMethod());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionCall;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class CallTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class CallTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionCall());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf7.ActionCastOp;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
@@ -44,4 +46,14 @@ public class CastOpTreeItem extends TreeItem {
ret.addAll(object.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, constructor, object, new ActionCastOp());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionCharToAscii;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class CharToAsciiTreeItem extends TreeItem {
@@ -65,4 +67,14 @@ public class CharToAsciiTreeItem extends TreeItem {
}
return 0;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionCharToAscii());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionCloneSprite;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class CloneSpriteTreeItem extends TreeItem {
@@ -46,4 +48,14 @@ public class CloneSpriteTreeItem extends TreeItem {
ret.addAll(depth.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, source, target, depth, new ActionCloneSprite());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionDecrement;
import com.jpexs.decompiler.flash.ecma.*;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class DecrementTreeItem extends TreeItem {
@@ -51,4 +53,14 @@ public class DecrementTreeItem extends TreeItem {
ret.addAll(object.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, new ActionDecrement());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineLocal;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineLocal2;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class DefineLocalTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -72,4 +75,19 @@ public class DefineLocalTreeItem extends TreeItem implements SetTypeTreeItem {
public GraphTargetItem getObject() {
return new DefineLocalTreeItem(src, name, null);
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
if (value == null) {
return toSourceMerge(localData, generator, name, new ActionDefineLocal2());
} else {
return toSourceMerge(localData, generator, name, value, new ActionDefineLocal());
}
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -0,0 +1,43 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel;
/**
*
* @author JPEXS
*/
public class DefineRegisterTreeItem extends TreeItem {
private String identifier;
private int register;
public DefineRegisterTreeItem(String identifier, int register) {
super(null, PRECEDENCE_PRIMARY);
this.identifier = identifier;
this.register = register;
}
@Override
public String toString(ConstantPool constants) {
return "var " + identifier;
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionDelete;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class DeleteTreeItem extends TreeItem {
@@ -46,4 +48,14 @@ public class DeleteTreeItem extends TreeItem {
ret.addAll(propertyName.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, propertyName, new ActionDelete());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,13 +16,16 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ConstantIndex;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -32,6 +35,10 @@ public class DirectValueTreeItem extends TreeItem {
public List<String> constants;
public GraphTargetItem computedRegValue;
public DirectValueTreeItem(Object o) {
this(null, 0, o, new ArrayList<String>());
}
public DirectValueTreeItem(GraphSourceItem instruction, int instructionPos, Object value, List<String> constants) {
super(instruction, PRECEDENCE_PRIMARY);
this.constants = constants;
@@ -141,8 +148,7 @@ public class DirectValueTreeItem extends TreeItem {
@Override
public boolean isCompileTime() {
return (value instanceof Double) || (value instanceof Float) || (value instanceof Boolean) || (value instanceof Long) || (value instanceof Null) || (computedRegValue != null && computedRegValue.isCompileTime()) //||(value instanceof String) || (value instanceof ConstantIndex)
;
return (value instanceof Double) || (value instanceof Float) || (value instanceof Boolean) || (value instanceof Long) || (value instanceof Null) || (computedRegValue != null && computedRegValue.isCompileTime()) || (value instanceof String) || (value instanceof ConstantIndex);
}
@Override
@@ -192,4 +198,14 @@ public class DirectValueTreeItem extends TreeItem {
}
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionPush(value));
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -1,45 +0,0 @@
/*
* Copyright (C) 2010-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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import java.util.List;
public class EachTreeItem extends TreeItem {
public TreeItem object;
public TreeItem collection;
public EachTreeItem(GraphSourceItem instruction, TreeItem object, TreeItem collection) {
super(instruction, NOPRECEDENCE);
this.object = object;
this.collection = collection;
}
@Override
public String toString(ConstantPool constants) {
return hilight("each (") + object.toString(constants) + hilight(" in ") + collection.toString(constants) + ")";
}
@Override
public List<com.jpexs.decompiler.flash.graph.GraphSourceItemPos> getNeededSources() {
List<com.jpexs.decompiler.flash.graph.GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(object.getNeededSources());
ret.addAll(collection.getNeededSources());
return ret;
}
}
@@ -41,4 +41,9 @@ public class EnumerateTreeItem extends TreeItem {
ret.addAll(object.getNeededSources());
return ret;
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -34,4 +37,14 @@ public class EvalTreeItem extends TreeItem {
public String toString(ConstantPool constants) {
return hilight("eval(") + value.toString(constants) + hilight(")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionGetVariable());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -47,4 +47,9 @@ public class ExtendsTreeItem extends TreeItem {
ret.addAll(superclass.getNeededSources());
return ret;
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,12 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.flashlite.ActionFSCommand2;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.ArrayList;
import java.util.List;
public class FSCommand2TreeItem extends TreeItem {
@@ -51,4 +55,21 @@ public class FSCommand2TreeItem extends TreeItem {
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
List<GraphSourceItem> ret = new ArrayList<>();
for (GraphTargetItem a : arguments) {
ret.addAll(a.toSource(localData, generator));
}
ret.addAll(command.toSource(localData, generator));
ret.add(new ActionPush((Long) (long) arguments.size()));
ret.add(new ActionFSCommand2());
return ret;
}
@Override
public boolean hasReturnValue() {
return true; //FIXME ?
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionGetURL;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
/**
*
@@ -36,4 +39,14 @@ public class FSCommandTreeItem extends TreeItem {
public String toString(ConstantPool constants) {
return hilight("fscommand(\"") + Helper.escapeString(command) + hilight("\")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionGetURL("FSCommand:" + command, ""));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,10 +16,23 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.graph.Graph;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.TreeSet;
public class FunctionTreeItem extends TreeItem {
@@ -29,6 +42,12 @@ public class FunctionTreeItem extends TreeItem {
public List<String> paramNames;
public GraphTargetItem calculatedFunctionName;
private int regStart;
public static final int REGISTER_THIS = 1;
public static final int REGISTER_ARGUMENTS = 2;
public static final int REGISTER_SUPER = 3;
public static final int REGISTER_ROOT = 4;
public static final int REGISTER_PARENT = 5;
public static final int REGISTER_GLOBAL = 6;
public FunctionTreeItem(GraphSourceItem instruction, String functionName, List<String> paramNames, List<GraphTargetItem> actions, List<String> constants, int regStart) {
super(instruction, PRECEDENCE_PRIMARY);
@@ -104,4 +123,182 @@ public class FunctionTreeItem extends TreeItem {
public boolean needsNewLine() {
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
List<GraphSourceItem> ret = new ArrayList<>();
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
List<Integer> paramRegs = new ArrayList<>();
@SuppressWarnings("unchecked")
List<Object> localDataCopy = (List<Object>) Helper.deepCopy(localData);
HashMap<String, Integer> registerVars = asGenerator.getRegisterVars(localDataCopy);
registerVars.put("_parent", REGISTER_PARENT);
registerVars.put("_root", REGISTER_ROOT);
registerVars.put("super", REGISTER_SUPER);
registerVars.put("arguments", REGISTER_ARGUMENTS);
registerVars.put("this", REGISTER_THIS);
registerVars.put("_global", REGISTER_GLOBAL);
for (int i = 0; i < paramNames.size(); i++) {
registerVars.put(paramNames.get(i), (7 + i)); //(paramNames.size() - i)));
}
boolean preloadParentFlag = false;
boolean preloadRootFlag = false;
boolean preloadSuperFlag = false;
boolean preloadArgumentsFlag = false;
boolean preloadThisFlag = false;
boolean preloadGlobalFlag = false;
boolean suppressParentFlag = false;
boolean suppressArgumentsFlag = false;
boolean suppressThisFlag = false;
TreeSet<Integer> usedRegisters = new TreeSet<>();
if (actions != null && !actions.isEmpty()) {
asGenerator.setInFunction(localDataCopy, true);
List<Action> body = asGenerator.toActionList(asGenerator.generate(localDataCopy, actions));
for (Action a : body) {
if (a instanceof ActionStoreRegister) {
usedRegisters.add(((ActionStoreRegister) a).registerNumber);
}
if (a instanceof ActionPush) {
ActionPush ap = (ActionPush) a;
for (Object o : ap.values) {
if (o instanceof RegisterNumber) {
usedRegisters.add(((RegisterNumber) o).number);
}
}
}
}
if (usedRegisters.contains(REGISTER_PARENT)) {
preloadParentFlag = true;
} else {
suppressParentFlag = true;
}
if (usedRegisters.contains(REGISTER_ROOT)) {
preloadRootFlag = true;
}
if (usedRegisters.contains(REGISTER_SUPER)) {
preloadSuperFlag = true;
}
if (usedRegisters.contains(REGISTER_ARGUMENTS)) {
preloadArgumentsFlag = true;
} else {
suppressArgumentsFlag = true;
}
if (usedRegisters.contains(REGISTER_THIS)) {
preloadThisFlag = true;
} else {
suppressThisFlag = true;
}
if (usedRegisters.contains(REGISTER_GLOBAL)) {
preloadGlobalFlag = true;
}
int newpos = 1;
HashMap<Integer, Integer> registerMap = new HashMap<>();
if (preloadThisFlag) {
registerMap.put(REGISTER_THIS, newpos);
newpos++;
}
if (preloadArgumentsFlag) {
registerMap.put(REGISTER_ARGUMENTS, newpos);
newpos++;
}
if (preloadSuperFlag) {
registerMap.put(REGISTER_SUPER, newpos);
newpos++;
}
if (preloadRootFlag) {
registerMap.put(REGISTER_ROOT, newpos);
newpos++;
}
if (preloadParentFlag) {
registerMap.put(REGISTER_PARENT, newpos);
newpos++;
}
if (preloadGlobalFlag) {
registerMap.put(REGISTER_GLOBAL, newpos);
newpos++;
}
if (newpos < 1) {
newpos = 1;
}
for (int i = 0; i < 256; i++) {
if (usedRegisters.contains(7 + i)) {
registerMap.put(7 + i, newpos);
if (i < paramNames.size()) {
paramRegs.add(newpos);
}
newpos++;
} else {
if (i < paramNames.size()) {
paramRegs.add(0);
}
}
}
TreeSet<Integer> usedRegisters2 = new TreeSet<>();
for (int i : usedRegisters) {
if (registerMap.get(i) == null) {
usedRegisters2.add(i);
} else {
usedRegisters2.add(registerMap.get(i));
}
}
usedRegisters = usedRegisters2;
for (Action a : body) {
if (a instanceof ActionStoreRegister) {
if (registerMap.containsKey(((ActionStoreRegister) a).registerNumber)) {
((ActionStoreRegister) a).registerNumber = registerMap.get(((ActionStoreRegister) a).registerNumber);
}
}
if (a instanceof ActionPush) {
ActionPush ap = (ActionPush) a;
for (Object o : ap.values) {
if (o instanceof RegisterNumber) {
if (registerMap.containsKey(((RegisterNumber) o).number)) {
((RegisterNumber) o).number = registerMap.get(((RegisterNumber) o).number);
}
}
}
}
}
ret.addAll(body);
} else {
for (int i = 0; i < paramNames.size(); i++) {
paramRegs.add(1 + i);
}
}
int len = Action.actionsToBytes(asGenerator.toActionList(ret), false, SWF.DEFAULT_VERSION).length;
if ((!preloadParentFlag)
&& (!preloadRootFlag)
&& (!preloadSuperFlag)
&& (!preloadArgumentsFlag)
&& (!preloadThisFlag)
&& (!preloadGlobalFlag)
&& (suppressArgumentsFlag)
&& (suppressThisFlag)
&& (suppressParentFlag)
&& usedRegisters.isEmpty()) {
ret.add(0, new ActionDefineFunction(functionName, paramNames, len, SWF.DEFAULT_VERSION));
} else {
ret.add(0, new ActionDefineFunction2(functionName,
preloadParentFlag,
preloadRootFlag,
suppressParentFlag,
preloadSuperFlag,
suppressArgumentsFlag,
preloadArgumentsFlag,
suppressThisFlag,
preloadThisFlag,
preloadGlobalFlag,
usedRegisters.isEmpty() ? 0 : (usedRegisters.last() + 1), len, SWF.DEFAULT_VERSION, paramNames, paramRegs));
}
return ret;
}
@Override
public boolean hasReturnValue() {
return false; //function actually returns itself, but here is false for generator to not add Pop
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionGetMember;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class GetMemberTreeItem extends TreeItem {
@@ -73,4 +75,14 @@ public class GetMemberTreeItem extends TreeItem {
}
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, memberName, new ActionGetMember());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -17,8 +17,11 @@
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.swf4.ActionGetProperty;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class GetPropertyTreeItem extends TreeItem {
@@ -46,4 +49,14 @@ public class GetPropertyTreeItem extends TreeItem {
ret.addAll(target.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex), new ActionGetProperty());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,7 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetTime;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
import java.util.Random;
public class GetTimeTreeItem extends TreeItem {
@@ -39,4 +42,14 @@ public class GetTimeTreeItem extends TreeItem {
public Object getResult() {
return (Double) (double) new Random().nextInt(10000) + 1000;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionGetTime());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class GetURL2TreeItem extends TreeItem {
@@ -53,4 +55,14 @@ public class GetURL2TreeItem extends TreeItem {
ret.addAll(targetString.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(sendVarsMethod, false, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionGetURL;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
public class GetURLTreeItem extends TreeItem {
@@ -34,4 +37,14 @@ public class GetURLTreeItem extends TreeItem {
this.urlString = urlString;
this.targetString = targetString;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionGetURL(urlString, targetString));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class GetVariableTreeItem extends TreeItem {
@@ -99,4 +101,14 @@ public class GetVariableTreeItem extends TreeItem {
}
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, name, new ActionGetVariable());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,7 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -32,4 +36,14 @@ public class GetVersionTreeItem extends TreeItem {
public String toString(ConstantPool constants) {
return hilight("getVersion()");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionPush("/:$version"), new ActionGetVariable());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGotoFrame2;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class GotoFrame2TreeItem extends TreeItem {
@@ -50,4 +52,14 @@ public class GotoFrame2TreeItem extends TreeItem {
ret.addAll(frame.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, frame, new ActionGotoFrame2(playFlag, sceneBiasFlag, sceneBias));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,7 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionGotoFrame;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class GotoFrameTreeItem extends TreeItem {
@@ -29,6 +32,16 @@ public class GotoFrameTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("gotoAndStop(") + frame + hilight(")");
return hilight("gotoAndStop(") + (frame + 1) + hilight(")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionGotoFrame(frame));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionGoToLabel;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
public class GotoLabelTreeItem extends TreeItem {
@@ -32,4 +35,14 @@ public class GotoLabelTreeItem extends TreeItem {
public String toString(ConstantPool constants) {
return hilight("gotoAndStop(\"") + Helper.escapeString(label) + hilight("\")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionGoToLabel(label));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -53,4 +53,9 @@ public class ImplementsOpTreeItem extends TreeItem {
}
return ret;
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionIncrement;
import com.jpexs.decompiler.flash.ecma.*;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class IncrementTreeItem extends TreeItem {
@@ -51,4 +53,14 @@ public class IncrementTreeItem extends TreeItem {
ret.addAll(object.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, new ActionIncrement());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionInitArray;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItemPos;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class InitArrayTreeItem extends TreeItem {
@@ -50,4 +52,14 @@ public class InitArrayTreeItem extends TreeItem {
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, toSourceCall(localData, generator, values), new ActionInitArray());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,12 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.graph.TernarOpItem;
import java.util.ArrayList;
import java.util.List;
public class InitObjectTreeItem extends TreeItem {
@@ -59,4 +62,20 @@ public class InitObjectTreeItem extends TreeItem {
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
List<GraphSourceItem> ret = new ArrayList<>();
for (int i = values.size() - 1; i >= 0; i--) {
ret.addAll(names.get(i).toSource(localData, generator));
ret.addAll(values.get(i).toSource(localData, generator));
}
ret.add(new ActionPush((Long) (long) values.size()));
return ret;
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,13 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -26,10 +31,10 @@ import com.jpexs.decompiler.flash.graph.GraphTargetItem;
public class LoadMovieNumTreeItem extends TreeItem {
private GraphTargetItem urlString;
private int num;
private GraphTargetItem num;
private int method;
public LoadMovieNumTreeItem(GraphSourceItem instruction, GraphTargetItem urlString, int num, int method) {
public LoadMovieNumTreeItem(GraphSourceItem instruction, GraphTargetItem urlString, GraphTargetItem num, int method) {
super(instruction, PRECEDENCE_PRIMARY);
this.urlString = urlString;
this.num = num;
@@ -47,4 +52,15 @@ public class LoadMovieNumTreeItem extends TreeItem {
}
return hilight("loadMovieNum(") + urlString.toString(constants) + hilight(",") + num + hilight(methodStr + ")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
return toSourceMerge(localData, generator, urlString, new AddTreeItem(src, asGenerator.pushConstTargetItem("_level"), num, true), new ActionGetURL2(method, false, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -47,4 +50,14 @@ public class LoadMovieTreeItem extends TreeItem {
}
return hilight("loadMovie(") + urlString.toString(constants) + hilight(",") + targetString.toString(constants) + hilight(methodStr + ")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(method, true, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,13 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -26,10 +31,10 @@ import com.jpexs.decompiler.flash.graph.GraphTargetItem;
public class LoadVariablesNumTreeItem extends TreeItem {
private GraphTargetItem urlString;
private int num;
private GraphTargetItem num;
private int method;
public LoadVariablesNumTreeItem(GraphSourceItem instruction, GraphTargetItem urlString, int num, int method) {
public LoadVariablesNumTreeItem(GraphSourceItem instruction, GraphTargetItem urlString, GraphTargetItem num, int method) {
super(instruction, PRECEDENCE_PRIMARY);
this.urlString = urlString;
this.num = num;
@@ -47,4 +52,15 @@ public class LoadVariablesNumTreeItem extends TreeItem {
}
return hilight("loadVariablesNum(") + urlString.toString(constants) + hilight(",") + num + hilight(methodStr + ")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
return toSourceMerge(localData, generator, urlString, new AddTreeItem(src, asGenerator.pushConstTargetItem("_level"), num, true), new ActionGetURL2(method, false, true));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -47,4 +50,14 @@ public class LoadVariablesTreeItem extends TreeItem {
}
return hilight("loadVariables(") + urlString.toString(constants) + hilight(",") + targetString.toString(constants) + hilight(methodStr + ")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(method, false, true));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionMBAsciiToChar;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class MBAsciiToCharTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class MBAsciiToCharTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionMBAsciiToChar());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionMBCharToAscii;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class MBCharToAsciiTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class MBCharToAsciiTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionMBCharToAscii());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionMBStringExtract;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class MBStringExtractTreeItem extends TreeItem {
@@ -46,4 +48,14 @@ public class MBStringExtractTreeItem extends TreeItem {
ret.addAll(count.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, index, count, new ActionMBStringExtract());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionMBStringLength;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class MBStringLengthTreeItem extends TreeItem {
@@ -43,4 +45,14 @@ public class MBStringLengthTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionMBStringLength());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionNewMethod;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class NewMethodTreeItem extends TreeItem {
@@ -75,4 +77,14 @@ public class NewMethodTreeItem extends TreeItem {
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, toSourceCall(localData, generator, arguments), scriptObject, methodName, new ActionNewMethod());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionNewObject;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class NewObjectTreeItem extends TreeItem {
@@ -52,4 +54,14 @@ public class NewObjectTreeItem extends TreeItem {
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, toSourceCall(localData, generator, arguments), objectName, new ActionNewObject());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2010-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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionNextFrame;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class NextFrameTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("nextFrame()");
}
public NextFrameTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionNextFrame());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,21 +16,29 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionPlay;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class WaitForFrameTreeItem extends TreeItem {
public int frame;
public int skipCount;
public WaitForFrameTreeItem(GraphSourceItem instruction, int frame, int skipCount) {
super(instruction, PRECEDENCE_PRIMARY);
this.frame = frame;
this.skipCount = skipCount;
}
public class PlayTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("waitForFrame(") + frame + "," + skipCount + hilight(")");
return hilight("play()");
}
public PlayTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionPlay());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,7 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionPop;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -42,4 +45,14 @@ public class PopTreeItem extends TreeItem {
public boolean isEmpty() {
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionPop());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,20 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionPop;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSetProperty;
import com.jpexs.decompiler.flash.action.swf4.ActionSetVariable;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionDecrement;
import com.jpexs.decompiler.flash.action.swf5.ActionSetMember;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.action.treemodel.operations.SubtractTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.ArrayList;
import java.util.List;
public class PostDecrementTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -62,6 +73,51 @@ public class PostDecrementTreeItem extends TreeItem implements SetTypeTreeItem {
@Override
public void setValue(GraphTargetItem value) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public List<GraphSourceItem> toSourceIgnoreReturnValue(List<Object> localData, SourceGenerator generator) {
List<GraphSourceItem> ret = new ArrayList<>();
if (object instanceof GetVariableTreeItem) {
GetVariableTreeItem gv = (GetVariableTreeItem) object;
ret.addAll(gv.toSource(localData, generator));
ret.remove(ret.size() - 1); //ActionGetVariable
ret.addAll(gv.toSource(localData, generator));
ret.add(new ActionDecrement());
ret.add(new ActionSetVariable());
} else if (object instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) object;
ret.addAll(mem.toSource(localData, generator));
ret.remove(ret.size() - 1); //ActionGetMember
ret.addAll(mem.toSource(localData, generator));
ret.add(new ActionDecrement());
ret.add(new ActionSetMember());
} else if ((object instanceof DirectValueTreeItem) && ((DirectValueTreeItem) object).value instanceof RegisterNumber) {
RegisterNumber rn = (RegisterNumber) ((DirectValueTreeItem) object).value;
ret.add(new ActionPush(new RegisterNumber(rn.number)));
ret.add(new ActionDecrement());
ret.add(new ActionStoreRegister(rn.number));
ret.add(new ActionPop());
} else if (object instanceof GetPropertyTreeItem) {
GetPropertyTreeItem gp = (GetPropertyTreeItem) object;
ret.addAll(gp.toSource(localData, generator));
ret.remove(ret.size() - 1);
ret.addAll(gp.toSource(localData, generator));
ret.add(new ActionDecrement());
ret.add(new ActionSetProperty());
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object.toSource(localData, generator), toSourceIgnoreReturnValue(localData, generator));
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,20 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionPop;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSetProperty;
import com.jpexs.decompiler.flash.action.swf4.ActionSetVariable;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionIncrement;
import com.jpexs.decompiler.flash.action.swf5.ActionSetMember;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.ArrayList;
import java.util.List;
public class PostIncrementTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -64,4 +75,49 @@ public class PostIncrementTreeItem extends TreeItem implements SetTypeTreeItem {
public void setValue(GraphTargetItem value) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public List<GraphSourceItem> toSourceIgnoreReturnValue(List<Object> localData, SourceGenerator generator) {
List<GraphSourceItem> ret = new ArrayList<>();
if (object instanceof GetVariableTreeItem) {
GetVariableTreeItem gv = (GetVariableTreeItem) object;
ret.addAll(gv.toSource(localData, generator));
ret.remove(ret.size() - 1); //ActionGetVariable
ret.addAll(gv.toSource(localData, generator));
ret.add(new ActionIncrement());
ret.add(new ActionSetVariable());
} else if (object instanceof GetMemberTreeItem) {
GetMemberTreeItem mem = (GetMemberTreeItem) object;
ret.addAll(mem.toSource(localData, generator));
ret.remove(ret.size() - 1); //ActionGetMember
ret.addAll(mem.toSource(localData, generator));
ret.add(new ActionIncrement());
ret.add(new ActionSetMember());
} else if ((object instanceof DirectValueTreeItem) && ((DirectValueTreeItem) object).value instanceof RegisterNumber) {
RegisterNumber rn = (RegisterNumber) ((DirectValueTreeItem) object).value;
ret.add(new ActionPush(new RegisterNumber(rn.number)));
ret.add(new ActionIncrement());
ret.add(new ActionStoreRegister(rn.number));
ret.add(new ActionPop());
} else if (object instanceof GetPropertyTreeItem) {
GetPropertyTreeItem gp = (GetPropertyTreeItem) object;
ret.addAll(gp.toSource(localData, generator));
ret.remove(ret.size() - 1);
ret.addAll(gp.toSource(localData, generator));
ret.add(new ActionIncrement());
ret.add(new ActionSetProperty());
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object.toSource(localData, generator), toSourceIgnoreReturnValue(localData, generator));
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2010-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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionPrevFrame;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class PrevFrameTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("prevFrame()");
}
public PrevFrameTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionPrevFrame());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,13 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -25,10 +30,10 @@ import com.jpexs.decompiler.flash.helpers.Helper;
*/
public class PrintAsBitmapNumTreeItem extends TreeItem {
private int num;
private String boundingBox;
private GraphTargetItem num;
private GraphTargetItem boundingBox;
public PrintAsBitmapNumTreeItem(GraphSourceItem instruction, int num, String boundingBox) {
public PrintAsBitmapNumTreeItem(GraphSourceItem instruction, GraphTargetItem num, GraphTargetItem boundingBox) {
super(instruction, PRECEDENCE_PRIMARY);
this.num = num;
this.boundingBox = boundingBox;
@@ -36,6 +41,18 @@ public class PrintAsBitmapNumTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("printAsBitmapNum(") + num + hilight(",") + "\"" + Helper.escapeString(boundingBox) + "\"" + hilight(")");
return hilight("printAsBitmapNum(") + num.toString(constants) + hilight(",") + boundingBox.toString(constants) + hilight(")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
return toSourceMerge(localData, generator, new AddTreeItem(src, asGenerator.pushConstTargetItem("printasbitmap:#"), boundingBox, true), new AddTreeItem(src, asGenerator.pushConstTargetItem("_level"), num, true), new ActionGetURL2(0, false, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,14 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.helpers.Helper;
import static com.jpexs.decompiler.flash.graph.GraphTargetItem.PRECEDENCE_PRIMARY;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -27,9 +32,9 @@ import com.jpexs.decompiler.flash.helpers.Helper;
public class PrintAsBitmapTreeItem extends TreeItem {
private GraphTargetItem target;
private String boundingBox;
private GraphTargetItem boundingBox;
public PrintAsBitmapTreeItem(GraphSourceItem instruction, GraphTargetItem target, String boundingBox) {
public PrintAsBitmapTreeItem(GraphSourceItem instruction, GraphTargetItem target, GraphTargetItem boundingBox) {
super(instruction, PRECEDENCE_PRIMARY);
this.target = target;
this.boundingBox = boundingBox;
@@ -37,6 +42,17 @@ public class PrintAsBitmapTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("printAsBitmap(") + target.toString(constants) + hilight(",") + "\"" + Helper.escapeString(boundingBox) + "\"" + hilight(")");
return hilight("printAsBitmap(") + target.toString(constants) + hilight(",") + boundingBox.toString(constants) + hilight(")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
return toSourceMerge(localData, generator, new AddTreeItem(src, asGenerator.pushConstTargetItem("printasbitmap:#"), boundingBox, true), target, new ActionGetURL2(0, false, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,13 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -25,10 +30,10 @@ import com.jpexs.decompiler.flash.helpers.Helper;
*/
public class PrintNumTreeItem extends TreeItem {
private int num;
private String boundingBox;
private GraphTargetItem num;
private GraphTargetItem boundingBox;
public PrintNumTreeItem(GraphSourceItem instruction, int num, String boundingBox) {
public PrintNumTreeItem(GraphSourceItem instruction, GraphTargetItem num, GraphTargetItem boundingBox) {
super(instruction, PRECEDENCE_PRIMARY);
this.num = num;
this.boundingBox = boundingBox;
@@ -36,6 +41,17 @@ public class PrintNumTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("printNum(") + num + hilight(",") + "\"" + Helper.escapeString(boundingBox) + "\"" + hilight(")");
return hilight("printNum(") + num.toString(constants) + hilight(",") + boundingBox.toString(constants) + hilight(")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
return toSourceMerge(localData, generator, new AddTreeItem(src, asGenerator.pushConstTargetItem("print:#"), boundingBox, true), new AddTreeItem(src, asGenerator.pushConstTargetItem("_level"), num, true), new ActionGetURL2(0, false, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,13 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2;
import com.jpexs.decompiler.flash.action.treemodel.operations.AddTreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
/**
*
@@ -27,9 +31,9 @@ import com.jpexs.decompiler.flash.helpers.Helper;
public class PrintTreeItem extends TreeItem {
private GraphTargetItem target;
private String boundingBox;
private GraphTargetItem boundingBox;
public PrintTreeItem(GraphSourceItem instruction, GraphTargetItem target, String boundingBox) {
public PrintTreeItem(GraphSourceItem instruction, GraphTargetItem target, GraphTargetItem boundingBox) {
super(instruction, PRECEDENCE_PRIMARY);
this.target = target;
this.boundingBox = boundingBox;
@@ -37,6 +41,17 @@ public class PrintTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("print(") + target.toString(constants) + hilight(",") + "\"" + Helper.escapeString(boundingBox) + "\"" + hilight(")");
return hilight("print(") + target.toString(constants) + hilight(",") + boundingBox.toString(constants) + hilight(")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
return toSourceMerge(localData, generator, new AddTreeItem(src, asGenerator.pushConstTargetItem("print:#"), boundingBox, true), target, new ActionGetURL2(0, false, false));
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionRandomNumber;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class RandomNumberTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class RandomNumberTreeItem extends TreeItem {
ret.addAll(maximum.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, maximum, new ActionRandomNumber());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionRemoveSprite;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class RemoveSpriteTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class RemoveSpriteTreeItem extends TreeItem {
ret.addAll(target.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, target, new ActionRemoveSprite());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,21 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
import com.jpexs.decompiler.flash.action.swf5.ActionReturn;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.graph.ExitItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.ArrayList;
import java.util.List;
public class ReturnTreeItem extends TreeItem implements ExitItem {
@@ -45,4 +57,33 @@ public class ReturnTreeItem extends TreeItem implements ExitItem {
public boolean isCompileTime() {
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
List<GraphSourceItem> ret = new ArrayList<>();
int forinlevel = asGenerator.getForInLevel(localData);
for (int i = 0; i < forinlevel; i++) { //Must POP all remaining values from enumerations (for..in)
List<Action> forinret = new ArrayList<>();
forinret.add(new ActionPush(new Null()));
forinret.add(new ActionEquals2());
forinret.add(new ActionNot());
ActionIf aforinif = new ActionIf(0);
forinret.add(aforinif);
aforinif.setJumpOffset(-Action.actionsToBytes(forinret, false, SWF.DEFAULT_VERSION).length);
ret.addAll(forinret);
}
if (value == null) {
ret.add(new ActionPush(new Undefined()));
} else {
ret.addAll(value.toSource(localData, generator));
}
ret.add(new ActionReturn());
return ret;
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,15 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionSetMember;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.graph.GraphPart;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class SetMemberTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -87,4 +93,21 @@ public class SetMemberTreeItem extends TreeItem implements SetTypeTreeItem {
public boolean hasSideEffect() {
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
int tmpReg = asGenerator.getTempRegister(localData);
return toSourceMerge(localData, generator, object, objectName, value, new ActionStoreRegister(tmpReg), new ActionSetMember(), new ActionPush(new RegisterNumber(tmpReg)));
}
@Override
public List<GraphSourceItem> toSourceIgnoreReturnValue(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, objectName, value, new ActionSetMember());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -17,9 +17,15 @@
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSetProperty;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.graph.GraphPart;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class SetPropertyTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -86,4 +92,21 @@ public class SetPropertyTreeItem extends TreeItem implements SetTypeTreeItem {
public boolean hasSideEffect() {
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
int tmpReg = asGenerator.getTempRegister(localData);
return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex), value, new ActionStoreRegister(tmpReg), new ActionSetProperty(), new ActionPush(new RegisterNumber(tmpReg)));
}
@Override
public List<GraphSourceItem> toSourceIgnoreReturnValue(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex), value, new ActionSetProperty());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class SetTarget2TreeItem extends TreeItem {
@@ -40,4 +41,14 @@ public class SetTarget2TreeItem extends TreeItem {
ret.addAll(target.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
throw new UnsupportedOperationException();
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -17,7 +17,9 @@
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
public class SetTargetTreeItem extends TreeItem {
@@ -32,4 +34,14 @@ public class SetTargetTreeItem extends TreeItem {
public String toString(ConstantPool constants) {
return hilight("tellTarget(\"") + Helper.escapeString(target) + hilight("\")");
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
throw new UnsupportedOperationException();
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,15 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.parser.script.ActionScriptSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSetVariable;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.graph.GraphPart;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class SetVariableTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -89,4 +95,21 @@ public class SetVariableTreeItem extends TreeItem implements SetTypeTreeItem {
public boolean hasSideEffect() {
return true;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
ActionScriptSourceGenerator asGenerator = (ActionScriptSourceGenerator) generator;
int tmpReg = asGenerator.getTempRegister(localData);
return toSourceMerge(localData, generator, name, value, new ActionStoreRegister(tmpReg), new ActionSetVariable(), new ActionPush(new RegisterNumber(tmpReg)));
}
@Override
public List<GraphSourceItem> toSourceIgnoreReturnValue(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, name, value, new ActionSetVariable());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionStartDrag;
import com.jpexs.decompiler.flash.ecma.*;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class StartDragTreeItem extends TreeItem {
@@ -64,4 +66,24 @@ public class StartDragTreeItem extends TreeItem {
ret.addAll(y2.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
boolean hasConstrains = true;
if (constrain instanceof DirectValueTreeItem) {
if (Double.compare(EcmaScript.toNumber(constrain.getResult()), 0) == 0) {
hasConstrains = false;
}
}
if (hasConstrains) {
return toSourceMerge(localData, generator, x1, y1, x2, y2, constrain, lockCenter, target, new ActionStartDrag());
} else {
return toSourceMerge(localData, generator, constrain, lockCenter, target, new ActionStartDrag());
}
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2010-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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionStopSounds;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class StopAllSoundsTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("stopAllSounds()");
}
public StopAllSoundsTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionStopSounds());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,19 +16,29 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionEndDrag;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class VoidTreeItem extends TreeItem {
public TreeItem value;
public VoidTreeItem(GraphSourceItem instruction, TreeItem value) {
super(instruction, PRECEDENCE_PRIMARY);
this.value = value;
}
public class StopDragTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return value.toString(constants);
return hilight("stopDrag()");
}
public StopDragTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionEndDrag());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,19 +16,29 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionStop;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class SimpleActionTreeItem extends TreeItem {
private String actionString;
public class StopTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight(actionString);
return hilight("stop()");
}
public SimpleActionTreeItem(GraphSourceItem instruction, String actionString) {
public StopTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
this.actionString = actionString;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionStop());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -17,9 +17,11 @@
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.graph.GraphPart;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class StoreRegisterTreeItem extends TreeItem implements SetTypeTreeItem {
@@ -77,4 +79,14 @@ public class StoreRegisterTreeItem extends TreeItem implements SetTypeTreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionStoreRegister(register.number));
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -31,4 +31,9 @@ public class StrictModeTreeItem extends TreeItem {
public String toString(ConstantPool constants) {
return "StrictMode(" + mode + ");"; //I still don't know how AS source of Strict Mode instruction looks like, assuming this...
}
@Override
public boolean hasReturnValue() {
return false; //FIXME ?
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionStringExtract;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class StringExtractTreeItem extends TreeItem {
@@ -46,4 +48,14 @@ public class StringExtractTreeItem extends TreeItem {
ret.addAll(count.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, index, count, new ActionStringExtract());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -14,12 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel.operations;
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.treemodel.ConstantPool;
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLength;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class StringLengthTreeItem extends TreeItem {
@@ -38,4 +39,14 @@ public class StringLengthTreeItem extends TreeItem {
public boolean isCompileTime() {
return false;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionStringLength());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionTargetPath;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class TargetPathTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class TargetPathTreeItem extends TreeItem {
ret.addAll(object.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, new ActionTargetPath());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,9 +16,11 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf7.ActionThrow;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItemPos;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
@@ -42,4 +44,14 @@ public class ThrowTreeItem extends TreeItem {
ret.addAll(object.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, object, new ActionThrow());
}
@Override
public boolean hasReturnValue() {
return false;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf4.ActionToInteger;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class ToIntegerTreeItem extends TreeItem {
@@ -40,4 +42,14 @@ public class ToIntegerTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionToInteger());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionToNumber;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
@@ -41,4 +43,14 @@ public class ToNumberTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionToNumber());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -16,8 +16,10 @@
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf5.ActionToString;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.util.List;
@@ -41,4 +43,14 @@ public class ToStringTreeItem extends TreeItem {
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, value, new ActionToString());
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2010-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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel;
import com.jpexs.decompiler.flash.action.swf3.ActionToggleQuality;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.SourceGenerator;
import java.util.List;
public class ToggleHighQualityTreeItem extends TreeItem {
@Override
public String toString(ConstantPool constants) {
return hilight("toggleHighQuality()");
}
public ToggleHighQualityTreeItem(GraphSourceItem instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public List<GraphSourceItem> toSource(List<Object> localData, SourceGenerator generator) {
return toSourceMerge(localData, generator, new ActionToggleQuality());
}
}

Some files were not shown because too many files have changed in this diff Show More