Skip to content

Commit bf0564f

Browse files
committed
Terminal (Windows): removes using of Win32 registry APIs
1 parent dbb060e commit bf0564f

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/common/windows/registry.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ static bool processRegValue(const FFRegValueArg* arg, const ULONG regType, const
192192
}
193193

194194
case FF_ARG_TYPE_BUFFER: {
195-
if (regType != REG_BINARY) {
196-
goto type_mismatch;
197-
}
198-
199195
FFArgBuffer* buffer = (FFArgBuffer*) arg->value;
200196
if (buffer->length == 0) {
201197
buffer->data = malloc(regDataLen);

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,22 @@ static bool getTerminalFromEnv(FFTerminalResult* result) {
160160
static bool detectDefaultTerminal(FFTerminalResult* result) {
161161
wchar_t regPath[128] = L"SOFTWARE\\Classes\\PackagedCom\\ClassIndex\\";
162162
wchar_t* uuid = regPath + strlen("SOFTWARE\\Classes\\PackagedCom\\ClassIndex\\");
163-
DWORD bufSize = 80;
164-
if (RegGetValueW(HKEY_CURRENT_USER, L"Console\\%%Startup", L"DelegationTerminal", RRF_RT_REG_SZ, NULL, uuid, &bufSize) == ERROR_SUCCESS) {
163+
FF_AUTO_CLOSE_FD HANDLE hkcu = NULL;
164+
if (ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Console\\%%Startup", &hkcu, NULL) &&
165+
ffRegReadData(hkcu, L"DelegationTerminal", &(FFArgBuffer) {
166+
.data = uuid,
167+
.length = (uint32_t) (sizeof(regPath) - (size_t) (uuid - regPath) * sizeof(wchar_t)),
168+
}, NULL)) {
165169
if (wcscmp(uuid, L"{00000000-0000-0000-0000-000000000000}") == 0 || // Let Windows decide
166170
wcscmp(uuid, L"{B23D10C0-E52E-411E-9D5B-C09FDF709C7D}") == 0) // Conhost
167171
{
168172
goto conhost;
169173
}
170174

171-
FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
172-
if (ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regPath, &hKey, NULL)) {
175+
FF_AUTO_CLOSE_FD HANDLE hklm = NULL;
176+
if (ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regPath, &hklm, NULL)) {
173177
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
174-
if (ffRegGetSubKey(hKey, 0, &path, NULL)) {
178+
if (ffRegGetSubKey(hklm, 0, &path, NULL)) {
175179
if (ffStrbufStartsWithS(&path, "Microsoft.WindowsTerminal")) {
176180
ffStrbufSetS(&result->processName, "WindowsTerminal.exe");
177181
ffStrbufSetS(&result->prettyName, "WindowsTerminal");

0 commit comments

Comments
 (0)