Search in sources :

Example 1 with StmtSearcher

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

the class NpeTransformer method transformReportChanged.

@Override
public boolean transformReportChanged(IrMethod method) {
    boolean changed = false;
    if (method.locals.size() == 0) {
        return false;
    }
    StmtSearcher st = new StmtSearcher() {

        @Override
        public void travel(Stmt stmt) {
            if (stmt.st == Stmt.ST.FILL_ARRAY_DATA) {
                if (isNull(stmt.getOp1())) {
                    throw NPE;
                }
            }
            super.travel(stmt);
        }

        @Override
        public void travel(Value op) {
            switch(op.vt) {
                case INVOKE_VIRTUAL:
                case INVOKE_SPECIAL:
                case INVOKE_INTERFACE:
                    {
                        if (isNull(op.getOps()[0])) {
                            throw NPE;
                        }
                    }
                    break;
                case ARRAY:
                    {
                        if (isNull(op.getOp1())) {
                            throw NPE;
                        }
                    }
                    break;
                case FIELD:
                    {
                        if (isNull(op.getOp())) {
                            throw NPE;
                        }
                    }
                    break;
                case IDIV:
                    if (op.getOp2().vt == Value.VT.CONSTANT) {
                        Constant constant = (Constant) op.getOp2();
                        if (((Number) constant.value).intValue() == 0) {
                            throw DIVE;
                        }
                    }
                    break;
                case LDIV:
                    if (op.getOp2().vt == Value.VT.CONSTANT) {
                        Constant constant = (Constant) op.getOp2();
                        if (((Number) constant.value).longValue() == 0) {
                            throw DIVE;
                        }
                    }
                    break;
                case NEW_ARRAY:
                    if (op.getOp().vt == Value.VT.CONSTANT) {
                        Constant constant = (Constant) op.getOp();
                        if (((Number) constant.value).intValue() < 0) {
                            throw NEGATIVE_ARRAY_SIZE;
                        }
                    }
                    break;
                case NEW_MUTI_ARRAY:
                    for (Value size : op.getOps()) {
                        if (size.vt == Value.VT.CONSTANT) {
                            Constant constant = (Constant) size;
                            if (((Number) constant.value).intValue() < 0) {
                                throw NEGATIVE_ARRAY_SIZE;
                            }
                        }
                    }
                    break;
                default:
            }
        }
    };
    for (Stmt p = method.stmts.getFirst(); p != null; ) {
        try {
            st.travel(p);
            p = p.getNext();
        } catch (MustThrowException e) {
            replace(method, p);
            Stmt q = p.getNext();
            method.stmts.remove(p);
            changed = true;
            p = q;
        }
    }
    return changed;
}
Also used : Constant(com.googlecode.dex2jar.ir.expr.Constant) Value(com.googlecode.dex2jar.ir.expr.Value) StmtSearcher(com.googlecode.dex2jar.ir.StmtSearcher) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt)

Aggregations

StmtSearcher (com.googlecode.dex2jar.ir.StmtSearcher)1 Constant (com.googlecode.dex2jar.ir.expr.Constant)1 Value (com.googlecode.dex2jar.ir.expr.Value)1 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)1