Search in sources :

Example 1 with IrMethod

use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.

the class ArrayElementTransformer method main.

public static void main(String... args) {
    IrMethod m = new IrMethod();
    m.isStatic = true;
    m.name = "a";
    m.args = new String[0];
    m.ret = "[Ljava/lang/String;";
    m.owner = "La;";
    Local array = Exprs.nLocal(1);
    m.locals.add(array);
    m.stmts.add(Stmts.nAssign(array, Exprs.nNewArray("Ljava/lang/String;", Exprs.nInt(2))));
    m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(1), "Ljava/lang/String;"), Exprs.nString("123")));
    m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(0), "Ljava/lang/String;"), Exprs.nString("456")));
    m.stmts.add(Stmts.nReturn(array));
    new ArrayElementTransformer().transform(m);
}
Also used : IrMethod(com.googlecode.dex2jar.ir.IrMethod)

Example 2 with IrMethod

use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.

the class FillArrayTransformer method main.

public static void main(String... args) {
    IrMethod m = new IrMethod();
    m.isStatic = true;
    m.name = "a";
    m.args = new String[0];
    m.ret = "[Ljava/lang/String;";
    m.owner = "La;";
    Local array = Exprs.nLocal(1);
    m.locals.add(array);
    m.stmts.add(Stmts.nAssign(array, Exprs.nNewArray("Ljava/lang/String;", Exprs.nInt(2))));
    m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(1), "Ljava/lang/String;"), Exprs.nString("123")));
    m.stmts.add(Stmts.nAssign(Exprs.nArray(array, Exprs.nInt(0), "Ljava/lang/String;"), Exprs.nString("456")));
    m.stmts.add(Stmts.nReturn(array));
    new FillArrayTransformer().transform(m);
    System.out.println(m);
}
Also used : IrMethod(com.googlecode.dex2jar.ir.IrMethod)

Example 3 with IrMethod

use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.

the class ConstTransformerTest method test04.

@Test
public void test04() {
    IrMethod jm = new IrMethod();
    Local a = nLocal("a");
    Local b = nLocal("b");
    Local p = nLocal("p");
    jm.locals.add(a);
    jm.locals.add(b);
    jm.locals.add(p);
    jm.stmts.add(nAssign(a, nString(new String("a String"))));
    jm.stmts.add(nAssign(b, nString(new String("a String"))));
    jm.stmts.add(nAssign(p, Exprs.nPhi(a, b)));
    UnopStmt retStmt = nReturn(p);
    jm.stmts.add(retStmt);
    new ConstTransformer().transform(jm);
    Assert.assertTrue(jm.locals.size() == 3);
    Assert.assertTrue(jm.stmts.getSize() == 4);
    Assert.assertEquals(VT.CONSTANT, retStmt.op.vt);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) Exprs.nString(com.googlecode.dex2jar.ir.expr.Exprs.nString) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Example 4 with IrMethod

use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.

the class DecryptStringCmd method decryptByIr.

private boolean decryptByIr(ClassNode cn, Map<MethodConfig, MethodConfig> map) {
    MethodConfig key = this.key;
    boolean changed = false;
    for (Iterator<MethodNode> it = cn.methods.iterator(); it.hasNext(); ) {
        MethodNode m = it.next();
        if (m.instructions == null) {
            continue;
        }
        key.owner = cn.name;
        key.name = m.name;
        key.desc = m.desc;
        if (map.containsKey(key)) {
            if (deleteMethod) {
                it.remove();
            }
            continue;
        }
        if (false && verbose) {
            System.out.println();
            System.out.println("===============");
            System.out.println("on method " + cn.name + ";->" + m.name + m.desc);
        }
        boolean find = false;
        // search for the decrypt method
        for (AbstractInsnNode p = m.instructions.getFirst(); p != null; p = p.getNext()) {
            if (p.getOpcode() == Opcodes.INVOKESTATIC) {
                MethodInsnNode mn = (MethodInsnNode) p;
                key.owner = mn.owner;
                key.name = mn.name;
                key.desc = mn.desc;
                MethodConfig config = map.get(key);
                if (config != null) {
                    find = true;
                }
            }
        }
        if (find) {
            try {
                // copy m to m2 for cleanup debug info
                MethodNode m2 = new MethodNode();
                m2.tryCatchBlocks = new ArrayList<>();
                m2.name = m.name;
                m2.access = m.access;
                m2.desc = m.desc;
                m.accept(m2);
                cleanDebug(m2);
                // convert m2 to ir
                IrMethod irMethod = J2IRConverter.convert(cn.name, m2);
                // opt and decrypt
                optAndDecrypt(irMethod, map);
                // convert ir to m3
                MethodNode m3 = new MethodNode();
                m3.tryCatchBlocks = new ArrayList<>();
                new IR2JConverter(true).convert(irMethod, m3);
                // copy back m3 to m
                m.maxLocals = -1;
                m.maxLocals = -1;
                m.instructions = m3.instructions;
                m.tryCatchBlocks = m3.tryCatchBlocks;
                m.localVariables = null;
                changed = true;
            } catch (Exception ex) {
                if (verbose) {
                    ex.printStackTrace();
                }
            }
        }
    }
    return changed;
}
Also used : IrMethod(com.googlecode.dex2jar.ir.IrMethod) IR2JConverter(com.googlecode.d2j.converter.IR2JConverter) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with IrMethod

use of com.googlecode.dex2jar.ir.IrMethod in project dex2jar by pxb1988.

the class ConstTransformerTest method test00.

@Test
public void test00() {
    IrMethod jm = new IrMethod();
    Local a = nLocal("a");
    jm.locals.add(a);
    jm.stmts.add(nAssign(a, nString("a String")));
    UnopStmt retStmt = nReturn(a);
    jm.stmts.add(retStmt);
    new ConstTransformer().transform(jm);
    Assert.assertTrue(jm.locals.size() == 1);
    Assert.assertTrue(jm.stmts.getSize() == 2);
    Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Aggregations

IrMethod (com.googlecode.dex2jar.ir.IrMethod)14 Exprs.nLocal (com.googlecode.dex2jar.ir.expr.Exprs.nLocal)5 Local (com.googlecode.dex2jar.ir.expr.Local)5 UnopStmt (com.googlecode.dex2jar.ir.stmt.UnopStmt)5 ConstTransformer (com.googlecode.dex2jar.ir.ts.ConstTransformer)5 Test (org.junit.Test)5 IOException (java.io.IOException)3 IR2JConverter (com.googlecode.d2j.converter.IR2JConverter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DexFileNode (com.googlecode.d2j.node.DexFileNode)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1 StmtTraveler (com.googlecode.dex2jar.ir.StmtTraveler)1 Exprs.nString (com.googlecode.dex2jar.ir.expr.Exprs.nString)1 Value (com.googlecode.dex2jar.ir.expr.Value)1 LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)1 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)1 Method (java.lang.reflect.Method)1 Path (java.nio.file.Path)1 Before (org.junit.Before)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1