List of usage examples for org.objectweb.asm.tree ClassNode ClassNode
public ClassNode()
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformEntityTNTPrimed(byte[] bytes) { /*try/*from w w w.j ava2 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(); }
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformEntityFallingSand(byte[] bytes) { /*try//from w w w . ja va 2 s . co m { FileOutputStream fos = new FileOutputStream("d:/EntityFallingSand.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching EntityFallingSand.class ......."); boolean ok = false; boolean ok2 = false; boolean ok3 = false; boolean ok4 = false; boolean ok5 = false; boolean ok6 = false; boolean ok7 = false; boolean ok8 = false; boolean ok9 = false, ok10 = 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("(Labv;)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(ICONST_1)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "m", "Z")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new LdcInsnNode(new Float("0.996"))); toInject.add(new LdcInsnNode(new Float("0.996"))); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "sq", "a", "(FF)V")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "sq", "P", "F")); toInject.add(new InsnNode(FCONST_2)); toInject.add(new InsnNode(FDIV)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "N", "F")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "x", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "y", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "z", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationX", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new LdcInsnNode(new Double("-0.024525"))); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationY", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationZ", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "slideDir", "B")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_1)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "Z", "Z")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new LdcInsnNode(new Float("0.8"))); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "aa", "F")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_4)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "dead", "B")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "bpdata", "I")); m.instructions.insertBefore(m.instructions.get(index), toInject); ok10 = true; break; } } } else if (m.name.equals("<init>") && m.desc.equals("(Labv;DDDII)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("sq") && ((MethodInsnNode) m.instructions.get(index)).name.equals("a")) { m.instructions.set(m.instructions.get(index - 1), new LdcInsnNode(new Float("0.996"))); m.instructions.set(m.instructions.get(index - 2), new LdcInsnNode(new Float("0.996"))); ok = true; break; } } 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(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationX", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new LdcInsnNode(new Double("-0.024525"))); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationY", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationZ", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "slideDir", "B")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_1)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "Z", "Z")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new LdcInsnNode(new Float("0.8"))); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "aa", "F")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_4)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "dead", "B")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "bpdata", "I")); m.instructions.insertBefore(m.instructions.get(index), toInject); ok2 = true; break; } } } 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); ok9 = 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, "sq", "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); ok3 = true; } else if (m.name.equals("b") && m.desc.equals("(F)V")) { m.instructions.clear(); m.localVariables.clear(); m.instructions.add(new InsnNode(RETURN)); ok4 = true; } 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("Acceleration")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_3)); toInject.add(new IntInsnNode(NEWARRAY, T_DOUBLE)); toInject.add(new InsnNode(DUP)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "sq", "accelerationX", "D")); toInject.add(new InsnNode(DASTORE)); toInject.add(new InsnNode(DUP)); toInject.add(new InsnNode(ICONST_1)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "sq", "accelerationY", "D")); toInject.add(new InsnNode(DASTORE)); toInject.add(new InsnNode(DUP)); toInject.add(new InsnNode(ICONST_2)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "sq", "accelerationZ", "D")); toInject.add(new InsnNode(DASTORE)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "sq", "a", "([D)Lcf;")); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "a", "(Ljava/lang/String;Lck;)V")); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new LdcInsnNode("BPData")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "sq", "bpdata", "I")); toInject.add(new InsnNode(I2B)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "a", "(Ljava/lang/String;B)V")); m.instructions.insertBefore(m.instructions.get(index), toInject); ok5 = true; break; } } } else if (m.name.equals("a") && m.desc.equals("(Lbx;)V")) { while (!(m.instructions.get(0).getType() == AbstractInsnNode.LDC_INSN && ((LdcInsnNode) m.instructions.get(0)).cst.equals("Data"))) { m.instructions.remove(m.instructions.get(0)); ok6 = true; } InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "readFallingSandID", "(Lbx;)I")); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "a", "I")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 1)); m.instructions.insertBefore(m.instructions.get(0), toInject); for (int index = m.instructions.size() - 1; index >= 0; index--) { if (m.instructions.get(index).getOpcode() == RETURN) { toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new LdcInsnNode("Acceleration")); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "b", "(Ljava/lang/String;)Z")); LabelNode l4 = new LabelNode(); toInject.add(new JumpInsnNode(IFEQ, l4)); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new LdcInsnNode("Acceleration")); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "m", "(Ljava/lang/String;)Lcf;")); toInject.add(new VarInsnNode(ASTORE, 2)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 2)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "cf", "b", "(I)Lck;")); toInject.add(new TypeInsnNode(CHECKCAST, "ca")); toInject.add(new FieldInsnNode(GETFIELD, "ca", "a", "D")); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationX", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 2)); toInject.add(new InsnNode(ICONST_1)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "cf", "b", "(I)Lck;")); toInject.add(new TypeInsnNode(CHECKCAST, "ca")); toInject.add(new FieldInsnNode(GETFIELD, "ca", "a", "D")); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationY", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 2)); toInject.add(new InsnNode(ICONST_2)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "cf", "b", "(I)Lck;")); toInject.add(new TypeInsnNode(CHECKCAST, "ca")); toInject.add(new FieldInsnNode(GETFIELD, "ca", "a", "D")); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationZ", "D")); LabelNode l5 = new LabelNode(); toInject.add(new JumpInsnNode(GOTO, l5)); toInject.add(l4); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationX", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationY", "D")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(DCONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "accelerationZ", "D")); toInject.add(l5); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new LdcInsnNode("BPData")); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "bx", "b", "(Ljava/lang/String;)Z")); LabelNode l7 = new LabelNode(); toInject.add(new JumpInsnNode(IFEQ, l7)); 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, "sq", "bpdata", "I")); LabelNode l8 = new LabelNode(); toInject.add(new JumpInsnNode(GOTO, l8)); toInject.add(l7); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "sq", "bpdata", "I")); toInject.add(l8); m.instructions.insertBefore(m.instructions.get(index), toInject); ok7 = true; break; } } } else if (m.name.equals("au") && m.desc.equals("()Z")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "sq", "ae", "()Z")); toInject.add(new InsnNode(IRETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok8 = true; } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); FieldVisitor fv; fv = cw.visitField(ACC_PUBLIC, "accelerationX", "D", null, null); fv.visitEnd(); fv = cw.visitField(ACC_PUBLIC, "accelerationY", "D", null, null); fv.visitEnd(); fv = cw.visitField(ACC_PUBLIC, "accelerationZ", "D", null, null); fv.visitEnd(); fv = cw.visitField(ACC_PUBLIC, "bpdata", "I", null, null); fv.visitEnd(); fv = cw.visitField(ACC_PUBLIC, "slideDir", "B", null, null); fv.visitEnd(); fv = cw.visitField(ACC_PUBLIC, "media", "I", null, null); fv.visitEnd(); fv = cw.visitField(ACC_PUBLIC, "dead", "B", null, null); fv.visitEnd(); MethodVisitor mv; mv = cw.visitMethod(ACC_PUBLIC, "D", "()Lasu;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "sq", "E", "Lasu;"); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); mv = cw.visitMethod(ACC_PUBLIC, "al", "()V", null, null); mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 1); mv.visitEnd(); mv = cw.visitMethod(ACC_PUBLIC, "d", "(DDD)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "sq", "q", "Labv;"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(DLOAD, 1); mv.visitVarInsn(DLOAD, 3); mv.visitVarInsn(DLOAD, 5); mv.visitMethodInsn(INVOKESTATIC, "blockphysics/BlockPhysics", "moveEntity", "(Labv;Lsq;DDD)V"); mv.visitInsn(RETURN); mv.visitMaxs(8, 7); mv.visitEnd(); if (!ok8) { mv = cw.visitMethod(ACC_PUBLIC, "au", "()Z", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "sq", "ae", "()Z"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); ok8 = true; } cw.visitEnd(); if (ok && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8 && ok9 && ok10) System.out.println("OK"); else System.out.println("Failed." + ok + ok2 + ok3 + ok4 + ok5 + ok6 + ok7 + ok8 + ok9 + ok10); /*try { FileOutputStream fos = new FileOutputStream("d:/EntityFallingSand.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[] transformRenderFallingSand(byte[] bytes) { /*try//from w w w . j av a 2 s .c om { FileOutputStream fos = new FileOutputStream("d:/RenderFallingSand.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching RenderFallingSand.class ......."); boolean ok = false, ok2 = false, ok4 = 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("(Lsq;DDDFF)V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BClient", "cancelRender", "(Lsq;)Z")); LabelNode l0 = new LabelNode(); toInject.add(new JumpInsnNode(IFEQ, l0)); toInject.add(new InsnNode(RETURN)); toInject.add(l0); m.instructions.insertBefore(m.instructions.getFirst(), toInject); int index; for (index = 0; index < m.instructions.size(); index++) { if (m.instructions.get(index).getOpcode() == GETFIELD && m.instructions.get(index).getType() == AbstractInsnNode.FIELD_INSN && ((FieldInsnNode) m.instructions.get(index)).owner.equals("sq") && ((FieldInsnNode) m.instructions.get(index)).name.equals("a") && ((FieldInsnNode) m.instructions.get(index)).desc.equals("I")) { index = index + 3; ok = true; break; } } while (!(m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN && ((MethodInsnNode) m.instructions.get(index)).name.equals("glPushMatrix"))) { m.instructions.remove(m.instructions.get(index)); ok2 = true; } for (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("bfo") && ((MethodInsnNode) m.instructions.get(index)).name.equals("a") && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(Laqw;Labv;IIII)V")) { m.instructions.set(m.instructions.get(index), new MethodInsnNode(INVOKESTATIC, "blockphysics/BClient", "renderBlockSandFalling", "(Lbfo;Laqw;Labv;IIII)V")); ok4 = true; break; } } } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); if (ok && ok2 && ok4) System.out.println("OK"); else System.out.println("Failed." + ok + ok2 + ok4); /*try { FileOutputStream fos = new FileOutputStream("d:/RenderFallingSand.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[] transformNetClientHandler(byte[] bytes) { /*try// w w w . j av a2 s . co m { FileOutputStream fos = new FileOutputStream("d:/NetClientHandler.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching NetClientHandler.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("(Ldc;)V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "bct", "i", "Lbda;")); toInject.add(new VarInsnNode(DLOAD, 2)); toInject.add(new VarInsnNode(DLOAD, 4)); toInject.add(new VarInsnNode(DLOAD, 6)); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "createFallingsand", "(Labv;DDDLdc;)Lsq;")); toInject.add(new VarInsnNode(ASTORE, 8)); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new InsnNode(ICONST_1)); toInject.add(new FieldInsnNode(PUTFIELD, "dc", "k", "I")); 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("sq") && ((MethodInsnNode) m.instructions.get(index)).name.equals("<init>")) { while (m.instructions.get(index).getType() != AbstractInsnNode.FIELD_INSN || m.instructions.get(index).getOpcode() != PUTFIELD || !((FieldInsnNode) m.instructions.get(index)).owner.equals("dc") || !((FieldInsnNode) m.instructions.get(index)).name.equals("k")) { index++; } while (m.instructions.get(index).getType() != AbstractInsnNode.TYPE_INSN || !((TypeInsnNode) m.instructions.get(index)).desc.equals("sq")) { m.instructions.remove(m.instructions.get(index)); index--; ok = true; } if (ok) { m.instructions.remove(m.instructions.get(index)); m.instructions.insertBefore(m.instructions.get(index), toInject); } 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:/NetClientHandler.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[] transformGuiSelectWorld(byte[] bytes) { /*try/*from ww w .jav a2 s . c om*/ { FileOutputStream fos = new FileOutputStream("d:/GuiSelectWorld.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching GuiSelectWorld.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("A_") && m.desc.equals("()V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "awe", "d", "Z")); 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); ok = true; break; } } } else if (m.name.equals("e") && m.desc.equals("(I)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("ats") && ((MethodInsnNode) m.instructions.get(index)).name.equals("a") && ((MethodInsnNode) m.instructions.get(index)).desc .equals("(Ljava/lang/String;Ljava/lang/String;Lacc;)V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 2)); toInject.add(new VarInsnNode(ALOAD, 3)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BClient", "loadWorld", "(Lawb;Ljava/lang/String;Ljava/lang/String;)V")); m.instructions.insert(m.instructions.get(index), toInject); while (m.instructions.get(index).getType() != AbstractInsnNode.JUMP_INSN) { m.instructions.remove(m.instructions.get(index)); index--; } 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:/GuiSelectWorld.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[] transformGuiCreateWorld(byte[] bytes) { /*try// w w w . j a va2 s .c o m { FileOutputStream fos = new FileOutputStream("d:/GuiCreateWorld.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching GuiCreateWorld.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("A_") && m.desc.equals("()V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "auy", "v", "Z")); 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); ok = true; break; } } } else if (m.name.equals("a") && m.desc.equals("(Lauq;)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("ats") && ((MethodInsnNode) m.instructions.get(index)).name.equals("a") && ((MethodInsnNode) m.instructions.get(index)).desc .equals("(Ljava/lang/String;Ljava/lang/String;Lacc;)V")) { m.instructions.remove(m.instructions.get(index)); InsnList toInject = new InsnList(); toInject.add(new InsnNode(ICONST_1)); toInject.add(new MethodInsnNode(INVOKESPECIAL, "blockphysics/BGui", "<init>", "(Lawb;Ljava/lang/String;Ljava/lang/String;Lacc;Z)V")); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "ats", "a", "(Lawb;)V")); m.instructions.insertBefore(m.instructions.get(index), toInject); while (m.instructions.get(index).getOpcode() != GETFIELD || m.instructions.get(index).getType() != AbstractInsnNode.FIELD_INSN || !((FieldInsnNode) m.instructions.get(index)).owner.equals("auy") || !((FieldInsnNode) m.instructions.get(index)).name.equals("f") || !((FieldInsnNode) m.instructions.get(index)).desc.equals("Lats;")) { index--; } toInject = new InsnList(); toInject.add(new TypeInsnNode(NEW, "blockphysics/BGui")); toInject.add(new InsnNode(DUP)); toInject.add(new VarInsnNode(ALOAD, 0)); m.instructions.insert(m.instructions.get(index), 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:/GuiCreateWorld.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[] transformBlock(byte[] bytes) { /*try//from w w w. j a v a 2 s .c o m { FileOutputStream fos = new FileOutputStream("d:/Block.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching Block.class ..................."); boolean ok2 = false; boolean ok3 = false; boolean ok4 = false; boolean ok5 = false; boolean ok6 = false; boolean ok7 = false; boolean ok8 = 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("g") && m.desc.equals("(Labv;IIII)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(ILOAD, 5)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "aqw", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onBlockDestroyedByPlayer", "(Labv;IIIII)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); ok2 = true; break; } } } else if (m.name.equals("a") && m.desc.equals("(Labv;IIII)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, "aqw", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onNeighborBlockChange", "(Labv;IIII)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); ok3 = true; break; } } } else if (m.name.equals("b") && 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, "aqw", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onNeighborBlockChange", "(Labv;IIII)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); ok4 = true; break; } } } else 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, "aqw", "cF", "I")); toInject.add(new VarInsnNode(ALOAD, 5)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onEntityCollidedWithBlock", "(Labv;IIIILnm;)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); ok5 = true; break; } } } else if (m.name.equals("k") && m.desc.equals("(Labv;IIII)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, "aqw", "cF", "I")); toInject.add(new VarInsnNode(ILOAD, 5)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onPostBlockPlaced", "(Labv;IIIII)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); ok6 = true; break; } } } else if (m.name.equals("a") && m.desc.equals("(Labv;IIILnm;F)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, "aqw", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onNeighborBlockChange", "(Labv;IIII)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; } } } } FieldNode f; Iterator<FieldNode> fields = classNode.fields.iterator(); while (fields.hasNext()) { f = fields.next(); if (f.name.equals("blockFlammability") && f.desc.equals("[I")) { f.access = ACC_PUBLIC + ACC_STATIC; ok8 = true; break; } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); if (ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8) System.out.println("OK"); else System.out.println("Failed." + ok2 + ok3 + ok4 + ok5 + ok6 + ok7 + ok8); /*try { FileOutputStream fos = new FileOutputStream("d:/Block.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[] transformBlockRailBase(byte[] bytes) { /*try/*from w w w . j av a 2s. c o m*/ { FileOutputStream fos = new FileOutputStream("d:/BlockRailBase.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockRailBase.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;IIII)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, "amv", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onNeighborBlockChange", "(Labv;IIII)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); 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:/BlockRailBase.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[] transformBlockPistonBase(byte[] bytes) { /*try//from w w w .jav a 2 s.co m { FileOutputStream fos = new FileOutputStream("d:/BlockPistonBase.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockPistonBase.class ........."); boolean ok = false, ok2 = false, ok3 = 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;IIII)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, "asq", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onNeighborBlockChange", "(Labv;IIII)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); ok = true; break; } } } else if (m.name.equals("k") && m.desc.equals("(Labv;III)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 VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "asq", "a", "Z")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "updatePistonState", "(Labv;IIILasq;Z)V")); toInject.add(new InsnNode(RETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok2 = true; } else if (m.name.equals("b") && m.desc.equals("(Labv;IIIII)Z")) { 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(ILOAD, 5)); toInject.add(new VarInsnNode(ILOAD, 6)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "asq", "a", "Z")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onBlockPistonEventReceived", "(Labv;IIIIILasq;Z)Z")); toInject.add(new InsnNode(IRETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok3 = true; } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); if (ok && ok2 && ok3) System.out.println("OK"); else System.out.println("Failed." + ok + ok2 + ok3); /*try { FileOutputStream fos = new FileOutputStream("d:/BlockPistonBase.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[] transformBlockSand(byte[] bytes) { /*try/*from w w w.j ava 2 s . c o m*/ { FileOutputStream fos = new FileOutputStream("d:/BlockSand.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockSand.class ..............."); boolean ok = false; boolean ok2 = false; boolean ok3 = false; boolean ok4 = 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;IIII)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, "aop", "cF", "I")); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "onNeighborBlockChange", "(Labv;IIII)V")); toInject.add(new InsnNode(RETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok = true; } else if (m.name.equals("a") && m.desc.equals("(Labv;IIILjava/util/Random;)V")) { m.instructions.clear(); m.localVariables.clear(); m.instructions.insert(new InsnNode(RETURN)); ok2 = true; } else if (m.name.equals("k") && m.desc.equals("(Labv;III)V")) { m.instructions.clear(); m.localVariables.clear(); m.instructions.insert(new InsnNode(RETURN)); ok3 = true; } else if (m.name.equals("a_") && m.desc.equals("(Labv;III)Z")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ILOAD, 1)); toInject.add(new VarInsnNode(ILOAD, 2)); toInject.add(new VarInsnNode(ILOAD, 3)); toInject.add(new InsnNode(ICONST_0)); toInject.add( new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "canMoveTo", "(Labv;IIII)Z")); toInject.add(new InsnNode(IRETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok4 = true; } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); if (ok && ok2 && ok3 && ok4) System.out.println("OK"); else System.out.println("Failed." + ok + ok2 + ok3 + ok4); /*try { FileOutputStream fos = new FileOutputStream("d:/BlockSand.class"); fos.write(cw.toByteArray()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return cw.toByteArray(); }