Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-05-2012, 02:42 PM
|
#1
|
|
Member
Registered: Oct 2012
Location: Alabama, US
Distribution: Several Debian Based Distros
Posts: 55
Rep: 
|
I have a partially theoretical question.
Would it be possible to write a program that writes/changes its own source code?
I mean, virus writers can do it, can't we?
|
|
|
|
11-05-2012, 03:08 PM
|
#2
|
|
Member
Registered: Jun 2009
Posts: 84
Rep:
|
Yup. If the program knows where it's own source files are, it can edit them and recompile.
|
|
|
|
11-05-2012, 03:48 PM
|
#3
|
|
Member
Registered: Oct 2012
Location: Alabama, US
Distribution: Several Debian Based Distros
Posts: 55
Original Poster
Rep: 
|
Can you help me find source code showing this?
|
|
|
|
11-05-2012, 09:45 PM
|
#4
|
|
Senior Member
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 4,554
|
Yes, you can compile a program if you have its source-code, but it's far more difficult to swap the image of a running process on-the-fly. Very often the executable file is locked to prevent such modification. Almost always, it's simply ignored if you try.
When a program is executing, its code-segment is almost always protected against modification, for a variety of reasons not just this one.
(And all of the foregoing comments are "not-at-all Linux-specific.")
|
|
|
|
11-06-2012, 03:52 AM
|
#6
|
|
Senior Member
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,671
|
Donald Knuth, in the Art of Computer Programming (one of the early parts, if I remember correctly) considers the problem of self-modifying code and is prepared to do it and so has an example. Of course, this is in assembler for the hypothetical MIX machine, but you should be able to extrapolate from there.
|
|
|
|
11-06-2012, 06:47 AM
|
#7
|
|
Member
Registered: Jun 2009
Posts: 84
Rep:
|
I think the program would just compile itself, start the modified copy, pass the copy whatever data/parameters it needs, and exit. I'm not a C programmer, though, so I can't be sure.
|
|
|
|
11-06-2012, 04:13 PM
|
#8
|
|
Member
Registered: Oct 2012
Location: Alabama, US
Distribution: Several Debian Based Distros
Posts: 55
Original Poster
Rep: 
|
Thanks, all!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:45 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|