cold-debug-elevator 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Utils.hpp ADDED
@@ -0,0 +1,151 @@
1
+ #ifndef UTILS_H
2
+ #define UTILS_H
3
+
4
+ #include <windows.h>
5
+ #include <filesystem>
6
+ #include <iostream>
7
+ #include <regex>
8
+ #include <optional>
9
+ #include <tlhelp32.h>
10
+
11
+ namespace fs = std::filesystem;
12
+
13
+ enum class DebugStatus
14
+ {
15
+ Normal,
16
+ DebuggerAttached,
17
+ Waiting,
18
+ Breakpoint,
19
+ Error
20
+ };
21
+
22
+ WORD ColorForStatus(DebugStatus status)
23
+ {
24
+ switch (status)
25
+ {
26
+ case DebugStatus::DebuggerAttached:
27
+ return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // hard green
28
+
29
+ case DebugStatus::Waiting:
30
+ return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // yellow
31
+
32
+ case DebugStatus::Breakpoint:
33
+ return FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; // magenta
34
+
35
+ case DebugStatus::Error:
36
+ return FOREGROUND_RED | FOREGROUND_INTENSITY; // red
37
+
38
+ case DebugStatus::Normal:
39
+ default:
40
+ return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // normal gray
41
+ }
42
+ }
43
+
44
+ void PrintBanner(DebugStatus status)
45
+ {
46
+ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
47
+
48
+ CONSOLE_SCREEN_BUFFER_INFO oldInfo = {};
49
+ bool hasConsoleInfo = GetConsoleScreenBufferInfo(hConsole, &oldInfo);
50
+ constexpr const char* Reset = "\x1b[0m";
51
+
52
+ SetConsoleTextAttribute(hConsole, ColorForStatus(status));
53
+
54
+ std::cout << R"BANNER(________ ___. ___________.__ __
55
+ \______ \ ____\_ |__ __ __ ____\_ _____/| | _______ _______ _/ |_ ___________
56
+ | | \_/ __ \| __ \| | \/ ___\| __)_ | | _/ __ \ \/ /\__ \\ __\/ _ \_ __ \
57
+ | ` \ ___/| \_\ \ | / /_/ > \| |_\ ___/\ / / __ \| | ( <_> ) | \/
58
+ /_______ /\___ >___ /____/\___ /_______ /|____/\___ >\_/ (____ /__| \____/|__|
59
+ \/ \/ \/ /_____/ \/ \/ \/
60
+ )BANNER" << Reset;
61
+
62
+ if (hasConsoleInfo)
63
+ {
64
+ SetConsoleTextAttribute(hConsole, oldInfo.wAttributes);
65
+ }
66
+
67
+ std::cout << "\n";
68
+ }
69
+
70
+ std::optional<fs::path> FindChromeVersionFolder(const fs::path& chromeExePath)
71
+ {
72
+ fs::path applicationDir = chromeExePath.parent_path();
73
+
74
+ if (!fs::exists(applicationDir) || !fs::is_directory(applicationDir))
75
+ return std::nullopt;
76
+
77
+ // Example: 147.0.7729.123
78
+ const std::wregex versionRegex(
79
+ LR"(^\d+\.\d+\.\d+\.\d+$)"
80
+ );
81
+
82
+ for (const auto& entry : fs::directory_iterator(applicationDir))
83
+ {
84
+ if (!entry.is_directory())
85
+ continue;
86
+
87
+ std::wstring folderName = entry.path().filename().wstring();
88
+
89
+ if (std::regex_match(folderName, versionRegex))
90
+ return entry.path();
91
+ }
92
+
93
+ return std::nullopt;
94
+ }
95
+
96
+ bool EqualsIgnoreCase(const std::wstring& a, const std::wstring& b)
97
+ {
98
+ return _wcsicmp(a.c_str(), b.c_str()) == 0;
99
+ }
100
+
101
+ std::vector<DWORD> KillProcessesByName(const std::wstring& processName)
102
+ {
103
+ std::vector<DWORD> killedPids;
104
+
105
+ HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
106
+
107
+ if (snapshot == INVALID_HANDLE_VALUE)
108
+ return killedPids;
109
+
110
+ PROCESSENTRY32W pe = {};
111
+ pe.dwSize = sizeof(pe);
112
+
113
+ if (!Process32FirstW(snapshot, &pe))
114
+ {
115
+ CloseHandle(snapshot);
116
+ return killedPids;
117
+ }
118
+
119
+ do
120
+ {
121
+ if (!EqualsIgnoreCase(pe.szExeFile, processName))
122
+ continue;
123
+
124
+ DWORD pid = pe.th32ProcessID;
125
+
126
+ // Do not try to kill yourself accidentally
127
+ if (pid == GetCurrentProcessId())
128
+ continue;
129
+
130
+ HANDLE hProcess = OpenProcess(
131
+ PROCESS_TERMINATE,
132
+ FALSE,
133
+ pid
134
+ );
135
+
136
+ if (!hProcess)
137
+ continue;
138
+
139
+ if (TerminateProcess(hProcess, 0))
140
+ killedPids.push_back(pid);
141
+
142
+ CloseHandle(hProcess);
143
+
144
+ } while (Process32NextW(snapshot, &pe));
145
+
146
+ CloseHandle(snapshot);
147
+
148
+ return killedPids;
149
+ }
150
+
151
+ #endif
package/src/main.cpp ADDED
@@ -0,0 +1,31 @@
1
+ #include <napi.h>
2
+ #include <windows.h>
3
+ #include <string>
4
+
5
+ extern "C" bool ExtractBrowserData(const wchar_t* browserPath, const wchar_t* outputPath);
6
+
7
+ Napi::Value Extract(const Napi::CallbackInfo& info) {
8
+ Napi::Env env = info.Env();
9
+
10
+ if (info.Length() < 2 || !info[0].IsString() || !info[1].IsString()) {
11
+ Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
12
+ return env.Null();
13
+ }
14
+
15
+ std::u16string browserPathU16 = info[0].As<Napi::String>().Utf16Value();
16
+ std::u16string outputPathU16 = info[1].As<Napi::String>().Utf16Value();
17
+
18
+ bool result = ExtractBrowserData(
19
+ reinterpret_cast<const wchar_t*>(browserPathU16.c_str()),
20
+ reinterpret_cast<const wchar_t*>(outputPathU16.c_str())
21
+ );
22
+
23
+ return Napi::Boolean::New(env, result);
24
+ }
25
+
26
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
27
+ exports.Set(Napi::String::New(env, "extract"), Napi::Function::New(env, Extract));
28
+ return exports;
29
+ }
30
+
31
+ NODE_API_MODULE(debug1337, Init)