首页 > 其他 > 详细

自毁程序

时间:2020-03-10 00:52:40      阅读:57      评论:0      收藏:0      [点我收藏+]
 1 void SelfDestroy()
 2 {
 3     // temporary .bat file
 4     static const WCHAR tempbatname[] = L"_uninsep.bat";
 5     CString csCmd;    //bat contents
 6     std::string szCmd;
 7 
 8     static WCHAR templ[] =
 9         L":Repeat\r\n"
10         L"del \"%s\"\r\n"
11         L"if exist \"%s\" goto Repeat\r\n"
12         L"rmdir \"%s\"\r\n"
13         L"del \"%s\"";
14     
15     WCHAR modulename[_MAX_PATH];    // absolute path of calling .exe file
16     WCHAR temppath[_MAX_PATH];      // absolute path of temporary .bat file
17     WCHAR folder[_MAX_PATH];
18     // absolute path of temporary .bat file
19     GetTempPath(_MAX_PATH, temppath);
20     wcscat_s(temppath, tempbatname);
21     // absolute path of calling .exe file
22     GetModuleFileName(NULL, modulename, MAX_PATH);
23     wcscpy_s(folder, modulename);
24     
25     PWCHAR pb = wcsrchr(folder, \\);
26     if (pb != NULL)
27         *pb = 0;
28 
29     HANDLE hf;
30 
31     hf = CreateFile(temppath, GENERIC_WRITE, 0, NULL,
32         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
33     //Long,如执行成功,则返回文件句柄。INVALID_HANDLE_VALUE表示出错,会设置GetLastError。即使函数成功,但若文件存在,且指定了CREATE_ALWAYS 或 OPEN_ALWAYS,GetLastError也会设为ERROR_ALREADY_EXISTS
34     if (hf != INVALID_HANDLE_VALUE)
35     {
36         csCmd.Format(templ, modulename, modulename, folder, temppath);
37         CStringToString(csCmd, szCmd);
38         DWORD len;
39         PWCHAR bat;
40         //缓存大小最大1024
41         WriteFile(hf, szCmd.c_str(), szCmd.size(), &len, NULL);
42         CloseHandle(hf);
43         ShellExecuteW(NULL, L"open", temppath, NULL, NULL, SW_HIDE);
44     }
45 }

 

自毁程序

原文:https://www.cnblogs.com/endenvor/p/12452786.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!