decompiling class files

  • Thread starter Aryeh M. Friedman
  • Start date
A

Aryeh M. Friedman

In switch machines I lost a critical set or source code but I still
have the .class files is there anyway decompile them and/or make my
life a little easier instead of a ground up rewrite (will take maybe 4
hours)
 
M

Manish Pandit

In switch machines I lost a critical set or source code but I still
have the .class files is there anyway decompile them and/or make my
life a little easier instead of a ground up rewrite (will take maybe 4
hours)

JAD (http://www.kpdus.com/jad.html) is pretty common dis-assembler for
Java class files.

-cheers,
Manish
 
S

Sherman Pendley

Aryeh M. Friedman said:
In switch machines I lost a critical set or source code but I still
have the .class files is there anyway decompile them and/or make my
life a little easier instead of a ground up rewrite (will take maybe 4
hours)

Decompilers exist, but you'd have to google around (for "java decompiler"),
download one, install it, spend some time getting familiar with it, etc.
And after you were done, you'd have only the .java files - you'd still have
to recreate the IDE project, ant file, or whatever other build environment
you used for it.

You'd be just as well off doing the four-hour rewrite, IMHO.

sherm--
 
A

Aryeh M. Friedman

Decompilers exist, but you'd have to google around (for "java decompiler"),
download one, install it, spend some time getting familiar with it, etc.
And after you were done, you'd have only the .java files - you'd still have
to recreate the IDE project, ant file, or whatever other build environment
you used for it.

You'd be just as well off doing the four-hour rewrite, IMHO.

Took 45 mins with Jad. Very obvious command line interface (jad
*.class) and then just some file manipulation to move it back to the
right location.... Since I don't use an IDE it was probably easier
then typical
 
L

Lew

Took 45 mins with jad

That is very impressive.

I will look into this Jad thing. Does it do Java 6?

It doesn't look like any of the ones mentioned on mindprod.com are new enough
to handle Java 6.

I do see that
since the version 1.5.6 it's no longer free for commercial use.
... At the same time, Jad can be used freely for personal needs
in a commercial or non-commercial environments.

So the loss of comments and local variable names wasn't a problem?

What about all the Javadocs? How long did it take to redo those?
 
M

Mike Schilling

Lew said:
That is very impressive.

I will look into this Jad thing. Does it do Java 6?

It doesn't look like any of the ones mentioned on mindprod.com are
new enough to handle Java 6.

I do see that

So the loss of comments and local variable names wasn't a problem?

If the .class file was compiled for debug, jad will preserve local variable
names.
 
A

Aryeh M. Friedman

That is very impressive.

I will look into this Jad thing. Does it do Java 6?

It doesn't look like any of the ones mentioned on mindprod.com are new enough
to handle Java 6.

No I had to redo the generics by hand and thats why it was 45 mins not
15. (I will at some point have to go back and rename/restyle stuff
also)
I do see that


So the loss of comments and local variable names wasn't a problem?

If your goal is to get back your work without having to do an other
debug cycle yes... but if it is maintain the complete formating of the
orginal code oh well.
What about all the Javadocs? How long did it take to redo those?

That is part of the renaming/restyling but in my case it is only 10
classes and about 3 methods each so it was pretty fast.
 
L

Lew

Aryeh said:
No I had to redo the generics by hand and thats why it was 45 mins not
15. (I will at some point have to go back and rename/restyle stuff
also)

So the 45 minutes is not true. I was counting the rename/restyle in my
estimate of how long it would take.
 
P

Patricia Shanahan

Lew said:
I repeat:

There are two milestones in this sort of recovery:

1. Getting to the point of having source code that can compiled,
supporting continued development in other parts of the system.

2. Being fully whole, with meaningful identifiers, javadocs, etc.

Milestone #1 could be on the critical path for current development. In
that case, I would look for the fastest way to achieve it, even if it is
not necessarily any faster at getting to milestone #2. The remaining
work needs doing, but can be done on a less urgent basis, perhaps as
part of a refactoring pass.

Patricia
 
M

Mike Schilling

Patricia said:
There are two milestones in this sort of recovery:

1. Getting to the point of having source code that can compiled,
supporting continued development in other parts of the system.

2. Being fully whole, with meaningful identifiers, javadocs, etc.

Milestone #1 could be on the critical path for current development. In
that case, I would look for the fastest way to achieve it, even if it
is not necessarily any faster at getting to milestone #2. The
remaining work needs doing, but can be done on a less urgent basis,
perhaps as part of a refactoring pass.

It's not obvious to me that the "four hour" estimate was for milestone 2
rather than milestone 1. The other advantage of the decompilation route is
that it's much less likely to introduce subtle changes in behavior than
rewriting from scratch would be.
 
J

Joshua Cranmer

Lew said:
It doesn't look like any of the ones mentioned on mindprod.com are new
enough to handle Java 6.

Well, I am currently writing a Java decompiler capable of handling Java
6 right now.
> What about all the Javadocs? How long did it take to redo those?

One of my ideas is to add on a filter that can reproduce the Javadoc
comments from the HTML documentation files.

Would you like me to tell you when I finish it?
 
M

Mike Schilling

Joshua said:
Well, I am currently writing a Java decompiler capable of handling
Java 6 right now.


One of my ideas is to add on a filter that can reproduce the Javadoc
comments from the HTML documentation files.

What about generating empty Javadoc descriptions of all the methods?
(assuming there's enough debug information present to get the parameter
names right.)

Speaking of which, I'd assumed a decompiler like jad wuld only find local
variable names when the java file was compiled -g, but I see them being
correct even with -g:none. Is the local variable table always present?
 
L

Lew

Excellent points, and convincing.

Mike said:
It's not obvious to me that the "four hour" estimate was for milestone 2

Sorry, it was meant to represent complete recovery of the class. It never
occurred to me that a partial recovery could be acceptable, or I'd've
accounted for that possibility.

I also hadn't known how easy Jad was to use, as I mentioned upthread. So even
though I meant milestone #2 (not being aware that there was an earlier
milestone), I was still wrong.
rather than milestone 1. The other advantage of the decompilation route is
that it's much less likely to introduce subtle changes in behavior than
rewriting from scratch would be.

Another good point.
 
A

Aryeh M. Friedman

What about generating empty Javadoc descriptions of all the methods?
(assuming there's enough debug information present to get the parameter
names right.)

Even if the names are not quite right you will have all your @params,
@returns and @throws so that will help a lot for large projects
(global search and replace is your friend)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top