Questions tagged [java-bytecode-asm]

ASM is a Java library used for JVM bytecode manipulation and creation.

ASM is a Java bytecode manipulation and analysis framework. It provides a library to read, write, transform, and analyze compiled Java classes, directly in the binary form of byte arrays. Its API allows easy access to class items such as annotations, fields, and methods. Instructions in methods can be analyzed, removed, or inserted as necessary. Output classes can be saved into files, or loaded dynamically by a ClassLoader.

Website: http://asm.ow2.org/

Document: ASM 4.0 A Java bytecode engineering library

798 questions
12
votes
1 answer

Bytecode analysis in Java

I am working on a Bytecode analysis project, for which I am using ASM. Everything is going good, I am able to parse, get class and method informations successfully. But I am stuck in understanding bytecode representation for Generics. Here is the…
Pradeep Simha
  • 17,683
  • 18
  • 56
  • 107
12
votes
2 answers

Adding code to a Java class w/ Instrumentation: ASM or BCEL?

I am writing a game engine/library in which I have an event dispatcher class which dispatches events by calling listener methods of "registered" event handler classes. One can register an event handler/listener with the event dispatcher by calling…
user1299784
  • 2,019
  • 18
  • 30
11
votes
4 answers

ASM jar - Why my java project has a dependency on this?

I have a Java project and internally it is dependent on asm jar. Strangely, I don't even know why my project somehow is dependent on this library (might be brought in by maven as a transitive dependency)? Can anyone help me know why some one needs…
peakit
  • 28,597
  • 27
  • 63
  • 80
11
votes
3 answers

Injecting a Java method _before_ another method is called

I am using ASM and want to rewrite something like: someMethod().targetMethod(args...) to: someMethod().injectedMethod(arg).targetMethod(args...) The trouble is that I don't know what the method before is, I only know the target method (so finding…
David
  • 171
  • 10
10
votes
1 answer

JVM language interoperability

Recently I've been writing a compiler for a JVM programming language and I've realised a problem. I would like to access a Java method from my programming language and also allow a Java method to access a method in my language. The problem is…
10
votes
1 answer

How to debug a Java agent

At the moment there is possibility to run JVM with an agent: -javaagent:somejar.jar this way in order to run the Java agent I have wrote as an I have to put it into a jar. therefore it is limited in debugging. Is there a technique for debugging a…
user2850243
10
votes
1 answer

How to modify a Java bytecode using ASM 4.0

I am new to ASM framework. I have been working around this ASM framework for a week. I saw tutorials in net regarding parsing a class and Generating a .class file from scratch. But am unable to follow how to modify a existing class in ASM. I am…
Narayana
  • 363
  • 3
  • 14
10
votes
2 answers

Custom Programming Language(jar) in Android

Here is my situation, I have a Custom Programming Language that compile down into Java Byte Code. I have the jar and I am looking to use some of the classes in an Android Application. I need some advice on how to approach this. I can import some…
user2701224
  • 119
  • 2
10
votes
2 answers

Java method parameters values in ASM

I am trying to get the values of a Java program's method's parameters. I am using ASM to instrument the bytecode and getting these values. However, I'm running into some troubles. Here is the visitCode() method used to instrument the code. What it…
Adel
  • 441
  • 1
  • 5
  • 14
9
votes
2 answers

Adding try/catch block in bytecode through ASM

I am new to ASM and I want some help related to bytecode transformation. Question: I would like to add try/catch block for the entire method in bytecode through ASM and want to run the method with out using java -noverify option. I can able to add…
Farooq Rahman
  • 336
  • 3
  • 10
9
votes
1 answer

Finding the Bytecode Size of a Java Method

I am trying to figure out the bytecode size of a method because I want to be sure that it will be small enough to be inlined by compiler optimizations. I saw that the default max size for inlining methods is 35, so if the method is larger than that…
isapir
  • 21,295
  • 13
  • 115
  • 116
9
votes
2 answers

Java ASM Bytecode Modification-Changing method bodies

I have a method of a class in a jar whose body I want to exchange with my own. In this case I just want to have the method print out "GOT IT" to the console and return true; I am using the system loader to load the classes of the jar. I am using…
emist
  • 137
  • 1
  • 2
  • 8
8
votes
1 answer

How do I use Instrumentation.retransformClasses() correctly from within asm code?

I'm using the asm library to perform some Java bytecode modification - specifically to modify my classes to implement a new interface and associated methods. My current approach is using the core asm API via a javaagent. I'd like to keep this…
Jens
  • 131
  • 1
  • 3
8
votes
3 answers

Java: new instance from bytecode

ClassWriter cw = new ClassWriter(...); byte[] bytes = cw.toByteArray(); I would like to create new class instance from bytes array. How do I do this? Is it possible at all?
8
votes
2 answers

Access private inner classes in java ASM

I have a class which contains several inner classes. I would like to generate additional inner classes that interact with the compile-time private inner classes using the ASM library. My code looks like: public class Parent { public void…
Tareq Sha
  • 515
  • 4
  • 14
1
2
3
53 54