Results 1 to 5 of 5
  1. #1
    ykzforever is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default Help: how can get method, arg, return type... from a file .class

    This is the first time I visit this forum, and I hope I will receive all bros 's advices.
    This is my matter:
    I have a problem in taking method, args, return type from a file .class of Java. For example, from this file : A.java

    class A
    {
    public int add(int a, int b);
    }

    It will be compiled into A.class. I only have file A.class. And i must write java code to create a tool, input is compiled file A.class, output is :
    method "add"
    arg: "a" (int)
    arg: "b" (int)
    return: (int)

    of courses this is a simple example.

    I 've read program translate from file .class to file .java at link :
    vijaymukhi.com/vmis/jclass.htm
    , and this is source code in C++
    vijaymukhi.com/vmis/source.htm
    . In that program, they read file .class in binary, and translate each byte. But with me, this is so complex :(:(

    I want to ask, is there another way to get method, args, ... from file .class without read file .class in binary?
    And who can give me some sample of source code to solve this problem?

    Thanks for reading and answering a lot.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Perhaps you would like to clarify how it is that you have the .class files and don't have (and can't obtain) the source code.

    Do you have the legal right to reverse engineer those .class files?

  3. #3
    ykzforever is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Perhaps you would like to clarify how it is that you have the .class files and don't have (and can't obtain) the source code.

    Do you have the legal right to reverse engineer those .class files?
    Thanks for your reply.
    Further purpose of me is import detail that i took from .class file into WSDL (Web Services Description Language) - is alike one kind of XML. To write WSDL, i must have information from .class file such as method, argument, return data type,... So that, my work is:
    1. Compile file A.java into A.class
    2. Take details from A.class
    3. Using details from [2] to write WSDL

    Because i will group all of 3 steps above into one tool, so that i want to take details from A.class first.

    Thanks for reading.

  4. #4
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default Use your IDE/javap?

    If you just want the method signatures:
    (1) most IDEs will give you this if you load the class file into them;
    (2) the 'javap' command-line utility supplied with the JDK will dump out the method signatures of a given class.

    To the person who mentioned reverse-engineering-- I think you'd have a hard time argung that reading the method signatures from a .class file was "reverse engineering".

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Neil

    I think you'd have a hard time arguing that I argued that reading the method signatures from a .class file was "reverse engineering". Or don't you know the difference between a question and an accusation?

    I was going to suggest using a decompiler, in case the actual requirement was more than originally stated -- which is often the case, as you'll come to know when you have more experience of reading and responding to forum posts.

    cheers, db
    Last edited by DarrylBurke; 11-25-2008 at 06:59 AM.

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 09:05 PM
  2. Return value of method
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 09:23 AM
  3. return type determines override/overload?
    By hedefalk in forum Advanced Java
    Replies: 4
    Last Post: 07-11-2007, 02:48 PM
  4. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •