Example usage for org.objectweb.asm.tree AbstractInsnNode METHOD_INSN

List of usage examples for org.objectweb.asm.tree AbstractInsnNode METHOD_INSN

Introduction

In this page you can find the example usage for org.objectweb.asm.tree AbstractInsnNode METHOD_INSN.

Prototype

int METHOD_INSN

To view the source code for org.objectweb.asm.tree AbstractInsnNode METHOD_INSN.

Click Source Link

Document

The type of MethodInsnNode instructions.

Usage

From source file:analysis.ReferenceGenerator.java

License:Open Source License

private void refInstructions(InsnList insnList) {
    AbstractInsnNode insn;/*from ww  w.  j a v  a  2  s.c  o  m*/

    insn = insnList.getFirst();

    Object cst;

    while (insn != null) {
        switch (insn.getType()) {
        case AbstractInsnNode.FIELD_INSN:
            //addTypeClassRef(Type.getType(((FieldInsnNode)insn).desc));
            addFieldRef(((FieldInsnNode) insn).owner, ((FieldInsnNode) insn).name);
            break;
        /*case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
                   
           break;*/
        /*case AbstractInsnNode.LDC_INSN:
           cst = ((LdcInsnNode)insn).cst;
           if(cst instanceof Type) {
              addTypeClassRef((Type)cst);
           }
           break;*/
        case AbstractInsnNode.METHOD_INSN:
            addMethodRef(((MethodInsnNode) insn).owner, ((MethodInsnNode) insn).name,
                    ((MethodInsnNode) insn).desc);
            break;
        case AbstractInsnNode.MULTIANEWARRAY_INSN:
            addTypeClassRef(Type.getType(((MultiANewArrayInsnNode) insn).desc));
            break;
        case AbstractInsnNode.TYPE_INSN:
            addTypeClassRef(Type.getType(((TypeInsnNode) insn).desc));
            break;
        }
        insn = insn.getNext();
    }
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformTileEntityPiston(byte[] bytes) {
    /*try//  w  w  w.  j a  va 2 s  . com
    {
        FileOutputStream fos = new FileOutputStream("d:/TileEntityPiston.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    System.out.print("[BlockPhysics] Patching TileEntityPiston.class ........");

    boolean ok = false, ok2 = false, ok3 = false, ok4 = false, ok5 = false;
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();
        if (m.name.equals("<init>") && m.desc.equals("(IIIZZ)V")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new InsnNode(ACONST_NULL));
                    toInject.add(new FieldInsnNode(PUTFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new InsnNode(ICONST_0));
                    toInject.add(new FieldInsnNode(PUTFIELD, "ast", "bpmeta", "I"));

                    m.instructions.insertBefore(m.instructions.get(index), toInject);

                    ok = true;
                    break;
                }
            }
        } else if (m.name.equals("f") && m.desc.equals("()V")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("abv")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("g")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(IIII)V")) {
                    InsnList toInject = new InsnList();

                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "k", "Labv;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "l", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "m", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "n", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "bpmeta", "I"));
                    toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "setBlockBPdata",
                            "(Labv;IIII)Z"));
                    toInject.add(new InsnNode(POP));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    LabelNode l1 = new LabelNode();
                    toInject.add(new JumpInsnNode(IFNULL, l1));
                    toInject.add(new FieldInsnNode(GETSTATIC, "aqw", "s", "[Laqw;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "a", "I"));
                    toInject.add(new InsnNode(AALOAD));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "k", "Labv;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "b", "I"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "aqw", "createTileEntity", "(Labv;I)Lasm;"));
                    toInject.add(new VarInsnNode(ASTORE, 1));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "asm", "a", "(Lbx;)V"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "k", "Labv;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "l", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "m", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "n", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "abv", "a", "(IIILasm;)V"));
                    toInject.add(l1);

                    m.instructions.insert(m.instructions.get(index), toInject);

                    ok2 = true;
                    break;
                }
            }
        } else if (m.name.equals("a") && m.desc.equals("(Lbx;)V")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new LdcInsnNode("BPData"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "b", "(Ljava/lang/String;)Z"));
                    LabelNode l1 = new LabelNode();
                    toInject.add(new JumpInsnNode(IFEQ, l1));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new LdcInsnNode("BPData"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "c", "(Ljava/lang/String;)B"));
                    toInject.add(new FieldInsnNode(PUTFIELD, "ast", "bpmeta", "I"));
                    toInject.add(l1);
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new LdcInsnNode("TileEntityData"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "b", "(Ljava/lang/String;)Z"));
                    LabelNode l0 = new LabelNode();
                    toInject.add(new JumpInsnNode(IFEQ, l0));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new LdcInsnNode("TileEntityData"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "l", "(Ljava/lang/String;)Lbx;"));
                    toInject.add(new FieldInsnNode(PUTFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    toInject.add(l0);

                    m.instructions.insertBefore(m.instructions.get(index), toInject);

                    ok3 = true;
                    break;
                }
            }
        } else if (m.name.equals("b") && m.desc.equals("(Lbx;)V")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new LdcInsnNode("BPData"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "bpmeta", "I"));
                    toInject.add(new InsnNode(I2B));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "a", "(Ljava/lang/String;B)V"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    LabelNode l0 = new LabelNode();
                    toInject.add(new JumpInsnNode(IFNULL, l0));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new LdcInsnNode("TileEntityData"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "a", "(Ljava/lang/String;Lbx;)V"));
                    toInject.add(l0);

                    m.instructions.insertBefore(m.instructions.get(index), toInject);

                    ok4 = true;
                    break;
                }
            }
        } else if (m.name.equals("h") && m.desc.equals("()V")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("abv")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("g")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(IIII)V")) {
                    InsnList toInject = new InsnList();

                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "k", "Labv;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "l", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "m", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "n", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "bpmeta", "I"));
                    toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "setBlockBPdata",
                            "(Labv;IIII)Z"));
                    toInject.add(new InsnNode(POP));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    LabelNode l0 = new LabelNode();
                    toInject.add(new JumpInsnNode(IFNULL, l0));
                    toInject.add(new FieldInsnNode(GETSTATIC, "aqw", "s", "[Laqw;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "a", "I"));
                    toInject.add(new InsnNode(AALOAD));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "k", "Labv;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "b", "I"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "aqw", "createTileEntity", "(Labv;I)Lasm;"));
                    toInject.add(new VarInsnNode(ASTORE, 1));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "movingBlockTileEntityData", "Lbx;"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "asm", "a", "(Lbx;)V"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "k", "Labv;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "l", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "m", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "ast", "n", "I"));
                    toInject.add(new VarInsnNode(ALOAD, 1));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "abv", "a", "(IIILasm;)V"));
                    toInject.add(l0);

                    m.instructions.insert(m.instructions.get(index), toInject);

                    ok5 = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok && ok2 && ok3 && ok4 && ok5)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok + ok2 + ok3 + ok4 + ok5);

    FieldVisitor fv;

    fv = cw.visitField(ACC_PUBLIC, "movingBlockTileEntityData", "Lbx;", null, null);
    fv.visitEnd();

    fv = cw.visitField(ACC_PUBLIC, "bpmeta", "I", null, null);
    fv.visitEnd();

    cw.visitEnd();

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/TileEntityPiston.mod.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformBlockFurnace(byte[] bytes) {
    /*try//from  w w w  . jav a2 s  .c  om
     {
         FileOutputStream fos = new FileOutputStream("d:/BlockFurnace.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

    System.out.print("[BlockPhysics] Patching BlockFurnace.class ............");

    boolean ok = false;
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();
        if (m.name.equals("a") && m.desc.equals("(Labv;III)V")) {
            for (int index = 0; index < m.instructions.size(); index++) {
                if (m.instructions.get(index).getOpcode() == INVOKESPECIAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("aoh")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("k")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Labv;III)V")) {
                    index = index - 5;
                    for (int i = 0; i < 6; i++)
                        m.instructions.remove(m.instructions.get(index));

                    ok = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/BlockFurnace.mod.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformBlockDispenser(byte[] bytes) {
    /*try//from www . j  a v  a2s.  c  o  m
     {
         FileOutputStream fos = new FileOutputStream("d:/BlockDispenser.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

    System.out.print("[BlockPhysics] Patching BlockDispenser.class ..........");

    boolean ok = false;
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();
        if (m.name.equals("a") && m.desc.equals("(Labv;III)V")) {
            for (int index = 0; index < m.instructions.size(); index++) {
                if (m.instructions.get(index).getOpcode() == INVOKESPECIAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("anv")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("k")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Labv;III)V")) {
                    index = index - 5;
                    for (int i = 0; i < 6; i++)
                        m.instructions.remove(m.instructions.get(index));

                    ok = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/BlockDispenser.mod.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformBlockChest(byte[] bytes) {
    /*try//from   w ww  .j ava2 s.c  o m
     {
         FileOutputStream fos = new FileOutputStream("d:/BlockChest.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

    System.out.print("[BlockPhysics] Patching BlockChest.class ..............");

    boolean ok = false;
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();
        if (m.name.equals("a") && m.desc.equals("(Labv;III)V")) {
            for (int index = 0; index < m.instructions.size(); index++) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("anh")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("f_")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Labv;III)V")) {
                    index = index - 5;
                    for (int i = 0; i < 6; i++)
                        m.instructions.remove(m.instructions.get(index));

                    ok = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/BlockChest.mod.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformAnvilChunkLoader(byte[] bytes) {
    /*try/*from ww  w . j av a 2 s .  c  o m*/
     {
         FileOutputStream fos = new FileOutputStream("d:/AnvilChunkLoader.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

    System.out.print("[BlockPhysics] Patching AnvilChunkLoader.class ........");

    boolean ok = false, ok2 = false, ok3 = false, ok4 = false, ok6 = false, ok7 = false;
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();
        if (m.name.equals("a") && m.desc.equals("(Ladq;Labv;Lbx;)V")) {
            int var1 = 9;
            for (int index = 0; index < m.instructions.size(); index++) {
                if (ok3)
                    break;
                if (m.instructions.get(index).getOpcode() == INVOKESPECIAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("bx")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("<init>")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("()V")) {
                    for (int index2 = index; index2 < m.instructions.size(); index2++) {
                        if (m.instructions.get(index2).getOpcode() == ASTORE) {
                            var1 = ((VarInsnNode) m.instructions.get(index2)).var;
                            ok3 = true;
                            break;
                        }
                    }
                }
            }

            int var2 = 11;
            for (int index = 0; index < m.instructions.size(); index++) {
                if (ok4)
                    break;
                if (m.instructions.get(index).getType() == AbstractInsnNode.LDC_INSN
                        && ((LdcInsnNode) m.instructions.get(index)).cst.equals("Data")) {
                    for (int index2 = index; index2 < m.instructions.size(); index2++) {
                        if (m.instructions.get(index2).getOpcode() == ALOAD) {
                            var2 = ((VarInsnNode) m.instructions.get(index2)).var;
                            ok4 = true;
                            break;
                        }
                    }
                }
            }

            for (int index = 0; index < m.instructions.size(); index++) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("cf")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("a")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Lck;)V")) {
                    InsnList toInject = new InsnList();

                    toInject.add(new VarInsnNode(ALOAD, var1));
                    toInject.add(new LdcInsnNode("BPData"));
                    toInject.add(new VarInsnNode(ALOAD, var2));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "getBPdataArray", "()[B"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "a", "(Ljava/lang/String;[B)V"));

                    m.instructions.insertBefore(m.instructions.get(index - 2), toInject);

                    ok = true;
                    break;
                }
            }
        } else if (m.name.equals("a") && m.desc.equals("(Labv;Lbx;)Ladq;")) {
            int var1 = 11;
            for (int index = 0; index < m.instructions.size(); index++) {

                if (ok6)
                    break;
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("cf")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("b")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(I)Lck;")) {
                    for (int index2 = index; index2 < m.instructions.size(); index2++) {
                        if (m.instructions.get(index2).getOpcode() == ASTORE) {
                            var1 = ((VarInsnNode) m.instructions.get(index2)).var;
                            ok6 = true;
                            break;
                        }
                    }
                }
            }

            int var2 = 13;
            for (int index = 0; index < m.instructions.size(); index++) {
                if (ok7)
                    break;
                if (m.instructions.get(index).getOpcode() == INVOKESPECIAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("adr")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("<init>")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(IZ)V")) {
                    for (int index2 = index; index2 < m.instructions.size(); index2++) {
                        if (m.instructions.get(index2).getOpcode() == ASTORE) {
                            var2 = ((VarInsnNode) m.instructions.get(index2)).var;
                            ok7 = true;
                            break;
                        }
                    }
                }
            }

            for (int index = 0; index < m.instructions.size(); index++) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("adr")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("e")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("()V")) {
                    InsnList toInject = new InsnList();

                    toInject.add(new VarInsnNode(ALOAD, var1));
                    toInject.add(new LdcInsnNode("BPData"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "b", "(Ljava/lang/String;)Z"));
                    LabelNode l6 = new LabelNode();
                    toInject.add(new JumpInsnNode(IFEQ, l6));
                    toInject.add(new VarInsnNode(ALOAD, var2));
                    toInject.add(new VarInsnNode(ALOAD, var1));
                    toInject.add(new LdcInsnNode("BPData"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "j", "(Ljava/lang/String;)[B"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "setBPdataArray", "([B)V"));
                    LabelNode l7 = new LabelNode();
                    toInject.add(new JumpInsnNode(GOTO, l7));
                    toInject.add(l6);
                    toInject.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
                    toInject.add(new VarInsnNode(ALOAD, var2));
                    toInject.add(new IntInsnNode(SIPUSH, 4096));
                    toInject.add(new IntInsnNode(NEWARRAY, T_BYTE));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "setBPdataArray", "([B)V"));
                    toInject.add(l7);

                    m.instructions.insertBefore(m.instructions.get(index - 1), toInject);

                    ok2 = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok && ok2 && ok3 && ok4 && ok6 && ok7)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok + ok2 + ok3 + ok4 + ok6 + ok7);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/AnvilChunkLoader.mod.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformWorld(byte[] bytes) {
    /*try// w ww .  java  2s  .  co  m
    {
        FileOutputStream fos = new FileOutputStream("d:/World.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    System.out.print("[BlockPhysics] Patching World.class ...................");
    boolean ok = false, ok2 = false;
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();

        if (m.name.equals("<init>")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new TypeInsnNode(NEW, "blockphysics/BTickList"));
                    toInject.add(new InsnNode(DUP));
                    toInject.add(new MethodInsnNode(INVOKESPECIAL, "blockphysics/BTickList", "<init>", "()V"));
                    toInject.add(
                            new FieldInsnNode(PUTFIELD, "abv", "moveTickList", "Lblockphysics/BTickList;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new TypeInsnNode(NEW, "java/util/HashSet"));
                    toInject.add(new InsnNode(DUP));
                    toInject.add(new MethodInsnNode(INVOKESPECIAL, "java/util/HashSet", "<init>", "()V"));
                    toInject.add(new FieldInsnNode(PUTFIELD, "abv", "pistonMoveBlocks", "Ljava/util/HashSet;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new TypeInsnNode(NEW, "blockphysics/ExplosionQueue"));
                    toInject.add(new InsnNode(DUP));
                    toInject.add(
                            new MethodInsnNode(INVOKESPECIAL, "blockphysics/ExplosionQueue", "<init>", "()V"));
                    toInject.add(new FieldInsnNode(PUTFIELD, "abv", "explosionQueue",
                            "Lblockphysics/ExplosionQueue;"));

                    m.instructions.insertBefore(m.instructions.get(index), toInject);
                    ok = true;
                }
            }
        } else if (m.name.equals("a") && m.desc.equals("(Lnm;DDDFZZ)Labq;"))
            ;
        {
            for (int index = m.instructions.size() - 1; index > 0; index--) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("abq")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("a")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Z)V")) {

                    while (!(m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                            && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                            && ((MethodInsnNode) m.instructions.get(index)).owner.equals("abq")
                            && ((MethodInsnNode) m.instructions.get(index)).name.equals("a")
                            && ((MethodInsnNode) m.instructions.get(index)).desc.equals("()V"))) {
                        m.instructions.remove(m.instructions.get(index));
                        index--;
                    }
                    m.instructions.remove(m.instructions.get(index - 1));
                    m.instructions.remove(m.instructions.get(index - 1));

                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "abv", "explosionQueue",
                            "Lblockphysics/ExplosionQueue;"));
                    toInject.add(new VarInsnNode(ALOAD, 11));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "blockphysics/ExplosionQueue", "add",
                            "(Labq;)V"));

                    m.instructions.insertBefore(m.instructions.get(index - 1), toInject);

                    ok2 = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    FieldVisitor fv;

    fv = cw.visitField(ACC_PUBLIC, "moveTickList", "Lblockphysics/BTickList;", null, null);
    fv.visitEnd();

    fv = cw.visitField(ACC_PUBLIC, "pistonMoveBlocks", "Ljava/util/HashSet;",
            "Ljava/util/HashSet<Ljava/lang/String;>;", null);
    fv.visitEnd();

    fv = cw.visitField(ACC_PUBLIC, "explosionQueue", "Lblockphysics/ExplosionQueue;", null, null);
    fv.visitEnd();

    cw.visitEnd();

    if (ok && ok2)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok + ok2);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/World.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformWorldServer(byte[] bytes) {
    /*try/*from w  w  w . jav  a2 s.co m*/
    {
        FileOutputStream fos = new FileOutputStream("d:/WorldServer.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    boolean ok = false, ok2 = false;

    boolean bukkit = false;
    try {
        Class.forName("org.bukkit.Bukkit");
        System.out.println("[BlockPhysics] Bukkit detected.");
        bukkit = true;
        ok2 = true;
    } catch (ClassNotFoundException e) {

    }

    System.out.print("[BlockPhysics] Patching WorldServer.class .............");
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();

        if (m.name.equals("b") && m.desc.equals("()V")) {
            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics",
                            "tickBlocksRandomMove", "(Ljr;)V"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "jr", "moveTickList", "Lblockphysics/BTickList;"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "blockphysics/BTickList", "tickMoveUpdates",
                            "(Labv;)V"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "jr", "pistonMoveBlocks", "Ljava/util/HashSet;"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "java/util/HashSet", "clear", "()V"));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "jr", "explosionQueue",
                            "Lblockphysics/ExplosionQueue;"));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "blockphysics/ExplosionQueue",
                            "doNextExplosion", "()V"));

                    m.instructions.insertBefore(m.instructions.get(index), toInject);

                    ok = true;
                    break;
                }
            }
        } else if (!bukkit && m.name.equals("a") && m.desc.equals("(Lnm;DDDFZZ)Labq;"))
            ;
        {
            for (int index = m.instructions.size() - 1; index > 0; index--) {
                if (m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("abq")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("a")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Z)V")) {

                    while (!(m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                            && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                            && ((MethodInsnNode) m.instructions.get(index)).owner.equals("abq")
                            && ((MethodInsnNode) m.instructions.get(index)).name.equals("a")
                            && ((MethodInsnNode) m.instructions.get(index)).desc.equals("()V"))) {
                        m.instructions.remove(m.instructions.get(index));
                        index--;
                    }
                    m.instructions.remove(m.instructions.get(index - 1));
                    m.instructions.remove(m.instructions.get(index - 1));

                    InsnList toInject = new InsnList();
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new FieldInsnNode(GETFIELD, "jr", "explosionQueue",
                            "Lblockphysics/ExplosionQueue;"));
                    toInject.add(new VarInsnNode(ALOAD, 11));
                    toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "blockphysics/ExplosionQueue", "add",
                            "(Labq;)V"));

                    m.instructions.insertBefore(m.instructions.get(index - 1), toInject);

                    ok2 = true;
                    break;
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok && ok2)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok + ok2);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/WorldServer.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformMinecraftServer(byte[] bytes) {
    /*try/*from  w w w .  j a v a 2  s. c  o  m*/
    {
        FileOutputStream fos = new FileOutputStream("d:/MinecraftServer.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    boolean bukkit = false;
    try {
        Class.forName("org.bukkit.Bukkit");
        System.out.println("[BlockPhysics] Bukkit detected.");
        bukkit = true;
    } catch (ClassNotFoundException e) {

    }

    System.out.print("[BlockPhysics] Patching MinecraftServer.class .........");
    boolean ok = false;
    boolean ok2 = false;

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();

        if (m.name.equals("run") && m.desc.equals("()V")) {
            if (bukkit) {
                int index;
                for (index = 0; index < m.instructions.size(); index++) {
                    if (m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                            && m.instructions.get(index).getOpcode() == INVOKESTATIC
                            && ((MethodInsnNode) m.instructions.get(index)).owner.equals("java/lang/System")
                            && ((MethodInsnNode) m.instructions.get(index)).name.equals("nanoTime")) {
                        ok = true;
                        break;
                    }
                }

                if (ok) {
                    while (index < m.instructions.size()) {
                        if (m.instructions.get(index).getOpcode() == LSUB) {
                            InsnList toInject = new InsnList();
                            toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics",
                                    "setSkipMoveM", "(J)J"));

                            m.instructions.insert(m.instructions.get(index), toInject);

                            ok2 = true;
                            break;
                        }
                        index++;
                    }
                }
            } else {
                int index;
                for (index = 0; index < m.instructions.size(); index++) {
                    if (m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                            && m.instructions.get(index).getOpcode() == INVOKEVIRTUAL
                            && ((MethodInsnNode) m.instructions.get(index)).owner
                                    .equals("net/minecraft/server/MinecraftServer")
                            && ((MethodInsnNode) m.instructions.get(index)).name.equals("s")) {
                        ok = true;
                        break;
                    }
                }

                if (ok) {
                    while (index > 0) {

                        if (m.instructions.get(index).getOpcode() == LLOAD
                                && m.instructions.get(index).getType() == AbstractInsnNode.VAR_INSN
                                && ((VarInsnNode) m.instructions.get(index)).var == 3) {
                            InsnList toInject = new InsnList();
                            toInject.add(new VarInsnNode(LLOAD, 7));
                            toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics",
                                    "setSkipMove", "(J)V"));

                            m.instructions.insertBefore(m.instructions.get(index), toInject);

                            ok2 = true;
                            break;
                        }
                        index--;
                    }
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok && ok2)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok + ok2);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/MinecraftServer.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformEntityTNTPrimed(byte[] bytes) {
    /*try/*  w  ww . j a  v a 2 s  .c  o  m*/
    {
        FileOutputStream fos = new FileOutputStream("d:/EntityTNTPrimed.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    boolean bukkit = false;
    try {
        Class.forName("org.bukkit.Bukkit");
        System.out.println("[BlockPhysics] Bukkit detected.");
        bukkit = true;
    } catch (ClassNotFoundException e) {

    }

    System.out.print("[BlockPhysics] Patching EntityTNTPrimed.class .........");
    boolean ok = false, ok2 = false, ok5 = false, ok6 = false, ok7 = false, ok8 = false, ok9 = false,
            ok10 = false;

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    classNode.superName = "sq";

    MethodNode m;
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        m = methods.next();

        if (m.name.equals("<init>") && m.desc.equals("(Labv;)V")) {
            for (int index = 0; index < m.instructions.size(); index++) {
                if (m.instructions.get(index).getOpcode() == INVOKESPECIAL
                        && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                        && ((MethodInsnNode) m.instructions.get(index)).owner.equals("nm")
                        && ((MethodInsnNode) m.instructions.get(index)).name.equals("<init>")
                        && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Labv;)V")) {
                    m.instructions.set(m.instructions.get(index),
                            new MethodInsnNode(INVOKESPECIAL, "sq", "<init>", "(Labv;)V"));
                    ok = true;
                    break;
                }
            }
        } else if (m.name.equals("<init>") && m.desc.equals("(Labv;DDDLoe;)V")) {
            InsnList toInject = new InsnList();

            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(new VarInsnNode(DLOAD, 2));
            toInject.add(new VarInsnNode(DLOAD, 4));
            toInject.add(new VarInsnNode(DLOAD, 6));
            toInject.add(new IntInsnNode(BIPUSH, 46));
            toInject.add(new InsnNode(ICONST_0));
            toInject.add(new MethodInsnNode(INVOKESPECIAL, "sq", "<init>", "(Labv;DDDII)V"));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new IntInsnNode(BIPUSH, 80));
            toInject.add(new FieldInsnNode(PUTFIELD, "tb", "a", "I"));

            if (bukkit) {
                toInject.add(new VarInsnNode(ALOAD, 0));
                toInject.add(new LdcInsnNode(new Float("4.0")));
                toInject.add(new FieldInsnNode(PUTFIELD, "tb", "yield", "F"));
                toInject.add(new VarInsnNode(ALOAD, 0));
                toInject.add(new InsnNode(ICONST_0));
                toInject.add(new FieldInsnNode(PUTFIELD, "tb", "isIncendiary", "Z"));
            }

            toInject.add(new InsnNode(RETURN));

            m.instructions.clear();
            m.localVariables.clear();
            m.instructions.add(toInject);

            ok2 = true;
        } else if (m.name.equals("K") && m.desc.equals("()Z")) {
            InsnList toInject = new InsnList();
            toInject.add(new InsnNode(ICONST_0));
            toInject.add(new InsnNode(IRETURN));

            m.instructions.clear();
            m.localVariables.clear();
            m.instructions.add(toInject);
            ok5 = true;
        } else if (m.name.equals("l_") && m.desc.equals("()V")) {
            InsnList toInject = new InsnList();
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new FieldInsnNode(GETFIELD, "tb", "q", "Labv;"));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "fallingSandUpdate",
                    "(Labv;Lsq;)V"));
            toInject.add(new InsnNode(RETURN));

            m.instructions.clear();
            m.localVariables.clear();
            m.instructions.add(toInject);
            ok6 = true;
        } else if (m.name.equals("b") && m.desc.equals("(Lbx;)V")) {
            InsnList toInject = new InsnList();

            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(new MethodInsnNode(INVOKESPECIAL, "sq", "b", "(Lbx;)V"));

            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    m.instructions.insertBefore(m.instructions.get(index), toInject);
                    ok7 = true;
                    break;
                }
            }
        } else if (m.name.equals("a") && m.desc.equals("(Lbx;)V")) {
            InsnList toInject = new InsnList();

            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(new MethodInsnNode(INVOKESPECIAL, "sq", "a", "(Lbx;)V"));

            for (int index = m.instructions.size() - 1; index >= 0; index--) {
                if (m.instructions.get(index).getOpcode() == RETURN) {
                    m.instructions.insertBefore(m.instructions.get(index), toInject);
                    ok8 = true;
                    break;
                }
            }
        } else if (m.name.equals("d") && m.desc.equals("()V")) {
            m.access = ACC_PUBLIC;
            ok9 = true;
            if (bukkit) {
                for (int index = 0; index < m.instructions.size(); index++) {
                    if (m.instructions.get(index).getOpcode() == INVOKESTATIC
                            && m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN
                            && ((MethodInsnNode) m.instructions.get(index)).owner.contains("entity/CraftEntity")
                            && ((MethodInsnNode) m.instructions.get(index)).name.equals("getEntity")) {
                        String pclass = ((MethodInsnNode) m.instructions.get(index)).owner
                                .replace("entity/CraftEntity", "");
                        m.instructions.set(m.instructions.get(index),
                                new MethodInsnNode(INVOKESPECIAL, pclass + "entity/CraftTNTPrimed", "<init>",
                                        "(L" + pclass + "CraftServer;Ltb;)V"));

                        InsnList toInject = new InsnList();

                        toInject.add(new TypeInsnNode(NEW, pclass + "entity/CraftTNTPrimed"));
                        toInject.add(new InsnNode(DUP));

                        m.instructions.insert(m.instructions.get(index - 3), toInject);

                        ok10 = true;
                        break;
                    }
                }
            } else {
                for (int index = 0; index < m.instructions.size(); index++) {
                    if (m.instructions.get(index).getOpcode() == ACONST_NULL) {
                        m.instructions.set(m.instructions.get(index), new VarInsnNode(ALOAD, 0));
                        ok10 = true;
                        break;
                    }
                }
            }
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    if (ok && ok2 && ok5 && ok6 && ok7 && ok8 && ok9)
        System.out.println("OK");
    else
        System.out.println("Failed." + ok + ok2 + ok5 + ok6 + ok7 + ok8 + ok9);

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/EntityTNTPrimed.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}