Thread: self destroying program

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    67

    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?

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    18
    system()?

  3. #3
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Or if there are any files that your central exe depends on to run, just delete them.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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.

  6. #6
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I had asked a question pertaining to some circular dependence issues, but then I thoguht about it and realized that was silly.
    Last edited by skorman00; 08-01-2004 at 04:06 PM. Reason: realized the answer to my question

  7. #7

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Nope, exe 1 spawns exe 2 and captures the return value of exe 2 and deletes it if need be.

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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?

  10. #10
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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"

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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
    Last edited by Thantos; 08-01-2004 at 04:11 PM.

  12. #12
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Ahh.... Okay - I get it now.

  13. #13
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    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?

  14. #14
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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[])

  15. #15
    Registered User
    Join Date
    Feb 2004
    Posts
    35
    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.
    Last edited by MortalMonkey; 08-01-2004 at 05:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM