Questions tagged [bytecode-manipulation]

Low level Virtual Machine bytecode manipulations. Including creating/modifying/optimizing/etc bytecode for various VMs. For example JVM, Python VM, Lua VM, etc.

Why?

Using some VM based programming languages for period of time usually leads to realising that some parts of the code aren't translated into bytecode efficiently, might be optimized for the specific VM even more or we just need some functionality which isn't implemented into standard bytecode compiler/interpreter/etc, like:

  • bytecode encryption
  • bytecode linkage
  • etc.

Links:

More about bytecode:

383 questions
5
votes
1 answer

Tracing method invocation arguments in bytecode using ASM

How can I inspect the bytecode of a class (using something such as ASM) to learn which initial values were passed through to a method? For example: Given some methods that pass values to each other: void m1(Object o) { Object v = o; m2(v); …
Josh Stone
  • 4,328
  • 7
  • 29
  • 37
5
votes
1 answer

Injecting code in an existing method using BCEL

For my thesis research I need to inject a piece of code to a definable method in a test suite of which I do not have the source ( the DaCapo benchmark suite in this case, http://dacapobench.org/ ). Previous research, on which this part of my thesis…
Peter
  • 620
  • 6
  • 13
5
votes
2 answers

Javassist: re-creating a class - delete first, or defrost() and modify?

I use Javassist to create a class. And in a test suite, when a second test tries to create the same class, it fails at pool.makeClass( ... ) because the class is frozen (i.e. already created via toClass(). What's the way to overcome this? Ideally,…
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
5
votes
2 answers

Incompatible argument to function with ASM bytecode instrumentation

I am having some troubles running a simple main program with Guava libraries. I have instrumented the classes to get the methods parameters using my code from here : Java method parameters values in ASM The issue is, that while the code works for…
5
votes
1 answer

How to add static final field with initializer using ASM?

I want to add static final field into .class file using ASM, and the source file is public class Example { public Example(int code) { this.code = code; } public int getCode() { return code; } private final int…
4
votes
1 answer

How to augment methods during ByteBuddy transformation?

Context I am implementing byte code transformations with ByteBuddy and the process of manipulation is a multi step process. Because of that, the manipulation has to be able to: augment originally existing methods create new methods entirely augment…
Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
4
votes
1 answer

Java bytecode asm - How can I create a clone of a class with only the class name changed?

Java asm - How can I create a clone of a class with only the class name changed ? I know that there's a simple way to modify the class name using asm SimpleRemapper, but I just want the outer class name changed without modifying the class names used…
4
votes
2 answers

Constructor bytecode

The ASM guide talks about constructors: package pkg; public class Bean { private int f; public int getF() { return this.f; } public void setF(int f) { this.f = f; } } The Bean class also has a default public constructor which…
rapt
  • 11,810
  • 35
  • 103
  • 145
4
votes
1 answer

Why can't I load resources which are appended to the bootstrap class loader search?

When adding a jar to the bootstrap class loader via java.lang.instrument.Instrumentation#appendToBootstrapClassLoaderSearch, I can't load any of it's resources…
Felix
  • 5,804
  • 4
  • 25
  • 37
4
votes
2 answers

How to remove method body at runtime with ASM 5.2

I'm trying to remove the method body of test() in the following program so that nothing is printed to the Console. I'm using using ASM 5.2 but everything I've tried doesn't seem to have any effect. Can someone explain what I'm doing wrong and also…
kmecpp
  • 2,371
  • 1
  • 23
  • 38
4
votes
1 answer

Removing Methods with Java ASM

I'm trying to use the Java ASM library, and after quite a bit of research, I haven't found the solutions to a problem I'm having. I'm trying to make an application that does the following: Reads classes from an external Jar file Remove completely…
RubbaBoy
  • 41
  • 2
  • 5
4
votes
5 answers

java disassemble reassemble

Say I want to take a java class file, disassemble it, tweak the java bytecode output, and then reassemble it again. I need to rename a symbol in the constant pool table. I also don't have access to the source code, and using a decompiler seems like…
Lunpa
  • 151
  • 2
  • 9
4
votes
1 answer

JVMTI RetransformClasses() is taking a lot of time

I deployed a simple JVMTI agent to test bytecode instrumentation. My strategy is to call RetransformClasses function in CompiledMethodLoad call back to invoke ClassFileLoadHook. I wrote following code to do so: err =…
Saqib Ahmed
  • 1,056
  • 14
  • 33
4
votes
2 answers

ClassWriter COMPUTE_FRAMES in ASM

I've been trying to understand how stack map frames work in Java by playing around with jumps in ASM. I created a simple method to try some things out: (disassembled with Krakatau): L0: ldc 'hello' L2: astore_1 L3: …
konsolas
  • 1,041
  • 11
  • 24
4
votes
1 answer

ASM Java replace method call instruction

Background I want to do some instrumentation work on some time consuming method such as org/json/JSONObject.toString(), using ASM Java framework. Original call to the Method public class JSONUsage { public void callToString() { …
kvh
  • 2,118
  • 19
  • 29