List of usage examples for org.objectweb.asm.tree AbstractInsnNode getNext
public AbstractInsnNode getNext()
From source file:com.friz.instruction.utility.InstructionUtil.java
License:Open Source License
/** * Finds the next non-psuedo node following the specified node. * /*w ww. j a v a2 s. c om*/ * @param node * The node. * @return The next non-psuedo node, or {@code null} if the end of the * instruction list is reached. */ public static AbstractInsnNode nextNonPsuedoNode(AbstractInsnNode node) { while ((node = node.getNext()) != null && node.getOpcode() == -1) ; return node; }
From source file:com.friz.instruction.utility.InstructionUtil.java
License:Open Source License
/** * Finds the next psuedo node following the specified node. * /*from w w w . j a v a 2 s .com*/ * @param node * The node. * @return The next psuedo node, or {@code null} if the end of the * instruction list is reached. */ public static AbstractInsnNode nextPsuedoNode(AbstractInsnNode node) { while ((node = node.getNext()) != null && node.getOpcode() != -1) ; return node; }
From source file:com.github.fge.grappa.transform.process.SuperCallRewriter.java
License:Apache License
@Override public void process(@Nonnull ParserClassNode classNode, @Nonnull RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); InsnList instructions = method.instructions; AbstractInsnNode insn = instructions.getFirst(); while (insn.getOpcode() != ARETURN) { if (insn.getOpcode() == INVOKESPECIAL) process(classNode, method, (MethodInsnNode) insn); insn = insn.getNext(); }/*w w w. j a v a2 s. co m*/ }
From source file:com.github.fge.grappa.transform.process.UnusedLabelsRemover.java
License:Apache License
@Override public void process(@Nonnull ParserClassNode classNode, @Nonnull RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); AbstractInsnNode current = method.instructions.getFirst(); AbstractInsnNode next;/*w w w. j av a 2 s .c o m*/ boolean doRemove; while (current != null) { next = current.getNext(); //noinspection SuspiciousMethodCalls doRemove = current.getType() == AbstractInsnNode.LABEL && !method.getUsedLabels().contains(current); if (doRemove) method.instructions.remove(current); current = next; } }
From source file:com.google.devtools.build.android.desugar.DefaultMethodClassFixerTest.java
License:Open Source License
private void checkClinitForDefaultInterfaceMethodWithStaticInitializerTestInterfaceSetOneC( byte[] classContent) { ClassReader reader = new ClassReader(classContent); reader.accept(new ClassVisitor(Opcodes.ASM5) { class ClinitMethod extends MethodNode { public ClinitMethod(int access, String name, String desc, String signature, String[] exceptions) { super(Opcodes.ASM5, access, name, desc, signature, exceptions); }//from w w w . jav a 2 s. c om } private ClinitMethod clinit; @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if ("<clinit>".equals(name)) { assertThat(clinit).isNull(); clinit = new ClinitMethod(access, name, desc, signature, exceptions); return clinit; } return super.visitMethod(access, name, desc, signature, exceptions); } @Override public void visitEnd() { assertThat(clinit).isNotNull(); assertThat(clinit.instructions.size()).isEqualTo(3); AbstractInsnNode instruction = clinit.instructions.getFirst(); { assertThat(instruction).isInstanceOf(MethodInsnNode.class); MethodInsnNode field = (MethodInsnNode) instruction; assertThat(field.owner).isEqualTo("com/google/devtools/build/android/desugar/testdata/java8/" + "DefaultInterfaceMethodWithStaticInitializer" + "$TestInterfaceSetOne$I1$$CC"); assertThat(field.name) .isEqualTo(InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_NAME); assertThat(field.desc) .isEqualTo(InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_DESC); } { instruction = instruction.getNext(); assertThat(instruction).isInstanceOf(MethodInsnNode.class); MethodInsnNode field = (MethodInsnNode) instruction; assertThat(field.owner).isEqualTo("com/google/devtools/build/android/desugar/testdata/java8/" + "DefaultInterfaceMethodWithStaticInitializer" + "$TestInterfaceSetOne$I2$$CC"); assertThat(field.name) .isEqualTo(InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_NAME); assertThat(field.desc) .isEqualTo(InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_DESC); } { instruction = instruction.getNext(); assertThat(instruction).isInstanceOf(InsnNode.class); assertThat(instruction.getOpcode()).isEqualTo(Opcodes.RETURN); } } }, 0); }
From source file:com.googlecode.dex2jar.tools.DecryptStringCmd.java
License:Apache License
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();/*from w w w. j av a 2s . c om*/ return; } final Path jar = new File(remainingArgs[0]).toPath(); if (!Files.exists(jar)) { System.err.println(jar + " is not exists"); return; } if (methodName == null || methodOwner == null) { System.err.println("Please set --decrypt-method-owner and --decrypt-method-name"); return; } if (output == null) { if (Files.isDirectory(jar)) { output = new File(jar.getFileName() + "-decrypted.jar").toPath(); } else { output = new File(getBaseName(jar.getFileName().toString()) + "-decrypted.jar").toPath(); } } if (Files.exists(output) && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); return; } System.err.println(jar + " -> " + output); List<String> list = new ArrayList<String>(); if (classpath != null) { list.addAll(Arrays.asList(classpath.split(";|:"))); } list.add(jar.toAbsolutePath().toString()); URL[] urls = new URL[list.size()]; for (int i = 0; i < list.size(); i++) { urls[i] = new File(list.get(i)).toURI().toURL(); } final Method jmethod; try { URLClassLoader cl = new URLClassLoader(urls); jmethod = cl.loadClass(methodOwner).getMethod(methodName, String.class); jmethod.setAccessible(true); } catch (Exception ex) { System.err.println("can't load method: String " + methodOwner + "." + methodName + "(String), message:" + ex.getMessage()); return; } final String methodOwnerInternalType = this.methodOwner.replace('.', '/'); try (FileSystem outputFileSystem = createZip(output)) { final Path outputBase = outputFileSystem.getPath("/"); walkJarOrDir(jar, new FileVisitorX() { @Override public void visitFile(Path file, Path relative) throws IOException { if (file.getFileName().toString().endsWith(".class")) { ClassReader cr = new ClassReader(Files.readAllBytes(file)); ClassNode cn = new ClassNode(); cr.accept(cn, 0); for (Object m0 : cn.methods) { MethodNode m = (MethodNode) m0; if (m.instructions == null) { continue; } AbstractInsnNode p = m.instructions.getFirst(); while (p != null) { if (p.getOpcode() == Opcodes.LDC) { LdcInsnNode ldc = (LdcInsnNode) p; if (ldc.cst instanceof String) { String v = (String) ldc.cst; AbstractInsnNode q = p.getNext(); if (q.getOpcode() == Opcodes.INVOKESTATIC) { MethodInsnNode mn = (MethodInsnNode) q; if (mn.name.equals(methodName) && mn.desc.equals("(Ljava/lang/String;)Ljava/lang/String;") && mn.owner.equals(methodOwnerInternalType)) { try { Object newValue = jmethod.invoke(null, v); ldc.cst = newValue; } catch (Exception e) { // ignore } m.instructions.remove(q); } } } } p = p.getNext(); } } ClassWriter cw = new ClassWriter(0); cn.accept(cw); Files.write(outputBase.resolve(relative), cw.toByteArray()); } else { Files.copy(file, outputBase.resolve(relative)); } } }); } }
From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java
License:Open Source License
private void patchWorldServerTick(MethodNode method, boolean obfuscated) { Iterator<AbstractInsnNode> iter = method.instructions.iterator(); // Replace/*from w w w . j a v a 2 s. c om*/ // > this.worldInfo.setWorldTime(this.worldInfo.getWorldTime() + 1L); // To // > TimeTweaksManager.addTick(this.worldInfo); int index = 0; while (iter.hasNext()) { AbstractInsnNode currentNode = iter.next(); if (currentNode.getOpcode() == Opcodes.INVOKEVIRTUAL) { MethodInsnNode methodInsnNode = (MethodInsnNode) currentNode; if (WORLD_INFO_GET_WORLD_TIME.matchesNode(methodInsnNode, "()J", obfuscated) && currentNode.getNext().getOpcode() == Opcodes.LCONST_1) { // Found the call index = method.instructions.indexOf(currentNode) - 2; } } } if (index == 0) error("Could not find call in WorldServer.tick method"); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.insertBefore(method.instructions.get(index), new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager", "addTick", "(L" + WORLD_INFO.getPath(obfuscated) + ";)V")); }
From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java
License:Open Source License
private void patchWorldClientTick(MethodNode method, boolean obfuscated) { Iterator<AbstractInsnNode> iter = method.instructions.iterator(); // Replace// w w w.j a v a 2 s . com // > this.setWorldTime(this.getWorldTime() + 1L); // To // > TimeTweaksManager.addTick(this.provider); int index = 0; while (iter.hasNext()) { AbstractInsnNode currentNode = iter.next(); if (currentNode.getOpcode() == Opcodes.INVOKEVIRTUAL) { MethodInsnNode methodInsnNode = (MethodInsnNode) currentNode; if (WORLD_CLIENT_GET_WORLD_TIME.matchesNode(methodInsnNode, "()J", obfuscated) && currentNode.getNext().getOpcode() == Opcodes.LCONST_1) { index = method.instructions.indexOf(currentNode) - 1; } } } if (index == 0) error("Could not find call in WorldServer.tick method"); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.remove(method.instructions.get(index)); method.instructions.insertBefore(method.instructions.get(index), new FieldInsnNode(Opcodes.GETFIELD, WORLD.getPath(obfuscated), WORLD_PROVIDER.get(obfuscated), "L" + WORLD_PROVIDER_CLASS.getPath(obfuscated) + ";")); method.instructions.insert(method.instructions.get(index), new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager", "addTick", "(L" + WORLD_PROVIDER_CLASS.getPath(obfuscated) + ";)V")); }
From source file:com.lodgon.parboiled.transform.SuperCallRewriter.java
License:Apache License
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); InsnList instructions = method.instructions; AbstractInsnNode insn = instructions.getFirst(); while (insn.getOpcode() != ARETURN) { if (insn.getOpcode() == INVOKESPECIAL) { process(classNode, method, (MethodInsnNode) insn); }// ww w .java 2s . com insn = insn.getNext(); } }
From source file:com.lodgon.parboiled.transform.UnusedLabelsRemover.java
License:Apache License
@SuppressWarnings({ "SuspiciousMethodCalls" }) public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); AbstractInsnNode current = method.instructions.getFirst(); while (current != null) { AbstractInsnNode next = current.getNext(); if (current.getType() == AbstractInsnNode.LABEL && !method.getUsedLabels().contains(current)) { method.instructions.remove(current); }// w w w .j a v a 2s. co m current = next; } }