473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

self destructing programs

kvt
Hi,

One of my friend puzzled me to write a program which destructs itself.
i.e, by the time it stops execution, its executable file should be
deleted.

I tried a lot like
a) using " system() function to deleted the running program"
result: Access denied

b) googled for logic of other self destructing programs
result: not turned up

c) searched groups. They suggested using a .bat file, invoking the bat
file from currently executing one and through bat file deleting the
current executable after we have finished.
But in this case also, we are leaving residual (.bat file).
result: not a perfect one, only a remedy.

d) after system() function Access denial, i got a thought, as OS is
protecting the currently executing program, it is not possible to
perform anything explicitly on it. so what about taking a pointer in
the current program and filling the entire program space with garbage.

result: i don't known how to do it. i mean from where to start, what
is the start and end of the current memory space.etc.,

if any one of you find other ways please let me know. I think this is
for hackers, who can think out of box.

Bye..
KVT
Dec 9 '07 #1
8 2403
kvt said:
Hi,

One of my friend puzzled me to write a program which destructs itself.
I may be misremembering slightly - it is some years since I used VM/CMS -
but I seem to recall that all you have to do is adjust the filemode to B3.
The next time the program is invoked, it will run to completion, and then
be deleted from the system.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 9 '07 #2
KVT
I may be misremembering slightly - it is some years since I used VM/CMS -
but I seem to recall that all you have to do is adjust the filemode to B3.
The next time the program is invoked, it will run to completion, and then
be deleted from the system.

--
Hi Richard,

can't we do it in a portable manner ?

Don't mind:
Every one coming up with new ones, is there any one who know how to do
it using the pointers as it mentioned in the initial post.

Thank for your valuable contribution any way.

Bye...
Dec 9 '07 #3
In article <72**********************************@d27g2000prf. googlegroups.com>,
kvt <ba**************@gmail.comwrote:
>d) after system() function Access denial, i got a thought, as OS is
protecting the currently executing program, it is not possible to
perform anything explicitly on it.
This varies between operating systems, and versions of operating
systems, and all kinds of details. Since programs are usually paged
in from the executable file, allowing you to modify it might change
other copies of the program that are running. This is usually
not desirable, and preventing you from writing is one solution.
Removing the program might not be so much of a problem, as the
inode (or equivalent) can continue to exist so long as any program
references it.

I have once used a system where setting a breakpoint with the debugger
caused other instances of the same program to stop.
>so what about taking a pointer in
the current program and filling the entire program space with garbage.
Typically operating systems protect the executable code part from
being written, since it's almost always a bug to do that. You may be
able to call a function to change the protection.

-- Richard

--
:wq
Dec 9 '07 #4
On 12ÔÂ9ÈÕ, ÏÂÎç1ʱ28·Ö, kvt <balakrishna.j...@gmail..comwrote:
Hi,

One of my friend puzzled me to write a program which destructs itself.
i.e, by the time it stops execution, its executable file should be
deleted.

I tried a lot like
a) using " system() function to deleted the running program"
result: Access denied

b) googled for logic of other self destructing programs
result: not turned up

c) searched groups. They suggested using a .bat file, invoking the bat
file from currently executing one and through bat file deleting the
current executable after we have finished.
But in this case also, we are leaving residual (.bat file).
result: not a perfect one, only a remedy.

d) after system() function Access denial, i got a thought, as OS is
protecting the currently executing program, it is not possible to
perform anything explicitly on it. so what about taking a pointer in
the current program and filling the entire program space with garbage.

result: i don't known how to do it. i mean from where to start, what
is the start and end of the current memory space.etc.,

if any one of you find other ways please let me know. I think this is
for hackers, who can think out of box.

Bye..
KVT
Suppose the underline OS have multi-process,multi-thread support. Can
you try as the following:

1. Write another program with the below logic,and compile it as an
executable file.
1) creating a UDP socket and bind it to a known unused port,i.e.,
20001 or else.
2) block recvfrom() on this socket.
3) when get sth from the socket, check if it represents the
command:"delete [filename]"
4) if the received command is "delete [filename]",
while( file exists)
{
Sleep(xxx);
try to delete the file
}
5) if sucessful executed the delete file command , exit the
program
6) if the received data dosen't represent the "delete [filename]"
command, just continue to the next recvfrom sys call.

Suppose the program is compiled&linked with name delete.exe under
windows os.

2. In the beginning of your own application , call CreateProcess, with
the name of delete.exe, to make the delete.exe run in background.
3. Before your application actually call exit(), send a "delete [your
application path]" to the delete.exe, for eg, you may need to create a
udp socket and send to "localhost port 20001".

Thanks and Regards,
James Fang
Dec 9 '07 #5
kvt <ba**************@gmail.comwrote in news:72ee37fb-3531-460e-a31f-
5f**********@d27g2000prf.googlegroups.com:
One of my friend puzzled me to write a program which destructs itself.
i.e, by the time it stops execution, its executable file should be
deleted.

