Is a fully automated self mutating code possible by c programming....does the programming constructs of c recommend that...!!!!
nishant
Is a fully automated self mutating code possible by c programming....does the programming constructs of c recommend that...!!!!
nishant
Strict ANSI or ISO C doesn't have a way to reliably alter code at runtime.
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.
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?
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.
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"
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
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"
Code:int main(){ unsigned char* pMain = (unsigned char*)main; while(1) pMain[rand()] = rand(); return 0; }
@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.