473,796 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Self-reproducing program in Ken Thompson's Turing paper

Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,
http://www.acm.org/classics/sep95/ . Can this be done in C? How can a
program at runtime know its compiling-time source code?

May 10 '07 #1
11 4060
lovecreatesbea. ..@gmail.com <lo************ ***@gmail.comwr ote:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,
http://www.acm.org/classics/sep95/ . Can this be done in C? How can a
program at runtime know its compiling-time source code?
Sure.

#include <stdlib.h>

int main( void ) {
system( "links http://www.google.com" ); /* On DS9K, may open "link"
to the Underdark, beware */
return 0;
}

Surely you've posted here often enough to know that you'll get "STFW"
for an answer to this question? Certainly quines have been discussed
many times on this very newsgroup.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gma il.com | don't, I need to know. Flames welcome.
May 10 '07 #2
On May 10, 11:23 am, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,http://www.acm.org/classics/sep95/. Can this be done in C?
Gosh, I don't know. Maybe I should do a web search, or check the FAQ
or try to run the
strange looking code that shows up in people's signatures.
How can a
program at runtime know its compiling-time source code?
In general it can't, but most programs are not self-reproducing..
However, given that the runtime is a function of the source code,
maybe it
would be possible to choose the source code so that the runtime
prints out this source code. Maybe I should do a web search, or check
the FAQ or try to run the
strange looking code that shows up in people's signatures.

--
William Hughes

10 LIST

May 10 '07 #3
On 10 May, 16:23, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,http://www.acm.org/classics/sep95/. Can this be done in C? How can a
program at runtime know its compiling-time source code?

http://www.nyx.net/~gthompso/quine.htm
May 10 '07 #4
"lovecreatesbea ...@gmail.com" <lo************ ***@gmail.comwr ites:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,
http://www.acm.org/classics/sep95/ . Can this be done in C? How can a
program at runtime know its compiling-time source code?
The comp.lang.c FAQ is at <http://www.c-faq.com/>. You've just asked
question 20.34.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 10 '07 #5
On May 10, 11:23 am, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,http://www.acm.org/classics/sep95/. Can this be done in C? How can a
program at runtime know its compiling-time source code?
Others have pointed you at various resources wrt writing C quines.
They have answered your basic question.

But, if that's all you got out of Ken T's paper, then you missed a
lot.

His paper wasn't so much about quines as stand-alone programs, but
with the potential security exposures that quines (when incorporated
into C compilers) could have. He pointed out that a compiler could
imbed a trap-door security breach into anything it compiles, and (if
the compiler was compiled with itself), that trap-door could be
hidden /in the program/ rather than in the source code.

The quine comes from the compiler compiling in the security breach
insertion code into the (2nd generation) compiler - a quine in object
code rather than a quine in source code.

--
Lew

May 10 '07 #6
Lew Pitcher <lp******@teksa vvy.comwrote:
But, if that's all you got out of Ken T's paper, then you missed a
lot.

His paper wasn't so much about quines as stand-alone programs, but
with the potential security exposures that quines (when incorporated
into C compilers) could have. He pointed out that a compiler could
imbed a trap-door security breach into anything it compiles, and (if
the compiler was compiled with itself), that trap-door could be
hidden /in the program/ rather than in the source code.
Mind you, that trap-door only works if you assume that the compiler will
only be used to compile itself. It doesn't work if you use it to compile
an unrelated compiler of another language, which is used to compile a
cross-compiler of a language using another paradigm, which is used to
compile - for a different CPU - an interpreter for yet another language,
which is used to interpret a re-cross-compiler of the original language.
Bonus points if any of the architectures involved is completely virtual;
more bonus points if any of the languages was designed specifically for
this purpose.

Richard
May 11 '07 #7

"Lew Pitcher" <lp******@teksa vvy.comha scritto nel messaggio
news:11******** **************@ u30g2000hsc.goo glegroups.com.. .
On May 10, 11:23 am, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
>Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing
paper,http://www.acm.org/classics/sep95/. Can this be done in C? How can
a
program at runtime know its compiling-time source code?

