get the source code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    get the source code

    is there a function or a way to get the source code of the program and display it?
    i need to display the source code of java program simple hello world would be enough:)
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Like this?

    Code:
    class S{public static void main(String[]a){String s="class S{public static void main(String[]a){String s=;char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}";char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}
    kind regards,

    Jos

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Basically, if you have the .java file, just open it with an editor (e.g. notepad). If you don't, you can decode it from a .class file with specific programs. (The legality of this may vary, depending on the licence and country you are in.) And if you have a .jar file, you can unpack that first - a jar file is just a zip file with a different extension and a MANIFEST file.

      Greetings,
      Nepomuk

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Two nitpicks:

        1) a jar file doesn't always need a MANIFEST file;
        2) what to do if there's no .java source file around?

        kind regards,

        Jos

        Comment

        • Nepomuk
          Recognized Expert Specialist
          • Aug 2007
          • 3111

          #5
          OK, there doesn't have to be a Manifest file. But I answered that "what if there's no .java file" question already. Second sentence... ^^

          Greetings,
          Nepomuk

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Nepomuk
            OK, there doesn't have to be a Manifest file. But I answered that "what if there's no .java file" question already. Second sentence... ^^
            Have you ever seen the result of a Java decompiler? They're all crap from what I have seen. It doesn't even compile anymore.

            kind regards,

            Jos

            Comment

            • Nepomuk
              Recognized Expert Specialist
              • Aug 2007
              • 3111

              #7
              Actually, I have and for simple programs at least, the output can be quite good. Don't know which decompilers you used of course.

              Greetings,
              Nepomuk

              Comment

              • oll3i
                Contributor
                • Mar 2007
                • 679

                #8
                no no i just need to write a simple program that displays its source code

                Comment

                • oll3i
                  Contributor
                  • Mar 2007
                  • 679

                  #9
                  but that would mean i have to write a decompiler

                  Comment

                  • oll3i
                    Contributor
                    • Mar 2007
                    • 679

                    #10
                    hmm and how do i strat ? hm hm hm

                    Comment

                    • oll3i
                      Contributor
                      • Mar 2007
                      • 679

                      #11
                      so this program will have to read in .class file and then output the source code
                      i will have to look for patterns?

                      Comment

                      • Nepomuk
                        Recognized Expert Specialist
                        • Aug 2007
                        • 3111

                        #12
                        You don't have to write one yourself, no. I've used DJ Decompiler in the past and was quite pleased with it. However as I said, make sure the licence of whatever you're decompiling actually allows to do so.

                        Greetings,
                        Nepomuk

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by oll3i
                          no no i just need to write a simple program that displays its source code
                          Programs that display their own source code are called a "quinne"; see my reply #2.

                          kind regards,

                          Jos

                          Comment

                          Working...