Search in sources :

Example 26 with FieldInsnNode

use of org.objectweb.asm.tree.FieldInsnNode in project drill by apache.

the class ReplacingInterpreter method unaryOperation.

@Override
public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value) throws AnalyzerException {
    /*
     * We're looking for the assignment of an operator member variable that's a holder to a local
     * objectref. If we spot that, we can't replace the local objectref (at least not
     * until we do the work to replace member variable holders).
     *
     * Note that a GETFIELD does not call newValue(), as would happen for a local variable, so we're
     * emulating that here.
     */
    if ((insn.getOpcode() == Opcodes.GETFIELD) && (value instanceof ReplacingBasicValue)) {
        final ReplacingBasicValue possibleThis = (ReplacingBasicValue) value;
        if (possibleThis.isThis()) {
            final FieldInsnNode fieldInsn = (FieldInsnNode) insn;
            if (HOLDERS.get(fieldInsn.desc) != null) {
                final BasicValue fetchedField = super.unaryOperation(insn, value);
                final ReplacingBasicValue replacingValue = ReplacingBasicValue.create(fetchedField.getType(), null, -1, valueList);
                replacingValue.setAssignedToMember();
                return replacingValue;
            }
        }
    }
    return super.unaryOperation(insn, value);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) BasicValue(org.objectweb.asm.tree.analysis.BasicValue)

Example 27 with FieldInsnNode

use of org.objectweb.asm.tree.FieldInsnNode in project pinpoint by naver.

the class ASMClassNodeAdapter method addSetterMethod.

public void addSetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
    Objects.requireNonNull(methodName, "methodName");
    Objects.requireNonNull(fieldNode, "fieldNode");
    // void is V.
    final String desc = "(" + fieldNode.getDesc() + ")V";
    final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
    final InsnList instructions = getInsnList(methodNode);
    // load this.
    instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    final Type type = Type.getType(fieldNode.getDesc());
    // put field.
    instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 1));
    instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
    // return.
    instructions.add(new InsnNode(Opcodes.RETURN));
    addMethodNode0(methodNode);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodNode(org.objectweb.asm.tree.MethodNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 28 with FieldInsnNode

use of org.objectweb.asm.tree.FieldInsnNode in project robolectric by robolectric.

the class ClassInstrumentor method rewriteMethodBody.

/**
 * Filters methods that might need special treatment because of various reasons
 */
private void rewriteMethodBody(MutableClass mutableClass, MethodNode callingMethod) {
    ListIterator<AbstractInsnNode> instructions = callingMethod.instructions.iterator();
    while (instructions.hasNext()) {
        AbstractInsnNode node = instructions.next();
        switch(node.getOpcode()) {
            case Opcodes.NEW:
                TypeInsnNode newInsnNode = (TypeInsnNode) node;
                newInsnNode.desc = mutableClass.config.mappedTypeName(newInsnNode.desc);
                break;
            case Opcodes.GETFIELD:
            /* falls through */
            case Opcodes.PUTFIELD:
            /* falls through */
            case Opcodes.GETSTATIC:
            /* falls through */
            case Opcodes.PUTSTATIC:
                FieldInsnNode fieldInsnNode = (FieldInsnNode) node;
                // todo test
                fieldInsnNode.desc = mutableClass.config.mappedTypeName(fieldInsnNode.desc);
                break;
            case Opcodes.INVOKESTATIC:
            /* falls through */
            case Opcodes.INVOKEINTERFACE:
            /* falls through */
            case Opcodes.INVOKESPECIAL:
            /* falls through */
            case Opcodes.INVOKEVIRTUAL:
                MethodInsnNode targetMethod = (MethodInsnNode) node;
                targetMethod.desc = mutableClass.config.remapParams(targetMethod.desc);
                if (isGregorianCalendarBooleanConstructor(targetMethod)) {
                    replaceGregorianCalendarBooleanConstructor(instructions, targetMethod);
                } else if (mutableClass.config.shouldIntercept(targetMethod)) {
                    interceptInvokeVirtualMethod(mutableClass, instructions, targetMethod);
                }
                break;
            case Opcodes.INVOKEDYNAMIC:
                /* no unusual behavior */
                break;
            default:
                break;
        }
    }
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 29 with FieldInsnNode

use of org.objectweb.asm.tree.FieldInsnNode 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 30 with FieldInsnNode

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

the class FieldInsnNodeSerializer method deserialize.

@Override
public FieldInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    int opcode;
    String owner = null, name = null, desc = null;
    JsonObject object = (JsonObject) json;
    opcode = object.get("opcode").getAsInt();
    owner = object.get("owner").getAsString();
    name = object.get("name").getAsString();
    desc = object.get("desc").getAsString();
    if (owner == null || name == null || desc == null)
        throw new JsonParseException("Could not parse FieldInsnNode");
    return new FieldInsnNode(opcode, owner, name, desc);
}
Also used : JsonObject(com.google.gson.JsonObject) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) JsonParseException(com.google.gson.JsonParseException)

Aggregations

FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)53 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)29 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)28 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)26 InsnList (org.objectweb.asm.tree.InsnList)24 InsnNode (org.objectweb.asm.tree.InsnNode)20 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)20 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)16 MethodNode (org.objectweb.asm.tree.MethodNode)15 Type (org.objectweb.asm.Type)14 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)13 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)11 ClassNode (org.objectweb.asm.tree.ClassNode)10 LabelNode (org.objectweb.asm.tree.LabelNode)9 IntInsnNode (org.objectweb.asm.tree.IntInsnNode)8 ClassReader (org.objectweb.asm.ClassReader)7 Label (org.objectweb.asm.Label)5 FieldNode (org.objectweb.asm.tree.FieldNode)5 LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)5 FrameNode (org.objectweb.asm.tree.FrameNode)4