Test seems promising

This commit is contained in:
Adam
2015-12-13 12:39:48 -05:00
parent 69600fbf4e
commit 5ca2e373f5
16 changed files with 248 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ public abstract class Instruction implements Cloneable
public String toString()
{
Method m = this.getInstructions().getCode().getAttributes().getMethod();
return super.toString() + " in " + m + " at pc " + this.getPc();
return super.toString() + " in " + m + " at pc 0x" + Integer.toHexString(this.getPc());
}
@Override

View File

@@ -5,7 +5,7 @@ import java.util.List;
import net.runelite.deob.Method;
import net.runelite.deob.pool.PoolEntry;
public interface InvokeInstruction
public interface InvokeInstruction extends MappableInstruction
{
public void removeParameter(int idx);

View File

@@ -0,0 +1,8 @@
package net.runelite.deob.attributes.code.instruction.types;
import net.runelite.deob.execution.InstructionContext;
public interface MappableInstruction
{
void map(InstructionContext ctx, InstructionContext other);
}

View File

@@ -1,5 +1,5 @@
package net.runelite.deob.attributes.code.instruction.types;
public interface SetFieldInstruction extends FieldInstruction
public interface SetFieldInstruction extends FieldInstruction, MappableInstruction
{
}

View File

@@ -22,6 +22,12 @@ public class Goto extends Instruction implements JumpingInstruction
{
super(instructions, type, pc);
}
@Override
public String toString()
{
return "goto " + to + " (at pc " + (this.getPc() + offset) + ")";
}
public Goto(Instructions instructions, Instruction to)
{

View File

@@ -15,8 +15,9 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
public class If extends Instruction implements JumpingInstruction, ComparisonInstruction
public abstract class If extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction
{
private Instruction to;
private short offset;
@@ -93,4 +94,29 @@ public class If extends Instruction implements JumpingInstruction, ComparisonIns
{
return Arrays.asList(to);
}
@Override
public final/*XXX tmp*/ void map(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));
assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass());
Frame branch1 = ctx.getBranches().get(0),
branch2 = other.getBranches().get(0);
assert branch1.other == null;
assert branch2.other == null;
branch1.other = branch2;
branch2.other = branch1;
// we can map these if they are getfield instructions?
//
}
}

View File

@@ -15,8 +15,9 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
public class If0 extends Instruction implements JumpingInstruction, ComparisonInstruction
public abstract class If0 extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction
{
private Instruction to;
private short offset;
@@ -94,4 +95,24 @@ public class If0 extends Instruction implements JumpingInstruction, ComparisonIn
{
return Arrays.asList(to);
}
@Override
public final/*XXX tmp*/ void map(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?
assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass());
Frame branch1 = ctx.getBranches().get(0),
branch2 = other.getBranches().get(0);
assert branch1.other == null;
assert branch2.other == null;
branch1.other = branch2;
branch2.other = branch1;
}
}

View File

@@ -157,4 +157,11 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolInterfaceMethod(); // is this right?
}
@Override
public void map(InstructionContext ctx, InstructionContext other)
{
List<net.runelite.deob.Method> myMethods = this.getMethods(),
otherMethods = ((InvokeInterface) other.getInstruction()).getMethods();
}
}

View File

@@ -150,4 +150,11 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod();
}
@Override
public void map(InstructionContext ctx, InstructionContext other)
{
List<net.runelite.deob.Method> myMethods = this.getMethods(),
otherMethods = ((InvokeSpecial) other.getInstruction()).getMethods();
}
}

View File

@@ -160,4 +160,11 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod();
}
@Override
public void map(InstructionContext ctx, InstructionContext other)
{
List<net.runelite.deob.Method> myMethods = this.getMethods(),
otherMethods = ((InvokeStatic) other.getInstruction()).getMethods();
}
}

View File

@@ -161,4 +161,11 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
if (myMethods != null && !myMethods.isEmpty())
method = myMethods.get(0).getPoolMethod(); // is this right?
}
@Override
public void map(InstructionContext ctx, InstructionContext other)
{
List<net.runelite.deob.Method> myMethods = this.getMethods(),
otherMethods = ((InvokeVirtual) other.getInstruction()).getMethods();
}
}

View File

@@ -94,4 +94,13 @@ public class PutField extends Instruction implements SetFieldInstruction
if (myField != null)
field = myField.getPoolField();
}
@Override
public void map(InstructionContext ctx, InstructionContext other)
{
net.runelite.deob.Field myField = this.getMyField(),
otherField = ((PutField) other.getInstruction()).getMyField();
System.out.println("MAPPING " + myField + " -> " + otherField);
}
}

View File

