Let's talk about the method of self-deletion after running the program (C++ source code)

巴扎黑
Release: 2016-12-20 14:44:34
Original
2493 people have browsed it

JohnChen analyzed a self-deleting program written by Gary Nebbett. It is a very subtle piece of code. The subtlety is that the process is still there, but the executable file has been deleted.

I also wrote a piece of self-deleting code some time ago, but it was not that advanced. I just used the batch processing function and called my function at the end of the program to delete myself. Now post the function code.

void SelfDelete()
{
static char templ[] =
":Repeatrn"
"del "%s"rn"
"if exist "%s" goto Repeatrn"
"rmdir %s rn"
"del "%s"" ;
static const char tempbatname[] = "_uninsep.bat" ;

char modulename[MAX_PATH] ;
char temppath[MAX_PATH] ;
char folder[MAX_PATH] ;

GetTempPath(MAX_PATH, temppath) ;
strcat(temppath, tempbatname) ;

GetModuleFileName(NULL, modulename, MAX_PATH) ;
strcpy (folder, modulename) ;
char *pb = strrchr(folder, '\');
if (pb != NULL)
*pb = 0;

HANDLE hf
DWORD len ;
char *bat ;

bat = (char*)alloca(strlen(templ) +
strlen(modulename) * 2 + strlen(temppath) + 20) ;

wsprintf(bat, templ, modulename, modulename, folder, temppath) ;

WriteFile(hf, bat, strlen(bat), &len, NULL) ;
CloseHandle(hf) ;

ShellExecute(NULL, "open", temppath, NULL, NULL, SW_HIDE);
}
}



Related labels:
c
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!