From 7669a6747c3dee800722d5a4deac8787f54bc2fa Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Fri, 24 Jul 2015 20:09:02 +0200 Subject: [PATCH] #489 Hex decode very large integers --- .../abc/avm2/model/IntegerValueAVM2Item.java | 70 +++++++++++++++++++ .../action/model/DirectValueActionItem.java | 6 +- .../flash/configuration/Configuration.java | 4 ++ .../flash/tags/DefineBitsLossless2Tag.java | 2 +- .../locales/AdvancedSettingsDialog.properties | 3 + .../AdvancedSettingsDialog_hu.properties | 3 + 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java index f86c63e09..b1201dab2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/IntegerValueAVM2Item.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushByteIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushIntIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushShortIns; import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.DottedChain; @@ -31,6 +32,7 @@ import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.IntegerValueTypeItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -45,6 +47,74 @@ public class IntegerValueAVM2Item extends NumberValueAVM2Item implements Integer @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { + if (Configuration.smartNumberFormatting.get()) { + if (value >= 256 && value <= 0xffffffffL) { + int intVal = (int) (long) (value & 0xffffff); + int r = (intVal >> 16) & 0xff; + int g = (intVal >> 8) & 0xff; + int b = intVal & 0xff; + if ((r == b && b == g) // gray + || (((intVal & 0x0f0000) == 0 || (intVal & 0x0f0000) == 0x0f0000) // a(0/F)b(0/F)c(0/F) + && ((intVal & 0x000f00) == 0 || (intVal & 0x000f00) == 0x000f00) + && ((intVal & 0x00000f) == 0 || (intVal & 0x00000f) == 0x00000f)) + || ((((intVal & 0xf00000) >> 20) == ((intVal & 0x0f0000) >> 16)) // aabbcc + && (((intVal & 0x00f000) >> 12) == ((intVal & 0x000f00) >> 8)) + && (((intVal & 0x0000f0) >> 4) == ((intVal & 0x00000f))))) { + return writer.append("0x").append(Long.toHexString(value)); + } + } + + long value2 = (long) value; + if (value2 > 0 && value2 % 60 == 0) { + int thousandCount = 0; + value2 /= 60; + boolean isHour = false; + boolean isDay = false; + if (value2 % 60 == 0) { + value2 /= 60; + isHour = true; + if (value2 % 24 == 0) { + value2 /= 24; + isDay = true; + } + } + + // check milli, micro and nanoseconds + while (thousandCount < 3) { + if (value2 % 1000 == 0) { + thousandCount++; + value2 /= 1000; + } else { + break; + } + } + + if (value2 < 1000) { + List factors = new ArrayList<>(); + if (value2 > 1) { + factors.add((int) value2); + } + if (isDay) { + factors.add(24); + } + if (isHour) { + factors.add(60); + } + factors.add(60); + for (int i = 0; i < thousandCount; i++) { + factors.add(1000); + } + for (int i = 0; i < factors.size(); i++) { + if (i != 0) { + writer.append(" * "); + } + writer.append(factors.get(i)); + } + return writer; + } + } + } + return writer.append(value); } 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 851b21771..78c69670c 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 @@ -149,19 +149,19 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue { public String toStringNoH(ConstantPool constants) { if (value instanceof Double) { if (Double.compare((double) (Double) value, 0) == 0) { - return ("0"); + return "0"; } } if (value instanceof Float) { if (Float.compare((float) (Float) value, 0) == 0) { - return ("0"); + return "0"; } } if (value instanceof String) { return (String) value; } if (value instanceof ConstantIndex) { - return (this.constants.get(((ConstantIndex) value).index)); + return this.constants.get(((ConstantIndex) value).index); } return value.toString(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index fd9a6f35a..662ffe089 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -487,6 +487,10 @@ public class Configuration { @ConfigurationCategory("script") public static final ConfigurationItem ignoreCLikePackages = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("script") + public static final ConfigurationItem smartNumberFormatting = null; + private enum OSId { WINDOWS, OSX, UNIX diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java index 9de60ad30..11c736cdf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java @@ -165,7 +165,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag { int a = (argb >> 24) & 0xff; int r = (argb >> 16) & 0xff; int g = (argb >> 8) & 0xff; - int b = (argb) & 0xff; + int b = argb & 0xff; r = r * a / 255; g = g * a / 255; diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index af3740d03..8aff7357f 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -371,3 +371,6 @@ config.description.ignoreCLikePackages = FlashCC/Alchemy packages cannot usually config.name.overwriteExistingFiles = Overwrite the existing files config.description.overwriteExistingFiles = Overwrite the existing files during export. Currently only for AS2/3 scripts + +config.name.smartNumberFormatting = Use smart number formatting +config.description.smartNumberFormatting = Format special numbers (for example colors and times) diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties index 6260dc64d..e920f8a4b 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties @@ -371,3 +371,6 @@ config.description.ignoreCLikePackages = FlashCC/Alchemy csomagok \u00e1ltal\u00 config.name.overwriteExistingFiles = L\u00e9tez\u0151 f\u00e1jlok fel\u00fcl\u00edr\u00e1sa config.description.overwriteExistingFiles = Fel\u00fcl\u00edrja a l\u00e9tez\u0151 f\u00e1jlokat export\u00e1l\u00e1s sor\u00e1n. Jelenleg csak az AS2/3 szkriptekre \u00e9rv\u00e9nyes + +config.name.smartNumberFormatting = Okos sz\u00e1m form\u00e1z\u00e1s haszn\u00e1lata +config.description.smartNumberFormatting = A speci\u00e1lis sz\u00e1mokat (mint p\u00e9ld\u00e1ul sz\u00ednek \u00e9s id\u0151k) felismeri