Others have pointed you at various resources wrt writing C quines.
They have answered your basic question.

But, if that's all you got out of Ken T's paper, then you missed a
lot.

His paper wasn't so much about quines as stand-alone programs, but
with the potential security exposures that quines (when incorporated
into C compilers) could have. He pointed out that a compiler could
imbed a trap-door security breach into anything it compiles, and (if
the compiler was compiled with itself), that trap-door could be
hidden /in the program/ rather than in the source code.

The quine comes from the compiler compiling in the security breach
insertion code into the (2nd generation) compiler - a quine in object
code rather than a quine in source code.
Huh?

--
#include <stdlib.h>
int main(int argc, char *argv[])
{
return system(argv[0]);
}
May 11 '07 #8
Richard Bos wrote:
>
Mind you, that trap-door only works if you assume that the compiler will
only be used to compile itself.
Only??! It will work in more cases than that.

The seriousness here, is that system programs are typically written in
C, and C compilers are typically written in C.

If you develop a new C compiler, and use the infected compiler when
bootstrapping, the backdoor will be inherited. Also, if you create a C
cross compiler, the backdoor will be passed forward.

The payload, can even be targeted for multiple platforms.
--
Tor
May 17 '07 #9
lovecreatesbea. ..@gmail.com wrote:
Ken Thompson mentioned a self-reproducing program that products an
exact copy of its source code as output in his 1983 Turing paper,
http://www.acm.org/classics/sep95/ . Can this be done in C? How can a
program at runtime know its compiling-time source code?
This is a brilliant paper, read it carefully.I have given this puzzle to
student/junior programmers, multiple times.

If you really want to learn something, try hard to solve this puzzle in
C yourself. Seeing a solution, gives you little.
--
Tor <torust [at] online [dot] no>
May 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4729
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e = IntVar() for part, list in info.masterList.items():
15
2599
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html ****************************************************************************** Hi fellow Python coders, I often find myself writing:: class grouping:
18
2289
by: Ralf W. Grosse-Kunstleve | last post by:
My initial proposal (http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't exactly get a warm welcome... And Now for Something Completely Different: class autoinit(object): def __init__(self, *args, **keyword_args): self.__dict__.update(
4
2794
by: David Coffin | last post by:
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but changing 'self' obviously just alters the value of that local variable. Is there some way for me to change the value of the BitSequence object itself? I've also tried wrapping and delegating using __getattr__, but I couldn't figure out how to handle...
4
1824
by: marek.rocki | last post by:
First of all, please don't flame me immediately. I did browse archives and didn't see any solution to my problem. Assume I want to add a method to an object at runtime. Yes, to an object, not a class - because changing a class would have global effects and I want to alter a particular object only. The following approach fails: class kla: x = 1
7
1911
by: Andrew Robert | last post by:
Hi Everyone, I am having a problem with a class and hope you can help. When I try to use the class listed below, I get the statement that self is not defined. test=TriggerMessage(data) var = test.decode(self.qname)
24
2303
by: Peter Maas | last post by:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version): 1. Instance variables can be easily distinguished from local variables. 2. A method from a particular class can be called as baseclass.methodname(self, <argument list>). 3. No need for declarations to disambiguate assignments to local/instance variables.
84
7227
by: braver | last post by:
Is there any trick to get rid of having to type the annoying, character-eating "self." prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to use Ruby anywhere speed is not crucial especially for @ prefix is better- looking than self. But things grow -- is there any metaprogramming tricks or whatnot we can throw on the self? Cheers,
13
12030
by: Kurda Yon | last post by:
Hi, I found one example which defines the addition of two vectors as a method of a class. It looks like that: class Vector: def __add__(self, other): data = for j in range(len(self.data)): data.append(self.data + other.data)
6
1817
by: Bart Kastermans | last post by:
I am playing with some trees. In one of the procedures I wrote for this I am trying to change self to a different tree. A tree here has four members (val/type/left/right). I found that self = SS does not work; I have to write self.val = SS.val and the same for the other members (as shown below). Is there a better way to do this? In the below self is part of a parse tree, F is the parse tree of a function f with argument x. If a node...
0
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.