您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

再说程序运行后自删除的方法(C++源代码)

2024/3/25 6:28:26发布21次查看
johnchen分析了一下gary nebbett写的一段程序自删除的程序。是很精妙的一段代码,精妙之处在于其进程尚在,但可执行文件已经被删除了。
我前段时间也写了一段自删除代码,不过没有那么高深,只是利用了批处理的功能,在程序的最后调用我这个函数,就能够将自己删除。现在把函数代码贴出来。
void selfdelete() 
{
static char templ[] = 
:repeat\r\n
del \%s\\r\n
if exist \%s\ goto repeat\r\n
rmdir %s \r\n
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 ;
hf = createfile(temppath, generic_write, 0, null, 
create_always, file_attribute_normal, null) ;
if (hf != invalid_handle_value)
{
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);
}
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product