A
A
Alexander Smolin2017-05-10 11:52:06
Java
Alexander Smolin, 2017-05-10 11:52:06

How to identify and change string in java bytecode?

As the name suggests, I need to find and replace some data in the compiled class file.
Let's say we have:

public class MyClass {

  public static String staticField = "MyStaticField";
  public String myField = "MyField";

  public static void main(String[] args) {
    System.out.println("OutString");
  }
}

It is compiled, in fact, into MyClass.class (which is located in its own jar file, but this, miho, is not a problem since the utilities built into the JRE allow you to get and edit data in archives). Decompilation is not acceptable.
You need to get all the strings ("MyStaticField", "MyField", "OutString") directly from the bytecode, replace some of them and save them back to the class file. Having searched for analogues on the Internet, I found InClassTranslater, but it does not suit me because I need to automate this process. javap does not return the strings themselves, and it's not very clear how to write them back to the class (other than a dumb byte search).
Actually, are there any libraries that analyze java bytecode with the ability to make changes to the data? Or: Are there some "blocks" of bytes that signal that the line is next (and when the line ends)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2017-05-10
@saboteur_kiev

I read a little (I recommend reading it briefly here: https://www.acloudtree.com/hacking-java-bytecode-f...
It's easier with bytecode - you can replace text strings without much concern. You can write a script in any programming language that is convenient for you , which will find the right one, replace it and write it back.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question