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

Change behaviour of static method in Java - byte code manipulation

I am trying to manipulate a static method. For this, Byte Buddy or any other framework can be used. There is one library that is called Pi4J that is used for controlling GPIO of Raspberry Pi. This library has a method called: GpioController gpio =…
2
votes
1 answer

How make Eclipse instrument classes at build time?

Sometimes I have to perform some custom bytecode transformation. I have used mainly asm and javaassit. Inside eclipse usually I run my code with the -javaagent jvm parameter. Outside eclipse I use maven, ant, or the command prompt to invoke the…
2
votes
1 answer

Code modification with Javassist generate a java.lang.VerifyError: Expecting to find integer on stack

I use javassist to rewrite a method called compile (which takes an array of String as argument) : I created a new method having the signature as the compile method ( it's a copy of the original one ) , rename the actual compile method to…
Master Mind
  • 3,014
  • 4
  • 32
  • 63
2
votes
1 answer

How does ldc turn a sequence of characters into a String object?

In java bytecode a string constant is stored in the constant pool as a sequence of characters. I'm curious as to how the jvm converts that into a string object and if there's a way to take advantage of that for other object types that you want…
EnderShadow
  • 105
  • 8
2
votes
1 answer

Javassist: Create class that implements generic interface

I´m trying to create a class with javassit that implements a generic interface passing the generic argument but without sucess so far. I´m aware of the answer Javassist: creating an interface that extends another interface with generics and the…
Heitor
  • 190
  • 2
  • 13
2
votes
1 answer

Avoid Byte Code injection Java

I am currently using javassist to manipulate byte code at runtime for my appserver. I am not creating methods or changing prototype nor creating additional member variables. Are there any security policies or any other ways to block runtime byte…
2
votes
1 answer

Bytecode instrumentation using ASM 5.0 . inject a tracer to trace local variables

I am doing Java bytecode analyse. I want to keep tracking each changing state of local variables. The idea is quite like a debugger. For example, I have a Java source code like public class Foo { public void main() { printOne(); } public void…
Saddy
  • 313
  • 4
  • 22
2
votes
2 answers

Reloading classes with maniupulated bytecode from rt.jar

I am currently trying to track method calls for learning purposes. The javagent I have implemented is a modified version of the implementation in this article. The programm adds to any method call logging instructions into the bytecode.…
2
votes
1 answer

Construct FrameNode with ASM api

I succeeded in implementing bytecode method inline optimization and the generated code seems OK for me. Yet, the verification fails with message: java.lang.VerifyError: Expecting a stackmap frame at branch target 47 Exception Details: Location: …
2
votes
1 answer

Wrong Stack Size calculated by ASM library

I generate bytecodes using ASM library and 'Max stack size' for a method is left to be calculated automatically. During runtime,i found this value (max stack size) is not correct. My source code is: ClassWriter cw = new…
shijie xu
  • 1,975
  • 21
  • 52
2
votes
4 answers

Determine where a catch block ends ASM

In ASM, I'm trying to determine the labels for a try-catch block. Currently I have: public void printTryCatchLabels(MethodNode method) { if (method.tryCatchBlocks != null) { for (int i = 0; i < method.tryCatchBlocks.size(); ++i) { …
Brandon
  • 22,723
  • 11
  • 93
  • 186
2
votes
1 answer

Is there a bytecode back-end (like LLVM) that has a tool to translate the assembled bytecode into machine code?

I thought that you could turn LLVM bytecode into machine code directly using one of it's built-in tools, but according to this SO post, you have to actually provide the front and back-ends. LLVM is really just a tool for applying…
antimatter
  • 3,240
  • 2
  • 23
  • 34
2
votes
1 answer

Why Jsp pages are not directly converted to bytecode?

Jsp pages are first converted to *.java files and then this source file is compiled and executed by the container. why can't we use some byte code engineering libraries to make the class files directly?
sarathsoman
  • 65
  • 1
  • 1
  • 4
2
votes
1 answer

How to generate code objects from modules in Python?

I have a .pyc file with no corresponding Python source code. I want to see the disassembly of the module using dis. I can import my module just fine with import dis import foo But to call dis.dis on it, I can't use the module object. I need the…
Tac-Tics
  • 1,895
  • 13
  • 19
2
votes
2 answers

refractoring java bytecode

I am trying to replace a certain class file with my own in an obfuscated jar. The original class file has methods named "new" and "null" so a quick decompile + compile doesn't work. I tried compiling and using jbe to add new methods named "new" that…
camel
  • 135
  • 5