Search in sources :

Example 6 with AConstNull

use of net.runelite.asm.attributes.code.instructions.AConstNull in project runelite by runelite.

the class DupDeobfuscatorTest method test2.

// 035   aload_0               // this
// 036   dup                   // this this
// 037   getfield              class153/field2097 I // this I
// 038   ldc                   830083863
// 039   imul                                      // this I
// 040   ldc                   830083863
// 041   iadd                                      // this I
// 042   dup_x1                                    // I this I
@Test
public void test2() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(3);
    Instruction[] body = { // this
    new AConstNull(ins), // this this
    new Dup(ins), new GetField(ins, new Field(new Class("test"), "field", Type.INT)), // this this I I
    new LDC(ins, 830083863), // this this I
    new IMul(ins), new LDC(ins, 830083863), new IAdd(ins), new Dup_X1(ins), new LDC(ins, 636900519), // pops dup
    new IMul(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new DupDeobfuscator();
    d.run(group);
    // assert the dup wasn't duplicated
    long dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup).count();
    Assert.assertEquals(1, dupCount);
    // assert the dup_x1 was removed
    dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup_X1).count();
    Assert.assertEquals(0, dupCount);
}
Also used : Pop2(net.runelite.asm.attributes.code.instructions.Pop2) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) GetField(net.runelite.asm.attributes.code.instructions.GetField) IMul(net.runelite.asm.attributes.code.instructions.IMul) Dup(net.runelite.asm.attributes.code.instructions.Dup) Code(net.runelite.asm.attributes.Code) Test(org.junit.Test) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Class(net.runelite.asm.pool.Class) ClassGroupFactory(net.runelite.deob.ClassGroupFactory) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) LDC(net.runelite.asm.attributes.code.instructions.LDC) IStore(net.runelite.asm.attributes.code.instructions.IStore) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Instructions(net.runelite.asm.attributes.code.Instructions) Field(net.runelite.asm.pool.Field) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) Assert(org.junit.Assert) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) GetField(net.runelite.asm.attributes.code.instructions.GetField) Instructions(net.runelite.asm.attributes.code.Instructions) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.pool.Field) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Class(net.runelite.asm.pool.Class) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Dup(net.runelite.asm.attributes.code.instructions.Dup) Test(org.junit.Test)

Example 7 with AConstNull

use of net.runelite.asm.attributes.code.instructions.AConstNull 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());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Pop2(net.runelite.asm.attributes.code.instructions.Pop2) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) Swap(net.runelite.asm.attributes.code.instructions.Swap) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 8 with AConstNull

use of net.runelite.asm.attributes.code.instructions.AConstNull 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());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Pop2(net.runelite.asm.attributes.code.instructions.Pop2) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 9 with AConstNull

use of net.runelite.asm.attributes.code.instructions.AConstNull in project runelite by runelite.

the class LvtTest method testReuseIndex.

@Test
public void testReuseIndex() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    Instruction[] body = { // var0 = null
    new AConstNull(ins), new AStore(ins, 0), // this forces a reindex to varn
    new LDC(ins, 0), new IStore(ins, 0), // var2 = null
    new AConstNull(ins), new AStore(ins, 2), // this forces a reindex to varn+1
    new LDC(ins, 0), new IStore(ins, 2), // var0 = 0L
    new LDC(ins, 0L), new LStore(ins, 0), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Lvt lvt = new Lvt();
    lvt.run(group);
    AStore astore1 = (AStore) body[1];
    IStore istore1 = (IStore) body[3];
    AStore astore2 = (AStore) body[5];
    IStore istore2 = (IStore) body[7];
    LStore lstore1 = (LStore) body[9];
    int astore1Idx = astore1.getVariableIndex();
    int istore1Idx = istore1.getVariableIndex();
    int astore2Idx = astore2.getVariableIndex();
    int istore2Idx = istore2.getVariableIndex();
    int lstore1Idx = lstore1.getVariableIndex();
    logger.debug("{} -> {}", astore1, astore1.getVariableIndex());
    logger.debug("{} -> {}", istore1, istore1.getVariableIndex());
    logger.debug("{} -> {}", astore2, astore2.getVariableIndex());
    logger.debug("{} -> {}", istore2, istore2.getVariableIndex());
    logger.debug("{} -> {}", lstore1, lstore1.getVariableIndex());
    Assert.assertNotEquals(astore1Idx, istore1Idx);
    Assert.assertNotEquals(astore2Idx, istore2Idx);
    // assert that the lstore doesn't overwrite an existing index
    Assert.assertNotEquals(lstore1Idx + 1, astore1Idx);
    Assert.assertNotEquals(lstore1Idx + 1, istore1Idx);
    Assert.assertNotEquals(lstore1Idx + 1, astore2Idx);
    Assert.assertNotEquals(lstore1Idx + 1, istore2Idx);
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) Instructions(net.runelite.asm.attributes.code.Instructions) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) LStore(net.runelite.asm.attributes.code.instructions.LStore) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) AStore(net.runelite.asm.attributes.code.instructions.AStore) ClassGroup(net.runelite.asm.ClassGroup) Test(org.junit.Test)

Example 10 with AConstNull

use of net.runelite.asm.attributes.code.instructions.AConstNull in project runelite by runelite.

the class ExprArgOrder method compare.

public static int compare(Method method, InstructionType type, Expression expr1, Expression expr2) {
    Instruction i1 = expr1.getHead().getInstruction();
    Instruction i2 = expr2.getHead().getInstruction();
    if (type == IF_ICMPEQ || type == IF_ICMPNE || type == IADD || type == IMUL) {
        if (!(i1 instanceof PushConstantInstruction) && (i2 instanceof PushConstantInstruction)) {
            return 1;
        }
        if (i1 instanceof PushConstantInstruction && !(i2 instanceof PushConstantInstruction)) {
            return -1;
        }
    }
    if (type == IF_ACMPEQ || type == IF_ACMPNE) {
        if (!(i1 instanceof AConstNull) && (i2 instanceof AConstNull)) {
            return 1;
        }
        if (i1 instanceof AConstNull && !(i2 instanceof AConstNull)) {
            return -1;
        }
    }
    int hash1 = hash(method, expr1.getHead());
    int hash2 = hash(method, expr2.getHead());
    if (hash1 == hash2) {
        logger.debug("Unable to differentiate {} from {}", expr1.getHead(), expr2.getHead());
    }
    return Integer.compare(hash1, hash2);
}
Also used : PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Aggregations

AConstNull (net.runelite.asm.attributes.code.instructions.AConstNull)10 Instruction (net.runelite.asm.attributes.code.Instruction)9 Code (net.runelite.asm.attributes.Code)7 Instructions (net.runelite.asm.attributes.code.Instructions)7 ClassGroup (net.runelite.asm.ClassGroup)6 LDC (net.runelite.asm.attributes.code.instructions.LDC)6 Test (org.junit.Test)6 IStore (net.runelite.asm.attributes.code.instructions.IStore)5 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)5 Execution (net.runelite.asm.execution.Execution)5 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)4 IMul (net.runelite.asm.attributes.code.instructions.IMul)4 Pop2 (net.runelite.asm.attributes.code.instructions.Pop2)4 Deobfuscator (net.runelite.deob.Deobfuscator)4 Type (net.runelite.asm.Type)3 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)3 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)3 ClassGroupFactory (net.runelite.deob.ClassGroupFactory)3 Assert (org.junit.Assert)3 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)2