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

How to pass InvokeDynamic as parameter to MethodCall in ByteBuddy

I want to generate byte code of a class which passes a method reference as argument to another method. e.g.: public class GeneratedClass { public GeneratedClass() { Test.foo((Function)Test::getId) } } Using ByteBuddy I can generate…
Rasoul
  • 53
  • 1
  • 5
3
votes
3 answers

Java Bytecode Manipulation Without External Library

Libraries such as ASM, BCEL, Javaassist and AspectJ are all capable of runtime bytecode manipulation but how do they achieve this? I have done some basic bytecode manipulation using ASM before but i don't understand how it works. Is the Java Agent…
Will D
  • 43
  • 5
3
votes
5 answers

What programming languages will let me manipulate the sequence of instructions in a method?

I have an upcoming project in which a core requirement will be to mutate the way a method works at runtime. Note that I'm not talking about a higher level OO concept like "shadow one method with another", although the practical effect would be…
3
votes
2 answers

Retro-actively add Java annotations to methods?

Is there a way to modify .class files in order to add Java annotations to certain methods? Basically I want to traverse methods of each class file in a jar file and annotate certain ones. Note that this is not at run-time while using the jar file.…
Epaga
  • 38,231
  • 58
  • 157
  • 245
3
votes
1 answer

identifying ``method code too large`` origin

So I've run into MY: WARNING cannot transform class XYZ java.lang.RuntimeException: Method code too large! at org.objectweb.asm.MethodWriter.a(Unknown Source) at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source) at ... I am…
3
votes
2 answers

Any way to regenerate stackmap from byte code?

I have an old library (circa 2005) that performs byte code manipulation, but does not touch the stackmap. Consequently my jvm (java 8) complains that they are invalid classes. Only way to circumvent the errors is to run the jvm with -noverify. But…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
3
votes
1 answer

Intercept constructors during rebase in ByteBuddy

What I try to do I am trying to rebase and rename class to intercept it's constructor with Bytebuddy 1.6.7 Motivation I am working on SAAS system, where user can provide annotated java classes, system should instrument them before storing or…
Mikalai Parafeniuk
  • 1,328
  • 15
  • 10
3
votes
2 answers

What are the dangers of bytecode manipulation (if any)?

Bytecode enhancement seems like a very interesting Java technique, but it has the feel of a bit of "black magic" about it. Are there any disadvantages to using it (other than the fact that functionality is added to classes that is not apparent from…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
3
votes
1 answer

Adding jar file to instrumentation path

I have two jar files (for the example lets call them Updater.jar and Code.jar). Updater.jar is launched with its main method, and then it launches itself again with a premain method: package Update; import java.io.File; import…
JD9999
  • 394
  • 1
  • 7
  • 18
3
votes
1 answer

JDI, Java Byte code instrumentation and Java agents (JWDP, JVMTI)

I am new in the realm of debuggers, instrumentation and JVMTI. So I have few questions about them. What is the difference between JDI(java debugger interface), JWDP, javaagent and native agent(JVMTI). and where does the java instrumentation API fit…
Rahul khandelwal
  • 331
  • 3
  • 14
3
votes
1 answer

How to use importlib for rewriting bytecode?

I'm looking for a way to use importlib in Python 2.x to rewrite bytecode of imported modules on-the-fly. In other words, I need to hook my own function between the compilation and execution step during import. Besides that I want the import…
Michał Kwiatkowski
  • 9,196
  • 2
  • 25
  • 20
3
votes
1 answer

unexpected instructions and parameters for invokevirtual in the inlined method body

I followed the sample code in the "3.2.6 Inline Method“ in the http://asm.ow2.org/current/asm-transformations.pdf, to inline a MethodNode to a call site. My problem is that there are some unexpected instructions shown in the generated bytecode…
shijie xu
  • 1,975
  • 21
  • 52
3
votes
2 answers

To get the hashCode() of the object that calls a specific method in Java

What I'm trying to is to get 'hashCode()' value of the object that calls a specific method in Java. For example, public class Caller { public void aMethod() { Callee calleeObj = new Callee(); calleeObj.aSpecificMethod(); …
byron1st
  • 969
  • 1
  • 13
  • 35
3
votes
2 answers

How can I run DataNucleus Bytecode Enhancer from SBT?

I've put together a proof of concept which aims to provide a skeleton SBT multimodule project which utilizes DataNucleus JDO Enhancer with mixed Java and Scala sources. The difficulty appears when I try to enhance persistence classes from SBT.…
Richard Gomes
  • 5,675
  • 2
  • 44
  • 50
3
votes
1 answer

Java Access Flag Verification

Consider the following scenario: package packA; public class A { private static int i = 0; } package packB; public class B { public static void main(String[] args) { int i = A.i + 1; } } Because A.i is private, it is not…
Clashsoft
  • 11,553
  • 5
  • 40
  • 79