mirror of
https://github.com/valinet/ExplorerPatcher.git
synced 2024-12-18 02:16:00 +01:00
75 lines
2.2 KiB
C
75 lines
2.2 KiB
C
#include <Windows.h>
|
|
#include <Shlwapi.h>
|
|
#pragma comment(lib, "Shlwapi.lib")
|
|
#include "../ExplorerPatcher/utility.h"
|
|
|
|
int WINAPI wWinMain(
|
|
_In_ HINSTANCE hInstance,
|
|
_In_opt_ HINSTANCE hPrevInstance,
|
|
_In_ LPWSTR lpCmdLine,
|
|
_In_ int nShowCmd
|
|
)
|
|
{
|
|
WCHAR wszPath[MAX_PATH];
|
|
GetModuleFileNameW(GetModuleHandle(NULL), wszPath, MAX_PATH);
|
|
PathRemoveFileSpecW(wszPath);
|
|
wcscat_s(wszPath, MAX_PATH, L"\\" _T(PRODUCT_NAME) L".amd64.dll");
|
|
|
|
CHAR hash[100];
|
|
ZeroMemory(hash, 100);
|
|
ComputeFileHash(wszPath, hash, 100);
|
|
|
|
PathRemoveFileSpecW(wszPath);
|
|
wcscat_s(wszPath, MAX_PATH, L"\\" _T(SETUP_UTILITY_NAME));
|
|
|
|
HANDLE hFile = CreateFileW(wszPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
HANDLE hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
|
|
if (hFileMapping == 0)
|
|
{
|
|
CloseHandle(hFile);
|
|
return 2;
|
|
}
|
|
|
|
char* lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
|
if (lpFileBase == 0)
|
|
{
|
|
CloseHandle(hFileMapping);
|
|
CloseHandle(hFile);
|
|
return 3;
|
|
}
|
|
|
|
memcpy(lpFileBase + DOSMODE_OFFSET, hash, strlen(hash));
|
|
|
|
UnmapViewOfFile(lpFileBase);
|
|
CloseHandle(hFileMapping);
|
|
CloseHandle(hFile);
|
|
|
|
if (__argc > 1)
|
|
{
|
|
SHELLEXECUTEINFO ShExecInfo = { 0 };
|
|
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
|
|
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
ShExecInfo.hwnd = NULL;
|
|
ShExecInfo.lpVerb = L"runas";
|
|
ShExecInfo.lpFile = wszPath;
|
|
ShExecInfo.lpParameters = L"/update_silent";
|
|
ShExecInfo.lpDirectory = NULL;
|
|
ShExecInfo.nShow = SW_SHOW;
|
|
ShExecInfo.hInstApp = NULL;
|
|
if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess)
|
|
{
|
|
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
|
|
DWORD dwExitCode = 0;
|
|
GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode);
|
|
CloseHandle(ShExecInfo.hProcess);
|
|
return dwExitCode;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |