Fixed #2052 Detection of switches based on notequal operator

update license in header
This commit is contained in:
Jindra Petřík
2023-09-07 23:15:11 +02:00
parent 4402c0b5b7
commit 05d5fee409
19 changed files with 246 additions and 40 deletions

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2010-2023 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.
*/

View File

@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.NotEqualsTypeItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
@@ -34,7 +35,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class NeqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition {
public class NeqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition, NotEqualsTypeItem {
public NeqAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_EQUALITY, leftSide, rightSide, "!=", "", "");

View File

@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.NotEqualsTypeItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
@@ -34,7 +35,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class StrictNeqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition {
public class StrictNeqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondition, NotEqualsTypeItem {
public StrictNeqAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_EQUALITY, leftSide, rightSide, "!==", "", "");

View File

@@ -1,7 +1,5 @@
/* The following code was generated by JFlex 1.6.0 */
/*
* Copyright (C) 2010-2021 JPEXS, All rights reserved.
* Copyright (C) 2010-2023 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
@@ -16,7 +14,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
/* Flash assembler language lexer specification */
package com.jpexs.decompiler.flash.abc.avm2.parser.pcode;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;

View File

@@ -1,7 +1,5 @@
/* The following code was generated by JFlex 1.6.0 */
/*
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
* Copyright (C) 2010-2023 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
@@ -16,7 +14,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
/* Method info lexer specification */
package com.jpexs.decompiler.flash.abc.methodinfo_parser;

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.NotEqualsTypeItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
@@ -35,7 +36,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class NeqActionItem extends BinaryOpItem implements LogicalOpItem, Inverted {
public class NeqActionItem extends BinaryOpItem implements LogicalOpItem, Inverted, NotEqualsTypeItem {
boolean version2;

View File

@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.NotEqualsTypeItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
@@ -34,7 +35,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class StrictNeqActionItem extends BinaryOpItem implements LogicalOpItem, Inverted {
public class StrictNeqActionItem extends BinaryOpItem implements LogicalOpItem, Inverted, NotEqualsTypeItem {
public StrictNeqActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, lineStartIns, PRECEDENCE_EQUALITY, leftSide, rightSide, "!==", "", "");

View File

@@ -1,7 +1,5 @@
/* The following code was generated by JFlex 1.6.0 */
/*
* Copyright (C) 2010-2021 JPEXS, All rights reserved.
* Copyright (C) 2010-2023 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

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
import com.jpexs.decompiler.graph.model.BranchStackResistant;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.CommaExpressionItem;
@@ -2346,19 +2347,27 @@ public class Graph {
if (it instanceof IfItem) {
IfItem ii = (IfItem) it;
if (ii.expression instanceof EqualsTypeItem) {
if (!ii.onFalse.isEmpty() && !ii.onTrue.isEmpty()
&& ii.onTrue.get(ii.onTrue.size() - 1) instanceof PushItem
&& ii.onTrue.get(ii.onTrue.size() - 1).value instanceof IntegerValueTypeItem) {
int cpos = ((IntegerValueTypeItem) ii.onTrue.get(ii.onTrue.size() - 1).value).intValue();
List<GraphTargetItem> iiOnTrue = ii.onTrue;
List<GraphTargetItem> iiOnFalse = ii.onFalse;
if ((ii.expression instanceof EqualsTypeItem) || (ii.expression instanceof NotEqualsTypeItem)) {
if (ii.expression instanceof NotEqualsTypeItem) {
iiOnTrue = ii.onFalse;
iiOnFalse = ii.onTrue;
}
if (!iiOnFalse.isEmpty() && !iiOnTrue.isEmpty()
&& iiOnTrue.get(iiOnTrue.size() - 1) instanceof PushItem
&& iiOnTrue.get(iiOnTrue.size() - 1).value instanceof IntegerValueTypeItem) {
int cpos = ((IntegerValueTypeItem) iiOnTrue.get(iiOnTrue.size() - 1).value).intValue();
caseCommaCommands.put(cpos, commaCommands);
caseExpressionLeftSides.put(cpos, ((EqualsTypeItem) ii.expression).getLeftSide());
caseExpressionRightSides.put(cpos, ((EqualsTypeItem) ii.expression).getRightSide());
caseExpressionLeftSides.put(cpos, ((BinaryOpItem) ii.expression).getLeftSide());
caseExpressionRightSides.put(cpos, ((BinaryOpItem) ii.expression).getRightSide());
commaCommands = new ArrayList<>();
for (int f = 0; f < ii.onFalse.size() - 1; f++) {
commaCommands.add(ii.onFalse.get(f));
for (int f = 0; f < iiOnFalse.size() - 1; f++) {
commaCommands.add(iiOnFalse.get(f));
}
it = ii.onFalse.get(ii.onFalse.size() - 1);
it = iiOnFalse.get(iiOnFalse.size() - 1);
if (it instanceof PushItem) {
it = it.value;
}
@@ -2374,14 +2383,21 @@ public class Graph {
}
} else if (it instanceof TernarOpItem) {
TernarOpItem to = (TernarOpItem) it;
if (to.expression instanceof EqualsTypeItem) {
if (to.onTrue instanceof IntegerValueTypeItem) {
int cpos = ((IntegerValueTypeItem) to.onTrue).intValue();
caseExpressionLeftSides.put(cpos, ((EqualsTypeItem) to.expression).getLeftSide());
caseExpressionRightSides.put(cpos, ((EqualsTypeItem) to.expression).getRightSide());
GraphTargetItem toOnTrue = to.onTrue;
GraphTargetItem toOnFalse = to.onFalse;
if ((to.expression instanceof EqualsTypeItem) || (to.expression instanceof NotEqualsTypeItem)) {
if (to.expression instanceof NotEqualsTypeItem) {
toOnTrue = to.onFalse;
toOnFalse = to.onTrue;
}
if (toOnTrue instanceof IntegerValueTypeItem) {
int cpos = ((IntegerValueTypeItem) toOnTrue).intValue();
caseExpressionLeftSides.put(cpos, ((BinaryOpItem) to.expression).getLeftSide());
caseExpressionRightSides.put(cpos, ((BinaryOpItem) to.expression).getRightSide());
caseCommaCommands.put(cpos, commaCommands);
commaCommands = new ArrayList<>();
it = to.onFalse;
it = toOnFalse;
if (it instanceof CommaExpressionItem) {
commaCommands = new ArrayList<>();
CommaExpressionItem ce = (CommaExpressionItem) it;

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2023 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.graph;
import com.jpexs.decompiler.graph.model.BinaryOp;
/**
*
* @author JPEXS
*/
public interface NotEqualsTypeItem extends BinaryOp {
}

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2010-2023 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.
*/