Example usage for org.objectweb.asm Opcodes PUTFIELD

List of usage examples for org.objectweb.asm Opcodes PUTFIELD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes PUTFIELD.

Prototype

int PUTFIELD

To view the source code for org.objectweb.asm Opcodes PUTFIELD.

Click Source Link

Usage

From source file:bytecode.InstructionExporter.java

License:Apache License

/**
 * Outputs a write operation, choosing both the correct opcode family
 * (variable write, array store, field put, etc.) and type.
 *
 * @param instruction Write instruction.
 * @return            <code>null</code>
 *///w  w  w .j a va2 s . c  o m
@Override
public Void visit(Write instruction) {
    // Variable Stores
    if (instruction.getState() instanceof Variable) {
        Variable v = (Variable) instruction.getState();

        switch (v.getType().getSort()) {
        case LONG:
            mv.visitVarInsn(Opcodes.LSTORE, v.getIndex());
            break;
        case FLOAT:
            mv.visitVarInsn(Opcodes.FSTORE, v.getIndex());
            break;
        case DOUBLE:
            mv.visitVarInsn(Opcodes.DSTORE, v.getIndex());
            break;
        case REF:
            mv.visitVarInsn(Opcodes.ASTORE, v.getIndex());
            break;
        default:
            mv.visitVarInsn(Opcodes.ISTORE, v.getIndex());
            break;
        }
        // Array Stores
    } else if (instruction.getState() instanceof ArrayElement) {
        switch (instruction.getState().getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IASTORE);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LASTORE);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FASTORE);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DASTORE);
            break;
        case REF:
            mv.visitInsn(Opcodes.AASTORE);
            break;
        case BYTE:
            mv.visitInsn(Opcodes.BASTORE);
            break;
        case BOOL:
            mv.visitInsn(Opcodes.BASTORE);
            break;
        case CHAR:
            mv.visitInsn(Opcodes.CASTORE);
            break;
        case SHORT:
            mv.visitInsn(Opcodes.SASTORE);
            break;
        }
        // Static Writes
    } else if (instruction.getState() instanceof Field) {
        Field f = (Field) instruction.getState();

        mv.visitFieldInsn(Opcodes.PUTSTATIC, f.getOwner().getName(), f.getName(), f.getType().getDescriptor());
        // Field Writes
    } else if (instruction.getState() instanceof InstanceField) {
        Field f = (Field) ((InstanceField) instruction.getState()).getField();

        mv.visitFieldInsn(Opcodes.PUTFIELD, f.getOwner().getName(), f.getName(), f.getType().getDescriptor());
    }

    return null;
}

From source file:bytecode.MethodImporter.java

License:Apache License

/**
 * Imports field instructions (put and get), both for static and instance
 * fields.//from w  w  w .j av  a 2  s. com
 *
 * @param opcode Opcode.
 * @param owner  Class containing the field.
 * @param name   Name of field.
 * @param desc   Type descriptor of field.
 */
@Override
public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) {
    Field f = ClassNode.getClass(owner).getField(name, desc);

    if (((opcode == Opcodes.GETSTATIC) || (opcode == Opcodes.PUTSTATIC)) != f.getModifiers()
            .contains(Modifier.STATIC)) {
        throw new RuntimeException("Field staticness conflicts with instruction");
    }

    switch (opcode) {
    // Loads
    case Opcodes.GETSTATIC:
    case Opcodes.GETFIELD:
        createFieldRead(f);
        break;
    // Stores
    case Opcodes.PUTSTATIC:
    case Opcodes.PUTFIELD:
        createFieldWrite(f);
        break;
    }
}

From source file:Client.JClassPatcher.java

License:Open Source License

