This forum is in archive mode. You will not be able to post new content.

Author Topic: Program that can write its own code in C++?  (Read 5942 times)

0 Members and 3 Guests are viewing this topic.

Offline Vacrin

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Program that can write its own code in C++?
« on: October 14, 2012, 02:30:04 AM »
Hello everyone, im looking for code that i can make write its own kind of code if i tell it to. I know that it can be done, but i have yet to see the code for such a program.


Thank you

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: Program that can write its own code in C++?
« Reply #1 on: October 14, 2012, 01:21:35 PM »

Offline Polyphony

  • VIP
  • Knight
  • *
  • Posts: 178
  • Cookies: 23
    • View Profile
Re: Program that can write its own code in C++?
« Reply #2 on: October 14, 2012, 07:21:03 PM »
I know there are ways to do this with zip files too.
Code: [Select]
http://www.steike.com/code/useless/zip-file-quine/droste.zip for example

Code: [Select]
<Spacecow_> for that matter I have trouble believing bitches are made out of ribs
<Gundilido> we are the revolutionary vanguard fighting for the peoples right to display sombrero dawning poultry
<Spacecow> did they see your doodle?
<~phage> Maybe
<+Unresolved> its just not creative enough for me
<+Unresolved> my imagination is to big to something so simple

pllaybuoy

  • Guest
Re: Program that can write its own code in C++?
« Reply #3 on: October 14, 2012, 07:26:05 PM »
Ugh ugh , provide more details please

Offline Vacrin

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: Program that can write its own code in C++?
« Reply #4 on: October 14, 2012, 08:11:39 PM »
a quine just displays its own source code, im looking for a program or the code of a program that can write more code into itself while it is compiled or in runtime.

so basically if i have a program that does nothing but accept code, then i can give it the location of a piece of code i want to insert lets say it was cout << "hello"; well then now the code can say hello when it is activated, but i dont want to go into the source code to edit it, i would like to edit it while it is in runtime or something.

this is much different from a quine because a quine only displays its own code which can be done with cout << easily

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: Program that can write its own code in C++?
« Reply #5 on: October 14, 2012, 08:32:40 PM »
AFAIK, you won't be able to do this with a AOT (ahead of time) compiled program (e.g. most C compilers), but it can be possible by using a JIT (just in time) compiler (like py2exe)
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: Program that can write its own code in C++?
« Reply #6 on: October 14, 2012, 09:12:51 PM »
You can make a process execute dynamic code that it reads / receives from somewhere.
If you are using a compiled language you will have to send it pre-compiled (or include a compiler in your executable, which is not very efficient).
With scripting languages you can use eval().

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: Program that can write its own code in C++?
« Reply #7 on: October 14, 2012, 09:21:41 PM »
If you are using a compiled language you will have to send it pre-compiled (or include a compiler in your executable, which is not very efficient).

JIT compiler have a compiler included wich compiles bytecode to machine code.That makes loading the application much more efficient than with AOT compiler, and as it compiles the code segment just before executing,executing it is faster than with a interpreter...

So a JIT compiler combine the advantages of a AOT compiler and a Interpreter
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline Vacrin

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: Program that can write its own code in C++?
« Reply #8 on: October 14, 2012, 10:46:19 PM »
So using one of these compilers code i write a program that can then access its own code through the compiler and then write and recompile itself all while it is still running or would it have to restart itself?

Offline Live Wire

  • Knight
  • **
  • Posts: 189
  • Cookies: 4
  • Up on your Net
    • View Profile
Re: Program that can write its own code in C++?
« Reply #9 on: October 14, 2012, 11:01:07 PM »
I'm 90 percent sure that it would have to restart itself. Whenever I've tried something like this, I always end up writing a program to execute, and a program to modify. I'm actually interested in the answer now.
"There is no right or wrong, there is only fun and boring."

Offline Vacrin

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: Program that can write its own code in C++?
« Reply #10 on: October 15, 2012, 06:30:31 AM »
i had that idea or a back and forth kinda idea, meaning i would make 2 programs, but they can edit each other so when one has to write a new code it adds it to the other and runs it and closes itself and then when the other one has to add a line it adds what was added to it and the line it has to add and then runs the other one and closes itself... dont know how productive it would be however

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: Program that can write its own code in C++?
« Reply #11 on: October 15, 2012, 07:01:38 AM »
What can be done is have a compiled exe (since we are in the C/C++ section) that does nothing until you append data (or information) to the existing binary file. See http://stackoverflow.com/questions/2266735/make-an-executable-at-runtime

You could also right code that invoke a compiler (GCC).

But having code compiled at runtime by a compiled executable is far from simple. It is way easier to do with scripting languages.
Satan911
Evilzone Network Administrator

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: Program that can write its own code in C++?
« Reply #12 on: October 15, 2012, 01:15:29 PM »
Yes, just use a scripting language. You can modify the source at runtime, the have itself restart or like mentioned something like eval() (not recommended though). Using eval() or similar method to execute code from an outside source is a big security hole.
>>>import this
-----------------------------

Offline Daemon

  • VIP
  • Baron
  • *
  • Posts: 845
  • Cookies: 153
  • A wise man fears a gentle mans anger
    • View Profile
Re: Program that can write its own code in C++?
« Reply #13 on: October 15, 2012, 08:07:41 PM »
isn't that just self-modifying code?

 http://en.m.wikipedia.org/wiki/Self-modifying_code
This lifestyle is strictly DIY or GTFO - lucid

Because sexploits are for h0edays - noncetonic


Xires burns the souls of HF skids as a power supply

Offline Vacrin

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 0
    • View Profile
Re: Program that can write its own code in C++?
« Reply #14 on: October 16, 2012, 04:42:46 AM »
Yes, that is what it is, i just said it differently xD

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.