List of usage examples for org.objectweb.asm.tree InsnList InsnList
InsnList
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformBlockRailBase(byte[] bytes) { /*try/*from w w w . ja v a 2 s . c om*/ { 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 .j a v a 2 s .c o 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 ww w . j ava2 s .co 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(); }
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformBlockRedstoneLight(byte[] bytes) { /*try// ww w. j a v a2 s . c o m { FileOutputStream fos = new FileOutputStream("d:/BlockRedstoneLight.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockRedstoneLight.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, "aqa", "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:/BlockRedstoneLight.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[] transformBlockTNT(byte[] bytes) { /*try/*from w w w . ja va 2 s.c o m*/ { FileOutputStream fos = new FileOutputStream("d:/BlockTNT.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockTNT.class ................"); boolean ok = false; boolean ok2 = false; ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); MethodNode m; Iterator<MethodNode> methods = classNode.methods.iterator(); while (methods.hasNext()) { m = methods.next(); if (m.name.equals("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, "arb", "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("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, "arb", "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; } } } } 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:/BlockTNT.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[] transformBlockFarmland(byte[] bytes) { /*try// ww w .ja v a 2s. co m { FileOutputStream fos = new FileOutputStream("d:/BlockFarmland.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockFarmland.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;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, "aoc", "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:/BlockFarmland.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[] transformBlockDragonEgg(byte[] bytes) { /*try/*from w ww .java 2s . c o m*/ { FileOutputStream fos = new FileOutputStream("d:/BlockDragonEgg.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ System.out.print("[BlockPhysics] Patching BlockDragonEgg.class .........."); boolean ok = false, ok2 = false, ok3 = 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("(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, "any", "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("m") && m.desc.equals("(Labv;III)V")) { InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new VarInsnNode(ILOAD, 6)); toInject.add(new VarInsnNode(ILOAD, 7)); toInject.add(new VarInsnNode(ILOAD, 8)); toInject.add( new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "notifyMove", "(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("abv") && ((MethodInsnNode) m.instructions.get(index)).name.equals("i") && ((MethodInsnNode) m.instructions.get(index)).desc.equals("(III)Z")) { if (m.instructions.get(index + 1).getOpcode() == POP) { m.instructions.insert(m.instructions.get(index + 1), toInject); } else m.instructions.insert(m.instructions.get(index), toInject); ok4 = true; break; } } } } 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:/BlockDragonEgg.class"); fos.write(cw.toByteArray()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return cw.toByteArray(); }
From source file:cl.inria.stiq.instrumenter.BCIUtils.java
License:Open Source License
private static InsnList cloneInstructions(ClonerMap aMap, InsnList aList) { InsnList theInsnListClone = new InsnList(); AbstractInsnNode theNode = aList.getFirst(); while (theNode != null) { AbstractInsnNode theClone = theNode.clone(aMap); if (theClone instanceof LabelNode) { LabelNode theLabelNode = (LabelNode) theClone; }//from w ww . j a v a2s . c om theInsnListClone.add(theClone); theNode = theNode.getNext(); } return theInsnListClone; }
From source file:com.android.builder.testing.MockableJarGenerator.java
License:Apache License
private static InsnList throwExceptionsList(MethodNode methodNode, ClassNode classNode) { try {// ww w. j a v a2 s. co m String runtimeException = Type.getInternalName(RuntimeException.class); Constructor<RuntimeException> constructor = RuntimeException.class.getConstructor(String.class); InsnList instructions = new InsnList(); instructions.add(new TypeInsnNode(Opcodes.NEW, runtimeException)); instructions.add(new InsnNode(Opcodes.DUP)); String className = classNode.name.replace('/', '.'); instructions.add(new LdcInsnNode("Method " + methodNode.name + " in " + className + " not mocked. " + "See http://g.co/androidstudio/not-mocked for details.")); instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, runtimeException, CONSTRUCTOR, Type.getType(constructor).getDescriptor(), false)); instructions.add(new InsnNode(Opcodes.ATHROW)); return instructions; } catch (NoSuchMethodException e) { throw new RuntimeException(e); } }
From source file:com.builtbroken.mc.patch.ClassTransformer.java
/** Fixes {@link net.minecraft.tileentity.TileEntityChest#invalidate()} causing inf loops on chunk edges */ private void injectInvalidateEdit(ClassNode cn) { final MethodNode method = ASMUtility.getMethod(cn, "invalidate", "func_145843_s"); if (method != null) { //Create method call final InsnList nodeAdd = new InsnList(); nodeAdd.add(new VarInsnNode(ALOAD, 0)); nodeAdd.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, "chestInvalidate", "(Lnet/minecraft/tileentity/TileEntityChest;)V", false)); //Inject method call at top of method ListIterator<AbstractInsnNode> it = method.instructions.iterator(); MethodInsnNode checkForAdjacentChests = null; while (it.hasNext()) { AbstractInsnNode node = it.next(); if (node instanceof MethodInsnNode) { if (((MethodInsnNode) node).name.equals("checkForAdjacentChests")) { checkForAdjacentChests = (MethodInsnNode) node; }/*from ww w . j av a 2s .co m*/ } } if (checkForAdjacentChests != null) { //Inject replacement method.instructions.insertBefore(method.instructions.get(method.instructions.size() - 1), nodeAdd); //Remove broken code method.instructions.remove(checkForAdjacentChests); } } else { CoreMod.logger.error("Failed to find 'public void invalidate()' in TileEntityChest.class"); } }