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

Replace java operators by methods in bytecode using javassist

My Goal To be able to detect when, at runtime, a comparison is made (or any other operation like, *, - , /, >, < ,... This should be achieved to edit the bytecode of a class using Javassist or ow2 ASM What must be achieved This code public class…
tgoossens
  • 9,676
  • 2
  • 18
  • 23
5
votes
3 answers

native java bytecode instrumentation

for bytecode instrumentation in java, there is the asm framework and the bcel and javaassist libraries. However I need to do instrumentation in native code, since some java classes are already loaded by the time the javaagent runs, eg…
pdeva
  • 43,605
  • 46
  • 133
  • 171
5
votes
1 answer

Byte code instrumentation - implement native or java agent?

If I want to realize a profiler using byte code instrumentation, should I write a native agent using JVMTI or should I write a java agent using the java.lang.instrument package? If I want to use libraries like ASM - which seems to be mandatory if…
Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143
5
votes
1 answer

JPEG file size markers, inserting bytes, IPTC metadata

I'm interested in manually injecting IPTC fields into JPG file on bytes level. JPEG file has multiple metadata segments with respectable size markers. The segments-containers for IPTC are: App13 - starts with FF ED XX XX .. 8BIM IPTC text metadata -…
yosh
  • 3,245
  • 7
  • 55
  • 84
5
votes
1 answer

Common stack-based VM bytecode optimizations?

Ok, I'm posting this fearing that it might be closed before anyone ever reads it - I'm quite used to that - but I'll give it a try... even pointing me to the right direction or some existing answer that does contain a specific answer would…
5
votes
1 answer

Is it possible to modify the bytecode and save it with javassist?

All the references I've found on the web says the bytecode can be modified at runtime, but I don't seem to find if that modified bytecode could replace the original. This way the original bytecode could be substituted once, and the rest of the…
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
5
votes
2 answers

When is a Java object fully initialized?

As one may know, an object just allocated by the new bytecode is not initialized, and is thus not a java.lang.Object. If I do runtime bytecode manipulation and give that object to a method, the JVM will complain or even crash (because the "thing" I…
xuq01
  • 588
  • 4
  • 17
5
votes
5 answers

Is it possible to inject code in an android application?

I would like to inject code in an android application at runtime. I have tried to use dx tool to generate a dexfile in the sdcard but when i want to instantiate, it fails. Are there any tools to inject code generating new dalvik bytecode? I am…
Sergio
  • 53
  • 1
  • 1
  • 3
5
votes
2 answers

Bytecode manipulation to intercept setting the value of a field

Using a library like ASM or cglib, is there a way to add bytecode instructions to a class to execute code whenever the value of a class field is set? For example, let’s say I have this class: public class Person { bool dirty; …
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
5
votes
1 answer

Selecting and modifying `if` statement with ASM

I want to update if statement in already existing class on particular line without changing the whole method. Here is the target code (names of classes, methods and some code changed because they're not relevant): public class Target extends…
5
votes
2 answers

Java: list fields used in a method

In Java, how can I get the Fields that are used in a method ? Basically, this is the same questions as this one in .NET. I dont wan't to list the fields from a Class, but to list the fields that are used in a given method of the…
Julien
  • 1,302
  • 10
  • 23
5
votes
1 answer

invokestatic on static method in interface

Disassembling some Java 8 code I found out that some invokestatic calls on static methods in interface (particularly this was java.util.function.Function.identity()) uses InterfaceMethodRef in const pool; this is what javap -s -c -v p show me: …
Radim Vansa
  • 5,686
  • 2
  • 25
  • 40
5
votes
3 answers

Inconsistent stack height 0 != 1

I'm modifying a Java class bytecode through an hexadecimal editor, and I want to force a method to always return true. Replaced all its bytecode with nops to keep the size intact (original size is 1890). Execute a pop to restore the stack height…
m0skit0
  • 25,268
  • 11
  • 79
  • 127
5
votes
2 answers

Proxy Final Method In Non Final Class

I need to proxy methods on various view classes in the Android UI Framework such as TextView. Particularly TextView#setText(int resId). This method is not part of an interface. Therefore, Java Proxy will not work since it only works for…
jophde
  • 444
  • 1
  • 5
  • 13
5
votes
1 answer

Remove Exception from method body with ASM

Intro: I have a (obfuscated) METHOD that I printed using ASM and the output was as follows: METHOD: m(ZB)Lcc; -------------------------------------- L0: { ALOAD_0 GETFIELD d/x I LDC 2036719157 IMUL ISTORE GOTO …
Brandon
  • 22,723
  • 11
  • 93
  • 186