From d5029139bbf642031d997c4adb569b08b41ed771 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 24 Sep 2015 22:54:55 +0200 Subject: [PATCH] fixes --- .../jpexs/decompiler/flash/action/Action.java | 10 ++++-- .../action/model/AsciiToCharActionItem.java | 6 ++-- .../action/model/DirectValueActionItem.java | 4 +-- .../action/model/MBAsciiToCharActionItem.java | 6 ++-- .../flash/action/swf5/ActionDefineLocal.java | 10 +++++- .../flash/ecma/EcmaFloatingDecimal.java | 32 ++++++++++--------- .../decompiler/flash/ecma/EcmaScript.java | 6 +++- 7 files changed, 46 insertions(+), 28 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index ccdf2a633..eb0e01b22 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -52,7 +52,9 @@ import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; import com.jpexs.decompiler.flash.action.swf5.ActionConstantPool; import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction; import com.jpexs.decompiler.flash.action.swf5.ActionEquals2; +import com.jpexs.decompiler.flash.action.swf5.ActionWith; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; +import com.jpexs.decompiler.flash.action.swf7.ActionTry; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -976,9 +978,11 @@ public abstract class Action implements GraphSourceItem { List out; try { HashMap regNames = cnt.getRegNames(); - for (Map.Entry e : registerNames.entrySet()) { - if (!regNames.containsKey(e.getKey())) { - regNames.put(e.getKey(), e.getValue()); + if (action instanceof ActionWith || action instanceof ActionTry) { + for (Map.Entry e : registerNames.entrySet()) { + if (!regNames.containsKey(e.getKey())) { + regNames.put(e.getKey(), e.getValue()); + } } } out = ActionGraph.translateViaGraph(regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName)); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/AsciiToCharActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/AsciiToCharActionItem.java index 664434d64..ced11c1e0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/AsciiToCharActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/AsciiToCharActionItem.java @@ -52,12 +52,12 @@ public class AsciiToCharActionItem extends ActionItem { @Override public Object getResult() { - Double res = EcmaScript.toNumber(value.getResult()); - if (Double.isNaN(res) || Double.compare(res, 0) == 0) { + int res = (int) (double) (EcmaScript.toNumber(value.getResult())); + if (res == 0) { return ""; } - return ((Character) (char) res.intValue()).toString(); + return ((Character) (char) res).toString(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java index 07c0a554f..95a0a518a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java @@ -157,7 +157,7 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { if (value instanceof String) { - return writer.append("\"").append(Helper.escapeActionScriptString(EcmaScript.toString(value))).append("\""); + return writer.append("\"").append(Helper.escapeActionScriptString((String) value)).append("\""); } if (value instanceof ConstantIndex) { return writer.append("\"").append(Helper.escapeActionScriptString(this.constants.get(((ConstantIndex) value).index))).append("\""); @@ -165,7 +165,7 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue { if (value instanceof RegisterNumber) { return writer.append(((RegisterNumber) value).translate()); } - return writer.append(EcmaScript.toString(value)); + return writer.append(EcmaScript.toString(value, true)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/MBAsciiToCharActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/MBAsciiToCharActionItem.java index 87ac0e30b..b22d6c62b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/MBAsciiToCharActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/MBAsciiToCharActionItem.java @@ -52,12 +52,12 @@ public class MBAsciiToCharActionItem extends ActionItem { @Override public Object getResult() { - Double res = EcmaScript.toNumber(value.getResult()); - if (Double.isNaN(res) || Double.compare(res, 0) == 0) { + int res = (int) (double) (EcmaScript.toNumber(value.getResult())); + if (res == 0) { return ""; } - return ((Character) (char) res.intValue()).toString(); + return ((Character) (char) res).toString(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineLocal.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineLocal.java index 917e3610c..051628e47 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineLocal.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineLocal.java @@ -19,6 +19,8 @@ package com.jpexs.decompiler.flash.action.swf5; import com.jpexs.decompiler.flash.BaseLocalData; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.model.DefineLocalActionItem; +import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.model.LocalData; @@ -40,7 +42,13 @@ public class ActionDefineLocal extends Action { public void translate(TranslateStack stack, List output, HashMap regNames, HashMap variables, HashMap functions, int staticOperation, String path) { GraphTargetItem value = stack.pop(); GraphTargetItem name = stack.pop(); - variables.put(name.toStringNoQuotes(LocalData.empty), value); + String nameStr; + if (name instanceof DirectValueActionItem) { + nameStr = name.toStringNoQuotes(LocalData.empty); + } else { + nameStr = EcmaScript.toString(name.getResult()); + } + variables.put(nameStr, value); output.add(new DefineLocalActionItem(this, name, value)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaFloatingDecimal.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaFloatingDecimal.java index 7400d3413..b59cd759c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaFloatingDecimal.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaFloatingDecimal.java @@ -445,7 +445,7 @@ public class EcmaFloatingDecimal { /* * FIRST IMPORTANT CONSTRUCTOR: DOUBLE */ - public EcmaFloatingDecimal(double d) { + public EcmaFloatingDecimal(double d, boolean maxPrecision) { long dBits = Double.doubleToLongBits(d); long fractBits; int binExp; @@ -499,6 +499,19 @@ public class EcmaFloatingDecimal { binExp -= expBias; // call the routine that actually does all the hard work. dtoa(binExp, fractBits, nSignificantBits); + + if (!maxPrecision) { + if (nDigits > 15) { + nDigits = 15; + if (digits[15] >= '5') { + roundup(); + } + + while (nDigits > 0 && digits[nDigits - 1] == '0') { + nDigits--; + } + } + } } /* @@ -769,7 +782,7 @@ public class EcmaFloatingDecimal { * Thus we will need more than one digit if we're using * E-form */ - if (decExp <= -3 || decExp >= 8) { + if (decExp <= -6 || decExp >= 8) { high = low = false; } while (!low && !high) { @@ -822,7 +835,7 @@ public class EcmaFloatingDecimal { * Thus we will need more than one digit if we're using * E-form */ - if (decExp <= -3 || decExp >= 8) { + if (decExp <= -6 || decExp >= 8) { high = low = false; } while (!low && !high) { @@ -885,7 +898,7 @@ public class EcmaFloatingDecimal { * Thus we will need more than one digit if we're using * E-form */ - if (decExp <= -3 || decExp >= 8) { + if (decExp <= -6 || decExp >= 8) { high = low = false; } while (!low && !high) { @@ -924,17 +937,6 @@ public class EcmaFloatingDecimal { roundup(); } } - - if (nDigits > 15) { - nDigits = 15; - if (digits[15] >= '5') { - roundup(); - } - - while (nDigits > 0 && digits[nDigits - 1] == '0') { - nDigits--; - } - } } public String toString() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java index 0855d9415..db0e6a1e5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ecma/EcmaScript.java @@ -293,6 +293,10 @@ public class EcmaScript { } public static String toString(Object o) { + return toString(o, false); + } + + public static String toString(Object o, boolean maxPrecision) { if (o == null) { return "null"; } @@ -300,7 +304,7 @@ public class EcmaScript { if (o instanceof Number) { // http://www.ecma-international.org/ecma-262/5.1/#sec-9.8.1 Number n = (Number) o; - return new EcmaFloatingDecimal(n.doubleValue()).toJavaFormatString(); + return new EcmaFloatingDecimal(n.doubleValue(), maxPrecision).toJavaFormatString(); } return o.toString();