bytecode-manipulation

get CtClass using specific ClassLoader

ぐ巨炮叔叔 提交于 2021-02-10 18:44:44
问题 I have a class structure like this: package com.mydomain.myproject; public class Outer{ public class Inner{ //some code } } Now, I can get a CtClass of the inner class using: ClassPool pool=ClassPool.getDefault(); CtClass innerCt=pool.getCtClass("com.mydomain.myproject.Outer$Inner"); The problem occurs if those classes are loaded by a special ClassLoader . ClassPool#getCtClass fails because the ClassLoader it uses doesn't know of the class. I get the following exception: javassist

get CtClass using specific ClassLoader

纵饮孤独 提交于 2021-02-10 18:41:10
问题 I have a class structure like this: package com.mydomain.myproject; public class Outer{ public class Inner{ //some code } } Now, I can get a CtClass of the inner class using: ClassPool pool=ClassPool.getDefault(); CtClass innerCt=pool.getCtClass("com.mydomain.myproject.Outer$Inner"); The problem occurs if those classes are loaded by a special ClassLoader . ClassPool#getCtClass fails because the ClassLoader it uses doesn't know of the class. I get the following exception: javassist

Java Adding field and method to compiled class and reload using class loader

牧云@^-^@ 提交于 2020-06-11 11:43:57
问题 I would like to add field along with its getter/setter in compiled Java classes which is loaded in a Spring boot application. I was able to modify the class using JavaAssist and ASM. But the problem is it is not letting me reload the class after modification, since this is already been loaded. I tried to write a class extending java.lang.ClassLoader but custom classloader is not getting called. Also, I checked java's Instrumentation API which clearly states The retransformation may change

Java Adding field and method to compiled class and reload using class loader

那年仲夏 提交于 2020-06-11 11:43:09
问题 I would like to add field along with its getter/setter in compiled Java classes which is loaded in a Spring boot application. I was able to modify the class using JavaAssist and ASM. But the problem is it is not letting me reload the class after modification, since this is already been loaded. I tried to write a class extending java.lang.ClassLoader but custom classloader is not getting called. Also, I checked java's Instrumentation API which clearly states The retransformation may change

How to create a dynamic proxy using ByteBuddy

▼魔方 西西 提交于 2020-02-22 06:48:30
问题 In Java it is possible to create dynamic proxies using an implementation of InvocationHandler . Despite JVM optimizations, using reflection will always have some overhead invoking a method. To try to solve this problem, I tried to use ByteBuddy to create the proxy classes at runtime, but the documentation didn't seem clear enough on this aspect. How do I create a MethodCallProxy in order to forward a method invocation to some class instance? Edit: To better clarify my problem, I am providing

How to create a dynamic proxy using ByteBuddy

点点圈 提交于 2020-02-22 06:47:57
问题 In Java it is possible to create dynamic proxies using an implementation of InvocationHandler . Despite JVM optimizations, using reflection will always have some overhead invoking a method. To try to solve this problem, I tried to use ByteBuddy to create the proxy classes at runtime, but the documentation didn't seem clear enough on this aspect. How do I create a MethodCallProxy in order to forward a method invocation to some class instance? Edit: To better clarify my problem, I am providing

unexpected instructions and parameters for invokevirtual in the inlined method body

两盒软妹~` 提交于 2020-01-11 11:07:59
问题 I followed the sample code in the "3.2.6 Inline Method“ in the http://asm.ow2.org/current/asm-transformations.pdf, to inline a MethodNode to a call site. My problem is that there are some unexpected instructions shown in the generated bytecode after inlining (these bytecodes are inconsistent to my code), and the problem only exists when an ifeq is after inlineed method body and the variable on the stack is loaded by xLoad. I still have not found the root cause for the issue. Now i am start to

ASM: outputting java bytecode and opcode

丶灬走出姿态 提交于 2020-01-11 07:07:26
问题 I am trying to write a program that takes a .class file and collects all the methods of the .class file as well as the contents of each method. Here is my code public class ClassReaderTest1 { public static void main(String[] args) throws Exception{ InputStream in = new FileInputStream("*.class"); ClassReader reader = new ClassReader(in); ClassNode classNode = new ClassNode(); reader.accept(classNode,0); @SuppressWarnings("unchecked") final List<MethodNode> methods = classNode.methods; for

Can I instrument outgoing method/constructor calls with ByteBuddy?

℡╲_俬逩灬. 提交于 2020-01-07 04:00:51
问题 I have a project where I was using Javassist to log outgoing method/constructor calls with code like this: CtMethod cm = ... ; cm.instrument( new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { if (m.getClassName().equals("Point") && m.getMethodName().equals("move")) m.replace("{ $1 = 0; $_ = $proceed($$); }"); } }); which assigns '0' to the first argument of the called method and then proceeds with the original call, that is, if cm represents the method