Map fields from ifs
This commit is contained in:
@@ -15,7 +15,10 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.runelite.deob.Field;
|
||||
import net.runelite.deob.attributes.code.instruction.types.GetFieldInstruction;
|
||||
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
|
||||
import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil;
|
||||
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
|
||||
import net.runelite.deob.execution.Execution;
|
||||
|
||||
@@ -110,6 +113,8 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
|
||||
|
||||
branch1.other = branch2;
|
||||
branch2.other = branch1;
|
||||
|
||||
this.mapArguments(mapping, ctx, other);
|
||||
}
|
||||
|
||||
protected void mapOtherBranch(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
|
||||
@@ -147,12 +152,55 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
|
||||
//
|
||||
// e2.frames.remove(i2);
|
||||
// e2.frames.add(i2, f2);
|
||||
|
||||
this.mapArguments(mapping, ctx, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
private void mapArguments(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
|
||||
{
|
||||
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
|
||||
Field f1 = getComparedField(ctx), f2 = getComparedField(other);
|
||||
|
||||
if (f1 == null || f2 == null)
|
||||
return;
|
||||
|
||||
assert f1.getType().equals(f2.getType());
|
||||
|
||||
mapping.map(f1, f2);
|
||||
}
|
||||
|
||||
private Field getComparedField(InstructionContext ctx)
|
||||
{
|
||||
GetFieldInstruction gfi = null;
|
||||
|
||||
for (StackContext sctx : ctx.getPops())
|
||||
{
|
||||
InstructionContext base = MappingExecutorUtil.resolve(sctx.getPushed(), sctx);
|
||||
|
||||
if (base.getInstruction() instanceof GetFieldInstruction)
|
||||
{
|
||||
if (gfi != null)
|
||||
return null;
|
||||
|
||||
gfi = (GetFieldInstruction) base.getInstruction();
|
||||
}
|
||||
}
|
||||
|
||||
if (gfi == null)
|
||||
return null;
|
||||
|
||||
return gfi.getMyField();
|
||||
}
|
||||
|
||||
protected boolean isSameField(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
Field f1 = getComparedField(thisIc), f2 = getComparedField(otherIc);
|
||||
if ((f1 != null) != (f2 != null))
|
||||
return false;
|
||||
|
||||
if (f1 == null || f2 == null)
|
||||
return true;
|
||||
|
||||
return f1.getType().equals(f2.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,10 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.runelite.deob.Field;
|
||||
import net.runelite.deob.attributes.code.instruction.types.GetFieldInstruction;
|
||||
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
|
||||
import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil;
|
||||
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
|
||||
import net.runelite.deob.execution.Execution;
|
||||
|
||||
@@ -112,6 +115,8 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
|
||||
|
||||
branch1.other = branch2;
|
||||
branch2.other = branch1;
|
||||
|
||||
this.mapArguments(mapping, ctx, other);
|
||||
}
|
||||
|
||||
// duplicated from If
|
||||
@@ -150,12 +155,54 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
|
||||
//
|
||||
// e2.frames.remove(i2);
|
||||
// e2.frames.add(i2, f2);
|
||||
|
||||
this.mapArguments(mapping, ctx, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
private void mapArguments(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
|
||||
{
|
||||
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
|
||||
Field f1 = getComparedField(ctx), f2 = getComparedField(other);
|
||||
if (f1 == null || f2 == null)
|
||||
return;
|
||||
|
||||
assert f1.getType().equals(f2.getType());
|
||||
|
||||
mapping.map(f1, f2);
|
||||
}
|
||||
|
||||
private Field getComparedField(InstructionContext ctx)
|
||||
{
|
||||
GetFieldInstruction gfi = null;
|
||||
|
||||
for (StackContext sctx : ctx.getPops())
|
||||
{
|
||||
InstructionContext base = MappingExecutorUtil.resolve(sctx.getPushed(), sctx);
|
||||
|
||||
if (base.getInstruction() instanceof GetFieldInstruction)
|
||||
{
|
||||
if (gfi != null)
|
||||
return null;
|
||||
|
||||
gfi = (GetFieldInstruction) base.getInstruction();
|
||||
}
|
||||
}
|
||||
|
||||
if (gfi == null)
|
||||
return null;
|
||||
|
||||
return gfi.getMyField();
|
||||
}
|
||||
|
||||
protected boolean isSameField(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
Field f1 = getComparedField(thisIc), f2 = getComparedField(otherIc);
|
||||
if ((f1 != null) != (f2 != null))
|
||||
return false;
|
||||
|
||||
if (f1 == null || f2 == null)
|
||||
return true;
|
||||
|
||||
return f1.getType().equals(f2.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,10 @@ public class IfACmpEq extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfNull || otherIc.getInstruction() instanceof IfNonNull)
|
||||
|
||||
@@ -16,7 +16,10 @@ public class IfACmpNe extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfNonNull || otherIc.getInstruction() instanceof IfNull)
|
||||
|
||||
@@ -15,7 +15,10 @@ public class IfCmpGe extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfCmpLt)
|
||||
|
||||
@@ -17,7 +17,10 @@ public class IfCmpGt extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfCmpLe)
|
||||
|
||||
@@ -15,7 +15,10 @@ public class IfCmpLe extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfCmpGt)
|
||||
|
||||
@@ -15,7 +15,10 @@ public class IfCmpLt extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfCmpGe)
|
||||
|
||||
@@ -18,7 +18,10 @@ public class IfEq extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfNe)
|
||||
|
||||
@@ -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 net.runelite.deob.execution.InstructionContext;
|
||||
|
||||
public class IfGe extends If0
|
||||
{
|
||||
@@ -10,4 +11,16 @@ public class IfGe extends If0
|
||||
super(instructions, type, pc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@ public class IfGt extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfLe)
|
||||
|
||||
@@ -41,7 +41,10 @@ public class IfICmpEq extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
// check for other being ifeq and this has a constant 0
|
||||
|
||||
@@ -31,7 +31,10 @@ public class IfICmpNe extends If
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
// check for other being ifne and this has a constant 0
|
||||
|
||||
@@ -15,7 +15,10 @@ public class IfLe extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfGt)
|
||||
|
||||
@@ -15,7 +15,10 @@ public class IfLt extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfGe)
|
||||
|
||||
@@ -18,7 +18,10 @@ public class IfNe extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfICmpNe || otherIc.getInstruction() instanceof IfICmpEq)
|
||||
|
||||
@@ -16,7 +16,10 @@ public class IfNonNull extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfACmpNe)
|
||||
|
||||
@@ -16,7 +16,10 @@ public class IfNull extends If0
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
{
|
||||
if (super.isSame(thisIc, otherIc))
|
||||
if (!this.isSameField(thisIc, otherIc))
|
||||
return false;
|
||||
|
||||
if (thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass())
|
||||
return true;
|
||||
|
||||
if (otherIc.getInstruction() instanceof IfACmpEq || otherIc.getInstruction() instanceof IfACmpNe)
|
||||
|
||||
@@ -245,16 +245,16 @@ public class MapStaticTest
|
||||
System.out.println("GROUP 2 " + sg2);
|
||||
|
||||
|
||||
for (Method m : group1.findClass("client").getMethods().getMethods())
|
||||
{
|
||||
if (!finalm.getMap().containsKey(m))
|
||||
System.out.println("missing " + m);
|
||||
}
|
||||
for (Field m : group1.findClass("client").getFields().getFields())
|
||||
{
|
||||
if (!finalm.getMap().containsKey(m))
|
||||
System.out.println("missing " + m);
|
||||
}
|
||||
// for (Method m : group1.findClass("client").getMethods().getMethods())
|
||||
// {
|
||||
// if (!finalm.getMap().containsKey(m))
|
||||
// System.out.println("missing " + m);
|
||||
// }
|
||||
// for (Field m : group1.findClass("client").getFields().getFields())
|
||||
// {
|
||||
// if (!finalm.getMap().containsKey(m))
|
||||
// System.out.println("missing " + m);
|
||||
// }
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
||||
Reference in New Issue
Block a user