Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: how to read a .class file

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to read a .class file

    Well, I don't have the source for some app. I already decompiled the apk and decompiled the jar file. Now, my question is how do I edit the .class file? Is there any way to do that? Any help with links would be appreciated.
    Thank you guys


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: how to read a .class file

    Quote Originally Posted by cowsquad View Post
    W... Now, my question is how do I edit the .class file? Is there any way to do that? ...
    You don't. You make edits to the .java file obtained from decompilation and then compile that into a new .class file.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by curmudgeon View Post
    You don't. You make edits to the .java file obtained from decompilation and then compile that into a new .class file.
    So i probably am decompiling the wrong because I don't get any .java file. Do you mind sharing a decompiler. I am using dex2jar right now

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how to read a .class file

    Quote Originally Posted by curmudgeon View Post
    You don't. You make edits to the .java file obtained from decompilation and then compile that into a new .class file.
    I agree with curmudgeon that you most likely don't want to do this. If you can get the source, edit that. If you can't, then there's probably a good reason for that and reverse-engineering/cracking the compiled .class files is not recommended.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by helloworld922 View Post
    I agree with curmudgeon that you most likely don't want to do this. If you can get the source, edit that. If you can't, then there's probably a good reason for that and reverse-engineering/cracking the compiled .class files is not recommended.
    Of course I can get the source for it, it is and android app. So I will do that. I was just wondering possibilities.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: how to read a .class file

    Quote Originally Posted by cowsquad View Post
    Of course I can get the source for it, it is and android app. So I will do that. I was just wondering possibilities.
    Usually that process involves breaking a law, so beware what you decompile. You probably didn't get any .java files because the source was not packed. Which makes a flag stand out on the "might be illegal" category, but does not necessarily mean it is. You can turn the .class into .java with a different program but all non-keywords are not going to be so easy to understand without really knowing how to see what is there. If you can get the original .java files like they said above, that is the best option as the .java files are likely to have good variable/method/etc names, comments, and possibly even javadoc. You can get to the same point (access to functional source code) both ways, but .java files are the easiest as far as what you have to do.

  7. #7
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jps View Post
    Usually that process involves breaking a law, so beware what you decompile. You probably didn't get any .java files because the source was not packed. Which makes a flag stand out on the "might be illegal" category, but does not necessarily mean it is. You can turn the .class into .java with a different program but all non-keywords are not going to be so easy to understand without really knowing how to see what is there. If you can get the original .java files like they said above, that is the best option as the .java files are likely to have good variable/method/etc names, comments, and possibly even javadoc. You can get to the same point (access to functional source code) both ways, but .java files are the easiest as far as what you have to do.
    I am not trying to break the law :-) I was trying to understand how reverse engineering really work. I decompile an apk that I have the source for it, and there are some methods that don't look alike .thank all of you for your kind and helpful answers :-)

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: how to read a .class file

    Quote Originally Posted by cowsquad View Post
    I am not trying to break the law :-)
    Of course not. I am not accusing you, just so it was said.


    Quote Originally Posted by cowsquad View Post
    I was trying to understand how reverse engineering really work.
    Yes, for educational purposes. Learning is fun.


    Quote Originally Posted by cowsquad View Post
    I decompile an apk that I have the source for it, and there are some methods that don't look alike .
    Did you get it figured out?


    Quote Originally Posted by cowsquad View Post
    thank all of you for your kind and helpful answers :-)
    You are welcome.

  9. #9
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jps View Post
    Of course not. I am not accusing you, just so it was said.


    Yes, for educational purposes. Learning is fun.


    Did you get it figured out?


    You are welcome.
    I am trying to understand all this java thing, but having trouble understanding how to download source code from the web into my PC, and then editing that :-(

  10. #10
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: how to read a .class file

    What source code do you have? Post a sample or describe what exactly you have. What format it is in etc.
    What do you mean by edit it? Post the code you have questions about editing.

Similar Threads

  1. Read input, read file, find match, and output... URGENT HELP!
    By MooseHead in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 3rd, 2012, 11:01 AM
  2. Java I/O File code; how to read/write file
    By ryu2le in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 18th, 2011, 05:51 PM
  3. Read a text file and parse the contents of file
    By HelloAll in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 3rd, 2011, 04:47 AM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  5. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM