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
6
votes
6 answers

Is it possible to have the System ClassLoader load .class files specified at run time?

I am writing a static analysis tool for an assignment, it analyses Java bytecode using the ASM library. One of the parts of ASM that we use requires (or at least, appears to require) that the class be loaded from the ClassLoader. We were hoping the…
Grundlefleck
  • 124,925
  • 25
  • 94
  • 111
6
votes
3 answers

Can JVM bytecode be manipulated at compile time?

Is it possible to use a bytecode manipulation library like ASM at compile time? Specifically, I'd like to use Java's annotation processing API to implement boilerplate-heavy methods on annotated classes. Implementing an annotation processor is…
Mike Craig
  • 1,677
  • 1
  • 13
  • 22
6
votes
3 answers

Is there a CIL Static Analysis Library like ASM for Java Bytecode?

I am looking for a library for doing custom static code analysis on CIL code. READ: I have no interest in a tool that already does static analysis like those shown here. For custom analysis with Java Bytecodes, I have used ASM and I like the…
Lincoln
  • 1,008
  • 12
  • 20
6
votes
2 answers

Replace java operators by methods in bytecode using javassist

My Goal To be able to detect when, at runtime, a comparison is made (or any other operation like, *, - , /, >, < ,... This should be achieved to edit the bytecode of a class using Javassist or ow2 ASM What must be achieved This code public class…
tgoossens
  • 9,676
  • 2
  • 18
  • 23
5
votes
1 answer

Eclipse: Error (Bytecode Outline) SOURCE FILE [in PROJECT] is not on its project's build path

I've just installer the ASM Eclipse Plugin (and restarted), which give an improved Bytecode Outline, and I can use it for the JRE classes, but looking at my own code, I get the error message in the title. My java project is on Build Automatically,…
Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85
5
votes
4 answers

Pretty printing a method in ASM Bytecode

I am trying (with no success) to print only the contents of a given method. The following code almost does the trick: class MyTraceMethodVisitor extends MethodVisitor { public MyTraceMethodVisitor(MethodVisitor mv) { …
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
5
votes
1 answer

Byte code instrumentation - implement native or java agent?

If I want to realize a profiler using byte code instrumentation, should I write a native agent using JVMTI or should I write a java agent using the java.lang.instrument package? If I want to use libraries like ASM - which seems to be mandatory if…
Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143
5
votes
2 answers

Bytecode manipulation to intercept setting the value of a field

Using a library like ASM or cglib, is there a way to add bytecode instructions to a class to execute code whenever the value of a class field is set? For example, let’s say I have this class: public class Person { bool dirty; …
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
5
votes
1 answer

Is it possible to access local variables with ByteBuddy's Advice?

When intercepting a method's implementation with an @Advice, is it possible to access local variables?
Carlos Melo
  • 3,052
  • 3
  • 37
  • 45
5
votes
1 answer

What is the difference between AspectJ And ASM?

As I understand, the 2 frameworks are both static that injects monitor codes into class codes. So, what is the difference?
Viyu
  • 51
  • 4
5
votes
2 answers

How to load a modified superclass in Java?

I have a class A extends B. I've created a CustomClassLoader extends ClassLoader to use defineClass(className, byte[], offset, length). I've instanciate a new CustomClassLoader(Thread.currentThread().getContextClassLoader()). So the parent of my…
A.DUPONCHEL
  • 193
  • 12
5
votes
1 answer

Selecting and modifying `if` statement with ASM

I want to update if statement in already existing class on particular line without changing the whole method. Here is the target code (names of classes, methods and some code changed because they're not relevant): public class Target extends…
5
votes
2 answers

Java: list fields used in a method

In Java, how can I get the Fields that are used in a method ? Basically, this is the same questions as this one in .NET. I dont wan't to list the fields from a Class, but to list the fields that are used in a given method of the…
Julien
  • 1,302
  • 10
  • 23
5
votes
1 answer

ifeq/ifne JVM opcode always branches

[TL;DR: the following JVM bytecode instructions seems not to work: iconst_0 istore 6 ...sequential iinc 6 1 jsr L42 ... ; L42 iload 6 ifeq L53 ; Always branches!!! astore 8 iinc 6 -1 ; L53 LDC 100 ISUB ; ERROR, returnAddress is at the top of the…
Bruno Kim
  • 2,300
  • 4
  • 17
  • 27
5
votes
3 answers

Detect recursive method calls at run time in byte code using ASM (5.x): howto?

The problem is as follows; the method, in Java code, is: Rule foo() { return sequence(foo(), x()); } This will provoke a parsing loop which of course should be avoided; however, this is legal: Rule foo() { return sequence(x(),…
fge
  • 119,121
  • 33
  • 254
  • 329