可强删运行中的exe文件,好奇这东西的底层原理是什么,有没有懂的解答一下
[C++] 纯文本查看 复制代码 BOOL ForceDeleteW(LPCWSTR file) {
TCHAR TempPath[MAX_PATH] = { 0 };
if (!GetTempPathW(MAX_PATH, TempPath)) {
return FALSE;
}
const char seed_str[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
srand(time(0));
int len = wcslen(TempPath);
int i = len;
for (; i < len + 10; ++i) {
TempPath[i] = seed_str[(rand() % (sizeof seed_str - 1))];
}
TempPath[i] = 0;
CreateDirectoryW(TempPath, 0);
wcscat_s(TempPath, L"\\....\\");
CreateDirectoryW(TempPath, 0);
TCHAR TempFile[MAX_PATH] = { 0 };
wcscpy_s(TempFile, TempPath);
wcscat_s(TempFile, L"temp");
MoveFileW(file, TempFile);
MoveFileW(TempPath, TempFile);
RemoveDirectoryAndFileW(TempPath);
return TRUE;
} |