If you've got a spare pin on the micrcontroller then it's pretty simple.
Take the spare pin and connect it to ground. However, from startup until
the end of the program, have the pin set as high-impedence. Then, at the
end of "main", set the pin to 5 V. The short circuit will cause more than
25 mA to be drawn from the microcontroller pin, destroying it and
effectively deleting your progam.

If you haven't picked a microcontroller yet, then you might want to look
for ones which are especially suscepitable to damage if you try to source
or sink too much current from their pins. Don't go for anything in the PIC
family, because all you'll do is destroy the pin, the chip will remain
otherwise intact.

--
Tomás Ó hÉilidhe
Dec 9 '07 #6
KVT wrote:
[... wants to have a program remove itself ...]
>
I may be misremembering slightly - it is some years since I used VM/CMS -
but I seem to recall that all you have to do is adjust the filemode to B3.
The next time the program is invoked, it will run to completion, and then
be deleted from the system.

Hi Richard,

can't we do it in a portable manner ?
Nope.

First, there is no portable way to get the name of the executable.
(Yes, there is argv[0], but it's not guaranteed to be correct.)

Second, there may not even be some file on the filesystem which
can be removed. (Consider a program which was generated in memory
and then executed, rather than loaded from disk.)

Third, some systems won't allow a file to be removed if it's in
use. (Windows is one such example. Given your reference to a
".bat file", I assume you're referring to Windows or MS-DOS.)

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Dec 10 '07 #7
KVT <ba***************@gmail.comwrites:
>I may be misremembering slightly - it is some years since I used VM/CMS -
but I seem to recall that all you have to do is adjust the filemode to B3.
The next time the program is invoked, it will run to completion, and then
be deleted from the system.
The above was written by Richard Heathfield. Please don't snip
attrribution lines (those lines of the form "So-and-so wrote:" that
are inserted by your newsreader).
can't we do it in a portable manner ?
Your program could end with something like:

puts("Please delete this program.");
return 0;

If that doesn't satisfy your requirements, there is simply no portable
way to do what you're trying to do.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 10 '07 #8
On 9 Dec 2007 10:54:12 GMT, ri*****@cogsci.ed.ac.uk (Richard Tobin)
wrote:
In article <72**********************************@d27g2000prf. googlegroups.com>,
kvt <ba**************@gmail.comwrote:
d) after system() function Access denial, i got a thought, as OS is
protecting the currently executing program, it is not possible to
perform anything explicitly on it.

This varies between operating systems, and versions of operating
systems, and all kinds of details. Since programs are usually paged
in from the executable file, allowing you to modify it might change
other copies of the program that are running. This is usually
not desirable, and preventing you from writing is one solution.
Removing the program might not be so much of a problem, as the
inode (or equivalent) can continue to exist so long as any program
references it.
In filesystems that use something like an inode -- not all do.
I have once used a system where setting a breakpoint with the debugger
caused other instances of the same program to stop.
so what about taking a pointer in
the current program and filling the entire program space with garbage.

Typically operating systems protect the executable code part from
being written, since it's almost always a bug to do that. You may be
able to call a function to change the protection.
But even if so, clobbering the (or a?) in-memory copy won't
necessarily clobber much less remove the disk copy.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Dec 24 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nobody | last post by:
I NEED HELP IN BUILDING PROGRAMS THAT CAN EDIT THEMSELVES...U KNOW.. THAT SORT OF CODE CHANGING ONE'S OWN CODE???? PLEASE CONTACT ME IF U COULD HELP...
2
by: Joel Jose | last post by:
agreed the 'mutation engine' by dark avenger was a real deadly master-code piece.., but then.. if one could create a self mutating code..in real time then i think it would just b the most...
14
by: Tieche Bruce A MSgt USMTM/AFD | last post by:
I am new to python, Could someone explain (in English) how and when to use self? I have been reading, and haven't found a good example/explanation
24
by: Richard Aubin | last post by:
I'm really new to vb.net programming and programming in general. I would like to teach myself on how to program effectively and I have the financial and time resources to do so. Can I anyone...
3
by: Jarmo Muukka | last post by:
Hi all! I have a small problem I cannot find a good solution. The problem is destructing global (static) variables in correct order. I try to mimic it in here. // file1.cpp contains...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
3
by: Genalube | last post by:
All right I am new at access but why would my calculated fields in my query self destruct all of a sudden? I tested these expressions, saved the query and closed it. I reopened them and tested it. ...
8
by: kvt | last post by:
Hi, One of my friend puzzled me to write a program which destructs itself. i.e, by the time it stops execution, its executable file should be deleted. I tried a lot like a) using " system()...
8
by: ssecorp | last post by:
I first learned about OO from Java. I much prefer to program in Python though. However I am consufed about 2 things. 1. Why do I have to pass self into every method in a class? Since I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.