• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reverse and Recompile of Legacy Code  RSS feed

 
Francis Richter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Francis Richter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. Most things are hard at first; then we learn how to do them, at which point they become ridiculously easy :-)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!