AS2: New instructions - FSCommand2 added (Issue #5), StrictMode added

This commit is contained in:
Jindra Pet��k
2011-12-27 11:00:29 +01:00
parent d04c4cb3a0
commit 1e764ba652
6 changed files with 202 additions and 1 deletions
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2010-2011 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.jpexs.asdec.action.flashlite;
import com.jpexs.asdec.action.Action;
import com.jpexs.asdec.action.treemodel.ConstantPool;
import com.jpexs.asdec.action.treemodel.FSCommand2TreeItem;
import com.jpexs.asdec.action.treemodel.TreeItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
public class ActionFSCommand2 extends Action {
public ActionFSCommand2() {
super(0x2D, 0);
}
@Override
public String toString() {
return "FSCommand2";
}
@Override
public void translate(Stack<TreeItem> stack, ConstantPool constants, List<TreeItem> output, java.util.HashMap<Integer,String> regNames) {
long numArgs = popLong(stack);
TreeItem command = stack.pop();
List<TreeItem> args = new ArrayList<TreeItem>();
for (long l = 0; l < numArgs; l++) {
args.add(stack.pop());
}
stack.push(new FSCommand2TreeItem(this, command, args));
}
}
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2010-2011 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.jpexs.asdec.action.flashlite;
import com.jpexs.asdec.SWFInputStream;
import com.jpexs.asdec.SWFOutputStream;
import com.jpexs.asdec.action.Action;
import com.jpexs.asdec.action.parser.FlasmLexer;
import com.jpexs.asdec.action.parser.ParseException;
import com.jpexs.asdec.action.treemodel.ConstantPool;
import com.jpexs.asdec.action.treemodel.StrictModeTreeItem;
import com.jpexs.asdec.action.treemodel.TreeItem;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Stack;
public class ActionStrictMode extends Action {
public int mode;
public ActionStrictMode(SWFInputStream sis) throws IOException {
super(0x89, 1);
mode = sis.readUI8();
}
public ActionStrictMode(FlasmLexer lexer) throws IOException, ParseException {
super(0x89, 1);
mode = (int) lexLong(lexer);
}
public byte[] getBytes(int version) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SWFOutputStream sos = new SWFOutputStream(baos, version);
try {
sos.writeUI8(mode);
sos.close();
} catch (IOException e) {
}
return surroundWithAction(baos.toByteArray(), version);
}
@Override
public String toString() {
return "StrictMode " + mode;
}
@Override
public void translate(Stack<TreeItem> stack, ConstantPool constants, List<TreeItem> output, java.util.HashMap<Integer,String> regNames) {
output.add(new StrictModeTreeItem(this, mode));
}
}
@@ -19,6 +19,8 @@
package com.jpexs.asdec.action.parser;
import com.jpexs.asdec.action.Action;
import com.jpexs.asdec.action.flashlite.ActionFSCommand2;
import com.jpexs.asdec.action.flashlite.ActionStrictMode;
import com.jpexs.asdec.action.swf3.*;
import com.jpexs.asdec.action.swf4.*;
import com.jpexs.asdec.action.swf5.*;
@@ -240,6 +242,10 @@ public class ASMParser {
list.add(new ActionThrow());
} else if (instructionName.equals("Try".toLowerCase())) {
list.add(new ActionTry(labels, address, lexer, constantPool, version));
} else if (instructionName.equals("FSCommand2".toLowerCase())) {
list.add(new ActionFSCommand2());
} else if (instructionName.equals("StrictMode".toLowerCase())) {
list.add(new ActionStrictMode(lexer));
} else {
throw new ParseException("Unknown instruction name :" + instructionName, lexer.yyline());
}
@@ -20,7 +20,6 @@ package com.jpexs.asdec.action.treemodel;
import com.jpexs.asdec.action.Action;
import com.jpexs.asdec.action.swf4.Undefined;
import java.util.List;
public class CallMethodTreeItem extends TreeItem {
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2010-2011 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.jpexs.asdec.action.treemodel;
import com.jpexs.asdec.action.Action;
import java.util.List;
public class FSCommand2TreeItem extends TreeItem {
public String target;
public List<TreeItem> arguments;
public TreeItem command;
public FSCommand2TreeItem(Action instruction, TreeItem command,List<TreeItem> arguments) {
super(instruction, PRECEDENCE_PRIMARY);
this.command = command;
this.arguments=arguments;
}
@Override
public String toString(ConstantPool constants) {
String paramStr = "";
for (int t = 0; t < arguments.size(); t++) {
paramStr += ",";
paramStr += arguments.get(t).toString(constants);
}
return "FSCommand2(" + command.toString(constants)+paramStr+");";
}
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2011 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.jpexs.asdec.action.treemodel;
import com.jpexs.asdec.action.Action;
public class StrictModeTreeItem extends TreeItem {
public int mode;
public StrictModeTreeItem(Action instruction,int mode){
super(instruction,PRECEDENCE_PRIMARY);
this.mode=mode;
}
@Override
public String toString(ConstantPool constants) {
return "StrictMode("+mode+");"; //I still don't know how AS source of Strict Mode instruction looks like, assuming this...
}
}