private void patchClient(ClassNode node) {
    Logger.Info("Patching client (" + node.name + ".class)");

    Iterator<MethodNode> methodNodeList = node.methods.iterator();
    while (methodNodeList.hasNext()) {
        MethodNode methodNode = methodNodeList.next();

        // I (I)V is where most of the interface is processed
        if (methodNode.name.equals("I") && methodNode.desc.equals("(I)V")) {
            // Show combat menu
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                if (insnNode.getOpcode() == Opcodes.BIPUSH) {
                    IntInsnNode bipush = (IntInsnNode) insnNode;

                    if (bipush.operand == -9) {
                        AbstractInsnNode findNode = insnNode;
                        while (findNode.getOpcode() != Opcodes.IF_ICMPEQ)
                            findNode = findNode.getNext();

                        LabelNode label = ((JumpInsnNode) findNode).label;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_MENU", "Z"));
                        methodNode.instructions.insertBefore(insnNode, new JumpInsnNode(Opcodes.IFGT, label));
                        break;
                    }//from   w  w w.j a  v a  2 s  . c  o  m
                }
            }
        } else if (methodNode.name.equals("J") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Chat command patch
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 627) {
                        AbstractInsnNode jmpNode = insnNode;
                        while (jmpNode.getOpcode() != Opcodes.IFEQ)
                            jmpNode = jmpNode.getNext();

                        AbstractInsnNode insertNode = insnNode;
                        while (insertNode.getOpcode() != Opcodes.INVOKEVIRTUAL)
                            insertNode = insertNode.getPrevious();

                        JumpInsnNode jmp = (JumpInsnNode) jmpNode;
                        methodNode.instructions.insert(insertNode, new VarInsnNode(Opcodes.ASTORE, 2));
                        methodNode.instructions.insert(insertNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                                "Game/Client", "processChatCommand", "(Ljava/lang/String;)Ljava/lang/String;"));
                        methodNode.instructions.insert(insertNode, new VarInsnNode(Opcodes.ALOAD, 2));
                    }
                }
            }
        } else if (methodNode.name.equals("h") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Private chat command patch
                if (insnNode.getOpcode() == Opcodes.GETFIELD) {
                    FieldInsnNode field = (FieldInsnNode) insnNode;
                    if (field.owner.equals("client") && field.name.equals("Ob")
                            && insnNode.getPrevious().getPrevious().getOpcode() != Opcodes.INVOKEVIRTUAL) {
                        insnNode = insnNode.getPrevious().getPrevious();
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.PUTFIELD, "client", "Ob", "Ljava/lang/String;"));
                        methodNode.instructions.insert(insnNode,
                                new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "processPrivateCommand",
                                        "(Ljava/lang/String;)Ljava/lang/String;"));
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.GETFIELD, "client", "Ob", "Ljava/lang/String;"));
                        methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
                        methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
                        break;
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IIIIIIII)V")) {
            // Draw NPC hook
            AbstractInsnNode insnNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 8));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 1));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 4));

            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "e", "Mb", "[Ljava/lang/String;"));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Tb", "[Lta;"));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 6));
            methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD));
            methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "ta", "t", "I"));
            methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD));
            methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                    "Game/Client", "drawNPC", "(IIIILjava/lang/String;)V"));
        } else if (methodNode.name.equals("b") && methodNode.desc.equals("(IIIIIIII)V")) {
            // Draw Player hook
            AbstractInsnNode insnNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 5));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 6));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 2));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "rg", "[Lta;"));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 8));
            methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD));
            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "ta", "C", "Ljava/lang/String;"));
            methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                    "Game/Client", "drawPlayer", "(IIIILjava/lang/String;)V"));
        } else if (methodNode.name.equals("b") && methodNode.desc.equals("(IIIIIII)V")) {
            // Draw Item hook
            // ILOAD 4 is item id
            AbstractInsnNode insnNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 3));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 5));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 1));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 4));
            methodNode.instructions.insertBefore(insnNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "drawItem", "(IIIII)V"));
        } else if (methodNode.name.equals("L") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Right click bounds fix
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    AbstractInsnNode nextNode = insnNode.getNext();

                    if (call.operand == 510) {
                        call.operand = 512 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    } else if (call.operand == 315) {
                        call.operand = 334 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height_client", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    } else if (call.operand == -316) {
                        call.operand = 334 - (call.operand * -1);
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height_client", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(ZZ)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Friends chat mouse fix
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 489 || call.operand == 429) {
                        call.operand = 512 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                    if (call.operand == -430) {
                        call.operand = 512 - (call.operand * -1);
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                }
            }
        } else if (methodNode.name.equals("i") && methodNode.desc.equals("(I)V")) {
            AbstractInsnNode lastNode = methodNode.instructions.getLast().getPrevious();

            // Send combat style option
            LabelNode label = new LabelNode();

            methodNode.instructions.insert(lastNode, label);

            // Format
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(I)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.SIPUSH, 21294));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Write byte
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ja", "c", "(II)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, -80));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_STYLE", "I"));
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "da", "f", "Lja;"));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Create Packet
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(II)V", false));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 29));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Skip combat packet if style is already controlled
            methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IF_ICMPLE, label));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_STYLE", "I"));

            // Client init_game
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init_game", "()V", false));
        } else if (methodNode.name.equals("o") && methodNode.desc.equals("(I)V")) {
            // Client.init_login patch
            AbstractInsnNode findNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(findNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init_login", "()V", false));
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Camera view distance crash fix
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 15000) {
                        call.operand = 32767;
                    }
                }
            }

            // Client.init patch
            AbstractInsnNode findNode = methodNode.instructions.getFirst();
            methodNode.instructions.insertBefore(findNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insertBefore(findNode,
                    new FieldInsnNode(Opcodes.PUTSTATIC, "Game/Client", "instance", "Ljava/lang/Object;"));
            methodNode.instructions.insertBefore(findNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init", "()V", false));
        } else if (methodNode.name.equals("G") && methodNode.desc.equals("(I)V")) {
            // TODO: This can be shortened, I'll fix it another time

            // NPC Dialogue keyboard
            AbstractInsnNode lastNode = methodNode.instructions.getLast().getPrevious();

            LabelNode label = new LabelNode();

            methodNode.instructions.insert(lastNode, label);

            // Hide dialogue
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.PUTFIELD, "client", "Ph", "Z"));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Format
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(I)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.SIPUSH, 21294));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Write byte
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ja", "c", "(II)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 115));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I"));
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "da", "f", "Lja;"));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Create Packet
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(II)V", false));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 116));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Check if dialogue option is pressed
            methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IF_ICMPGE, label));
            // Menu option count
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Id", "I"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I"));
            methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IFLT, label));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I"));
        } else if (methodNode.name.equals("f") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Hide Roof option
                if (insnNode.getOpcode() == Opcodes.GETFIELD) {
                    FieldInsnNode field = (FieldInsnNode) insnNode;

                    if (field.owner.equals("client") && field.name.equals("yj")) {
                        AbstractInsnNode nextNode = insnNode.getNext();
                        if (nextNode.getOpcode() == Opcodes.IFNE) {
                            LabelNode label = ((JumpInsnNode) nextNode).label;
                            methodNode.instructions.insert(nextNode, new JumpInsnNode(Opcodes.IFGT, label));
                            methodNode.instructions.insert(nextNode,
                                    new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "HIDE_ROOFS", "Z"));
                        }
                    }
                }

                // Move wilderness skull
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 465 || call.operand == 453) {
                        call.operand = 512 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IIZ)Z")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Move the load screen text dialogue
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 256) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 192) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 19));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    }
                }
            }
        } else if (methodNode.name.equals("d") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Center logout dialogue
                if (insnNode.getOpcode() == Opcodes.SIPUSH || insnNode.getOpcode() == Opcodes.BIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 256) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 173) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 126) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 130));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 137) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 36));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    }
                }
            }
        } else if (methodNode.name.equals("j") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Center welcome box
                if (insnNode.getOpcode() == Opcodes.SIPUSH || insnNode.getOpcode() == Opcodes.BIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 256) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 167) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 6));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 56) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 200));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == -87) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 169));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 426) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 170));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 106) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 150));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 406) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 150));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    }
                }
            }
        } else if (methodNode.name.equals("k") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Save settings from combat menu
                if (insnNode.getOpcode() == Opcodes.PUTFIELD) {
                    FieldInsnNode field = (FieldInsnNode) insnNode;

                    if (field.owner.equals("client") && field.name.equals("Fg")) {
                        methodNode.instructions.insert(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                                "Client/Settings", "save", "()V", false));
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.PUTSTATIC, "Client/Settings", "COMBAT_STYLE", "I"));
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.GETFIELD, "client", "Fg", "I"));
                        methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc
                .equals("(ZLjava/lang/String;ILjava/lang/String;IILjava/lang/String;Ljava/lang/String;)V")) {
            AbstractInsnNode first = methodNode.instructions.getFirst();
            methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 7));
            methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 4));
            methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ILOAD, 5));
            methodNode.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client",
                    "messageHook", "(Ljava/lang/String;Ljava/lang/String;I)V"));
        }
    }
}

