mapOtherBranch stuff, seems to run

This commit is contained in:
Adam
2016-01-13 12:34:05 -05:00
parent 99c51051fe
commit 28abf2f343
4 changed files with 79 additions and 23 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 If extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction
{
@@ -99,16 +100,6 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
// InstructionContext oneLhs = ctx.getPops().get(0).getPushed().resolve(ctx.getPops().get(0)),
// oneRhs = ctx.getPops().get(1).getPushed().resolve(ctx.getPops().get(1)),
//
// twoLhs = other.getPops().get(0).getPushed().resolve(other.getPops().get(0)),
// twoRhs = other.getPops().get(1).getPushed().resolve(other.getPops().get(1));
// if we get here weve assedted isSame(ctx, other). but they might not be the same instruction.
// need to do something so branching can be always done right, eg ifeq vs ifne
//assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass());
Frame branch1 = ctx.getBranches().get(0),
branch2 = other.getBranches().get(0);
@@ -117,8 +108,43 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
branch1.other = branch2;
branch2.other = branch1;
// we can map these if they are getfield instructions?
}
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

View File

@@ -3,6 +3,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.Execution;
import net.runelite.deob.execution.Frame;
import net.runelite.deob.execution.InstructionContext;
public class IfCmpGt extends If
@@ -21,9 +23,8 @@ public class IfCmpGt extends If
if (otherIc.getInstruction() instanceof IfCmpLe)
{
return true;
//this is equal, but the branching is different
}
return false;
}
@@ -32,11 +33,11 @@ public class IfCmpGt extends If
{
if (other.getInstruction() instanceof IfCmpLe)
{
super.mapOtherBranch(mapping, ctx, other);
}
else
{
//super.ma
super.map(mapping, ctx, other);
}
}
}

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 IfCmpLe extends If
{
@@ -10,4 +12,30 @@ public class IfCmpLe extends If
super(instructions, type, pc);
}
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
if (super.isSame(thisIc, otherIc))
return true;
if (otherIc.getInstruction() instanceof IfCmpGt)
{
return true;
}
return false;
}
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other)
{
if (other.getInstruction() instanceof IfCmpGt)
{
super.mapOtherBranch(mapping, ctx, other);
}
else
{
super.map(mapping, ctx, other);
}
}
}

View File

@@ -15,7 +15,8 @@ public class MapStaticTest
{ "class99.method2220", "class99.method2149" },
{ "class146.vmethod3158", "class146.vmethod3070" },
{ "class166.method3315", "class166.method3254" },
{ "class167.method3406", "class167.method3296" }
{ "class167.method3406", "class167.method3296" },
{ "client.method585", "class44.method930" }
};
//@Test
@@ -33,8 +34,8 @@ public class MapStaticTest
//@Test
public void testAll() throws IOException
{
ClassGroup group1 = JarUtil.loadJar(new File("c:/rs/adamin1.jar"));
ClassGroup group2 = JarUtil.loadJar(new File("c:/rs/adamin2.jar"));
ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar"));
ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar"));
for (String[] s : methods)
{
@@ -50,11 +51,11 @@ public class MapStaticTest
@Test
public void test() throws IOException
{
ClassGroup group1 = JarUtil.loadJar(new File("c:/rs/adamin1.jar"));
ClassGroup group2 = JarUtil.loadJar(new File("c:/rs/adamin2.jar"));
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("class167").findMethod("method3406");
Method m2 = group2.findClass("class167").findMethod("method3296");
Method m1 = group1.findClass("client").findMethod("method585");
Method m2 = group2.findClass("class44").findMethod("method930");
ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2);
}