-1

I have a jar, which contains a line of code which compares two doubles, one having the value of 0.7, but I need to be able to change that to 0.0.

I cannot use reflection or anything like that because of the fact that this is a compiled jar file (not open source) but changing this value is crucial, because if it stays at 0.7 there is a huge lag problem.

I was thinking of editing bytecode, but cannot find any good software to do so.

I appreciate any help with this.

bernhardkiv
  • 437
  • 4
  • 20

3 Answers3

1

If you can decompile the class, you can make the change and recompile it. Then roll up the jarfile with your patched class. It depends on the class and the JDK used to compile it how easy this will be.

References: JAD (Wiki link because JAD is basically a dead project, though it continues to work when I need it to.) If you use Eclipse, you might have luck with JD-Eclipse. There is also the Procyon project, which I have had limited success with.

  • Sorry for the late response, but this is EXACTLY what I needed, I can't believe I never though of decompiling the single class I need, then using the compiled jar in the classpath, and then compiling the class then putting it back into the compiled jar, simply genious :) – bernhardkiv Mar 22 '15 at 21:36
1

Look into how to decompile the program Java classes, and then re-compile the software yourself.

How do I "decompile" Java class files?

From another similar question: (Change string constant in a compiled class)

If you have the sources for this class, then my approach is:

  • Get the JAR file
  • Get the source for the single class
  • Compile the source with the JAR on the classpath (that way, you don't have to compile anything else; it doesn't hurt that the JAR already contains the binary). You can use the latest Java version for this; just downgrade the compiler using -source and -target.
  • Replace the class file in the JAR with the new one using jar u or an Ant task
Community
  • 1
  • 1
Connorelsea
  • 2,040
  • 5
  • 22
  • 42
0

Besides using (Hex) Editor or decompiler, use can use a byte code manipulation lib like asm. You actually might even be able to use an pre-load agent to transform the code on the fly.

eckes
  • 9,350
  • 1
  • 52
  • 65