Search in sources :

Example 1 with E1Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt in project dex2jar by pxb1988.

the class ArrayNullPointerTransformer method replaceNPE.

private void replaceNPE(StmtList stmts, List<Local> locals, Stmt p) {
    List<Value> values = new ArrayList<Value>();
    switch(p.et) {
        case E1:
            tryAdd(((E1Stmt) p).op.trim(), values);
            break;
        case E2:
            E2Stmt e2 = (E2Stmt) p;
            switch(e2.op1.trim().vt) {
                case LOCAL:
                    tryAdd(e2.op2.trim(), values);
                    break;
                case ARRAY:
                    ArrayExpr ae = (ArrayExpr) e2.op1.trim();
                    if (tryAdd(ae.op1.trim(), values)) {
                        if (tryAdd(ae.op2.trim(), values)) {
                            tryAdd(e2.op2.trim(), values);
                        }
                    }
                    break;
                case // putfield
                FIELD:
                    FieldExpr fe = (FieldExpr) e2.op1.trim();
                    if (fe.op == null || fe.op.trim() == null || tryAdd(fe.op.trim(), values)) {
                        tryAdd(e2.op2.trim(), values);
                    }
                    break;
                default:
                    if (tryAdd(e2.op2.trim(), values)) {
                        tryAdd(e2.op1.trim(), values);
                    }
            }
        default:
    }
    for (Value value : values) {
        switch(value.vt) {
            case CONSTANT:
            case LOCAL:
                break;
            default:
                Local n = Exprs.nLocal("xxx");
                locals.add(n);
                stmts.insertBefore(p, Stmts.nAssign(n, value));
        }
    }
    stmts.insertBefore(p, Stmts.nThrow(Exprs.nInvokeNew(new Value[0], new String[0], "Ljava/lang/NullPointerException;")));
    stmts.remove(p);
}
Also used : ArrayExpr(com.googlecode.dex2jar.ir.expr.ArrayExpr) E2Stmt(com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt) ArrayList(java.util.ArrayList) Value(com.googlecode.dex2jar.ir.expr.Value) Local(com.googlecode.dex2jar.ir.expr.Local) FieldExpr(com.googlecode.dex2jar.ir.expr.FieldExpr) E1Stmt(com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt)

Aggregations

ArrayExpr (com.googlecode.dex2jar.ir.expr.ArrayExpr)1 FieldExpr (com.googlecode.dex2jar.ir.expr.FieldExpr)1 Local (com.googlecode.dex2jar.ir.expr.Local)1 Value (com.googlecode.dex2jar.ir.expr.Value)1 E1Stmt (com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt)1 E2Stmt (com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt)1 ArrayList (java.util.ArrayList)1