发新话题
打印

看似“自杀程序”的源代码!

看似“自杀程序”的源代码!

//*******************************E N D*********************************
//程序很简单! 这个代码 通过复制本身到c:\盘 然后以带参数方式打开c:\得自身 参数为本程序的
//path!
#include "stdafx.h"
#include <conio.h>
#include "stdio.h"
#include <stdlib.h>

int main(int argc, char* argv[])
{
        // if this is a colne,it's arugment's count must is 3!
        // so if argc not equal to 3,that means this is a not clone runnin,yet!
        if( argc != 3 )   //判断程序是不是有参数! 如果没有就复制本身到 一个自定义的目录并执行!
        {
                char                                                CLONE_FILE[MAX_PATH];
                DWORD                                                pID;
                char                                                *lpBuff;
                int                                                        nBuff=MAX_PATH;
                STARTUPINFO                                        si;
                PROCESS_INFORMATION                        pi;
                char                                                *lpCommLines;

                // * here are 3 step need to plane *
                // first,get process's executable filename with full path
                pID = GetCurrentProcessId();  //取得本进程的 pid  传递给另一个自身文件文件 判断本进程是否关闭!
               
                if(pID==NULL)        return -1;

                lpBuff=new char[nBuff];
                GetTempPath(nBuff,lpBuff);          //取得临时文件夹的路径
                GetTempFileName(lpBuff,"Clone",0,CLONE_FILE);

                sprintf(CLONE_FILE,"%s","C:\\Clone.EXe");  //这个地址可以使用上面的临时文件夹的路径!
               
                // second,copy process's executable filename to a temporal file
                if(CopyFile(argv[0],CLONE_FILE,FALSE)==0)
                        printf("copy error...%d\n",GetLastError());

                // third,write temporal file flag,and run temporal with process mode
                CreateFile(CLONE_FILE,
                                GENERIC_READ,
                                FILE_SHARE_DELETE|FILE_SHARE_READ, // FILE_SHARE_DELETE <-- important
                                (LPSECURITY_ATTRIBUTES)NULL,
                                OPEN_EXISTING,
                                FILE_FLAG_DELETE_ON_CLOSE,
                                (HANDLE)NULL);

                lpCommLines = new char[MAX_PATH];
                memset(lpCommLines,0,MAX_PATH);

                // notice command line format
                sprintf(lpCommLines,"%s \"%s\" %d",CLONE_FILE,argv[0],pID);

                memset(&si,0,sizeof(STARTUPINFO));
                si.cb = sizeof(STARTUPINFO);

                if(CreateProcess(NULL,lpCommLines,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi)==0)  
                        //在创建一个进程 来删除自身! 参数为自身的 path  pid
                        printf("error %d.\n",GetLastError());
               
                // delay,waiting for new process!
                Sleep(400);

                delete lpCommLines;
                delete lpBuff;
        }
        else
        {
                HANDLE                                                hOrgProc;
                DWORD                                                pID;

                // debug infor
                //printf("Process ID:%s\nOld file name:%s",argv[2],argv[1]);

                // open process handle and waiting for it close automatical
                pID = (DWORD)_atoi64(argv[2]);
                hOrgProc = OpenProcess(PROCESS_ALL_ACCESS,TRUE,pID); //打开原程序进程
                WaitForSingleObject(hOrgProc,INFINITE);  //直到此原进程关闭
                CloseHandle(hOrgProc);

                // delete org file!
                DeleteFile(argv[1]);  //删除 原文件

                //
                printf("\npress any key to continue...\n");
                getch();
                // when clone process waiting finished,it will be delete by OS!
        }
        return 0;
}
附件: 您所在的用户组无法下载或查看附件

TOP

不错哦...

TOP

不错哦...

TOP

学习`

TOP

顶的打死

TOP

发新话题