Forums Register Login

Reverse and Recompile of Legacy Code

+Pie Number of slices to send: Send
Not 100% sure this is suitably advanced for the section, however I've asked around elsewhere and nobody seems to have an answer.


We have (and enjoy exclusive rights over) a .jar legacy application of some 300 classes. Unfortunately, The original developer is no longer contactable (read: out of business) and source appears not to be available on site.


One class requires amending and I confident in my ability to update this class using a standard decompiler.


Here's the question...

Is it possible to recompile the repaired class (Either from recovered Jasmin Bytecode or preferably Java Source) without first recreating the *entire* source tree. My admitedly incomplete understanding of the Java file format tells me that this should be possible particularly since we will not be changing the class interface in any way... however, all of the compilers I've looked at so far seem to insist on dependency checking.


Can any clever java guru propose a solution to this problem ? Or is a complete source tree absolutely necessary ?

My main aim at present is to simply recreate a modified class file using an unchecked compile and simply use it as a drop-in replacement for the current Jar

Any tools or obscure commandline hints for achieving this would be most welcome.

Regards,


-Francis R
+Pie Number of slices to send: Send
Welcome to JavaRanch.

Yes, that's easily doable. After decompiling and changing that one class, you can recompile it by keeping the original jar file in the classpath. That way you don't need all the other decompiled source files. It doesn't matter that the jar file still has the original class in it; compilcation will work fine.
+Pie Number of slices to send: Send
Many thanks for the prompt reply.

It seems this question was actually rather straightforward. I had a terrible feeling I needed to apply my fix in bytecode and rebuild the class from a Jasmin file.

My apologies to the boards moderators for posting in the wrong section.. and, again, thanks Ulf.


Regards,

-Francis R
+Pie Number of slices to send: Send
You're welcome. Most things are hard at first; then we learn how to do them, at which point they become ridiculously easy :-)
+Pie Number of slices to send: Send
There is some possibility for trouble if you keep the original jar with the original version of the clas around. If you're not careful with the classpath, you might end up running the old version rather than the new one. I would unjar everything, remove the original version of the class, compile a new one, and then re-jar. But you don't need to decompile everything, fortunately.
[ February 27, 2008: Message edited by: Jim Yingst ]
+Pie Number of slices to send: Send
Would there be a problem in decompiling everything and then recompiling? I ask because you may not be sure what would happen if the changed class were compiled with a different compiler to the other classes.
+Pie Number of slices to send: Send
 

Originally posted by Roger Chung-Wee:
Would there be a problem in decompiling everything and then recompiling?


With 300 classes the likelihood is high that some classes won't be decompiled correctly, and couldn't be recompiled. E.g., synthetic fields often cause problems with the various common decompilers.
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 715 times.
Similar Threads
java web start (jre) incompatibilities
compiling code using different versions (jdk 1.3 and jdk 1.4)
ARGH! Package problem while using *
"Could not find main class" problem in jar file
When to stop using a properties file?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:42:43.