Add isSame(). I guess I changed the methods being tested too.

This commit is contained in:
Adam
2016-01-03 18:38:37 -05:00
parent d029c128e3
commit 261e195ea5
12 changed files with 94 additions and 9 deletions

View File

@@ -6,4 +6,6 @@ import net.runelite.deob.execution.InstructionContext;
public interface MappableInstruction public interface MappableInstruction
{ {
void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other); void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other);
boolean isSame(MappableInstruction other);
} }

View File

@@ -118,4 +118,10 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
// we can map these if they are getfield instructions? // we can map these if they are getfield instructions?
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -116,4 +116,10 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
branch1.other = branch2; branch1.other = branch2;
branch2.other = branch1; branch2.other = branch1;
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Value; import net.runelite.deob.execution.Value;
@@ -170,4 +171,10 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
for (int i = 0; i < myMethods.size(); ++i) for (int i = 0; i < myMethods.size(); ++i)
mapping.map(myMethods.get(i), otherMethods.get(i)); mapping.map(myMethods.get(i), otherMethods.get(i));
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Value; import net.runelite.deob.execution.Value;
@@ -165,4 +166,10 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
for (int i = 0; i < myMethods.size(); ++i) for (int i = 0; i < myMethods.size(); ++i)
mapping.map(myMethods.get(i), otherMethods.get(i)); mapping.map(myMethods.get(i), otherMethods.get(i));
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Value; import net.runelite.deob.execution.Value;
@@ -173,4 +174,10 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
for (int i = 0; i < myMethods.size(); ++i) for (int i = 0; i < myMethods.size(); ++i)
mapping.map(myMethods.get(i), otherMethods.get(i)); mapping.map(myMethods.get(i), otherMethods.get(i));
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Value; import net.runelite.deob.execution.Value;
@@ -174,4 +175,10 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
for (int i = 0; i < myMethods.size(); ++i) for (int i = 0; i < myMethods.size(); ++i)
mapping.map(myMethods.get(i), otherMethods.get(i)); mapping.map(myMethods.get(i), otherMethods.get(i));
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -17,6 +17,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.runelite.deob.Method; import net.runelite.deob.Method;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
@@ -121,4 +122,10 @@ public class PutField extends Instruction implements SetFieldInstruction
mapping.map(myField, otherField); mapping.map(myField, otherField);
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -17,6 +17,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.runelite.deob.Method; import net.runelite.deob.Method;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
public class PutStatic extends Instruction implements SetFieldInstruction public class PutStatic extends Instruction implements SetFieldInstruction
@@ -103,4 +104,10 @@ public class PutStatic extends Instruction implements SetFieldInstruction
mapping.map(myField, otherField); mapping.map(myField, otherField);
} }
@Override
public boolean isSame(MappableInstruction other)
{
return this.getClass() == other.getClass();
}
} }

View File

@@ -98,9 +98,10 @@ public class MappingExecutorUtil
assert p1.getInstruction() instanceof MappableInstruction; assert p1.getInstruction() instanceof MappableInstruction;
assert p2.getInstruction() instanceof MappableInstruction; assert p2.getInstruction() instanceof MappableInstruction;
assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass()); MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(),
mi2 = (MappableInstruction) p2.getInstruction();
MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(); assert mi1.isSame(mi2);
//assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass());
mi1.map(mappings, p1, p2); mi1.map(mappings, p1, p2);

View File

@@ -309,6 +309,7 @@ public class Rename2
} }
} }
static int pass = 0, asserts = 0;
private void executeNewMethods() private void executeNewMethods()
{ {
for (Vertex v : g1.getVerticies()) for (Vertex v : g1.getVerticies())
@@ -318,13 +319,26 @@ public class Rename2
if (other == null || !(v.getObject() instanceof Method)) if (other == null || !(v.getObject() instanceof Method))
continue; continue;
executeMethod((Method) v.getObject(), (Method) other.getObject()); try
{
executeMethod((Method) v.getObject(), (Method) other.getObject());
++pass;
}
catch (Exception | AssertionError ex)
{
ex.printStackTrace();
++asserts;
}
} }
} }
static int count = 0; static int count = 0;
private Set<Method> executed = new HashSet<>();
private void executeMethod(Method m1, Method m2) private void executeMethod(Method m1, Method m2)
{ {
if (executed.contains(m1))
return;
executed.add(m1);
// assert (m1.getCode() == null) == (m2.getCode() == null); // assert (m1.getCode() == null) == (m2.getCode() == null);
// //
// if (m1.getCode() == null) // if (m1.getCode() == null)
@@ -343,9 +357,23 @@ public class Rename2
{ {
if (e.getKey() instanceof Method) if (e.getKey() instanceof Method)
{ {
try
{
executeMethod((Method) e.getKey(), (Method) e.getValue());
++pass;
}
catch (Exception | AssertionError ex)
{
ex.printStackTrace();
++asserts;
}
Method m = (Method) e.getKey(); Method m = (Method) e.getKey();
if (m.isStatic()) if (m.isStatic())
{
// we can map execute these, though.
continue; continue;
}
} }
Vertex v1 = g1.getVertexFor(e.getKey()), Vertex v1 = g1.getVertexFor(e.getKey()),
v2 = g2.getVertexFor(e.getValue()); v2 = g2.getVertexFor(e.getValue());
@@ -433,13 +461,12 @@ public class Rename2
solve(); solve();
g1.getVerticies().forEach(v -> v.finish()); g1.getVerticies().forEach(v -> v.finish());
//g2
executeNewMethods();
int after = g1.solved(null); int after = g1.solved(null);
System.out.println("After " + after); System.out.println("After " + after);
executeNewMethods();
if (before == after) if (before == after)
break; break;
} }
@@ -488,6 +515,7 @@ public class Rename2
// show(mappings); // show(mappings);
System.out.println("Solved methods "+ g1.solved(VertexType.METHOD) + ", solved fields " + g1.solved(VertexType.FIELD) + ", unsolved methods " +g1.unsolved(VertexType.METHOD) + ", unsolved fields " + g1.unsolved(VertexType.FIELD)); System.out.println("Solved methods "+ g1.solved(VertexType.METHOD) + ", solved fields " + g1.solved(VertexType.FIELD) + ", unsolved methods " +g1.unsolved(VertexType.METHOD) + ", unsolved fields " + g1.unsolved(VertexType.FIELD));
System.out.println("asserts " + asserts + ", pass " + pass);
//rename(mappings, two); //rename(mappings, two);

View File

@@ -28,8 +28,8 @@ public class MapStaticTest
ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar"));
ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar")); ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar"));
Method m1 = group1.findClass("client").findMethod("vmethod3050"); Method m1 = group1.findClass("client").findMethod("vmethod3054");
Method m2 = group2.findClass("client").findMethod("vmethod3007"); Method m2 = group2.findClass("client").findMethod("vmethod2973");
ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2);
} }