diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 6d99694df..5613e3a20 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash; import SevenZip.Compression.LZMA.Encoder; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.RenameType; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.action.Action; @@ -28,7 +29,6 @@ import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ActionSetVariable; import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; -import com.jpexs.decompiler.flash.action.swf4.Null; import com.jpexs.decompiler.flash.action.swf5.ActionCallFunction; import com.jpexs.decompiler.flash.action.swf5.ActionCallMethod; import com.jpexs.decompiler.flash.action.swf5.ActionConstantPool; @@ -48,6 +48,7 @@ import com.jpexs.decompiler.flash.action.treemodel.GetMemberTreeItem; import com.jpexs.decompiler.flash.action.treemodel.GetVariableTreeItem; import com.jpexs.decompiler.flash.action.treemodel.clauses.ClassTreeItem; import com.jpexs.decompiler.flash.action.treemodel.clauses.InterfaceTreeItem; +import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.flv.AUDIODATA; import com.jpexs.decompiler.flash.flv.FLVOutputStream; import com.jpexs.decompiler.flash.flv.FLVTAG; @@ -113,6 +114,13 @@ import java.util.Locale; import java.util.Map; import java.util.Random; import java.util.Stack; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -492,6 +500,123 @@ public class SWF { return false; } + private List> uniqueAS3Packs(List> packs) { + List> ret = new ArrayList<>(); + for (KeyValue item : packs) { + System.err.println(item.key); + for (KeyValue itemOld : ret) { + if (item.key.equals(itemOld.key)) { + Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Duplicate pack path found!"); + break; + } + } + ret.add(item); + } + return ret; + } + + public List> getAS3Packs() { + List abcTags = new ArrayList<>(); + for (Tag t : tags) { + if (t instanceof ABCContainerTag) { + abcTags.add((ABCContainerTag) t); + } + } + List> packs = new ArrayList<>(); + for (int i = 0; i < abcTags.size(); i++) { + ABCContainerTag t = abcTags.get(i); + packs.addAll(t.getABC().getScriptPacks()); + } + return uniqueAS3Packs(packs); + } + + private class ExportPackTask implements Callable { + + ScriptPack pack; + String directory; + List abcList; + boolean pcode; + String informStr; + ClassPath path; + AtomicInteger index; + int count; + boolean paralel; + + public ExportPackTask(AtomicInteger index, int count, ClassPath path, ScriptPack pack, String directory, List abcList, boolean pcode, String informStr, boolean paralel) { + this.pack = pack; + this.directory = directory; + this.abcList = abcList; + this.pcode = pcode; + this.informStr = informStr; + this.path = path; + this.index = index; + this.count = count; + this.paralel = paralel; + } + + @Override + public File call() throws Exception { + try { + return pack.export(directory, abcList, pcode, paralel); + } catch (IOException ex) { + Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, ex); + } + synchronized (ABC.class) { + informListeners("export", "Exported " + informStr + " script " + index.getAndIncrement() + "/" + count + " " + path); + } + return null; + } + } + + public List exportActionScript2(String outdir, boolean isPcode, boolean paralel, EventListener evl) { + List ret = new ArrayList<>(); + List list2 = new ArrayList<>(); + list2.addAll(tags); + List list = createASTagList(list2, null); + + TagNode.setExport(list, true); + if (!outdir.endsWith(File.separator)) { + outdir += File.separator; + } + outdir += "scripts" + File.separator; + ret.addAll(TagNode.exportNodeAS(list, outdir, isPcode, evl)); + return ret; + } + + public List exportActionScript3(String outdir, boolean isPcode, boolean paralel) { + ExecutorService executor = Executors.newFixedThreadPool(20); + List> futureResults = new ArrayList<>(); + AtomicInteger cnt = new AtomicInteger(1); + List abcTags = new ArrayList<>(); + for (Tag t : tags) { + if (t instanceof ABCContainerTag) { + abcTags.add((ABCContainerTag) t); + } + } + List> packs = getAS3Packs(); + for (KeyValue item : packs) { + Future future = executor.submit(new ExportPackTask(cnt, packs.size(), item.key, item.value, outdir, abcTags, isPcode, "", paralel)); + futureResults.add(future); + } + + List ret = new ArrayList<>(); + for (int f = 0; f < futureResults.size(); f++) { + try { + ret.add(futureResults.get(f).get()); + } catch (InterruptedException | ExecutionException ex) { + Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); + } + } + + try { + executor.shutdown(); + executor.awaitTermination(30, TimeUnit.MINUTES); + } catch (InterruptedException ex) { + Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "30 minutes ActionScript export limit reached", ex); + } + return ret; + } + public List exportActionScript(String outdir, boolean isPcode, boolean paralel) throws Exception { boolean asV3Found = false; List ret = new ArrayList<>(); @@ -503,30 +628,16 @@ public class SWF { } } }; - List abcTags = new ArrayList<>(); for (Tag t : tags) { if (t instanceof ABCContainerTag) { - abcTags.add((ABCContainerTag) t); asV3Found = true; } } - for (int i = 0; i < abcTags.size(); i++) { - ABCContainerTag t = abcTags.get(i); - t.getABC().addEventListener(evl); - ret.addAll(t.getABC().export(outdir, isPcode, abcTags, "tag " + (i + 1) + "/" + abcTags.size() + " ", paralel)); - } - if (!asV3Found) { - List list2 = new ArrayList<>(); - list2.addAll(tags); - List list = createASTagList(list2, null); - - TagNode.setExport(list, true); - if (!outdir.endsWith(File.separator)) { - outdir += File.separator; - } - outdir += "scripts" + File.separator; - ret.addAll(TagNode.exportNodeAS(list, outdir, isPcode, evl)); + if (asV3Found) { + ret.addAll(exportActionScript3(outdir, isPcode, paralel)); + } else { + ret.addAll(exportActionScript2(outdir, isPcode, paralel, evl)); } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index c8c62681a..3fb756441 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -28,6 +28,8 @@ import com.jpexs.decompiler.flash.action.swf6.*; import com.jpexs.decompiler.flash.action.swf7.*; import com.jpexs.decompiler.flash.action.treemodel.ConstantPool; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; +import com.jpexs.decompiler.flash.ecma.EcmaScript; +import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.graph.GraphSourceItemPos; @@ -658,7 +660,7 @@ public class SWFInputStream extends InputStream { } } } - boolean condition = stack.peek().toBoolean(); + boolean condition = EcmaScript.toBoolean(stack.peek().getResult()); if (debugMode) { if (condition) { System.err.println("JUMP"); @@ -945,7 +947,7 @@ public class SWFInputStream extends InputStream { if (debugMode) { System.err.print("is compiletime -> "); } - if (top.toBoolean()) { + if (EcmaScript.toBoolean(top.getResult())) { newip = rri.getPos() + aif.getJumpOffset(); //rri.setPos(newip); if (((!enableVariables) || (!top.isVariableComputed())) && (!aif.ignoreUsed)) { @@ -1156,7 +1158,11 @@ public class SWFInputStream extends InputStream { @Override public Tag call() throws Exception { - return SWFInputStream.resolveTag(tag, version, level, paralel); + try { + return SWFInputStream.resolveTag(tag, version, level, paralel); + } catch (Exception ex) { + return null; + } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index 790d23f53..b5e485196 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc; import com.jpexs.decompiler.flash.EventListener; +import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.UnknownInstructionCode; @@ -31,7 +32,6 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.abc.usages.*; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; import java.io.*; import java.util.ArrayList; import java.util.HashMap; @@ -39,16 +39,8 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Random; import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -711,77 +703,45 @@ public class ABC { } } - public void export(String directory, boolean pcode, List abcList, boolean paralel) throws IOException { - export(directory, pcode, abcList, "", paralel); - } - - private class ExportPackTask implements Callable { - - ScriptPack pack; - String directory; - List abcList; - boolean pcode; - String informStr; - ClassPath path; - AtomicInteger index; - int count; - boolean paralel; - - public ExportPackTask(AtomicInteger index, int count, ClassPath path, ScriptPack pack, String directory, List abcList, boolean pcode, String informStr, boolean paralel) { - this.pack = pack; - this.directory = directory; - this.abcList = abcList; - this.pcode = pcode; - this.informStr = informStr; - this.path = path; - this.index = index; - this.count = count; - this.paralel = paralel; - } - - @Override - public File call() throws Exception { - try { - return pack.export(directory, abcList, pcode, paralel); - } catch (IOException ex) { - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, ex); - } - synchronized (ABC.class) { - informListeners("export", "Exported " + informStr + " script " + index.getAndIncrement() + "/" + count + " " + path); - } - return null; - } - } - - public List export(String directory, boolean pcode, List abcList, String abcStr, boolean paralel) throws IOException { - ExecutorService executor = Executors.newFixedThreadPool(20); - List> futureResults = new ArrayList<>(); - AtomicInteger cnt = new AtomicInteger(1); + /*public void export(String directory, boolean pcode, List abcList, boolean paralel) throws IOException { + export(directory, pcode, abcList, "", paralel); + }*/ + public List> getScriptPacks() { + List> ret = new ArrayList<>(); for (int i = 0; i < script_info.length; i++) { - HashMap packs = script_info[i].getPacks(this, i); - for (Entry entry : packs.entrySet()) { - Future future = executor.submit(new ExportPackTask(cnt, script_info.length, entry.getKey(), entry.getValue(), directory, abcList, pcode, abcStr, paralel)); - futureResults.add(future); - } - } - - List ret = new ArrayList<>(); - for (int f = 0; f < futureResults.size(); f++) { - try { - ret.add(futureResults.get(f).get()); - } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(Traits.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); - } - } - - try { - executor.shutdown(); - executor.awaitTermination(30, TimeUnit.MINUTES); - } catch (InterruptedException ex) { - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "30 minutes ActionScript export limit reached", ex); + ret.addAll(script_info[i].getPacks(this, i)); } return ret; } + /*public List export(String directory, boolean pcode, List abcList, String abcStr, boolean paralel) throws IOException { + ExecutorService executor = Executors.newFixedThreadPool(20); + List> futureResults = new ArrayList<>(); + AtomicInteger cnt = new AtomicInteger(1); + for (int i = 0; i < script_info.length; i++) { + HashMap packs = script_info[i].getPacks(this, i); + for (Entry entry : packs.entrySet()) { + Future future = executor.submit(new ExportPackTask(cnt, script_info.length, entry.getKey(), entry.getValue(), directory, abcList, pcode, abcStr, paralel)); + futureResults.add(future); + } + } + + List ret = new ArrayList<>(); + for (int f = 0; f < futureResults.size(); f++) { + try { + ret.add(futureResults.get(f).get()); + } catch (InterruptedException | ExecutionException ex) { + Logger.getLogger(Traits.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); + } + } + + try { + executor.shutdown(); + executor.awaitTermination(30, TimeUnit.MINUTES); + } catch (InterruptedException ex) { + Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "30 minutes ActionScript export limit reached", ex); + } + return ret; + }*/ public void dump(OutputStream os) { PrintStream output; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ClassPath.java b/trunk/src/com/jpexs/decompiler/flash/abc/ClassPath.java index 9c109e9a9..5ae2f7f19 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ClassPath.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ClassPath.java @@ -16,6 +16,8 @@ */ package com.jpexs.decompiler.flash.abc; +import java.util.Objects; + /** * * @author JPEXS @@ -34,4 +36,30 @@ public class ClassPath { public String toString() { return (packageStr == null || packageStr.equals("")) ? className : packageStr + "." + className; } + + @Override + public int hashCode() { + int hash = 7; + hash = 37 * hash + Objects.hashCode(this.packageStr); + hash = 37 * hash + Objects.hashCode(this.className); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ClassPath other = (ClassPath) obj; + if (!Objects.equals(this.packageStr, other.packageStr)) { + return false; + } + if (!Objects.equals(this.className, other.className)) { + return false; + } + return true; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 726f599e5..3e7492a26 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -54,6 +54,7 @@ import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.Graph; import com.jpexs.decompiler.flash.graph.GraphPart; import com.jpexs.decompiler.flash.graph.GraphSourceItem; @@ -2030,7 +2031,7 @@ public class AVM2Code implements Serializable { List branches = ins.getBranches(code); if ((ins instanceof AVM2Instruction) && (((AVM2Instruction) ins).definition instanceof LookupSwitchIns) && (!stack.isEmpty()) && (stack.peek().isCompileTime()) && (!stack.peek().hasSideEffect())) { - int c = (int) stack.peek().toNumber(); + int c = (int) (double) EcmaScript.toNumber(stack.peek().getResult()); Decision dec = new Decision(); if (decisions.containsKey(ins)) { dec = decisions.get(ins); @@ -2076,7 +2077,7 @@ public class AVM2Code implements Serializable { continue; } else if ((ins instanceof AVM2Instruction) && ((AVM2Instruction) ins).definition instanceof IfTypeIns && (!(((AVM2Instruction) ins).definition instanceof JumpIns)) && (!stack.isEmpty()) && (stack.peek().isCompileTime()) && (!stack.peek().hasSideEffect())) { - boolean condition = stack.peek().toBoolean(); + boolean condition = EcmaScript.toBoolean(stack.peek().getResult()); if (debugMode) { if (condition) { System.out.println("JUMP"); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/BooleanTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/BooleanTreeItem.java index d457744c9..2a0b16719 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/BooleanTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/BooleanTreeItem.java @@ -46,15 +46,10 @@ public class BooleanTreeItem extends TreeItem { } @Override - public boolean toBoolean() { + public Object getResult() { return value; } - @Override - public double toNumber() { - return value ? 1 : 0; - } - @Override public boolean isCompileTime() { return true; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/CoerceTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/CoerceTreeItem.java index a7275fcd9..edf4ec179 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/CoerceTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/CoerceTreeItem.java @@ -18,6 +18,8 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; @@ -43,4 +45,28 @@ public class CoerceTreeItem extends TreeItem { public GraphTargetItem getNotCoerced() { return value.getNotCoerced(); } + + @Override + public boolean isCompileTime() { + return value.isCompileTime(); + } + + @Override + public Object getResult() { + Object ret = value.getResult(); + switch (type) { + case "String": + if (ret instanceof Null) { + return ret; + } + if (ret instanceof Undefined) { + return new Null(); + } + return ret.toString(); + case "*": + break; + } + return ret; + + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/ConvertTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/ConvertTreeItem.java index 362aa050d..8aecf8aad 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/ConvertTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/ConvertTreeItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; @@ -44,77 +45,27 @@ public class ConvertTreeItem extends TreeItem { } @Override - public double toNumber() { - return toBoolean() ? 1 : 0; - } - - @Override - public boolean toBoolean() { - if (type.contains("Boolean")) { - if (value instanceof UndefinedTreeItem) { - return false; - } - if (value instanceof NullTreeItem) { - return false; - } - if (value instanceof BooleanTreeItem) { - return ((BooleanTreeItem) value).value; - } - if (value instanceof IntegerValueTreeItem) { - IntegerValueTreeItem iv = (IntegerValueTreeItem) value; - return iv.value != 0; - } - if (value instanceof FloatValueTreeItem) { - FloatValueTreeItem fv = (FloatValueTreeItem) value; - return !(fv.value == 0 || fv.value.isNaN()); - } - if (value instanceof StringTreeItem) { - StringTreeItem sv = (StringTreeItem) value; - return !sv.value.equals(""); - } - - if (value instanceof ThisTreeItem) { - return true; - } - if (value instanceof ClassTreeItem) { - return true; - } - //object - return false; + public Object getResult() { + switch (type) { + case "Boolean": + return EcmaScript.toBoolean(value.getResult()); + case "Number": + return EcmaScript.toNumber(value.getResult()); + case "int": + return (int) (double) EcmaScript.toNumber(value.getResult()); + case "uint": + return (int) (double) EcmaScript.toUint32(value.getResult()); + case "String": + return value.getResult().toString(); + case "Object": + return value.getResult(); //if not object throw TypeError + default: + return new Object(); } - return false; } @Override public boolean isCompileTime() { - if (type.contains("Boolean")) { - if (value instanceof UndefinedTreeItem) { - return true; - } - if (value instanceof NullTreeItem) { - return true; - } - if (value instanceof BooleanTreeItem) { - return true; - } - if (value instanceof IntegerValueTreeItem) { - return true; - } - if (value instanceof FloatValueTreeItem) { - return true; - } - if (value instanceof StringTreeItem) { - return true; - } - if (value instanceof ThisTreeItem) { - return true; - } - if (value instanceof ClassTreeItem) { - return true; - } - //object - return false; - } - return false; + return value.isCompileTime(); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/FloatValueTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/FloatValueTreeItem.java index 459d7c05b..e1d1cfbd7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/FloatValueTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/FloatValueTreeItem.java @@ -36,7 +36,7 @@ public class FloatValueTreeItem extends NumberValueTreeItem { } @Override - public double toNumber() { + public Object getResult() { return value; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IntegerValueTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IntegerValueTreeItem.java index 16364d4b3..04443e8c6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IntegerValueTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IntegerValueTreeItem.java @@ -36,8 +36,8 @@ public class IntegerValueTreeItem extends NumberValueTreeItem { } @Override - public double toNumber() { - return value; + public Object getResult() { + return (Double) (double) (long) value; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/LocalRegTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/LocalRegTreeItem.java index 1b41076cc..267b3e53f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/LocalRegTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/LocalRegTreeItem.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.treemodel.clauses.FilterTreeItem; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Helper; import java.util.HashMap; @@ -55,19 +56,12 @@ public class LocalRegTreeItem extends TreeItem { } @Override - public double toNumber() { + public Object getResult() { if (computedValue == null) { - return 0; + return new Undefined(); } - return computedValue.toNumber(); - } + return computedValue.getResult(); - @Override - public boolean toBoolean() { - if (computedValue == null) { - return false; - } - return computedValue.toBoolean(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NullTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NullTreeItem.java index 4abc4a45f..d923bbc79 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NullTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/NullTreeItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.Null; import java.util.HashMap; import java.util.List; @@ -38,12 +39,7 @@ public class NullTreeItem extends TreeItem { } @Override - public double toNumber() { - return 0; - } - - @Override - public boolean toBoolean() { - return false; + public Object getResult() { + return new Null(); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/StringTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/StringTreeItem.java index 5a894bbd1..940f9f8ad 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/StringTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/StringTreeItem.java @@ -35,4 +35,14 @@ public class StringTreeItem extends TreeItem { public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { return hilight("\"" + Helper.escapeString(value) + "\""); } + + @Override + public boolean isCompileTime() { + return true; + } + + @Override + public Object getResult() { + return value; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java index 4e7c317b3..a0d07c622 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.Undefined; import java.util.HashMap; import java.util.List; @@ -38,12 +39,7 @@ public class UndefinedTreeItem extends TreeItem { } @Override - public double toNumber() { - return 0; - } - - @Override - public boolean toBoolean() { - return false; + public Object getResult() { + return new Undefined(); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/AddTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/AddTreeItem.java index be6a4c687..c3d1bcc03 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/AddTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/AddTreeItem.java @@ -17,6 +17,8 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; +import com.jpexs.decompiler.flash.ecma.EcmaType; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; @@ -45,7 +47,10 @@ public class AddTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return leftSide.toNumber() + rightSide.toNumber(); + public Object getResult() { + if (EcmaScript.type(leftSide.getResult()) == EcmaType.STRING || EcmaScript.type(rightSide.getResult()) == EcmaType.STRING) { + return leftSide.getResult().toString() + rightSide.getResult().toString(); + } + return EcmaScript.toNumber(leftSide.getResult()) + EcmaScript.toNumber(rightSide.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitAndTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitAndTreeItem.java index a943d1bd3..3c4075f87 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitAndTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitAndTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class BitAndTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) & ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) & ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitNotTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitNotTreeItem.java index 0610d1c77..19a6df334 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitNotTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitNotTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -27,7 +28,7 @@ public class BitNotTreeItem extends UnaryOpItem { } @Override - public double toNumber() { - return ~((int) value.toNumber()); + public Object getResult() { + return ~((long) (double) EcmaScript.toNumber(value.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitOrTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitOrTreeItem.java index e7d98fd5c..61b94c3c6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitOrTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitOrTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class BitOrTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) | ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) | ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitXorTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitXorTreeItem.java index 0c4bef091..f8b66473a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitXorTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/BitXorTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class BitXorTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) ^ ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) ^ ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java index f33e32c63..ec2afa066 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,10 +28,10 @@ public class DivideTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - if (Double.compare(rightSide.toNumber(), 0) == 0) { + public Object getResult() { + if (Double.compare(EcmaScript.toNumber(rightSide.getResult()), 0) == 0) { return Double.NaN; } - return leftSide.toNumber() / rightSide.toNumber(); + return (EcmaScript.toNumber(leftSide.getResult())) / (EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/EqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/EqTreeItem.java index 98c6b91ac..3d3a48300 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/EqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/EqTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,8 @@ public class EqTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return (leftSide.toBoolean() == rightSide.toBoolean()) && (leftSide.toNumber() == rightSide.toNumber()); + public Object getResult() { + return EcmaScript.equals(leftSide.getResult(), rightSide.getResult()); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GeTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GeTreeItem.java index 0cef4175b..40fabae8e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GeTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GeTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -33,7 +34,14 @@ public class GeTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return leftSide.toNumber() >= rightSide.toNumber(); + public Object getResult() { + Object ret = EcmaScript.compare(leftSide.getResult(), rightSide.getResult()); + if (ret == Boolean.TRUE) { + return Boolean.FALSE; + } + if (ret == Boolean.FALSE) { + return Boolean.TRUE; + } + return ret;//undefined } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GtTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GtTreeItem.java index 6a32d435e..dd1dc9eaa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GtTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/GtTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -33,7 +34,7 @@ public class GtTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return leftSide.toNumber() > rightSide.toNumber(); + public Object getResult() { + return EcmaScript.compare(rightSide.getResult(), leftSide.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LShiftTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LShiftTreeItem.java index bbdb4c146..d22ad5f61 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LShiftTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LShiftTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class LShiftTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) << ((int) rightSide.toNumber()); + public Object getResult() { + return ((int) (double) EcmaScript.toNumber(leftSide.getResult())) << ((int) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LeTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LeTreeItem.java index 242fe7343..2ef5aa7a2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LeTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LeTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -33,7 +34,14 @@ public class LeTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return leftSide.toNumber() <= rightSide.toNumber(); + public Object getResult() { + Object ret = EcmaScript.compare(rightSide.getResult(), leftSide.getResult()); + if (ret == Boolean.TRUE) { + return Boolean.FALSE; + } + if (ret == Boolean.FALSE) { + return Boolean.TRUE; + } + return ret;//undefined } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LtTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LtTreeItem.java index 7b83950f3..266396b9f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LtTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/LtTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -33,7 +34,7 @@ public class LtTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return leftSide.toNumber() < rightSide.toNumber(); + public Object getResult() { + return EcmaScript.compare(leftSide.getResult(), rightSide.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/ModuloTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/ModuloTreeItem.java index 81d334c6e..bcede3f9c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/ModuloTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/ModuloTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,10 @@ public class ModuloTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) % ((int) rightSide.toNumber()); + public Object getResult() { + if (Double.compare(EcmaScript.toNumber(rightSide.getResult()), 0) == 0) { + return Double.NaN; + } + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) % ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/MultiplyTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/MultiplyTreeItem.java index ea66ac1f9..c086b2b46 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/MultiplyTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/MultiplyTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class MultiplyTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return leftSide.toNumber() * rightSide.toNumber(); + public Object getResult() { + return (EcmaScript.toNumber(leftSide.getResult())) * (EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NegTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NegTreeItem.java index e957ea3ea..73832434a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NegTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NegTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -27,7 +28,7 @@ public class NegTreeItem extends UnaryOpItem { } @Override - public double toNumber() { - return -value.toNumber(); + public Object getResult() { + return -EcmaScript.toNumber(value.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NeqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NeqTreeItem.java index 3c1398cb4..a13f6908b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NeqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NeqTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,8 @@ public class NeqTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return (leftSide.toNumber() != rightSide.toNumber()) || (leftSide.toBoolean() != rightSide.toBoolean()); + public Object getResult() { + return !EcmaScript.equals(leftSide.getResult(), rightSide.getResult()); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/OrTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/OrTreeItem.java index 02927cfa8..358d0769f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/OrTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/OrTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphPart; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -30,7 +31,7 @@ public class OrTreeItem extends BinaryOpItem { } @Override - public boolean toBoolean() { - return leftSide.toBoolean() || rightSide.toBoolean(); + public Object getResult() { + return EcmaScript.toBoolean(leftSide.getResult()) || EcmaScript.toBoolean(rightSide.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/RShiftTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/RShiftTreeItem.java index ef4cb077c..1ec48b618 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/RShiftTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/RShiftTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class RShiftTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) >> ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) >> ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictEqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictEqTreeItem.java index 73acbab42..91479371e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictEqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictEqTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,11 @@ public class StrictEqTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return (leftSide.toBoolean() == rightSide.toBoolean()) && (leftSide.toNumber() == rightSide.toNumber()); + public Object getResult() { + Object x = leftSide.getResult(); + Object y = rightSide.getResult(); + return EcmaScript.type(x) == EcmaScript.type(y) + && EcmaScript.equals(x, y); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java index 711081e5b..eee9549f9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -33,7 +34,10 @@ public class StrictNeqTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return !((leftSide.toBoolean() == rightSide.toBoolean()) && (leftSide.toNumber() == rightSide.toNumber())); + public Object getResult() { + Object x = leftSide.getResult(); + Object y = rightSide.getResult(); + return EcmaScript.type(x) != EcmaScript.type(y) + || (!EcmaScript.equals(x, y)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/SubtractTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/SubtractTreeItem.java index 8355ea2df..c67fd8e3b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/SubtractTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/SubtractTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; @@ -28,8 +29,8 @@ public class SubtractTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return leftSide.toNumber() - rightSide.toNumber(); + public Object getResult() { + return EcmaScript.toNumber(leftSide.getResult()) - EcmaScript.toNumber(rightSide.getResult()); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/TypeOfTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/TypeOfTreeItem.java index e4d56bc78..b7aefc1b8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/TypeOfTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/TypeOfTreeItem.java @@ -17,6 +17,14 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; +import com.jpexs.decompiler.flash.ecma.EcmaType; +import static com.jpexs.decompiler.flash.ecma.EcmaType.BOOLEAN; +import static com.jpexs.decompiler.flash.ecma.EcmaType.NULL; +import static com.jpexs.decompiler.flash.ecma.EcmaType.NUMBER; +import static com.jpexs.decompiler.flash.ecma.EcmaType.OBJECT; +import static com.jpexs.decompiler.flash.ecma.EcmaType.STRING; +import static com.jpexs.decompiler.flash.ecma.EcmaType.UNDEFINED; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -25,4 +33,32 @@ public class TypeOfTreeItem extends UnaryOpItem { public TypeOfTreeItem(AVM2Instruction instruction, GraphTargetItem value) { super(instruction, PRECEDENCE_UNARY, value, "typeof "); } + + @Override + public boolean isCompileTime() { + return value.isCompileTime(); + } + + @Override + public Object getResult() { + Object res = value.getResult(); + EcmaType type = EcmaScript.type(res); + switch (type) { + case UNDEFINED: + return "undefined"; + case NULL: + return "object"; + case BOOLEAN: + return "Boolean"; + case NUMBER: + return "number"; + case STRING: + return "string"; + case OBJECT: + return "object"; + + } + //TODO: function,xml + return "object"; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/URShiftTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/URShiftTreeItem.java index ae03ab84b..a6f0bef62 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/URShiftTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/URShiftTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class URShiftTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) >>> ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) >>> ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index a2a269a09..7898530a4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -16,15 +16,14 @@ */ package com.jpexs.decompiler.flash.abc.types; +import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; public class ScriptInfo { @@ -32,8 +31,8 @@ public class ScriptInfo { public int init_index; //MethodInfo public Traits traits; - public HashMap getPacks(ABC abc, int scriptIndex) { - HashMap ret = new HashMap<>(); + public List> getPacks(ABC abc, int scriptIndex) { + List> ret = new ArrayList<>(); List otherTraits = new ArrayList<>(); for (int j = 0; j < traits.traits.length; j++) { @@ -60,7 +59,7 @@ public class ScriptInfo { traitIndices.addAll(otherTraits); } otherTraits = new ArrayList<>(); - ret.put(new ClassPath(packageName, objectName), new ScriptPack(abc, scriptIndex, traitIndices)); + ret.add(new KeyValue<>(new ClassPath(packageName, objectName), new ScriptPack(abc, scriptIndex, traitIndices))); } } return ret; @@ -82,11 +81,4 @@ public class ScriptInfo { public String convert(List abcTags, ABC abc, boolean pcode, boolean highlighting, int scriptIndex, boolean paralel) { return traits.convert("", abcTags, abc, false, pcode, true, scriptIndex, -1, highlighting, new ArrayList(), paralel); } - - public void export(ABC abc, List abcList, String directory, boolean pcode, int scriptIndex, boolean paralel) throws IOException { - HashMap packs = getPacks(abc, scriptIndex); - for (ScriptPack pack : packs.values()) { - pack.export(directory, abcList, pcode, paralel); - } - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index 4cd5ec7c2..5cc0b56d4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.action.swf5.*; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.action.treemodel.*; import com.jpexs.decompiler.flash.action.treemodel.clauses.*; +import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.graph.CommentItem; import com.jpexs.decompiler.flash.graph.Graph; import com.jpexs.decompiler.flash.graph.GraphSource; @@ -1292,4 +1293,17 @@ public class Action implements GraphSourceItem { public String getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex) { return getASMSource(container, knownAddreses, constantPool, version, hex); } + + public static double toFloatPoint(Object o) { + if (o instanceof Double) { + return (Double) o; + } + if (o instanceof Integer) { + return (Integer) o; + } + if (o instanceof Long) { + return (Long) o; + } + return 0; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java index d18a56f6a..b5c02b26d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.action.swf4.ActionEquals; import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf4.ActionNot; import com.jpexs.decompiler.flash.action.swf4.ActionPush; -import com.jpexs.decompiler.flash.action.swf4.Null; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; import com.jpexs.decompiler.flash.action.swf5.ActionEquals2; import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister; @@ -33,6 +32,7 @@ import com.jpexs.decompiler.flash.action.treemodel.StoreRegisterTreeItem; import com.jpexs.decompiler.flash.action.treemodel.clauses.ForInTreeItem; import com.jpexs.decompiler.flash.action.treemodel.operations.NeqTreeItem; import com.jpexs.decompiler.flash.action.treemodel.operations.StrictEqTreeItem; +import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.graph.BreakItem; import com.jpexs.decompiler.flash.graph.ContinueItem; import com.jpexs.decompiler.flash.graph.Graph; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java b/trunk/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java index 32da21dcf..307f6280a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java @@ -5,9 +5,9 @@ package com.jpexs.decompiler.flash.action.parser.pcode; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; -import com.jpexs.decompiler.flash.action.swf4.Null; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; -import com.jpexs.decompiler.flash.action.swf4.Undefined; +import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.flash.ecma.Undefined; /** * This class is a scanner generated by diff --git a/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java b/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java index 5261d7440..2489394f1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java @@ -37,6 +37,8 @@ import com.jpexs.decompiler.flash.action.swf7.ActionImplementsOp; import com.jpexs.decompiler.flash.action.swf7.ActionThrow; import com.jpexs.decompiler.flash.action.swf7.ActionTry; import com.jpexs.decompiler.flash.action.treemodel.ConstantPool; +import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionAdd.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionAdd.java index 4fd583faa..3045c8856 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionAdd.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionAdd.java @@ -38,6 +38,6 @@ public class ActionAdd extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { GraphTargetItem a = stack.pop(); GraphTargetItem b = stack.pop(); - stack.push(new AddTreeItem(this, b, a)); + stack.push(new AddTreeItem(this, b, a, false)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionEquals.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionEquals.java index 24b43bd4c..75234b78c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionEquals.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionEquals.java @@ -38,6 +38,6 @@ public class ActionEquals extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { GraphTargetItem a = stack.pop(); GraphTargetItem b = stack.pop(); - stack.push(new EqTreeItem(this, b, a)); + stack.push(new EqTreeItem(this, b, a, false)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionLess.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionLess.java index ee0d1018f..f77015780 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionLess.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionLess.java @@ -38,6 +38,6 @@ public class ActionLess extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { GraphTargetItem a = stack.pop(); GraphTargetItem b = stack.pop(); - stack.push(new LtTreeItem(this, b, a)); + stack.push(new LtTreeItem(this, b, a, false)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index 0d9b8db82..d0a50ac30 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -24,6 +24,8 @@ import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; +import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Helper; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionStartDrag.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionStartDrag.java index 0f8a083b2..127054bf7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionStartDrag.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionStartDrag.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.swf4; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; import com.jpexs.decompiler.flash.action.treemodel.StartDragTreeItem; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; @@ -43,7 +44,7 @@ public class ActionStartDrag extends Action { boolean hasConstrains = true; if (constrain instanceof DirectValueTreeItem) { - if (Double.compare(constrain.toNumber(), 0) == 0) { + if (Double.compare(EcmaScript.toNumber(constrain.getResult()), 0) == 0) { hasConstrains = false; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionAdd2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionAdd2.java index 6b12122c9..70b37ea30 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionAdd2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionAdd2.java @@ -38,6 +38,6 @@ public class ActionAdd2 extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { GraphTargetItem a = stack.pop(); GraphTargetItem b = stack.pop(); - stack.push(new AddTreeItem(this, b, a)); + stack.push(new AddTreeItem(this, b, a, true)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEnumerate.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEnumerate.java index 079cf9a2c..25093b8bb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEnumerate.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEnumerate.java @@ -17,9 +17,9 @@ package com.jpexs.decompiler.flash.action.swf5; import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.swf4.Null; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; import com.jpexs.decompiler.flash.action.treemodel.EnumerateTreeItem; +import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.ArrayList; import java.util.HashMap; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEquals2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEquals2.java index 9e177bc44..a07d3b653 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEquals2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionEquals2.java @@ -38,6 +38,6 @@ public class ActionEquals2 extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { GraphTargetItem a = stack.pop(); GraphTargetItem b = stack.pop(); - stack.push(new EqTreeItem(this, b, a)); + stack.push(new EqTreeItem(this, b, a, true)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionLess2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionLess2.java index d2e4b5622..15a340f89 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionLess2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionLess2.java @@ -38,6 +38,6 @@ public class ActionLess2 extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { GraphTargetItem a = stack.pop(); GraphTargetItem b = stack.pop(); - stack.push(new LtTreeItem(this, b, a)); + stack.push(new LtTreeItem(this, b, a, true)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf6/ActionEnumerate2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf6/ActionEnumerate2.java index ef746ae7d..9b7fbcddb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf6/ActionEnumerate2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf6/ActionEnumerate2.java @@ -17,9 +17,9 @@ package com.jpexs.decompiler.flash.action.swf6; import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.swf4.Null; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; import com.jpexs.decompiler.flash.action.treemodel.EnumerateTreeItem; +import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.ArrayList; import java.util.HashMap; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java index 308c7dc4e..79188f3c6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java @@ -63,19 +63,11 @@ public class CallFunctionTreeItem extends TreeItem { } @Override - public boolean toBoolean() { + public Object getResult() { if (calculatedFunction == null) { - return false; + return null; } - return calculatedFunction.toBoolean(); - } - - @Override - public double toNumber() { - if (calculatedFunction == null) { - return 0; - } - return calculatedFunction.toNumber(); + return calculatedFunction.getResult(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java index 1c20070c3..21793e750 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java @@ -16,7 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel; -import com.jpexs.decompiler.flash.action.swf4.Undefined; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java index a3f30ca6f..a5299164d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CharToAsciiTreeItem.java @@ -56,22 +56,13 @@ public class CharToAsciiTreeItem extends TreeItem { } @Override - public double toNumber() { - if (value instanceof DirectValueTreeItem) { - DirectValueTreeItem dv = (DirectValueTreeItem) value; - if (dv.value instanceof String) { - String s = (String) dv.value; - if (s.length() > 0) { - char c = s.charAt(0); - return (int) c; - } - } + public Object getResult() { + Object res = value.getResult(); + String s = res.toString(); + if (s.length() > 0) { + char c = s.charAt(0); + return (int) c; } return 0; } - - @Override - public boolean toBoolean() { - return toNumber() != 0; - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DecrementTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DecrementTreeItem.java index 9ad797465..f9a5bbf4b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DecrementTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DecrementTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; @@ -40,8 +41,8 @@ public class DecrementTreeItem extends TreeItem { } @Override - public double toNumber() { - return object.toNumber() - 1; + public Object getResult() { + return EcmaScript.toNumber(object.getResult()) - 1; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java index be6b2b554..3f8548eb6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java @@ -17,7 +17,9 @@ package com.jpexs.decompiler.flash.action.treemodel; import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; -import com.jpexs.decompiler.flash.action.swf4.Null; +import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; +import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Helper; @@ -46,82 +48,33 @@ public class DirectValueTreeItem extends TreeItem { } @Override - public double toNumber() { + public Object getResult() { if (computedRegValue != null) { - return computedRegValue.toNumber(); + return computedRegValue.getResult(); } if (value instanceof Double) { return (Double) value; } if (value instanceof Float) { - return (Float) value; + return (double) (Float) value; } if (value instanceof Long) { - return (Long) value; + return (double) (Long) value; } if (value instanceof Boolean) { - return ((Boolean) value) ? 1 : 0; + return value; } if (value instanceof String) { - String s = (String) value; - if (s.length() == 1) { - return s.charAt(0); - } - double ret = 0.0; - try { - ret = Double.parseDouble(s); - } catch (NumberFormatException nex) { - } - return ret; + return value; } if (value instanceof ConstantIndex) { - String s = (this.constants.get(((ConstantIndex) value).index)); - if (s.length() == 1) { - return s.charAt(0); - } - double ret = 0.0; - try { - ret = Double.parseDouble(s); - } catch (NumberFormatException nex) { - } - return ret; + return (this.constants.get(((ConstantIndex) value).index)); } - return super.toNumber(); - } - - @Override - public boolean toBoolean() { - if (computedRegValue != null) { - return computedRegValue.toBoolean(); + if (value instanceof RegisterNumber) { + return new Undefined(); //has not computed value } - if (value instanceof Boolean) { - return (Boolean) value; - } - if (value instanceof Double) { - return Double.compare((Double) value, 0.0) != 0; - } - if (value instanceof Float) { - return Float.compare((Float) value, 0.0f) != 0; - } - if (value instanceof Long) { - return ((Long) value) != 0; - } - if (value instanceof String) { - String s = (String) value; - if (s.length() == 1) { - return toNumber() == 0; - } - return !s.equals(""); - } - if (value instanceof ConstantIndex) { - String s = (this.constants.get(((ConstantIndex) value).index)); - if (s.length() == 1) { - return toNumber() == 0; - } - return !s.equals(""); - } - return false; + return value; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/FunctionTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/FunctionTreeItem.java index f02b9a20c..502c72e5f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/FunctionTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/FunctionTreeItem.java @@ -90,22 +90,11 @@ public class FunctionTreeItem extends TreeItem { } @Override - public boolean toBoolean() { + public Object getResult() { if (!actions.isEmpty()) { if (actions.get(actions.size() - 1) instanceof ReturnTreeItem) { ReturnTreeItem r = (ReturnTreeItem) actions.get(actions.size() - 1); - return r.value.toBoolean(); - } - } - return false; - } - - @Override - public double toNumber() { - if (!actions.isEmpty()) { - if (actions.get(actions.size() - 1) instanceof ReturnTreeItem) { - ReturnTreeItem r = (ReturnTreeItem) actions.get(actions.size() - 1); - return r.value.toNumber(); + return r.value.getResult(); } } return 0; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetTimeTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetTimeTreeItem.java index 74043d880..c2642fdde 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetTimeTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetTimeTreeItem.java @@ -36,12 +36,7 @@ public class GetTimeTreeItem extends TreeItem { } @Override - public double toNumber() { - return new Random().nextInt(10000) + 1000; - } - - @Override - public boolean toBoolean() { - return true; + public Object getResult() { + return (Double) (double) new Random().nextInt(10000) + 1000; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java index 505dc85e1..1ccaef7ec 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; @@ -24,8 +25,7 @@ public class GetVariableTreeItem extends TreeItem { public GraphTargetItem name; private GraphTargetItem computedValue; - private double computedNumber = 0; - private boolean computedBool = false; + private Object computedResult; private boolean computedCompiletime = false; private boolean computedVariableComputed = false; @@ -64,26 +64,17 @@ public class GetVariableTreeItem extends TreeItem { } @Override - public boolean toBoolean() { + public Object getResult() { if (computedValue == null) { - return false; + return new Undefined(); } - return computedBool; - } - - @Override - public double toNumber() { - if (computedValue == null) { - return 0; - } - return computedNumber; + return computedResult; } public void setComputedValue(GraphTargetItem computedValue) { this.computedValue = computedValue; if (computedValue != null) { - computedNumber = computedValue.toNumber(); - computedBool = computedValue.toBoolean(); + computedResult = computedValue.getResult(); computedCompiletime = computedValue.isCompileTime(); computedVariableComputed = computedValue.isVariableComputed(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/IncrementTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/IncrementTreeItem.java index 0bd2ff47d..32b94e5c7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/IncrementTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/IncrementTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; @@ -40,8 +41,8 @@ public class IncrementTreeItem extends TreeItem { } @Override - public double toNumber() { - return object.toNumber() + 1; + public Object getResult() { + return EcmaScript.toNumber(object.getResult()) + 1; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewMethodTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewMethodTreeItem.java index ac13d11c1..86699b1ab 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewMethodTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewMethodTreeItem.java @@ -16,7 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel; -import com.jpexs.decompiler.flash.action.swf4.Undefined; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/PostIncrementTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/PostIncrementTreeItem.java index 1cefef6c2..fd365c98a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/PostIncrementTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/PostIncrementTreeItem.java @@ -47,7 +47,7 @@ public class PostIncrementTreeItem extends TreeItem implements SetTypeTreeItem { @Override public GraphTargetItem getValue() { - return new AddTreeItem(null, object, new DirectValueTreeItem(null, 0, new Long(1), null)); + return new AddTreeItem(null, object, new DirectValueTreeItem(null, 0, new Long(1), null), true); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/StartDragTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/StartDragTreeItem.java index dcdfd5793..3ee1c5a19 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/StartDragTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/StartDragTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.List; @@ -45,7 +46,7 @@ public class StartDragTreeItem extends TreeItem { public String toString(ConstantPool constants) { boolean hasConstrains = true; if (constrain instanceof DirectValueTreeItem) { - if (Double.compare(constrain.toNumber(), 0) == 0) { + if (Double.compare(EcmaScript.toNumber(constrain.getResult()), 0) == 0) { hasConstrains = false; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TypeOfTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TypeOfTreeItem.java index 1b56b7d6c..7cf8d48ec 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TypeOfTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TypeOfTreeItem.java @@ -16,6 +16,8 @@ */ package com.jpexs.decompiler.flash.action.treemodel; +import com.jpexs.decompiler.flash.ecma.EcmaScript; +import com.jpexs.decompiler.flash.ecma.EcmaType; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Helper; @@ -41,4 +43,31 @@ public class TypeOfTreeItem extends TreeItem { ret.addAll(value.getNeededSources()); return ret; } + + @Override + public Object getResult() { + Object res = value.getResult(); + EcmaType type = EcmaScript.type(res); + switch (type) { + case STRING: + return "string"; + case BOOLEAN: + return "boolean"; + case NUMBER: + return "number"; + case OBJECT: + return "object"; + case UNDEFINED: + return "undefined"; + case NULL: + return "null"; + } + //TODO: function,movieclip + return "object"; + } + + @Override + public boolean isCompileTime() { + return value.isCompileTime(); + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AddTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AddTreeItem.java index 994164971..d44d6f66b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AddTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AddTreeItem.java @@ -16,18 +16,30 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; public class AddTreeItem extends BinaryOpItem { - public AddTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) { + boolean version2; + + public AddTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide, boolean version2) { super(instruction, PRECEDENCE_ADDITIVE, leftSide, rightSide, "+"); + this.version2 = version2; } @Override - public double toNumber() { - return leftSide.toNumber() + rightSide.toNumber(); + public Object getResult() { + if (version2) { + if (EcmaScript.type(leftSide.getResult()) == EcmaType.STRING || EcmaScript.type(rightSide.getResult()) == EcmaType.STRING) { + return leftSide.getResult().toString() + rightSide.getResult().toString(); + } + return EcmaScript.toNumber(leftSide.getResult()) + EcmaScript.toNumber(rightSide.getResult()); + } else { + return Action.toFloatPoint(leftSide.getResult()) + Action.toFloatPoint(rightSide.getResult()); + } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AndTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AndTreeItem.java index f845fac4e..ddea13997 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AndTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/AndTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class AndTreeItem extends BinaryOpItem { } @Override - public boolean toBoolean() { - return leftSide.toBoolean() && rightSide.toBoolean(); + public Object getResult() { + return EcmaScript.toBoolean(leftSide.getResult()) && EcmaScript.toBoolean(rightSide.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitAndTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitAndTreeItem.java index a49b64d7a..0f95cd8ea 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitAndTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitAndTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class BitAndTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) & ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) & ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitNotTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitNotTreeItem.java index 1225c2723..b92a74aa3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitNotTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitNotTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.treemodel.operations; import com.jpexs.decompiler.flash.action.treemodel.TreeItem; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -27,7 +28,7 @@ public class BitNotTreeItem extends UnaryOpItem { } @Override - public double toNumber() { - return ~((int) value.toNumber()); + public Object getResult() { + return ~((long) (double) EcmaScript.toNumber(value.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitOrTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitOrTreeItem.java index 59cbc613a..cb28493ef 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitOrTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitOrTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class BitOrTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) | ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) | ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitXorTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitXorTreeItem.java index 8426ee6d4..817c8cb39 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitXorTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/BitXorTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class BitXorTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) ^ ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) ^ ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/DivideTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/DivideTreeItem.java index a3f37091d..eceae0140 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/DivideTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/DivideTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,10 @@ public class DivideTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return leftSide.toNumber() / rightSide.toNumber(); + public Object getResult() { + if (Double.compare(EcmaScript.toNumber(rightSide.getResult()), 0) == 0) { + return Double.NaN; + } + return (EcmaScript.toNumber(leftSide.getResult())) / (EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/EqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/EqTreeItem.java index 8cb1c74e4..8b9feaa4c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/EqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/EqTreeItem.java @@ -16,6 +16,8 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -23,17 +25,25 @@ import com.jpexs.decompiler.flash.graph.LogicalOpItem; public class EqTreeItem extends BinaryOpItem implements LogicalOpItem { - public EqTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) { + boolean version2; + + public EqTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide, boolean version2) { super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "=="); + this.version2 = version2; } @Override - public boolean toBoolean() { - return (leftSide.toBoolean() == rightSide.toBoolean()) && (leftSide.toNumber() == rightSide.toNumber()); + public Object getResult() { + if (version2) { + return EcmaScript.equals(leftSide.getResult(), rightSide.getResult()); + } else { + //For SWF 4 and older, it should return 1 or 0 + return (Action.toFloatPoint(leftSide.getResult()) == Action.toFloatPoint(rightSide.getResult())); + } } @Override public GraphTargetItem invert() { - return new NeqTreeItem(src, leftSide, rightSide); + return new NeqTreeItem(src, leftSide, rightSide, version2); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GeTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GeTreeItem.java index 7b31d6cc7..e59bd2ec6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GeTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GeTreeItem.java @@ -16,6 +16,8 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -23,17 +25,32 @@ import com.jpexs.decompiler.flash.graph.LogicalOpItem; public class GeTreeItem extends BinaryOpItem implements LogicalOpItem { - public GeTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) { + boolean version2; + + public GeTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide, boolean version2) { super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, ">="); + this.version2 = version2; } @Override - public boolean toBoolean() { - return leftSide.toNumber() >= rightSide.toNumber(); + public Object getResult() { + if (version2) { + Object ret = EcmaScript.compare(leftSide.getResult(), rightSide.getResult()); + if (ret == Boolean.TRUE) { + return Boolean.FALSE; + } + if (ret == Boolean.FALSE) { + return Boolean.TRUE; + } + return ret;//undefined + } else { + //For SWF 4 and older, it should return 1 or 0 + return Action.toFloatPoint(leftSide.getResult()) >= Action.toFloatPoint(rightSide.getResult()); + } } @Override public GraphTargetItem invert() { - return new LtTreeItem(src, leftSide, rightSide); + return new LtTreeItem(src, leftSide, rightSide, version2); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GtTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GtTreeItem.java index bb0df6401..5dfcc17a0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GtTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/GtTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,8 @@ public class GtTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return leftSide.toNumber() > rightSide.toNumber(); + public Object getResult() { + return EcmaScript.compare(rightSide.getResult(), leftSide.getResult()); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LShiftTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LShiftTreeItem.java index 3d3cce276..cdef78d2b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LShiftTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LShiftTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class LShiftTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) << ((int) rightSide.toNumber()); + public Object getResult() { + return ((int) (double) EcmaScript.toNumber(leftSide.getResult())) << ((int) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LeTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LeTreeItem.java index 464af1d47..d4d75023b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LeTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LeTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,15 @@ public class LeTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return leftSide.toNumber() <= rightSide.toNumber(); + public Object getResult() { + Object ret = EcmaScript.compare(rightSide.getResult(), leftSide.getResult()); + if (ret == Boolean.TRUE) { + return Boolean.FALSE; + } + if (ret == Boolean.FALSE) { + return Boolean.TRUE; + } + return ret;//undefined } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LtTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LtTreeItem.java index acd84a164..dbac54153 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LtTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/LtTreeItem.java @@ -16,6 +16,8 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -23,17 +25,25 @@ import com.jpexs.decompiler.flash.graph.LogicalOpItem; public class LtTreeItem extends BinaryOpItem implements LogicalOpItem { - public LtTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) { + boolean version2; + + public LtTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide, boolean version2) { super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, "<"); + this.version2 = version2; } @Override - public boolean toBoolean() { - return leftSide.toNumber() < rightSide.toNumber(); + public Object getResult() { + if (version2) { + return EcmaScript.compare(leftSide.getResult(), rightSide.getResult()); + } else { + //For SWF 4 and older, it should return 1 or 0 + return Action.toFloatPoint(leftSide.getResult()) < Action.toFloatPoint(rightSide.getResult()); + } } @Override public GraphTargetItem invert() { - return new GeTreeItem(src, leftSide, rightSide); + return new GeTreeItem(src, leftSide, rightSide, version2); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java index d916e8405..e2195085e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,10 +28,10 @@ public class ModuloTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - if (Double.compare(rightSide.toNumber(), 0) == 0) { + public Object getResult() { + if (Double.compare(EcmaScript.toNumber(rightSide.getResult()), 0) == 0) { return Double.NaN; } - return ((int) leftSide.toNumber()) % ((int) rightSide.toNumber()); + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) % ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/MultiplyTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/MultiplyTreeItem.java index ade271bba..ca47d05be 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/MultiplyTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/MultiplyTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class MultiplyTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return leftSide.toNumber() * rightSide.toNumber(); + public Object getResult() { + return (EcmaScript.toNumber(leftSide.getResult())) * (EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NegTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NegTreeItem.java index 1a453dda5..e1638f0f8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NegTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NegTreeItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.treemodel.operations; import com.jpexs.decompiler.flash.action.treemodel.TreeItem; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -27,7 +28,7 @@ public class NegTreeItem extends UnaryOpItem { } @Override - public double toNumber() { - return -value.toNumber(); + public Object getResult() { + return -EcmaScript.toNumber(value.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NeqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NeqTreeItem.java index 5fbd24adb..5a479b78d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NeqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/NeqTreeItem.java @@ -16,6 +16,8 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -23,17 +25,25 @@ import com.jpexs.decompiler.flash.graph.LogicalOpItem; public class NeqTreeItem extends BinaryOpItem implements LogicalOpItem { - public NeqTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) { + boolean version2; + + public NeqTreeItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide, boolean version2) { super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "!="); + this.version2 = version2; } @Override - public boolean toBoolean() { - return (leftSide.toNumber() != rightSide.toNumber()) || (leftSide.toBoolean() != rightSide.toBoolean()); + public Object getResult() { + if (version2) { + return !EcmaScript.equals(leftSide.getResult(), rightSide.getResult()); + } else { + //For SWF 4 and older, it should return 1 or 0 + return (Action.toFloatPoint(leftSide.getResult()) != Action.toFloatPoint(rightSide.getResult())); + } } @Override public GraphTargetItem invert() { - return new EqTreeItem(src, leftSide, rightSide); + return new EqTreeItem(src, leftSide, rightSide, version2); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/OrTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/OrTreeItem.java index 8ca7d40fc..da7dbf84b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/OrTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/OrTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class OrTreeItem extends BinaryOpItem { } @Override - public boolean toBoolean() { - return leftSide.toBoolean() || rightSide.toBoolean(); + public Object getResult() { + return EcmaScript.toBoolean(leftSide.getResult()) || EcmaScript.toBoolean(rightSide.getResult()); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreDecrementTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreDecrementTreeItem.java index 1ff7c4fac..6bf222430 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreDecrementTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreDecrementTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -27,7 +28,7 @@ public class PreDecrementTreeItem extends UnaryOpItem { } @Override - public double toNumber() { - return value.toNumber() - 1; + public Object getResult() { + return EcmaScript.toNumber(value.getResult()) - 1; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreIncrementTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreIncrementTreeItem.java index 7a0ca835c..5163cde88 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreIncrementTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/PreIncrementTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.graph.UnaryOpItem; @@ -27,7 +28,7 @@ public class PreIncrementTreeItem extends UnaryOpItem { } @Override - public double toNumber() { - return value.toNumber() + 1; + public Object getResult() { + return EcmaScript.toNumber(value.getResult()) + 1; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/RShiftTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/RShiftTreeItem.java index a029b92fa..b4c7ee37c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/RShiftTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/RShiftTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class RShiftTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) >> ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) >> ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictEqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictEqTreeItem.java index cf5aba58f..f1f7dbc23 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictEqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictEqTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,11 @@ public class StrictEqTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return (leftSide.toBoolean() == rightSide.toBoolean()) && (leftSide.toNumber() == rightSide.toNumber()); + public Object getResult() { + Object x = leftSide.getResult(); + Object y = rightSide.getResult(); + return EcmaScript.type(x) == EcmaScript.type(y) + && EcmaScript.equals(x, y); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictNeqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictNeqTreeItem.java index 42e1a1738..6bc6b968d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictNeqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/StrictNeqTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,11 @@ public class StrictNeqTreeItem extends BinaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - return (leftSide.toBoolean() != rightSide.toBoolean()) && (leftSide.toNumber() != rightSide.toNumber()); + public Object getResult() { + Object x = leftSide.getResult(); + Object y = rightSide.getResult(); + return EcmaScript.type(x) != EcmaScript.type(y) + || (!EcmaScript.equals(x, y)); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/SubtractTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/SubtractTreeItem.java index ba9916a99..6ef2a0fb8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/SubtractTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/SubtractTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -28,8 +29,8 @@ public class SubtractTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return leftSide.toNumber() - rightSide.toNumber(); + public Object getResult() { + return EcmaScript.toNumber(leftSide.getResult()) - EcmaScript.toNumber(rightSide.getResult()); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/URShiftTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/URShiftTreeItem.java index a65a7e22d..4d8852d76 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/URShiftTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/URShiftTreeItem.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.treemodel.operations; +import com.jpexs.decompiler.flash.ecma.*; import com.jpexs.decompiler.flash.graph.BinaryOpItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -27,7 +28,7 @@ public class URShiftTreeItem extends BinaryOpItem { } @Override - public double toNumber() { - return ((int) leftSide.toNumber()) >>> ((int) rightSide.toNumber()); + public Object getResult() { + return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) >>> ((long) (double) EcmaScript.toNumber(rightSide.getResult())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java b/trunk/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java new file mode 100644 index 000000000..da24e3b16 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java @@ -0,0 +1,295 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.ecma; + +/** + * + * @author JPEXS + */ +public class EcmaScript { + + public static Double toNumber(Object o) { + if (o == null) { + return 0.0; + } + if (o instanceof Undefined) { + return Double.NaN; + } + if (o instanceof Null) { + return 0.0; + } + if (o instanceof Boolean) { + return (Boolean) o ? 1.0 : 0.0; + } + if (o instanceof Double) { + return (Double) o; + } + if (o instanceof Long) { + return (double) (long) (Long) o; + } + if (o instanceof Integer) { + return (double) (int) (Integer) o; + } + if (o instanceof String) { + try { + return Double.parseDouble((String) o); + } catch (NumberFormatException nfe) { + return Double.NaN; + } + } + //TODO:ToPrimitive + return 0.0; + } + + public static EcmaType type(Object o) { + if (o == null) { + return EcmaType.NULL; + } + if (o.getClass() == String.class) { + return EcmaType.STRING; + } + if (o.getClass() == Integer.class) { + return EcmaType.NUMBER; + } + if (o.getClass() == Double.class) { + return EcmaType.NUMBER; + } + if (o.getClass() == Long.class) { + return EcmaType.NUMBER; + } + + if (o.getClass() == Null.class) { + return EcmaType.NULL; + } + if (o.getClass() == Undefined.class) { + return EcmaType.UNDEFINED; + } + return EcmaType.OBJECT; + } + + public static Object compare(Object x, Object y) { + Object px = x; + Object py = y; + /*if (leftFirst) { + px = x; //toPrimitive + py = y; //toPrimitive + } else { + py = y; //toPrimitive + px = x; //toPrimitive + }*/ + if (type(px) != EcmaType.STRING || type(py) != EcmaType.STRING) { + Double nx = toNumber(px); + Double ny = toNumber(py); + if (nx.isNaN()) { + return new Undefined(); + } + if (ny.isNaN()) { + return new Undefined(); + } + if (((Double) nx).compareTo((Double) ny) == 0) { + return false; + } + if ((Double.compare((Double) nx, -0.0) == 0) && (Double.compare((Double) ny, 0.0) == 0)) { + return false; + } + if ((Double.compare((Double) nx, 0.0) == 0) && (Double.compare((Double) ny, -0.0) == 0)) { + return false; + } + if (nx.isInfinite() && nx > 0) { + return false; + } + if (ny.isInfinite() && ny > 0) { + return true; + } + if (nx.isInfinite() && nx < 0) { + return false; + } + if (ny.isInfinite() && ny < 0) { + return true; + } + if (nx.compareTo(ny) < 0) { + return true; + } + return false; + } else {//Both are STRING + String sx = (String) px; + String sy = (String) py; + + if (sx.startsWith(sy)) { + return false; + } + if (sy.startsWith(sx)) { + return true; + } + int len = sx.length() > sy.length() ? sx.length() : sy.length(); + for (int k = 0; k < len; k++) { + int m = 0; + int n = 0; + if (sx.length() > k) { + m = sx.charAt(k); + } + if (sy.length() > k) { + n = sy.charAt(k); + } + if (m != n) { + if (m < n) { + return true; + } else { + return false; + } + } + } + return false; + } + } + + public static boolean equals(Object x, Object y) { + EcmaType typeX = type(x); + EcmaType typeY = type(y); + if (typeX == typeY) { + if (typeX == null) { + return true; + } + if (typeX == EcmaType.NULL) { + return true; + } + if (typeX == EcmaType.UNDEFINED) { + return true; + } + if (typeX == EcmaType.NUMBER) { + if (x instanceof Integer) { + x = Double.valueOf((Integer) x); + } + if (x instanceof Long) { + x = Double.valueOf((Long) x); + } + if (y instanceof Integer) { + y = Double.valueOf((Integer) y); + } + if (y instanceof Long) { + y = Double.valueOf((Long) y); + } + if (((Double) x).isNaN()) { + return false; + } + if (((Double) y).isNaN()) { + return false; + } + if (((Double) x).compareTo((Double) y) == 0) { + return true; + } + if ((Double.compare((Double) x, -0.0) == 0) && (Double.compare((Double) y, 0.0) == 0)) { + return true; + } + if ((Double.compare((Double) x, 0.0) == 0) && (Double.compare((Double) y, -0.0) == 0)) { + return true; + } + return false; + } + if (typeX == EcmaType.STRING) { + return ((String) x).equals((String) y); + } + if (typeX == EcmaType.BOOLEAN) { + return x == y; + } + return x == y; + } + if ((typeX == EcmaType.NULL) && (typeY == EcmaType.UNDEFINED)) { + return true; + } + if ((typeX == EcmaType.UNDEFINED) && (typeY == EcmaType.NULL)) { + return true; + } + + if ((typeX == EcmaType.NUMBER) && (typeY == EcmaType.STRING)) { + return equals(x, toNumber(y)); + } + if ((typeX == EcmaType.STRING) && (typeY == EcmaType.NUMBER)) { + return equals(toNumber(x), y); + } + if (typeX == EcmaType.BOOLEAN) { + return equals(toNumber(x), y); + } + if (typeY == EcmaType.BOOLEAN) { + return equals(x, toNumber(y)); + } + if (typeX == EcmaType.STRING || typeX == EcmaType.NUMBER) { + //y is object + //return ecmaEquals(ecmaToPrimitive(x), y); + } + if (typeY == EcmaType.STRING || typeY == EcmaType.NUMBER) { + //x is object + //return ecmaEquals(x, ecmaToPrimitive(y)); + } + return false; + } + + public static boolean toBoolean(Object o) { + if (o == null) { + return false; + } + if (o instanceof Undefined) { + return false; + } + if (o instanceof Null) { + return false; + } + if (o instanceof Boolean) { + return (Boolean) o; + } + if (o instanceof Long) { + return ((Long) o) != 0; + } + if (o instanceof Integer) { + return ((Integer) o) != 0; + } + if (o instanceof Double) { + Double d = (Double) o; + if (d.isNaN()) { + return false; + } + if (Double.compare(d, 0) == 0) { + return false; + } + return true; + } + if (o instanceof String) { + String s = (String) o; + return !s.equals(""); + } + return true; //other Object + } + + public static Long toUint32(Object o) { + Double n = toNumber(o); + if (n.isNaN()) { + return 0L; + } + if (Double.compare(n, 0.0) == 0) { + return 0L; + } + if (Double.compare(n, -0.0) == 0) { + return 0L; + } + if (Double.isInfinite(n)) { + return 0L; + } + Long posInt = (long) (double) (Math.signum(n) * Math.floor(Math.abs(n))); + posInt = posInt % (1 << 32); + return posInt; + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/ecma/EcmaType.java b/trunk/src/com/jpexs/decompiler/flash/ecma/EcmaType.java new file mode 100644 index 000000000..e22b880a1 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/ecma/EcmaType.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.ecma; + +/** + * + * @author JPEXS + */ +public enum EcmaType { + + NULL, + STRING, + NUMBER, + UNDEFINED, + OBJECT, + BOOLEAN +} diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/Null.java b/trunk/src/com/jpexs/decompiler/flash/ecma/Null.java similarity index 91% rename from trunk/src/com/jpexs/decompiler/flash/action/swf4/Null.java rename to trunk/src/com/jpexs/decompiler/flash/ecma/Null.java index 0d395b0e5..0aad7af44 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/Null.java +++ b/trunk/src/com/jpexs/decompiler/flash/ecma/Null.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.action.swf4; +package com.jpexs.decompiler.flash.ecma; public class Null { diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/Undefined.java b/trunk/src/com/jpexs/decompiler/flash/ecma/Undefined.java similarity index 91% rename from trunk/src/com/jpexs/decompiler/flash/action/swf4/Undefined.java rename to trunk/src/com/jpexs/decompiler/flash/ecma/Undefined.java index f8d9ce1fc..541130a09 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/Undefined.java +++ b/trunk/src/com/jpexs/decompiler/flash/ecma/Undefined.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.action.swf4; +package com.jpexs.decompiler.flash.ecma; public class Undefined { diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/BinaryOpItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/BinaryOpItem.java index e737424ca..42f6e3196 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/BinaryOpItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/BinaryOpItem.java @@ -126,4 +126,16 @@ public abstract class BinaryOpItem extends GraphTargetItem { } return true; } + + /*@Override + public boolean toBoolean() { + double val=toNumber(); + if(Double.isNaN(val)){ + return false; + } + if(Double.compare(val, 0)==0){ + return false; + } + return true; + }*/ } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/DuplicateItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/DuplicateItem.java index f5ef95a88..01aaee34f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/DuplicateItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/DuplicateItem.java @@ -30,13 +30,8 @@ public class DuplicateItem extends GraphTargetItem { } @Override - public boolean toBoolean() { - return value.toBoolean(); - } - - @Override - public double toNumber() { - return value.toNumber(); + public Object getResult() { + return value.getResult(); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java index 0187163c0..fc1774713 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java @@ -54,6 +54,9 @@ public abstract class GraphTargetItem { List ret = new ArrayList<>(); ret.add(new GraphSourceItemPos(src, pos)); ret.addAll(moreSrc); + if (value != null) { + ret.addAll(value.getNeededSources()); + } return ret; } @@ -111,12 +114,15 @@ public abstract class GraphTargetItem { return false; } - public double toNumber() { - return 0; - } + /*public double toNumber() { + return 0; + } - public boolean toBoolean() { - return Double.compare(toNumber(), 0.0) != 0; + public boolean toBoolean() { + return Double.compare(toNumber(), 0.0) != 0; + }*/ + public Object getResult() { + return null; } public String toStringNoQuotes(List localData) { diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/NotItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/NotItem.java index 5a8f63c23..3e04994d5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/NotItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/NotItem.java @@ -1,5 +1,7 @@ package com.jpexs.decompiler.flash.graph; +import com.jpexs.decompiler.flash.ecma.EcmaScript; + /** * * @author JPEXS @@ -11,11 +13,22 @@ public class NotItem extends UnaryOpItem implements LogicalOpItem { } @Override - public boolean toBoolean() { - boolean ret = !value.toBoolean(); + public Object getResult() { + Object ret = EcmaScript.toBoolean(value.getResult()); + if (ret == Boolean.TRUE) { + return Boolean.FALSE; + } + if (ret == Boolean.FALSE) { + return Boolean.TRUE; + } return ret; } + @Override + public boolean isCompileTime() { + return value.isCompileTime(); + } + @Override public GraphTargetItem invert() { return value; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 2b725dd56..86b44ac0f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -526,7 +526,7 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection abcList = new ArrayList<>(); getActionScript3(objs, abcList); if (!abcList.isEmpty()) { - abcPanel = new ABCPanel(abcList); + abcPanel = new ABCPanel(abcList, swf); detailPanel.add(abcPanel.tabbedPane, DETAILCARDAS3NAVIGATOR); menuTools.add(miGotoDocumentClass); } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index d1c582057..69012bd10 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -17,6 +17,8 @@ package com.jpexs.decompiler.flash.gui.abc; import com.jpexs.decompiler.flash.Configuration; +import com.jpexs.decompiler.flash.KeyValue; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; @@ -42,7 +44,6 @@ import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -91,7 +92,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { searchIgnoreCase = ignoreCase; searchRegexp = regexp; ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); - HashMap allpacks = clModel.getList(); + List> allpacks = clModel.getList(); found = new ArrayList<>(); Pattern pat = null; if (regexp) { @@ -99,10 +100,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { } else { pat = Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0); } - for (ScriptPack p : allpacks.values()) { - decompiledTextArea.cacheScriptPack(p, list); - if (pat.matcher(decompiledTextArea.getCachedText(p)).find()) { - found.add(p); + for (KeyValue item : allpacks) { + decompiledTextArea.cacheScriptPack(item.value, list); + if (pat.matcher(decompiledTextArea.getCachedText(item.value)).find()) { + found.add(item.value); } } @@ -238,7 +239,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { } @SuppressWarnings("unchecked") - public ABCPanel(List list) { + public ABCPanel(List list, SWF swf) { DefaultSyntaxKit.initKit(); @@ -339,7 +340,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { JPanel treePanel = new JPanel(); treePanel.setLayout(new BorderLayout()); - treePanel.add(new JScrollPane(classTree = new ClassesListTree(list, this)), BorderLayout.CENTER); + treePanel.add(new JScrollPane(classTree = new ClassesListTree(list, this, swf)), BorderLayout.CENTER); JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BorderLayout()); filterPanel.add(filterField, BorderLayout.CENTER); @@ -466,17 +467,13 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { public void hilightScript(String name) { ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); - HashMap list = clModel.getList(); - ClassPath path = null; - for (ClassPath p : list.keySet()) { - if (p.toString().equals(name)) { - path = p; + ScriptPack pack = null; + for (KeyValue item : clModel.getList()) { + if (item.key.toString().equals(name)) { + pack = item.value; + break; } } - if (path == null) { - return; - } - ScriptPack pack = clModel.getList().get(path); if (pack != null) { hilightScript(pack); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java index 62da0df75..1e2836ee8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java @@ -16,17 +16,16 @@ */ package com.jpexs.decompiler.flash.gui.abc; -import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.KeyValue; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; -import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; @@ -38,8 +37,9 @@ import javax.swing.tree.TreeSelectionModel; public class ClassesListTree extends JTree implements TreeSelectionListener { private List abcList; - public HashMap treeList; + public List> treeList; private ABCPanel abcPanel; + private SWF swf; public void selectClass(int classIndex) { ClassesListTreeModel model = (ClassesListTreeModel) getModel(); @@ -49,8 +49,9 @@ public class ClassesListTree extends JTree implements TreeSelectionListener { scrollPathToVisible(treePath); } - public ClassesListTree(List list, ABCPanel abcPanel) { + public ClassesListTree(List list, ABCPanel abcPanel, SWF swf) { this.abcList = list; + this.swf = swf; this.treeList = getTreeList(list); this.abcPanel = abcPanel; setModel(new ClassesListTreeModel(this.treeList)); @@ -96,19 +97,9 @@ public class ClassesListTree extends JTree implements TreeSelectionListener { return selectedScripts; } - public HashMap getTreeList(List list) { - HashMap ret = new HashMap<>(); - for (ABCContainerTag tag : list) { - ABC abc = tag.getABC(); - for (int i = 0; i < abc.script_info.length; i++) { - ScriptInfo script = abc.script_info[i]; - HashMap packs = script.getPacks(abc, i); - for (ClassPath path : packs.keySet()) { - ret.put(path, packs.get(path)); - } - } - } - return ret; + public List> getTreeList(List list) { + + return swf.getAS3Packs(); } public void setDoABCTags(List list) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java index e8e49d329..78e0054ab 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java @@ -16,12 +16,13 @@ */ package com.jpexs.decompiler.flash.gui.abc; +import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import static com.jpexs.decompiler.flash.gui.AppStrings.translate; -import java.util.HashMap; +import java.util.List; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; @@ -77,28 +78,28 @@ class ClassIndexVisitor implements TreeVisitor { public class ClassesListTreeModel implements TreeModel { private Tree classTree = new Tree(); - private HashMap list; + private List> list; - public HashMap getList() { + public List> getList() { return list; } - public ClassesListTreeModel(HashMap list) { + public ClassesListTreeModel(List> list) { this(list, null); } - public ClassesListTreeModel(HashMap list, String filter) { - for (ClassPath path : list.keySet()) { + public ClassesListTreeModel(List> list, String filter) { + for (KeyValue item : list) { if (filter != null) { if (!filter.equals("")) { - if (!path.toString().contains(filter)) { + if (!item.key.toString().contains(filter)) { continue; } } } //String nsName = path.contains(".") ? path.substring(path.lastIndexOf(".") + 1) : path; //String packageName = path.contains(".") ? path.substring(0, path.lastIndexOf(".")) : ""; - classTree.add(path.className, path.packageStr, list.get(path)); + classTree.add(item.key.className, item.key.packageStr, item.value); } this.list = list;