Altering The Program's Executable?
Hi all, :)
Let us presume a program knows its own filename and path, either gotten it during run-time or has it as a constant. Now is it possible for the program to alter the data in its own executable program file, the "EXE" meaning? I presume that it won’t get write access but I can’t understand why, when the program is running from the memory it shouldn’t affect it self during run-time and therefore shouldn’t affect the OS, so whats the problem? Is there a function that could give access for altering an executed program file, that is or isn’t the calling program's own executable file? I other words, is it possible for a program to alter the data in its own executable program file or another already executed program's executable file? :confused:
Re: Altering The Program's Executable?
Quote:
Originally posted by Aidman
Hi all, :)
Let us presume a program knows its own filename and path, either gotten it during run-time or has it as a constant. Now is it possible for the program to alter the data in its own executable program file, the "EXE" meaning? I presume that it won’t get write access but I can’t understand why, when the program is running from the memory it shouldn’t affect it self during run-time and therefore shouldn’t affect the OS, so whats the problem? Is there a function that could give access for altering an executed program file, that is or isn’t the calling program's own executable file? I other words, is it possible for a program to alter the data in its own executable program file or another already executed program's executable file? :confused:
With Windows, when you run an exe, the system creates a memory map for the execuatble file (basically mapping the bytes in the file to a region of virutal memory)...while this map is in place, the system denies other threads and processes from opening a "write" access handle to the mapped file.......that's why you cant alter it.....as soon as the running program has completed, the exe file can be altered just as any binary file - but beware! - messing around with an exe can easilly corrupt it unless you know exactly what you are doing