Example usage for org.objectweb.asm.tree ClassNode accept

List of usage examples for org.objectweb.asm.tree ClassNode accept

Introduction

In this page you can find the example usage for org.objectweb.asm.tree ClassNode accept.

Prototype

public void accept(final ClassVisitor classVisitor) 

Source Link

Document

Makes the given class visitor visit this class.

Usage

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformBlockChest(byte[] bytes) {
    /*try/* w  ww.  ja  v a 2s  .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/* ww  w. j  a  v a 2s  .  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[] transformExtendedBlockStorage(byte[] bytes) {
    /*try/* www  .j  ava 2  s  . c  om*/
     {
         FileOutputStream fos = new FileOutputStream("d:/ExtendedBlockStorage.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

    System.out.print("[BlockPhysics] Patching ExtendedBlockStorage.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("<init>") && m.desc.equals("(IZ)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 FrameNode(Opcodes.F_FULL, 3, new Object[] {"abx", Opcodes.INTEGER, Opcodes.INTEGER}, 0, new Object[] {}));
                    toInject.add(new VarInsnNode(ALOAD, 0));
                    toInject.add(new IntInsnNode(SIPUSH, 4096));
                    toInject.add(new IntInsnNode(NEWARRAY, T_BYTE));
                    toInject.add(new FieldInsnNode(PUTFIELD, "adr", "blockBPdataArray", "[B"));

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

                    ok = true;
                    break;
                }
            }
        }
    }

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

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBlockBPdata", "(III)I", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adr", "blockBPdataArray", "[B");
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(SIPUSH, 256);
    mv.visitInsn(IMUL);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitIntInsn(BIPUSH, 16);
    mv.visitInsn(IMUL);
    mv.visitInsn(IADD);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitInsn(IADD);
    mv.visitInsn(BALOAD);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(4, 4);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "setBlockBPdata", "(IIII)V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adr", "blockBPdataArray", "[B");
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(SIPUSH, 256);
    mv.visitInsn(IMUL);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitIntInsn(BIPUSH, 16);
    mv.visitInsn(IMUL);
    mv.visitInsn(IADD);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitInsn(IADD);
    mv.visitVarInsn(ILOAD, 4);
    mv.visitInsn(I2B);
    mv.visitInsn(BASTORE);
    mv.visitInsn(RETURN);
    mv.visitMaxs(4, 5);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "getBPdataArray", "()[B", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adr", "blockBPdataArray", "[B");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "setBPdataArray", "([B)V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, "adr", "blockBPdataArray", "[B");
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    FieldVisitor fv;

    fv = cw.visitField(ACC_PRIVATE, "blockBPdataArray", "[B", null, null);
    fv.visitEnd();

    cw.visitEnd();

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

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/ExtendedBlockStorage.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[] transformChunk(byte[] bytes) {
    /*try/*  w  w w .j a  va2 s .  c om*/
     {
         FileOutputStream fos = new FileOutputStream("d:/Chunk.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

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

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

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

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBlockBPdata", "(III)I", null, null);
    mv.visitCode();
    mv.visitVarInsn(ILOAD, 2);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(ISHR);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adq", "r", "[Ladr;");
    mv.visitInsn(ARRAYLENGTH);
    Label l0 = new Label();
    mv.visitJumpInsn(IF_ICMPLT, l0);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(IRETURN);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adq", "r", "[Ladr;");
    mv.visitVarInsn(ILOAD, 2);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(ISHR);
    mv.visitInsn(AALOAD);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitVarInsn(ALOAD, 4);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNULL, l1);
    mv.visitVarInsn(ALOAD, 4);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(BIPUSH, 15);
    mv.visitInsn(IAND);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "adr", "getBlockBPdata", "(III)I");
    Label l2 = new Label();
    mv.visitJumpInsn(GOTO, l2);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "adr" }, 0, null);
    mv.visitInsn(ICONST_0);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
    mv.visitInsn(IRETURN);
    mv.visitMaxs(4, 5);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "setBlockBPdata", "(IIII)Z", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adq", "r", "[Ladr;");
    mv.visitVarInsn(ILOAD, 2);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(ISHR);
    mv.visitInsn(AALOAD);
    mv.visitVarInsn(ASTORE, 5);
    mv.visitVarInsn(ALOAD, 5);
    Label lab0 = new Label();
    mv.visitJumpInsn(IFNONNULL, lab0);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(IRETURN);
    mv.visitLabel(lab0);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "adr" }, 0, null);
    mv.visitVarInsn(ALOAD, 5);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(BIPUSH, 15);
    mv.visitInsn(IAND);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "adr", "getBlockBPdata", "(III)I");
    mv.visitVarInsn(ISTORE, 6);
    mv.visitVarInsn(ILOAD, 6);
    mv.visitVarInsn(ILOAD, 4);
    Label lab1 = new Label();
    mv.visitJumpInsn(IF_ICMPNE, lab1);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(IRETURN);
    mv.visitLabel(lab1);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { Opcodes.INTEGER }, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitInsn(ICONST_1);
    mv.visitFieldInsn(PUTFIELD, "adq", "l", "Z");
    mv.visitVarInsn(ALOAD, 5);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(BIPUSH, 15);
    mv.visitInsn(IAND);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitVarInsn(ILOAD, 4);
    mv.visitMethodInsn(INVOKEVIRTUAL, "adr", "setBlockBPdata", "(IIII)V");
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(5, 7);
    mv.visitEnd();

    cw.visitEnd();

    System.out.println("OK");

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/Chunk.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[] transformBlockPhysics(byte[] bytes) {
    /*try//from   w  w w .ja v a2 s. c om
    {
        FileOutputStream fos = new FileOutputStream("d:/BlockPhysics.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    try {
        Class.forName("org.bukkit.Bukkit");
        System.out.println("[BlockPhysics] Bukkit detected.");
    } catch (ClassNotFoundException e) {
        return bytes;
    }

    System.out.print("[BlockPhysics] Patching BlockPhysics.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("tickBlocksRandomMove") && m.desc.equals("(Ljr;)V")) {
            m.instructions.clear();
            m.localVariables.clear();

            InsnList toInject = new InsnList();

            toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "skipMove", "Z"));
            LabelNode l0 = new LabelNode();
            toInject.add(new JumpInsnNode(IFEQ, l0));
            toInject.add(new InsnNode(RETURN));
            toInject.add(l0);
            toInject.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new FieldInsnNode(GETFIELD, "jr", "G", "Lgnu/trove/map/hash/TLongShortHashMap;"));
            toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "gnu/trove/map/hash/TLongShortHashMap", "iterator",
                    "()Lgnu/trove/iterator/TLongShortIterator;"));
            toInject.add(new VarInsnNode(ASTORE, 1));
            LabelNode l1 = new LabelNode();
            toInject.add(l1);
            toInject.add(new FrameNode(Opcodes.F_APPEND, 1,
                    new Object[] { "gnu/trove/iterator/TLongShortIterator" }, 0, null));
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(new MethodInsnNode(INVOKEINTERFACE, "gnu/trove/iterator/TLongShortIterator", "hasNext",
                    "()Z"));
            LabelNode l2 = new LabelNode();
            toInject.add(new JumpInsnNode(IFEQ, l2));
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(new MethodInsnNode(INVOKEINTERFACE, "gnu/trove/iterator/TLongShortIterator", "advance",
                    "()V"));
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(
                    new MethodInsnNode(INVOKEINTERFACE, "gnu/trove/iterator/TLongShortIterator", "key", "()J"));
            toInject.add(new VarInsnNode(LSTORE, 2));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new InsnNode(POP));
            toInject.add(new VarInsnNode(LLOAD, 2));
            toInject.add(new MethodInsnNode(INVOKESTATIC, "abv", "keyToX", "(J)I"));
            toInject.add(new VarInsnNode(ISTORE, 4));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new InsnNode(POP));
            toInject.add(new VarInsnNode(LLOAD, 2));
            toInject.add(new MethodInsnNode(INVOKESTATIC, "abv", "keyToZ", "(J)I"));
            toInject.add(new VarInsnNode(ISTORE, 5));
            toInject.add(new VarInsnNode(ILOAD, 4));
            toInject.add(new IntInsnNode(BIPUSH, 16));
            toInject.add(new InsnNode(IMUL));
            toInject.add(new VarInsnNode(ISTORE, 6));
            toInject.add(new VarInsnNode(ILOAD, 5));
            toInject.add(new IntInsnNode(BIPUSH, 16));
            toInject.add(new InsnNode(IMUL));
            toInject.add(new VarInsnNode(ISTORE, 7));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new VarInsnNode(ILOAD, 4));
            toInject.add(new VarInsnNode(ILOAD, 5));
            toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "jr", "e", "(II)Ladq;"));
            toInject.add(new VarInsnNode(ASTORE, 8));
            toInject.add(new VarInsnNode(ALOAD, 8));
            toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adq", "i", "()[Ladr;"));
            toInject.add(new VarInsnNode(ASTORE, 12));
            toInject.add(new VarInsnNode(ALOAD, 12));
            toInject.add(new InsnNode(ARRAYLENGTH));
            toInject.add(new VarInsnNode(ISTORE, 9));
            toInject.add(new InsnNode(ICONST_0));
            toInject.add(new VarInsnNode(ISTORE, 10));
            LabelNode l3 = new LabelNode();
            toInject.add(l3);
            toInject.add(new FrameNode(Opcodes.F_FULL, 12,
                    new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator", Opcodes.LONG, Opcodes.INTEGER,
                            Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "adq", Opcodes.INTEGER,
                            Opcodes.INTEGER, Opcodes.TOP, "[Ladr;" },
                    0, new Object[] {}));
            toInject.add(new VarInsnNode(ILOAD, 10));
            toInject.add(new VarInsnNode(ILOAD, 9));
            LabelNode l4 = new LabelNode();
            toInject.add(new JumpInsnNode(IF_ICMPGE, l4));
            toInject.add(new VarInsnNode(ALOAD, 12));
            toInject.add(new VarInsnNode(ILOAD, 10));
            toInject.add(new InsnNode(AALOAD));
            toInject.add(new VarInsnNode(ASTORE, 13));
            toInject.add(new VarInsnNode(ALOAD, 13));
            LabelNode l5 = new LabelNode();
            toInject.add(new JumpInsnNode(IFNULL, l5));
            toInject.add(new InsnNode(ICONST_0));
            toInject.add(new VarInsnNode(ISTORE, 14));
            LabelNode l6 = new LabelNode();
            toInject.add(l6);
            toInject.add(new FrameNode(Opcodes.F_APPEND, 2, new Object[] { "adr", Opcodes.INTEGER }, 0, null));
            toInject.add(new VarInsnNode(ILOAD, 14));
            toInject.add(new InsnNode(ICONST_3));
            toInject.add(new JumpInsnNode(IF_ICMPGE, l5));
            toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "updateLCG", "I"));
            toInject.add(new InsnNode(ICONST_3));
            toInject.add(new InsnNode(IMUL));
            toInject.add(new LdcInsnNode(new Integer(1013904223)));
            toInject.add(new InsnNode(IADD));
            toInject.add(new FieldInsnNode(PUTSTATIC, "blockphysics/BlockPhysics", "updateLCG", "I"));
            toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "updateLCG", "I"));
            toInject.add(new InsnNode(ICONST_2));
            toInject.add(new InsnNode(ISHR));
            toInject.add(new VarInsnNode(ISTORE, 11));
            toInject.add(new VarInsnNode(ILOAD, 11));
            toInject.add(new IntInsnNode(BIPUSH, 15));
            toInject.add(new InsnNode(IAND));
            toInject.add(new VarInsnNode(ISTORE, 15));
            toInject.add(new VarInsnNode(ILOAD, 11));
            toInject.add(new IntInsnNode(BIPUSH, 8));
            toInject.add(new InsnNode(ISHR));
            toInject.add(new IntInsnNode(BIPUSH, 15));
            toInject.add(new InsnNode(IAND));
            toInject.add(new VarInsnNode(ISTORE, 16));
            toInject.add(new VarInsnNode(ILOAD, 11));
            toInject.add(new IntInsnNode(BIPUSH, 16));
            toInject.add(new InsnNode(ISHR));
            toInject.add(new IntInsnNode(BIPUSH, 15));
            toInject.add(new InsnNode(IAND));
            toInject.add(new VarInsnNode(ISTORE, 17));
            toInject.add(new VarInsnNode(ALOAD, 13));
            toInject.add(new VarInsnNode(ILOAD, 15));
            toInject.add(new VarInsnNode(ILOAD, 17));
            toInject.add(new VarInsnNode(ILOAD, 16));
            toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "a", "(III)I"));
            toInject.add(new VarInsnNode(ISTORE, 18));
            toInject.add(new VarInsnNode(ALOAD, 13));
            toInject.add(new VarInsnNode(ILOAD, 15));
            toInject.add(new VarInsnNode(ILOAD, 17));
            toInject.add(new VarInsnNode(ILOAD, 16));
            toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "b", "(III)I"));
            toInject.add(new VarInsnNode(ISTORE, 19));
            toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "blockSet",
                    "[[Lblockphysics/BlockDef;"));
            toInject.add(new VarInsnNode(ILOAD, 18));
            toInject.add(new InsnNode(AALOAD));
            toInject.add(new VarInsnNode(ILOAD, 19));
            toInject.add(new InsnNode(AALOAD));
            toInject.add(new FieldInsnNode(GETFIELD, "blockphysics/BlockDef", "randomtick", "Z"));
            LabelNode l7 = new LabelNode();
            toInject.add(new JumpInsnNode(IFEQ, l7));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new VarInsnNode(ILOAD, 15));
            toInject.add(new VarInsnNode(ILOAD, 6));
            toInject.add(new InsnNode(IADD));
            toInject.add(new VarInsnNode(ILOAD, 17));
            toInject.add(new VarInsnNode(ALOAD, 13));
            toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "d", "()I"));
            toInject.add(new InsnNode(IADD));
            toInject.add(new VarInsnNode(ILOAD, 16));
            toInject.add(new VarInsnNode(ILOAD, 7));
            toInject.add(new InsnNode(IADD));
            toInject.add(new VarInsnNode(ILOAD, 18));
            toInject.add(new VarInsnNode(ILOAD, 19));
            toInject.add(new InsnNode(ICONST_0));
            toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "tryToMove",
                    "(Labv;IIIIIZ)Z"));
            toInject.add(new InsnNode(POP));
            toInject.add(l7);
            toInject.add(new FrameNode(Opcodes.F_FULL, 14,
                    new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator", Opcodes.LONG, Opcodes.INTEGER,
                            Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "adq", Opcodes.INTEGER,
                            Opcodes.INTEGER, Opcodes.INTEGER, "[Ladr;", "adr", Opcodes.INTEGER },
                    0, new Object[] {}));
            toInject.add(new IincInsnNode(14, 1));
            toInject.add(new JumpInsnNode(GOTO, l6));
            toInject.add(l5);
            toInject.add(new FrameNode(Opcodes.F_FULL, 12,
                    new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator", Opcodes.LONG, Opcodes.INTEGER,
                            Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "adq", Opcodes.INTEGER,
                            Opcodes.INTEGER, Opcodes.TOP, "[Ladr;" },
                    0, new Object[] {}));
            toInject.add(new IincInsnNode(10, 1));
            toInject.add(new JumpInsnNode(GOTO, l3));
            toInject.add(l4);
            toInject.add(new FrameNode(Opcodes.F_FULL, 2,
                    new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator" }, 0, new Object[] {}));
            toInject.add(new JumpInsnNode(GOTO, l1));
            toInject.add(l2);
            toInject.add(new FrameNode(Opcodes.F_CHOP, 1, null, 0, null));
            toInject.add(new InsnNode(RETURN));

            m.instructions.add(toInject);

            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:/BlockPhysics.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[] transformEntity(byte[] bytes) {
    /*try/*from   w ww.  ja v a  2s .  c  o  m*/
    {
        FileOutputStream fos = new FileOutputStream("d:/Entity.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    System.out.print("[BlockPhysics] Patching Entity.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("C") && m.desc.equals("()V")) {
            for (int index = 0; index < m.instructions.size() - 1; index++) {
                if (m.instructions.get(index).getType() == AbstractInsnNode.LDC_INSN
                        && ((LdcInsnNode) m.instructions.get(index)).cst.equals(0.001D)) {
                    ok = true;
                    m.instructions.set(m.instructions.get(index), new LdcInsnNode(new Double("0.07")));
                }
            }
        }
    }

    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:/Entity.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[] transformEntityMinecart(byte[] bytes) {
    /*try/*ww  w.  j a  va  2  s  . c o m*/
    {
        FileOutputStream fos = new FileOutputStream("d:/EntityMinecart.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

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

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

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

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "al", "()V", null, null);
    mv.visitCode();
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 1);
    mv.visitEnd();

    cw.visitEnd();

    System.out.println("OK");

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/EntityMinecart.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[] transformEntityXPOrb(byte[] bytes) {
    /*try/* w w  w . j  ava 2  s. com*/
    {
        FileOutputStream fos = new FileOutputStream("d:/EntityXPOrb.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

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

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

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

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "al", "()V", null, null);
    mv.visitCode();
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 1);
    mv.visitEnd();

    cw.visitEnd();

    System.out.println("OK");

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/EntityXPOrb.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[] transformEntityBoat(byte[] bytes) {
    /*try// w w w. j a  va 2  s.  co  m
    {
        FileOutputStream fos = new FileOutputStream("d:/EntityBoat.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

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

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

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

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "al", "()V", null, null);
    mv.visitCode();
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 1);
    mv.visitEnd();

    cw.visitEnd();

    System.out.println("OK");

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/EntityBoat.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[] transformBlockWeb(byte[] bytes) {
    /*try/*from w w w . j av  a  2  s.  c om*/
    {
        FileOutputStream fos = new FileOutputStream("d:/BlockWeb.orig.class");
        fos.write(bytes);
      fos.close();
    } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    System.out.print("[BlockPhysics] Patching BlockWeb.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;IIILnm;)V")) {
            InsnList toInject = new InsnList();
            toInject.add(new VarInsnNode(ALOAD, 1));
            toInject.add(new VarInsnNode(ILOAD, 2));
            toInject.add(new VarInsnNode(ILOAD, 3));
            toInject.add(new VarInsnNode(ILOAD, 4));
            toInject.add(new VarInsnNode(ALOAD, 0));
            toInject.add(new FieldInsnNode(GETFIELD, "arm", "cF", "I"));
            toInject.add(new VarInsnNode(ALOAD, 5));
            toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics",
                    "onEntityCollidedWithBlock", "(Labv;IIIILnm;)V"));
            toInject.add(new InsnNode(RETURN));

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

            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:/BlockWeb.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}