Skip to content

Commit 5a5734c

Browse files
committed
ExtraPlugins: Fix memory leak, Fix disabling plugin dependancy
1 parent 9f6937c commit 5a5734c

File tree

4 files changed

+25
-147
lines changed

4 files changed

+25
-147
lines changed

plugins/ExtraPlugins/cloud.c

Lines changed: 11 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Extra Plugins -
33
* Plugin Manager
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2017 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -44,134 +44,6 @@ ULONGLONG ParseVersionString(
4444
return MAKE_VERSION_ULONGLONG(majorInteger, minorInteger, reservedInteger, revisionInteger);
4545
}
4646

47-
HICON PluginDownloadImageThread(
48-
_In_ PPH_STRING ImageDownloadUrl
49-
)
50-
{
51-
HINTERNET httpSessionHandle = NULL;
52-
HINTERNET httpConnectionHandle = NULL;
53-
HINTERNET httpRequestHandle = NULL;
54-
PPH_STRING downloadHostPath = NULL;
55-
PPH_STRING downloadUrlPath = NULL;
56-
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig = { 0 };
57-
ULONG xmlStringBufferLength = 0;
58-
PSTR xmlStringBuffer = NULL;
59-
URL_COMPONENTS httpUrlComponents = { sizeof(URL_COMPONENTS) };
60-
61-
WinHttpGetIEProxyConfigForCurrentUser(&proxyConfig);
62-
63-
// Set lengths to non-zero
64-
httpUrlComponents.dwSchemeLength = (ULONG)-1;
65-
httpUrlComponents.dwHostNameLength = (ULONG)-1;
66-
httpUrlComponents.dwUrlPathLength = (ULONG)-1;
67-
68-
if (!WinHttpCrackUrl(
69-
PhGetStringOrEmpty(ImageDownloadUrl),
70-
0,
71-
0,
72-
&httpUrlComponents
73-
))
74-
{
75-
goto CleanupExit;
76-
}
77-
78-
// Create the Host string.
79-
downloadHostPath = PhCreateStringEx(
80-
httpUrlComponents.lpszHostName,
81-
httpUrlComponents.dwHostNameLength * sizeof(WCHAR)
82-
);
83-
if (PhIsNullOrEmptyString(downloadHostPath))
84-
goto CleanupExit;
85-
86-
// Create the Path string.
87-
downloadUrlPath = PhCreateStringEx(
88-
httpUrlComponents.lpszUrlPath,
89-
httpUrlComponents.dwUrlPathLength * sizeof(WCHAR)
90-
);
91-
if (PhIsNullOrEmptyString(downloadUrlPath))
92-
goto CleanupExit;
93-
94-
if (!(httpSessionHandle = WinHttpOpen(
95-
L"ExtraPlugins_1.0",
96-
proxyConfig.lpszProxy ? WINHTTP_ACCESS_TYPE_NAMED_PROXY : WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
97-
proxyConfig.lpszProxy,
98-
proxyConfig.lpszProxyBypass,
99-
0
100-
)))
101-
{
102-
goto CleanupExit;
103-
}
104-
105-
if (!(httpConnectionHandle = WinHttpConnect(
106-
httpSessionHandle,
107-
L"wj32.org",
108-
INTERNET_DEFAULT_HTTP_PORT,
109-
0
110-
)))
111-
{
112-
goto CleanupExit;
113-
}
114-
115-
if (!(httpRequestHandle = WinHttpOpenRequest(
116-
httpConnectionHandle,
117-
NULL,
118-
L"/processhacker/plugins/list.php",
119-
NULL,
120-
WINHTTP_NO_REFERER,
121-
WINHTTP_DEFAULT_ACCEPT_TYPES,
122-
WINHTTP_FLAG_REFRESH
123-
)))
124-
{
125-
goto CleanupExit;
126-
}
127-
128-
if (!WinHttpSendRequest(
129-
httpRequestHandle,
130-
WINHTTP_NO_ADDITIONAL_HEADERS,
131-
0,
132-
WINHTTP_NO_REQUEST_DATA,
133-
0,
134-
WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH,
135-
0
136-
))
137-
{
138-
goto CleanupExit;
139-
}
140-
141-
if (!WinHttpReceiveResponse(httpRequestHandle, NULL))
142-
goto CleanupExit;
143-
144-
if (!ReadRequestString(httpRequestHandle, &xmlStringBuffer, &xmlStringBufferLength))
145-
goto CleanupExit;
146-
147-
//pluginDllPath = PhConcatStrings(3, PhGetString(PhGetApplicationDirectory()), L"Plugins\\", PhGetString(entry->FileName));
148-
//PhInitializeStringRefLongHint(&pluginBaseName, PhGetString(entry->FileName));
149-
150-
//if (PhIsPluginDisabled(&pluginBaseName))
151-
// goto CleanupExit;
152-
153-
//if (RtlDoesFileExists_U(PhGetString(pluginDllPath)))
154-
//{
155-
//
156-
//}
157-
158-
CleanupExit:
159-
160-
if (httpRequestHandle)
161-
WinHttpCloseHandle(httpRequestHandle);
162-
163-
if (httpConnectionHandle)
164-
WinHttpCloseHandle(httpConnectionHandle);
165-
166-
if (httpSessionHandle)
167-
WinHttpCloseHandle(httpSessionHandle);
168-
169-
if (xmlStringBuffer)
170-
PhFree(xmlStringBuffer);
171-
172-
return NULL;
173-
}
174-
17547
NTSTATUS QueryPluginsCallbackThread(
17648
_In_ PVOID Parameter
17749
)
@@ -257,7 +129,6 @@ NTSTATUS QueryPluginsCallbackThread(
257129

258130
jvalue = JsonGetObjectArrayIndex(rootJsonObject, i);
259131
entry->Id = PhConvertUtf8ToUtf16(GetJsonValueAsString(jvalue, "plugin_id"));
260-
entry->Visible = PhConvertUtf8ToUtf16(GetJsonValueAsString(jvalue, "plugin_visible"));
261132
entry->InternalName = PhConvertUtf8ToUtf16(GetJsonValueAsString(jvalue, "plugin_internal_name"));
262133
entry->Name = PhConvertUtf8ToUtf16(GetJsonValueAsString(jvalue, "plugin_name"));
263134
entry->Version = PhConvertUtf8ToUtf16(GetJsonValueAsString(jvalue, "plugin_version"));
@@ -296,6 +167,8 @@ NTSTATUS QueryPluginsCallbackThread(
296167

297168
PPH_STRING directory = PhGetApplicationDirectory();
298169
pluginDllPath = PhConcatStrings(3, PhGetString(directory), L"Plugins\\", PhGetString(entry->FileName));
170+
PhDereferenceObject(directory);
171+
299172
PhInitializeStringRefLongHint(&pluginBaseName, PhGetString(entry->FileName));
300173

301174
if (PhIsPluginDisabled(&pluginBaseName))
@@ -441,6 +314,11 @@ NTSTATUS SetupExtractBuild(
441314
fullSetupPath = PhGetFullPath(PhGetStringOrEmpty(extractPath), &indexOfFileName);
442315

443316
SHCreateDirectoryEx(NULL, PhGetStringOrEmpty(fullSetupPath), NULL);
317+
318+
PhDereferenceObject(fullSetupPath);
319+
PhDereferenceObject(extractPath);
320+
PhDereferenceObject(directory);
321+
PhDereferenceObject(fileName);
444322
}
445323
else
446324
{
@@ -449,16 +327,13 @@ NTSTATUS SetupExtractBuild(
449327
PPH_STRING fullSetupPath;
450328
PPH_STRING extractPath;
451329
PPH_STRING directoryPath;
452-
//PPH_STRING baseNameString;
453330
PPH_STRING fileNameString;
454331
ULONG indexOfFileName = -1;
455332

456333
fileName = PhConvertUtf8ToUtf16(stat.m_filename);
457334
directory = PhGetApplicationDirectory();
458335
extractPath = PhConcatStringRef3(&directory->sr, &pluginsDirectory, &fileName->sr);
459336
fullSetupPath = PhGetFullPath(PhGetStringOrEmpty(extractPath), &indexOfFileName);
460-
//baseNameString = PhGetBaseName(fullSetupPath);
461-
//fullSetupPath = PhGetFullPath(PhGetStringOrEmpty(fileName), &indexOfFileName);
462337
fileNameString = PhConcatStrings(2, fullSetupPath->Buffer, L".bak");
463338

464339
if (indexOfFileName != -1)
@@ -480,8 +355,11 @@ NTSTATUS SetupExtractBuild(
480355
goto error;
481356
}
482357

358+
PhDereferenceObject(fileNameString);
483359
PhDereferenceObject(fullSetupPath);
484360
PhDereferenceObject(extractPath);
361+
PhDereferenceObject(directory);
362+
PhDereferenceObject(fileName);
485363
}
486364
}
487365

plugins/ExtraPlugins/dialog.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ BOOLEAN ProcessTreeFilterCallback(
151151
if (node->State != context->Type)
152152
return FALSE;
153153

154-
// Hide uninstalled plugins from the local tab
155-
//if (node->Type == PLUGIN_VIEW_LOCAL && node->State == PLUGIN_STATE_UNINSTALLED)
156-
// return FALSE;
157-
158-
//// Hide installed plugins from the remote tab
159-
//if (node->Type == PLUGIN_VIEW_REMOTE && node->State == PLUGIN_STATE_INSTALLED)
160-
// return FALSE;
161-
162154
if (PhIsNullOrEmptyString(context->SearchboxText))
163155
return TRUE;
164156

@@ -353,16 +345,22 @@ INT_PTR CALLBACK CloudPluginsDlgProc(
353345
}
354346
else if (selectedNode->State == PLUGIN_STATE_REMOTE)
355347
{
356-
if (StartInitialCheck(hwndDlg, selectedNode, PLUGIN_ACTION_INSTALL))
348+
if (PhGetOwnTokenAttributes().Elevated)
357349
{
350+
if (StartInitialCheck(hwndDlg, selectedNode, PLUGIN_ACTION_INSTALL))
351+
{
358352

353+
}
359354
}
360355
}
361356
else if (selectedNode->State == PLUGIN_STATE_UPDATE)
362357
{
363-
if (StartInitialCheck(hwndDlg, selectedNode, PLUGIN_ACTION_INSTALL))
358+
if (PhGetOwnTokenAttributes().Elevated)
364359
{
360+
if (StartInitialCheck(hwndDlg, selectedNode, PLUGIN_ACTION_INSTALL))
361+
{
365362

363+
}
366364
}
367365
}
368366
}

plugins/ExtraPlugins/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ typedef struct _PLUGIN_NODE
118118

119119
// Remote
120120
PPH_STRING Id;
121-
PPH_STRING Visible;
122-
123121
PPH_STRING Name;
124122
PPH_STRING Version;
125123
PPH_STRING Author;

plugins/ExtraPlugins/plugin.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ VOID EnumerateLoadedPlugins(
309309

310310
pluginInstance = CONTAINING_RECORD(links, PHAPP_PLUGIN, Links);
311311

312+
// HACK: Hide the CommonUtil plugin since it's a required dependency for multiple plugins.
313+
if (PhEqualStringRef2(&pluginInstance->Name, L"ProcessHacker.CommonUtil", TRUE))
314+
continue;
315+
312316
PhInitializeStringRefLongHint(&pluginBaseName, PhGetPluginBaseName(pluginInstance));
313317

314318
if (PhIsPluginDisabled(&pluginBaseName))
@@ -355,6 +359,7 @@ VOID EnumerateLoadedPlugins(
355359
entry->Name = PhCreateString(pluginInstance->Information.DisplayName);
356360
entry->Author = PhCreateString(pluginInstance->Information.Author);
357361
entry->Description = PhCreateString(pluginInstance->Information.Description);
362+
entry->PluginOptions = pluginInstance->Information.HasOptions;
358363
entry->FilePath = PhCreateString2(&pluginInstance->FileName->sr);
359364
entry->FileName = PhGetBaseName(entry->FilePath);
360365

@@ -364,8 +369,7 @@ VOID EnumerateLoadedPlugins(
364369

365370
PhLargeIntegerToSystemTime(&utcTime, &basic.CreationTime);
366371
SystemTimeToTzSpecificLocalTime(NULL, &utcTime, &localTime);
367-
entry->AddedTime = PhFormatDateTime(&localTime);
368-
entry->PluginOptions = pluginInstance->Information.HasOptions;
372+
entry->AddedTime = PhFormatDateTime(&localTime);
369373

370374
PluginsAddTreeNode(Context, entry);
371375
}

0 commit comments

Comments
 (0)