Nima Ghajari
Nima Ghajari

Reputation: 46

How I Can Edit A Exe File When It's Run

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

Answers (2)

cup
cup

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).

  1. The normal way to do this would be to write something into the registry. The key you use could be totally cryptic.
  2. Your program could launch a second program to do the work and when that has finished
    • write something to a hidden config file
    • writing 0 to the first n bytes and then saving it
    • rename the file so that the same filename with 3 backspaces and exe appended - this is not noticeable in explorer - everything looks the same but it is no longer an executable
    • replace the last e in exe with the Cyrillic e. This technique was used in the early 90s.
  3. Just tell the user not to do it.

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

mfro
mfro

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

Related Questions