LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 11-05-2012, 02:42 PM   #1
abcde597
Member
 
Registered: Oct 2012
Location: Alabama, US
Distribution: Several Debian Based Distros
Posts: 57

Rep: Reputation: Disabled
Question 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?
 
Old 11-05-2012, 03:08 PM   #2
hunternet93
Member
 
Registered: Jun 2009
Posts: 87

Rep: Reputation: 31
Yup. If the program knows where it's own source files are, it can edit them and recompile.
 
Old 11-05-2012, 03:48 PM   #3
abcde597
Member
 
Registered: Oct 2012
Location: Alabama, US
Distribution: Several Debian Based Distros
Posts: 57

Original Poster
Rep: Reputation: Disabled
Can you help me find source code showing this?
 
Old 11-05-2012, 09:45 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
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.")
 
Old 11-05-2012, 10:14 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
A famous problem: write a program that prints its source.
http://en.wikipedia.org/wiki/Quine_%28computing%29
 
Old 11-06-2012, 03:52 AM   #6
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
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.
 
Old 11-06-2012, 06:47 AM   #7
hunternet93
Member
 
Registered: Jun 2009
Posts: 87

Rep: Reputation: 31
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.
 
Old 11-06-2012, 04:13 PM   #8
abcde597
Member
 
Registered: Oct 2012
Location: Alabama, US
Distribution: Several Debian Based Distros
Posts: 57

Original Poster
Rep: Reputation: Disabled
Thanks, all!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Theoretical question: Install linux via serial port? linuxlicious Linux - General 10 12-05-2011 05:46 PM
INIT and the boot scripts, a theoretical question. stf92 Linux - Newbie 4 09-19-2011 05:09 AM
[SOLVED] wiping HDD using /dev/urandom versus /dev/zero, a theoretical question H_TeXMeX_H Linux - General 6 06-29-2009 06:55 AM
abi file in the /boot directory -- possibly theoretical question only mpts Ubuntu 0 09-04-2007 10:31 AM
Theoretical Question jgr220 Linux - Security 3 03-29-2003 05:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration