reverse engineering of java code

Discussion in 'Java' started by ram, Aug 21, 2007.

  1. ram

    ram Guest

    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.
     
    ram, Aug 21, 2007
    #1
    1. Advertising

  2. ram wrote:
    > 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).

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Aug 21, 2007
    #2
    1. Advertising

  3. ram wrote:
    > 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.
     
    Mike Schilling, Aug 21, 2007
    #3
  4. ram

    Joe Attardi Guest

    ram wrote:
    > 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 {};
    }



    --
    Joe Attardi
     
    Joe Attardi, Aug 21, 2007
    #4
  5. ram

    Jeff Higgins Guest

    ram wrote:
    > 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.

    Doxygen? <http://www.stack.nl/~dimitri/doxygen/>
    > 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.
    >
     
    Jeff Higgins, Aug 21, 2007
    #5
  6. ram

    Roedy Green Guest

    On Tue, 21 Aug 2007 07:53:27 -0700, ram <>
    wrote, quoted or indirectly quoted someone who 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.


    See http://mindprod.com/jgloss/decompiler.html
    http://mindprod.com/jgloss/disasssembler.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 22, 2007
    #6
  7. ram

    ram Guest

    On Aug 21, 8:51 pm, Joe Attardi <> wrote:
    > ram wrote:
    > > 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 {};
    >
    > }
    >
    > --
    > Joe Attardi
    >


    thanx a lot for quick and sincere support.
     
    ram, Aug 22, 2007
    #7
  8. ram

    Roedy Green Guest

    On Tue, 21 Aug 2007 15:40:31 GMT, Joshua Cranmer
    <> wrote, quoted or indirectly quoted someone who
    said :

    >
    >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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 22, 2007
    #8
  9. Roedy Green wrote:
    > On Tue, 21 Aug 2007 15:40:31 GMT, Joshua Cranmer
    > <> wrote, quoted or indirectly quoted someone who
    > said :
    >
    >> 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.


    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
     
    Patricia Shanahan, Aug 22, 2007
    #9
  10. ram

    Roedy Green Guest

    On Wed, 22 Aug 2007 06:02:53 -0700, Patricia Shanahan <>
    wrote, quoted or indirectly quoted someone who said :

    >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
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 23, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bradphelan
    Replies:
    2
    Views:
    1,478
    Rod Pemberton
    Oct 26, 2006
  2. mary
    Replies:
    2
    Views:
    3,058
    Ivan Vecerina
    Nov 7, 2006
  3. NicolasG
    Replies:
    3
    Views:
    328
    Ben Finney
    Aug 8, 2007
  4. Jim Cochrane

    Reverse engineering OO perl code

    Jim Cochrane, Aug 29, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    111
    Jim Cochrane
    Sep 5, 2007
  5. NABIL.B

    Reverse engineering of Perl Code

    NABIL.B, Nov 18, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    165
    Wanna-Be Sys Admin
    Nov 19, 2009
Loading...

Share This Page