use of net.runelite.asm.attributes.code.Label in project runelite by runelite.
the class LookupSwitch method getJumps.
@Override
public List<Label> getJumps() {
List<Label> list = new ArrayList<>();
for (Label i : branchi) {
list.add(i);
}
list.add(defi);
return list.stream().distinct().collect(Collectors.toList());
}
use of net.runelite.asm.attributes.code.Label in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test3.
@Test
public void test3() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1381104939), constant2 = new LDC(ins, 1381104939), constant3 = new LDC(ins, 981643079), constant4 = new LDC(ins, 1807370871), constant5 = new LDC(ins, 981643079);
Label label1 = new Label(ins);
Instruction[] body = { constant4, constant1, new ILoad(ins, 0), new IMul(ins), new LDC(ins, 0), new IfEq(ins, label1), constant2, new IMul(ins), label1, constant3, new IMul(ins), // constant4
new IMul(ins), constant5, new IMul(ins), new Pop(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
assert constant4.getConstantAsInt() * constant5.getConstantAsInt() == 1;
// {
// Collection<InstructionContext> ctxs = e.getInstructonContexts(body[3]);
// assert ctxs.size() == 1;
//
// InstructionContext ictx = ctxs.iterator().next();
// boolean onlyPath = MultiplicationDeobfuscator.isOnlyPath(e, ictx);
// Assert.assertFalse(onlyPath);
// }
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1381104939, constant1.getConstantAsInt());
Assert.assertEquals(1381104939, constant2.getConstantAsInt());
Assert.assertEquals(1, constant3.getConstantAsInt());
Assert.assertEquals(1, constant4.getConstantAsInt());
// assumes result is moved to the end here.
Assert.assertEquals(981643079, constant5.getConstantAsInt());
}
use of net.runelite.asm.attributes.code.Label in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test8.
@Test
public void test8() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, -1616202347);
LDC constant2 = new LDC(ins, 2747837);
Label label1 = new Label(ins), label2 = new Label(ins), label3 = new Label(ins);
Instruction[] body = { constant1, constant2, new IMul(ins), new ILoad(ins, 0), new LDC(ins, 42), new IfEq(ins, label1), new Goto(ins, label2), label1, new LDC(ins, -1), new Goto(ins, label3), label2, new LDC(ins, 0), new Goto(ins, label3), label3, new InvokeStatic(ins, group.findClass("test").findMethod("func2").getPoolMethod()), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
}
use of net.runelite.asm.attributes.code.Label in project runelite by runelite.
the class MultiplyOneDeobfuscatorTest method test.
@Test
public void test() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) ins.addInstruction(i);
Label label = new Label(ins), label2 = new Label(ins);
LDC one = new LDC(ins, 1);
IMul mul = new IMul(ins);
Instruction[] body = { new SiPush(ins, (short) 256), new ILoad(ins, 0), new IfEq(ins, label), label, one, label2, mul, new VReturn(ins) };
for (Instruction i : body) ins.addInstruction(i);
// check execution runs ok
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
Deobfuscator d = new MultiplyOneDeobfuscator(false);
d.run(group);
Assert.assertTrue(one.getInstructions() == null);
Assert.assertTrue(mul.getInstructions() == null);
}
use of net.runelite.asm.attributes.code.Label in project runelite by runelite.
the class MultiplyOneDeobfuscatorTest method testDir.
@Test
public void testDir() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) ins.addInstruction(i);
Label label = new Label(ins), label2 = new Label(ins);
LDC one = new LDC(ins, 1);
Instruction[] body = { new SiPush(ins, (short) 256), new ILoad(ins, 0), new IfEq(ins, label), new LDC(ins, 2), new Goto(ins, label2), label, one, label2, new IMul(ins), new VReturn(ins) };
for (Instruction i : body) ins.addInstruction(i);
// check execution runs ok
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
Deobfuscator d = new MultiplyOneDeobfuscator(false);
d.run(group);
Assert.assertTrue(one.getInstructions() != null);
}
Aggregations