Search code examples
javajarreverse-engineeringdecompiling

Modify a string in Java bytecode (jar)


I want to modify a connection string that's hard-coded in a Java application (jar without source).

I presume it's possible to decompile the jar, then change the source and recompile to a new jar, but is there a quicker way to do this?

EDIT:

  • It's a standalone application, not a jar I'm loading from my own code
  • I doubt it will have been obfuscated: niche scientific application, author AWOL.
  • A solution that entails modifying the string "in memory" while the app is running would also suffice, but not ideal

Solution

  • I think decompilation is probably the quickest way, provided the code hasn't been obfuscated such that a decompilation/compilation round-trip is not possible. You're going to have to decompile the code anyway to find the connection string, so you're half-way there already.

    More importantly, you can take advantage of this method to pull the connection string out into a properties file, and hence (hopefully) only perform the decompilation once!