Click here to Skip to main content
15,883,904 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
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?
Posted
Updated 11-Mar-14 9:02am
v2
Comments
Krunal Rohit 11-Mar-14 14:48pm    
elaborate it.

-KR
Sergey Alexandrovich Kryukov 11-Mar-14 15:13pm    
Do you really want any elaboration? Even though the purpose of it is totally unclear, what is already said is quite enough.
It makes the answer quite obvious. Please see my answer to see what I mean.
—SA
Krunal Rohit 11-Mar-14 15:16pm    
Question was updated right after I commented.

-KR
Sergey Alexandrovich Kryukov 11-Mar-14 15:33pm    
Got it, thank you.
—SA
ninomimi 11-Mar-14 15:19pm    
yeah i'am update my question ;)

Seriously?
There is a very good chance that you can't, not on a modern OS with a halfway-decent virus scanner.

Because that kind of activity is exactly what heuristic antivirus systems are looking for: anything trying to modify executable files...

If you can, it's simple: Open the file for read/write access, and overwrite the original DOS header. That should kill the file...
But...I suspect it won't work in production. And if it tries and fails, your app will be flagged to the user as virus infected, which will not improve the image of your company in the slightest.

I wouldn't do it, if I was you.
 
Share this answer
 
No way you can do so. All executable files are protected form any modification and deletion when they are loaded in any of the loaded and executing processes. This is the important security feature of most systems, and the important fool-proof feature . So, it's important not to try to play the role of one. :-)

—SA
 
Share this answer
 
In case of a modern operating system every single piece of memory allocated by a normal process is backed by disk storage. Executables/DLLs are backed by the files from which they were loaded while other kind of dynamically allocated memory block are backed by the system page file (this isn't etirely true, you can create your own memory mapped files, loaded exes/dlls are also special memory mapped files...). This way if a process is inactive the OS can throw out pages from the memory to give more memory for active processes. Of course before throwing out the pages of of writable/dirty memory blocks the OS writes these into the mapped files to be able to restore these memory blocks if the owner process tries to use them again.

For this very simple reason modifying a file that participates in memory mapping is not a good idea. On linux you can delete a running executable easily because the actual storage of a deleted file can exists without the directory entry - the actual storage can be referenced not only by directory entries but also by open file handles and the file contents are actually erased only when all referencing directory entries are deleted and all open file handles are closed. To be honest I have no clue how the "delete running executable file" magic works on windows as the windows filesystem works in a different (and in my opinion worse) way.

There is one more thing, you were talking about memory modification. Debuggers and hack programs exploit debugging functions. With these debugging functions you can launch an executable and you (the debugger) can read/modify the memory (even the code) of the debugged process (with the ReadProcessMemory and WriteProcessMemory functions) without affecting its executable file. Debuggers use these functions to implement variable watch/variable modification/memory view/debug breakpoint placement.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Mar-14 19:42pm    
Good explanation, 5ed.
We have the saying "the oats not in the horse" though. :-)
(It means that some really good food is unsuitable for some horse. Just read the last comments to the question.)
—SA
pasztorpisti 11-Mar-14 20:52pm    
Thank you! :-) :-) :-)
Near to impossible.
Because you're about to be modifying EXE.

As simple as that :)

-KR
 
Share this answer
 
Comments
ninomimi 11-Mar-14 15:26pm    
in this link: http://www.catch22.net/tuts/self-deleting-executables , the author can delete a exe file in runtime before exit, that's way not work for this? i try that and not work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900