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

Debugging python bytecode when source is not available

I need to debug a compiled python script (pyc file). The original source is not available. Is there a way to debug the bytecode directly? The closest thing I can find is to build python with LLTRACE enabled. The downside of this technique is that…
4
votes
2 answers

Use ASM to add an annotation to a foreign class

I want to use ASM bytecode manipulation to add an Annotation to a foreign class, but it seems that I am missing something. The printed result is still without any annotation. private void fixAnnotations4Classes() throws Exception { final…
KIC
  • 5,887
  • 7
  • 58
  • 98
4
votes
1 answer

Can an anonymous .class that extends a class (such as an enum) be hacked in such a way as to implement an interface?

I have an interface such as: public interface Foo() { public void bar(); } And I want to make an anonymous enum that implements it, as if this was valid Java: public enum MyEnum { A implements Foo { public void bar() { …
SoniEx2
  • 1,864
  • 3
  • 27
  • 40
4
votes
2 answers

What do 'start' and 'length' attribute in LocalVariableTable mean

So here is the example: LocalVariableTable: Start Length Slot Name Signature 0 133 0 this Lcom/my/class/Test; 2 131 1 a I 4 129 2 b I 7 …
dhblah
  • 9,751
  • 12
  • 56
  • 92
4
votes
7 answers

How to detect Java agents, JVMTI, etc

How does one secure the Java environment when running on a machine you don't control? What is to stop someone from creating a java agent or native JVMTI agent and dumping bytecode or re-writing classes to bypass licensing and/or other security…
4
votes
1 answer

Java Bytecode: Customized setter/getter with byte buddy

I am trying to create a "custom" setter method for a field with byte buddy. Buddy's own mechanism allows for standard setter/getter methods to be implemented very easily, however, I am looking for an elegant way to extend the setter with some…
Nikola Veber
  • 73
  • 1
  • 4
4
votes
1 answer

Bytecode: LOOKUPSWITCH and TABLESWITCH

I am currently instrumenting bytecode using BCEL. In the BCEL API, the two instructions types LOOKUPSWITCH and TABLESWITCH (package org.apache.bcel.generic) are implementing interface StackProducer. I know that these two instructions pop the operand…
H-H
  • 4,431
  • 6
  • 33
  • 41
4
votes
1 answer

Bytecode manipulation manifest entries

I'm having fun doing some Java bytecode modification tutorials. All of them state that I need to have the following manifest attirbutes set: Can-Redefine-Classes: true Can-Retransform-Classes: true Can-Set-Native-Method-Prefix: true It's completely…
maslan
  • 2,078
  • 16
  • 34
4
votes
2 answers

Create new object using ASM

I have been trying to use ASM framework to inject bytecode at my interested location and I have been successful till now.Currently I am trying to inject code which basically creates a new instance/object of a class and after reading a bit I found…
VishwanathB
  • 139
  • 2
  • 10
4
votes
1 answer

How to add a SerialVersionUID to a Class[_] instance in Scala?

I need to create an instances an instance of java.lang.Class that is otherwise identical to classOf[MyClass] but also has a SerialVersionUID, which MyClass does not have. MyClass is a Scala-2.10 class. One problem is that in Java SerialVersionUID is…
4
votes
1 answer

Javassist: Initializing static class field to a given value?

I'd like to bind some object instance to a class created using Javassist. This object is read from some source, the data are not known upfront. // Create the class. CtClass subClass = pool.makeClass( fullName ); final CtClass superClass…
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
4
votes
1 answer

Where does bytecode injection happen?

Motivation I have a SomeObject.java file: class SomeObject { String name; } Compiling it creates a bytecode-containing SomeObject.class file. 0xCAFEBABE... If we use SomeObject on the JVM, it is loaded by the current classloader and all works…
ipavlic
  • 4,906
  • 10
  • 40
  • 77
4
votes
5 answers

Rewriting method calls within compiled Java classes

I want to replace calls to a given class with calls to anther class within a method body whilst parsing compiled class files... or put another way, is there a method of detecting usages of a given class in a method and replacing just that part of…
recursv
4
votes
2 answers

Generate code that implements JSR 308 "instanceof @MyAnotations" runtime check

JSR 308 proposes to add type annotations to Java. After its ratification, programmers will be able to add an annotation wherever a Java type is currently allowed. That includes not only method/field/local/parameter decorations, but also constructor…
3
votes
1 answer

Use proxies with Hibernate runtime bytecode enhancement

I'm using Spring Boot 2.7.5 with Hibernate 5.6.12.Final and apply bytecode enhancement at build-time via hibernate-enhance-maven-plugin. It works great and prevents eagerly fetching @OneToOne relationships, as described here…
Blockost
  • 493
  • 1
  • 7
  • 18