boolean ifeq vs ificmpne. I want to unwrap these smaller ifs into larger ones to simplify code.
This commit is contained in:
@@ -2,6 +2,7 @@ package net.runelite.deob.attributes.code.instructions;
|
|||||||
|
|
||||||
import net.runelite.deob.attributes.code.InstructionType;
|
import net.runelite.deob.attributes.code.InstructionType;
|
||||||
import net.runelite.deob.attributes.code.Instructions;
|
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 static net.runelite.deob.attributes.code.instructions.IfICmpEq.isZero;
|
||||||
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
|
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
|
||||||
import net.runelite.deob.execution.InstructionContext;
|
import net.runelite.deob.execution.InstructionContext;
|
||||||
@@ -31,6 +32,12 @@ public class IfEq extends If0
|
|||||||
|
|
||||||
if (isZero(s1) || isZero(s2))
|
if (isZero(s1) || isZero(s2))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (otherIc.getInstruction() instanceof IfICmpNe)
|
||||||
|
{
|
||||||
|
if ((isOne(s1) && s2.getType().isBoolean()) || (isOne(s2) && s1.getType().isBoolean()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -39,7 +46,19 @@ public class IfEq extends If0
|
|||||||
@Override
|
@Override
|
||||||
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
|
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);
|
super.mapOtherBranch(mapping, ctx, other);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,20 +14,30 @@ public class IfICmpEq extends If
|
|||||||
super(instructions, type, pc);
|
super(instructions, type, pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isZero(StackContext s)
|
static boolean is(StackContext s, int val)
|
||||||
{
|
{
|
||||||
if (s.getPushed().getInstruction() instanceof PushConstantInstruction)
|
if (s.getPushed().getInstruction() instanceof PushConstantInstruction)
|
||||||
{
|
{
|
||||||
PushConstantInstruction pc = (PushConstantInstruction) s.getPushed().getInstruction();
|
PushConstantInstruction pc = (PushConstantInstruction) s.getPushed().getInstruction();
|
||||||
Object o = pc.getConstant().getObject();
|
Object o = pc.getConstant().getObject();
|
||||||
|
|
||||||
if (o instanceof Integer && (int) o == 0)
|
if (o instanceof Integer && (int) o == val)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isZero(StackContext s)
|
||||||
|
{
|
||||||
|
return is(s, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isOne(StackContext s)
|
||||||
|
{
|
||||||
|
return is(s, 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ public class Type
|
|||||||
return toStackType().equals(new Type(int.class.getName()));
|
return toStackType().equals(new Type(int.class.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBoolean()
|
||||||
|
{
|
||||||
|
return type.equals("boolean");
|
||||||
|
}
|
||||||
|
|
||||||
private static String asmTypeToClass(String type)
|
private static String asmTypeToClass(String type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
|||||||
Reference in New Issue
Block a user