Search in sources :

Example 6 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project soot by Sable.

the class AsmMethodSource method convert.

private void convert() {
    ArrayDeque<Edge> worklist = new ArrayDeque<Edge>();
    for (LabelNode ln : trapHandlers.keySet()) {
        if (checkInlineExceptionHandler(ln))
            handleInlineExceptionHandler(ln, worklist);
        else
            worklist.add(new Edge(ln, new ArrayList<Operand>()));
    }
    worklist.add(new Edge(instructions.getFirst(), new ArrayList<Operand>()));
    conversionWorklist = worklist;
    edges = HashBasedTable.create(1, 1);
    do {
        Edge edge = worklist.pollLast();
        AbstractInsnNode insn = edge.insn;
        stack = edge.stack;
        edge.stack = null;
        do {
            int type = insn.getType();
            if (type == FIELD_INSN) {
                convertFieldInsn((FieldInsnNode) insn);
            } else if (type == IINC_INSN) {
                convertIincInsn((IincInsnNode) insn);
            } else if (type == INSN) {
                convertInsn((InsnNode) insn);
                int op = insn.getOpcode();
                if ((op >= IRETURN && op <= RETURN) || op == ATHROW) {
                    break;
                }
            } else if (type == INT_INSN) {
                convertIntInsn((IntInsnNode) insn);
            } else if (type == LDC_INSN) {
                convertLdcInsn((LdcInsnNode) insn);
            } else if (type == JUMP_INSN) {
                JumpInsnNode jmp = (JumpInsnNode) insn;
                convertJumpInsn(jmp);
                int op = jmp.getOpcode();
                if (op == JSR)
                    throw new UnsupportedOperationException("JSR!");
                if (op != GOTO) {
                    /* ifX opcode, i.e. two successors */
                    AbstractInsnNode next = insn.getNext();
                    addEdges(insn, next, Collections.singletonList(jmp.label));
                } else {
                    addEdges(insn, jmp.label, null);
                }
                break;
            } else if (type == LOOKUPSWITCH_INSN) {
                LookupSwitchInsnNode swtch = (LookupSwitchInsnNode) insn;
                convertLookupSwitchInsn(swtch);
                LabelNode dflt = swtch.dflt;
                addEdges(insn, dflt, swtch.labels);
                break;
            } else if (type == METHOD_INSN) {
                convertMethodInsn((MethodInsnNode) insn);
            } else if (type == INVOKE_DYNAMIC_INSN) {
                convertInvokeDynamicInsn((InvokeDynamicInsnNode) insn);
            } else if (type == MULTIANEWARRAY_INSN) {
                convertMultiANewArrayInsn((MultiANewArrayInsnNode) insn);
            } else if (type == TABLESWITCH_INSN) {
                TableSwitchInsnNode swtch = (TableSwitchInsnNode) insn;
                convertTableSwitchInsn(swtch);
                LabelNode dflt = swtch.dflt;
                addEdges(insn, dflt, swtch.labels);
            } else if (type == TYPE_INSN) {
                convertTypeInsn((TypeInsnNode) insn);
            } else if (type == VAR_INSN) {
                if (insn.getOpcode() == RET)
                    throw new UnsupportedOperationException("RET!");
                convertVarInsn((VarInsnNode) insn);
            } else if (type == LABEL) {
                convertLabel((LabelNode) insn);
            } else if (type == LINE) {
                convertLine((LineNumberNode) insn);
            } else if (type == FRAME) {
            // we can ignore it
            } else
                throw new RuntimeException("Unknown instruction type: " + type);
        } while ((insn = insn.getNext()) != null);
    } while (!worklist.isEmpty());
    conversionWorklist = null;
    edges = null;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) ArrayList(java.util.ArrayList) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) ArrayDeque(java.util.ArrayDeque) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 7 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project cassandra by apache.

the class MonitorMethodTransformer method writeInnerTryCatchSynchronized.

