reverse engineering of java code

R

ram

hi guys,
iam developing an application which takes input as ".
java/.cpp"[i.e java/cpp source code] and gives output as " classes ,
sub classes,objects,methods"
of that source code.
can you guys help me out, is there ready made method,
classes ,packages to implement this?.
can you suggest me how to proceed.
hey pls don't comment on simplicity of problem, iam newbie.
 
J

Joshua Cranmer

ram said:
hi guys,
iam developing an application which takes input as ".
java/.cpp"[i.e java/cpp source code] and gives output as " classes ,
sub classes,objects,methods"
of that source code.

Java != C++. (Java and C++ are not the same)
Java !< C++. (Java is not a strict subset of C++)
Java !> C++. (Java is not a strict superset of C++)

No code that is capable of handling Java or C+ cannot handle the other
without some (often major) modifications.
can you guys help me out, is there ready made method,
classes ,packages to implement this?.

That said, there are two ways to do this:

1. Go through the JLS 3 and right your own lexer and parser that
manually looks for the class, method, and field (I presume that is what
you meant by 'objects') expressions.

2. Pipe the source code through a Java compiler and parse the resultant
class file for the class, subclasses, fields, and methods.
can you suggest me how to proceed.
hey pls don't comment on simplicity of problem, iam newbie.

Simple, this? You're talking about either implementing a LALR parser or
interfacing a compiler whether through the runtime compiler interface
new to Java 6, the undocumented Java 5 (and older) compiler interface in
tools.jar, or running a subprocess and then parsing a class file (the
spec (chapter 4 of the JVM spec 2 1.5 addendum is only ~ 80 pages long;
Java 6's addendum is another 100 or so pages on that). In short, this is
not a task for a "newbie" to work on.

The best way to proceed is to wet your feet on simpler topics. Roedy has
some pages about simple projects for beginners (see several other
threads for links).
 
M

Mike Schilling

ram said:
hi guys,
iam developing an application which takes input as ".
java/.cpp"[i.e java/cpp source code] and gives output as " classes ,
sub classes,objects,methods"
of that source code.
can you guys help me out, is there ready made method,
classes ,packages to implement this?.
can you suggest me how to proceed.
hey pls don't comment on simplicity of problem, iam newbie.

By far the simplest way to do this is to compile the Java source and use
reflection (see java.lang.reflect) on the result.
 
J

Joe Attardi

ram said:
hi guys,
iam developing an application which takes input as ".
java/.cpp"[i.e java/cpp source code] and gives output as " classes ,
sub classes,objects,methods"
of that source code.
can you guys help me out, is there ready made method,
classes ,packages to implement this?.
can you suggest me how to proceed.
hey pls don't comment on simplicity of problem, iam newbie.

There are already lots of applications that can do this. One such
program is included with the JDK: javap. Although, it's slightly
different in that you run it against .class files instead of .java files.

javap <class name>.

For example, javap java.lang.Object outputs:

Compiled from "Object.java"
public class java.lang.Object{
public java.lang.Object();
public final native java.lang.Class getClass();
public native int hashCode();
public boolean equals(java.lang.Object);
protected native java.lang.Object clone() throws
java.lang.CloneNotSupportedException;
public java.lang.String toString();
public final native void notify();
public final native void notifyAll();
public final native void wait(long) throws
java.lang.InterruptedException;
public final void wait(long, int) throws
java.lang.InterruptedException;
public final void wait() throws java.lang.InterruptedException;
protected void finalize() throws java.lang.Throwable;
static {};
}
 
J

Jeff Higgins

ram said:
hi guys,
iam developing an application which takes input as ".
java/.cpp"[i.e java/cpp source code] and gives output as " classes ,
sub classes,objects,methods"
of that source code.
 
R

Roedy Green

R

ram

ram said:
hi guys,
iam developing an application which takes input as ".
java/.cpp"[i.e java/cpp source code] and gives output as " classes ,
sub classes,objects,methods"
of that source code.
can you guys help me out, is there ready made method,
classes ,packages to implement this?.
can you suggest me how to proceed.
hey pls don't comment on simplicity of problem, iam newbie.

There are already lots of applications that can do this. One such
program is included with the JDK: javap. Although, it's slightly
different in that you run it against .class files instead of .java files.

javap <class name>.

For example, javap java.lang.Object outputs:

Compiled from "Object.java"
public class java.lang.Object{
public java.lang.Object();
public final native java.lang.Class getClass();
public native int hashCode();
public boolean equals(java.lang.Object);
protected native java.lang.Object clone() throws
java.lang.CloneNotSupportedException;
public java.lang.String toString();
public final native void notify();
public final native void notifyAll();
public final native void wait(long) throws
java.lang.InterruptedException;
public final void wait(long, int) throws
java.lang.InterruptedException;
public final void wait() throws java.lang.InterruptedException;
protected void finalize() throws java.lang.Throwable;
static {};

}

thanx a lot for quick and sincere support.
 
R

Roedy Green

The best way to proceed is to wet your feet on simpler topics. Roedy has
some pages about simple projects for beginners (see several other
threads for links).

see http://mindprod.com/project/projects.html
for project ideas. They are graded by difficulty, financial potential
and how many existing implementations there are.

I find it odd so many people tackle projects where there are over:20
implementations already, e.g. SQL engine, servlet womb, drawing
package, rules engine, xml parser.
 
P

Patricia Shanahan

Roedy said:
see http://mindprod.com/project/projects.html
for project ideas. They are graded by difficulty, financial potential
and how many existing implementations there are.

I find it odd so many people tackle projects where there are over:20
implementations already, e.g. SQL engine, servlet womb, drawing
package, rules engine, xml parser.

Deciding whether the task is feasible, and its approximate scope, is a
difficult part of project selection. If there is at least one existing
implementation there is a proof by example that it can be implemented in
no more than N lines of Java for some N.

Patricia
 
R

Roedy Green

Deciding whether the task is feasible, and its approximate scope, is a
difficult part of project selection. If there is at least one existing
implementation there is a proof by example that it can be implemented in
no more than N lines of Java for some N.

Sometimes it is even possible to peak at existing code, or
disassembler it. I still think re-inventing the wheel with only
trivial changes is cowardly and a waste of time. There are SO many
projects out there with no implementations at all or with just utterly
inept implementations. I have listed many of them at
http://mindprod.com/project/projects.html
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top