mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 02:40:43 +00:00
Simplify nonif expressions while deobfuscation too
Regexp deobfuscation. Implicit coercion handling. #1145 double not (!!) fix
This commit is contained in:
@@ -40,7 +40,7 @@ public class AndItem extends BinaryOpItem {
|
||||
}
|
||||
|
||||
public AndItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
|
||||
super(src, lineStartIns, PRECEDENCE_LOGICALAND, leftSide, rightSide, "&&");
|
||||
super(src, lineStartIns, PRECEDENCE_LOGICALAND, leftSide, rightSide, "&&", "Boolean", "Boolean");
|
||||
this.leftSide = leftSide;
|
||||
this.rightSide = rightSide;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
|
||||
|
||||
protected final String operator;
|
||||
|
||||
protected String coerceLeft;
|
||||
protected String coerceRight;
|
||||
|
||||
@Override
|
||||
public GraphPart getFirstPart() {
|
||||
GraphPart fp = leftSide.getFirstPart();
|
||||
@@ -47,11 +50,21 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
|
||||
return fp;
|
||||
}
|
||||
|
||||
public BinaryOpItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator) {
|
||||
public BinaryOpItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator, String coerceLeft, String coerceRight) {
|
||||
super(instruction, lineStartItem, precedence);
|
||||
this.leftSide = leftSide;
|
||||
this.rightSide = rightSide;
|
||||
this.operator = operator;
|
||||
this.coerceLeft = coerceLeft;
|
||||
this.coerceRight = coerceRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem simplify(String implicitCoerce) {
|
||||
BinaryOpItem r = (BinaryOpItem) clone();
|
||||
r.leftSide = r.leftSide.simplify(coerceLeft);
|
||||
r.rightSide = r.rightSide.simplify(coerceRight);
|
||||
return simplifySomething(r, implicitCoerce);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +111,7 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
|
||||
return false;
|
||||
}
|
||||
dependencies.add(rightSide);
|
||||
return leftSide.isCompileTime(dependencies) && rightSide.isCompileTime(dependencies);
|
||||
return leftSide.isConvertedCompileTime(dependencies) && rightSide.isConvertedCompileTime(dependencies);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,7 +86,12 @@ public class DoWhileItem extends LoopItem implements Block {
|
||||
if (i != 0) {
|
||||
writer.append(", ");
|
||||
}
|
||||
expression.get(i).toString(writer, localData);
|
||||
if (i == expression.size() - 1) {
|
||||
expression.get(i).toStringBoolean(writer, localData);
|
||||
} else {
|
||||
expression.get(i).toString(writer, localData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
writer.append(");").newLine();
|
||||
|
||||
@@ -51,10 +51,10 @@ public class DuplicateItem extends GraphTargetItem implements SimpleValue {
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
if (((value instanceof SimpleValue) && (((SimpleValue) value).isSimpleValue())) || !Configuration.displayDupInstructions.get()) {
|
||||
return value.appendTo(writer, localData);
|
||||
return value.appendTry(writer, localData);
|
||||
}
|
||||
writer.append("§§dup(");
|
||||
value.appendTo(writer, localData);
|
||||
value.appendTry(writer, localData);
|
||||
return writer.append(")");
|
||||
}
|
||||
|
||||
@@ -102,9 +102,14 @@ public class DuplicateItem extends GraphTargetItem implements SimpleValue {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem simplify(String implicitCoerce) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem returnType() {
|
||||
return TypeItem.UNBOUNDED;
|
||||
return value.returnType();
|
||||
}
|
||||
|
||||
/*@Override
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ForItem extends LoopItem implements Block {
|
||||
p++;
|
||||
}
|
||||
writer.append("; ");
|
||||
expression.toString(writer, localData);
|
||||
expression.toStringBoolean(writer, localData);
|
||||
writer.append("; ");
|
||||
p = 0;
|
||||
for (int i = 0; i < finalCommands.size(); i++) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
writer.append(" ");
|
||||
}
|
||||
writer.append("(");
|
||||
expr.toString(writer, localData);
|
||||
expr.toStringBoolean(writer, localData);
|
||||
writer.append(")");
|
||||
appendBlock(expr, writer, localData, ifBranch);
|
||||
if (elseBranch.size() > 0) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.graph.model;
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.action.model.operations.Inverted;
|
||||
import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
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;
|
||||
@@ -34,7 +35,7 @@ import java.util.Set;
|
||||
public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
|
||||
|
||||
public NotItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value) {
|
||||
super(instruction, lineStartIns, PRECEDENCE_UNARY, value, "!");
|
||||
super(instruction, lineStartIns, PRECEDENCE_UNARY, value, "!", "Boolean");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,8 +80,30 @@ public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
|
||||
return TypeItem.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter toStringBoolean(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
//Skip explicit conversion to boolean, it is not needed, it is done implicitly
|
||||
if (value instanceof NotItem) {
|
||||
return value.value.toStringBoolean(writer, localData);
|
||||
}
|
||||
return super.toStringBoolean(writer, localData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem invert(GraphSourceItem src) {
|
||||
if (true) {
|
||||
return value;
|
||||
}
|
||||
//if this is already !!val, convert to !val
|
||||
if (value instanceof NotItem) {
|
||||
return value;
|
||||
}
|
||||
//If it is not a boolean, put !! there for toBoolean conversion
|
||||
if (!TypeItem.BOOLEAN.equals(value.returnType()) && !(value instanceof DuplicateItem)) {
|
||||
return new NotItem(null, null, this);
|
||||
}
|
||||
|
||||
//can be inverted
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
public class OrItem extends BinaryOpItem {
|
||||
|
||||
public OrItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
|
||||
super(src, lineStartIns, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||");
|
||||
super(src, lineStartIns, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||", "Boolean", "Boolean");
|
||||
this.leftSide = leftSide;
|
||||
this.rightSide = rightSide;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PushItem extends GraphTargetItem {
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
//Logger.getLogger(PushItem.class.getName()).log(Level.WARNING, "Push item left in the source code");
|
||||
writer.append("§§push(");
|
||||
value.appendTo(writer, localData);
|
||||
value.appendTry(writer, localData);
|
||||
writer.append(")");
|
||||
return writer;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ThisAVM2Item;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItemPos;
|
||||
@@ -30,10 +31,19 @@ import java.util.Set;
|
||||
public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
|
||||
|
||||
public String operator;
|
||||
protected String coerce;
|
||||
|
||||
public UnaryOpItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem value, String operator) {
|
||||
public UnaryOpItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem value, String operator, String coerce) {
|
||||
super(instruction, lineStartItem, precedence, value);
|
||||
this.operator = operator;
|
||||
this.coerce = coerce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem simplify(String implicitCoerce) {
|
||||
GraphTargetItem r = clone();
|
||||
r.value = r.value.simplify(coerce);
|
||||
return simplifySomething(r, implicitCoerce);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,7 +69,7 @@ public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
|
||||
return false;
|
||||
}
|
||||
dependencies.add(value);
|
||||
return value.isCompileTime(dependencies);
|
||||
return value.isConvertedCompileTime(dependencies);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,7 +77,12 @@ public class WhileItem extends LoopItem implements Block {
|
||||
if (i != 0) {
|
||||
writer.append(", ");
|
||||
}
|
||||
expression.get(i).toString(writer, localData);
|
||||
if (i == expression.size() - 1) {
|
||||
expression.get(i).toStringBoolean(writer, localData);
|
||||
} else {
|
||||
expression.get(i).toString(writer, localData);
|
||||
}
|
||||
|
||||
}
|
||||
writer.append(")");
|
||||
appendBlock(expression.get(expression.size() - 1), writer, localData, commands);
|
||||
|
||||
Reference in New Issue
Block a user