Changed: #2228 AS1/2/3 bitwise operations use hexadecimal operands

This commit is contained in:
Jindra Petřík
2024-08-01 22:24:01 +02:00
parent 5fb20268b2
commit 9683dc6a6f
23 changed files with 226 additions and 33 deletions

View File

@@ -24,8 +24,6 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +31,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitAndAVM2Item extends BinaryOpItem implements CompoundableBinaryOp {
public class BitAndAVM2Item extends BitwiseBinaryOpAVM2Item {
public BitAndAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEAND, leftSide, rightSide, "&", "Number", "Number");
@@ -62,5 +60,5 @@ public class BitAndAVM2Item extends BinaryOpItem implements CompoundableBinaryOp
List<GraphSourceItem> ret = new ArrayList<>();
ret.add(new AVM2Instruction(0, AVM2Instructions.BitAnd, null));
return ret;
}
}
}

View File

@@ -19,11 +19,14 @@ package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.UnaryOpItem;
import java.util.List;
@@ -54,4 +57,20 @@ public class BitNotAVM2Item extends UnaryOpItem {
return TypeItem.INT; //?
//return TypeItem.UNBOUNDED;
}
@Override
protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (operand instanceof IntegerValueAVM2Item) {
Integer val = ((IntegerValueAVM2Item)operand).value;
if (val > 9) {
String valHex = Integer.toHexString(val).toUpperCase();
if (valHex.length() % 2 == 1) {
valHex = "0" + valHex;
}
writer.append("0x" + valHex);
return;
}
}
operand.toString(writer, localData, "");
}
}

View File

@@ -24,8 +24,6 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +31,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitOrAVM2Item extends BinaryOpItem implements CompoundableBinaryOp {
public class BitOrAVM2Item extends BitwiseBinaryOpAVM2Item {
public BitOrAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEOR, leftSide, rightSide, "|", "Number", "Number");

View File

@@ -24,8 +24,6 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +31,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitXorAVM2Item extends BinaryOpItem implements CompoundableBinaryOp {
public class BitXorAVM2Item extends BitwiseBinaryOpAVM2Item {
public BitXorAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEXOR, leftSide, rightSide, "^", "Number", "Number");

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2010-2024 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
import com.jpexs.decompiler.graph.model.LocalData;
/**
*
* @author JPEXS
*/
public abstract class BitwiseBinaryOpAVM2Item extends BinaryOpItem implements CompoundableBinaryOp {
public BitwiseBinaryOpAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator, String coerceLeft, String coerceRight) {
super(instruction, lineStartItem, precedence, leftSide, rightSide, operator, coerceLeft, coerceRight);
}
@Override
protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (operand instanceof IntegerValueAVM2Item) {
Integer val = ((IntegerValueAVM2Item)operand).value;
if (val > 9) {
String valHex = Integer.toHexString(val).toUpperCase();
if (valHex.length() % 2 == 1) {
valHex = "0" + valHex;
}
writer.append("0x" + valHex);
return;
}
}
operand.toString(writer, localData, "");
}
}

View File

@@ -17,7 +17,6 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitAnd;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
@@ -25,7 +24,6 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +31,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitAndActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public class BitAndActionItem extends BitwiseBinaryOpActionItem {
public BitAndActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEAND, leftSide, rightSide, "&", "int", "int");
@@ -63,5 +61,5 @@ public class BitAndActionItem extends BinaryOpItem implements CompoundableBinary
List<GraphSourceItem> ret = new ArrayList<>();
ret.add(new ActionBitAnd());
return ret;
}
}
}

View File

@@ -17,7 +17,6 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.swf5.ActionBitOr;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
@@ -25,7 +24,6 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +31,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitOrActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public class BitOrActionItem extends BitwiseBinaryOpActionItem {
public BitOrActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEOR, leftSide, rightSide, "|", "int", "int");

View File

@@ -17,7 +17,6 @@
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.swf5.ActionBitXor;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
@@ -27,7 +26,6 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.ArrayList;
import java.util.List;
@@ -36,7 +34,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BitXorActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public class BitXorActionItem extends BitwiseBinaryOpActionItem {
public BitXorActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_BITWISEXOR, leftSide, rightSide, "^", "int", "int");

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2010-2024 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.action.model.CompoundableBinaryOpAs12;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.LocalData;
/**
*
* @author JPEXS
*/
public abstract class BitwiseBinaryOpActionItem extends BinaryOpItem implements CompoundableBinaryOpAs12 {
public BitwiseBinaryOpActionItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator, String coerceLeft, String coerceRight) {
super(instruction, lineStartItem, precedence, leftSide, rightSide, operator, coerceLeft, coerceRight);
}
@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 (val > 9) {
String valHex = Long.toHexString(val).toUpperCase();
if (valHex.length() % 2 == 1) {
valHex = "0" + valHex;
}
writer.append("0x" + valHex);
return;
}
}
operand.toString(writer, localData, "");
}
}

View File

@@ -73,10 +73,10 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
int leftPrecedence = leftSide.getPrecedence();
if (leftPrecedence > precedence && leftPrecedence != GraphTargetItem.NOPRECEDENCE) {
writer.append("(");
leftSide.toString(writer, localData, ""); //coerceLeft);
operandToString(leftSide, writer, localData);
writer.append(")");
} else {
leftSide.toString(writer, localData, ""); //coerceLeft);
operandToString(leftSide, writer, localData);
}
writer.append(" ");
@@ -86,13 +86,17 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
int rightPrecedence = rightSide.getPrecedence();
if (rightPrecedence >= precedence && rightPrecedence != GraphTargetItem.NOPRECEDENCE) {
writer.append("(");
rightSide.toString(writer, localData, ""); //coerceRight);
operandToString(rightSide, writer, localData);
writer.append(")");
} else {
rightSide.toString(writer, localData, ""); //coerceRight);
operandToString(rightSide, writer, localData);
}
return writer;
}
protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException {
operand.toString(writer, localData, "");
}
@Override
public List<GraphSourceItemPos> getNeededSources() {

View File

@@ -53,10 +53,10 @@ public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
if (value != null) {
if (value.getPrecedence() > precedence) {
writer.append("(");
value.toString(writer, localData, ""); //coerce);
operandToString(value, writer, localData);
writer.append(")");
} else {
value.toString(writer, localData, ""); //coerce);
operandToString(value, writer, localData);
}
} else {
writer.append("null");
@@ -146,4 +146,8 @@ public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
int hash = 3;
return hash;
}
protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException {
operand.toString(writer, localData, "");
}
}