810 questions
1
vote
1
answer
100
views
How to use visitLocalVariable in ASM correctly?
So I am trying to add information about locals I use. The current way I am trying to achieve it - is:
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, "something", "()V&...
0
votes
1
answer
60
views
Method not found in class using ASM byte code
I have a perplexing problem. We use run-time created codec:s for message en- and decoding. The original authors has long since left the building. I've been asked to add some rather simple ...
0
votes
2
answers
70
views
How properly ThreadLocal Context in the ByteBuddy Instrumentation Advice
Hi I'm trying to build a trace agent where app agent propagates the origin application name across the multiple network calls using the HTTPUrlConnection.
So far, I was able to invoke the Advice ...
0
votes
0
answers
21
views
How to ensure instrumented class is packaged in the APK
I have this custom gradle plugin to replace the implementation of a class. When I build the apk I do see that the original class is modified as expected. However, the class packaged in the apk is ...
0
votes
0
answers
99
views
Unable to Transform with Android Gradle Plugin
I’m Trying to Intercept Some Methods Using the Byte-Buddy Android Gradle Plugin
I want to intercept some methods using the Byte-Buddy Android Gradle plugin. Here are the versions I am using:
• Java ...
0
votes
1
answer
88
views
Javabytecode generation, nested loops - Inconsistent stackmap frames at branch target 114
I am playing with Java bytecode generation (using Clojure with https://github.com/jgpc42/insn), Currently I am trying to generate a bytecode for a nested for loop, bellow is the relevant part of the ...
1
vote
1
answer
569
views
Starting a Spring boot project with a custom Java agent jar gives errors
As shown in the following figure, a custom Java agent package is added to the JVM options
-javaagent:/usr/local/maven/apache-maven-3.6.3/repository/com/graviton/Probe-Agent/1.0-SNAPSHOT/Probe-Agent-1....
-1
votes
1
answer
135
views
Java ClassFileTransformer fails to throw exception
I have code that attempts to redefine a class at runtime using a ClassFileTransformer and an instance of Instrumentation.
However, I've noticed that the transform method of ClassFileTransformer fails ...
0
votes
1
answer
122
views
Why does java agent get stuck and not perform any actions?
I am writing a term paper for the university. The task is to write two programs, one of which collects some information, signs it with a digital key, and saves the encrypted data and the key to ...
0
votes
2
answers
162
views
How to Mix Manual and Automatic Calculation of Max Locals, Max Stack, and Frames in ASM per Method Basis?
I'm currently working on a project where I generate Java bytecode from my own intermediate representation using the ASM library. For some methods in my code, I already have pre-calculated values for ...
-1
votes
1
answer
99
views
ASM does not preserve order in the constant pool table
It seems that ASM ClassWriter does not preserve the order of entries in the constant pool. For example, consider the following code snippet:
@Test
void hashShouldBeSame() throws IOException, ...
-1
votes
1
answer
288
views
Java ASM edit class/method that is aleready loaded by JVM
I'm currently trying to edit the bytecode of a java class after it has been loaded by the JVM.
I use Java 8 and ASM 5.0.3.
I can't change the command line or the JVM arguments.
Here is a minimal ...
0
votes
2
answers
176
views
How can I modify the core api in java ?
for example:I want to change LocalDateTime.now() return result in non-production enviroment,
I am trying to invoke the following code,but error occors:
@Test
public void test3() {
...
1
vote
2
answers
113
views
With a java ASM agent, how to detect a collection modification in a object?
I'am working in a Transparent Dirty Detection Agent (tdd-agent). It work really well redefining the target classes to implement the setDirty()/isDirty() and set it when it detect a putfield, but I ...
1
vote
1
answer
193
views
How can I make org.objectweb.asm.util.CheckClassAdapter throw an exception instead of printing errors to stderr?
I am currently utilizing org.objectweb.asm.util.CheckClassAdapter for bytecode verification in my Java project. However, I've observed that this class prints errors to stderr instead of throwing ...
1
vote
0
answers
150
views
How to dynamically replace methods with Byte Buddy?
I'm trying to replace methods in a class with their counterparts in a subpackage, if they exist. For example, if I have a class "name.package.ClassName" and I want to replace its methods ...
0
votes
1
answer
138
views
How to find out whether the ASM java instrumentation happens at compile time OR at runtime?
I am a bit new to the Java ecosystem. I am reading the ASM way (in this doc https://www.baeldung.com/java-asm ) to do Java instrumentation.
And I don't know when ASM changes the byte code, to be ...
0
votes
0
answers
140
views
How to inject a method into a class at runtime without ASM?
In past versions of the bytecode manipulation framework Mixin, there was a method called prepareConfigs(MixinEnvironment). A nonstandard, but very commonly-used, way to bootstrap Mixins at a certain ...
0
votes
1
answer
269
views
How is string concatenation handled in Java bytecode compilation?
public class TestException extends Exception {
public TestException(String msg) {
super("This is the message: " + msg);
}
}
The above code is compiled to:
public class ...
0
votes
1
answer
452
views
Exception when parsing Java 16 bytecode with ASM library
I'm trying to parse bytecode from Java 16 (bytecode version 60) using the ObjectWeb ASM. I've written the following code:
@Test
void parseBytecode() {
try (InputStream stream = this.getClass()
...
0
votes
0
answers
92
views
How to create a transforming class loader
I am trying to make a class loader which transforms the class bytes of the class being loaded using some kind of class transformer.
Suppose I have the following code:
static class Test {
void foo();
...
2
votes
1
answer
126
views
Merging int[] and String[] should result in Object[]
After carefully reading JVMS §4.10.2.2, I noticed the following paragraph:
If corresponding values are both array reference types, then their dimensions are examined. If the array types have the same ...
1
vote
1
answer
143
views
Using Java ASM library to manipulate bytecode at build time, how can I check if an annotation on a field contains other specific annotations?
SampleClass has a field, that is annotated with MyAnnotation.
I can detect that MyAnnotation is present on the field name using ASM visitor pattern, but unsure how to check if @NotNull is part of ...
1
vote
1
answer
104
views
Detect modified bytecode at runtime
There are a number of tools(e.g. JavaAssist, ASM) to re-generate bytecodes at runtime for various purposes. One case is Application permformance Management(APM), which provides agents to rewrite ...
0
votes
0
answers
91
views
Write bytecode to a method with ASM in java
I am trying to make something similar to Mixins (from the Minecraft mod loader Fabric)
and what I made so far seems to work (doesn't throw any errors, I don't know how else to check), but I got stuck ...
0
votes
1
answer
125
views
Difference between iload with '_' and without
I hava a question about the iload instruction of jasmin.
Is it correct to do iload 1 or it has to be iload_1?
Or when is a number between 1 and 3 we have to use the '' and the others we have to not ...
2
votes
1
answer
257
views
How to record visited constants by MethodVisitor in ASM
I'm trying to check how many times a constant is used in the given classes. My idea is to first use ClassReader.accept(ClassVisitor, ...) to visit the class, and then declare a methodVisitor for each ...
1
vote
0
answers
59
views
How to check the whole execution flow of a running program using ASM?
I am wondering what to do to take a deeper insight into the execution flow when running a test unit.
For example,
below should be a body of a test unit.
A.methodA(1,2,false);
B b = new B("foo&...
0
votes
1
answer
355
views
Use java agent with manipulated java bytecode (ASM)
I am trying to figure out how ASM works, with the help of A Guide to Java Bytecode Manipulation with ASM. I followed the tutorial and created an 'extra' static field for the Integer class. Here is the ...
0
votes
1
answer
78
views
Why are my self-written classes / 3-party library classes invisible to JRE classes?
I'm writing a security-boosted Java program that uses ASM tool to add some hooks into JRE classes. The hooks will then call my method to make some rule checks. But the odd thing is, the hooks in JRE ...
0
votes
0
answers
409
views
Java ASM bytecode manipulation - add code to constructor of a library class
I have code to insert instructions into the constructor of a class from a third party library (okhttp3.OkHttpClient in this case). Disassembled class shows the added line. However, I am not sure how ...
0
votes
1
answer
694
views
Java ASM ClassReader fails with java.io.IOException: Class not found
I am trying to instrument OkHttpClient builder class. However, I am not able to create ClassReader in the first place.
import org.objectweb.asm.ClassReader;
...
// this works meaning dependency from ...
0
votes
1
answer
505
views
Java ASM byte code manipulation to inject code into a method not working
I want to inject some code into an existing class/method. But I am unable to get the classloader to "find" the class in order to use the modified byte code.
MyClassInjector.java
import org....
2
votes
1
answer
271
views
Java ASM method override check
I have a problem with method override checks. I can detect simple override relations, but if the parent class has generics and the abstract method uses type parameters (return value/args), my code ...
1
vote
2
answers
216
views
Extract method raw bytes
How to extract method raw bytes using ASM ?
I need a map of method signatures* and raw bytes
ClassReader classReader = new ClassReader(artifact.getInputStream(jarEntry));
classReader.accept(new ...
2
votes
1
answer
170
views
How to add the exception handling row to the end of the exception handle using ASM
I'm doing instrumentation for java code with ASM library.
I want to surround a method body with a try-catch block, which doesn't interrupt the origianl method execution. However, when I use ...
0
votes
1
answer
658
views
Java ASM: Bad local variable type (dload) Type top (current frame, locals[5]) is not assignable to double
I am trying to generate Java bytecode using the Java Asm library (I am basically trying to create yet another JVM programming language)
Here is the code I am compiling
float f = 2f
float f2 = new ...
1
vote
1
answer
295
views
JVM byte code instructions, debug info source file as well as line number
I'm writing a compiler that generates JVM byte code, using the ASM library for the backend. It will be desirable to output debug information, so that stack traces can show source code locations where ...
4
votes
1
answer
113
views
Why does COMPUTE_FRAMES generate a lot of redundant instructions?
I'm writing a compiler that outputs JVM byte code, and using ASM 9.4 for the backend. This works fine, but I am puzzled about one particular quirk.
I'm specifying COMPUTE_FRAMES to automatically ...
1
vote
1
answer
1k
views
Java/ASM: Index 0 out of bounds for length 0 even though list is 1024 elements long
I'm trying to understand ASM and am currently stuck at chapter 2.2.4 in the handbook. This should be a simple Java question though.
The example code I'm trying to understand has this line in it called ...
0
votes
1
answer
267
views
How can I use ASM lib in java to instrument an if-else block?
I've been trying to instrument branch-related code using ASM lib in java. Suppose this is a period of code I want to instrument:
if (true) {
System.out.println("true");
...
0
votes
1
answer
107
views
Java ASM visitMethod access 4161 meaning
I have the following inheritance structure:
SomeModel implements Entity, and SomeModelQueryRepo has 2 methods that return SomeModel: get given an Id, and get returning all SomeModels in the repo.
For ...
0
votes
0
answers
570
views
Bad type on operand stack Error Java ASM ClassVisitor
I'm using a plugin for Eclipse (WindowBuilder) in my RCP application based on Eclipse. Since a few versions this plugin doesn't work anymore in my RCP setup. In Eclipse however there is no problem.
It ...
2
votes
1
answer
256
views
When instrumenting classes, offset of inserted stack frame overlap with existing one
What I did is to instrument java classes at runtime to warp the whole method with a big try-catch block, and then rethrow the exception in the catch block if any exception is caught.
I use a Premain ...
0
votes
0
answers
258
views
How to record all the possible values of public static fields during test suite execution?
Firstly, this question is more like a general question than a specific technical problem.
I'm doing a research project, where I need to record all the possible values of public static fields during ...
2
votes
1
answer
199
views
MethodVisitor's (api, MethodVisitor) constructor, is it needed for only reading
I am only reading bytecode not overwrite,
which one I should use:
public MethodVisitor visitMethod(...) {
return new MyMethodVisitor(Opcodes.ASM9, super.visitMethod(...));
}
or
public ...
3
votes
1
answer
163
views
How to get a Java method's all referring classes by jars like ASM or Javassist?
As the code shows below:
public class Main implements MainInter{
public static void main(String[] args) {
List<String> s = new ArrayList<>();
DClassFather var = new ...
1
vote
0
answers
804
views
ASM - can't instrument java/lang/Thread
I am able to instrument a boat load of my own classes and some third party libraries. But, when I want to load java/lang/Thread (need the thread id and name to link parent thread and child threads), ...
0
votes
1
answer
180
views
ASM method transformation stackmap frame exception
I'm trying to add to user bytecode from a premain method that adds certain information in String form to a list whenever a new line number node is encountered, although when I run the agent and ...
1
vote
0
answers
147
views
Track multithreaded program execution using ASM Framework
I am trying to write a program that observes the execution of a simple multithreaded user program and returns a queue structure detailing the order in which the user program's threads worked through ...