Thread: a self mutating code...!!!

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    3

    a self mutating code...!!!

    Is a fully automated self mutating code possible by c programming....does the programming constructs of c recommend that...!!!!

















    nishant

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Strict ANSI or ISO C doesn't have a way to reliably alter code at runtime.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Yes, it's possible (although very OS-dependant, I'm sure), but I would hardly say that the contructs of C recommend it. I've heard of an instance when developers were extremely limited by hardware resources, and used this technique to fit a 7kb algorithm in 5kb of code - because it would modify itself half way through VERY cleverly. However, that's hardly a problem these days - and self mutating code is usually used to simply disguise malicious code. I can't think of another legitimate use.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There are limitations to what any Turing Machine can do. (All computers you can buy, are Turing Machines).

    Before you could answer this, you'd have to put strict definitions on what "self mutating" means, to you. For instance, if I have a program that writes out another program (which is changed from the original), and then starts that program, and stops running itself, is that a "mutating" program?

    So the first thing I'd suggest is go read up on "Turing Machines", and see if your definition allows a TM to do what you want.

    The second problem of course, is memory and power. Say your program was running a series of quantum calculations, and now you wanted it to drive an experimental car. Both are very possible for a program, but I've never heard of any one program, or mutation of any one program, that could do both these things.

    Each is quite non-trivial, requires a lot of computational power, and specialized programming. If having one program play Tic-Tac-Toe, and then morph into playing Blackjack - I'm sure that could be done, without a lot of "mutations", though.

    Which gets back to a more central question - what's the purpose of the "mutations", in the first place?

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    It would be easier to write a interpreting engine for another language that allows self mutating code, then to make C code mutate itself.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    A few software 3D engines do self-modifying code.
    Duke Nukem 3D for the Mac had an option to allow it.
    Pixomatic is probably the extreme case.
    It's not something a beginner need concern themselves with
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Wouldn't that make a virus scanner go to red alert?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Not the kind of thing that's be picked up by your average virus scanner. It's more the kind of thing that DEP could have a fit over.

    However it wouldn't surprise me if one of those overly invasive "total system security" packages (which shall remain nameless) potentially complains about it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Code:
    int main(){
       unsigned char* pMain = (unsigned char*)main;
    
       while(1) pMain[rand()] = rand();
    
       return 0;
       }

  10. #10
    Registered User
    Join Date
    Nov 2010
    Posts
    1
    @abachler i tried ur code,
    but all i'm gettin is a Segmentation fault
    Can u explain it??

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by snapster View Post
    @abachler i tried ur code,
    but all i'm gettin is a Segmentation fault
    Can u explain it??
    Wow. Bump of an ancient thread. Though I didn't even notice it until I saw a post of Abachler...

    Anyways, Abachler's code is bull. It won't run usually but produce, as you got, a segmentation fault, as the instructions are usually protected from writing. That's not the only problem with this code, though.
    It's still possible, just not as trivial, and as said before, fairly OS dependent.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM