List of usage examples for org.objectweb.asm.tree InsnNode InsnNode
public InsnNode(final int opcode)
From source file:Test1.java
License:Apache License
private static void implementInterface(ClassNode cn) throws Exception { // MethodNode fromMethod = new MethodNode(ACC_PUBLIC, "fromData", // "(Ljava/io/DataInput;)V", null, new String[] { // "java/io/IOException", // "java/lang/ClassNotFoundException" }); // mv = cw.visitMethod(ACC_PUBLIC, "toData", "(Ljava/io/DataOutput;)V", // null, new String[] { "java/io/IOException" }); MethodNode toMethod = new MethodNode(ACC_PUBLIC, "toData", "(Ljava/io/DataOutput;)V", null, new String[] { "java/io/IOException" }); InsnList instToMethod = toMethod.instructions; for (int i = 0; i < cn.fields.size(); i++) { FieldNode fn = (FieldNode) cn.fields.get(i); toMethod(cn.name, fn, instToMethod); }//from ww w .ja va2s .c om instToMethod.add(new InsnNode(RETURN)); cn.methods.add(toMethod); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cn.accept(cw); byte[] bt = cw.toByteArray(); ClassReader cr = new ClassReader(bt); CheckClassAdapter ca = new CheckClassAdapter(cw); FileOutputStream fo = new FileOutputStream("d:/x1.log"); PrintWriter pw = new PrintWriter(fo); ca.verify(cr, true, pw); ByteArrayClassLoader bacl = new ByteArrayClassLoader(bt); Class cls = bacl.loadClass("ynd.test.Ac01"); DataSerializable di = (DataSerializable) cls.newInstance(); di.toData(null); }
From source file:appeng.transformer.asm.ASMTweaker.java
License:Open Source License
@Nullable @Override/*from ww w.j ava 2 s . c o m*/ public byte[] transform(String name, String transformedName, byte[] basicClass) { if (basicClass == null) { return null; } try { if (transformedName != null && this.privateToPublicMethods.containsKey(transformedName)) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); for (PublicLine set : this.privateToPublicMethods.get(transformedName)) { this.makePublic(classNode, set); } // CALL VIRTUAL! if (transformedName.equals("net.minecraft.client.gui.inventory.GuiContainer")) { for (MethodNode mn : classNode.methods) { if (mn.name.equals("func_146977_a") || (mn.name.equals("a") && mn.desc.equals("(Lzk;)V"))) { MethodNode newNode = new MethodNode(Opcodes.ACC_PUBLIC, "func_146977_a_original", mn.desc, mn.signature, EXCEPTIONS); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.name, mn.name, mn.desc, false)); newNode.instructions.add(new InsnNode(Opcodes.RETURN)); this.log(newNode.name + newNode.desc + " - New Method"); classNode.methods.add(newNode); break; } } for (MethodNode mn : classNode.methods) { if (mn.name.equals("func_73863_a") || mn.name.equals("drawScreen") || (mn.name.equals("a") && mn.desc.equals("(IIF)V"))) { Iterator<AbstractInsnNode> i = mn.instructions.iterator(); while (i.hasNext()) { AbstractInsnNode in = i.next(); if (in.getOpcode() == Opcodes.INVOKESPECIAL) { MethodInsnNode n = (MethodInsnNode) in; if (n.name.equals("func_146977_a") || (n.name.equals("a") && n.desc.equals("(Lzk;)V"))) { this.log(n.name + n.desc + " - Invoke Virtual"); mn.instructions.insertBefore(n, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, n.owner, n.name, n.desc, false)); mn.instructions.remove(in); break; } } } } } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); } } catch (Throwable ignored) { } return basicClass; }
From source file:bitmmo.PatternElementTest.java
License:Open Source License
@Test public void testInstructionElement() { InsnNode correct = new InsnNode(DUP); InsnNode incorrect = new InsnNode(ISUB); InstructionElement e = new InstructionElement(DUP); assertEquals(true, e.matches(correct)); assertEquals(false, e.matches(incorrect)); }
From source file:bitmmo.PatternTest.java
License:Open Source License
@Test public void testContains() { InsnList list = new InsnList(); // this is just junk code // its contents is irrelevant list.add(new InsnNode(DUP)); list.add(new InsnNode(ISUB)); list.add(new InsnNode(IMUL)); list.add(new MethodInsnNode(PUTFIELD, null, null, null, false)); list.add(new InsnNode(IADD)); Pattern correct = new PatternBuilder().add(new InstructionElement(ISUB), new InstructionElement(IMUL), new MethodElement(new MethodInsnNode(PUTFIELD, null, null, null, false))).build(); Pattern incorrect = new PatternBuilder().add(new InstructionElement(ISUB), new InstructionElement(DUP)) .build();//ww w .j a v a 2 s . c o m assertEquals(true, correct.contains(list)); assertEquals(false, incorrect.contains(list)); }
From source file:bitmmo.PatternTest.java
License:Open Source License
@Test public void testOffset() { InsnList list = new InsnList(); // this is just junk code // its contents is irrelevant list.add(new InsnNode(DUP)); list.add(new InsnNode(ISUB)); list.add(new InsnNode(IMUL)); list.add(new MethodInsnNode(PUTFIELD, null, null, null, false)); list.add(new InsnNode(IADD)); Pattern correct = new PatternBuilder().add(new InstructionElement(ISUB), new InstructionElement(IMUL)) .build();//from w ww . j a v a 2 s . c o m Pattern correct2 = new PatternBuilder().add(new InstructionElement(IMUL), new MethodElement(new MethodInsnNode(PUTFIELD, null, null, null, false))).build(); assertEquals(1, correct.getOffset(list)); assertEquals(2, correct2.getOffset(list)); }
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformTileEntityPiston(byte[] bytes) { /*try//from w w w. ja va 2s. c om { 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[] transformBlockPhysics(byte[] bytes) { /*try//from www.j ava 2 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[] transformBlockWeb(byte[] bytes) { /*try//from w w w . java 2 s .co m { 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(); }
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformWorld(byte[] bytes) { /*try//from ww w. j a v a 2s . c o 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[] transformExplosion(byte[] bytes) { /*try/*from w w w.j av a 2 s . c om*/ { FileOutputStream fos = new FileOutputStream("d:/Explosion.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching Explosion.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("<init>") && m.desc.equals("(Labv;Lnm;DDDF)V"))) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "abq", "impact", "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("()V"))) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "abq", "k", "Labv;")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "doExplosionA", "(Labv;Labq;)V")); toInject.add(new InsnNode(RETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok2 = true; } else if (m.name.equals("a") && m.desc.equals("(Z)V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "abq", "k", "Labv;")); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ILOAD, 1)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "doExplosionB", "(Labv;Labq;Z)V")); toInject.add(new InsnNode(RETURN)); m.instructions.clear(); m.localVariables.clear(); m.instructions.add(toInject); ok3 = true; } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); FieldVisitor fv; fv = cw.visitField(ACC_PUBLIC, "impact", "Z", null, null); fv.visitEnd(); cw.visitEnd(); if (ok && ok2 && ok3) System.out.println("OK"); else System.out.println("Failed." + ok + ok2 + ok3); /*try { FileOutputStream fos = new FileOutputStream("d:/Explosion.class"); fos.write(cw.toByteArray()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return cw.toByteArray(); }