// alternative approach (with writeOuterUnsynchronized)
@SuppressWarnings("unused")
void writeInnerTryCatchSynchronized() {
    access |= Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_SYNTHETIC;
    name = baseName + "$catch";
    Label start = new Label();
    Label normal = new Label();
    Label except = new Label();
    Label end = new Label();
    reset(start, end);
    // must load self or class onto stack, and return value (if any)
    maxStack = Math.max(maxLocalParams, returnCode == Opcodes.RETURN ? 1 : 2);
    ++maxLocals;
    tryCatchBlocks.add(new TryCatchBlockNode(getLabelNode(start), getLabelNode(normal), getLabelNode(except), null));
    instructions.add(getLabelNode(start));
    int invokeCode = loadParamsAndReturnInvokeCode();
    instructions.add(new MethodInsnNode(invokeCode, className, baseName + "$unsync", desc));
    instructions.add(getLabelNode(normal));
    invokePreMonitorExit();
    instructions.add(new InsnNode(returnCode()));
    instructions.add(getLabelNode(except));
    instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }));
    instructions.add(new IntInsnNode(Opcodes.ASTORE, maxLocalParams));
    invokePreMonitorExit();
    instructions.add(new IntInsnNode(Opcodes.ALOAD, maxLocalParams));
    instructions.add(new InsnNode(Opcodes.ATHROW));
    instructions.add(getLabelNode(end));
    methodWriterSink.writeSyntheticMethod(MONITOR, this);
}
Also used : TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) FrameNode(org.objectweb.asm.tree.FrameNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Label(org.objectweb.asm.Label) IntInsnNode(org.objectweb.asm.tree.IntInsnNode)

Example 8 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project cassandra by apache.

the class MonitorMethodTransformer method loadParamsAndReturnInvokeCode.

// TODO (cleanup): this _should_ be possible to determine purely from the method signature
int loadParamsAndReturnInvokeCode() {
    if (isInstanceMethod)
        instructions.add(new IntInsnNode(Opcodes.ALOAD, 0));
    ListIterator<LocalVariableNode> it = localVariables.listIterator();
    while (it.hasNext()) {
        LocalVariableNode cur = it.next();
        if (cur.index < maxLocalParams) {
            if (!isInstanceMethod || cur.index > 0) {
                int opcode;
                switch(cur.desc.charAt(0)) {
                    case 'L':
                    case '[':
                        opcode = Opcodes.ALOAD;
                        break;
                    case 'J':
                        opcode = Opcodes.LLOAD;
                        break;
                    case 'D':
                        opcode = Opcodes.DLOAD;
                        break;
                    case 'F':
                        opcode = Opcodes.FLOAD;
                        break;
                    default:
                        opcode = Opcodes.ILOAD;
                        break;
                }
                instructions.add(new IntInsnNode(opcode, cur.index));
            }
        }
    }
    int invokeCode;
    if (isInstanceMethod && (access & Opcodes.ACC_PRIVATE) != 0)
        invokeCode = Opcodes.INVOKESPECIAL;
    else if (isInstanceMethod)
        invokeCode = Opcodes.INVOKEVIRTUAL;
    else
        invokeCode = Opcodes.INVOKESTATIC;
    return invokeCode;
}
Also used : IntInsnNode(org.objectweb.asm.tree.IntInsnNode) LocalVariableNode(org.objectweb.asm.tree.LocalVariableNode)

Example 9 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project bytecode-viewer by Konloch.

the class RegexInsnFinder method getInsString.

private static String getInsString(AbstractInsnNode ain) {
    String insnString = "";
    switch(ain.getType()) {
        case AbstractInsnNode.INT_INSN:
            final IntInsnNode iin = (IntInsnNode) ain;
            insnString += "{" + iin.operand + "}";
            break;
        case AbstractInsnNode.LDC_INSN:
            final LdcInsnNode lin = (LdcInsnNode) ain;
            insnString += "{" + lin.cst.toString().replace("}", "\\}") + "}";
            break;
        case AbstractInsnNode.VAR_INSN:
            final VarInsnNode vin = (VarInsnNode) ain;
            insnString += "_" + vin.var;
            break;
        case AbstractInsnNode.IINC_INSN:
            final IincInsnNode iiin = (IincInsnNode) ain;
            insnString += "{" + iiin.var + "," + iiin.incr + "}";
            break;
        case AbstractInsnNode.FIELD_INSN:
            final FieldInsnNode fin = (FieldInsnNode) ain;
            insnString += "{" + fin.desc + "," + fin.owner + "," + fin.name + "}";
            break;
        case AbstractInsnNode.METHOD_INSN:
            final MethodInsnNode min = (MethodInsnNode) ain;
            insnString += "{" + min.desc + "," + min.owner + "," + min.name + "}";
            break;
        case AbstractInsnNode.TYPE_INSN:
            final TypeInsnNode tin = (TypeInsnNode) ain;
            insnString += "{" + tin.desc + "}";
            break;
        case AbstractInsnNode.MULTIANEWARRAY_INSN:
            final MultiANewArrayInsnNode manain = (MultiANewArrayInsnNode) ain;
            insnString += "{" + manain.dims + "," + manain.desc + "}";
            break;
    }
    return insnString;
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 10 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project maple-ir by LLVM-but-worse.

the class IntInsnNodeSerializer method deserialize.

@Override
public IntInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    int opcode, operand;
    opcode = jsonObject.get("opcode").getAsInt();
    operand = jsonObject.get("operand").getAsInt();
    return new IntInsnNode(opcode, operand);
}
Also used : JsonObject(com.google.gson.JsonObject) IntInsnNode(org.objectweb.asm.tree.IntInsnNode)

Aggregations

IntInsnNode (org.objectweb.asm.tree.IntInsnNode)15 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)7 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)7 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)7 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)7 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)6 InsnNode (org.objectweb.asm.tree.InsnNode)5 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)4 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)3 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)3 MultiANewArrayInsnNode (org.objectweb.asm.tree.MultiANewArrayInsnNode)3 JsonObject (com.google.gson.JsonObject)2 PrimitiveType (japa.parser.ast.type.PrimitiveType)2 ReferenceType (japa.parser.ast.type.ReferenceType)2 ArrayList (java.util.ArrayList)2 Label (org.objectweb.asm.Label)2 FrameNode (org.objectweb.asm.tree.FrameNode)2 LabelNode (org.objectweb.asm.tree.LabelNode)2 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)2 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)2