From source file:Client.JClassPatcher.java

License:Open Source License

/**
 * TODO: Complete JavaDoc/*w  w w.  j a  v  a  2s  .  c  o  m*/
 * 
 * @param methodNode
 * @param owner The class of the variable to be hooked
 * @param var The variable to be hooked
 * @param desc
 * @param newClass The class the hooked variable will be stored in
 * @param newVar The variable name the hooked variable will be stored in
 * @param newDesc
 * @param canRead Specifies if the hooked variable should be readable
 * @param canWrite Specifies if the hooked variable should be writable
 */
private void hookClassVariable(MethodNode methodNode, String owner, String var, String desc, String newClass,
        String newVar, String newDesc, boolean canRead, boolean canWrite) {
    Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
    while (insnNodeList.hasNext()) {
        AbstractInsnNode insnNode = insnNodeList.next();

        int opcode = insnNode.getOpcode();
        if (opcode == Opcodes.GETFIELD || opcode == Opcodes.PUTFIELD) {
            FieldInsnNode field = (FieldInsnNode) insnNode;
            if (field.owner.equals(owner) && field.name.equals(var) && field.desc.equals(desc)) {
                if (opcode == Opcodes.GETFIELD && canWrite) {
                    methodNode.instructions.insert(insnNode,
                            new FieldInsnNode(Opcodes.GETSTATIC, newClass, newVar, newDesc));
                    methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.POP));
                } else if (opcode == Opcodes.PUTFIELD && canRead) {
                    methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.DUP_X1));
                    methodNode.instructions.insert(insnNode,
                            new FieldInsnNode(Opcodes.PUTSTATIC, newClass, newVar, newDesc));
                }
            }
        }
    }
}

