Fix tests
This commit is contained in:
@@ -32,6 +32,13 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
|
||||
super(instructions, type, pc);
|
||||
}
|
||||
|
||||
public If(Instructions instructions, InstructionType type, Instruction to)
|
||||
{
|
||||
super(instructions, type, -1);
|
||||
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public If(Instructions instructions, Instruction to)
|
||||
{
|
||||
super(instructions, InstructionType.IF_ICMPNE, -1);
|
||||
|
||||
@@ -32,9 +32,9 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
|
||||
super(instructions, type, pc);
|
||||
}
|
||||
|
||||
public If0(Instructions instructions, Instruction to)
|
||||
public If0(Instructions instructions, InstructionType type, Instruction to)
|
||||
{
|
||||
super(instructions, InstructionType.IFEQ, -1);
|
||||
super(instructions, type, -1);
|
||||
|
||||
assert this != to;
|
||||
assert to.getInstructions() == this.getInstructions();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.runelite.deob.attributes.code.instructions;
|
||||
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.attributes.code.InstructionType;
|
||||
import net.runelite.deob.attributes.code.Instructions;
|
||||
import static net.runelite.deob.attributes.code.instructions.IfICmpEq.isOne;
|
||||
@@ -14,6 +15,11 @@ public class IfEq extends If0
|
||||
{
|
||||
super(instructions, type, pc);
|
||||
}
|
||||
|
||||
public IfEq(Instructions instructions, Instruction to)
|
||||
{
|
||||
super(instructions, InstructionType.IFEQ, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.runelite.deob.attributes.code.instructions;
|
||||
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.attributes.code.InstructionType;
|
||||
import net.runelite.deob.attributes.code.Instructions;
|
||||
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
|
||||
@@ -14,6 +15,11 @@ public class IfICmpEq extends If
|
||||
super(instructions, type, pc);
|
||||
}
|
||||
|
||||
public IfICmpEq(Instructions instructions, Instruction to)
|
||||
{
|
||||
super(instructions, InstructionType.IF_ICMPEQ, to);
|
||||
}
|
||||
|
||||
static boolean is(StackContext s, int val)
|
||||
{
|
||||
if (s.getPushed().getInstruction() instanceof PushConstantInstruction)
|
||||
|
||||
@@ -10,20 +10,17 @@ import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.attributes.code.Instructions;
|
||||
import net.runelite.deob.attributes.code.instructions.Dup2_X1;
|
||||
import net.runelite.deob.attributes.code.instructions.Dup_X1;
|
||||
import net.runelite.deob.attributes.code.instructions.GetStatic;
|
||||
import net.runelite.deob.attributes.code.instructions.Goto;
|
||||
import net.runelite.deob.attributes.code.instructions.IAdd;
|
||||
import net.runelite.deob.attributes.code.instructions.IConst_0;
|
||||
import net.runelite.deob.attributes.code.instructions.IConst_1;
|
||||
import net.runelite.deob.attributes.code.instructions.IConst_2;
|
||||
import net.runelite.deob.attributes.code.instructions.IConst_3;
|
||||
import net.runelite.deob.attributes.code.instructions.IConst_M1;
|
||||
import net.runelite.deob.attributes.code.instructions.IDiv;
|
||||
import net.runelite.deob.attributes.code.instructions.ILoad;
|
||||
import net.runelite.deob.attributes.code.instructions.IMul;
|
||||
import net.runelite.deob.attributes.code.instructions.IStore;
|
||||
import net.runelite.deob.attributes.code.instructions.IStore_0;
|
||||
import net.runelite.deob.attributes.code.instructions.If0;
|
||||
import net.runelite.deob.attributes.code.instructions.IfEq;
|
||||
import net.runelite.deob.attributes.code.instructions.InvokeStatic;
|
||||
import net.runelite.deob.attributes.code.instructions.LConst_1;
|
||||
import net.runelite.deob.attributes.code.instructions.LDC2_W;
|
||||
@@ -212,7 +209,7 @@ public class MultiplicationDeobfuscatorTest
|
||||
new ILoad(ins, 0),
|
||||
new IMul(ins),
|
||||
new IConst_0(ins),
|
||||
new If0(ins, label1),
|
||||
new IfEq(ins, label1),
|
||||
constant2,
|
||||
new IMul(ins),
|
||||
label1,
|
||||
@@ -281,7 +278,7 @@ public class MultiplicationDeobfuscatorTest
|
||||
new IMul(ins),
|
||||
|
||||
new IConst_0(ins),
|
||||
new If0(ins, label1),
|
||||
new IfEq(ins, label1),
|
||||
|
||||
new Pop(ins),
|
||||
new LDC_W(ins, 3),
|
||||
@@ -506,7 +503,7 @@ public class MultiplicationDeobfuscatorTest
|
||||
new ILoad(ins, 0),
|
||||
|
||||
new LDC_W(ins, 42),
|
||||
new If0(ins, label1),
|
||||
new IfEq(ins, label1),
|
||||
new Goto(ins, label2),
|
||||
|
||||
label1,
|
||||
|
||||
@@ -16,8 +16,8 @@ import net.runelite.deob.attributes.code.instructions.ILoad;
|
||||
import net.runelite.deob.attributes.code.instructions.IMul;
|
||||
import net.runelite.deob.attributes.code.instructions.IStore_0;
|
||||
import net.runelite.deob.attributes.code.instructions.IStore_1;
|
||||
import net.runelite.deob.attributes.code.instructions.If;
|
||||
import net.runelite.deob.attributes.code.instructions.If0;
|
||||
import net.runelite.deob.attributes.code.instructions.IfEq;
|
||||
import net.runelite.deob.attributes.code.instructions.IfICmpEq;
|
||||
import net.runelite.deob.attributes.code.instructions.LDC_W;
|
||||
import net.runelite.deob.attributes.code.instructions.NOP;
|
||||
import net.runelite.deob.attributes.code.instructions.SiPush;
|
||||
@@ -55,7 +55,7 @@ public class MultiplyOneDeobfuscatorTest
|
||||
new SiPush(ins, (short) 256),
|
||||
|
||||
new ILoad(ins, 0),
|
||||
new If0(ins, label),
|
||||
new IfEq(ins, label),
|
||||
|
||||
new IConst_2(ins),
|
||||
new Goto(ins, label2),
|
||||
@@ -111,7 +111,7 @@ public class MultiplyOneDeobfuscatorTest
|
||||
new SiPush(ins, (short) 256),
|
||||
|
||||
new ILoad(ins, 0),
|
||||
new If0(ins, label),
|
||||
new IfEq(ins, label),
|
||||
|
||||
label,
|
||||
one,
|
||||
@@ -195,7 +195,7 @@ public class MultiplyOneDeobfuscatorTest
|
||||
|
||||
new IConst_M1(ins),
|
||||
new ILoad(ins, 0),
|
||||
new If(ins, label),
|
||||
new IfICmpEq(ins, label),
|
||||
|
||||
new Goto(ins, label2),
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package net.runelite.deob.deobfuscators.rename;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.runelite.deob.ClassGroup;
|
||||
import net.runelite.deob.Field;
|
||||
import net.runelite.deob.Method;
|
||||
import net.runelite.deob.attributes.Code;
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction;
|
||||
import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction;
|
||||
import net.runelite.deob.attributes.code.instructions.InvokeStatic;
|
||||
import net.runelite.deob.execution.Execution;
|
||||
import net.runelite.deob.execution.Frame;
|
||||
import net.runelite.deob.util.JarUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Rename
|
||||
{
|
||||
private List<Instruction> getInstructionsInMethodInclStatic(Method method, Set<Method> visited)
|
||||
{
|
||||
List<Instruction> ilist = new ArrayList<>();
|
||||
|
||||
if (visited.contains(method))
|
||||
return ilist;
|
||||
visited.add(method);
|
||||
|
||||
Code code = method.getCode();
|
||||
if (code == null)
|
||||
return ilist;
|
||||
|
||||
for (Instruction i : code.getInstructions().getInstructions())
|
||||
{
|
||||
if (i instanceof InvokeStatic)
|
||||
{
|
||||
InvokeInstruction ii = (InvokeInstruction) i;
|
||||
List<Method> methods = ii.getMethods();
|
||||
|
||||
if (methods.isEmpty())
|
||||
continue;
|
||||
|
||||
Method m = methods.get(0);
|
||||
ilist.addAll(this.getInstructionsInMethodInclStatic(m, visited));
|
||||
}
|
||||
else
|
||||
{
|
||||
ilist.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
return ilist;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws IOException
|
||||
{
|
||||
ClassGroup one = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")), two = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar"));
|
||||
|
||||
Execution eone = new Execution(one);
|
||||
eone.setBuildGraph(true);
|
||||
eone.populateInitialMethods();
|
||||
eone.run();
|
||||
|
||||
Execution etwo = new Execution(two);
|
||||
etwo.setBuildGraph(true);
|
||||
etwo.populateInitialMethods();
|
||||
etwo.run();
|
||||
|
||||
// Method m1 = one.findClass("client").findMethod("vmethod3096"), m2 = two.findClass("client").findMethod("vmethod2975");
|
||||
//
|
||||
// List<SetFieldInstruction> l1 = (List<SetFieldInstruction>) getInstructionsInMethodInclStatic(m1, new HashSet()).stream().filter(i -> i instanceof SetFieldInstruction).collect(Collectors.toList()),
|
||||
// l2 = (List<SetFieldInstruction>) getInstructionsInMethodInclStatic(m2, new HashSet()).stream().filter(i -> i instanceof SetFieldInstruction).collect(Collectors.toList());
|
||||
//
|
||||
//
|
||||
// List<Field> lf1 =(List) l1.stream().filter(i -> i.getMyField() != null).map(i -> i.getMyField()).distinct().collect(Collectors.toList()),
|
||||
// lf2 = l2.stream().filter(i -> i.getMyField() != null).map(i -> i.getMyField()).distinct().collect(Collectors.toList());
|
||||
//
|
||||
// for (int i = 0; i< 100; ++i)
|
||||
// {
|
||||
// Field f1 = lf1.get(i), f2 = lf2.get(i);
|
||||
//
|
||||
// System.out.println(f1 + " <-> " + f2);
|
||||
// }
|
||||
// number of setfields
|
||||
//List<Frame> f1 = eone.processedFrames.stream().filter(f -> f.getMethod() == m1).collect(Collectors.toList()),
|
||||
// f2 = etwo.processedFrames.stream().filter(f -> f.getMethod() == m2).collect(Collectors.toList());
|
||||
|
||||
//System.out.println(ll1);
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package net.runelite.deob.execution;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import net.runelite.deob.ClassFile;
|
||||
import net.runelite.deob.ClassGroup;
|
||||
import net.runelite.deob.Method;
|
||||
import net.runelite.deob.deobfuscators.rename.InstructionList;
|
||||
import net.runelite.deob.deobfuscators.rename.Rename2;
|
||||
import net.runelite.deob.deobfuscators.rename.graph.Graph;
|
||||
import net.runelite.deob.deobfuscators.rename.graph.Vertex;
|
||||
import net.runelite.deob.util.NameMappings;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
class TestClass2
|
||||
{
|
||||
int array[];
|
||||
int count;
|
||||
|
||||
void method1()
|
||||
{
|
||||
array[++count - 1] = 1;
|
||||
array[++count - 1] = 2;
|
||||
}
|
||||
|
||||
void method2()
|
||||
{
|
||||
array[++count - 1] = 1;
|
||||
array[++count - 1] = 2;
|
||||
array[++count - 1] = 3;
|
||||
array[++count - 1] = 4;
|
||||
}
|
||||
}
|
||||
|
||||
public class GraphTest
|
||||
{
|
||||
private ClassGroup loadClassGroup(String name) throws IOException
|
||||
{
|
||||
ClassGroup group = new ClassGroup();
|
||||
|
||||
ClassFile cf = this.loadClass(name);
|
||||
group.addClass(cf);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
private ClassFile loadClass(String name) throws IOException
|
||||
{
|
||||
InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/deob/execution/" + name + ".class");
|
||||
Assert.assertNotNull(in);
|
||||
|
||||
ClassGroup group = new ClassGroup();
|
||||
ClassFile cf = new ClassFile(group, new DataInputStream(in));
|
||||
group.addClass(cf);
|
||||
return cf;
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void test() throws IOException
|
||||
{
|
||||
ClassGroup group1 = this.loadClassGroup("TestClass"), group2 = this.loadClassGroup("TestClass");
|
||||
|
||||
Execution e = new Execution(group1);
|
||||
e.setBuildGraph(true);
|
||||
e.populateInitialMethods();
|
||||
e.run();
|
||||
|
||||
Execution e2 = new Execution(group2);
|
||||
e2.setBuildGraph(true);
|
||||
e2.populateInitialMethods();
|
||||
e2.run();
|
||||
|
||||
Graph graph = e.getGraph();
|
||||
Graph graph2 = e2.getGraph();
|
||||
|
||||
Assert.assertEquals(4, graph.getVerticies().size());
|
||||
|
||||
Method m = group1.getClasses().get(0).findMethod("init");
|
||||
Vertex v = graph.getVertexFor(m);
|
||||
|
||||
Assert.assertEquals(1, v.getEdges().size());
|
||||
|
||||
m = group1.getClasses().get(0).findMethod("method2");
|
||||
v = graph.getVertexFor(m);
|
||||
|
||||
Assert.assertEquals(1, v.getEdges().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() throws IOException
|
||||
{
|
||||
ClassGroup group1 = this.loadClassGroup("one/TestClass"), group2 = this.loadClassGroup("two/TestClass");
|
||||
Rename2 rename2 = new Rename2();
|
||||
NameMappings mappings = rename2.run(group1, group2); // 2->1
|
||||
|
||||
ClassFile cf1 = group1.getClasses().get(0),
|
||||
cf2 = group2.getClasses().get(0);
|
||||
|
||||
Method m2 = cf2.findMethod("init");
|
||||
Assert.assertTrue(mappings.get(m2.getPoolMethod()).equals("init"));
|
||||
|
||||
m2 = cf2.findMethod("method6");
|
||||
String to = mappings.get(m2.getPoolMethod());
|
||||
Assert.assertNotNull(to);
|
||||
Assert.assertTrue(to.equals("method2"));
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testVertexEquals() throws IOException
|
||||
{
|
||||
ClassGroup group1 = this.loadClassGroup("one/TestClass"), group2 = this.loadClassGroup("two/TestClass");
|
||||
|
||||
ClassFile cf1 = group1.getClasses().get(0),
|
||||
cf2 = group2.getClasses().get(0);
|
||||
|
||||
Graph g1 = new Graph(), g2 = new Graph();
|
||||
|
||||
Vertex v1 = new Vertex(g1, cf2.findMethod("method6")),
|
||||
v2 = new Vertex(g2, cf1.findMethod("method2"));
|
||||
|
||||
Assert.assertTrue(v1.couldBeEqual(v2));
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void test3() throws IOException
|
||||
{
|
||||
ClassFile cf1 = this.loadClass("TestClass2"), cf2 = this.loadClass("TestClass2");
|
||||
|
||||
Method m1 = cf1.findMethod("method1"), m2 = cf2.findMethod("method2");
|
||||
|
||||
InstructionList il1 = new InstructionList(m1.getCode().getInstructions().getInstructions()),
|
||||
il2 = new InstructionList(m2.getCode().getInstructions().getInstructions());
|
||||
|
||||
Assert.assertFalse(il1.couldBeEqual(il2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user