Self Modifying Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Japcuh

    #1

    Self Modifying Code

    How do you write self modifying code in Java?

    Japcuh
    (Just Another Perl C Unix Hacker)

    ..0.
    ...0
    000
  • Eric Sosman

    #2
    Re: Self Modifying Code

    Japcuh wrote:[color=blue]
    > How do you write self modifying code in Java?[/color]

    What do you mean by "modify?" A Java program can
    extend itself by loading new classes on the fly, if
    that suits your needs.

    --
    Eric.Sosman@sun .com

    Comment

    • Roedy Green

      #3
      Re: Self Modifying Code

      On 2 Jul 2004 12:31:17 -0700, japcuh@gmail.co m (Japcuh) wrote or
      quoted :
      [color=blue]
      >How do you write self modifying code in Java?[/color]

      You can't modify a class once it has been loaded, but you can create a
      similar class and load that.

      You can do it by generating Java source and compiling that on the fly
      to byte codes, or by generating JVM byte codes directly.

      See http://mindprod.com/jgloss/eval.html



      --
      Canadian Mind Products, Roedy Green.
      Coaching, problem solving, economical contract programming.
      See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

      Comment

      • Kristian Larsen

        #4
        Re: Self Modifying Code

        japcuh@gmail.co m (Japcuh) wrote in news:3a8cbb2e.0 407021131.55805 361
        @posting.google .com:
        [color=blue]
        > How do you write self modifying code in Java?[/color]

        You may want to check out the Java code generation library cglib:


        Best Regards
        Kristian Larsen

        Comment

        • kjc

          #5
          Re: Self Modifying Code

          No, but this could be done in Smalltalk blind folded.

          Japcuh wrote:[color=blue]
          > How do you write self modifying code in Java?
          >
          > Japcuh
          > (Just Another Perl C Unix Hacker)
          > http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
          > .0.
          > ..0
          > 000[/color]

          Comment

          • Roedy Green

            #6
            Re: Self Modifying Code

            On Sat, 03 Jul 2004 15:49:21 GMT, kjc <ksitron@elp.rr .com> wrote or
            quoted :
            [color=blue]
            >No, but this could be done in Smalltalk blind folded.
            >
            >Japcuh wrote:[color=green]
            >> How do you write self modifying code in Java?[/color][/color]

            Is it a problem that you sometimes do it accidentally?

            --
            Canadian Mind Products, Roedy Green.
            Coaching, problem solving, economical contract programming.
            See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

            Comment

            • Andrew Chambers

              #7
              Re: Self Modifying Code

              > japcuh@gmail.co m (Japcuh) wrote in news:3a8cbb2e.0 407021131.55805 361[color=blue]
              > @posting.google .com:
              >[color=green]
              > > How do you write self modifying code in Java?[/color]
              >[/color]



              The metadata bit of this seems to suggest that in future releases of
              java, you'll be able to generate actual source code on the fly.

              Comment

              • Japcuh

                #8
                Re: Self Modifying Code

                Thanks for all the help.

                Japcuh
                (Just Another Perl C Unix Hacker)

                ..0.
                ...0
                000

                Comment

                • Joseph Daniel Zukiger

                  #9
                  Re: Self Modifying Code

                  andyfaeglasgow@ gmail.com (Andrew Chambers) wrote in message news:<f37001.04 07030819.5f2814 3d@posting.goog le.com>...[color=blue][color=green]
                  > > japcuh@gmail.co m (Japcuh) wrote in news:3a8cbb2e.0 407021131.55805 361
                  > > @posting.google .com:
                  > >[color=darkred]
                  > > > How do you write self modifying code in Java?[/color]
                  > >[/color]
                  >
                  > http://java.sun.com/developer/techni...leases/j2se15/
                  >
                  > The metadata bit of this seems to suggest that in future releases of
                  > java, you'll be able to generate actual source code on the fly.[/color]

                  I think the metadata is for hints for documentation generation.

                  I could be wrong.

                  But I'd hate to work out a security system for Java if they allow the
                  code to modify itself. Dynamically extending classes is plenty.

                  Comment

                  • Oliver Plohmann

                    #10
                    Re: Self Modifying Code

                    kjc <ksitron@elp.rr .com> wrote in message news:<5AAFc.125 77$mY2.621@fe1. texas.rr.com>.. .[color=blue]
                    > No, but this could be done in Smalltalk blind folded.[/color]

                    You can use Java Reflection which is Java's counterpart to Smalltalk's
                    perform: concatenate some strings to create an existing method name
                    and call that method. Or you can use the command pattern and add
                    commands as required to a list and execute them sequentially.

                    Cheers, Oliver
                    [color=blue]
                    > Japcuh wrote:[color=green]
                    > > How do you write self modifying code in Java?
                    > >
                    > > Japcuh
                    > > (Just Another Perl C Unix Hacker)
                    > > http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
                    > > .0.
                    > > ..0
                    > > 000[/color][/color]

                    Comment

                    • Java Architect

                      #11
                      Re: Self Modifying Code

                      Check out this package:




                      "Japcuh" <japcuh@gmail.c om> wrote in message
                      news:3a8cbb2e.0 407021131.55805 361@posting.goo gle.com...[color=blue]
                      > How do you write self modifying code in Java?
                      >
                      > Japcuh
                      > (Just Another Perl C Unix Hacker)
                      > http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
                      > .0.
                      > ..0
                      > 000[/color]


                      Comment

                      • Dave Monroe

                        #12
                        Re: Self Modifying Code

                        japcuh@gmail.co m (Japcuh) wrote in message news:<3a8cbb2e. 0407021131.5580 5361@posting.go ogle.com>...[color=blue]
                        > How do you write self modifying code in Java?
                        >
                        > Japcuh
                        > (Just Another Perl C Unix Hacker)
                        > http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
                        > .0.
                        > ..0
                        > 000[/color]

                        It's nowhere near as easy as it is in Perl.

                        If you look at JDBC you'll see that there's a call to Class.forName()
                        to load the driver class. That may be of use to you. It's sort of an
                        'import' on the fly.

                        Comment

                        • Michael N. Christoff

                          #13
                          Re: Self Modifying Code


                          "Japcuh" <japcuh@gmail.c om> wrote in message
                          news:3a8cbb2e.0 407021131.55805 361@posting.goo gle.com...[color=blue]
                          > How do you write self modifying code in Java?
                          >
                          > Japcuh
                          > (Just Another Perl C Unix Hacker)
                          > http://www.catb.org/~esr/faq/hacker-howto.htm#what_is
                          > .0.
                          > ..0
                          > 000[/color]

                          Look up "Javassist" on google. Its what JBoss 4.0 uses to do dynamic aspect
                          weaving and dynamic remote proxy generation among other things. By the way,
                          for those who have used cglib, can you point toward some good online docs?
                          I have been unable to find any I found adequate. Javassist has pretty good
                          docs however.



                          l8r, Mike N. Christoff



                          Comment

                          • Entropy

                            #14
                            Re: Self Modifying Code

                            japcuh@gmail.co m wrote...[color=blue]
                            > How do you write self modifying code in Java?[/color]

                            If it's truly self-modifying, good luck debugging it.

                            Comment

                            • Wiseguy

                              #15
                              Re: Self Modifying Code

                              Entropy <entropy@domain .invalid> scribbled on the stall wall:[color=blue]
                              > japcuh@gmail.co m wrote...[color=green]
                              >> How do you write self modifying code in Java?[/color]
                              >
                              > If it's truly self-modifying, good luck debugging it.[/color]

                              the simple answer is "you can't"...self modifying code hasn't really been
                              feasible since the fortran 4 days...or maybe in C but that is still
                              platform dependent.

                              ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
                              http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
                              ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

                              Comment

                              Working...