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

How to use a reference to an existing object in a method generated with Javassist

I'm using Javassist to generate a class and method at runtime but I want the generated code to have a reference to an existing object. For example: public Class createClass(Class eventClass, Consumer consumer) throws…
kmecpp
  • 2,371
  • 1
  • 23
  • 38
0
votes
1 answer

Instrumentation to count every statement in a Scala function

I have a simple Scala function in which I want to increment a class variable every time a statement is executed. class C { var cnt: Int: 0 def fun(): Unit = { var a: Int = 0 var b: Int = -10 …
0
votes
0 answers

java.lang.verify error : Inconsistent stack height 1 != 2

I have a custom application in which we have generated the Java Instruction code.We are generating the code using javacc. In one of the Scenarios, we are getting java.lang.verify error : Inconsistent stack height 1 != 2 I checked the generated class…
Ashu
  • 163
  • 4
  • 13
0
votes
0 answers

How to access a local variable in ASM?

When I have a class like this: public class Test { public String injectVariable; void test() { String name = "code"; } } How can I use ASM to inject code to the test method and get the local variable name? public class Test { public…
DSM
  • 1
0
votes
1 answer

Java bytecode modification using ASM throws ClassFormatError: Invalid length XXX in LocalVariableTable

I am using ASM (tree and util as well) and have faced a weird exception Exception in thread "main" java.lang.ClassFormatError: Invalid length 65526 in LocalVariableTable in class file I am trying to edit the bytecode of a .class file, to generate…
0
votes
1 answer

Byteman Implementation Details

I was looking at the byteman implementation to understand how they work specifically for cases like tracking variables AT/AFTER nth read, AT/AFTER nth write etc. In their implementation they read a class two times once for checking if it matches…
0
votes
0 answers

How to collect the usage of constant expressions via bytecode analysis?

The class A declares a constant C as follows: public class A { public static final int C = 10; } This constant is used in method M of class B as follows: public class B { public int M() { return A.C; } } In the bytecodes of…
0
votes
1 answer

Unpacking class file (bytes) into ASM ClassNode

Given a class file in the form of an array of bytes, how do you unpack it into an ASM ClassNode with its collection of MethodNodes? The PDF documentation doesn't seem to say – it seems to assume you will only be doing the reverse, creating a new…
rwallace
  • 31,405
  • 40
  • 123
  • 242
0
votes
1 answer

ASM not reporting constant instructions

I'm trying to use the ASM library to read byte code and translate it into a different format. Starting off with a simple test class containing this method: public static double square(double a) { return a * a; } Which compiles to this byte…
rwallace
  • 31,405
  • 40
  • 123
  • 242
0
votes
4 answers

How to decorate an existing Java object's method?

EDIT: I've described our solution at https://stackoverflow.com/a/60235242/3236516 I have a java object. It is an instance of one of many subclasses that extend an abstract class. I would like to modify one of its methods such that it runs some…
0
votes
2 answers

Is it possible to integrate the JVM's assembly language into standard high level Java code?

I am trying to merge the Java assembly code (using Jasmin (an assembler interface in java)) with standard Java code.Like this public class SomeClass{ public void testPrinting(){ System.out.println("Hello World"); } .method…
zaree
  • 641
  • 2
  • 6
  • 15
0
votes
0 answers

Changing the size of lua numbers in compiled lua script

My goal is to decompile, modify and recompile a lua script. I can do this easily expect that the header of the resulting binary file changes from the original one. The binary chunk I decompile starts with the following header: 1b4c 7561 5100 0104…
Stud
  • 521
  • 4
  • 8
0
votes
0 answers

It is possible to luaj convert a script to the binary representation of lua 5.2

I am trying to convert a script to binary representation using string.dump, but I saw that the luaj 3.0.1 representation is different from lua 5.2, has some way of changing this, or turns the luaj 3.0.1 representation into lua 5.2 ? Code Globals _G…
Idle
  • 1
  • 1
0
votes
1 answer

variable definition and assignment detect asm bytecode

I am trying to use the ASM bytecode tree API for static analysis of Java Code. I have a ClassNode cn, MethodNode m and the list of instructions in that method say InsnList list. Suppose for a given instruction( i.e. AbstractInsnNode) s, I need to…
0
votes
1 answer

java.lang.ClassNotFoundException while instrumenting eclipse rcp application

I tried injecting a method call statement using javassist in every method of some desired classes. The statement corresponds to a class in the java-agent jar. For example if my agent has class like a.b.HelperClass, I am injecting…