ASDec: Formatting code, organize imports

This commit is contained in:
Jindra Pet��k
2012-12-28 09:53:30 +01:00
parent 07c6cfcfca
commit 1223dd8aad
36 changed files with 149 additions and 248 deletions
+2 -1
View File
@@ -21,5 +21,6 @@ package com.jpexs.asdec;
* @author Jindra
*/
public interface EventListener {
public void handleEvent(String event,Object data);
public void handleEvent(String event, Object data);
}
-8
View File
@@ -18,19 +18,13 @@ package com.jpexs.asdec;
import com.jpexs.asdec.abc.NotSameException;
import com.jpexs.asdec.abc.avm2.AVM2Code;
import com.jpexs.asdec.action.TagNode;
import com.jpexs.asdec.gui.AboutDialog;
import com.jpexs.asdec.gui.LoadingDialog;
import com.jpexs.asdec.gui.ModeFrame;
import com.jpexs.asdec.gui.View;
import com.jpexs.asdec.gui.proxy.ProxyFrame;
import com.jpexs.asdec.helpers.Highlighting;
import com.jpexs.asdec.tags.ASMSource;
import com.jpexs.asdec.tags.DefineSpriteTag;
import com.jpexs.asdec.tags.DoABCTag;
import com.jpexs.asdec.tags.DoInitActionTag;
import com.jpexs.asdec.tags.Tag;
import com.jpexs.asdec.tags.TagName;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -41,8 +35,6 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFileChooser;
+13 -16
View File
@@ -283,18 +283,15 @@ public class SWF {
}
return true;
}
public boolean exportActionScript(String outdir, boolean isPcode) throws Exception {
boolean asV3Found = false;
final EventListener evl=new EventListener(){
public boolean exportActionScript(String outdir, boolean isPcode) throws Exception {
boolean asV3Found = false;
final EventListener evl = new EventListener() {
public void handleEvent(String event, Object data) {
if(event.equals("export")){
if (event.equals("export")) {
informListeners(event, data);
}
}
};
for (Tag t : tags) {
if (t instanceof DoABCTag) {
@@ -334,7 +331,7 @@ public class SWF {
if (node.subItems.isEmpty()) {
if (node.tag instanceof ASMSource) {
try {
String f = outdir + File.separatorChar + name + ".as";
String f = outdir + File.separatorChar + name + ".as";
informListeners("export", "Exporting " + f + " ...");
String ret = "";
if (isPcode) {
@@ -359,18 +356,18 @@ public class SWF {
}
return true;
}
protected HashSet<EventListener> listeners=new HashSet<EventListener>();
public void addEventListener(EventListener listener){
protected HashSet<EventListener> listeners = new HashSet<EventListener>();
public void addEventListener(EventListener listener) {
listeners.add(listener);
}
public void removeEventListener(EventListener listener){
public void removeEventListener(EventListener listener) {
listeners.remove(listener);
}
protected void informListeners(String event,Object data){
for(EventListener listener:listeners){
protected void informListeners(String event, Object data) {
for (EventListener listener : listeners) {
listener.handleEvent(event, data);
}
}
+15 -17
View File
@@ -17,7 +17,6 @@
package com.jpexs.asdec.abc;
import com.jpexs.asdec.EventListener;
import com.jpexs.asdec.Main;
import com.jpexs.asdec.abc.avm2.AVM2Code;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.UnknownInstructionCode;
@@ -57,23 +56,22 @@ public class ABC {
public static String IDENT_STRING = " ";
public static final int MINORwithDECIMAL = 17;
public static final boolean AUTOINIT_STATIC_VARIABLES = false;
protected HashSet<EventListener> listeners = new HashSet<EventListener>();
protected HashSet<EventListener> listeners=new HashSet<EventListener>();
public void addEventListener(EventListener listener){
public void addEventListener(EventListener listener) {
listeners.add(listener);
}
public void removeEventListener(EventListener listener){
public void removeEventListener(EventListener listener) {
listeners.remove(listener);
}
protected void informListeners(String event,Object data){
for(EventListener listener:listeners){
protected void informListeners(String event, Object data) {
for (EventListener listener : listeners) {
listener.handleEvent(event, data);
}
}
public int deobfuscateIdentifiers() {
int ret = 0;
for (int i = 1; i < constants.constant_multiname.length; i++) {
@@ -251,11 +249,11 @@ public class ABC {
method_info[mb.method_info].setBody(mb);
bodyIdxFromMethodIdx[mb.method_info] = i;
}
/*for(ScriptInfo si:script_info){
System.out.println("--------------------------------------------");
System.out.println(findBody(si.init_index).toString(true, false, -1, this, constants, method_info,new Stack<TreeItem>()));
}*/
System.out.println("--------------------------------------------");
System.out.println(findBody(si.init_index).toString(true, false, -1, this, constants, method_info,new Stack<TreeItem>()));
}*/
}
public void saveToStream(OutputStream os) throws IOException {
@@ -632,7 +630,7 @@ public class ABC {
String bodyStr = "";
int bodyIndex = findBodyIndex(class_info[i].cinit_index);
if (bodyIndex != -1) {
bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack<TreeItem>(),highlight), 3);
bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack<TreeItem>(), highlight), 3);
}
// if (!bodyStr.equals("")) {
toPrint = IDENT_STRING + IDENT_STRING + "{\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}";
@@ -661,7 +659,7 @@ public class ABC {
bodyStr = "";
bodyIndex = findBodyIndex(instance_info[i].iinit_index);
if (bodyIndex != -1) {
bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack<TreeItem>(),highlight), 3);
bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack<TreeItem>(), highlight), 3);
constructorParams = method_info[instance_info[i].iinit_index].getParamStr(constants, bodies[bodyIndex], this);
} else {
constructorParams = method_info[instance_info[i].iinit_index].getParamStr(constants, null, this);
@@ -739,7 +737,7 @@ public class ABC {
if ((packageName != null) && (!packageName.equals(""))) {
fullName = packageName + "." + fullName;
}
informListeners("export", "Exporting " + (i + 1) + "/" + instance_info.length + " " + fullName + " ...");
informListeners("export", "Exporting " + (i + 1) + "/" + instance_info.length + " " + fullName + " ...");
File outDir = new File(directory + File.separatorChar + packageName.replace('.', File.separatorChar));
if (!outDir.exists()) {
outDir.mkdirs();
@@ -22,7 +22,6 @@ 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;
import com.jpexs.asdec.abc.avm2.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.instructions.arithmetic.*;
import com.jpexs.asdec.abc.avm2.instructions.bitwise.*;
import com.jpexs.asdec.abc.avm2.instructions.comparsion.*;
@@ -41,8 +40,6 @@ import com.jpexs.asdec.abc.avm2.treemodel.*;
import com.jpexs.asdec.abc.avm2.treemodel.clauses.*;
import com.jpexs.asdec.abc.avm2.treemodel.operations.AndTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.operations.OrTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.operations.PreDecrementTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.operations.PreIncrementTreeItem;
import com.jpexs.asdec.abc.types.ABCException;
import com.jpexs.asdec.abc.types.MethodBody;
import com.jpexs.asdec.abc.types.MethodInfo;
@@ -1491,12 +1488,12 @@ public class AVM2Code {
}
}
}
if(!isKilled(reg, ip, end)){
if (!isKilled(reg, ip, end)) {
TreeItem v = (TreeItem) stack.pop();
stack.push(new LocalRegTreeItem(ins, reg,v));
stack.push(new LocalRegTreeItem(ins, reg, v));
stack.push(v);
}else{
ins.definition.translate(isStatic, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames);
} else {
ins.definition.translate(isStatic, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames);
}
ip++;
addr = pos2adr(ip);
@@ -43,7 +43,7 @@ public class NewFunctionIns extends InstructionDefinition {
String bodyStr = "";
String paramStr = "";
if (mybody != null) {
bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info,scopeStack, true) + Highlighting.hilighMethodBegin(body.method_info);
bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info, scopeStack, true) + Highlighting.hilighMethodBegin(body.method_info);
paramStr = method_info[methodIndex].getParamStr(constants, mybody, abc);
}
stack.push(new NewFunctionTreeItem(ins, paramStr, method_info[methodIndex].getReturnTypeStr(constants), bodyStr));
@@ -16,27 +16,14 @@
*/
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.ABC;
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.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.FindPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
import com.jpexs.asdec.abc.types.MethodInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public class SetLocal0Ins extends SetLocalTypeIns {
public SetLocal0Ins() {
super(0xd4, "setlocal_0", new int[]{});
}
public int getRegisterId(AVM2Instruction ins) {
return 0;
}
@@ -16,20 +16,7 @@
*/
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.ABC;
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.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.FindPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
import com.jpexs.asdec.abc.types.MethodInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public class SetLocal1Ins extends SetLocalTypeIns {
@@ -40,5 +27,4 @@ public class SetLocal1Ins extends SetLocalTypeIns {
public int getRegisterId(AVM2Instruction ins) {
return 1;
}
}
@@ -16,20 +16,7 @@
*/
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.ABC;
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.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.FindPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
import com.jpexs.asdec.abc.types.MethodInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public class SetLocal2Ins extends SetLocalTypeIns {
@@ -16,20 +16,7 @@
*/
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.ABC;
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.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.FindPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
import com.jpexs.asdec.abc.types.MethodInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public class SetLocal3Ins extends SetLocalTypeIns {
@@ -16,21 +16,8 @@
*/
package com.jpexs.asdec.abc.avm2.instructions.localregs;
import com.jpexs.asdec.abc.ABC;
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.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.FindPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.SetLocalTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
import com.jpexs.asdec.abc.types.MethodInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public class SetLocalIns extends SetLocalTypeIns {
@@ -23,7 +23,6 @@ import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.asdec.abc.avm2.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.DecrementTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.FindPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.GetPropertyTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.IncrementTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
@@ -55,7 +54,7 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
if (value instanceof FindPropertyTreeItem) {
return;
}
if (value.getNotCoerced() instanceof IncrementTreeItem) {
if (value.getNotCoerced() instanceof IncrementTreeItem) {
TreeItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getNotCoerced();
if (inside instanceof LocalRegTreeItem) {
if (((LocalRegTreeItem) inside).regIndex == regId) {
@@ -78,7 +77,7 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
}
}
if (value.getNotCoerced() instanceof DecrementTreeItem) {
if (value.getNotCoerced() instanceof DecrementTreeItem) {
TreeItem inside = ((DecrementTreeItem) value.getNotCoerced()).object.getNotCoerced();
if (inside instanceof LocalRegTreeItem) {
if (((LocalRegTreeItem) inside).regIndex == regId) {
@@ -100,7 +99,7 @@ public abstract class SetLocalTypeIns extends InstructionDefinition implements S
}
}
}
//if(val.startsWith("catchscope ")) return;
//if(val.startsWith("newactivation()")) return;
output.add(new SetLocalTreeItem(ins, regId, value));
@@ -21,7 +21,6 @@ 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;
import com.jpexs.asdec.abc.avm2.treemodel.TreeItem;
import com.jpexs.asdec.abc.types.MethodInfo;
import java.util.HashMap;
@@ -46,11 +46,11 @@ public class GetSlotIns extends InstructionDefinition {
Multiname slotname = null;
if (obj instanceof ExceptionTreeItem) {
slotname = constants.constant_multiname[((ExceptionTreeItem) obj).exception.name_index];
} else if(obj instanceof ClassTreeItem){
slotname=((ClassTreeItem)obj).className;
} else if(obj instanceof ThisTreeItem){
slotname=((ThisTreeItem)obj).className;
}else{
} else if (obj instanceof ClassTreeItem) {
slotname = ((ClassTreeItem) obj).className;
} else if (obj instanceof ThisTreeItem) {
slotname = ((ThisTreeItem) obj).className;
} else {
for (int t = 0; t < body.traits.traits.length; t++) {
if (body.traits.traits[t] instanceof TraitSlotConst) {
if (((TraitSlotConst) body.traits.traits[t]).slot_id == slotIndex) {
@@ -25,7 +25,6 @@ import com.jpexs.asdec.abc.avm2.instructions.SetTypeIns;
import com.jpexs.asdec.abc.avm2.treemodel.DecrementTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.GetSlotTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.IncrementTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.LocalRegTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.NewActivationTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.PostDecrementTreeItem;
import com.jpexs.asdec.abc.avm2.treemodel.PostIncrementTreeItem;
@@ -73,14 +72,13 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
return;
}
}
if (value.getNotCoerced() instanceof IncrementTreeItem) {
if (value.getNotCoerced() instanceof IncrementTreeItem) {
TreeItem inside = ((IncrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced();
if (inside instanceof GetSlotTreeItem) {
GetSlotTreeItem slotItem=(GetSlotTreeItem)inside;
if ((slotItem.scope.getThroughRegister()==obj.getThroughRegister())
&&(slotItem.slotName==slotname))
{
GetSlotTreeItem slotItem = (GetSlotTreeItem) inside;
if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
&& (slotItem.slotName == slotname)) {
if (stack.size() > 0) {
TreeItem top = stack.peek().getNotCoerced();
if (top == inside) {
@@ -99,14 +97,13 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
}
}
}
if (value.getNotCoerced() instanceof DecrementTreeItem) {
if (value.getNotCoerced() instanceof DecrementTreeItem) {
TreeItem inside = ((DecrementTreeItem) value.getNotCoerced()).object.getThroughRegister().getNotCoerced();
if (inside instanceof GetSlotTreeItem) {
GetSlotTreeItem slotItem=(GetSlotTreeItem)inside;
if ((slotItem.scope.getThroughRegister()==obj.getThroughRegister())
&&(slotItem.slotName==slotname))
{
GetSlotTreeItem slotItem = (GetSlotTreeItem) inside;
if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
&& (slotItem.slotName == slotname)) {
if (stack.size() > 0) {
TreeItem top = stack.peek().getNotCoerced();
if (top == inside) {
@@ -125,7 +122,7 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
}
}
}
output.add(new SetSlotTreeItem(ins, obj, slotname, value));
}
@@ -43,7 +43,7 @@ public class DupIns extends InstructionDefinition {
@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, HashMap<Integer, String> localRegNames) {
TreeItem v = (TreeItem) stack.pop();
stack.push(v);
stack.push(v);
stack.push(v);
}
@@ -44,12 +44,12 @@ public class CallTreeItem extends TreeItem {
args = args + arguments.get(a).toString(constants, localRegNames);
}
/*String recPart = ""; receiver.toString(constants, localRegNames) + hilight(".");
if (receiver instanceof NewActivationTreeItem) {
recPart = "";
}
if (receiver instanceof ThisTreeItem) {
recPart = "";
}*/
if (receiver instanceof NewActivationTreeItem) {
recPart = "";
}
if (receiver instanceof ThisTreeItem) {
recPart = "";
}*/
return function.toString(constants, localRegNames) + hilight("(") + args + hilight(")");
}
}
@@ -36,7 +36,7 @@ public class ConvertTreeItem extends TreeItem {
//return hilight("("+type+")")+
return value.toString(constants, localRegNames);
}
@Override
public TreeItem getNotCoerced() {
return value;
@@ -24,8 +24,8 @@ public class FullMultinameTreeItem extends TreeItem {
public int multinameIndex;
public TreeItem name;
public TreeItem namespace;
public TreeItem namespace;
public FullMultinameTreeItem(AVM2Instruction instruction, int multinameIndex, TreeItem name) {
super(instruction, PRECEDENCE_PRIMARY);
this.multinameIndex = multinameIndex;
@@ -69,35 +69,34 @@ public class FullMultinameTreeItem extends TreeItem {
}
return ret;
}
public boolean compareSame(FullMultinameTreeItem other)
{
if(multinameIndex!=other.multinameIndex){
public boolean compareSame(FullMultinameTreeItem other) {
if (multinameIndex != other.multinameIndex) {
return false;
}
TreeItem tiName=name;
while(tiName instanceof LocalRegTreeItem){
tiName=((LocalRegTreeItem)tiName).computedValue;
TreeItem tiName = name;
while (tiName instanceof LocalRegTreeItem) {
tiName = ((LocalRegTreeItem) tiName).computedValue;
}
TreeItem tiName2=other.name;
while(tiName2 instanceof LocalRegTreeItem){
tiName2=((LocalRegTreeItem)tiName2).computedValue;
TreeItem tiName2 = other.name;
while (tiName2 instanceof LocalRegTreeItem) {
tiName2 = ((LocalRegTreeItem) tiName2).computedValue;
}
if(tiName!=tiName2){
if (tiName != tiName2) {
return false;
}
TreeItem tiNameSpace=namespace;
while(tiNameSpace instanceof LocalRegTreeItem){
tiNameSpace=((LocalRegTreeItem)tiNameSpace).computedValue;
TreeItem tiNameSpace = namespace;
while (tiNameSpace instanceof LocalRegTreeItem) {
tiNameSpace = ((LocalRegTreeItem) tiNameSpace).computedValue;
}
TreeItem tiNameSpace2=other.namespace;
while(tiNameSpace2 instanceof LocalRegTreeItem){
tiNameSpace2=((LocalRegTreeItem)tiNameSpace2).computedValue;
TreeItem tiNameSpace2 = other.namespace;
while (tiNameSpace2 instanceof LocalRegTreeItem) {
tiNameSpace2 = ((LocalRegTreeItem) tiNameSpace2).computedValue;
}
if(tiNameSpace!=tiNameSpace2){
if (tiNameSpace != tiNameSpace2) {
return false;
}
return true;
@@ -53,6 +53,4 @@ public class LocalRegTreeItem extends TreeItem {
public TreeItem getThroughRegister() {
return computedValue.getThroughRegister();
}
}
@@ -23,9 +23,10 @@ import java.util.HashMap;
public class ThisTreeItem extends TreeItem {
public Multiname className;
public ThisTreeItem(Multiname className) {
super(null, PRECEDENCE_PRIMARY);
this.className=className;
this.className = className;
}
@Override
@@ -42,16 +42,16 @@ public abstract class TreeItem {
public static final int NOPRECEDENCE = 16;
public int precedence = NOPRECEDENCE;
public AVM2Instruction instruction;
public TreeItem(AVM2Instruction instruction, int precedence) {
this.instruction = instruction;
this.precedence = precedence;
}
public abstract String toString(ConstantPool constants, HashMap<Integer, String> localRegNames);
public String toStringNoH(ConstantPool constants, HashMap<Integer, String> localRegNames){
return Highlighting.stripHilights(toString(constants,localRegNames));
public String toStringNoH(ConstantPool constants, HashMap<Integer, String> localRegNames) {
return Highlighting.stripHilights(toString(constants, localRegNames));
}
public String toStringSemicoloned(ConstantPool constants, HashMap<Integer, String> localRegNames) {
@@ -108,7 +108,7 @@ public abstract class TreeItem {
public TreeItem getNotCoerced() {
return this;
}
public TreeItem getThroughRegister() {
return this;
}
@@ -35,36 +35,35 @@ public class DeclarationTreeItem extends TreeItem {
public TreeItem assignment;
public String type;
public DeclarationTreeItem(TreeItem assignment,String type){
super(assignment.instruction,assignment.precedence);
this.type=type;
this.assignment=assignment;
public DeclarationTreeItem(TreeItem assignment, String type) {
super(assignment.instruction, assignment.precedence);
this.type = type;
this.assignment = assignment;
}
public DeclarationTreeItem(TreeItem assignment){
this(assignment,null);
public DeclarationTreeItem(TreeItem assignment) {
this(assignment, null);
}
@Override
public String toString(ConstantPool constants, HashMap<Integer, String> localRegNames) {
if(assignment instanceof SetLocalTreeItem)
{
SetLocalTreeItem lti=(SetLocalTreeItem)assignment;
String type="*";
if(lti.value instanceof CoerceTreeItem){
type = ((CoerceTreeItem)lti.value).type;
if (assignment instanceof SetLocalTreeItem) {
SetLocalTreeItem lti = (SetLocalTreeItem) assignment;
String type = "*";
if (lti.value instanceof CoerceTreeItem) {
type = ((CoerceTreeItem) lti.value).type;
}
if(lti.value instanceof ConvertTreeItem){
type = ((ConvertTreeItem)lti.value).type;
if (lti.value instanceof ConvertTreeItem) {
type = ((ConvertTreeItem) lti.value).type;
}
return "var "+hilight(localRegName(localRegNames, lti.regIndex) + ":"+type+" = ") + lti.value.toString(constants, localRegNames);
return "var " + hilight(localRegName(localRegNames, lti.regIndex) + ":" + type + " = ") + lti.value.toString(constants, localRegNames);
}
if(assignment instanceof SetSlotTreeItem)
{
SetSlotTreeItem ssti=(SetSlotTreeItem)assignment;
String ret="";
if (assignment instanceof SetSlotTreeItem) {
SetSlotTreeItem ssti = (SetSlotTreeItem) assignment;
String ret = "";
if (!(ssti.scope instanceof NewActivationTreeItem)) {
ret = ssti.scope.toString(constants, localRegNames) + ".";
ret = ssti.scope.toString(constants, localRegNames) + ".";
}
if (ssti.scope instanceof LocalRegTreeItem) {
if (((LocalRegTreeItem) ssti.scope).computedValue != null) {
@@ -72,10 +71,9 @@ public class DeclarationTreeItem extends TreeItem {
ret = "";
}
}
}
return "var "+ret + hilight(ssti.slotName.getName(constants)) + ":"+type+hilight(" = ") + ssti.value.toString(constants, localRegNames);
}
return "var " + ret + hilight(ssti.slotName.getName(constants)) + ":" + type + hilight(" = ") + ssti.value.toString(constants, localRegNames);
}
return "var "+assignment.toString(constants, localRegNames);
return "var " + assignment.toString(constants, localRegNames);
}
}
@@ -56,7 +56,7 @@ public class ForInTreeItem extends LoopTreeItem implements Block {
public String toString(ConstantPool constants, HashMap<Integer, String> localRegNames) {
String ret = "";
ret += "loop" + loopBreak + ":\r\n";
ret += hilight("for (") + expression.toString(constants, localRegNames) + hilight(")")+"\r\n{\r\n";
ret += hilight("for (") + expression.toString(constants, localRegNames) + hilight(")") + "\r\n{\r\n";
for (TreeItem ti : commands) {
ret += ti.toStringSemicoloned(constants, localRegNames) + "\r\n";
}
@@ -40,7 +40,7 @@ public class IfTreeItem extends TreeItem implements Block {
@Override
public String toString(ConstantPool constants, HashMap<Integer, String> localRegNames) {
String ret = "";
ret = hilight("if(") + expression.toString(constants, localRegNames) + hilight(")")+"\r\n{\r\n";
ret = hilight("if(") + expression.toString(constants, localRegNames) + hilight(")") + "\r\n{\r\n";
for (TreeItem ti : onTrue) {
ret += ti.toStringSemicoloned(constants, localRegNames) + "\r\n";
}
@@ -19,7 +19,6 @@ package com.jpexs.asdec.abc.gui;
import com.jpexs.asdec.Configuration;
import com.jpexs.asdec.Main;
import com.jpexs.asdec.abc.ABC;
import com.jpexs.asdec.EventListener;
import com.jpexs.asdec.abc.gui.tablemodels.*;
import com.jpexs.asdec.gui.LoadingPanel;
import com.jpexs.asdec.gui.View;
@@ -314,7 +313,7 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
JMenuItem miAbout = new JMenuItem("About...");
miAbout.setActionCommand("ABOUT");
miAbout.addActionListener(this);
JMenuItem miCheckUpdates = new JMenuItem("Check for updates...");
miCheckUpdates.setActionCommand("CHECKUPDATES");
miCheckUpdates.addActionListener(this);
@@ -418,8 +417,8 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
(new Thread() {
@Override
public void run() {
try {
Main.swf.exportActionScript(selFile, isPcode);
try {
Main.swf.exportActionScript(selFile, isPcode);
} catch (Exception ignored) {
JOptionPane.showMessageDialog(null, "Cannot write to the file");
}
@@ -430,9 +429,9 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener {
}
}
if (e.getActionCommand().equals("CHECKUPDATES")) {
if(!Main.checkForUpdates()){
if (!Main.checkForUpdates()) {
JOptionPane.showMessageDialog(null, "No new version available.");
}
}
@@ -74,7 +74,7 @@ public class MethodBody implements Cloneable {
}
public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack<TreeItem> scopeStack) {
return toString(pcode, isStatic, classIndex, abc, constants, method_info, scopeStack,false);
return toString(pcode, isStatic, classIndex, abc, constants, method_info, scopeStack, false);
}
public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack<TreeItem> scopeStack, boolean hilight) {
@@ -86,7 +86,7 @@ public class MethodBody implements Cloneable {
s += code.toASMSource(constants, this);
} else {
try {
s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc),scopeStack);
s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc), scopeStack);
s = s.trim();
if (hilight) {
s = Highlighting.hilighMethod(s, this.method_info);
@@ -42,16 +42,16 @@ public class TraitSlotConst extends Trait {
return "0x" + Helper.formatAddress(fileOffset) + " " + Helper.byteArrToString(bytes) + " SlotConst " + abc.constants.constant_multiname[name_index].toString(abc.constants) + " slot=" + slot_id + " type=" + typeStr + " value=" + (new ValueKind(value_index, value_kind)).toString(abc.constants) + " metadata=" + Helper.intArrToString(metadata);
}
public String getType(ConstantPool constants){
public String getType(ConstantPool constants) {
String typeStr = "*";
if (type_index > 0) {
typeStr = constants.constant_multiname[type_index].getName(constants);
}
return typeStr;
}
public String getNameValueStr(ConstantPool constants) {
String typeStr = getType(constants);
String valueStr = "";
if (value_kind != 0) {
+6 -6
View File
@@ -578,12 +578,12 @@ public class Action {
* @return String with Source code
*/
public static String actionsToSource(List<Action> actions, int version) {
try{
List<TreeItem> tree = actionsToTree(new HashMap<Integer, String>(), actions, version);
return treeToString(tree);
}catch(Exception ex){
return "//Decompilation error :"+ex.getLocalizedMessage();
try {
List<TreeItem> tree = actionsToTree(new HashMap<Integer, String>(), actions, version);
return treeToString(tree);
} catch (Exception ex) {
return "//Decompilation error :" + ex.getLocalizedMessage();
}
}
@@ -41,7 +41,7 @@ public class TagNode {
public String toString() {
return tag.toString();
}
public static List<TagNode> createTagList(List<Object> list) {
List<TagNode> ret = new ArrayList<TagNode>();
int frame = 1;
@@ -17,15 +17,14 @@
package com.jpexs.asdec.action.gui;
import com.jpexs.asdec.Configuration;
import com.jpexs.asdec.action.TagNode;
import com.jpexs.asdec.Main;
import com.jpexs.asdec.action.TagNode;
import com.jpexs.asdec.action.parser.ASMParser;
import com.jpexs.asdec.action.parser.ParseException;
import com.jpexs.asdec.gui.LoadingPanel;
import com.jpexs.asdec.gui.View;
import com.jpexs.asdec.helpers.Highlighting;
import com.jpexs.asdec.tags.ASMSource;
import com.jpexs.asdec.tags.DoABCTag;
import com.jpexs.asdec.tags.Tag;
import java.awt.BorderLayout;
import java.awt.Container;
@@ -39,7 +38,6 @@ import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.border.BevelBorder;
@@ -313,13 +311,13 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi
if (e.getActionCommand().equals("OPEN")) {
Main.openFileDialog();
}
if (e.getActionCommand().equals("CHECKUPDATES")) {
if(!Main.checkForUpdates()){
if (!Main.checkForUpdates()) {
JOptionPane.showMessageDialog(null, "No new version available.");
}
}
if (e.getActionCommand().equals("EXPORT") || e.getActionCommand().equals("EXPORTPCODE")) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File((String) Configuration.getConfig("lastExportDir", ".")));
@@ -35,7 +35,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class DefineButton2Tag extends Tag implements Container,TagName {
public class DefineButton2Tag extends Tag implements Container, TagName {
/**
* ID for this character
@@ -166,9 +166,9 @@ public class DefineButton2Tag extends Tag implements Container,TagName {
}
public String getName() {
return "DefineButton2Tag"+buttonId;
return "DefineButton2Tag" + buttonId;
}
public String toString() {
String name = "";
for (ExportAssetsTag eat : exportAssetsTags) {
@@ -34,7 +34,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class DefineButtonTag extends Tag implements ASMSource,TagName {
public class DefineButtonTag extends Tag implements ASMSource, TagName {
/**
* ID for this character
@@ -99,11 +99,9 @@ public class DefineButtonTag extends Tag implements ASMSource,TagName {
}
public String getName() {
return "DefineButtonTag"+buttonId;
return "DefineButtonTag" + buttonId;
}
public String toString() {
String name = "";
for (ExportAssetsTag eat : exportAssetsTags) {
@@ -30,7 +30,7 @@ import java.util.List;
/**
* Defines a sprite character
*/
public class DefineSpriteTag extends Tag implements Container,TagName {
public class DefineSpriteTag extends Tag implements Container, TagName {
/**
* Character ID of sprite
@@ -96,11 +96,9 @@ public class DefineSpriteTag extends Tag implements Container,TagName {
@Override
public String getName() {
return "DefineSpriteTag"+spriteId;
return "DefineSpriteTag" + spriteId;
}
public String toString() {
String name = "";
for (ExportAssetsTag eat : exportAssetsTags) {
@@ -25,7 +25,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class DoInitActionTag extends Tag implements ASMSource,TagName {
public class DoInitActionTag extends Tag implements ASMSource, TagName {
/**
* Identifier of Sprite
@@ -76,7 +76,6 @@ public class DoInitActionTag extends Tag implements ASMSource,TagName {
return baos.toByteArray();
}
public String toString() {
String name = "";
for (ExportAssetsTag eat : exportAssetsTags) {
@@ -88,11 +87,9 @@ public class DoInitActionTag extends Tag implements ASMSource,TagName {
}
public String getName() {
return "DoInitActionTag"+spriteId;
return "DoInitActionTag" + spriteId;
}
/**
* Whether or not this object contains ASM source
*
@@ -21,5 +21,6 @@ package com.jpexs.asdec.tags;
* @author JPEXS
*/
public interface TagName {
public String getName();
}