From source file:com.alibaba.hotswap.processor.constructor.modifier.FieldHolderInitModifier.java

License:Open Source License

@Override
public void visitCode() {
    super.visitCode();

    // this.__$$hotswap_field_holder$$__ = new ConcurrentHashMap();
    mv.visitVarInsn(Opcodes.ALOAD, 0);/*from w w w  .  j a v  a  2s  .c o  m*/
    mv.visitFieldInsn(Opcodes.GETFIELD, className, HotswapConstants.FIELD_HOLDER,
            "Ljava/util/concurrent/ConcurrentHashMap;");
    Label end = newLabel();
    ifNonNull(end);

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/concurrent/ConcurrentHashMap");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/concurrent/ConcurrentHashMap", "<init>", "()V");
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, HotswapConstants.FIELD_HOLDER,
            "Ljava/util/concurrent/ConcurrentHashMap;");
    mark(end);
}

From source file:com.alibaba.hotswap.processor.field.access.FieldAccessModifier.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    if (HotswapRuntime.getClassInitialized(className) && !name.equals(HotswapConstants.STATIC_FIELD_HOLDER)
            && !name.equals(HotswapConstants.FIELD_HOLDER)) {

        Queue<String> owners = new LinkedList<String>();
        owners.offer(owner);/*from w  w w.  j a v a 2 s .c  om*/
        String tmpOwner = owners.poll();
        while (tmpOwner != null) {
            if (HotswapRuntime.hasClassMeta(tmpOwner)) {
                // Try to reload owner.
                HotswapRuntime.try2Reload(tmpOwner);

                ClassMeta classMeta = HotswapRuntime.getClassMeta(tmpOwner);
                String fmKey = HotswapFieldUtil.getFieldKey(name, desc);
                FieldMeta fm = classMeta.getFieldMeta(fmKey);

                if (classMeta.isInterface) {
                    if (fm != null && !fm.isDeleted(classMeta.loadedIndex)
                            && (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.GETSTATIC)) {
                        super.visitFieldInsn(opcode, Type.getInternalName(classMeta.vClass), fm.name, fm.desc);
                        return;
                    }
                }

                if (fm != null && classMeta.primaryFieldKeyList.contains(fmKey)
                        && !fm.isDeleted(classMeta.loadedIndex)) {
                    break;
                } else if (fm != null && classMeta.primaryFieldKeyList.contains(fmKey)
                        && fm.isDeleted(classMeta.loadedIndex)) {
                    // If this accessed field is primary and deleted, it perhaps is a alias field
                    fm = classMeta.getFieldMeta(HotswapFieldUtil
                            .getFieldKey(HotswapConstants.PREFIX_FIELD_ALIAS + fm.name, fm.desc));
                }

                if (fm != null && fm.isAdded() && !fm.isDeleted(classMeta.loadedIndex)) {
                    if (opcode == Opcodes.PUTSTATIC) {
                        // put static
                        box(Type.getType(fm.desc));
                        mv.visitFieldInsn(Opcodes.GETSTATIC, tmpOwner, HotswapConstants.STATIC_FIELD_HOLDER,
                                "Ljava/util/concurrent/ConcurrentHashMap;");
                        mv.visitLdcInsn(fm.name);
                        mv.visitLdcInsn(fm.desc);
                        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class),
                                "setFieldValue",
                                "(Ljava/lang/Object;Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)V");
                        return;
                    } else if (opcode == Opcodes.GETSTATIC) {
                        // get static
                        mv.visitFieldInsn(Opcodes.GETSTATIC, tmpOwner, HotswapConstants.STATIC_FIELD_HOLDER,
                                "Ljava/util/concurrent/ConcurrentHashMap;");
                        mv.visitLdcInsn(fm.name);
                        mv.visitLdcInsn(fm.desc);
                        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class),
                                "getFieldValue",
                                "(Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
                        unbox(Type.getType(fm.desc));
                        return;
                    } else if (opcode == Opcodes.PUTFIELD) {
                        // put field
                        // stack: obj fieldValue
                        box(Type.getType(fm.desc));
                        mv.visitInsn(Opcodes.SWAP);
                        mv.visitFieldInsn(Opcodes.GETFIELD, tmpOwner, HotswapConstants.FIELD_HOLDER,
                                "Ljava/util/concurrent/ConcurrentHashMap;");
                        mv.visitLdcInsn(fm.name);
                        mv.visitLdcInsn(fm.desc);
                        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class),
                                "setFieldValue",
                                "(Ljava/lang/Object;Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)V");

                        return;
                    } else if (opcode == Opcodes.GETFIELD) {
                        // get field
                        // stack: obj
                        mv.visitFieldInsn(Opcodes.GETFIELD, tmpOwner, HotswapConstants.FIELD_HOLDER,
                                "Ljava/util/concurrent/ConcurrentHashMap;");
                        mv.visitLdcInsn(fm.name);
                        mv.visitLdcInsn(fm.desc);
                        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class),
                                "getFieldValue",
                                "(Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");

                        Label notnull = newLabel();
                        Type type = Type.getType(fm.desc);

                        mv.visitInsn(Opcodes.DUP);
                        mv.visitJumpInsn(Opcodes.IFNONNULL, notnull);

                        Label end = newLabel();
                        switch (type.getSort()) {
                        case Type.BOOLEAN:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Boolean(false));
                            break;

                        case Type.CHAR:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Character(' '));
                            break;

                        case Type.BYTE:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Byte((byte) 0));
                            break;

                        case Type.SHORT:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Short((short) 0));
                            break;

                        case Type.INT:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Integer(0));
                            break;

                        case Type.FLOAT:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Float(0));
                            break;

                        case Type.LONG:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Long(0));
                            break;

                        case Type.DOUBLE:
                            mv.visitInsn(Opcodes.POP);
                            mv.visitLdcInsn(new Double(0));
                            break;

                        default:
                            break;
                        }
                        mv.visitJumpInsn(Opcodes.GOTO, end);

                        mark(notnull);
                        unbox(type);

                        mark(end);
                        return;
                    }
                }

                if (classMeta.clazz != null) {
                    Class<?> superClass = classMeta.clazz.getSuperclass();
                    if (superClass != null) {
                        owners.offer(HotswapUtil.getInternalClassName(superClass.getName()));
                    }
                    Class<?>[] superInterfaces = classMeta.clazz.getInterfaces();
                    if (superInterfaces != null) {
                        for (Class<?> itf : superInterfaces) {
                            owners.offer(HotswapUtil.getInternalClassName(itf.getName()));
                        }
                    }
                }
            }
            tmpOwner = owners.poll();
        }
    }
    super.visitFieldInsn(opcode, owner, name, desc);
}

