-
self destroying program
there is a security feature on my program and i have an if statement. if it is true then the program runs. if it's false it prints "Hack" and exits the program. instead of having it print "HacK" and exiting i want it to delete itself. i tried using _unlink() like you would with a text file but it didn't work. is there any way i can do this?
-
-
I'm pretty sure you'd have to ask another program to do it, and end the first one before the second one goes to work. You could probably go all sneaky and rename an exe to some propriatory file and hide it among your others (assuming you have other files). Then when you want to delete the exe, you could execute that hidden one, you might have to change it back to a .exe extension.
Or you can use something like install wizard, assuming you're on a Windows platform.
-
Or if there are any files that your central exe depends on to run, just delete them.
-
To expand on the two executable method:
Exe 1 calls exe 2 will certain parameters that are only known to you, such as a key and a small cipher string to make sure that exe 2 isn't being called by itself.
Now if you determine that exe 2 needs t be deleted it uses an exit value other then zero which tells exe 1 to remove exe 2.
-
I had asked a question pertaining to some circular dependence issues, but then I thoguht about it and realized that was silly.
-
-
Nope, exe 1 spawns exe 2 and captures the return value of exe 2 and deletes it if need be.
-
I'm sure you're correct but I'm just confused - how can exe 1 capture the return value of exe 2 if exe 2 deletes exe 1 before it returns anything?
-
I had originally asked the same question sean, when I realized "oh wait, the program is being ran from a mirror kept in system memory, not directly from the file"
-
exe 2 is the program that does whatever you want
exe 1 is the program that launches exe 2 and waits for the return value from exe 2 and does the deletion
Code:
launch Exe 1
create cipher
lauch exe 2 with cipher as a parameter
do stuff
if hacked return 1
else return 0
if return value is 1
delete exe 2
else
leave program
-
Ahh.... Okay - I get it now.
-
thank you every1 for your input. i'm looking into those 2 provided links right now.
how do u open exe 2 from exe 1 and how do u pass parameters to it?
-
Someone mentioned system() earlier, which is usually advised against, but I think cosnidering the circumstances it's okay. Just put whatever system call is necessary (i.e. whatever you'd type to start running the program from the command line) in double quotes as a parameter to the system function. And you'd pass parameters just like any other program from a command line call. You'd need to read up on parameters being passed to the main function first. You'll know you've found it when you see examples like
Code:
int main(int argc, char *argv[])
-
You could probably also achieve a desirable effect with a stack-smashing hax. I'm thinking something along the lines of allocating some mem that you inject with deletion instructions, then hack a return adress to that mem.
Might be a problem deallocating the memory afterwards though.
Edit: I see something better was used in one of them docs. Gotta learn some propper assembly one of these days.