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
0
votes
1 answer

Works in sbt but not raw Java: after using `javac` to compile a .class file, why can't `java` find it?

I used ObjectWeb's ASMifier to get a 'HelloDump.java', and added classloader and a main method to load and run a spoofed "HelloWorld". If I run 'HelloDump.java' in the build tool sbt, everything works fine and outputs "HelloWorld!". But if I use…
Julian Peeters
  • 853
  • 1
  • 6
  • 19
0
votes
1 answer

Annotation based JMX

How would you implement Spring like annotation based JMX feature. If class is marked by @ManagedResource methods of the class marked with @ManagedOperation are automatically exposed via JMX. I would like to avoid creating interfaces with MBean…
0
votes
2 answers

Inserting chain of ClassVisitors I don't control in between a ClassReader and ClassWriter?

public class ChainingVisitors { public static void main(String[] args) throws Exception { ClassReader reader = new ClassReader("com.foo.Bar"); ClassWriter writer = new ClassWriter(COMPUTE_MAXS | COMPUTE_FRAMES); …
pholser
  • 4,908
  • 1
  • 27
  • 37
0
votes
2 answers

ASM Bytecode With HttpURLConnection

Using ASM ByteCode library , add a request header (UUID) when a HttpUrlConnection ic created Below is my code - Also am getting the output === > This is Http CONNECT Method!. But dont know how to add a Header? package com.eg.agent; …
Ramesh Subramanian
  • 944
  • 1
  • 12
  • 28
0
votes
1 answer

Wrapping constructor call in the method to the static call using ASM bytecode manipulation

My query is related to bytecode manipulation using ASM. I have one method as follows -- /*Original method code*/ String str ="abs"; // create object of SampleClass2 // constructor calling SampleClass2 sample = new SampleClass2(); …
Ashiq Sayyad
  • 111
  • 2
  • 5
0
votes
2 answers

Java: Type mismatch cannot convert from element type Object to MethodNode

Hello i have problems in this code and it's really bothering me because i don't know how to fix it, if you guys could help me then that would be great! public void execute(final String name, final ClassNode cn) { …
Frunk
  • 180
  • 1
  • 2
  • 11
0
votes
1 answer

Opcode reading of a classfile at runtime with the use of ASM4

Does anybody have any document, which can show me end to end implementation of ASM framework to display opcode of a class file? Or is there any body help me with Hello, World! Program example for ASM frame implementation? I want to display opcodes…
Prathako
  • 91
  • 1
  • 8
0
votes
1 answer

Utility methods in ASM bytecode library for opcode nature determination?

Are there any utils classes in ASM that allows me to infer from the opcode whether the instruction is some kind of store, load, or whatever? For instance, and considering the following code (from ASM) /** * Visits a zero operand instruction. * *…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
0
votes
1 answer

Is org.objectweb.asm.commons.LocalVariablesSorter incorrectly optimizing?

I'm trying to use ASM to wrap a method in a try/finally block. Specifically, I am extending org.objectweb.asm.commons.AdviceAdapter and following the technique described "Using ASM framework to implement common bytecode transformation patterns"…
Patrick
  • 5,714
  • 4
  • 31
  • 36
0
votes
1 answer

Bytecode instrumentation generating java verifier error

I am using ASM in order to do bytecode instrumentation for Java programs. What I'm doing is simple - When instrumenting a method, if the instruction is a PUTFIELD, simply do a DUP_X1 right before the instruction, then visit the PUTFIELD and inject…
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
0
votes
1 answer

How to chain ASM MethodVisitors End to End

I'm trying to implement a transformation in ASM that requires two passes over each method. The first to collect information about where instrumentation is needed (has to do with jump target, which is why I need two passes), and the second completes…
Jochen
  • 2,277
  • 15
  • 22
0
votes
1 answer

How to avoid the VerifyError: “Expecting to find unitialized object on stack” for objects already initialized

I am developing an instrumentation engine with ASM and I need to intercept the invocation of methods, which receive parameters of array type. For that purpose I implemented a MethodVisitor and in its visitMethodInsn I check if the desc parameter…
Miguel Gamboa
  • 8,855
  • 7
  • 47
  • 94
0
votes
1 answer

NoClassDefFoundError error while invoking method added using Java ASM

I'm using ASM to inject code to methods: @Override public void visitCode() { visitMethodInsn(Opcodes.INVOKESTATIC, "sssss/CopyOfsss", "foo", "()V"); super.visitCode(); } Exception in thread "main"…
Sefler
  • 2,237
  • 5
  • 19
  • 29
0
votes
1 answer

JAVA ASM: Why does modification cause nested exception?

In my project I use ASM to change methods signatures. I choose methods which are using RMI and change them this way: from: String f(int i, String s) { ... } to String f(int i, String s, ThreadId t) { log(t) ... log(t) } and…
alicjasalamon
  • 4,171
  • 15
  • 41
  • 65
0
votes
1 answer

ASM method execution listener

Is it possible to implement an adapter capable to intercept all inner method invocations inside main method? If we have this class... class Zombie { private Grave grave = new Grave(); public void kill(Integer zombieId) { …
Nedo
  • 627
  • 1
  • 10
  • 20