diff --git a/2.x/trunk/plugins/OnlineChecks/main.c b/2.x/trunk/plugins/OnlineChecks/main.c
index 369eae158..07b0e2ab8 100644
--- a/2.x/trunk/plugins/OnlineChecks/main.c
+++ b/2.x/trunk/plugins/OnlineChecks/main.c
@@ -1,9 +1,9 @@
/*
* Process Hacker Online Checks -
- * main program
+ * Main Program
*
* Copyright (C) 2010-2013 wj32
- * Copyright (C) 2013 dmex
+ * Copyright (C) 2012-2014 dmex
*
* This file is part of Process Hacker.
*
@@ -21,103 +21,16 @@
* along with Process Hacker. If not, see .
*/
-#include
#include "onlnchk.h"
-#include "resource.h"
-
-VOID NTAPI LoadCallback(
- _In_opt_ PVOID Parameter,
- _In_opt_ PVOID Context
- );
-
-VOID NTAPI ShowOptionsCallback(
- _In_opt_ PVOID Parameter,
- _In_opt_ PVOID Context
- );
-
-VOID NTAPI MenuItemCallback(
- _In_opt_ PVOID Parameter,
- _In_opt_ PVOID Context
- );
-
-VOID NTAPI ProcessMenuInitializingCallback(
- _In_opt_ PVOID Parameter,
- _In_opt_ PVOID Context
- );
-
-VOID NTAPI ModuleMenuInitializingCallback(
- _In_opt_ PVOID Parameter,
- _In_opt_ PVOID Context
- );
PPH_PLUGIN PluginInstance;
-PH_CALLBACK_REGISTRATION PluginLoadCallbackRegistration;
-PH_CALLBACK_REGISTRATION PluginShowOptionsCallbackRegistration;
-PH_CALLBACK_REGISTRATION PluginMenuItemCallbackRegistration;
-PH_CALLBACK_REGISTRATION ProcessMenuInitializingCallbackRegistration;
-PH_CALLBACK_REGISTRATION ModuleMenuInitializingCallbackRegistration;
+static PH_CALLBACK_REGISTRATION PluginLoadCallbackRegistration;
+static PH_CALLBACK_REGISTRATION PluginShowOptionsCallbackRegistration;
+static PH_CALLBACK_REGISTRATION PluginMenuItemCallbackRegistration;
+static PH_CALLBACK_REGISTRATION ProcessMenuInitializingCallbackRegistration;
+static PH_CALLBACK_REGISTRATION ModuleMenuInitializingCallbackRegistration;
-LOGICAL DllMain(
- _In_ HINSTANCE Instance,
- _In_ ULONG Reason,
- _Reserved_ PVOID Reserved
- )
-{
- switch (Reason)
- {
- case DLL_PROCESS_ATTACH:
- {
- PPH_PLUGIN_INFORMATION info;
-
- PluginInstance = PhRegisterPlugin(L"ProcessHacker.OnlineChecks", Instance, &info);
-
- if (!PluginInstance)
- return FALSE;
-
- info->DisplayName = L"Online Checks";
- info->Author = L"dmex & wj32";
- info->Description = L"Allows files to be checked with online services.";
- info->HasOptions = FALSE;
-
- PhRegisterCallback(
- PhGetPluginCallback(PluginInstance, PluginCallbackLoad),
- LoadCallback,
- NULL,
- &PluginLoadCallbackRegistration
- );
- PhRegisterCallback(
- PhGetPluginCallback(PluginInstance, PluginCallbackShowOptions),
- ShowOptionsCallback,
- NULL,
- &PluginShowOptionsCallbackRegistration
- );
- PhRegisterCallback(
- PhGetPluginCallback(PluginInstance, PluginCallbackMenuItem),
- MenuItemCallback,
- NULL,
- &PluginMenuItemCallbackRegistration
- );
-
- PhRegisterCallback(
- PhGetGeneralCallback(GeneralCallbackProcessMenuInitializing),
- ProcessMenuInitializingCallback,
- NULL,
- &ProcessMenuInitializingCallbackRegistration
- );
- PhRegisterCallback(
- PhGetGeneralCallback(GeneralCallbackModuleMenuInitializing),
- ModuleMenuInitializingCallback,
- NULL,
- &ModuleMenuInitializingCallbackRegistration
- );
- }
- break;
- }
-
- return TRUE;
-}
-
-VOID NTAPI LoadCallback(
+static VOID NTAPI LoadCallback(
_In_opt_ PVOID Parameter,
_In_opt_ PVOID Context
)
@@ -125,7 +38,7 @@ VOID NTAPI LoadCallback(
// Nothing
}
-VOID NTAPI ShowOptionsCallback(
+static VOID NTAPI ShowOptionsCallback(
_In_opt_ PVOID Parameter,
_In_opt_ PVOID Context
)
@@ -133,7 +46,7 @@ VOID NTAPI ShowOptionsCallback(
// Nothing
}
-VOID NTAPI MenuItemCallback(
+static VOID NTAPI MenuItemCallback(
_In_opt_ PVOID Parameter,
_In_opt_ PVOID Context
)
@@ -158,7 +71,7 @@ VOID NTAPI MenuItemCallback(
}
}
-PPH_EMENU_ITEM CreateSendToMenu(
+static PPH_EMENU_ITEM CreateSendToMenu(
_In_ PPH_EMENU_ITEM Parent,
_In_ PWSTR InsertAfter,
_In_ PPH_STRING FileName
@@ -186,7 +99,7 @@ PPH_EMENU_ITEM CreateSendToMenu(
return sendToMenu;
}
-VOID NTAPI ProcessMenuInitializingCallback(
+static VOID NTAPI ProcessMenuInitializingCallback(
_In_opt_ PVOID Parameter,
_In_opt_ PVOID Context
)
@@ -210,7 +123,7 @@ VOID NTAPI ProcessMenuInitializingCallback(
}
}
-VOID NTAPI ModuleMenuInitializingCallback(
+static VOID NTAPI ModuleMenuInitializingCallback(
_In_opt_ PVOID Parameter,
_In_opt_ PVOID Context
)
@@ -231,3 +144,63 @@ VOID NTAPI ModuleMenuInitializingCallback(
sendToMenu->Flags |= PH_EMENU_DISABLED;
}
}
+
+LOGICAL DllMain(
+ _In_ HINSTANCE Instance,
+ _In_ ULONG Reason,
+ _Reserved_ PVOID Reserved
+ )
+{
+ switch (Reason)
+ {
+ case DLL_PROCESS_ATTACH:
+ {
+ PPH_PLUGIN_INFORMATION info;
+
+ PluginInstance = PhRegisterPlugin(SETTING_PREFIX, Instance, &info);
+
+ if (!PluginInstance)
+ return FALSE;
+
+ info->DisplayName = L"Online Checks";
+ info->Author = L"dmex, wj32";
+ info->Description = L"Allows files to be checked with online services.";
+ info->Url = L"http://processhacker.sf.net/forums/viewtopic.php?f=18&t=1118";
+ info->HasOptions = FALSE;
+
+ PhRegisterCallback(
+ PhGetPluginCallback(PluginInstance, PluginCallbackLoad),
+ LoadCallback,
+ NULL,
+ &PluginLoadCallbackRegistration
+ );
+ PhRegisterCallback(
+ PhGetPluginCallback(PluginInstance, PluginCallbackShowOptions),
+ ShowOptionsCallback,
+ NULL,
+ &PluginShowOptionsCallbackRegistration
+ );
+ PhRegisterCallback(
+ PhGetPluginCallback(PluginInstance, PluginCallbackMenuItem),
+ MenuItemCallback,
+ NULL,
+ &PluginMenuItemCallbackRegistration
+ );
+ PhRegisterCallback(
+ PhGetGeneralCallback(GeneralCallbackProcessMenuInitializing),
+ ProcessMenuInitializingCallback,
+ NULL,
+ &ProcessMenuInitializingCallbackRegistration
+ );
+ PhRegisterCallback(
+ PhGetGeneralCallback(GeneralCallbackModuleMenuInitializing),
+ ModuleMenuInitializingCallback,
+ NULL,
+ &ModuleMenuInitializingCallbackRegistration
+ );
+ }
+ break;
+ }
+
+ return TRUE;
+}
\ No newline at end of file
diff --git a/2.x/trunk/plugins/OnlineChecks/onlnchk.h b/2.x/trunk/plugins/OnlineChecks/onlnchk.h
index 0a3b7bff9..c810845bf 100644
--- a/2.x/trunk/plugins/OnlineChecks/onlnchk.h
+++ b/2.x/trunk/plugins/OnlineChecks/onlnchk.h
@@ -1,28 +1,48 @@
+/*
+ * Process Hacker Online Checks -
+ * Main Headers
+ *
+ * Copyright (C) 2010-2013 wj32
+ * Copyright (C) 2012-2014 dmex
+ *
+ * This file is part of Process Hacker.
+ *
+ * Process Hacker is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Process Hacker is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Process Hacker. If not, see .
+ */
+
#ifndef ONLNCHK_H
#define ONLNCHK_H
-#pragma comment(lib, "OleAut32.lib")
#pragma comment(lib, "Winhttp.lib")
#define CINTERFACE
#define COBJMACROS
-#include
-#include
#include
-#include
+#include
#include
-#include
-#include
#include "sha256.h"
#include "resource.h"
+#define SETTING_PREFIX L"ProcessHacker.OnlineChecks"
+
#define HASH_SHA1 1
#define HASH_SHA256 2
-#define UM_EXISTS (WM_APP + 1)
-#define UM_LAUNCH (WM_APP + 2)
-#define UM_ERROR (WM_APP + 3)
+#define UM_EXISTS (WM_USER + 1)
+#define UM_LAUNCH (WM_USER + 2)
+#define UM_ERROR (WM_USER + 3)
#define Control_Visible(hWnd, visible) \
ShowWindow(hWnd, visible ? SW_SHOW : SW_HIDE);
@@ -30,7 +50,6 @@
typedef enum _PH_UPLOAD_SERVICE_STATE
{
PhUploadServiceDefault = 0,
-
PhUploadServiceChecking,
PhUploadServiceViewReport,
PhUploadServiceUploading,
@@ -50,24 +69,22 @@ typedef struct _SERVICE_INFO
typedef struct _UPLOAD_CONTEXT
{
- PPH_STRING FileName;
- PPH_STRING WindowFileName;
ULONG Service;
HWND DialogHandle;
HWND MessageHandle;
HWND StatusHandle;
HWND ProgressHandle;
HFONT MessageFont;
- HINTERNET HttpHandle;
-
+ HINTERNET HttpHandle;
+
ULONG ErrorCode;
- PPH_STRING ErrorMessage;
- PPH_STRING ErrorStatusMessage;
+ ULONG TotalFileLength;
PH_UPLOAD_SERVICE_STATE UploadServiceState;
- HANDLE FileHandle;
- ULONG TotalFileLength;
+
+ PPH_STRING FileName;
PPH_STRING BaseFileName;
+ PPH_STRING WindowFileName;
PPH_STRING ObjectName;
PPH_STRING LaunchCommand;
} UPLOAD_CONTEXT, *PUPLOAD_CONTEXT;
@@ -85,11 +102,4 @@ VOID UploadToOnlineService(
_In_ ULONG Service
);
-INT_PTR CALLBACK UploadDlgProc(
- _In_ HWND hwndDlg,
- _In_ UINT uMsg,
- _In_ WPARAM wParam,
- _In_ LPARAM lParam
- );
-
#endif
diff --git a/2.x/trunk/plugins/OnlineChecks/upload.c b/2.x/trunk/plugins/OnlineChecks/upload.c
index e672ca9c7..809ec0641 100644
--- a/2.x/trunk/plugins/OnlineChecks/upload.c
+++ b/2.x/trunk/plugins/OnlineChecks/upload.c
@@ -1,9 +1,9 @@
/*
* Process Hacker Online Checks -
- * uploader
+ * Uploader Window
*
* Copyright (C) 2010-2013 wj32
- * Copyright (C) 2013 dmex
+ * Copyright (C) 2012-2014 dmex
*
* This file is part of Process Hacker.
*
@@ -30,56 +30,6 @@ static SERVICE_INFO UploadServiceInfo[] =
{ UPLOAD_SERVICE_CIMA, L"camas.comodo.com", INTERNET_DEFAULT_HTTP_PORT, 0, L"/cgi-bin/submit", L"file" }
};
-static PPH_STRING PhGetWinHttpMessage(
- _In_ ULONG Result
- )
-{
- return PhGetMessage(GetModuleHandle(L"winhttp.dll"), 0xb, GetUserDefaultLangID(), Result);
-}
-
-static NTSTATUS PhUploadToDialogThreadStart(
- _In_ PVOID Parameter
- )
-{
- BOOL result;
- MSG message;
- HWND dialogHandle;
- PH_AUTO_POOL autoPool;
- PUPLOAD_CONTEXT context = (PUPLOAD_CONTEXT)Parameter;
-
- PhInitializeAutoPool(&autoPool);
-
- dialogHandle = CreateDialogParam(
- (HINSTANCE)PluginInstance->DllBase,
- MAKEINTRESOURCE(IDD_PROGRESS),
- PhMainWndHandle,
- UploadDlgProc,
- (LPARAM)Parameter
- );
-
- ShowWindow(dialogHandle, SW_SHOW);
- SetForegroundWindow(dialogHandle);
-
- while (result = GetMessage(&message, NULL, 0, 0))
- {
- if (result == -1)
- break;
-
- if (!IsDialogMessage(dialogHandle, &message))
- {
- TranslateMessage(&message);
- DispatchMessage(&message);
- }
-
- PhDrainAutoPool(&autoPool);
- }
-
- PhDeleteAutoPool(&autoPool);
- DestroyWindow(dialogHandle);
- PhFree(context);
- return STATUS_SUCCESS;
-}
-
static HFONT InitializeFont(
_In_ HWND hwndDlg
)
@@ -165,15 +115,14 @@ static VOID RaiseUploadError(
_In_ ULONG ErrorCode
)
{
- PhSwapReference(&Context->ErrorMessage, NULL);
- PhSwapReference(&Context->ErrorStatusMessage, NULL);
-
- Context->ErrorMessage = PhFormatString(L"Error: [%u] %s", ErrorCode, Error);
- Context->ErrorStatusMessage = PhGetWinHttpMessage(ErrorCode);
-
if (Context->DialogHandle)
{
- PostMessage(Context->DialogHandle, UM_ERROR, 0, 0);
+ PostMessage(
+ Context->DialogHandle,
+ UM_ERROR,
+ 0,
+ (LPARAM)PhFormatString(L"Error: [%u] %s", ErrorCode, Error)
+ );
}
}
@@ -376,7 +325,13 @@ static NTSTATUS HashFileAndResetPosition(
}
positionInfo.CurrentByteOffset.QuadPart = 0;
- status = NtSetInformationFile(FileHandle, &iosb, &positionInfo, sizeof(FILE_POSITION_INFORMATION), FilePositionInformation);
+ status = NtSetInformationFile(
+ FileHandle,
+ &iosb,
+ &positionInfo,
+ sizeof(FILE_POSITION_INFORMATION),
+ FilePositionInformation
+ );
}
return status;
@@ -386,30 +341,33 @@ static NTSTATUS UploadFileThreadStart(
_In_ PVOID Parameter
)
{
- time_t timeStart = 0;
- time_t timeTransferred = 0;
+ NTSTATUS status = STATUS_SUCCESS;
+ ULONG httpStatus = 0;
+ ULONG httpStatusLength = sizeof(ULONG);
ULONG httpPostSeed = 0;
ULONG totalUploadLength = 0;
ULONG totalUploadedLength = 0;
ULONG totalPostHeaderWritten = 0;
ULONG totalPostFooterWritten = 0;
- ULONG totalWriteLength = 0;
- BYTE buffer[PAGE_SIZE];
-
+ ULONG totalWriteLength = 0;
+ LARGE_INTEGER timeNow;
+ LARGE_INTEGER timeStart;
+ ULONG64 timeTicks = 0;
+ ULONG64 timeBitsPerSecond = 0;
+
+ HANDLE fileHandle;
IO_STATUS_BLOCK isb;
- NTSTATUS status = STATUS_SUCCESS;
PSERVICE_INFO serviceInfo = NULL;
-
- ULONG httpStatus = 0;
- ULONG httpStatusLength = sizeof(ULONG);
HINTERNET connectHandle = NULL;
HINTERNET requestHandle = NULL;
- PPH_STRING postBoundary = NULL;
+
+ PPH_STRING postBoundary = NULL;
PPH_ANSI_STRING ansiPostData = NULL;
PPH_ANSI_STRING ansiFooterData = NULL;
PH_STRING_BUILDER httpRequestHeaders = { 0 };
PH_STRING_BUILDER httpPostHeader = { 0 };
PH_STRING_BUILDER httpPostFooter = { 0 };
+ BYTE buffer[PAGE_SIZE];
PUPLOAD_CONTEXT context = (PUPLOAD_CONTEXT)Parameter;
@@ -417,6 +375,23 @@ static NTSTATUS UploadFileThreadStart(
__try
{
+ // Open the file and check its size.
+ status = PhCreateFileWin32(
+ &fileHandle,
+ context->FileName->Buffer,
+ FILE_GENERIC_READ,
+ 0,
+ FILE_SHARE_READ | FILE_SHARE_DELETE,
+ FILE_OPEN,
+ FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
+ );
+
+ if (!NT_SUCCESS(status))
+ {
+ RaiseUploadError(context, L"Unable to open the file", RtlNtStatusToDosError(status));
+ __leave;
+ }
+
// Connect to the online service.
if (!(connectHandle = WinHttpConnect(
context->HttpHandle,
@@ -512,8 +487,7 @@ static NTSTATUS UploadFileThreadStart(
ansiFooterData = PhCreateAnsiStringFromUnicode(httpPostFooter.String->Buffer);
// Start the clock.
- timeStart = time(NULL);
- timeTransferred = timeStart;
+ PhQuerySystemTime(&timeStart);
// Write the header
if (!WinHttpWriteData(
@@ -531,12 +505,12 @@ static NTSTATUS UploadFileThreadStart(
while (TRUE)
{
status = NtReadFile(
- context->FileHandle,
+ fileHandle,
NULL,
NULL,
NULL,
&isb,
- &buffer,
+ buffer,
PAGE_SIZE,
NULL,
NULL
@@ -545,28 +519,24 @@ static NTSTATUS UploadFileThreadStart(
if (!NT_SUCCESS(status))
break;
- // Check bytes read.
- if (isb.Information == 0)
- break;
-
if (!WinHttpWriteData(requestHandle, buffer, (ULONG)isb.Information, &totalWriteLength))
{
RaiseUploadError(context, L"Unable to upload the file data", GetLastError());
__leave;
}
- // Zero our uploaded file buffer.
- memset(buffer, 0, PAGE_SIZE);
-
totalUploadedLength += totalWriteLength;
- {
- time_t time_taken = (time(NULL) - timeTransferred);
- time_t bps = totalUploadedLength / __max(time_taken, 1);
- //time_t remain = (MulDiv((INT)time_taken, totalFileLength, totalFileReadLength) - time_taken);
+ PhQuerySystemTime(&timeNow);
+
+ timeTicks = (timeNow.QuadPart - timeStart.QuadPart) / PH_TICKS_PER_SEC;
+ timeBitsPerSecond = totalUploadedLength / __max(timeTicks, 1);
+
+ {
+ FLOAT percent = ((FLOAT)totalUploadedLength / context->TotalFileLength * 100);
PPH_STRING totalLength = PhFormatSize(context->TotalFileLength, -1);
PPH_STRING totalDownloadedLength = PhFormatSize(totalUploadedLength, -1);
- PPH_STRING totalSpeed = PhFormatSize(bps, -1);
+ PPH_STRING totalSpeed = PhFormatSize(timeBitsPerSecond, -1);
PPH_STRING dlLengthString = PhFormatString(
L"%s of %s @ %s/s",
@@ -583,7 +553,7 @@ static NTSTATUS UploadFileThreadStart(
PhDereferenceObject(totalDownloadedLength);
// Update the progress bar position
- PostMessage(context->ProgressHandle, PBM_SETPOS, MulDiv(100, totalUploadedLength, context->TotalFileLength), 0);
+ PostMessage(context->ProgressHandle, PBM_SETPOS, (INT)percent, 0);
}
}
@@ -743,10 +713,6 @@ static NTSTATUS UploadFileThreadStart(
}
__finally
{
- //assert(ansiFooterData->Length == totalPostFooterWritten);
- //assert(ansiPostData->Length == totalPostHeaderWritten);
- //assert(totalUploadedLength == context->TotalFileLength);
-
if (postBoundary)
{
PhDereferenceObject(postBoundary);
@@ -754,12 +720,12 @@ static NTSTATUS UploadFileThreadStart(
if (ansiFooterData)
{
- PhReferenceObject(ansiFooterData);
+ PhDereferenceObject(ansiFooterData);
}
if (ansiPostData)
{
- PhReferenceObject(ansiPostData);
+ PhDereferenceObject(ansiPostData);
}
if (httpPostFooter.String)
@@ -794,6 +760,7 @@ static NTSTATUS UploadCheckThreadStart(
PSERVICE_INFO serviceInfo = NULL;
PPH_STRING hashString = NULL;
PPH_STRING subObjectName = NULL;
+ HANDLE fileHandle;
PUPLOAD_CONTEXT context = (PUPLOAD_CONTEXT)Parameter;
@@ -803,7 +770,7 @@ static NTSTATUS UploadCheckThreadStart(
{
// Open the file and check its size.
status = PhCreateFileWin32(
- &context->FileHandle,
+ &fileHandle,
context->FileName->Buffer,
FILE_GENERIC_READ,
0,
@@ -812,26 +779,23 @@ static NTSTATUS UploadCheckThreadStart(
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
);
- if (NT_SUCCESS(status))
- {
- if (NT_SUCCESS(status = PhGetFileSize(context->FileHandle, &fileSize64)))
- {
- if (fileSize64.QuadPart > 20 * 1024 * 1024) // 20 MB
- {
- RaiseUploadError(context, L"The file is too large (over 20 MB)", ERROR_FILE_TOO_LARGE);
- __leave;
- }
-
- context->TotalFileLength = fileSize64.LowPart;
- }
- }
-
if (!NT_SUCCESS(status))
{
RaiseUploadError(context, L"Unable to open the file", RtlNtStatusToDosError(status));
__leave;
}
+ if (NT_SUCCESS(status = PhGetFileSize(fileHandle, &fileSize64)))
+ {
+ if (fileSize64.QuadPart > 20 * 1024 * 1024) // 20 MB
+ {
+ RaiseUploadError(context, L"The file is too large (over 20 MB)", ERROR_FILE_TOO_LARGE);
+ __leave;
+ }
+
+ context->TotalFileLength = fileSize64.LowPart;
+ }
+
// Get proxy configuration and create winhttp handle (used for all winhttp sessions + requests).
{
PPH_STRING phVersion = NULL;
@@ -840,7 +804,7 @@ static NTSTATUS UploadCheckThreadStart(
// Create a user agent string.
phVersion = PhGetPhVersion();
- userAgent = PhConcatStrings2(L"Process Hacker ", phVersion->Buffer);
+ userAgent = PhConcatStrings2(L"ProcessHacker_", phVersion->Buffer);
// Query the current system proxy
WinHttpGetIEProxyConfigForCurrentUser(&proxyConfig);
@@ -870,7 +834,7 @@ static NTSTATUS UploadCheckThreadStart(
ULONG bufferLength = 0;
UCHAR hash[32];
- status = HashFileAndResetPosition(context->FileHandle, &fileSize64, HASH_SHA256, hash);
+ status = HashFileAndResetPosition(fileHandle, &fileSize64, HASH_SHA256, hash);
if (!NT_SUCCESS(status))
{
RaiseUploadError(context, L"Unable to hash the file", RtlNtStatusToDosError(status));
@@ -918,7 +882,7 @@ static NTSTATUS UploadCheckThreadStart(
ULONG bufferLength = 0;
UCHAR hash[20];
- status = HashFileAndResetPosition(context->FileHandle, &fileSize64, HASH_SHA1, hash);
+ status = HashFileAndResetPosition(fileHandle, &fileSize64, HASH_SHA1, hash);
if (!NT_SUCCESS(status))
{
RaiseUploadError(context, L"Unable to hash the file", RtlNtStatusToDosError(status));
@@ -956,7 +920,7 @@ static NTSTATUS UploadCheckThreadStart(
ULONG status = 0;
ULONG statusLength = sizeof(statusLength);
- status = HashFileAndResetPosition(context->FileHandle, &fileSize64, HASH_SHA256, hash);
+ status = HashFileAndResetPosition(fileHandle, &fileSize64, HASH_SHA256, hash);
if (!NT_SUCCESS(status))
{
RaiseUploadError(context, L"Unable to hash the file", RtlNtStatusToDosError(status));
@@ -1044,15 +1008,8 @@ static NTSTATUS UploadCheckThreadStart(
}
__finally
{
- if (hashString)
- {
- PhDereferenceObject(hashString);
- }
-
- if (subObjectName)
- {
- PhDereferenceObject(subObjectName);
- }
+ PhSwapReference2(&hashString, NULL);
+ PhSwapReference2(&subObjectName, NULL);
if (requestHandle)
{
@@ -1063,12 +1020,15 @@ static NTSTATUS UploadCheckThreadStart(
{
WinHttpCloseHandle(connectHandle);
}
+
+ if (fileHandle)
+ NtClose(fileHandle);
}
return status;
}
-INT_PTR CALLBACK UploadDlgProc(
+static INT_PTR CALLBACK UploadDlgProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
@@ -1088,14 +1048,11 @@ INT_PTR CALLBACK UploadDlgProc(
if (uMsg == WM_NCDESTROY)
{
- if (context->FileName)
- PhDereferenceObject(context->FileName);
-
- if (context->BaseFileName)
- PhDereferenceObject(context->BaseFileName);
-
- if (context->WindowFileName)
- PhDereferenceObject(context->WindowFileName);
+ PhSwapReference2(&context->FileName, NULL);
+ PhSwapReference2(&context->BaseFileName, NULL);
+ PhSwapReference2(&context->WindowFileName, NULL);
+ PhSwapReference2(&context->LaunchCommand, NULL);
+ PhSwapReference2(&context->ObjectName, NULL);
if (context->MessageFont)
DeleteObject(context->MessageFont);
@@ -1103,16 +1060,8 @@ INT_PTR CALLBACK UploadDlgProc(
if (context->HttpHandle)
WinHttpCloseHandle(context->HttpHandle);
- if (context->ObjectName)
- PhDereferenceObject(context->ObjectName);
-
- if (context->FileHandle)
- NtClose(context->FileHandle);
-
- if (context->LaunchCommand)
- PhDereferenceObject(context->LaunchCommand);
-
RemoveProp(hwndDlg, L"Context");
+ PhFree(context);
}
}
@@ -1133,7 +1082,9 @@ INT_PTR CALLBACK UploadDlgProc(
context->ProgressHandle = GetDlgItem(hwndDlg, IDC_PROGRESS1);
context->MessageHandle = GetDlgItem(hwndDlg, IDC_MESSAGE);
context->MessageFont = InitializeFont(context->MessageHandle);
-
+ context->WindowFileName = PhFormatString(L"Uploading: %s", context->BaseFileName->Buffer);
+ context->UploadServiceState = PhUploadServiceChecking;
+
// Reset the window status...
Static_SetText(context->MessageHandle, context->WindowFileName->Buffer);
@@ -1150,8 +1101,6 @@ INT_PTR CALLBACK UploadDlgProc(
break;
}
- context->UploadServiceState = PhUploadServiceChecking;
-
if (dialogThread = PhCreateThread(0, (PUSER_THREAD_START_ROUTINE)UploadCheckThreadStart, (PVOID)context))
NtClose(dialogThread);
}
@@ -1251,25 +1200,22 @@ INT_PTR CALLBACK UploadDlgProc(
break;
case UM_ERROR:
{
+ PPH_STRING errorMessage = (PPH_STRING)lParam;
+
context->UploadServiceState = PhUploadServiceMaximum;
- Static_SetText(GetDlgItem(hwndDlg, IDNO), L"Close");
-
- if (context->ErrorMessage)
+ if (errorMessage)
{
- Static_SetText(context->MessageHandle, context->ErrorMessage->Buffer);
- PhDereferenceObject(context->ErrorMessage);
- }
-
- if (context->ErrorStatusMessage)
- {
- Static_SetText(context->StatusHandle, context->ErrorStatusMessage->Buffer);
- PhDereferenceObject(context->ErrorStatusMessage);
+ Static_SetText(GetDlgItem(hwndDlg, IDC_MESSAGE), errorMessage->Buffer);
+ PhSwapReference2(&errorMessage, NULL);
}
else
{
- Static_SetText(context->StatusHandle, L"");
- }
+ Static_SetText(GetDlgItem(hwndDlg, IDC_MESSAGE), L"Error");
+ }
+
+ Static_SetText(GetDlgItem(hwndDlg, IDC_STATUS), L"");
+ Static_SetText(GetDlgItem(hwndDlg, IDNO), L"Close");
}
break;
}
@@ -1277,19 +1223,62 @@ INT_PTR CALLBACK UploadDlgProc(
return FALSE;
}
+static NTSTATUS PhUploadToDialogThreadStart(
+ _In_ PVOID Parameter
+ )
+{
+ BOOL result;
+ MSG message;
+ HWND dialogHandle;
+ PH_AUTO_POOL autoPool;
+ PUPLOAD_CONTEXT context = (PUPLOAD_CONTEXT)Parameter;
+
+ PhInitializeAutoPool(&autoPool);
+
+ dialogHandle = CreateDialogParam(
+ (HINSTANCE)PluginInstance->DllBase,
+ MAKEINTRESOURCE(IDD_PROGRESS),
+ PhMainWndHandle,
+ UploadDlgProc,
+ (LPARAM)Parameter
+ );
+
+ ShowWindow(dialogHandle, SW_SHOW);
+ SetForegroundWindow(dialogHandle);
+
+ while (result = GetMessage(&message, NULL, 0, 0))
+ {
+ if (result == -1)
+ break;
+
+ if (!IsDialogMessage(dialogHandle, &message))
+ {
+ TranslateMessage(&message);
+ DispatchMessage(&message);
+ }
+
+ PhDrainAutoPool(&autoPool);
+ }
+
+ PhDeleteAutoPool(&autoPool);
+ DestroyWindow(dialogHandle);
+
+ return STATUS_SUCCESS;
+}
+
VOID UploadToOnlineService(
_In_ PPH_STRING FileName,
_In_ ULONG Service
)
{
HANDLE dialogThread = NULL;
+
PUPLOAD_CONTEXT context = (PUPLOAD_CONTEXT)PhAllocate(sizeof(UPLOAD_CONTEXT));
memset(context, 0, sizeof(UPLOAD_CONTEXT));
context->Service = Service;
- context->FileName = PhFormatString(L"%s", FileName->Buffer);
+ context->FileName = PhDuplicateString(FileName);
context->BaseFileName = PhGetBaseName(context->FileName);
- context->WindowFileName = PhFormatString(L"Uploading: %s", context->BaseFileName->Buffer);
if (dialogThread = PhCreateThread(0, (PUSER_THREAD_START_ROUTINE)PhUploadToDialogThreadStart, (PVOID)context))
NtClose(dialogThread);