use of net.runelite.asm.attributes.code.instructions.Pop2 in project runelite by runelite.
the class DupDeobfuscator method undup2_x1.
private void undup2_x1(InstructionContext ictx) {
assert ictx.getInstruction() instanceof Dup2_X1;
// only support this form
assert ictx.getPops().size() == 2;
// I L -> L I L
Instructions instructions = ictx.getInstruction().getInstructions();
// can't swap a long on the stack, so
int idx = instructions.getInstructions().indexOf(ictx.getInstruction());
assert idx != -1;
// remove dup2_x1
instructions.remove(ictx.getInstruction());
// pop long
instructions.addInstruction(idx++, new Pop2(instructions));
// pop int
instructions.addInstruction(idx++, new Pop(instructions));
// insert copy of long
idx = copy(ictx.getPops().get(0), instructions, idx);
// insert copy of int
idx = copy(ictx.getPops().get(1), instructions, idx);
// insert copy of long
/* idx = */
copy(ictx.getPops().get(0), instructions, idx);
}
use of net.runelite.asm.attributes.code.instructions.Pop2 in project runelite by runelite.
the class DupDeobfuscatorTest method test.
@Test
public void test() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(5);
Instruction[] prepareVariables = { new LDC(ins, 1), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1129258489), constant2 = new LDC(ins, -1692330935), constant3 = new LDC(ins, 1641298955), constant4 = new LDC(ins, 1043501435);
Instruction[] body = { // this
new AConstNull(ins), // this
new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), // putfield
new Pop2(ins), constant3, new IMul(ins), constant4, new IMul(ins), // putfield
new Pop2(ins), 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;
assert constant3.getConstantAsInt() * constant4.getConstantAsInt() * constant1.getConstantAsInt() == 1;
Deobfuscator d = new DupDeobfuscator();
d.run(group);
// assert the dup_x1 was removed
long dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup_X1).count();
Assert.assertEquals(0, dupCount);
}
use of net.runelite.asm.attributes.code.instructions.Pop2 in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test12.
// 020 aload_0
// 021 aload_0
// 022 iload_1
// 023 ldc 1129258489
// 024 imul // this, this, mul
// 025 swap // this, mul s, this
// 026 iload_1
// 027 iconst_1
// 028 imul // this, mul s, this, mul
// 029 iconst_1
// 030 imul
// 031 putfield class81/field1351 I // this, mul
// 032 iconst_1
// 033 imul
// 034 ldc -1692330935
// 035 imul
// 036 putfield class81/field1326 I
@Test
public void test12() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(5);
Instruction[] prepareVariables = { new LDC(ins, 1), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1129258489);
LDC constant2 = new LDC(ins, -1692330935);
Instruction[] body = { // this
new AConstNull(ins), // this
new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), // null, mul, null
new Swap(ins), new ILoad(ins, 0), // putfield
new Pop2(ins), constant2, new IMul(ins), // putfield
new Pop2(ins), 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.instructions.Pop2 in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test11.
// 020 aload_0
// 021 aload_0
// 022 iload_1
// 023 ldc 1129258489
// 024 imul
// 025 dup_x1
// 026 ldc -1692330935
// 027 imul
// 028 putfield class81/field1351 I
// 029 ldc 1641298955
// 030 imul // this pops other side of dup_x1
// 031 ldc 1043501435
// 032 imul
// 033 putfield class81/field1326 I
@Test
public void test11() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(5);
Instruction[] prepareVariables = { new LDC(ins, 1), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1129258489), constant2 = new LDC(ins, -1692330935), constant3 = new LDC(ins, 1641298955), constant4 = new LDC(ins, 1043501435);
Instruction[] body = { // this
new AConstNull(ins), // this
new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), // putfield
new Pop2(ins), constant3, new IMul(ins), constant4, new IMul(ins), // putfield
new Pop2(ins), 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;
assert constant3.getConstantAsInt() * constant4.getConstantAsInt() * constant1.getConstantAsInt() == 1;
;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
Assert.assertEquals(1, constant3.getConstantAsInt());
Assert.assertEquals(1, constant4.getConstantAsInt());
}
Aggregations