More tests

This commit is contained in:
Adam
2016-01-13 14:58:15 -05:00
parent 28abf2f343
commit 3b4ea9ce0d
5 changed files with 93 additions and 14 deletions

View File

@@ -17,6 +17,7 @@ import java.util.Arrays;
import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution;
public abstract class If0 extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction
{
@@ -97,17 +98,10 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
return Arrays.asList(to);
}
// duplicated from If
@Override
public final/*XXX tmp*/ void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
InstructionContext one = ctx.getPops().get(0).getPushed().resolve(ctx.getPops().get(0)),
two = other.getPops().get(0).getPushed().resolve(other.getPops().get(0));
// we can map these if they are getfield instructions?
// this is already checked before this
//assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass());
Frame branch1 = ctx.getBranches().get(0),
branch2 = other.getBranches().get(0);
@@ -118,6 +112,44 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
branch2.other = branch1;
}
// duplicated from If
protected void mapOtherBranch(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
Frame f1 = ctx.getFrame(),
f2 = other.getFrame(),
branch1 = ctx.getBranches().get(0),
branch2 = other.getBranches().get(0);
assert branch1.other == null;
assert branch2.other == null;
// currently f1 <-> f2
assert f1.other == f2;
assert f2.other == f1;
// change to f1 <-> branch2, f2 <-> branch1
f1.other = branch2;
branch2.other = f1;
f2.other = branch1;
branch1.other = f2;
// switch frame order in executor frame list
Execution e = f1.getExecution(),
e2 = f2.getExecution();
int i = e2.frames.indexOf(f2),
i2 = e2.frames.indexOf(branch2);
e2.frames.remove(i);
e2.frames.add(i, branch2);
e2.frames.remove(i2);
e2.frames.add(i2, f2);
}
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{

View File

@@ -2,6 +2,8 @@ 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.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.InstructionContext;
public class IfEq extends If0
{
@@ -10,4 +12,30 @@ public class IfEq extends If0
super(instructions, type, pc);
}
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
if (super.isSame(thisIc, otherIc))
return true;
if (otherIc.getInstruction() instanceof IfNe)
{
return true;
}
return false;
}
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
if (other.getInstruction() instanceof IfNe)
{
super.mapOtherBranch(mapping, ctx, other);
}
else
{
super.map(mapping, ctx, other);
}
}
}

View File

@@ -4,6 +4,7 @@ import net.runelite.deob.attributes.code.InstructionType;
import net.runelite.deob.attributes.code.Instructions;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.InstructionContext;
import net.runelite.deob.execution.StackContext;
@@ -47,7 +48,24 @@ public class IfNe extends If0
}
}
}
else if (otherIc.getInstruction() instanceof IfEq)
{
return true;
}
return false;
}
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
if (other.getInstruction() instanceof IfEq)
{
super.mapOtherBranch(mapping, ctx, other);
}
else
{
super.map(mapping, ctx, other);
}
}
}

View File

@@ -30,12 +30,12 @@ public class ParallellMappingExecutor
assert f1.other == f2;
assert f2.other == f1;
assert f1.isExecuting() == f2.isExecuting();
//assert f1.isExecuting() == f2.isExecuting();
// this will happen because conditional branches will create their frame
// before realizing its already executed it before, so it will set the frame
// as not executing
if (!f1.isExecuting())
if (!f1.isExecuting() || !f2.isExecuting())
{
assert e.frames.get(0) == f1;
assert e2.frames.get(0) == f2;

View File

@@ -16,7 +16,8 @@ public class MapStaticTest
{ "class146.vmethod3158", "class146.vmethod3070" },
{ "class166.method3315", "class166.method3254" },
{ "class167.method3406", "class167.method3296" },
{ "client.method585", "class44.method930" }
{ "client.method585", "class44.method930" },
{ "class222.method4086", "class222.method3957" }
};
//@Test
@@ -54,8 +55,8 @@ public class MapStaticTest
ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar"));
ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar"));
Method m1 = group1.findClass("client").findMethod("method585");
Method m2 = group2.findClass("class44").findMethod("method930");
Method m1 = group1.findClass("class222").findMethod("method4086");
Method m2 = group2.findClass("class222").findMethod("method3957");
ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2);
}