boolean ifeq vs ificmpne. I want to unwrap these smaller ifs into larger ones to simplify code.

This commit is contained in:
Adam
2016-01-30 16:29:22 -05:00
parent cbe45eddfe
commit 8e73f37eba
3 changed files with 37 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package net.runelite.deob.attributes.code.instructions;
import net.runelite.deob.attributes.code.InstructionType;
import net.runelite.deob.attributes.code.Instructions;
import static net.runelite.deob.attributes.code.instructions.IfICmpEq.isOne;
import static net.runelite.deob.attributes.code.instructions.IfICmpEq.isZero;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.InstructionContext;
@@ -31,6 +32,12 @@ public class IfEq extends If0
if (isZero(s1) || isZero(s2))
return true;
if (otherIc.getInstruction() instanceof IfICmpNe)
{
if ((isOne(s1) && s2.getType().isBoolean()) || (isOne(s2) && s1.getType().isBoolean()))
return true;
}
}
return false;
@@ -39,7 +46,19 @@ public class IfEq extends If0
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
if (other.getInstruction() instanceof IfNe || other.getInstruction() instanceof IfICmpNe)
if (other.getInstruction() instanceof IfICmpNe)
{
StackContext s1 = other.getPops().get(0),
s2 = other.getPops().get(1);
if (isZero(s1) || isZero(s2))
super.mapOtherBranch(mapping, ctx, other); // ifeq 0 vs ificmpne 0
else if (isOne(s1) || isOne(s2))
super.map(mapping, ctx, other); // iseq 0 vs ifne 1
else
assert false;
}
else if (other.getInstruction() instanceof IfNe)
{
super.mapOtherBranch(mapping, ctx, other);
}

View File

@@ -14,20 +14,30 @@ public class IfICmpEq extends If
super(instructions, type, pc);
}
static boolean isZero(StackContext s)
static boolean is(StackContext s, int val)
{
if (s.getPushed().getInstruction() instanceof PushConstantInstruction)
{
PushConstantInstruction pc = (PushConstantInstruction) s.getPushed().getInstruction();
Object o = pc.getConstant().getObject();
if (o instanceof Integer && (int) o == 0)
if (o instanceof Integer && (int) o == val)
return true;
}
return false;
}
static boolean isZero(StackContext s)
{
return is(s, 0);
}
static boolean isOne(StackContext s)
{
return is(s, 1);
}
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{

View File

@@ -31,6 +31,11 @@ public class Type
return toStackType().equals(new Type(int.class.getName()));
}
public boolean isBoolean()
{
return type.equals("boolean");
}
private static String asmTypeToClass(String type)
{
switch (type)