From d6683839cfa269438769022bee7e2e4a5c72c86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 2 May 2025 09:11:27 +0200 Subject: [PATCH] Fixed: #2355 AS3 Simplify expressions feature colliding with some other features like hex values --- CHANGELOG.md | 2 +- .../flash/abc/avm2/model/DoubleValueAVM2Item.java | 4 ++++ .../flash/abc/avm2/model/IntegerValueAVM2Item.java | 6 +++++- .../avm2/model/operations/BitwiseBinaryOpAVM2Item.java | 8 +++++--- .../flash/action/model/DirectValueActionItem.java | 5 +++++ .../model/operations/BitwiseBinaryOpActionItem.java | 5 +++-- .../src/com/jpexs/decompiler/graph/GraphTargetItem.java | 7 ++----- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33748a4d7..65bcf7fba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,7 @@ All notable changes to this project will be documented in this file. - [#2446] Nightly version asked for update to previous stable - [#2447] SVG import - gradients can inherit (href) from other gradient types (radial vs linear) - [#2450] Morphshape replace button/menu is not working (throws exception due to missing icon) -- [#2355] AS1/2 Simplify expressions feature colliding with some other features like hex values +- [#2355] AS1/2/3 Simplify expressions feature colliding with some other features like hex values - Exception on FFDec start when simple editor is on - [#2419] AS3 - There should be empty line after class header - AS 1/2/3 - Fast switching of scripts causing incorrect caret position remembered diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/DoubleValueAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/DoubleValueAVM2Item.java index 44f6be669..ae55d932b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/DoubleValueAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/DoubleValueAVM2Item.java @@ -113,4 +113,8 @@ public class DoubleValueAVM2Item extends NumberValueAVM2Item { return true; } + @Override + public long getAsLong() { + return (long)(double) value; + } } 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 0e59fac12..cf244ecd7 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 @@ -213,5 +213,9 @@ public class IntegerValueAVM2Item extends NumberValueAVM2Item implements Integer } return true; } - + + @Override + public long getAsLong() { + return (long) value; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/BitwiseBinaryOpAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/BitwiseBinaryOpAVM2Item.java index b1bd15897..e04be5c00 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/BitwiseBinaryOpAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/operations/BitwiseBinaryOpAVM2Item.java @@ -17,7 +17,9 @@ package com.jpexs.decompiler.flash.abc.avm2.model.operations; import com.jpexs.decompiler.flash.abc.avm2.graph.AVM2GraphTargetDialect; +import com.jpexs.decompiler.flash.abc.avm2.model.DoubleValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item; +import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -49,10 +51,10 @@ public abstract class BitwiseBinaryOpAVM2Item extends BinaryOpItem implements Co @Override protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException { - if (operand instanceof IntegerValueAVM2Item) { - Integer val = ((IntegerValueAVM2Item) operand).value; + if ((operand instanceof IntegerValueAVM2Item) || (operand instanceof DoubleValueAVM2Item)) { + long val = operand.getAsLong(); if (val > 9) { - String valHex = Integer.toHexString(val).toUpperCase(); + String valHex = Long.toHexString(val).toUpperCase(); if (valHex.length() % 2 == 1) { valHex = "0" + valHex; } 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 f54c465b0..acdfa9e5f 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 @@ -317,4 +317,9 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue { public String toString() { return "" + getResult(); } + + @Override + public long getAsLong() { + return (long) (double) EcmaScript.toNumberAs2(value); + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/BitwiseBinaryOpActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/BitwiseBinaryOpActionItem.java index bade394da..35e5ef915 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/BitwiseBinaryOpActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/BitwiseBinaryOpActionItem.java @@ -49,8 +49,9 @@ public abstract class BitwiseBinaryOpActionItem extends BinaryOpItem implements @Override protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException { - if ((operand instanceof DirectValueActionItem) && (((DirectValueActionItem) operand).value instanceof Long)) { - long val = (long) (Long) ((DirectValueActionItem) operand).value; + if ((operand instanceof DirectValueActionItem) + && ((((DirectValueActionItem) operand).value instanceof Long) || (((DirectValueActionItem) operand).value instanceof Double))) { + long val = operand.getAsLong(); if (val > 9) { String valHex = Long.toHexString(val).toUpperCase(); if (valHex.length() % 2 == 1) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index b72692774..b5af80d97 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.graph; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.DoubleValueAVM2Item; import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.ecma.EcmaScript; @@ -1065,11 +1066,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { * @return This as long */ public long getAsLong() { - if (this instanceof DirectValueActionItem) { - DirectValueActionItem dvai = (DirectValueActionItem) this; - return (long) (double) EcmaScript.toNumberAs2(dvai.value); - } - + //override as needed return 0; }