-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (77 loc) · 2.67 KB
/
main.cpp
File metadata and controls
86 lines (77 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <windows.h>
#include <filesystem>
#include <string>
#include <vector>
namespace fs = std::filesystem;
// --- Native API Definitions ---
typedef enum _SYSTEM_MEMORY_LIST_COMMAND {
MemoryFlushWorkingSets = 2,
MemoryFlushModifiedList = 3,
MemoryFlushStandbyList = 4,
MemoryPurgeLowPriorityStandbyList = 5,
MemoryPurgeStandbyList = 6
} SYSTEM_MEMORY_LIST_COMMAND;
typedef LONG (WINAPI *NtSetSystemInformation)(
INT SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength
);
// --- 1. RAM Cleaning Logic ---
void EmptyStandbyList() {
SetProcessWorkingSetSize(GetCurrentProcess(), (SIZE_T)-1, (SIZE_T)-1);
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
if (ntdll) {
auto setInfo = (NtSetSystemInformation)GetProcAddress(ntdll, "NtSetSystemInformation");
if (setInfo) {
SYSTEM_MEMORY_LIST_COMMAND command;
command = MemoryFlushStandbyList;
setInfo(80, &command, sizeof(command));
command = MemoryPurgeLowPriorityStandbyList;
setInfo(80, &command, sizeof(command));
}
}
}
// --- 2. Safe File Cleaning ---
void CleanDirectory(const std::wstring& path) {
std::error_code ec;
if (!fs::exists(path, ec)) return;
auto options = fs::directory_options::skip_permission_denied;
for (auto it = fs::directory_iterator(path, options, ec); it != fs::end(it); it.increment(ec)) {
if (ec) break;
try {
fs::remove_all(it->path(), ec);
} catch (...) {}
}
}
// --- 3. Registry Cleanup ---
void CleanRegistry(HKEY hKeyRoot, const std::wstring& subKey) {
RegDeleteTreeW(hKeyRoot, subKey.c_str());
}
// --- Main Entry ---
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
std::string cmdLine = lpCmdLine ? lpCmdLine : "";
if (cmdLine.find("-et") != std::string::npos) {
EmptyStandbyList();
return 0;
}
EmptyStandbyList();
DWORD bufferSize = GetTempPathW(0, NULL);
if (bufferSize > 0) {
std::wstring tempPath(bufferSize, L'\0');
DWORD len = GetTempPathW(bufferSize, &tempPath[0]);
if (len > 0 && len < bufferSize) {
tempPath.resize(len);
std::vector<std::wstring> targets = {
tempPath,
L"C:\\Windows\\Temp",
L"C:\\Windows\\Prefetch",
};
for (const auto& path : targets) {
CleanDirectory(path);
}
}
}
CleanRegistry(HKEY_CLASSES_ROOT, L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache");
CleanRegistry(HKEY_CURRENT_USER, L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache");
return 0;
}