@@ -93,4 +93,13 @@ public class PutStatic extends Instruction implements SetFieldInstruction
if (myField != null)
field = myField.getPoolField();
}
@Override
public void map(InstructionContext ctx, InstructionContext other)
{
net.runelite.deob.Field myField = this.getMyField(),
otherField = ((PutStatic) other.getInstruction()).getMyField();
System.out.println("MAPPING " + myField + " -> " + otherField);
}
}

View File

@@ -11,6 +11,7 @@ import net.runelite.deob.attributes.code.Instruction;
import net.runelite.deob.attributes.code.Instructions;
import net.runelite.deob.pool.NameAndType;
import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.attributes.code.instruction.types.ReturnInstruction;
import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction;
import net.runelite.deob.attributes.code.instructions.AThrow;
@@ -28,6 +29,7 @@ public class Frame
private MethodContext ctx;
protected Method nonStatic; // next non static method up the stack
private Frame caller;
public Frame other; // in the other execution for mapping
public Frame(Execution execution, Method method)
{
@@ -44,6 +46,12 @@ public class Frame
ctx = new MethodContext(execution);
nonStatic = method;
}
@Override
public String toString()
{
return "Frame{" + "cur=" + cur + '}';
}
public void initialize()
{
@@ -219,6 +227,12 @@ public class Frame
{
/* jump */
}
if (oldCur instanceof MappableInstruction)
{
execution.paused = true;
return;
}
}
}

View File

@@ -98,6 +98,11 @@ public class InstructionContext
{
return invokes;
}
public List<Frame> getBranches()
{
return branches;
}
public List<StackContext> removeStack(int idx)
{

View File

@@ -0,0 +1,117 @@
package net.runelite.deob.deobfuscators.rename;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.Method;
import net.runelite.deob.attributes.code.Instruction;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Frame;
import net.runelite.deob.execution.InstructionContext;
import net.runelite.deob.util.JarUtil;
import org.junit.Test;
public class MapTest
{
@Test
public void main() throws IOException
{
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("class99").findMethod("method2220");
Execution e = new Execution(group1);
Frame frame = new Frame(e, m1);
frame.initialize();
e.frames.add(frame);
Method m2 = group2.findClass("class99").findMethod("method2149");
Execution e2 = new Execution(group2);
Frame frame2 = new Frame(e2, m2);
frame2.initialize();
e2.frames.add(frame2);
frame.other = frame2;
frame2.other = frame;
List<Instruction> l1 = m1.getCode().getInstructions().getInstructions().stream().filter(i -> i instanceof MappableInstruction).collect(Collectors.toList());
List<Instruction> l2 = m2.getCode().getInstructions().getInstructions().stream().filter(i -> i instanceof MappableInstruction).collect(Collectors.toList());
while (!e.frames.isEmpty())
{
assert e.frames.size() == e2.frames.size();
Frame f1 = e.frames.get(0), f2 = e2.frames.get(0);
assert f1.other == f2;
assert f2.other == f1;
assert f1.isExecuting() == f2.isExecuting();
// on if it is duped then jumped,
if (!f1.isExecuting())
{
assert e.frames.get(0) == f1;
assert e2.frames.get(0) == f2;
e.frames.remove(0);
e2.frames.remove(0);
continue;
}
// step frame
f1.execute();
f2.execute();
// get what each frame is paused/exited on
InstructionContext p1 = f1.getInstructions().get(f1.getInstructions().size() - 1);
InstructionContext p2 = f2.getInstructions().get(f2.getInstructions().size() - 1);
if (!f1.isExecuting() || !f2.isExecuting())
{
for (Frame branch : p1.getBranches())
{
e.frames.remove(branch);
}
for (Frame branch : p2.getBranches())
{
e2.frames.remove(branch);
}
// System.out.println("Something exited " + f1 + " " + f2);
assert e.frames.get(0) == f1;
assert e2.frames.get(0) == f2;
e.frames.remove(0);
e2.frames.remove(0);
continue;
}
// frames can stop executing if they've determined that they've executed
// the ins before, and it won't necessarily be at the same time?
assert e.paused;
assert e2.paused;
//System.out.println(p1.getInstruction() + " <-> " + p2.getInstruction());
assert p1.getInstruction().getInstructions().getCode().getAttributes().getMethod() == m1;
assert p2.getInstruction().getInstructions().getCode().getAttributes().getMethod() == m2;
assert p1.getInstruction() instanceof MappableInstruction;
assert p2.getInstruction() instanceof MappableInstruction;
assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass());
MappableInstruction mi1 = (MappableInstruction) p1.getInstruction();
mi1.map(p1, p2);
e.paused = e2.paused = false;
}
}
}