version apha 9

AS3: Included new undocumented instructions, new Multiname kind - Typename
AS3: Export PCode
AS3: Implemented code for executing some instructions
Many bugfixes
This commit is contained in:
Jindra Petk
2011-07-02 18:28:51 +02:00
parent 6f4754f481
commit eaeaa19923
578 changed files with 2900 additions and 2522 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -52,16 +52,23 @@ public class Main {
public static String file;
public static String maskURL;
public static SWF swf;
public static final String version = "alpha8";
public static final String version = "alpha9";
public static String applicationName = "JP ActionScript Decompiler v." + version;
public static LoadingDialog loadingDialog = new LoadingDialog();
public static ModeFrame modeFrame;
private static boolean working = false;
private static TrayIcon trayIcon;
private static MenuItem stopMenuItem;
public static boolean DEBUG_COPY = false;
/** Debug mode = throwing an error when comparing original file and recompiled */
public static boolean DEBUG_MODE = false;
/** Turn off reading unsafe tags (tags which can cause problems with recompiling)*/
public static boolean DISABLE_DANGEROUS = false;
/** Turn off resolving constants in ActionScript 2 */
public static final boolean RESOLVE_CONSTANTS = true;
/** Turn off decompiling if needed */
public static final boolean DO_DECOMPILE=true;
public static String getFileTitle() {
if (maskURL != null) return maskURL;
@@ -282,7 +289,7 @@ public class Main {
public static void updateLicenseInDir(File dir){
String license="/*\r\n * Copyright (C) 2010 JPEXS\r\n * \r\n * This program is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU General Public License\r\n * as published by the Free Software Foundation; either version 2\r\n * of the License, or (at your option) any later version.\r\n * \r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU General Public License for more details.\r\n * \r\n * You should have received a copy of the GNU General Public License\r\n * along with this program; if not, write to the Free Software\r\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r\n */\r\n";
String license="/*\r\n * Copyright (C) 2010-2011 JPEXS\r\n * \r\n * This program is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU General Public License\r\n * as published by the Free Software Foundation; either version 2\r\n * of the License, or (at your option) any later version.\r\n * \r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU General Public License for more details.\r\n * \r\n * You should have received a copy of the GNU General Public License\r\n * along with this program; if not, write to the Free Software\r\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r\n */\r\n";
File files[]=dir.listFiles();
for(File f:files){
@@ -336,6 +343,8 @@ public class Main {
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
updateLicenseInDir(new File("src"));
System.exit(0);
View.setWinLookAndFeel();
loadReplacements();
if (args.length < 1) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -110,7 +110,7 @@ public class SWFInputStream extends InputStream {
int r = 0;
while (true) {
r = read();
if (r == 0) return new String(baos.toByteArray(), "utf8");
if (r <= 0) return new String(baos.toByteArray(), "utf8");
baos.write(r);
}
}
@@ -268,6 +268,7 @@ public class SWFInputStream extends InputStream {
* @throws IOException
*/
public byte[] readBytes(long count) throws IOException {
if(count<=0) return new byte[0];
byte ret[] = new byte[(int) count];
for (int i = 0; i < count; i++) {
ret[i] = (byte) read();
@@ -496,7 +497,7 @@ public class SWFInputStream extends InputStream {
case 0x81:
return new ActionGotoFrame(this);
case 0x83:
return new ActionGetURL(actionLength, this);
return new ActionGetURL(actionLength, this,version);
case 0x04:
return new ActionNextFrame();
case 0x05:
@@ -512,9 +513,9 @@ public class SWFInputStream extends InputStream {
case 0x8A:
return new ActionWaitForFrame(this);
case 0x8B:
return new ActionSetTarget(actionLength, this);
return new ActionSetTarget(actionLength, this,version);
case 0x8C:
return new ActionGoToLabel(actionLength, this);
return new ActionGoToLabel(actionLength, this,version);
//SWF4 Actions
case 0x96:
return new ActionPush(actionLength, this, version);
@@ -604,7 +605,7 @@ public class SWFInputStream extends InputStream {
case 0x52:
return new ActionCallMethod();
case 0x88:
return new ActionConstantPool(actionLength, this);
return new ActionConstantPool(actionLength, this,version);
case 0x9B:
return new ActionDefineFunction(actionLength, this, version);
case 0x3C:
@@ -811,7 +812,8 @@ public class SWFInputStream extends InputStream {
ret.keyCode = readUI8();
actionRecordSize--;
}
ret.actions = (new SWFInputStream(new ByteArrayInputStream(readBytes(actionRecordSize)), version)).readActionList();
ret.actionBytes=readBytes(actionRecordSize);
//ret.actions = (new SWFInputStream(new ByteArrayInputStream(readBytes(actionRecordSize)), version)).readActionList();
return ret;
}
@@ -1154,7 +1156,7 @@ public class SWFInputStream extends InputStream {
public BUTTONCONDACTION readBUTTONCONDACTION() throws IOException {
BUTTONCONDACTION ret = new BUTTONCONDACTION();
int condActionSize = readUI16();
ret.isLast = condActionSize == 0;
ret.isLast = condActionSize <= 0;
ret.condIdleToOverDown = readUB(1) == 1;
ret.condOutDownToIdle = readUB(1) == 1;
ret.condOutDownToOverDown = readUB(1) == 1;
@@ -1165,7 +1167,20 @@ public class SWFInputStream extends InputStream {
ret.condIdleToOverUp = readUB(1) == 1;
ret.condKeyPress = (int) readUB(7);
ret.condOverDownToIddle = readUB(1) == 1;
ret.actions = readActionList();
if(condActionSize<=0){
ret.actionBytes=readBytes(available());
}else{
ret.actionBytes=readBytes(condActionSize-4);
}
//ret.actions = readActionList();
return ret;
}
@Override
public int available() throws IOException {
return is.available();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -601,7 +601,8 @@ public class SWFOutputStream extends OutputStream {
if (value.eventFlags.clipEventKeyPress) {
sos.writeUI8(value.keyCode);
}
sos.write(Action.actionsToBytes(value.actions, true, version));
sos.write(value.actionBytes);
//sos.write(Action.actionsToBytes(value.actions, true, version));
sos.close();
byte data[] = baos.toByteArray();
writeUI32(data.length); //actionRecordSize
@@ -923,7 +924,8 @@ public class SWFOutputStream extends OutputStream {
sos.writeUB(1, value.condIdleToOverUp ? 1 : 0);
sos.writeUB(7, value.condKeyPress);
sos.writeUB(1, value.condOverDownToIddle ? 1 : 0);
sos.write(Action.actionsToBytes(value.actions, true, version));
sos.write(value.actionBytes);
//sos.write(Action.actionsToBytes(value.actions, true, version));
sos.close();
byte data[] = baos.toByteArray();
if (isLast) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -15,6 +15,7 @@
* 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.abc;
import com.jpexs.asdec.Main;
@@ -49,8 +50,7 @@ public class ABC {
public long stringOffsets[];
public static String IDENT_STRING = " ";
public ABC(InputStream is) throws IOException {
public ABC(InputStream is) throws IOException {
ABCInputStream ais = new ABCInputStream(is);
major_version = ais.readU16();
minor_version = ais.readU16();
@@ -83,7 +83,7 @@ public class ABC {
constants.constant_string[0] = "";
for (int i = 1; i < constant_string_pool_count; i++) { //index 0 not used. Values 1..n-1
long pos = ais.getPosition();
constants.constant_string[i] = ais.readString();
constants.constant_string[i] = ais.readString();
stringOffsets[i] = pos;
}
@@ -92,7 +92,7 @@ public class ABC {
constants.constant_namespace = new Namespace[constant_namespace_pool_count];
for (int i = 1; i < constant_namespace_pool_count; i++) { //index 0 not used. Values 1..n-1
constants.constant_namespace[i] = ais.readNamespace();
cleanOneName(constants.constant_namespace[i].name_index);
//cleanOneName(constants.constant_namespace[i].name_index);
}
//constant namespace set
@@ -110,10 +110,12 @@ public class ABC {
//constant multiname
int constant_multiname_pool_count = ais.readU30();
//System.out.println("Reading "+constant_multiname_pool_count+" multinames");
constants.constant_multiname = new Multiname[constant_multiname_pool_count];
for (int i = 1; i < constant_multiname_pool_count; i++) { //index 0 not used. Values 1..n-1
constants.constant_multiname[i] = ais.readMultiname();
cleanNamespace(constants.constant_multiname[i].name_index);
//System.out.println("Multiname read:"+constants.constant_multiname[i]);
//cleanNamespace(constants.constant_multiname[i].name_index);
}
@@ -146,7 +148,7 @@ public class ABC {
for (int i = 0; i < class_count; i++) {
instance_info[i] = ais.readInstanceInfo();
}
class_info = new ClassInfo[class_count];
class_info = new ClassInfo[class_count];
for (int i = 0; i < class_count; i++) {
class_info[i] = new ClassInfo();
class_info[i].cinit_index = ais.readU30();
@@ -195,7 +197,7 @@ public class ABC {
bodies[i].code.clearCode(constants, bodies[i]);
} catch (ConvertException ignored) {
} */
}
}
}
public void saveToStream(OutputStream os) throws IOException {
@@ -205,12 +207,7 @@ public class ABC {
aos.writeU30(constants.constant_int.length);
for (int i = 1; i < constants.constant_int.length; i++) {
try {
aos.writeS32(constants.constant_int[i]);
} catch (NotSameException nex) {
System.out.println("written:" + constants.constant_int[i]);
throw nex;
}
aos.writeS32(constants.constant_int[i]);
}
aos.writeU30(constants.constant_uint.length);
for (int i = 1; i < constants.constant_uint.length; i++) {
@@ -241,6 +238,7 @@ public class ABC {
}
aos.writeU30(constants.constant_multiname.length);
//System.out.println("Writing "+constants.constant_multiname.length+" multinames");
for (int i = 1; i < constants.constant_multiname.length; i++) {
aos.writeMultiname(constants.constant_multiname[i]);
}
@@ -459,6 +457,7 @@ public class ABC {
private String addTabs(String s, int tabs) {
String parts[] = s.split("\r\n");
if(!s.contains("\r\n")) parts = s.split("\n");
String ret = "";
for (int i = 0; i < parts.length; i++) {
for (int t = 0; t < tabs; t++) {
@@ -498,7 +497,7 @@ public class ABC {
}
}
public String classToString(int i, boolean highlight) {
public String classToString(int i, boolean highlight,boolean pcode) {
String ret = "";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
@@ -580,7 +579,7 @@ public class ABC {
String bodyStr = "";
int bodyIndex = findBodyIndex(instance_info[i].iinit_index);
if (bodyIndex != -1) {
bodyStr = addTabs(bodies[bodyIndex].toString(false, i, this, constants, method_info, highlight), 3);
bodyStr = addTabs(bodies[bodyIndex].toString(pcode,false, i, this, constants, method_info, highlight), 3);
}
String toPrint = IDENT_STRING + IDENT_STRING + modifier + "function " + constants.constant_multiname[instance_info[i].name_index].getName(constants) + "(" + constructorParams + ") {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}";
if (highlight) {
@@ -598,7 +597,7 @@ public class ABC {
String bodyStr = "";
int bodyIndex = findBodyIndex(tm.method_info);
if (bodyIndex != -1) {
bodyStr = addTabs(bodies[bodyIndex].toString(true, i, this, constants, method_info, highlight), 3);
bodyStr = addTabs(bodies[bodyIndex].toString(pcode,true, i, this, constants, method_info, highlight), 3);
}
toPrint = IDENT_STRING + IDENT_STRING + tm.convert(constants, method_info, true) + " {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}";
}
@@ -627,7 +626,7 @@ public class ABC {
String bodyStr = "";
int bodyIndex = findBodyIndex(tm.method_info);
if (bodyIndex != -1) {
bodyStr = addTabs(bodies[bodyIndex].toString(false, i, this, constants, method_info, highlight), 3);
bodyStr = addTabs(bodies[bodyIndex].toString(pcode,false, i, this, constants, method_info, highlight), 3);
}
toPrint = IDENT_STRING + IDENT_STRING + tm.convert(constants, method_info, false) + " {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}";
}
@@ -647,7 +646,7 @@ public class ABC {
return baos.toString();
}
public void export(String directory) throws IOException {
public void export(String directory,boolean pcode) throws IOException {
for (int i = 0; i < instance_info.length; i++) {
String packageName = instance_info[i].getName(constants).getNamespace(constants).getName(constants);
String className = instance_info[i].getName(constants).getName(constants);
@@ -658,7 +657,7 @@ public class ABC {
}
String fileName = outDir.toString() + File.separator + className + ".as";
FileOutputStream fos = new FileOutputStream(fileName);
fos.write(classToString(i, false).getBytes());
fos.write(classToString(i, false,pcode).getBytes());
fos.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -24,6 +24,8 @@ import com.jpexs.asdec.abc.types.traits.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class ABCInputStream extends InputStream {
@@ -31,6 +33,7 @@ public class ABCInputStream extends InputStream {
private InputStream is;
private long bytesRead = 0;
private ByteArrayOutputStream bufferOs = null;
public static boolean DEBUG_READ=false;
public void startBuffer() {
bufferOs = new ByteArrayOutputStream();
@@ -51,6 +54,10 @@ public class ABCInputStream extends InputStream {
public int read() throws IOException {
bytesRead++;
int i = is.read();
if(DEBUG_READ)
{
System.out.println("Read:0x"+Integer.toHexString(i));
}
if (bufferOs != null) {
if (i != -1)
bufferOs.write(i);
@@ -165,27 +172,48 @@ public class ABCInputStream extends InputStream {
}
public Multiname readMultiname() throws IOException {
int kind = read();
int kind = readU8();
int namespace_index = -1;
int name_index = -1;
int namespace_set_index = -1;
List<Integer> params=new ArrayList<Integer>();
if ((kind == 7) || (kind == 0xd)) { // CONSTANT_QName and CONSTANT_QNameA.
namespace_index = readU30();
name_index = readU30();
}
else
if ((kind == 0xf) || (kind == 0x10)) { //CONSTANT_RTQName and CONSTANT_RTQNameA
name_index = readU30();
}else
if((kind==0x11)||(kind==0x12))//kind==0x11,0x12 nothing CONSTANT_RTQNameL and CONSTANT_RTQNameLA.
{
}
else
if ((kind == 9) || (kind == 0xe)) { // CONSTANT_Multiname and CONSTANT_MultinameA.
name_index = readU30();
namespace_set_index = readU30();
}
if ((kind == 0xf) || (kind == 0x10)) { //CONSTANT_RTQName and CONSTANT_RTQNameA
name_index = readU30();
}
else
if ((kind == 0x1B) || (kind == 0x1C)) { //CONSTANT_MultinameL and CONSTANT_MultinameLA
namespace_set_index = readU30();
}
//kind==0x11,0x12 nothing CONSTANT_RTQNameL and CONSTANT_RTQNameLA.
return new Multiname(kind, name_index, namespace_index, namespace_set_index);
else if(kind==0x1D)
{
//Constant_TypeName
name_index=readU30();
int paramsLength=readU30();
for(int i=0;i<paramsLength;i++){
params.add(readU30());
}
}
else{
System.err.println("Unknown kind of Multiname:0x"+Integer.toHexString(kind));
System.exit(1);
}
return new Multiname(kind, name_index, namespace_index, namespace_set_index,params);
}
public MethodInfo readMethodInfo() throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -167,7 +167,7 @@ public class ABCOutputStream extends OutputStream {
}
public void writeMultiname(Multiname m) throws IOException {
write(m.kind);
writeU8(m.kind);
if ((m.kind == 7) || (m.kind == 0xd)) { // CONSTANT_QName and CONSTANT_QNameA.
writeU30(m.namespace_index);
writeU30(m.name_index);
@@ -182,6 +182,15 @@ public class ABCOutputStream extends OutputStream {
if ((m.kind == 0x1B) || (m.kind == 0x1C)) { //CONSTANT_MultinameL and CONSTANT_MultinameLA
writeU30(m.namespace_set_index);
}
if(m.kind==0x1D)
{
writeU30(m.name_index);
writeU30(m.params.size());
for(int i=0;i<m.params.size();i++)
{
writeU30(m.params.get(i));
}
}
//kind==0x11,0x12 nothing CONSTANT_RTQNameL and CONSTANT_RTQNameLA.
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,112 +1,112 @@
/*
* Copyright (C) 2010 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.abc;
import com.jpexs.asdec.abc.types.traits.Trait;
import com.jpexs.asdec.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
/**
*
* @author JPEXS
*/
public class Usage {
public int classIndex;
public int traitIndex;
public int subTraitIndex;
public boolean isStatic;
public static final int TYPE_CLASS_NAME=0;
public static final int TYPE_TRAIT_NAME=1;
public static final int TYPE_SUBTRAIT_NAME=4;
public static final int TYPE_INITIALIZER_SUBTRAIT_NAME=5;
public static final int TYPE_INITIALIZER=2;
public static final int TYPE_TRAIT_BODY=3;
public int type;
public ABC abc;
public int bodyIndex;
public Usage(ABC abc,int bodyIndex,int classIndex, int traitIndex, int subTraitIndex, boolean isStatic, int type) {
this.abc = abc;
this.classIndex = classIndex;
this.traitIndex = traitIndex;
this.isStatic = isStatic;
this.type = type;
this.subTraitIndex = subTraitIndex;
this.bodyIndex = bodyIndex;
}
@Override
public String toString() {
String ret="";
String className=abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants);
Trait tr=null;
String staticStr="";
String traitName="";
String subTraitName="";
switch(type){
case TYPE_CLASS_NAME:
return "Class "+className;
case TYPE_TRAIT_NAME:
if(isStatic){
tr=abc.class_info[classIndex].static_traits.traits[traitIndex];
}else{
tr=abc.instance_info[classIndex].instance_traits.traits[traitIndex];
}
traitName=tr.getMultiName(abc.constants).getName(abc.constants);
staticStr=isStatic?"static ":"";
String typeStr="";
if(tr instanceof TraitMethodGetterSetter) typeStr="method ";
if(tr instanceof TraitSlotConst) {
if(((TraitSlotConst)tr).isConst()) typeStr="const ";
if(((TraitSlotConst)tr).isVar()) typeStr="var ";
}
return staticStr+typeStr+className+"."+traitName;
case TYPE_INITIALIZER_SUBTRAIT_NAME:
case TYPE_INITIALIZER:
if(type==TYPE_SUBTRAIT_NAME){
subTraitName="."+abc.bodies[bodyIndex].traits.traits[subTraitIndex].getMultiName(abc.constants).getName(abc.constants);
}
if(isStatic){
return "static initializer "+className+subTraitName;
}else{
return "instance initializer "+className+subTraitName;
}
case TYPE_SUBTRAIT_NAME:
case TYPE_TRAIT_BODY:
if(isStatic){
tr=abc.class_info[classIndex].static_traits.traits[traitIndex];
}else{
tr=abc.instance_info[classIndex].instance_traits.traits[traitIndex];
}
traitName=tr.getMultiName(abc.constants).getName(abc.constants);
if(type==TYPE_SUBTRAIT_NAME){
subTraitName="."+abc.bodies[bodyIndex].traits.traits[subTraitIndex].getMultiName(abc.constants).getName(abc.constants);
}
staticStr=isStatic?"static ":"";
return staticStr+"method body "+className+"."+traitName+subTraitName;
}
return ret;
}
}
/*
* 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.abc;
import com.jpexs.asdec.abc.types.traits.Trait;
import com.jpexs.asdec.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
/**
*
* @author JPEXS
*/
public class Usage {
public int classIndex;
public int traitIndex;
public int subTraitIndex;
public boolean isStatic;
public static final int TYPE_CLASS_NAME=0;
public static final int TYPE_TRAIT_NAME=1;
public static final int TYPE_SUBTRAIT_NAME=4;
public static final int TYPE_INITIALIZER_SUBTRAIT_NAME=5;
public static final int TYPE_INITIALIZER=2;
public static final int TYPE_TRAIT_BODY=3;
public int type;
public ABC abc;
public int bodyIndex;
public Usage(ABC abc,int bodyIndex,int classIndex, int traitIndex, int subTraitIndex, boolean isStatic, int type) {
this.abc = abc;
this.classIndex = classIndex;
this.traitIndex = traitIndex;
this.isStatic = isStatic;
this.type = type;
this.subTraitIndex = subTraitIndex;
this.bodyIndex = bodyIndex;
}
@Override
public String toString() {
String ret="";
String className=abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants);
Trait tr=null;
String staticStr="";
String traitName="";
String subTraitName="";
switch(type){
case TYPE_CLASS_NAME:
return "Class "+className;
case TYPE_TRAIT_NAME:
if(isStatic){
tr=abc.class_info[classIndex].static_traits.traits[traitIndex];
}else{
tr=abc.instance_info[classIndex].instance_traits.traits[traitIndex];
}
traitName=tr.getMultiName(abc.constants).getName(abc.constants);
staticStr=isStatic?"static ":"";
String typeStr="";
if(tr instanceof TraitMethodGetterSetter) typeStr="method ";
if(tr instanceof TraitSlotConst) {
if(((TraitSlotConst)tr).isConst()) typeStr="const ";
if(((TraitSlotConst)tr).isVar()) typeStr="var ";
}
return staticStr+typeStr+className+"."+traitName;
case TYPE_INITIALIZER_SUBTRAIT_NAME:
case TYPE_INITIALIZER:
if(type==TYPE_SUBTRAIT_NAME){
subTraitName="."+abc.bodies[bodyIndex].traits.traits[subTraitIndex].getMultiName(abc.constants).getName(abc.constants);
}
if(isStatic){
return "static initializer "+className+subTraitName;
}else{
return "instance initializer "+className+subTraitName;
}
case TYPE_SUBTRAIT_NAME:
case TYPE_TRAIT_BODY:
if(isStatic){
tr=abc.class_info[classIndex].static_traits.traits[traitIndex];
}else{
tr=abc.instance_info[classIndex].instance_traits.traits[traitIndex];
}
traitName=tr.getMultiName(abc.constants).getName(abc.constants);
if(type==TYPE_SUBTRAIT_NAME){
subTraitName="."+abc.bodies[bodyIndex].traits.traits[subTraitIndex].getMultiName(abc.constants).getName(abc.constants);
}
staticStr=isStatic?"static ":"";
return staticStr+"method body "+className+"."+traitName+subTraitName;
}
return ret;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -20,6 +20,7 @@ package com.jpexs.asdec.abc.avm2;
import com.jpexs.asdec.abc.ABC;
import com.jpexs.asdec.abc.ABCInputStream;
import com.jpexs.asdec.abc.CopyOutputStream;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.IfTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
@@ -61,6 +62,7 @@ import java.util.regex.Pattern;
public class AVM2Code {
public List<AVM2Instruction> code = new LinkedList<AVM2Instruction>();
public static boolean DEBUG_REWRITE=false;
public static final int OPT_U30 = 0x100;
public static final int OPT_U8 = 0x200;
public static final int OPT_S24 = 0x300;
@@ -85,25 +87,37 @@ public class AVM2Code {
public static final int DAT_CASE_BASEOFFSET = OPT_S24 + 0x11;
public static InstructionDefinition instructionSet[] = new InstructionDefinition[]{
new AddIns(),
new InstructionDefinition(0x9b,"add_d",new int[]{}),
new AddIIns(),
new InstructionDefinition(0x53,"applytype",new int[]{AVM2Code.OPT_U30}),
new AsTypeIns(),
new AsTypeLateIns(),
new BitAndIns(),
new BitNotIns(),
new BitOrIns(),
new BitXorIns(),
new InstructionDefinition(0x01,"bkpt",new int[]{}),
new InstructionDefinition(0xf2,"bkptline",new int[]{AVM2Code.OPT_U30}),
new CallIns(),
new InstructionDefinition(0x4d,"callinterface",new int[]{AVM2Code.OPT_U30}),
new CallMethodIns(),
new CallPropertyIns(),
new CallPropLexIns(),
new CallPropVoidIns(),
new CallStaticIns(),
new CallSuperIns(),
new InstructionDefinition(0x4b,"callsuperid",new int[]{}),
new CallSuperVoidIns(),
new CheckFilterIns(),
new CoerceIns(),
new CoerceAIns(),
new InstructionDefinition(0x81,"coerce_b",new int[]{}),
new InstructionDefinition(0x84,"coerce_d",new int[]{}),
new InstructionDefinition(0x83,"coerce_i",new int[]{}),
new InstructionDefinition(0x89,"coerce_o",new int[]{}),
new CoerceSIns(),
new InstructionDefinition(0x88,"coerce_u",new int[]{}),
new InstructionDefinition(0x9a,"concat",new int[]{}),
new ConstructIns(),
new ConstructPropIns(),
new ConstructSuperIns(),
@@ -121,6 +135,7 @@ public class AVM2Code {
new DecrementIns(),
new DecrementIIns(),
new DeletePropertyIns(),
new InstructionDefinition(0x6b,"deletepropertylate",new int[]{}),
new DivideIns(),
new DupIns(),
new DXNSIns(),
@@ -128,6 +143,9 @@ public class AVM2Code {
new EqualsIns(),
new EscXAttrIns(),
new EscXElemIns(),
new InstructionDefinition(0x5f,"finddef",new int[]{AVM2Code.DAT_MULTINAME_INDEX}),
new InstructionDefinition(0x5b,"findpropglobalstrict",new int[]{AVM2Code.DAT_MULTINAME_INDEX}),
new InstructionDefinition(0x5c,"findpropglobal",new int[]{AVM2Code.DAT_MULTINAME_INDEX}),
new FindPropertyIns(),
new FindPropertyStrictIns(),
new GetDescendantsIns(),
@@ -139,6 +157,7 @@ public class AVM2Code {
new GetLocal1Ins(),
new GetLocal2Ins(),
new GetLocal3Ins(),
new InstructionDefinition(0x67,"getouterscope",new int[]{AVM2Code.DAT_MULTINAME_INDEX}),
new GetPropertyIns(),
new GetScopeObjectIns(),
new GetSlotIns(),
@@ -195,6 +214,7 @@ public class AVM2Code {
new PopIns(),
new PopScopeIns(),
new PushByteIns(),
new InstructionDefinition(0x22,"pushconstant",new int[]{AVM2Code.DAT_STRING_INDEX}),
new PushDoubleIns(),
new PushFalseIns(),
new PushIntIns(),
@@ -218,6 +238,7 @@ public class AVM2Code {
new SetLocal3Ins(),
new SetGlobalSlotIns(),
new SetPropertyIns(),
new InstructionDefinition(0x69,"setpropertylate",new int[]{}),
new SetSlotIns(),
new SetSuperIns(),
new StrictEqualsIns(),
@@ -226,7 +247,22 @@ public class AVM2Code {
new SwapIns(),
new ThrowIns(),
new TypeOfIns(),
new URShiftIns()};
new URShiftIns(),
new InstructionDefinition(0x35,"li8",new int[]{}),
new InstructionDefinition(0x36,"li16",new int[]{}),
new InstructionDefinition(0x37,"li32",new int[]{}),
new InstructionDefinition(0x38,"lf32",new int[]{}),
new InstructionDefinition(0x39,"lf64",new int[]{}),
new InstructionDefinition(0x3A,"si8",new int[]{}),
new InstructionDefinition(0x3B,"si16",new int[]{}),
new InstructionDefinition(0x3C,"si32",new int[]{}),
new InstructionDefinition(0x3D,"sf32",new int[]{}),
new InstructionDefinition(0x3E,"sf64",new int[]{}),
new InstructionDefinition(0x50,"sxi1",new int[]{}),
new InstructionDefinition(0x51,"sxi8",new int[]{}),
new InstructionDefinition(0x52,"sxi16",new int[]{})
};
//endoflist
public static final String IDENTOPEN = "/*IDENTOPEN*/";
public static final String IDENTCLOSE = "/*IDENTCLOSE*/";
@@ -245,6 +281,50 @@ public class AVM2Code {
public AVM2Code() {
}
public Object execute(HashMap arguments,ConstantPool constants){
int pos=0;
LocalDataArea lda=new LocalDataArea();
lda.localRegisters=arguments;
try{
while(true){
AVM2Instruction ins=code.get(pos);
if(ins.definition instanceof JumpIns){
pos=adr2pos((Long)ins.getParamsAsList(constants).get(0));
continue;
}
if(ins.definition instanceof IfFalseIns){
Boolean b=(Boolean)lda.operandStack.pop();
if(b==false){
pos=adr2pos((Long)ins.getParamsAsList(constants).get(0));
}else{
pos++;
}
continue;
}
if(ins.definition instanceof IfTrueIns){
Boolean b=(Boolean)lda.operandStack.pop();
if(b==true){
pos=adr2pos((Long)ins.getParamsAsList(constants).get(0));
}else{
pos++;
}
continue;
}
if(ins.definition instanceof ReturnValueIns){
return lda.operandStack.pop();
}
if(ins.definition instanceof ReturnVoidIns){
return null;
}
ins.definition.execute(lda, constants, ins.getParamsAsList(constants));
pos++;
}
}catch(ConvertException e){
}
return null;
}
public AVM2Code(InputStream is) throws IOException {
ABCInputStream ais = new ABCInputStream(is);
while (ais.available() > 0) {
@@ -297,10 +377,22 @@ public class AVM2Code {
}
public byte[] getBytes() {
return getBytes(null);
}
public byte[] getBytes(byte origBytes[]) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStream cos;
if((origBytes!=null)&&(DEBUG_REWRITE))
{
ByteArrayInputStream origis=new ByteArrayInputStream(origBytes);
cos=new CopyOutputStream(bos,origis);
}else{
cos=bos;
}
try {
for (AVM2Instruction instruction : code) {
bos.write(instruction.getBytes());
cos.write(instruction.getBytes());
}
} catch (IOException ex) {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -18,14 +18,13 @@
package com.jpexs.asdec.abc.avm2;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Stack;
public class LocalDataArea {
public Stack operandStack = new Stack();
public Stack scopeStack = new Stack();
public List localRegisters = new ArrayList<Object>();
public HashMap localRegisters = new HashMap<Integer,Object>();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -23,7 +23,7 @@ public class UnknownInstructionCode extends RuntimeException {
public int code;
public UnknownInstructionCode(int code) {
super("Unknown instruction code:" + Integer.toHexString(code));
super("Unknown instruction code: 0x" + Integer.toHexString(code));
this.code = code;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,358 +1,223 @@
/*
* Copyright (C) 2010 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.abc.avm2.flowgraph;
import com.jpexs.asdec.abc.avm2.AVM2Code;
import com.jpexs.asdec.abc.avm2.ConvertException;
import com.jpexs.asdec.abc.avm2.instructions.IfTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.jumps.IfFalseIns;
import com.jpexs.asdec.abc.avm2.instructions.jumps.IfTrueIns;
import com.jpexs.asdec.abc.avm2.instructions.jumps.JumpIns;
import com.jpexs.asdec.abc.avm2.instructions.localregs.GetLocalTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.localregs.SetLocalTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.other.ReturnValueIns;
import com.jpexs.asdec.abc.avm2.instructions.other.ReturnVoidIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.DupIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.PopIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.PushFalseIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.PushTrueIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.SwapIns;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class Graph {
public List<GraphPart> parts;
public List<Integer> ignored = new ArrayList<Integer>();
private int trueReg = -1;
private int falseReg = -1;
public Graph(AVM2Code code) {
parts = new ArrayList<GraphPart>();
int start = checkSWFSecureStart(code);
makeGraph(new Stack<Boolean>(),code, start, parts, new ArrayList<GraphBlock>());
do {
} while (optimizeDecisions(parts) > 0);
}
private int checkSWFSecureStart(AVM2Code code) {
if (code.code.size() < 2) {
return 0;
}
if (!((code.code.get(0).definition instanceof PushFalseIns) || (code.code.get(0).definition instanceof PushTrueIns))) {
return 0;
}
if (!((code.code.get(1).definition instanceof PushFalseIns) || (code.code.get(1).definition instanceof PushTrueIns))) {
return 0;
}
System.out.println("A");
int pos = 2;
Stack<Boolean> myStack = new Stack<Boolean>();
int ip = 0;
int setCount = 0;
while (ip < code.code.size()) {
if (code.code.get(ip).definition instanceof PushFalseIns) {
myStack.push(Boolean.FALSE);
} else if (code.code.get(ip).definition instanceof PushTrueIns) {
myStack.push(Boolean.TRUE);
} else if (code.code.get(ip).definition instanceof SwapIns) {
Boolean b1 = myStack.pop();
Boolean b2 = myStack.pop();
myStack.push(b1);
myStack.push(b2);
} else if (code.code.get(ip).definition instanceof JumpIns) {
try {
ip = code.adr2pos(code.pos2adr(ip + 1) + code.code.get(ip).operands[0]);
} catch (ConvertException ex) {
Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex);
}
continue;
} else if (code.code.get(ip).definition instanceof SetLocalTypeIns) {
Boolean val = myStack.pop();
if (val == true) {
trueReg = ((SetLocalTypeIns) code.code.get(ip).definition).getRegisterId(code.code.get(ip));
} else {
falseReg = ((SetLocalTypeIns) code.code.get(ip).definition).getRegisterId(code.code.get(ip));
}
setCount++;
if (setCount == 2) {
return ip + 1;
}
}
ip++;
}
return 0;
}
private int optimizeDecisions(List<GraphPart> parts) {
for (int p = 0; p < parts.size(); p++) {
GraphPart part = parts.get(p);
if (part instanceof GraphDecision) {
/**
* if
* onTrue: nop
* nop
* link A
* onFalse: nop
* A
* B
*
* ==>
*
* if onTrue: nop
* nop
* onFalse: nop
* A
* B
*/
if (((GraphDecision) part).onTrue.size() > 0) {
GraphPart lastTruePart = ((GraphDecision) part).onTrue.get(((GraphDecision) part).onTrue.size() - 1);
if (lastTruePart instanceof GraphLink) {
for (int f = 0; f < ((GraphDecision) part).onFalse.size(); f++) {
if (((GraphDecision) part).onFalse.get(f).start == ((GraphLink) lastTruePart).ip) {
((GraphDecision) part).onFalse.get(f).linkCount--;
((GraphDecision) part).onTrue.remove(((GraphDecision) part).onTrue.size() - 1);
for (int k = f; k < ((GraphDecision) part).onFalse.size(); k++) {
parts.add(p + 1, ((GraphDecision) part).onFalse.remove(k));
}
return optimizeDecisions(parts) + 1;
}
}
}
}
/**
* if
* onTrue: nop
* nop
* A
* B
* onFalse: nop
* link A
*
* ==>
*
* if onTrue: nop
* nop
* onFalse: nop
* A
* B
*/
if (((GraphDecision) part).onFalse.size() > 0) {
GraphPart lastFalsePart = ((GraphDecision) part).onFalse.get(((GraphDecision) part).onFalse.size() - 1);
if (lastFalsePart instanceof GraphLink) {
for (int t = 0; t < ((GraphDecision) part).onTrue.size(); t++) {
if (((GraphDecision) part).onTrue.get(t).start == ((GraphLink) lastFalsePart).ip) {
((GraphDecision) part).onTrue.get(t).linkCount--;
((GraphDecision) part).onFalse.remove(((GraphDecision) part).onFalse.size() - 1);
for (int k = t; k < ((GraphDecision) part).onTrue.size(); k++) {
parts.add(p + 1, ((GraphDecision) part).onTrue.remove(k));
}
return optimizeDecisions(parts) + 1;
}
}
}
}
/*
* if
* onTrue: nop
* link A
* onFalse: nop
* link A
*
* ==>
* if
* onTrue: nop
* onFalse: nop
* link A
*
*/
if ((((GraphDecision) part).onTrue.size() > 0)&&(((GraphDecision) part).onFalse.size() > 0)) {
GraphPart lastFalsePart = ((GraphDecision) part).onFalse.get(((GraphDecision) part).onFalse.size() - 1);
GraphPart lastTruePart = ((GraphDecision) part).onTrue.get(((GraphDecision) part).onTrue.size() - 1);
if((lastFalsePart instanceof GraphLink)&&(lastTruePart instanceof GraphLink)){
if(((GraphLink)lastFalsePart).ip==((GraphLink)lastTruePart).ip){
((GraphDecision) part).onFalse.remove(((GraphDecision) part).onFalse.size()-1);
((GraphDecision) part).onTrue.remove(((GraphDecision) part).onTrue.size()-1);
parts.add(p+1,lastTruePart);
return optimizeDecisions(parts) + 1;
}
}
}
}
}
int optcount = 0;
for (int p = 0; p < parts.size(); p++) {
GraphPart part = parts.get(p);
if (part instanceof GraphDecision) {
optcount += optimizeDecisions(((GraphDecision) part).onTrue);
optcount += optimizeDecisions(((GraphDecision) part).onFalse);
}
}
return optcount;
}
private GraphBlock splitBlock(GraphBlock block, int ip, List<GraphBlock> allBlocks) {
return processSplit(block, parts, ip, allBlocks);
}
private GraphBlock processSplit(GraphBlock block, List<GraphPart> parts, int ip, List<GraphBlock> allBlocks) {
for (int i = 0; i < parts.size(); i++) {
if (parts.get(i) == block) {
parts.remove(i);
GraphBlock gr1 = new GraphBlock(block.start, ip - 1);
parts.add(i, gr1);
gr1.linkCount=block.linkCount;
GraphBlock gr2 = new GraphBlock(ip, block.end);
parts.add(i + 1, gr2);
allBlocks.remove(block);
allBlocks.add(gr1);
allBlocks.add(gr2);
return (GraphBlock) parts.get(i + 1);
} else if (parts.get(i) instanceof GraphDecision) {
GraphBlock gr = processSplit(block, ((GraphDecision) parts.get(i)).onTrue, ip, allBlocks);
if (gr != null) {
return gr;
}
gr = processSplit(block, ((GraphDecision) parts.get(i)).onFalse, ip, allBlocks);
if (gr != null) {
return gr;
}
}
}
return null;
}
private void makeGraph(Stack<Boolean> myStack,AVM2Code code, int start, List<GraphPart> parts, List<GraphBlock> allBlocks) {
try {
int ip = start;
while (ip < code.code.size()) {
for (GraphBlock block : allBlocks) {
if (block.contains(ip)) {
if (block.start < ip) {
block = splitBlock(block, ip, allBlocks);
}
if (ip - 1 >= start) {
GraphBlock bl = new GraphBlock(start, ip - 1);
parts.add(bl);
allBlocks.add(bl);
}
parts.add(new GraphLink(block));
return;
}
}
boolean forceJump = false;
boolean forceSkip = false;
if (code.code.get(ip).definition instanceof IfTrueIns) {
if (!myStack.empty()) {
if (myStack.pop() == true) {
forceJump = true;
} else {
forceSkip = true;
}
}
}
if (code.code.get(ip).definition instanceof IfFalseIns) {
if (!myStack.empty()) {
if (myStack.pop() == false) {
forceJump = true;
} else {
forceSkip = true;
}
}
}
if (code.code.get(ip).definition instanceof GetLocalTypeIns) {
int locreg = ((GetLocalTypeIns) code.code.get(ip).definition).getRegisterId(code.code.get(ip));
if (locreg == trueReg) {
myStack.push(Boolean.TRUE);
ignored.add(ip);
}
if (locreg == falseReg) {
myStack.push(Boolean.FALSE);
ignored.add(ip);
}
} else if (code.code.get(ip).definition instanceof PopIns) {
if (!myStack.empty()) {
myStack.pop();
ignored.add(ip);
}
} else if (code.code.get(ip).definition instanceof SwapIns) {
if (myStack.size() >= 2) {
Boolean b1 = myStack.pop();
Boolean b2 = myStack.pop();
myStack.push(b1);
myStack.push(b2);
ignored.add(ip);
}
} else if (code.code.get(ip).definition instanceof DupIns) {
if (!myStack.empty()) {
Boolean b = myStack.pop();
myStack.push(b);
myStack.push(b);
ignored.add(ip);
}
} else if ((code.code.get(ip).definition instanceof JumpIns) || forceJump) {
if (ip - 1 >= start) {
GraphBlock bl = new GraphBlock(start, ip - 1);
parts.add(bl);
allBlocks.add(bl);
}
int jumpIp = code.adr2pos(code.pos2adr(ip + 1) + code.code.get(ip).operands[0]);
makeGraph(myStack,code, jumpIp, parts, allBlocks);
return;
} else if (code.code.get(ip).definition instanceof IfTypeIns) {
if (forceSkip) {
ip++;
continue;
}
if (ip - 1 >= start) {
GraphBlock bl = new GraphBlock(start, ip - 1);
parts.add(bl);
allBlocks.add(bl);
}
int jumpIp = code.adr2pos(code.pos2adr(ip + 1) + code.code.get(ip).operands[0]);
GraphDecision dec = new GraphDecision();
parts.add(dec);
dec.start = ip;
makeGraph(myStack,code, jumpIp, dec.onTrue, allBlocks);
makeGraph(myStack,code, ip + 1, dec.onFalse, allBlocks);
return;
} else if ((code.code.get(ip).definition instanceof ReturnValueIns) || (code.code.get(ip).definition instanceof ReturnVoidIns)) {
ip++;
break;
}
ip++;
}
GraphFinalBlock bl = new GraphFinalBlock(start, ip - 1);
parts.add(bl);
allBlocks.add(bl);
} catch (ConvertException ex) {
Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/*
* 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.abc.avm2.flowgraph;
import com.jpexs.asdec.abc.avm2.AVM2Code;
import com.jpexs.asdec.abc.avm2.ConvertException;
import com.jpexs.asdec.abc.avm2.instructions.IfTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.jumps.IfFalseIns;
import com.jpexs.asdec.abc.avm2.instructions.jumps.IfTrueIns;
import com.jpexs.asdec.abc.avm2.instructions.jumps.JumpIns;
import com.jpexs.asdec.abc.avm2.instructions.localregs.GetLocalTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.localregs.SetLocalTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.other.ReturnValueIns;
import com.jpexs.asdec.abc.avm2.instructions.other.ReturnVoidIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.DupIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.PopIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.PushFalseIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.PushTrueIns;
import com.jpexs.asdec.abc.avm2.instructions.stack.SwapIns;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class Graph {
public GraphPart head;
public List<Integer> ignored = new ArrayList<Integer>();
private int trueReg = -1;
private int falseReg = -1;
public Graph(AVM2Code code) {
int start = checkSWFSecureStart(code);
head=makeGraph(new Stack<Boolean>(), code, start, new ArrayList<GraphPart>());
}
private int checkSWFSecureStart(AVM2Code code) {
if (code.code.size() < 2) {
return 0;
}
if (!((code.code.get(0).definition instanceof PushFalseIns) || (code.code.get(0).definition instanceof PushTrueIns))) {
return 0;
}
if (!((code.code.get(1).definition instanceof PushFalseIns) || (code.code.get(1).definition instanceof PushTrueIns))) {
return 0;
}
int pos = 2;
Stack<Boolean> myStack = new Stack<Boolean>();
int ip = 0;
int setCount = 0;
while (ip < code.code.size()) {
if (code.code.get(ip).definition instanceof PushFalseIns) {
myStack.push(Boolean.FALSE);
} else if (code.code.get(ip).definition instanceof PushTrueIns) {
myStack.push(Boolean.TRUE);
} else if (code.code.get(ip).definition instanceof SwapIns) {
Boolean b1 = myStack.pop();
Boolean b2 = myStack.pop();
myStack.push(b1);
myStack.push(b2);
} else if (code.code.get(ip).definition instanceof JumpIns) {
try {
ip = code.adr2pos(code.pos2adr(ip + 1) + code.code.get(ip).operands[0]);
} catch (ConvertException ex) {
Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex);
}
continue;
} else if (code.code.get(ip).definition instanceof SetLocalTypeIns) {
Boolean val = myStack.pop();
if (val == true) {
trueReg = ((SetLocalTypeIns) code.code.get(ip).definition).getRegisterId(code.code.get(ip));
} else {
falseReg = ((SetLocalTypeIns) code.code.get(ip).definition).getRegisterId(code.code.get(ip));
}
setCount++;
if (setCount == 2) {
return ip + 1;
}
}
ip++;
}
return 0;
}
private GraphPart makeGraph(Stack<Boolean> myStack,AVM2Code code, int start, List<GraphPart> allBlocks) {
GraphPart ret=new GraphPart(start,-1);
ret.instanceCount=1;
allBlocks.add(ret);
GraphPart actual=ret;
try {
int ip = start;
while (ip < code.code.size()) {
for (GraphPart block : allBlocks) {
if (block.containsIP(ip)) {
if(block.start<ip){
int oldEnd=block.end;
block.end=ip-1;
GraphPart newBlock=new GraphPart(ip,oldEnd);
newBlock.nextParts.addAll(block.nextParts);
newBlock.instanceCount=1;
block.nextParts.clear();
block.nextParts.add(newBlock);
allBlocks.add(newBlock);
block=newBlock;
}
block.instanceCount++;
if(start<ip){
actual.end=ip-1;
actual.nextParts.add(block);
return ret;
}else{
return block;
}
}
}
boolean forceJump = false;
boolean forceSkip = false;
if (code.code.get(ip).definition instanceof IfTrueIns) {
if (!myStack.empty()) {
if (myStack.pop() == true) {
forceJump = true;
} else {
forceSkip = true;
}
}
}
if (code.code.get(ip).definition instanceof IfFalseIns) {
if (!myStack.empty()) {
if (myStack.pop() == false) {
forceJump = true;
} else {
forceSkip = true;
}
}
}
if (code.code.get(ip).definition instanceof GetLocalTypeIns) {
int locreg = ((GetLocalTypeIns) code.code.get(ip).definition).getRegisterId(code.code.get(ip));
if (locreg == trueReg) {
myStack.push(Boolean.TRUE);
ignored.add(ip);
}
if (locreg == falseReg) {
myStack.push(Boolean.FALSE);
ignored.add(ip);
}
} else if (code.code.get(ip).definition instanceof PopIns) {
if (!myStack.empty()) {
myStack.pop();
ignored.add(ip);
}
} else if (code.code.get(ip).definition instanceof SwapIns) {
if (myStack.size() >= 2) {
Boolean b1 = myStack.pop();
Boolean b2 = myStack.pop();
myStack.push(b1);
myStack.push(b2);
ignored.add(ip);
}
} else if (code.code.get(ip).definition instanceof DupIns) {
if (!myStack.empty()) {
Boolean b = myStack.pop();
myStack.push(b);
myStack.push(b);
ignored.add(ip);
}
} else if ((code.code.get(ip).definition instanceof JumpIns) || forceJump) {
int jumpIp = code.adr2pos(code.pos2adr(ip + 1) + code.code.get(ip).operands[0]);
actual.end=ip;
GraphPart newActual=makeGraph(myStack,code,jumpIp,allBlocks);
actual.nextParts.add(newActual);
return ret;
} else if (code.code.get(ip).definition instanceof IfTypeIns) {
if (forceSkip) {
ip++;
continue;
}
actual.end=ip;
int jumpIp = code.adr2pos(code.pos2adr(ip + 1) + code.code.get(ip).operands[0]);
GraphPart onTrue=makeGraph(myStack,code, jumpIp, allBlocks);
actual.nextParts.add(onTrue);
GraphPart onFalse=makeGraph(myStack,code, ip + 1, allBlocks);
actual.nextParts.add(onFalse);
return ret;
} else if ((code.code.get(ip).definition instanceof ReturnValueIns) || (code.code.get(ip).definition instanceof ReturnVoidIns)) {
ip++;
break;
}
ip++;
}
actual.end=ip-1;
return ret;
} catch (ConvertException ex) {
Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright (C) 2010 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.abc.avm2.flowgraph;
/**
*
* @author JPEXS
*/
public class GraphBlock extends GraphPart {
public int end;
public GraphBlock(int start, int end) {
this.start = start;
this.end = end;
}
public boolean contains(int ip){
return ip>=start && ip<=end;
}
@Override
public String toString() {
return "Block "+(start+1)+"-"+(end+1)+(linkCount>0?" ("+linkCount+" links)":"");
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2010 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.abc.avm2.flowgraph;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class GraphDecision extends GraphPart {
public List<GraphPart> onTrue=new ArrayList<GraphPart>();
public List<GraphPart> onFalse=new ArrayList<GraphPart>();
@Override
public String toString() {
return "Decision "+(start+1);
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright (C) 2010 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.abc.avm2.flowgraph;
/**
*
* @author JPEXS
*/
public class GraphFinalBlock extends GraphBlock {
public GraphFinalBlock(int start,int end) {
super(start,end);
}
@Override
public String toString() {
return "Final"+super.toString();
}
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright (C) 2010 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.abc.avm2.flowgraph;
/**
*
* @author JPEXS
*/
public class GraphLink extends GraphPart {
public int ip=0;
public GraphLink(GraphPart linked) {
ip=linked.start;
linked.linkCount++;
}
@Override
public String toString() {
return "Link to "+(ip+1);
}
}

View File

@@ -1,28 +1,72 @@
/*
* Copyright (C) 2010 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.abc.avm2.flowgraph;
/**
*
* @author JPEXS
*/
public class GraphPart {
public int start=0;
public int linkCount=0;
}
/*
* 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.abc.avm2.flowgraph;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class GraphPart {
public int start=0;
public int end=0;
public int instanceCount=0;
public List<GraphPart> nextParts=new ArrayList<GraphPart>();
public int posX=-1;
public int posY=-1;
public GraphPart(int start,int end) {
this.start=start;
this.end=end;
}
@Override
public String toString() {
if(end<start){
return "<->";
}
return ""+(start+1)+"-"+(end+1)+(instanceCount>1?"("+instanceCount+" links)":"");
}
public boolean containsIP(int ip){
return (ip>=start)&&(ip<=end);
}
private boolean containsPart(GraphPart part,GraphPart what,List<GraphPart> used){
if(used.contains(part)) return false;
used.add(part);
for(GraphPart subpart:part.nextParts){
if(subpart==what) return true;
if(containsPart(subpart,what,used)) return true;
}
return false;
}
public boolean containsPart(GraphPart what){
return containsPart(this,what,new ArrayList<GraphPart>());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -111,6 +111,45 @@ public class AVM2Instruction {
return ret;
}
public List getParamsAsList(ConstantPool constants){
List s = new ArrayList();
for (int i = 0; i < definition.operands.length; i++) {
switch (definition.operands[i]) {
case AVM2Code.DAT_MULTINAME_INDEX:
s.add(constants.constant_multiname[operands[i]]);
break;
case AVM2Code.DAT_STRING_INDEX:
s.add(constants.constant_string[operands[i]]);
break;
case AVM2Code.DAT_INT_INDEX:
s.add(new Long(constants.constant_int[operands[i]]));
break;
case AVM2Code.DAT_UINT_INDEX:
s.add(new Long(constants.constant_uint[operands[i]]));
break;
case AVM2Code.DAT_DOUBLE_INDEX:
s.add(new Double(constants.constant_double[operands[i]]));
break;
case AVM2Code.DAT_OFFSET:
s.add(new Long(offset + operands[i] + getBytes().length));
break;
case AVM2Code.DAT_CASE_BASEOFFSET:
s.add(new Long(offset + operands[i]));
break;
case AVM2Code.OPT_CASE_OFFSETS:
s.add(new Long(operands[i]));
for (int j = i + 1; j < operands.length; j++) {
s.add(new Long(offset + operands[j]));
}
break;
default:
s.add(new Long(operands[i]));
}
}
return s;
}
public String getParams(ConstantPool constants) {
String s = "";
for (int i = 0; i < definition.operands.length; i++) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -76,6 +76,7 @@ public class InstructionDefinition {
}
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
throw new UnsupportedOperationException("Instruction "+instructionName+" not implemented");
}
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -38,8 +38,8 @@ public class DivideIns extends InstructionDefinition {
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
Object o1 = lda.operandStack.pop();
Object o2 = lda.operandStack.pop();
Object o1 = lda.operandStack.pop();
if ((o1 instanceof Long) && ((o2 instanceof Long))) {
Long ret = new Long(((Long) o1).longValue() / ((Long) o2).longValue());
lda.operandStack.push(ret);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -19,6 +19,7 @@
package com.jpexs.asdec.abc.avm2.instructions.arithmetic;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
@@ -35,6 +36,19 @@ public class ModuloIns extends InstructionDefinition {
super(0xa4, "modulo", new int[]{});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
Object o1 = lda.operandStack.pop();
Object o2 = lda.operandStack.pop();
if ((o1 instanceof Long) && ((o2 instanceof Long))) {
Long ret = new Long(((Long) o2).longValue() % ((Long) o1).longValue());
lda.operandStack.push(ret);
} else {
throw new RuntimeException("Cannot modulo");
}
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
TreeItem v2 = (TreeItem) stack.pop();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -19,6 +19,7 @@
package com.jpexs.asdec.abc.avm2.instructions.arithmetic;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
@@ -35,6 +36,27 @@ public class MultiplyIns extends InstructionDefinition {
super(0xa2, "multiply", new int[]{});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
Object o1 = lda.operandStack.pop();
Object o2 = lda.operandStack.pop();
if ((o1 instanceof Long) && ((o2 instanceof Long))) {
Long ret = new Long(((Long) o1).longValue() * ((Long) o2).longValue());
lda.operandStack.push(ret);
} else if ((o1 instanceof Double) && ((o2 instanceof Double))) {
Double ret = new Double(((Double) o1).doubleValue() * ((Double) o2).doubleValue());
lda.operandStack.push(ret);
} else if ((o1 instanceof Long) && ((o2 instanceof Double))) {
Double ret = new Double(((Long) o1).longValue() * ((Double) o2).doubleValue());
lda.operandStack.push(ret);
} else if ((o1 instanceof Double) && ((o2 instanceof Long))) {
Double ret = new Double(((Double) o1).doubleValue() * ((Long) o2).longValue());
lda.operandStack.push(ret);
} else {
throw new RuntimeException("Cannot multiply");
}
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
TreeItem v2 = (TreeItem) stack.pop();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -43,7 +43,7 @@ public class NewFunctionIns extends InstructionDefinition {
MethodBody mybody = abc.findBody(methodIndex);
String bodyStr = "";
if (mybody != null) {
bodyStr = mybody.toString(isStatic, classIndex, abc, constants, method_info, false);
bodyStr = mybody.toString(false,isStatic, classIndex, abc, constants, method_info, false);
}
stack.push(new NewFunctionTreeItem(ins, method_info[methodIndex].getParamStr(constants), method_info[methodIndex].getReturnTypeStr(constants), bodyStr));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -43,14 +43,14 @@ public class DecLocalIIns extends InstructionDefinition {
Object obj = lda.localRegisters.get(locRegIndex);
if (obj instanceof Long) {
Long obj2 = ((Long) obj).longValue() - 1;
lda.localRegisters.set(locRegIndex, obj2);
lda.localRegisters.put(locRegIndex, obj2);
} else if (obj instanceof Double) {
Double obj2 = ((Double) obj).doubleValue() - 1;
lda.localRegisters.set(locRegIndex, obj2);
lda.localRegisters.put(locRegIndex, obj2);
}
if (obj instanceof String) {
Double obj2 = Double.parseDouble((String) obj) - 1;
lda.localRegisters.set(locRegIndex, obj2);
lda.localRegisters.put(locRegIndex, obj2);
} else {
throw new RuntimeException("Cannot decrement local register");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -43,14 +43,14 @@ public class DecLocalIns extends InstructionDefinition {
Object obj = lda.localRegisters.get(locRegIndex);
if (obj instanceof Long) {
Long obj2 = ((Long) obj).longValue() - 1;
lda.localRegisters.set(locRegIndex, obj2);
lda.localRegisters.put(locRegIndex, obj2);
} else if (obj instanceof Double) {
Double obj2 = ((Double) obj).doubleValue() - 1;
lda.localRegisters.set(locRegIndex, obj2);
lda.localRegisters.put(locRegIndex, obj2);
}
if (obj instanceof String) {
Double obj2 = Double.parseDouble((String) obj) - 1;
lda.localRegisters.set(locRegIndex, obj2);
lda.localRegisters.put(locRegIndex, obj2);
} else {
throw new RuntimeException("Cannot decrement local register");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -19,6 +19,7 @@
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.ClassTreeItem;
@@ -36,6 +37,11 @@ public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeI
super(0xd0, "getlocal_0", new int[]{});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
lda.operandStack.push(lda.localRegisters.get(0));
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
if (isStatic) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -19,6 +19,7 @@
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
@@ -35,6 +36,11 @@ public class GetLocal1Ins extends InstructionDefinition implements GetLocalTypeI
super(0xd1, "getlocal_1", new int[]{});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
lda.operandStack.push(lda.localRegisters.get(1));
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
stack.push(new LocalRegTreeItem(ins, 1, localRegs.get(1)));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -19,6 +19,7 @@
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
@@ -35,6 +36,11 @@ public class GetLocal2Ins extends InstructionDefinition implements GetLocalTypeI
super(0xd2, "getlocal_2", new int[]{});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
lda.operandStack.push(lda.localRegisters.get(2));
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
stack.push(new LocalRegTreeItem(ins, 2, localRegs.get(2)));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -19,6 +19,7 @@
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
@@ -35,6 +36,13 @@ public class GetLocal3Ins extends InstructionDefinition implements GetLocalTypeI
super(0xd3, "getlocal_3", new int[]{});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
lda.operandStack.push(lda.localRegisters.get(3));
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
stack.push(new LocalRegTreeItem(ins, 3, localRegs.get(3)));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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
@@ -20,6 +20,7 @@ package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.avm2.AVM2Code;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.LocalDataArea;
import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
@@ -36,6 +37,13 @@ public class GetLocalIns extends InstructionDefinition implements GetLocalTypeIn
super(0x62, "getlocal", new int[]{AVM2Code.DAT_LOCAL_REG_INDEX});
}
@Override
public void execute(LocalDataArea lda, ConstantPool constants, List arguments) {
lda.operandStack.push(lda.localRegisters.get((int)(long)(Long)arguments.get(0)));
}
@Override
public void translate(boolean isStatic, int classIndex, java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, java.util.Stack<TreeItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<TreeItem> output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc) {
int regIndex = ins.operands[0];

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 JPEXS
* 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

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