Search in sources :

Example 1 with DexStmtNode

use of com.googlecode.d2j.node.insn.DexStmtNode in project dex2jar by pxb1988.

the class BaksmaliDumper method accept.

void accept(Out out, DexCodeNode code, DexCodeVisitor v) {
    if (code.tryStmts != null) {
        for (TryCatchNode n : code.tryStmts) {
            n.accept(v);
        }
    }
    if (code.debugNode != null) {
        DexDebugVisitor ddv = v.visitDebug();
        if (ddv != null) {
            code.debugNode.accept(ddv);
            ddv.visitEnd();
        }
    }
    if (code.totalRegister >= 0 && code.stmts.size() > 0) {
        v.visitRegister(code.totalRegister);
    }
    for (DexStmtNode n : code.stmts) {
        if (n instanceof DexLabelStmtNode) {
            n.accept(v);
        } else {
            out.push();
            n.accept(v);
            out.pop();
        }
    }
}
Also used : DexDebugVisitor(com.googlecode.d2j.visitors.DexDebugVisitor) DexStmtNode(com.googlecode.d2j.node.insn.DexStmtNode) DexLabelStmtNode(com.googlecode.d2j.node.insn.DexLabelStmtNode)

Example 2 with DexStmtNode

use of com.googlecode.d2j.node.insn.DexStmtNode in project dex2jar by pxb1988.

the class SmaliCodeVisitor method visitF31tStmt.

/* package */
void visitF31tStmt(final Op op, final int reg, final DexLabel label) {
    add(new DexStmtNode(op) {

        @Override
        public void accept(DexCodeVisitor cv) {
            int labelIndex = findLabelIndex(label);
            if (labelIndex < 0 || labelIndex >= needCareStmts.size()) {
                throw new RuntimeException("can't find label for " + op + " " + label);
            }
            switch(op) {
                case PACKED_SWITCH:
                    PackedSwitchStmt packedSwitchStmt = (PackedSwitchStmt) needCareStmts.get(labelIndex + 1);
                    cv.visitPackedSwitchStmt(op, reg, packedSwitchStmt.firstCase, packedSwitchStmt.labels);
                    break;
                case SPARSE_SWITCH:
                    SparseSwitchStmt sparseSwitchStmt = (SparseSwitchStmt) needCareStmts.get(labelIndex + 1);
                    cv.visitSparseSwitchStmt(op, reg, sparseSwitchStmt.cases, sparseSwitchStmt.labels);
                    break;
                case FILL_ARRAY_DATA:
                    ArrayDataStmt arrayDataStmt = (ArrayDataStmt) needCareStmts.get(labelIndex + 1);
                    Object v;
                    byte[] vs = arrayDataStmt.objs;
                    switch(arrayDataStmt.length) {
                        case 1:
                            {
                                v = vs;
                            }
                            break;
                        case 2:
                            {
                                short[] vs1 = new short[vs.length / 2];
                                for (int i = 0; i < vs1.length; i++) {
                                    vs1[i] = (short) ((vs[i * 2] & 0xFF) | ((vs[i * 2 + 1] & 0xFF) << 8));
                                }
                                v = vs1;
                            }
                            break;
                        case 4:
                            {
                                int[] vs1 = new int[vs.length / 4];
                                for (int i = 0; i < vs1.length; i++) {
                                    int base = i * 4;
                                    vs1[i] = (vs[base + 0] & 0xFF) | ((vs[base + 1] & 0xFF) << 8) | ((vs[base + 2] & 0xFF) << 16) | ((vs[base + 3] & 0xFF) << 24);
                                }
                                v = vs1;
                            }
                            break;
                        case 8:
                            {
                                long[] vs1 = new long[vs.length / 8];
                                for (int i = 0; i < vs1.length; i++) {
                                    int base = i * 8;
                                    int a = ((vs[base + 0] & 0xFF) << 0) | ((vs[base + 1] & 0xFF) << 8) | ((vs[base + 2] & 0xFF) << 16) | ((vs[base + 3] & 0xFF) << 24);
                                    int b = ((vs[base + 4] & 0xFF) << 0) | ((vs[base + 5] & 0xFF) << 8) | ((vs[base + 6] & 0xFF) << 16) | ((vs[base + 7] & 0xFF) << 24);
                                    vs1[i] = (((long) b) << 32) | a;
                                }
                                v = vs1;
                            }
                            break;
                        default:
                            throw new RuntimeException();
                    }
                    cv.visitFillArrayDataStmt(Op.FILL_ARRAY_DATA, reg, v);
                    break;
                default:
                    throw new RuntimeException();
            }
        }
    });
}
Also used : DexStmtNode(com.googlecode.d2j.node.insn.DexStmtNode) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor)

Example 3 with DexStmtNode

use of com.googlecode.d2j.node.insn.DexStmtNode in project dex2jar by pxb1988.

the class Dex2IrAdapter method convert.

public IrMethod convert(DexCodeNode codeNode) {
    if (codeNode.tryStmts != null) {
        for (TryCatchNode n : codeNode.tryStmts) {
            n.accept(this);
        }
    }
    if (codeNode.debugNode != null) {
        DexDebugVisitor ddv = this.visitDebug();
        if (ddv != null) {
            codeNode.debugNode.accept(ddv);
            ddv.visitEnd();
        }
    }
    lastIsInvokeOrFilledNewArray = false;
    if (codeNode.totalRegister >= 0) {
        this.visitRegister(codeNode.totalRegister);
    }
    for (DexStmtNode n : codeNode.stmts) {
        n.accept(this);
        if (n instanceof FilledNewArrayStmtNode) {
            lastIsInvokeOrFilledNewArray = true;
        } else if (n instanceof MethodStmtNode) {
            lastIsInvokeOrFilledNewArray = !((MethodStmtNode) n).method.getReturnType().equals("V");
        } else if (!(n instanceof DexLabelStmtNode)) {
            lastIsInvokeOrFilledNewArray = false;
        }
    }
    visitEnd();
    return irMethod;
}
Also used : DexDebugVisitor(com.googlecode.d2j.visitors.DexDebugVisitor) MethodStmtNode(com.googlecode.d2j.node.insn.MethodStmtNode) TryCatchNode(com.googlecode.d2j.node.TryCatchNode) DexStmtNode(com.googlecode.d2j.node.insn.DexStmtNode) DexLabelStmtNode(com.googlecode.d2j.node.insn.DexLabelStmtNode) FilledNewArrayStmtNode(com.googlecode.d2j.node.insn.FilledNewArrayStmtNode)

Aggregations

DexStmtNode (com.googlecode.d2j.node.insn.DexStmtNode)3 DexLabelStmtNode (com.googlecode.d2j.node.insn.DexLabelStmtNode)2 DexDebugVisitor (com.googlecode.d2j.visitors.DexDebugVisitor)2 TryCatchNode (com.googlecode.d2j.node.TryCatchNode)1 FilledNewArrayStmtNode (com.googlecode.d2j.node.insn.FilledNewArrayStmtNode)1 MethodStmtNode (com.googlecode.d2j.node.insn.MethodStmtNode)1 DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)1