From source file:com.android.ide.eclipse.apt.internal.analysis.InternalGetSetAnalyzer.java

License:Apache License

/**
 * Checks if a method is a setter/*from   w ww.ja va2  s .  co  m*/
 * @param methodTest The method to be checked
 * @return True if the method is a setter, false otherwise
 */
private boolean isSetter(final MethodNode methodTest) {
    boolean setter = false;
    final String desc = methodTest.desc;
    final Type[] arguments = Type.getArgumentTypes(desc);
    final Type returnType = Type.getReturnType(desc);
    if (arguments.length == 1 && returnType.getSort() == Type.VOID) {
        final InsnList instructions = methodTest.instructions;
        //skip label and line number instructions
        final AbstractInsnNode first = instructions.getFirst().getNext().getNext();
        final int loadOp = arguments[0].getOpcode(Opcodes.ILOAD);
        final int firstOp = first.getOpcode();
        //check for static setter
        if ((Opcodes.ACC_STATIC & methodTest.access) == 0) {
            if (firstOp == Opcodes.ALOAD) {
                final AbstractInsnNode second = first.getNext();
                if (second.getOpcode() == loadOp) {
                    final AbstractInsnNode third = second.getNext();
                    if (third.getOpcode() == Opcodes.PUTFIELD) {
                        //three next to skip label and line number instructions
                        final AbstractInsnNode fourth = third.getNext().getNext().getNext();
                        if (fourth.getOpcode() == Opcodes.RETURN) {
                            setter = true;
                        }
                    }
                }
            }
        } else {
            if (firstOp == loadOp) {
                final AbstractInsnNode second = first.getNext();
                if (second.getOpcode() == Opcodes.PUTSTATIC) {
                    final AbstractInsnNode third = second.getNext().getNext().getNext();
                    if (third.getOpcode() == Opcodes.RETURN) {
                        setter = true;
                    }
                }
            }
        }
    }
    return setter;
}

