Altering .class files or recompiling isolated .java ones
-
Hello there, We have this module at work who nobody knows where the source code is. It was behaving erratically on certain scenarios so i decided to decompile it (using DJ Java decompiler which btw works wonderfully) and found the problem line. Now the how to fix it, i can think of 2 ways: 1) I decompile everything, change the line and recompile The module is pretty large in amount of classes and submodules. I dont really feel confident that i can recompile everything right. 2) Editing the .class file somehow. Now i grabbed a class file editor that showed me bytecode, the method names and the variables declared in it, but no real way to edit a line out (or maybe hardcode a variable somehow). So basically i am asking for advice on option #2 or maybe some other option i am unaware of. Thanks
-
Hello there, We have this module at work who nobody knows where the source code is. It was behaving erratically on certain scenarios so i decided to decompile it (using DJ Java decompiler which btw works wonderfully) and found the problem line. Now the how to fix it, i can think of 2 ways: 1) I decompile everything, change the line and recompile The module is pretty large in amount of classes and submodules. I dont really feel confident that i can recompile everything right. 2) Editing the .class file somehow. Now i grabbed a class file editor that showed me bytecode, the method names and the variables declared in it, but no real way to edit a line out (or maybe hardcode a variable somehow). So basically i am asking for advice on option #2 or maybe some other option i am unaware of. Thanks
Option #2 is fine if you really understand the structure of the class file but it is so prone to errors that I would not recommend it for a commercial or business application. You would be much safer in recreating the source code and rebuilding the application from that. This is the second such question I've seen today; I would suggest a better use of source control systems for your company.
It's time for a new signature.
-
Option #2 is fine if you really understand the structure of the class file but it is so prone to errors that I would not recommend it for a commercial or business application. You would be much safer in recreating the source code and rebuilding the application from that. This is the second such question I've seen today; I would suggest a better use of source control systems for your company.
It's time for a new signature.
I'm totally agreed with you. If you don't have a better idea about the project/application structure better to take the second option. Patching the code like this is real headache in most of the cases.
I appreciate your help all the time... CodingLover :)
-
I'm totally agreed with you. If you don't have a better idea about the project/application structure better to take the second option. Patching the code like this is real headache in most of the cases.
I appreciate your help all the time... CodingLover :)
I think this could help you: First, take out the Java source code for that particular class using DJ de-compiler and save it as '.java' file to a separate location with the same name & in the same package. For same package you will have to create empty folders as per the desired package. Make the change you want into the Java code using any text editor or IDE. If you use IDE like eclipse, set the classes and jars which are available in that application into the classpath. :) Find out the JDK by which the original class file was compiled. In case of jar file, the JDK version could be found in the MENIFEST file. You will have to compile your new code using the same JDK. Generate the classfile either by IDE or by javac command from the JDK used in creating original class file. Keep a backup of the original jar file. Open the original jar file into Winrar or Winzip such that it shows the complete folder structure of the jar file. Open the folder in which the original class file is present. Delete the original class file and insert the new generated class file in its place. Close the Winzip/ Winrar application. You are done! keep this new jar in place of the original jar and enjoy. ~UJ
UJ, the Power Builder.