java-bytecode-asm

Invalid Entry Compressed Size

北城余情 提交于 2019-12-05 07:03:33
I'm using a bytecode library known as ASM to alter classfiles, then I want to write each classfile back into a jar file rather than a folder filled with class files. I do this by running this code: My problem occurs when a ZipException is throw for not being the expected size, i.e. java.util.zip.ZipException: invalid entry compressed size (expected 695 but got 693 bytes) at java.util.zip.ZipOutputStream.closeEntry(Unknown Source) at org.steinburg.client.accessor.Accessor.accessJar(Accessor.java:64) at org.steinburg.client.accessor.Accessor.<init>(Accessor.java:41) at Loader.main(Loader.java:5)

Implementing abstract methods at runtime?

别来无恙 提交于 2019-12-04 06:21:14
Let's say I have an abstract class: abstract class Foo extends Bar { public abstract int foo(); } that I want to extend at runtime to create a Class object. The hope would be that I could have a dynamically generated class: class FooImpl extends Foo { @Override public int foo() { return 5; } } that would be represented by a Class object and that I could then use reflection to create new instances of. The key is that I would like to decide the return value of the method foo() at runtime. My thought is to use ASM to create the bytecode for the class and then use reflection on a ClassLoader

Is “final” final at runtime?

独自空忆成欢 提交于 2019-12-03 23:44:10
I've been toying with ASM , and I believe I succeeded in adding the final modifier to an instance field of a class; however I then proceeded to instantiate said class and invoke a setter on it, which successfully changed the value of the now-final field. Am I doing something wrong with my bytecode changes, or is final enforced only by the Java compiler? Update: (31 Jul) Here's some code for you. The main parts are a simple POJO with a private int x and private final int y , the MakeFieldsFinalClassAdapter, which makes every field it visits final unless it already is, and the

Generating methods with generic types with Asm bytecode generator (ClassWriter)

时光毁灭记忆、已成空白 提交于 2019-12-03 11:52:32
Defining simple getters and setters is easy using Asm (and fortunately it is even explained in their FAQ). But one thing that is not mentioned, and for which I have been unable to find documentation, is how to implement these using generic type information. I am actually able to determine generic type information itself quite easily (since code will take existing fields and/or methods and full generic type handling and resolution exists). I just need to generate generics version for types that have generic type included. I hope this is something as easy as modifying signature Asm ClassWriter

Remapper variables during bytecode method inlining by ASM

一世执手 提交于 2019-12-03 06:48:01
I am doing an online bytecode method inlining optimization using ASM. My changes are based on the example 3.2.6 Inline Method ( http://asm.ow2.org/current/asm-transformations.pdf ). The test example (inline callee's calculate(int,int) at Caller::test) is: public class Caller { final Callee _callee; public Caller(Callee callee){ _callee = callee; } public static void main(String[] args) { new Caller(new Callee("xu", "shijie")).test(5, 100); } public void test(int a, int b){ int t = a; int p = b; int r = t+p-_callee.calculate(a, b); int m = t-p; System.out.println(t); } } public class Callee {

ASM 5.0.3 With Java 1.8 incorrect maxStack with Java.lang.VerifyError: Operand stack overflow

China☆狼群 提交于 2019-12-02 18:24:43
问题 Using ASM 5.0.3 (with Java 1.8.0_65 & Tomcat 8.0.30) , Visiting one of the JSP (date.jsp) Method - _JSP(_jspService) , getting below exception javax.servlet.ServletException: java.lang.VerifyError: Operand stack overflow Exception Details: Location: org/apache/jsp/jsp/dates/date_jsp._jspService(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V @0: aload_1 Reason: Exceeded max stack size. Current Frame: bci: @0 flags: { } locals: { 'org/apache/jsp/jsp/dates/date

How to change static variable value using ASM?

那年仲夏 提交于 2019-12-02 12:25:13
I started learning Java Agent few days ago. But documentation is not very good and beginners like me struggling to understand the basics. I created a basic multiplier class and export it to runnable jar using eclipse. Here is the code snippet. Main jar file: public class Multiplier { public static void main(String[] args) { int x = 10; int y = 25; int z = x * y; System.out.println("Multiply of x*y = " + z); } } Bytecode for above class Now I want to manipulate the value of x from an agent. I tried to create the Agent class like this Agent: package myagent; import org.objectweb.asm.*; import

ASM 5.0.3 With Java 1.8 incorrect maxStack with Java.lang.VerifyError: Operand stack overflow

删除回忆录丶 提交于 2019-12-02 11:31:16
Using ASM 5.0.3 (with Java 1.8.0_65 & Tomcat 8.0.30) , Visiting one of the JSP (date.jsp) Method - _JSP(_jspService) , getting below exception javax.servlet.ServletException: java.lang.VerifyError: Operand stack overflow Exception Details: Location: org/apache/jsp/jsp/dates/date_jsp._jspService(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V @0: aload_1 Reason: Exceeded max stack size. Current Frame: bci: @0 flags: { } locals: { 'org/apache/jsp/jsp/dates/date_jsp', 'javax/servlet/http/HttpServletRequest', 'javax/servlet/http/HttpServletResponse' } stack: { }

How to redefine an already defined class on Java

♀尐吖头ヾ 提交于 2019-12-02 09:21:58
I want the modulated ASM class to be applied when calling newTarget.a () and newTarget.b () in the code below so that it looks like this How can I get the following result when I call newTarget.a () and newTarget.b () with Modified ASM Class applied? Code: package asm; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import static org.objectweb.asm.Opcodes.ASM5; public class Main { public static void main(String[] args) throws Exception { Target target =

Wrong Stack Size calculated by ASM library

百般思念 提交于 2019-12-02 06:02:05
I generate bytecodes using ASM library and 'Max stack size' for a method is left to be calculated automatically. During runtime,i found this value (max stack size) is not correct. My source code is: ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); .... MethodType initType = MethodType.methodType(void.class, clsList); mv = cw.visitMethod(ACC_PUBLIC, "<init>", initType.toMethodDescriptorString(), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/invoke/BaseTemplate", "<init>", "()V", false); for(int i=0; i< list.size(); i++){ mv