From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java

License:Apache License

/**
 * Performs {@code PUTFIELD} instruction.
 * @param method the target method/*from w  w  w  .  j  av  a 2 s .  c  o  m*/
 * @param field the target field ref
 */
public static void putField(MethodVisitor method, FieldRef field) {
    method.visitFieldInsn(Opcodes.PUTFIELD, field.declaring.getInternalName(), field.name,
            field.type.getDescriptor());
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void addConstructor(ClassWriter writer, ClassDescription target, List<VertexElement> elements,
        Function<VertexElement, String> ids) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(OperationAdapter.Context.class)), null, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(Object.class).getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE), false);

    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), FIELD_CONTEXT,
            typeOf(OperationAdapter.Context.class).getDescriptor());

    for (VertexElement element : elements) {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, target.getInternalName(), ids.apply(element),
                Type.getMethodDescriptor(Type.VOID_TYPE), false);
    }/*from   w ww.ja  v a  2s.  c om*/
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void addElementMethods(ClassWriter writer, ClassDescription target, List<VertexElement> elements,
        Function<VertexElement, String> ids) {
    for (VertexElement element : elements) {
        String id = ids.apply(element);
        MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE, id,
                Type.getMethodDescriptor(Type.VOID_TYPE), null, null);
        method.visitVarInsn(Opcodes.ALOAD, 0);
        switch (element.getElementKind()) {
        case VALUE:
            getValue(method, target, (ValueElement) element, ids);
            break;
        case OPERATOR:
        case AGGREGATE:
            getClass(method, target, (ClassNode) element, ids);
            break;
        case OUTPUT:
            getOutput(method, target, (OutputNode) element, ids);
            break;
        case DATA_TABLE:
            getDataTable(method, target, (DataTableNode) element, ids);
            break;
        case CONTEXT:
            getContext(method, target, ids);
            break;
        case EMPTY_DATA_TABLE:
            getEmptyDataTable(method, target, ids);
            break;
        default:/*ww  w  . j  ava 2s  . c om*/
            throw new AssertionError(element.getElementKind());
        }
        method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), id,
                typeOf(element.getRuntimeType()).getDescriptor());
        method.visitInsn(Opcodes.RETURN);
        method.visitMaxs(0, 0);
        method.visitEnd();
    }
}