Reputation: 46
i want to change some byte of an .exe file that is running in my source file to destroy it(NOT DELETE) and not run next time. how i can do this?
assume that my source file is Test.C, i want to write a code in this source file that change some byte of my Tese.exe file before exit. i can delete this exe file completely befor exit with http://www.catch22.net/tuts/self-deleting-executables[^] can i use a second executable file like test2.exe to write on test1.exe in runtime? if this is possible,how?
Upvotes: 0
Views: 2045
Reputation: 8267
Presumably you want this because you only want the program to run only once.Some of these techniques were used in the early 80s in DOS programs. It doesn't stop the user from taking a copy before executing it the first time (which is what I did - that is how I know these techniques).
In the cases where the second program is used, it checks argc[1]. This has to be a bunch of control characters that cannot be typed in on the keyboard by can be passed in from the launching program. Also, check that it can be written to or renamed before you launch it. It is possible that the user has protected the directory so you cannot write to the file. Alternatively, they may have the file on CD.
Upvotes: 2
Reputation: 3335
Technically, .exe files can be read or written like any other file, provided you have proper access rights and know what you are doing.
It's however very bad practice to do so.
If you want to change your program's behaviour on next start, I'd rather suggest storing that information in your program's private config file.
Upvotes: 3