self destroying program

This is a discussion on self destroying program within the C++ Programming forums, part of the General Programming Boards category; >> thank you every1 for your input. i'm looking into those 2 provided links right now. >> how do u ...

  1. #16
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    >> 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?

    how hard is it to type complete words? after all, this isn't a chat room...
    anyway, look into the execXXX family of functions...
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  2. #17
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    sorry if it bothers you.............

    everyone*
    two*
    one*
    Last edited by bballzone; 08-01-2004 at 05:41 PM.

  3. #18
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30
    hi,

    a undocumented way to do what you want is calling FreeLibrary() in your own imagebase(under w9x) or UnmapViewOfFile(), under nt4.

    in assembler, you would do something like that:

    delete_self:
    mov ecx,implant_size
    sub esp, ecx ;alloc some mem in stack
    mov edi,esp
    mov esi,offset implant
    rep movsb ;copy self-delete code to there
    jmp esp ;and jump


    implant:
    sub esp,200h ;alloc temp buffer in stack
    mov eax, esp
    push 200h
    push eax
    push 0
    call GetModuleFileName ;get current filename
    push 0
    call GetModuleHandle
    push eax ;arg for UnmapViewOfFile
    push eax
    call FreeLibrary
    call UnmapViewOfFile
    push esp
    call DeleteFile
    add esp,200h
    jmp $ ;hang (you can also call ExitProcess)
    implant_size equ $-implant

    very likely the code willnt compile as is, coz i write it from the top of my head. but play with this idea and it will work...

    hope it help.

    jmgk

  4. #19
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    this doesn't work

    Check1.exe
    Code:
    int main()
    {
    system("check2.exe test");
    return 0;
    }
    Check2.exe
    Code:
    int main(int argc, char *argv[])
    {
    cout << argv[1] << endl;
    if (argv[1] = "test")
    {
    Sleep(1000);
    system("del check1.exe");
    }
    else
    {
    cout << "Error";
    }
    return 0;
    }
    output/error:
    test
    c:\documents and....\check1.exe
    Access is denied

  5. #20
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    delete won't delete a running program. How about trying one of the suggestion given during this thread?

  6. #21
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    The second link posted by anonytmouse is excellent. I suggest you try his snippet at the bottom of his page.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  7. #22
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    Sebastiani: The exec family of functions replaces the current process image with a new process image.

    how does this help?


    Thantos: i did try one of the suggestions. a couple were about exe 1 calling exe 2 and exe 2 deleting exe 1. that's what i tried to accompish.


    pianorain: can't remember but either that code didn't compile or i got errors when running the program.

  8. #23
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thantos: i did try one of the suggestions. a couple were about exe 1 calling exe 2 and exe 2 deleting exe 1. that's what i tried to accompish
    NO NO NO NO NO NO NO NO NO!
    EXE 1 deletes EXE 2 based off of the return value from EXE 2.

  9. #24
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    do u have any code on how exe 1 gets the return value of exe 2?

    and will that solve my problem or will i still get an Access Denied?

  10. #25
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Just as a note, the following line:
    Code:
    if (argv[1] = "test")
    will not work as you expect it to. You are assigning a value to a pointer, not testing the value of a string (firstly, = vs. ==). Look into the strcmp function in <cstring> to test the value.

  11. #26
    Registered User
    Join Date
    May 2004
    Posts
    3

  12. #27
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    that link was already posted and i assure you i read the whole thing word for word. there was a problem with each one. either it didn't compile on my crap compiler, the method would not work on my version of Windows, or i didn't know enough about what a method talked about to be able to use it.

    still don't know how to get return values from other programs
    Last edited by bballzone; 08-02-2004 at 05:15 PM.

  13. #28
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30
    bballzone,

    so, what more we can do for you?

    jmgk

  14. #29
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    "NO NO NO NO NO NO NO NO NO!
    EXE 1 deletes EXE 2 based off of the return value from EXE 2"

    i think the last thing i need before i can get this to work is how to get a return value from another program. maybe i'm just too new at this and the answer is obvious.

    WHAT A SEC...attempting to do more things on my own and it might be working.

    ok yep i got it. sometimes experimenting on your own is the best way to learn..which is the hard way unfortunately

    thx every1 for the help
    Last edited by bballzone; 08-02-2004 at 06:50 PM.

Page 2 of 2 FirstFirst 12
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, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21